From e5dd1721b341fefad6fc0acee2ba661b2764d60c Mon Sep 17 00:00:00 2001 From: Diogo Monica Date: Wed, 17 Jun 2015 21:11:36 -0700 Subject: [PATCH] Renamed SKID to kID --- cmd/notary/keys.go | 2 +- trustmanager/X509FileStore.go | 8 ++++---- trustmanager/X509MemStore.go | 8 ++++---- trustmanager/X509MemStore_test.go | 14 +++++--------- trustmanager/X509Store.go | 2 +- 5 files changed, 15 insertions(+), 19 deletions(-) diff --git a/cmd/notary/keys.go b/cmd/notary/keys.go index 7c37b8a13b..a562f984e3 100644 --- a/cmd/notary/keys.go +++ b/cmd/notary/keys.go @@ -62,7 +62,7 @@ func keysRemove(cmd *cobra.Command, args []string) { } failed := true - cert, err := caStore.GetCertificateBySKID(args[0]) + cert, err := caStore.GetCertificateBykID(args[0]) if err == nil { fmt.Printf("Removing: ") printCert(cert) diff --git a/trustmanager/X509FileStore.go b/trustmanager/X509FileStore.go index 44b19b8411..67ac05f69a 100644 --- a/trustmanager/X509FileStore.go +++ b/trustmanager/X509FileStore.go @@ -175,15 +175,15 @@ func (s X509FileStore) GetCertificatePool() *x509.CertPool { return pool } -// GetCertificateBySKID returns the certificate that matches a certain SKID or error -func (s X509FileStore) GetCertificateBySKID(hexSKID string) (*x509.Certificate, error) { +// GetCertificateBykID returns the certificate that matches a certain kID or error +func (s X509FileStore) GetCertificateBykID(hexkID string) (*x509.Certificate, error) { // If it does not look like a hex encoded sha256 hash, error - if len(hexSKID) != 64 { + if len(hexkID) != 64 { return nil, errors.New("invalid Subject Key Identifier") } // Check to see if this subject key identifier exists - if cert, ok := s.fingerprintMap[ID(hexSKID)]; ok { + if cert, ok := s.fingerprintMap[ID(hexkID)]; ok { return cert, nil } diff --git a/trustmanager/X509MemStore.go b/trustmanager/X509MemStore.go index 8af41eea31..11cbc0ef8f 100644 --- a/trustmanager/X509MemStore.go +++ b/trustmanager/X509MemStore.go @@ -139,15 +139,15 @@ func (s X509MemStore) GetCertificatePool() *x509.CertPool { return pool } -// GetCertificateBySKID returns the certificate that matches a certain SKID or error -func (s X509MemStore) GetCertificateBySKID(hexSKID string) (*x509.Certificate, error) { +// GetCertificateBykID returns the certificate that matches a certain kID or error +func (s X509MemStore) GetCertificateBykID(hexkID string) (*x509.Certificate, error) { // If it does not look like a hex encoded sha256 hash, error - if len(hexSKID) != 64 { + if len(hexkID) != 64 { return nil, errors.New("invalid Subject Key Identifier") } // Check to see if this subject key identifier exists - if cert, ok := s.fingerprintMap[ID(hexSKID)]; ok { + if cert, ok := s.fingerprintMap[ID(hexkID)]; ok { return cert, nil } diff --git a/trustmanager/X509MemStore_test.go b/trustmanager/X509MemStore_test.go index 7ced8ae75d..5baa8f50d0 100644 --- a/trustmanager/X509MemStore_test.go +++ b/trustmanager/X509MemStore_test.go @@ -1,9 +1,7 @@ package trustmanager import ( - "crypto/sha256" "crypto/x509" - "encoding/hex" "encoding/pem" "io/ioutil" "testing" @@ -108,20 +106,20 @@ func TestRemoveCert(t *testing.T) { } } -func TestInexistentGetCertificateBySKID(t *testing.T) { +func TestInexistentGetCertificateBykID(t *testing.T) { store := NewX509MemStore() err := store.AddCertFromFile("../fixtures/notary/root-ca.crt") if err != nil { t.Fatalf("failed to load certificate from file: %v", err) } - _, err = store.GetCertificateBySKID("4d06afd30b8bed131d2a84c97d00b37f422021598bfae34285ce98e77b708b5a") + _, err = store.GetCertificateBykID("4d06afd30b8bed131d2a84c97d00b37f422021598bfae34285ce98e77b708b5a") if err == nil { t.Fatalf("no error returned for inexistent certificate") } } -func TestGetCertificateBySKID(t *testing.T) { +func TestGetCertificateBykID(t *testing.T) { b, err := ioutil.ReadFile("../fixtures/notary/root-ca.crt") if err != nil { t.Fatalf("couldn't load fixture: %v", err) @@ -140,12 +138,10 @@ func TestGetCertificateBySKID(t *testing.T) { t.Fatalf("failed to load certificate from PEM: %v", err) } - // Calculate SHA256 fingerprint for cert - fingerprintBytes := sha256.Sum256(cert.Raw) - certFingerprint := hex.EncodeToString(fingerprintBytes[:]) + certFingerprint := FingerprintCert(cert) // Tries to retreive cert by Subject Key IDs - _, err = store.GetCertificateBySKID(certFingerprint) + _, err = store.GetCertificateBykID(string(certFingerprint)) if err != nil { t.Fatalf("expected certificate in store: %s", certFingerprint) } diff --git a/trustmanager/X509Store.go b/trustmanager/X509Store.go index e160095fe3..8e5763b621 100644 --- a/trustmanager/X509Store.go +++ b/trustmanager/X509Store.go @@ -10,7 +10,7 @@ type X509Store interface { AddCertFromPEM(pemCerts []byte) error AddCertFromFile(filename string) error RemoveCert(cert *x509.Certificate) error - GetCertificateBySKID(hexSKID string) (*x509.Certificate, error) + GetCertificateBykID(hexkID string) (*x509.Certificate, error) GetCertificates() []*x509.Certificate GetCertificatePool() *x509.CertPool GetVerifyOptions(dnsName string) (x509.VerifyOptions, error)