|
@@ -11,8 +11,8 @@ import (
|
|
"time"
|
|
"time"
|
|
)
|
|
)
|
|
|
|
|
|
-func GenerateCertificate(timeFunc func() time.Time, serverName string) (*tls.Certificate, error) {
|
|
|
|
- privateKeyPem, publicKeyPem, err := GenerateKeyPair(timeFunc, serverName, timeFunc().Add(time.Hour))
|
|
|
|
|
|
+func GenerateKeyPair(parent *x509.Certificate, parentKey any, timeFunc func() time.Time, serverName string) (*tls.Certificate, error) {
|
|
|
|
+ privateKeyPem, publicKeyPem, err := GenerateCertificate(parent, parentKey, timeFunc, serverName, timeFunc().Add(time.Hour))
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
@@ -23,7 +23,7 @@ func GenerateCertificate(timeFunc func() time.Time, serverName string) (*tls.Cer
|
|
return &certificate, err
|
|
return &certificate, err
|
|
}
|
|
}
|
|
|
|
|
|
-func GenerateKeyPair(timeFunc func() time.Time, serverName string, expire time.Time) (privateKeyPem []byte, publicKeyPem []byte, err error) {
|
|
|
|
|
|
+func GenerateCertificate(parent *x509.Certificate, parentKey any, timeFunc func() time.Time, serverName string, expire time.Time) (privateKeyPem []byte, publicKeyPem []byte, err error) {
|
|
if timeFunc == nil {
|
|
if timeFunc == nil {
|
|
timeFunc = time.Now
|
|
timeFunc = time.Now
|
|
}
|
|
}
|
|
@@ -47,7 +47,11 @@ func GenerateKeyPair(timeFunc func() time.Time, serverName string, expire time.T
|
|
},
|
|
},
|
|
DNSNames: []string{serverName},
|
|
DNSNames: []string{serverName},
|
|
}
|
|
}
|
|
- publicDer, err := x509.CreateCertificate(rand.Reader, template, template, key.Public(), key)
|
|
|
|
|
|
+ if parent == nil {
|
|
|
|
+ parent = template
|
|
|
|
+ parentKey = key
|
|
|
|
+ }
|
|
|
|
+ publicDer, err := x509.CreateCertificate(rand.Reader, template, parent, key.Public(), parentKey)
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
}
|
|
}
|