Renamed SKID to kID

This commit is contained in:
Diogo Monica 2015-06-17 21:11:36 -07:00
parent bb32390698
commit e5dd1721b3
5 changed files with 15 additions and 19 deletions

View File

@ -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)

View File

@ -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
}

View File

@ -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
}

View File

@ -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)
}

View File

@ -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)