diff --git a/internal/certdb/validation.go b/internal/certdb/validation.go index edf4bc7..be4e525 100644 --- a/internal/certdb/validation.go +++ b/internal/certdb/validation.go @@ -65,7 +65,7 @@ func ValidateCertificate(cert string) error { for i, firstCert := range certificates[:len(certificates)-1] { secondCert := certificates[i+1] if !secondCert.IsCA { - return fmt.Errorf("invalid certificate chain: certificate %d is not a certificate authority", i) + return fmt.Errorf("invalid certificate chain: certificate %d is not a certificate authority", i+1) } if !bytes.Equal(firstCert.RawIssuer, secondCert.RawSubject) { return fmt.Errorf("invalid certificate chain: certificate %d, certificate %d: subjects do not match", i, i+1) diff --git a/internal/certdb/validation_test.go b/internal/certdb/validation_test.go index d02c8e9..8abf1ff 100644 --- a/internal/certdb/validation_test.go +++ b/internal/certdb/validation_test.go @@ -91,6 +91,33 @@ Pp7ObjaWxjCT3O6nEH3w6Ozsyg2cHXQIdVXLvNnV1bxUbPnfhQosKGKgU6s+lcLM SRhHB2k= -----END CERTIFICATE----- ` + StrawberryCert string = `-----BEGIN CERTIFICATE----- +MIIEUjCCAjoCFE8lmuBE85/RPw2M17Kzl93O+9IJMA0GCSqGSIb3DQEBCwUAMGEx +CzAJBgNVBAYTAlRSMQ4wDAYDVQQIDAVJem1pcjESMBAGA1UEBwwJTmFybGlkZXJl +MSEwHwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQxCzAJBgNVBAMMAm1l +MB4XDTI0MDYyODA4NDIzN1oXDTI1MDYyODA4NDIzN1owajELMAkGA1UEBhMCSVQx +DzANBgNVBAgMBlBhZG92YTEOMAwGA1UEBwwFUGFkdWExITAfBgNVBAoMGEludGVy +bmV0IFdpZGdpdHMgUHR5IEx0ZDEXMBUGA1UEAwwOc3RyYXdiZXJyeS5jb20wggEi +MA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDXXHpy+3LLRCImyEQitM9eUdgY +kexLz2PcAf89tTpkpt3L1woJw0bv+YR80UcR2Pg+7uUVm4XSKFvcdyWg8yADH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tzvrckATlycRVfwwDQYJKoZIhvcNAQEL @@ -266,6 +293,8 @@ func TestCertValidationFail(t *testing.T) { var issuerCertPKDoesNotMatchErr = "invalid certificate chain: certificate 0, certificate 1: keys do not match" var issuerCertSubjectDoesNotMatch = fmt.Sprintf("%s\n%s", BananaCert, WrongSubjectIssuerCert) var issuerCertSubjectDoesNotMatchErr = "invalid certificate chain: certificate 0, certificate 1: subjects do not match" + var issuerCertNotCA = fmt.Sprintf("%s\n%s", BananaCert, StrawberryCert) + var issuerCertNotCaErr = "invalid certificate chain: certificate 1 is not a certificate authority" cases := []struct { inputCert string @@ -295,6 +324,10 @@ func TestCertValidationFail(t *testing.T) { inputCert: issuerCertSubjectDoesNotMatch, expectedErr: issuerCertSubjectDoesNotMatchErr, }, + { + inputCert: issuerCertNotCA, + expectedErr: issuerCertNotCaErr, + }, } for i, c := range cases { diff --git a/ui/src/app/certificate_requests/components.tsx b/ui/src/app/certificate_requests/components.tsx index 25c6005..3e94b68 100644 --- a/ui/src/app/certificate_requests/components.tsx +++ b/ui/src/app/certificate_requests/components.tsx @@ -46,9 +46,9 @@ function SubmitCertificate({ existingCSRText, existingCertText, certText, onClic setValidationErrorText("Certificate does not match request") return } - let a = await validateBundle(certText) - if (await validateBundle(certText)) { - setValidationErrorText("Bundle validation failed: " + a) + let validationMessage = await validateBundle(certText) + if (validationMessage != "") { + setValidationErrorText("Bundle validation failed: " + validationMessage) return } } diff --git a/ui/src/app/utils.ts b/ui/src/app/utils.ts index 51b2b4d..9b128ee 100644 --- a/ui/src/app/utils.ts +++ b/ui/src/app/utils.ts @@ -295,6 +295,5 @@ export const validateBundle = async (bundle: string) => { trustedCerts: [rootCa] }) const result = await chainEngine.verify() - console.log(result) return result.resultMessage } \ No newline at end of file