-
Notifications
You must be signed in to change notification settings - Fork 245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle password with empty string for certificate auth #581
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -147,12 +147,10 @@ | |
* Helper to convert a {@link Secret} password into a {@code char[]} | ||
* | ||
* @param password the password. | ||
* @return a {@code char[]} containing the password or {@code null} | ||
* @return a {@code char[]} containing the password | ||
*/ | ||
@CheckForNull | ||
private static char[] toCharArray(@NonNull Secret password) { | ||
String plainText = Util.fixEmpty(password.getPlainText()); | ||
return plainText == null ? null : plainText.toCharArray(); | ||
return password.getPlainText().toCharArray(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Empty string is used at least commonly in Azure if not elsewhere for PFX files. Shouldn't modify what the user has passed here |
||
} | ||
|
||
/** | ||
|
@@ -248,7 +246,7 @@ | |
return FormValidation.error(Messages.CertificateCredentialsImpl_ShortPasswordFIPS()); | ||
} | ||
if (pw.isEmpty()) { | ||
return FormValidation.warning(Messages.CertificateCredentialsImpl_NoPassword()); | ||
return FormValidation.ok(Messages.CertificateCredentialsImpl_NoPassword()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
if (pw.length() < 14) { | ||
return FormValidation.warning(Messages.CertificateCredentialsImpl_ShortPassword()); | ||
|
@@ -624,9 +622,7 @@ | |
} catch (KeyStoreException | CertificateException | NoSuchAlgorithmException | IOException e) { | ||
return FormValidation.warning(e, Messages.CertificateCredentialsImpl_LoadKeystoreFailed()); | ||
} finally { | ||
if (passwordChars != null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no longer possible to be null here |
||
Arrays.fill(passwordChars, ' '); | ||
} | ||
Arrays.fill(passwordChars, ' '); | ||
} | ||
} | ||
|
||
|
@@ -739,6 +735,9 @@ | |
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would agree if Jenkins did not allow you to hit "Save" or Apply when the form was in an invalid state or otherwise called out mandatory parameters from optional ones, but it does neither. Hitting save leads to an angry Jenkins which is IMO a worse UX that the error.
|
||
return FormValidation.ok(); | ||
} | ||
return FormValidation.error(Messages.CertificateCredentialsImpl_PEMNoCertificates()); | ||
} | ||
// ensure only certs are provided. | ||
|
@@ -771,6 +770,9 @@ | |
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
return FormValidation.ok(); | ||
} | ||
return FormValidation.error(Messages.CertificateCredentialsImpl_PEMNoKeys()); | ||
} | ||
if (count > 1) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
Comment on lines
-27
to
-28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these error messages made no sense before |
||
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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a difference between no password and an empty password.
It seems like Azure is using the empty password rather than no password (why I have no idea).
https://stackoverflow.com/a/53523999 appears to confirm this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure looks like other systems try both empty string and null