Skip to content

Commit

Permalink
dump-certurl: Print SHA-256 hash of SubjectPublicKeyInfo (WICG#703)
Browse files Browse the repository at this point in the history
This information can be used as the value of
`--ignore-certificate-errors-spki-list=` command line flag of Chrome
when using a test certificate.
  • Loading branch information
irori authored Nov 24, 2021
1 parent ab932ef commit 1645f3d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions go/signedexchange/certurl/certchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"crypto/sha256"
"crypto/x509"
"encoding/asn1"
"encoding/base64"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -115,6 +116,12 @@ func (ac *AugmentedCertificate) CertSha256() []byte {
return sum[:]
}

// CertSha256 returns SHA-256 hash of the DER-encoded SubjectPublicKeyInfo.
func (ac *AugmentedCertificate) SPKISha256() []byte {
sum := sha256.Sum256(ac.Cert.RawSubjectPublicKeyInfo)
return sum[:]
}

// ReadCertChain parses the application/cert-chain+cbor format.
func ReadCertChain(r io.Reader) (CertChain, error) {
dec := cbor.NewDecoder(r)
Expand Down Expand Up @@ -188,6 +195,7 @@ func (chain CertChain) PrettyPrint(w io.Writer) {
fmt.Fprintln(w, " Valid from:", item.Cert.NotBefore)
fmt.Fprintln(w, " Valid until:", item.Cert.NotAfter)
fmt.Fprintln(w, " Issuer:", item.Cert.Issuer.CommonName)
fmt.Fprintln(w, " SubjectPublicKeyInfo hash:", base64.StdEncoding.EncodeToString(item.SPKISha256()))
prettyPrintSCTFromCert(w, item.Cert)

if i == 0 {
Expand Down

0 comments on commit 1645f3d

Please sign in to comment.