Skip to content

Commit dfd3205

Browse files
authored
Fix generated tls-alpn challenge cert for IP Identifier (#47)
For the "tls-alpn-01" challenge, the subjectAltName extension in the validation certificate MUST contain a single iPAddress that matches the address being validated. Reference: https://www.rfc-editor.org/rfc/rfc8738.html
1 parent f6b8d4a commit dfd3205

1 file changed

Lines changed: 24 additions & 5 deletions

File tree

tlsalpn01.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ import (
2424
"crypto/x509/pkix"
2525
"encoding/asn1"
2626
"encoding/pem"
27+
"fmt"
2728
"math/big"
29+
"net"
2830
"time"
2931

3032
"github.com/mholt/acmez/v3/acme"
@@ -34,10 +36,26 @@ import (
3436
// TLSALPN01ChallengeCert creates a certificate that can be used for
3537
// handshakes while solving the tls-alpn-01 challenge. See RFC 8737 §3.
3638
func TLSALPN01ChallengeCert(challenge acme.Challenge) (*tls.Certificate, error) {
37-
// certificates must encode their SANs as ASCII
38-
asciiIdentifier, err := idna.ToASCII(challenge.Identifier.Value)
39-
if err != nil {
40-
return nil, err
39+
dnsNames := []string{}
40+
ipAddresses := []net.IP{}
41+
42+
// https://www.iana.org/assignments/acme/acme.xhtml#acme-identifier-types
43+
switch challenge.Identifier.Type {
44+
case "dns":
45+
// certificates must encode their SANs as ASCII
46+
asciiIdentifier, err := idna.ToASCII(challenge.Identifier.Value)
47+
if err != nil {
48+
return nil, err
49+
}
50+
dnsNames = append(dnsNames, asciiIdentifier)
51+
case "ip":
52+
ipIdentifier := net.ParseIP(challenge.Identifier.Value)
53+
if ipIdentifier == nil {
54+
return nil, fmt.Errorf("invalid ip identifier: %s", challenge.Identifier.Value)
55+
}
56+
ipAddresses = append(ipAddresses, ipIdentifier)
57+
default:
58+
return nil, fmt.Errorf("unsupported identifier type: %s", challenge.Identifier.Type)
4159
}
4260

4361
keyAuthSum := sha256.Sum256([]byte(challenge.KeyAuthorization))
@@ -67,7 +85,8 @@ func TLSALPN01ChallengeCert(challenge acme.Challenge) (*tls.Certificate, error)
6785
NotAfter: time.Now().Add(24 * time.Hour * 365),
6886
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
6987
BasicConstraintsValid: true,
70-
DNSNames: []string{asciiIdentifier},
88+
DNSNames: dnsNames,
89+
IPAddresses: ipAddresses,
7190

7291
// add key authentication digest as the acmeValidation-v1 extension
7392
// (marked as critical such that it won't be used by non-ACME software).

0 commit comments

Comments
 (0)