Simplified IdentityRootAction.getFingerprint
package jenkins.model.identity;
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.Extension;
import hudson.model.UnprotectedRootAction;
import java.nio.charset.StandardCharsets;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
import java.security.interfaces.RSAPublicKey;
import java.util.Base64;
+import org.jenkinsci.remoting.util.KeyUtils;
/**
* A simple root action that exposes the public key to users so that they do not need to search for the
@@ -62,34 +60,8 @@ public class IdentityRootAction implements UnprotectedRootAction {
*
* @return the fingerprint of the public key.
*/
- @SuppressFBWarnings(value = "WEAK_MESSAGE_DIGEST_MD5", justification = "Not used for security. ")
public String getFingerprint() {
- RSAPublicKey key = InstanceIdentityProvider.RSA.getPublicKey();
- if (key == null) {
- return null;
- }
- // TODO replace with org.jenkinsci.remoting.util.KeyUtils once JENKINS-36871 changes are merged
- try {
- MessageDigest digest = getMd5();
- digest.reset();
- byte[] bytes = digest.digest(key.getEncoded());
- StringBuilder result = new StringBuilder(Math.max(0, bytes.length * 3 - 1));
- for (int i = 0; i < bytes.length; i++) {
- if (i > 0) {
- result.append(':');
- }
- int b = bytes[i] & 0xFF;
- result.append(Character.forDigit((b>>4)&0x0f, 16)).append(Character.forDigit(b&0xf, 16));
- }
- return result.toString();
- } catch (NoSuchAlgorithmException e) {
- throw new IllegalStateException("JLS mandates MD5 support");
- }
+ return KeyUtils.fingerprint(InstanceIdentityProvider.RSA.getPublicKey());
}
- // TODO JENKINS-60563 remove MD5 from all usages in Jenkins
- @SuppressFBWarnings(value = "WEAK_MESSAGE_DIGEST_MD5", justification = "Not used for security. ")
- private MessageDigest getMd5() throws NoSuchAlgorithmException {
- return MessageDigest.getInstance("MD5");
- }
}
