Checking Validity of all Certs in the chain [VAULT-2114] (#11883)

* Checking Validity of all Certs in the chain

* Addressing Comments for TLS cert validation

* Fixing tls_verification tests

* Fixing minor issue in tls_verification tests

* Addressing Comments, Rebasing with main

* Adding comment on top of a test
This commit is contained in:
hghaf099 2021-06-22 16:23:55 -04:00 committed by GitHub
parent 5483eba5fc
commit 658a4ea276
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 59 additions and 7 deletions

View File

@ -0,0 +1,52 @@
-----BEGIN PRIVATE KEY-----
MIIJRQIBADANBgkqhkiG9w0BAQEFAASCCS8wggkrAgEAAoICAQDtrZixHp89k9ga
lQNBWxIUlJpftmo55xCK5NqAhtuI81VaDOczA+0dV2ZmONlCykwzj2jHrBeJPZao
EYiCtoUH5VbTQjxczAzriB49yvs0rwg2DCmG+Uj1xusdBhx7rBZ7Es79LsQnRQVK
ezosZGfwVy1chqW7UeCR5PeMumjcWevZSfBADGWNvy9b7mi2kEMJFFd+BKrl29ms
+H6HGt8E0Vmx3SAkZIkTN3X3jzn57ly9IqzuTJp5AGXEQQE/9qLvOug+HMTIFObv
/aqevyxaakVQciALTM7yp/dOcnocMIYbApcsSMcH6+tEEHiICAOZSxiVbobwD5Ta
EACNOLeTYkedrlAEvsIR7NpTgbPJLYp/cxAsszKqe1EiWi1fMoFqghCXw9Jll13L
Fad3eqvBrBgLiUMQWjUqcTmb6NSiNfHziKgrCqPa9nv4tPqQISutP8OLjuKLz1js
qJsXbpkDchylS1g17Kkea3UDh4LEsh11/qsq0HBVvxwf929178IStJAqyYD0tW++
blX3XL6gDJ/pzOmSdTvQXeFi4KMU3fjuKlhJRi8Oq+4gycWj+ACqSieoN1hztbuX
UYx+/Gv1z2jKaoyaXlbQU0zvvCcvqRQ0mGWBp11UUdVaJSN65f4bi6/YR6Z3M+bA
HwG0LVfp48QpSVZdVWD44t+EV2+ivQIDAQABAoICAQCUOjeH/rkBBjs4GMa2870K
6MJ9/p2xDtHaTW+XyIMRnfAV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sJPp5aysggcWPkgjrVEOh7bdrhejcbauzGUotf/
uwI8csEjJ1PUzmojlO1dlZ2BjEKIkreTBx1hKgNi8VjpR+/2lGXAp4iAm7gpJrsk
mDnqmwBJ6gwRVrB9+8qmicpqNloopj43PeJTWrREUEcpdTpx2drIylAc/o71l3Cd
WBbQKYf3YXzmsthICWmCXL6U5Hv9quKXUs3hSAmPMay+sopulxFnNck+ppf759H8
xOLGonW/TvDl4gkmCzyFJcFxz77EF6N7hw==
-----END PRIVATE KEY-----

View File

@ -59,7 +59,6 @@ func ListenerChecks(ctx context.Context, listeners []listenerutil.Listener) ([]s
// Perform checks on the Client CA Cert
warnings, err = TLSClientCAFileCheck(l)
listenerWarnings, listenerErrors = outputError(ctx, warnings, listenerWarnings, err, listenerErrors, listenerID)
// TODO: Use listenerutil.TLSConfig to warn on incorrect protocol specified
// Alternatively, use tlsutil.SetupTLSConfig.
}
@ -221,10 +220,9 @@ func TLSErrorChecks(leafCerts, interCerts, rootCerts []*x509.Certificate) error
// and root certificates provided.
func TLSFileWarningChecks(leafCerts, interCerts, rootCerts []*x509.Certificate) ([]string, error) {
var warnings []string
// add a warning for when there are more than one leaf certs
if len(leafCerts) > 1 {
warnings = append(warnings, "leafCerts contains more than one cert.")
warnings = append(warnings, fmt.Sprintf("More than one leaf certificate detected. Please ensure that there is one unique leaf certificate being supplied to vault in the vault server config file."))
}
for _, c := range leafCerts {

View File

@ -193,7 +193,7 @@ func TestTLSMultiKeys(t *testing.T) {
}
}
// TestTLSMultiCerts verifies that a unique error message is thrown when a cert is specified twice.
// TestTLSCertAsKey verifies that a unique error message is thrown when a cert is specified twice.
func TestTLSCertAsKey(t *testing.T) {
listeners := []listenerutil.Listener{
{
@ -261,6 +261,7 @@ func TestTLSNoRoot(t *testing.T) {
},
}
_, errs := ListenerChecks(context.Background(), listeners)
if errs != nil {
t.Fatalf("server certificate without root certificate is insecure, but still valid")
}
@ -285,7 +286,7 @@ func TestTLSInvalidMinVersion(t *testing.T) {
}
_, errs := ListenerChecks(context.Background(), listeners)
if errs == nil || len(errs) != 1 {
t.Fatalf("TLS Config check on fake certificate should fail")
t.Fatalf("TLS Config check on invalid 'tls_min_version' should fail")
}
if !strings.Contains(errs[0].Error(), fmt.Errorf(minVersionError, "0").Error()) {
t.Fatalf("Bad error message: %s", errs[0])
@ -311,7 +312,7 @@ func TestTLSInvalidMaxVersion(t *testing.T) {
}
_, errs := ListenerChecks(context.Background(), listeners)
if errs == nil || len(errs) != 1 {
t.Fatalf("TLS Config check on fake certificate should fail")
t.Fatalf("TLS Config check on invalid 'tls_max_version' should fail")
}
if !strings.Contains(errs[0].Error(), fmt.Errorf(maxVersionError, "0").Error()) {
t.Fatalf("Bad error message: %s", errs[0])
@ -550,7 +551,8 @@ func TestTLSMultipleRootInClietCACert(t *testing.T) {
}
}
func TestTLSSelfSignedCert(t *testing.T) {
// TestTLSSelfSignedCerts tests invalid self-signed cert as TLSClientCAFile
func TestTLSSelfSignedCerts(t *testing.T) {
listeners := []listenerutil.Listener{
{
Config: &configutil.Listener{