Closed izstas closed 2 years ago
It worked using this method, will it be correct? @kaikramer
@jgrateron Yes, that fixes the issue.
The actual problem is that one PublicKey object was created by BouncyCastle and is of type BCECPublicKey
and the other one was created by the Java runtime and is of type ECPublicKeyImpl
. And the equals method of BCECPublicKey
is not correctly implemented:
public boolean equals(Object o)
{
if (!(o instanceof BCECPublicKey))
{
return false;
}
BCECPublicKey other = (BCECPublicKey)o;
return ecPublicKey.getQ().equals(other.ecPublicKey.getQ()) && (engineGetSpec().equals(other.engineGetSpec()));
}
It should check for instanceof ECPublicKey
instead. They have done it right in BCRSAPublicKey
, that is why this error only happens with EC keys.
I'll report this bug to the Bouncy Castle project.
And BTW just changing the order would fix the problem as well:
if (!exitingEntryCerts[0].getPublicKey().equals(certs[0].getPublicKey())) {
->
if (!certs[0].getPublicKey().equals(exitingEntryCerts[0].getPublicKey())) {
Because then the equals method of ECPublicKeyImpl
would be used, which is implemented correctly.
Perfect much better, you have to do it equally in ImportCaReplyFromClipboardAction
Yep, same issue in ImportCaReplyFromClipboardAction and there might be other code locations with similar problems. I would really prefer this to be fixed in BC.
I have created a ticket: https://github.com/bcgit/bc-java/issues/1083
Describe the bug Import CA Reply always fails for EC keys on KSE 5.5.0.
Below are the simplest steps to reproduce I could find, of course, the bug also occurs when you're importing an actual new certificate instead of the one you just exported.
To Reproduce
Actual behavior The import fails with "The public key of the CA Reply does not match the public key of the key pair entry".
Expected behavior The import succeeds.
Environment