Skip to content

Commit

Permalink
Handle password with empty string for certificate auth
Browse files Browse the repository at this point in the history
  • Loading branch information
timja committed Dec 7, 2024
1 parent f51f5d5 commit 3a1d390
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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();

Check warning on line 619 in src/main/java/com/cloudbees/plugins/credentials/impl/CertificateCredentialsImpl.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 619 is only partially covered, one branch is missing
try {
KeyStore keyStore = KeyStore.getInstance("PKCS12");
keyStore.load(new ByteArrayInputStream(keystoreBytes), passwordChars);
Expand Down Expand Up @@ -739,6 +739,9 @@ public FormValidation doCheckCertChain(@QueryParameter String value) {
List<PEMEncodable> pemEncodables = PEMEncodable.decodeAll(pemCerts, null);
long count = pemEncodables.stream().map(PEMEncodable::toCertificate).filter(Objects::nonNull).count();
if (count < 1) {
if (Util.fixEmpty(value) == null) {

Check warning on line 742 in src/main/java/com/cloudbees/plugins/credentials/impl/CertificateCredentialsImpl.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 742 is only partially covered, one branch is missing
return FormValidation.ok();
}
return FormValidation.error(Messages.CertificateCredentialsImpl_PEMNoCertificates());
}
// ensure only certs are provided.
Expand Down Expand Up @@ -771,6 +774,9 @@ public FormValidation doCheckPrivateKey(@QueryParameter String value,
List<PEMEncodable> 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) {

Check warning on line 777 in src/main/java/com/cloudbees/plugins/credentials/impl/CertificateCredentialsImpl.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 777 is only partially covered, one branch is missing
return FormValidation.ok();
}
return FormValidation.error(Messages.CertificateCredentialsImpl_PEMNoKeys());
}
if (count > 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3a1d390

Please sign in to comment.