Check xcerts.Manager is initialized before adding certificates (#673)
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
@@ -146,15 +147,14 @@ func startServer(ctx *cli.Context) error {
|
||||
SwaggerServerCACertificate := ctx.String("tls-ca")
|
||||
// load tls cert and key from swagger server tls-certificate and tls-key flags
|
||||
if swaggerServerCertificate != "" && swaggerServerCertificateKey != "" {
|
||||
if errAddCert := restapi.GlobalTLSCertsManager.AddCertificate(swaggerServerCertificate, swaggerServerCertificateKey); errAddCert == nil {
|
||||
if x509Certs, errParseCert := config.ParsePublicCertFile(swaggerServerCertificate); errParseCert == nil && len(x509Certs) > 0 {
|
||||
restapi.GlobalPublicCerts = append(restapi.GlobalPublicCerts, x509Certs[0])
|
||||
} else {
|
||||
log.Println(errParseCert)
|
||||
}
|
||||
} else {
|
||||
if errAddCert := certs.AddCertificate(context.Background(), restapi.GlobalTLSCertsManager, swaggerServerCertificate, swaggerServerCertificateKey); errAddCert != nil {
|
||||
log.Println(errAddCert)
|
||||
}
|
||||
if x509Certs, errParseCert := config.ParsePublicCertFile(swaggerServerCertificate); errParseCert == nil {
|
||||
if len(x509Certs) > 0 {
|
||||
restapi.GlobalPublicCerts = append(restapi.GlobalPublicCerts, x509Certs[0])
|
||||
}
|
||||
}
|
||||
}
|
||||
// load ca cert from swagger server tls-ca flag
|
||||
if SwaggerServerCACertificate != "" {
|
||||
|
||||
@@ -228,3 +228,14 @@ func GetAllCertificatesAndCAs() (*x509.CertPool, []*x509.Certificate, *xcerts.Ma
|
||||
logger.FatalIf(err, "Unable to load the TLS configuration")
|
||||
return GlobalRootCAs, globalPublicCerts, globalTLSCertsManager
|
||||
}
|
||||
|
||||
// AddCertificate check if Manager is initialized and then append a new certificate to it
|
||||
func AddCertificate(ctx context.Context, manager *xcerts.Manager, publicKey, privateKey string) (err error) {
|
||||
// If Cert Manager is not nil add more certificates
|
||||
if manager != nil {
|
||||
return manager.AddCertificate(publicKey, privateKey)
|
||||
}
|
||||
// Initialize cert manager
|
||||
manager, err = xcerts.NewManager(ctx, publicKey, privateKey, config.LoadX509KeyPair)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -557,9 +557,7 @@ const ViewBucket = ({
|
||||
setPolicyEdit(row);
|
||||
};
|
||||
|
||||
const PolicyActions = [
|
||||
{ type: "view", onClick: viewAction },
|
||||
];
|
||||
const PolicyActions = [{ type: "view", onClick: viewAction }];
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
|
||||
Reference in New Issue
Block a user