@@ -10,6 +10,7 @@ import (
10
10
"crypto/x509"
11
11
"crypto/x509/pkix"
12
12
"encoding/asn1"
13
+ "encoding/hex"
13
14
"encoding/json"
14
15
"encoding/pem"
15
16
"errors"
@@ -77,6 +78,27 @@ func randomDomain() string {
77
78
return fmt .Sprintf ("%x.example.com" , bytes [:])
78
79
}
79
80
81
+ // randomIPv6 creates a random IPv6 netip.Addr for testing. It uses a real IPv6
82
+ // address range, not a test/documentation range.
83
+ //
84
+ // panics if crypto/rand.Rand.Read or netip.AddrFromSlice fails.
85
+ func randomIPv6 () netip.Addr {
86
+ var ipBytes [10 ]byte
87
+ _ , err := rand .Read (ipBytes [:])
88
+ if err != nil {
89
+ panic (err )
90
+ }
91
+ ipPrefix , err := hex .DecodeString ("2602080a600f" )
92
+ if err != nil {
93
+ panic (err )
94
+ }
95
+ ip , ok := netip .AddrFromSlice (bytes .Join ([][]byte {ipPrefix , ipBytes [:]}, nil ))
96
+ if ! ok {
97
+ panic ("Couldn't parse random IP to netip.Addr" )
98
+ }
99
+ return ip
100
+ }
101
+
80
102
func createPendingAuthorization (t * testing.T , sa sapb.StorageAuthorityClient , ident identifier.ACMEIdentifier , exp time.Time ) * corepb.Authorization {
81
103
t .Helper ()
82
104
@@ -354,6 +376,7 @@ func initAuthorities(t *testing.T) (*DummyValidationAuthority, sapb.StorageAutho
354
376
validAuthzLifetime : 300 * 24 * time .Hour ,
355
377
orderLifetime : 7 * 24 * time .Hour ,
356
378
maxNames : 100 ,
379
+ identifierTypes : []identifier.IdentifierType {identifier .TypeDNS },
357
380
}},
358
381
}
359
382
@@ -1801,12 +1824,14 @@ func TestNewOrder_ValidationProfiles(t *testing.T) {
1801
1824
validAuthzLifetime : 1 * 24 * time .Hour ,
1802
1825
orderLifetime : 1 * 24 * time .Hour ,
1803
1826
maxNames : 10 ,
1827
+ identifierTypes : []identifier.IdentifierType {identifier .TypeDNS },
1804
1828
},
1805
1829
"two" : {
1806
1830
pendingAuthzLifetime : 2 * 24 * time .Hour ,
1807
1831
validAuthzLifetime : 2 * 24 * time .Hour ,
1808
1832
orderLifetime : 2 * 24 * time .Hour ,
1809
1833
maxNames : 10 ,
1834
+ identifierTypes : []identifier.IdentifierType {identifier .TypeDNS },
1810
1835
},
1811
1836
},
1812
1837
}
@@ -1900,6 +1925,7 @@ func TestNewOrder_ProfileSelectionAllowList(t *testing.T) {
1900
1925
for _ , tc := range testCases {
1901
1926
t .Run (tc .name , func (t * testing.T ) {
1902
1927
tc .profile .maxNames = 1
1928
+ tc .profile .identifierTypes = []identifier.IdentifierType {identifier .TypeDNS }
1903
1929
ra .profiles .byName = map [string ]* validationProfile {
1904
1930
"test" : & tc .profile ,
1905
1931
}
@@ -1921,6 +1947,83 @@ func TestNewOrder_ProfileSelectionAllowList(t *testing.T) {
1921
1947
}
1922
1948
}
1923
1949
1950
+ func TestNewOrder_ProfileIdentifierTypes (t * testing.T ) {
1951
+ _ , _ , ra , _ , _ , cleanUp := initAuthorities (t )
1952
+ defer cleanUp ()
1953
+
1954
+ testCases := []struct {
1955
+ name string
1956
+ identTypes []identifier.IdentifierType
1957
+ idents []* corepb.Identifier
1958
+ expectErr string
1959
+ }{
1960
+ {
1961
+ name : "Permit DNS, provide DNS names" ,
1962
+ identTypes : []identifier.IdentifierType {identifier .TypeDNS },
1963
+ idents : []* corepb.Identifier {identifier .NewDNS (randomDomain ()).ToProto (), identifier .NewDNS (randomDomain ()).ToProto ()},
1964
+ },
1965
+ {
1966
+ name : "Permit IP, provide IPs" ,
1967
+ identTypes : []identifier.IdentifierType {identifier .TypeIP },
1968
+ idents : []* corepb.Identifier {identifier .NewIP (randomIPv6 ()).ToProto (), identifier .NewIP (randomIPv6 ()).ToProto ()},
1969
+ },
1970
+ {
1971
+ name : "Permit DNS & IP, provide DNS & IP" ,
1972
+ identTypes : []identifier.IdentifierType {identifier .TypeDNS , identifier .TypeIP },
1973
+ idents : []* corepb.Identifier {identifier .NewIP (randomIPv6 ()).ToProto (), identifier .NewDNS (randomDomain ()).ToProto ()},
1974
+ },
1975
+ {
1976
+ name : "Permit DNS, provide IP" ,
1977
+ identTypes : []identifier.IdentifierType {identifier .TypeDNS },
1978
+ idents : []* corepb.Identifier {identifier .NewIP (randomIPv6 ()).ToProto ()},
1979
+ expectErr : "Profile \" test\" does not permit ip type identifiers" ,
1980
+ },
1981
+ {
1982
+ name : "Permit DNS, provide DNS & IP" ,
1983
+ identTypes : []identifier.IdentifierType {identifier .TypeDNS },
1984
+ idents : []* corepb.Identifier {identifier .NewDNS (randomDomain ()).ToProto (), identifier .NewIP (randomIPv6 ()).ToProto ()},
1985
+ expectErr : "Profile \" test\" does not permit ip type identifiers" ,
1986
+ },
1987
+ {
1988
+ name : "Permit IP, provide DNS" ,
1989
+ identTypes : []identifier.IdentifierType {identifier .TypeIP },
1990
+ idents : []* corepb.Identifier {identifier .NewDNS (randomDomain ()).ToProto ()},
1991
+ expectErr : "Profile \" test\" does not permit dns type identifiers" ,
1992
+ },
1993
+ {
1994
+ name : "Permit IP, provide DNS & IP" ,
1995
+ identTypes : []identifier.IdentifierType {identifier .TypeIP },
1996
+ idents : []* corepb.Identifier {identifier .NewIP (randomIPv6 ()).ToProto (), identifier .NewDNS (randomDomain ()).ToProto ()},
1997
+ expectErr : "Profile \" test\" does not permit dns type identifiers" ,
1998
+ },
1999
+ }
2000
+
2001
+ for _ , tc := range testCases {
2002
+ t .Run (tc .name , func (t * testing.T ) {
2003
+ var profile validationProfile
2004
+ profile .maxNames = 2
2005
+ profile .identifierTypes = tc .identTypes
2006
+ ra .profiles .byName = map [string ]* validationProfile {
2007
+ "test" : & profile ,
2008
+ }
2009
+
2010
+ orderReq := & rapb.NewOrderRequest {
2011
+ RegistrationID : Registration .Id ,
2012
+ Identifiers : tc .idents ,
2013
+ CertificateProfileName : "test" ,
2014
+ }
2015
+ _ , err := ra .NewOrder (context .Background (), orderReq )
2016
+
2017
+ if tc .expectErr != "" {
2018
+ test .AssertErrorIs (t , err , berrors .RejectedIdentifier )
2019
+ test .AssertContains (t , err .Error (), tc .expectErr )
2020
+ } else {
2021
+ test .AssertNotError (t , err , "NewOrder failed" )
2022
+ }
2023
+ })
2024
+ }
2025
+ }
2026
+
1924
2027
// mockSAWithAuthzs has a GetAuthorizations2 method that returns the protobuf
1925
2028
// version of its authzs struct member. It also has a fake GetOrderForNames
1926
2029
// which always fails, and a fake NewOrderAndAuthzs which always succeeds, to
0 commit comments