Skip to content

Commit bdc0699

Browse files
authored
Merge pull request ibmruntimes#516 from dev-koan/fix_KeyAgreement
Add compatibility for a key from a different provider
2 parents 2575450 + 7fa34fe commit bdc0699

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

closed/src/jdk.crypto.ec/share/classes/sun/security/ec/NativeXDHKeyAgreement.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
/*
2727
* ===========================================================================
28-
* (c) Copyright IBM Corp. 2023, 2023 All Rights Reserved
28+
* (c) Copyright IBM Corp. 2023, 2025 All Rights Reserved
2929
* ===========================================================================
3030
*/
3131

@@ -159,7 +159,18 @@ protected Key engineDoPhase(Key key, boolean lastPhase)
159159
}
160160

161161
if (!(key instanceof XDHPublicKeyImpl)) {
162-
throw new InvalidKeyException("Unsupported key type");
162+
if (!(key instanceof XECPublicKey)) {
163+
throw new InvalidKeyException("Unsupported key type");
164+
}
165+
try {
166+
XDHKeyFactory kf = new XDHKeyFactory();
167+
key = kf.engineTranslateKey(key);
168+
} catch (Exception exception) {
169+
throw new InvalidKeyException("Unable to translate key", exception);
170+
}
171+
if (!(key instanceof XDHPublicKeyImpl)) {
172+
throw new InvalidKeyException("Unsupported key type");
173+
}
163174
}
164175

165176
XDHPublicKeyImpl publicKey = (XDHPublicKeyImpl) key;

0 commit comments

Comments
 (0)