-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bugs in googleca and update flag description (#897)
* Fix bug in googleca and update flag description Signed-off-by: Priya Wadhwa <[email protected]> * Remove requirement for specifying certificateAuthority Signed-off-by: Priya Wadhwa <[email protected]> * Code review comments Signed-off-by: Priya Wadhwa <[email protected]> * Fix nit Signed-off-by: Priya Wadhwa <[email protected]> * Update variable names Signed-off-by: Priya Wadhwa <[email protected]> Signed-off-by: Priya Wadhwa <[email protected]>
- Loading branch information
1 parent
4da60f7
commit 865c05a
Showing
3 changed files
with
148 additions
and
14 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
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 |
---|---|---|
|
@@ -149,7 +149,82 @@ func TestReq(t *testing.T) { | |
}, | ||
} | ||
|
||
req, err := Req(parent, pubKeyBytes, cert) | ||
req, err := Req(parent, "", pubKeyBytes, cert) | ||
// We must copy over this field because we don't inject a clock, so | ||
// lifetime will always be different. | ||
expectedReq.Certificate.Lifetime = req.Certificate.Lifetime | ||
|
||
if err != nil { | ||
t.Fatalf("unexpected error, got: %v", err) | ||
} | ||
if !proto.Equal(req, expectedReq) { | ||
t.Fatalf("proto equality failed, expected: %v, got: %v", req, expectedReq) | ||
} | ||
} | ||
|
||
func TestReqCertAuthority(t *testing.T) { | ||
parent := "parent-ca" | ||
priv, err := rsa.GenerateKey(rand.Reader, 2048) | ||
failErr(t, err) | ||
|
||
uri := "sigstore.dev" | ||
parsedURI, err := url.Parse(uri) | ||
failErr(t, err) | ||
|
||
emailAddress := "[email protected]" | ||
notAfter := time.Now().Add(time.Minute * 10) | ||
pubKeyBytes, err := cryptoutils.MarshalPublicKeyToPEM(priv.Public()) | ||
failErr(t, err) | ||
ext := pkix.Extension{Id: asn1.ObjectIdentifier{1, 2, 3}, Value: []byte{1, 2, 3}} | ||
|
||
cert := &x509.Certificate{ | ||
NotAfter: notAfter, | ||
EmailAddresses: []string{emailAddress}, | ||
URIs: []*url.URL{parsedURI}, | ||
ExtraExtensions: []pkix.Extension{ext}, | ||
} | ||
|
||
expectedReq := &privatecapb.CreateCertificateRequest{ | ||
Parent: parent, | ||
IssuingCertificateAuthorityId: "cert-authority", | ||
Certificate: &privatecapb.Certificate{ | ||
CertificateConfig: &privatecapb.Certificate_Config{ | ||
Config: &privatecapb.CertificateConfig{ | ||
PublicKey: &privatecapb.PublicKey{ | ||
Format: privatecapb.PublicKey_PEM, | ||
Key: pubKeyBytes, | ||
}, | ||
X509Config: &privatecapb.X509Parameters{ | ||
KeyUsage: &privatecapb.KeyUsage{ | ||
BaseKeyUsage: &privatecapb.KeyUsage_KeyUsageOptions{ | ||
DigitalSignature: true, | ||
}, | ||
ExtendedKeyUsage: &privatecapb.KeyUsage_ExtendedKeyUsageOptions{ | ||
CodeSigning: true, | ||
}, | ||
}, | ||
AdditionalExtensions: []*privatecapb.X509Extension{ | ||
{ | ||
ObjectId: &privatecapb.ObjectId{ | ||
ObjectIdPath: convertID(ext.Id), | ||
}, | ||
Value: ext.Value, | ||
}, | ||
}, | ||
}, | ||
SubjectConfig: &privatecapb.CertificateConfig_SubjectConfig{ | ||
Subject: &privatecapb.Subject{}, | ||
SubjectAltName: &privatecapb.SubjectAltNames{ | ||
EmailAddresses: []string{emailAddress}, | ||
Uris: []string{uri}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
req, err := Req(parent, "cert-authority", pubKeyBytes, cert) | ||
// We must copy over this field because we don't inject a clock, so | ||
// lifetime will always be different. | ||
expectedReq.Certificate.Lifetime = req.Certificate.Lifetime | ||
|