Fix certificate relabel issue (#385)
* Fix certificate relabel issue * Address review comments * Pull in changes from master * More merge changes from master * Update copyright year * Updated change log. Attempting to get WhiteSource scan run successfully
This commit is contained in:
committed by
GitHub Enterprise
parent
c8d13e36e6
commit
26195d1bd9
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
© Copyright IBM Corporation 2018, 2022
|
||||
© Copyright IBM Corporation 2018, 2023
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -182,8 +182,8 @@ func (ks *KeyStore) GetCertificateLabels() ([]string, error) {
|
||||
var labels []string
|
||||
for scanner.Scan() {
|
||||
s := scanner.Text()
|
||||
if strings.HasPrefix(s, "-") || strings.HasPrefix(s, "*-") || strings.HasPrefix(s, "!") {
|
||||
s := strings.TrimLeft(s, "-*!")
|
||||
if strings.HasPrefix(s, "-") || strings.HasPrefix(s, "*-") {
|
||||
s := strings.TrimLeft(s, "-*")
|
||||
labels = append(labels, strings.TrimSpace(s))
|
||||
}
|
||||
}
|
||||
@@ -226,6 +226,8 @@ func (ks *KeyStore) ListAllCertificates() ([]string, error) {
|
||||
var labels []string
|
||||
for scanner.Scan() {
|
||||
s := scanner.Text()
|
||||
// Check for trusted certficates as well here as this method can
|
||||
// be called for trusted store as well.
|
||||
if strings.HasPrefix(s, "-") || strings.HasPrefix(s, "*-") || strings.HasPrefix(s, "!") {
|
||||
s := strings.TrimLeft(s, "-*!")
|
||||
labels = append(labels, strings.TrimSpace(s))
|
||||
|
||||
@@ -255,6 +255,13 @@ func processKeys(tlsStore *TLSStore, keystoreDir string, keyDir string) (string,
|
||||
return "", err
|
||||
}
|
||||
|
||||
// Validate certificates for duplicate Subject DNs
|
||||
if len(caCertificate) > 0 {
|
||||
errCertValid := validateCertificates(publicCertificate, caCertificate)
|
||||
if errCertValid != nil {
|
||||
return "", errCertValid
|
||||
}
|
||||
}
|
||||
// Create a new PKCS#12 Keystore - containing private key, public certificate & optional CA certificate
|
||||
file, err := pkcs.Encode(rand.Reader, privateKey, publicCertificate, caCertificate, tlsStore.Keystore.Password)
|
||||
if err != nil {
|
||||
@@ -647,3 +654,19 @@ func haveKeysAndCerts(keyDir string) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Iterate through the certificates to ensure there are no two certificates with same Subject DN.
|
||||
// GSKit does not allow two certificates with same Subject DN/Friendly Names
|
||||
func validateCertificates(personalCert *x509.Certificate, caCertificates []*x509.Certificate) error {
|
||||
// Check if we have been asked to override certificate validation by setting
|
||||
// MQ_ENABLE_CERT_VALIDATION to false
|
||||
enableValidation, enableValidationSet := os.LookupEnv("MQ_ENABLE_CERT_VALIDATION")
|
||||
if !enableValidationSet || (enableValidationSet && !strings.EqualFold(strings.Trim(enableValidation, ""), "false")) {
|
||||
for _, caCert := range caCertificates {
|
||||
if strings.EqualFold(personalCert.Subject.String(), caCert.Subject.String()) {
|
||||
return fmt.Errorf("Error: The Subject DN of the Issuer Certificate and the Queue Manager are same")
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user