@@ -25,6 +25,7 @@ import (
25
25
var (
26
26
issuerCert * x509.Certificate
27
27
issuerKey crypto.Signer
28
+ leafCsr * x509.CertificateRequest
28
29
leafCert * x509.Certificate
29
30
leafKey crypto.Signer
30
31
tlsCert * tls.Certificate
@@ -60,7 +61,7 @@ func TestMain(m *testing.M) {
60
61
if err != nil {
61
62
panic (err )
62
63
}
63
- leafCsr , err : = x509util .CreateCertificateRequest ("Leaf" , []string {"127.0.0.1" , "localhost" }, leafKey )
64
+ leafCsr , err = x509util .CreateCertificateRequest ("Leaf" , []string {"127.0.0.1" , "localhost" }, leafKey )
64
65
if err != nil {
65
66
panic (err )
66
67
}
@@ -97,18 +98,23 @@ func TestMain(m *testing.M) {
97
98
}
98
99
99
100
func testRenewFunc () (* tls.Certificate , * tls.Config , error ) {
100
- var err error
101
- leafCert .NotBefore = time .Now ()
102
- leafCert .NotAfter = leafCert .NotBefore .Add (time .Hour )
103
- leafCert .SerialNumber = leafCert .SerialNumber .Add (leafCert .SerialNumber , big .NewInt (1 ))
104
- leafCert , err = x509util .CreateCertificate (leafCert , issuerCert , leafKey .Public (), issuerKey )
101
+ cert , err := x509util .NewCertificate (leafCsr ,
102
+ x509util .WithTemplate (x509util .DefaultLeafTemplate , x509util .CreateTemplateData ("Leaf" , []string {"127.0.0.1" , "localhost" })))
103
+ if err != nil {
104
+ return nil , nil , err
105
+ }
106
+ template := cert .GetCertificate ()
107
+ template .NotBefore = time .Now ()
108
+ template .NotAfter = template .NotBefore .Add (time .Hour )
109
+ template .SerialNumber = big .NewInt (1 )
110
+ leaf , err := x509util .CreateCertificate (template , issuerCert , leafKey .Public (), issuerKey )
105
111
if err != nil {
106
112
return nil , nil , err
107
113
}
108
114
return & tls.Certificate {
109
115
Certificate : [][]byte {leafCert .Raw },
110
116
PrivateKey : leafKey ,
111
- Leaf : leafCert ,
117
+ Leaf : leaf ,
112
118
}, tlsConfig , nil
113
119
}
114
120
0 commit comments