Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ComputeSKI to use SHA-256 per RFC 7093 Section 2(1). #1402

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions signer/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"crypto/elliptic"
"crypto/rsa"
"crypto/sha1"
"crypto/sha256"
"crypto/x509"
"crypto/x509/pkix"
"encoding/asn1"
Expand Down Expand Up @@ -263,8 +264,9 @@ type subjectPublicKeyInfo struct {
}

// ComputeSKI derives an SKI from the certificate's public key in a
// standard manner. This is done by computing the SHA-1 digest of the
// SubjectPublicKeyInfo component of the certificate.
// standard manner. This is done by computing the SHA-256 digest of the
// SubjectPublicKeyInfo component of the certificate, and returning the
// leftmost 160 bits, per RFC 7093 Section 2(1).
func ComputeSKI(template *x509.Certificate) ([]byte, error) {
pub := template.PublicKey
encodedPub, err := x509.MarshalPKIXPublicKey(pub)
Expand All @@ -278,8 +280,8 @@ func ComputeSKI(template *x509.Certificate) ([]byte, error) {
return nil, err
}

pubHash := sha1.Sum(subPKI.SubjectPublicKey.Bytes)
return pubHash[:], nil
pubHash := sha256.Sum256(subPKI.SubjectPublicKey.Bytes)
return pubHash[:20], nil
}

// FillTemplate is a utility function that tries to load as much of
Expand Down