diff --git a/src/main/java/com/cloudbees/plugins/credentials/impl/CertificateCredentialsImpl.java b/src/main/java/com/cloudbees/plugins/credentials/impl/CertificateCredentialsImpl.java index 34e7ccb0..603ae36c 100644 --- a/src/main/java/com/cloudbees/plugins/credentials/impl/CertificateCredentialsImpl.java +++ b/src/main/java/com/cloudbees/plugins/credentials/impl/CertificateCredentialsImpl.java @@ -248,7 +248,7 @@ public FormValidation doCheckPassword(@QueryParameter String value) { return FormValidation.error(Messages.CertificateCredentialsImpl_ShortPasswordFIPS()); } if (pw.isEmpty()) { - return FormValidation.warning(Messages.CertificateCredentialsImpl_NoPassword()); + return FormValidation.ok(Messages.CertificateCredentialsImpl_NoPassword()); } if (pw.length() < 14) { return FormValidation.warning(Messages.CertificateCredentialsImpl_ShortPassword()); @@ -616,7 +616,7 @@ protected static FormValidation validateCertificateKeystore(byte[] keystoreBytes return FormValidation.warning(Messages.CertificateCredentialsImpl_LoadKeystoreFailed()); } - char[] passwordChars = toCharArray(Secret.fromString(password)); + char[] passwordChars = password == null ? null : password.toCharArray(); try { KeyStore keyStore = KeyStore.getInstance("PKCS12"); keyStore.load(new ByteArrayInputStream(keystoreBytes), passwordChars); @@ -739,6 +739,9 @@ public FormValidation doCheckCertChain(@QueryParameter String value) { List pemEncodables = PEMEncodable.decodeAll(pemCerts, null); long count = pemEncodables.stream().map(PEMEncodable::toCertificate).filter(Objects::nonNull).count(); if (count < 1) { + if (Util.fixEmpty(value) == null) { + return FormValidation.ok(); + } return FormValidation.error(Messages.CertificateCredentialsImpl_PEMNoCertificates()); } // ensure only certs are provided. @@ -771,6 +774,9 @@ public FormValidation doCheckPrivateKey(@QueryParameter String value, List pemEncodables = PEMEncodable.decodeAll(key, toCharArray(Secret.fromString(password))); long count = pemEncodables.stream().map(PEMEncodable::toPrivateKey).filter(Objects::nonNull).count(); if (count == 0) { + if (Util.fixEmpty(value) == null) { + return FormValidation.ok(); + } return FormValidation.error(Messages.CertificateCredentialsImpl_PEMNoKeys()); } if (count > 1) { diff --git a/src/main/resources/com/cloudbees/plugins/credentials/impl/Messages.properties b/src/main/resources/com/cloudbees/plugins/credentials/impl/Messages.properties index 90ab3277..e3898abb 100644 --- a/src/main/resources/com/cloudbees/plugins/credentials/impl/Messages.properties +++ b/src/main/resources/com/cloudbees/plugins/credentials/impl/Messages.properties @@ -24,8 +24,8 @@ UsernamePasswordCredentialsImpl.DisplayName=Username with password CertificateCredentialsImpl.DisplayName=Certificate CertificateCredentialsImpl.EmptyKeystore=Empty keystore -CertificateCredentialsImpl.LoadKeyFailed=Could retrieve key "{0}" -CertificateCredentialsImpl.LoadKeyFailedQueryEmptyPassword=Could retrieve key "{0}". You may need to provide a password +CertificateCredentialsImpl.LoadKeyFailed=Couldn''t retrieve key for alias "{0}" +CertificateCredentialsImpl.LoadKeyFailedQueryEmptyPassword=Couldn''t retrieve key for alias "{0}". You may need to provide a password CertificateCredentialsImpl.LoadKeystoreFailed=Could not load keystore CertificateCredentialsImpl.NoCertificateUploaded=No certificate uploaded CertificateCredentialsImpl.UploadedKeyStoreSourceDisplayName=Upload PKCS#12 certificate and key