@@ -737,6 +737,93 @@ func TestTPMAttestationVerificationFailPubArea(t *testing.T) {
737737 }
738738}
739739
740+ func TestTPMAttestationVerificationRSAExponent (t * testing.T ) {
741+ _ , _ , _ , rsaKey , _ , err := getTPMAttestionKeys ()
742+ require .NoError (t , err )
743+
744+ testCases := []struct {
745+ name string
746+ exponent []byte
747+ pubAreaExponent uint32
748+ err string
749+ }{
750+ {
751+ "ShouldNotPanicWithSingleByteExponentMatchingPubArea" ,
752+ []byte {0x03 },
753+ 3 ,
754+ "unmarshalling field 1 of struct of type 'tpm2.TPMSAttest', EOF" ,
755+ },
756+ {
757+ "ShouldNotPanicWithSingleByteExponentMismatchingPubArea" ,
758+ []byte {0x03 },
759+ 65537 ,
760+ "Mismatch between RSAParameters in pubArea and credentialPublicKey" ,
761+ },
762+ {
763+ "ShouldNotPanicWithTwoByteExponentMatchingPubArea" ,
764+ []byte {0x01 , 0x00 },
765+ 256 ,
766+ "unmarshalling field 1 of struct of type 'tpm2.TPMSAttest', EOF" ,
767+ },
768+ {
769+ "ShouldNotPanicWithTwoByteExponentMismatchingPubArea" ,
770+ []byte {0x01 , 0x00 },
771+ 1 ,
772+ "Mismatch between RSAParameters in pubArea and credentialPublicKey" ,
773+ },
774+ {
775+ "ShouldDecodeThreeByteExponentAsBigEndian" ,
776+ []byte {0x01 , 0x00 , 0x01 },
777+ 65537 ,
778+ "unmarshalling field 1 of struct of type 'tpm2.TPMSAttest', EOF" ,
779+ },
780+ {
781+ "ShouldRejectExponentExceedingMaxUint32" ,
782+ []byte {0x01 , 0x00 , 0x00 , 0x00 , 0x00 },
783+ 65537 ,
784+ "Invalid RSA public key size" ,
785+ },
786+ }
787+
788+ for _ , tc := range testCases {
789+ t .Run (tc .name , func (t * testing.T ) {
790+ cpk , cerr := webauthncbor .Marshal (webauthncose.RSAPublicKeyData {
791+ PublicKeyData : webauthncose.PublicKeyData {
792+ KeyType : int64 (webauthncose .RSAKey ),
793+ Algorithm : int64 (webauthncose .AlgRS256 ),
794+ },
795+ Modulus : rsaKey .N .Bytes (),
796+ Exponent : tc .exponent ,
797+ })
798+ require .NoError (t , cerr )
799+
800+ attStmt := make (map [string ]any , len (defaultAttStatement ))
801+ for id , v := range defaultAttStatement {
802+ attStmt [id ] = v
803+ }
804+
805+ attStmt [stmtPubArea ] = tpm2 .Marshal (makeTPMTPublicRSA (& TPMRSATestParameters {Modulus : rsaKey .N .Bytes (), Exponent : tc .pubAreaExponent }))
806+
807+ att := AttestationObject {
808+ AttStatement : attStmt ,
809+ AuthData : AuthenticatorData {
810+ AttData : AttestedCredentialData {
811+ CredentialPublicKey : cpk ,
812+ },
813+ },
814+ }
815+
816+ require .NotPanics (t , func () {
817+ attestationType , x5cs , aerr := attestationFormatValidationHandlerTPM (att , nil , nil )
818+
819+ assert .Empty (t , attestationType )
820+ assert .Nil (t , x5cs )
821+ assert .EqualError (t , aerr , tc .err )
822+ })
823+ })
824+ }
825+ }
826+
740827func TestTPMAttestationVerificationFailCertInfo (t * testing.T ) {
741828 h := webauthncose .HasherFromCOSEAlg (webauthncose .AlgRS256 )
742829 extraData := h .Sum (nil )
0 commit comments