Skip to content

Commit 1e25424

Browse files
common-security: add workaround bouncycastle EC algorithm name mismatch
Motivation: ----------- commit 8de5c6f that tried to address "EC" vs "ECDSA" name mismatch. However the patch was insufficient and we ran into failure to start dCache when cert/key issued for dCache host used EC encryption algorithm Modification: ------------ "EC" and "ECDSA" are both used for elliptic-curve keys depending on provider and BouncyCastle version — treat them as equivalent. Result: ------- dCache starts normally w/ EC encrypted key/certs Target: trunk Request: 12.0, 11.2
1 parent 19b5372 commit 1e25424

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

modules/common-security/src/main/java/org/dcache/ssl/CanlContextFactory.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -400,13 +400,19 @@ public KeyAndCertCredential0(PrivateKey privateKey, X509Certificate[] certificat
400400
}
401401

402402
PublicKey pubKey = certificateChain[0].getPublicKey();
403-
String pubKeyAlgorithm = pubKey.getAlgorithm();
404-
// REVISIT: BouncyCastle uses "ECDSA" as the private key algorithm and "EC" as the public key algorithm names for elliptic curve keys.
405-
if (!privateKey.getAlgorithm().equals(pubKeyAlgorithm) && !(privateKey.getAlgorithm().equals("ECDSA") && pubKeyAlgorithm.equals("EC")))
403+
String pubAlg = pubKey.getAlgorithm();
404+
String privAlg = privateKey.getAlgorithm();
405+
// "EC" and "ECDSA" are both used for elliptic-curve keys depending on the
406+
// provider and BouncyCastle version — treat them as equivalent.
407+
boolean privIsEC = privAlg.equals("EC") || privAlg.equals("ECDSA");
408+
boolean pubIsEC = pubAlg.equals("EC") || pubAlg.equals("ECDSA");
409+
410+
if (!privAlg.equals(pubAlg) && !(privIsEC && pubIsEC)) {
406411
throw new KeyStoreException("Private and public keys are not matching: different algorithms: "
407-
+ privateKey.getAlgorithm() + " vs. " + pubKeyAlgorithm);
412+
+ privAlg + " vs. " + pubAlg);
413+
}
408414

409-
switch (pubKeyAlgorithm) {
415+
switch (pubAlg) {
410416
case "DSA":
411417
if (!checkKeysViaSignature("SHA1withDSA", privateKey, pubKey))
412418
throw new KeyStoreException("Private and public keys are not matching: DSA");
@@ -425,8 +431,12 @@ public KeyAndCertCredential0(PrivateKey privateKey, X509Certificate[] certificat
425431
if (!checkKeysViaSignature("GOST3411withECGOST3410", privateKey, pubKey))
426432
throw new KeyStoreException("Private and public keys are not matching: EC GOST 34.10");
427433
break;
434+
case "EC":
435+
if (!checkKeysViaSignature("SHA256withECDSA", privateKey, pubKey))
436+
throw new KeyStoreException("Private and public keys are not matching: EC DSA");
437+
break;
428438
case "ECDSA":
429-
if (!checkKeysViaSignature("SHA1withECDSA", privateKey, pubKey))
439+
if (!checkKeysViaSignature("SHA256withECDSA", privateKey, pubKey))
430440
throw new KeyStoreException("Private and public keys are not matching: EC DSA");
431441
break;
432442
}

0 commit comments

Comments
 (0)