@@ -71,14 +71,45 @@ func NewRSARootCA() (crypto.PrivateKey, *x509.Certificate, Pair, error) {
7171 return rootKey , cert , pair , err
7272}
7373
74- // GenerateChildCert generates a x509 Certificate as a child of caCert and
75- // returns the following:
76- // - the certificate in PEM format as a byte slice
77- // - the private key in PEM format as a byte slice
74+ // GenerateChildCert generates a ECDSA (P-384) x509 Certificate as a child of
75+ // caCert and returns the following:
7876// - the certificate and private key as a tls.Certificate
77+ // - a Pair with the certificate and its key im PEM format
7978//
8079// If any error occurs during the generation process, a non-nil error is returned.
81- func GenerateChildCert (
80+ func GenerateChildCert (name string , ips []net.IP , caPrivKey crypto.PrivateKey , caCert * x509.Certificate ) (* tls.Certificate , Pair , error ) {
81+ priv , err := rsa .GenerateKey (rand .Reader , 2048 )
82+ if err != nil {
83+ return nil , Pair {}, fmt .Errorf ("could not create RSA private key: %w" , err )
84+ }
85+
86+ cert , childPair , err :=
87+ GenerateGenericChildCert (
88+ name ,
89+ ips ,
90+ priv ,
91+ & priv .PublicKey ,
92+ caPrivKey ,
93+ caCert )
94+ if err != nil {
95+ return nil , Pair {}, fmt .Errorf (
96+ "could not generate child TLS certificate CA: %w" , err )
97+ }
98+
99+ return cert , childPair , nil
100+ }
101+
102+ // GenerateGenericChildCert generates a x509 Certificate using priv and pub
103+ // as the certificate's private and public keys and as a child of caCert.
104+ // Use this function if you need fine control over keys or ips and certificate name,
105+ // otherwise prefer GenerateChildCert or NewRootAndChildCerts/NewRSARootAndChildCerts
106+ //
107+ // It returns the following:
108+ // - the certificate and private key as a tls.Certificate
109+ // - a Pair with the certificate and its key im PEM format
110+ //
111+ // If any error occurs during the generation process, a non-nil error is returned.
112+ func GenerateGenericChildCert (
82113 name string ,
83114 ips []net.IP ,
84115 priv crypto.PrivateKey ,
@@ -263,7 +294,7 @@ func defaultChildCert(
263294 pub crypto.PublicKey ,
264295 rootCACert * x509.Certificate ) (Pair , error ) {
265296 _ , childPair , err :=
266- GenerateChildCert (
297+ GenerateGenericChildCert (
267298 "localhost" ,
268299 []net.IP {net .ParseIP ("127.0.0.1" )},
269300 priv ,
0 commit comments