Skip to content

Commit

Permalink
Add OIDEncryptionAlgorithmRSASHA256 to handled signature algorithms
Browse files Browse the repository at this point in the history
  • Loading branch information
hslatman committed Oct 23, 2023
1 parent 7ce6486 commit fe40e59
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ func getSignatureAlgorithm(digestEncryption, digest pkix.AlgorithmIdentifier) (x
switch {
case digest.Algorithm.Equal(OIDDigestAlgorithmSHA1):
return x509.SHA1WithRSA, nil
case digest.Algorithm.Equal(OIDDigestAlgorithmSHA256):
case digest.Algorithm.Equal(OIDDigestAlgorithmSHA256), digest.Algorithm.Equal(OIDEncryptionAlgorithmRSASHA256):
// TODO(hs): check that this is expected to work with the RSASHA256 one too; also add the others
return x509.SHA256WithRSA, nil
case digest.Algorithm.Equal(OIDDigestAlgorithmSHA384):
return x509.SHA384WithRSA, nil
Expand Down
19 changes: 19 additions & 0 deletions verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,3 +714,22 @@ func TestParseSignedOctetStringWithAppleAttestation(t *testing.T) {
t.Fatal("could not parse contained compound octet string content fully")
}
}

func TestAzureAttestationSignatureValidation(t *testing.T) {
// attested data from https://learn.microsoft.com/en-us/azure/virtual-machines/instance-metadata-service?tabs=linux#attested-data
b64 := `MIIEEgYJKoZIhvcNAQcCoIIEAzCCA/8CAQExDzANBgkqhkiG9w0BAQsFADCBugYJKoZIhvcNAQcBoIGsBIGpeyJub25jZSI6IjEyMzQ1NjY3NjYiLCJwbGFuIjp7Im5hbWUiOiIiLCJwcm9kdWN0IjoiIiwicHVibGlzaGVyIjoiIn0sInRpbWVTdGFtcCI6eyJjcmVhdGVkT24iOiIxMS8yMC8xOCAyMjowNzozOSAtMDAwMCIsImV4cGlyZXNPbiI6IjExLzIwLzE4IDIyOjA4OjI0IC0wMDAwIn0sInZtSWQiOiIifaCCAj8wggI7MIIBpKADAgECAhBn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:= base64.StdEncoding.DecodeString(b64)
if err != nil {
t.Errorf("failed decoding base64 attested data: %v", err)
}

p7, err := Parse(data)
if err != nil {
t.Fatal("failed parsing attested data", err)
}

err = p7.Verify()
if err != nil {
t.Fatal("failed verifying data", err)
}
}

0 comments on commit fe40e59

Please sign in to comment.