-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract all subjects from SANs for x509 verifier (#1632)
* Extract all subjects from SANs for x509 verifier Validation is also handled during certificate creation, so the contents of the x509 cert should follow rfc5280. Signed-off-by: Hayden Blauzvern <[email protected]> * fix lint Signed-off-by: Hayden Blauzvern <[email protected]> --------- Signed-off-by: Hayden Blauzvern <[email protected]>
- Loading branch information
1 parent
ea666c7
commit 08ea39a
Showing
2 changed files
with
11 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ import ( | |
"crypto/ed25519" | ||
"crypto/rsa" | ||
"crypto/x509" | ||
"net" | ||
"net/url" | ||
"reflect" | ||
"strings" | ||
|
@@ -249,8 +250,9 @@ func TestSignature_VerifyFail(t *testing.T) { | |
func TestPublicKeyWithCertChain(t *testing.T) { | ||
rootCert, rootKey, _ := testutils.GenerateRootCa() | ||
subCert, subKey, _ := testutils.GenerateSubordinateCa(rootCert, rootKey) | ||
url, _ := url.Parse("https://github.com/slsa-framework/slsa-github-generator/.github/workflows/builder_go_slsa3.yml@refs/tags/v1.1.1") | ||
leafCert, leafKey, _ := testutils.GenerateLeafCert("[email protected]", "oidc-issuer", url, subCert, subKey) | ||
subjectURL, _ := url.Parse("https://github.com/slsa-framework/slsa-github-generator/.github/workflows/builder_go_slsa3.yml@refs/tags/v1.1.1") | ||
leafCert, leafKey, _ := testutils.GenerateLeafCertWithSubjectAlternateNames( | ||
[]string{"example.com"}, []string{"[email protected]"}, []net.IP{{1, 1, 1, 1}}, []*url.URL{subjectURL}, "oidc-issuer", subCert, subKey) | ||
leafCertPEM, _ := cryptoutils.MarshalCertificateToPEM(leafCert) | ||
|
||
pemCertChain, err := cryptoutils.MarshalCertificatesToPEM([]*x509.Certificate{leafCert, subCert, rootCert}) | ||
|
@@ -274,7 +276,10 @@ func TestPublicKeyWithCertChain(t *testing.T) { | |
t.Fatalf("expected matching subjects, expected %v, got %v", leafCert.EmailAddresses, pub.EmailAddresses()) | ||
} | ||
|
||
expectedSubjects := leafCert.EmailAddresses | ||
var expectedSubjects []string | ||
expectedSubjects = append(expectedSubjects, leafCert.DNSNames...) | ||
expectedSubjects = append(expectedSubjects, leafCert.EmailAddresses...) | ||
expectedSubjects = append(expectedSubjects, leafCert.IPAddresses[0].String()) | ||
expectedSubjects = append(expectedSubjects, leafCert.URIs[0].String()) | ||
if !reflect.DeepEqual(pub.Subjects(), expectedSubjects) { | ||
t.Fatalf("expected matching subjects, expected %v, got %v", expectedSubjects, pub.Subjects()) | ||
|