-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #147 from sol-eng/trust-ca
Allow Administrators to optionally trust the CA in the provided SSL Certificate chain file
- Loading branch information
Showing
4 changed files
with
134 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package ssl | ||
|
||
import ( | ||
"crypto/x509" | ||
"encoding/pem" | ||
"fmt" | ||
"github.com/sol-eng/wbi/internal/config" | ||
"github.com/sol-eng/wbi/internal/system" | ||
) | ||
|
||
func TrustRootCertificate(rootCA *x509.Certificate, osType config.OperatingSystem) error { | ||
block := pem.Block{Type: "CERTIFICATE", Bytes: rootCA.Raw} | ||
var pemCert []string | ||
pemCert = append(pemCert, string(pem.EncodeToMemory(&block))) | ||
switch osType { | ||
case config.Ubuntu18, config.Ubuntu20, config.Ubuntu22: | ||
err := system.WriteStrings(pemCert, "/usr/local/share/ca-certificates/workbenchCA.crt", 0755) | ||
if err != nil { | ||
return fmt.Errorf("writing certificate to disk failed: %w", err) | ||
} | ||
err = system.RunCommand("update-ca-certificates", true, 1) | ||
if err != nil { | ||
return fmt.Errorf("running command to trust root certificate: %w", err) | ||
} | ||
case config.Redhat7, config.Redhat8, config.Redhat9: | ||
err := system.WriteStrings(pemCert, "/etc/pki/ca-trust/source/anchors/workbenchCA.crt", 0755) | ||
if err != nil { | ||
return fmt.Errorf("writing CA certificate to disk failed: %w", err) | ||
} | ||
err = system.RunCommand("update-ca-trust", true, 1) | ||
if err != nil { | ||
return fmt.Errorf("running command to trust root certificate: %w", err) | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters