-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Go crypto library for versions < 1.15 is not filling in the SKI field for CAs [1] this PR replicate the golang >= 1.15 fix [2] [1] golang/go#26676 [2] https://go-review.googlesource.com/c/go/+/227098/ Signed-off-by: Quique Llorente <ellorent@redhat.com>
- Loading branch information
Showing
3 changed files
with
77 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package triple | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
"github.com/onsi/ginkgo/reporters" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestTriple(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
junitReporter := reporters.NewJUnitReporter("junit.triple_suite_test.xml") | ||
RunSpecsWithDefaultAndCustomReporters(t, "Certificate Test Suite", []Reporter{junitReporter}) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package triple | ||
|
||
import ( | ||
"crypto/x509" | ||
"time" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Cert library", func() { | ||
Context("when NewCA is called", func() { | ||
var ( | ||
name string | ||
duration time.Duration | ||
now time.Time | ||
) | ||
BeforeEach(func() { | ||
now = time.Now() | ||
name = "foo-bar-name" | ||
duration = time.Minute | ||
Now = func() time.Time { return now } | ||
}) | ||
It("should generate key and CA cert with expected fields", func() { | ||
|
||
keyAndCert, err := NewCA(name, duration) | ||
Expect(err).ToNot(HaveOccurred(), "should succeed generating CA") | ||
|
||
privateKey := keyAndCert.Key | ||
caCert := keyAndCert.Cert | ||
|
||
Expect(privateKey).ToNot(BeNil(), "should generate a private key") | ||
Expect(caCert).ToNot(BeNil(), "should generate a CA certificate") | ||
Expect(caCert.SerialNumber.Int64()).To(Equal(int64(0)), "should have zero as serial number") | ||
Expect(caCert.Subject.CommonName).To(Equal(name), "should take CommonName from name field") | ||
Expect(caCert.NotBefore).To(BeTemporally("~", now.UTC(), time.Second), "should set NotBefore to now") | ||
Expect(caCert.NotAfter).To(BeTemporally("~", now.Add(duration).UTC(), time.Second), "should set NotAfter to now + duration") | ||
Expect(caCert.KeyUsage).To(Equal(x509.KeyUsageKeyEncipherment|x509.KeyUsageDigitalSignature|x509.KeyUsageCertSign), "should set proper KeyUsage") | ||
Expect(caCert.BasicConstraintsValid).To(BeTrue(), "should mark it as BasicConstraintsValid") | ||
Expect(caCert.IsCA).To(BeTrue(), "should mark it as CA") | ||
Expect(caCert.SubjectKeyId).ToNot(BeEmpty(), "should include a SKI") | ||
}) | ||
|
||
}) | ||
}) |