Add method for creating in-memory certificates

This commit is contained in:
Ralf Haferkamp
2022-11-03 11:58:53 +01:00
committed by Ralf Haferkamp
parent a4f5682851
commit cbe41fb85f
2 changed files with 14 additions and 11 deletions
+12
View File
@@ -4,6 +4,7 @@ import (
"crypto/ecdsa"
"crypto/rand"
"crypto/rsa"
"crypto/tls"
"crypto/x509"
"encoding/pem"
"fmt"
@@ -12,6 +13,7 @@ import (
"path/filepath"
"github.com/owncloud/ocis/v2/ocis-pkg/log"
mtls "go-micro.dev/v4/util/tls"
)
var (
@@ -50,6 +52,16 @@ func GenCert(certName string, keyName string, l log.Logger) error {
return nil
}
// GenTempCertForAddr generates temporary TLS-Certificates in memory.
func GenTempCertForAddr(addr string) (tls.Certificate, error) {
subjects := defaultHosts
if host, _, err := net.SplitHostPort(addr); err == nil && host != "" {
subjects = []string{host}
}
return mtls.Certificate(subjects...)
}
// persistCertificate generates a certificate using pk as private key and proceeds to store it into a file named certName.
func persistCertificate(certName string, l log.Logger, pk interface{}) error {
if err := ensureExistsDir(certName); err != nil {