@@ -5097,6 +5097,74 @@ func Test_deviceAttest01Validate(t *testing.T) {
50975097 }
50985098}
50995099
5100+ func Test_doAndroidKeyAttestionFormat_noAttestationRoots (t * testing.T ) {
5101+ // This test exercises the fallback path when no attestation roots
5102+ // are configured (the !attOk branch), verifying that:
5103+ // 1. The ECDSA root parsing and type assertion works correctly
5104+ // 2. Non-Google roots are properly rejected
5105+ ca , err := minica .New ()
5106+ require .NoError (t , err )
5107+
5108+ signer , err := ecdsa .GenerateKey (elliptic .P256 (), rand .Reader )
5109+ require .NoError (t , err )
5110+
5111+ jwk , keyAuth := mustAccountAndKeyAuthorization (t , "token" )
5112+ keyAuthSum := sha256 .Sum256 ([]byte (keyAuth ))
5113+ sig , err := signer .Sign (rand .Reader , keyAuthSum [:], crypto .SHA256 )
5114+ require .NoError (t , err )
5115+
5116+ atts := attestation.KeyDescription {
5117+ AttestationVersion : 300 ,
5118+ AttestationSecurityLevel : 1 ,
5119+ AttestationChallenge : sig ,
5120+ TeeEnforced : attestation.AuthorizationList {
5121+ AttestationIdSerial : []byte ("serial-number" ),
5122+ },
5123+ }
5124+ attestByte , err := attestation .CreateKeyDescription (& atts )
5125+ require .NoError (t , err )
5126+
5127+ leaf , err := ca .Sign (& x509.Certificate {
5128+ Subject : pkix.Name {CommonName : "attestation cert" },
5129+ PublicKey : signer .Public (),
5130+ ExtraExtensions : []pkix.Extension {
5131+ {Id : oidAndroidAttestation , Value : attestByte },
5132+ },
5133+ })
5134+ require .NoError (t , err )
5135+
5136+ att := & attestationObject {
5137+ Format : "android-key" ,
5138+ AttStatement : map [string ]any {
5139+ "x5c" : []any {leaf .Raw , ca .Intermediate .Raw , ca .Root .Raw },
5140+ },
5141+ }
5142+
5143+ // Create provisioner without attestation roots
5144+ prov := & provisioner.ACME {
5145+ Type : "ACME" ,
5146+ Name : "acme" ,
5147+ Challenges : []provisioner.ACMEChallenge {provisioner .DEVICE_ATTEST_01 },
5148+ }
5149+ require .NoError (t , prov .Init (provisioner.Config {
5150+ Claims : config .GlobalProvisionerClaims ,
5151+ }))
5152+
5153+ ch := & Challenge {
5154+ ID : "chID" ,
5155+ Token : "nonce" ,
5156+ Type : "device-attest-01" ,
5157+ Value : "serial-number" ,
5158+ }
5159+
5160+ _ , err = doAndroidKeyAttestionFormat (context .Background (), prov , ch , jwk , att )
5161+ require .Error (t , err )
5162+
5163+ var acmeErr * Error
5164+ require .ErrorAs (t , err , & acmeErr )
5165+ assert .Contains (t , acmeErr .Error (), "root certificate not signed by Google" )
5166+ }
5167+
51005168var (
51015169 oidTPMManufacturer = asn1.ObjectIdentifier {2 , 23 , 133 , 2 , 1 }
51025170 oidTPMModel = asn1.ObjectIdentifier {2 , 23 , 133 , 2 , 2 }
0 commit comments