Skip to content

Commit

Permalink
localize FormValidation messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jtnord committed Jul 8, 2024
1 parent 9552a40 commit edbec02
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,13 @@ public FormValidation doCheckPassword(@QueryParameter String value) {
Secret s = Secret.fromString(value);
String pw = s.getPlainText();
if (FIPS140.useCompliantAlgorithms() && pw.length() < 14) {
return FormValidation.error("password is too short (< 14 characters)");
return FormValidation.error(Messages.CertificateCredentialsImpl_ShortPasswordFIPS());
}
if (pw.isEmpty()) {
return FormValidation.warning("password is empty");
return FormValidation.warning(Messages.CertificateCredentialsImpl_NoPassword());
}
if (pw.length() < 14) {
return FormValidation.warning("password is short (< 14 characters)");
return FormValidation.warning(Messages.CertificateCredentialsImpl_ShortPassword());
}
return FormValidation.ok();
}
Expand Down Expand Up @@ -749,11 +749,11 @@ 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) {
return FormValidation.error("No Certificates provided");
return FormValidation.error(Messages.CertificateCredentialsImpl_PEMNoCertificates());
}
// ensure only certs are provided.
if (pemEncodables.size() != count) {
return FormValidation.error("PEM contains non certificate entries");
return FormValidation.error(Messages.CertificateCredentialsImpl_PEMNoCertificates());
}
Certificate cert = pemEncodables.get(0).toCertificate();
if (cert instanceof X509Certificate) {
Expand All @@ -765,9 +765,9 @@ public FormValidation doCheckCertChain(@QueryParameter String value) {
} catch (UnrecoverableKeyException | IOException e) {
String message = e.getMessage();
if (message != null) {
return FormValidation.error(e, "Could not parse certificate chain: " + message);
return FormValidation.error(e, Messages.CertificateCredentialsImpl_PEMCertificateParsingError(message));
}
return FormValidation.error(e, "Could not parse certificate chain");
return FormValidation.error(e, Messages.CertificateCredentialsImpl_PEMCertificateParsingError("unkown reason"));
}
}

Expand All @@ -781,14 +781,14 @@ 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) {
return FormValidation.error("No Keys Provided");
return FormValidation.error(Messages.CertificateCredentialsImpl_PEMNoKeys());
}
if (count > 1) {
return FormValidation.error("More than 1 key provided");
return FormValidation.error(Messages.CertificateCredentialsImpl_PEMMultipleKeys());
}
// ensure only keys are provided.
if (pemEncodables.size() != 1) {
return FormValidation.error("PEM contains non key entries");
return FormValidation.error(Messages.CertificateCredentialsImpl_PEMNonKeys());
}
PrivateKey pk = pemEncodables.get(0).toPrivateKey();
String format;
Expand All @@ -810,7 +810,7 @@ public FormValidation doCheckPrivateKey(@QueryParameter String value,
// the size of pemEncodables is one and contains a private key
// so it can not be
format = "unknown format (" + pk.getClass() +")";
length = "unknown length";
length = "unknown strength";
} else { // pk == null can not happen
return FormValidation.error("there is a bug in the code, pk is null!");
}
Expand All @@ -819,9 +819,9 @@ public FormValidation doCheckPrivateKey(@QueryParameter String value,
} catch (@SuppressWarnings("unused") DestroyFailedException ignored) {
// best effort
}
return FormValidation.ok(length + " " + format + " private key");
return FormValidation.ok(Messages.CertificateCredentialsImpl_PEMKeyInfo(length, format));
} catch (UnrecoverableKeyException | IOException e) {
return FormValidation.error(e, "Could not parse key: " + e.getLocalizedMessage());
return FormValidation.error(e, Messages.CertificateCredentialsImpl_PEMKeyParseError(e.getLocalizedMessage()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,15 @@ CertificateCredentialsImpl.UploadedKeyStoreSourceDisplayName=Upload PKCS#12 cert
CertificateCredentialsImpl.PEMEntryKeyStoreSourceDisplayName=PEM encoded certificate and key
CertificateCredentialsImpl.PEMNoCertificates=No certificates where provided
CertificateCredentialsImpl.PEMNoKey=No key was provided
CertificateCredentialsImpl.PEMNoPassword=No password was provided
CertificateCredentialsImpl.PEMNoPassword=No password was provided
CertificateCredentialsImpl.ShortPassword=Password is short (< 14 characters)
CertificateCredentialsImpl.ShortPasswordFIPS=Password is too short (< 14 characters)
CertificateCredentialsImpl.NoPassword=Password is empty
CertificateCredentialsImpl.PEMNoCertificate=No Certificates provided
CertificateCredentialsImpl.PEMNonCertificates=PEM contains non certificate entries
CertificateCredentialsImpl.PEMCertificateParsingError=Could not parse certificate chain: {0}
CertificateCredentialsImpl.PEMNoKeys=No Keys Provided
CertificateCredentialsImpl.PEMMultipleKeys=More than 1 key provided
CertificateCredentialsImpl.PEMNonKeys=PEM contains non key entries
CertificateCredentialsImpl.PEMKeyInfo={0} {1} private key
CertificateCredentialsImpl.PEMKeyParseError=Could not parse key: {0}

0 comments on commit edbec02

Please sign in to comment.