Skip to content

Commit e6b1200

Browse files
rolandshoemakerbradfitz
authored andcommitted
acme: fix encoding of the TLS-ALPN challenge extension
To comply with the specification the value of the extension should be a ASN.1 OCTET STRING rather than a raw SHA 256 hash. This change uses asn1.Marshal to wrap the hash before putting it in the extension. Change-Id: I4ebe88a00238c6f928555d605e4b5dd98aad8128 Reviewed-on: https://go-review.googlesource.com/118696 Reviewed-by: Brad Fitzpatrick <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 8ac0e0d commit e6b1200

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

acme/acme.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,10 +598,14 @@ func (c *Client) TLSALPN01ChallengeCert(token, domain string, opt ...CertOption)
598598
return tls.Certificate{}, err
599599
}
600600
shasum := sha256.Sum256([]byte(ka))
601+
extValue, err := asn1.Marshal(shasum[:])
602+
if err != nil {
603+
return tls.Certificate{}, err
604+
}
601605
acmeExtension := pkix.Extension{
602606
Id: idPeACMEIdentifierV1,
603607
Critical: true,
604-
Value: shasum[:],
608+
Value: extValue,
605609
}
606610

607611
tmpl := defaultTLSChallengeCertTemplate()

acme/acme_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,7 @@ func TestTLSALPN01ChallengeCert(t *testing.T) {
11661166
token = "evaGxfADs6pSRb2LAv9IZf17Dt3juxGJ-PCt92wr-oA"
11671167
keyAuth = "evaGxfADs6pSRb2LAv9IZf17Dt3juxGJ-PCt92wr-oA." + testKeyECThumbprint
11681168
// echo -n <token.testKeyECThumbprint> | shasum -a 256
1169-
h = "dbbd5eefe7b4d06eb9d1d9f5acb4c7cda27d320e4b30332f0b6cb441734ad7b0"
1169+
h = "0420dbbd5eefe7b4d06eb9d1d9f5acb4c7cda27d320e4b30332f0b6cb441734ad7b0"
11701170
domain = "example.com"
11711171
)
11721172

0 commit comments

Comments
 (0)