Closed AlexandruCiobanu closed 7 months ago
Hi Alex,
KeyNotFoundException
- it is some GeneralSecurityException
...
hth@Override
public PrivateKey getPrivateKey(@Nullable X509Certificate aCert) throws AS2Exception {
debugLog ( () -> "getPrivateKey (" + _debug (aCert) + ")");
String sRealAlias = null;
m_aRWLock.readLock ().lock ();
PrivateKey aKey = null;
try {
String[] aliases = Collections.list(getKeyStore().aliases ()).toArray(new String[]{});
for(int i = 0; i < aliases.length; i++) {
// This method heuristically scans the keystore and delivers the first result.
final String sAlias = aliases[i];
if(!getKeyStore().getCertificate(sAlias).equals(aCert)){
continue;
}
sRealAlias = getUnifiedAlias(sAlias);
// Find the key - is null if the alias represents a Public Certificate
aKey = (PrivateKey) getKeyStore().getKey(sRealAlias, getPassword());
if (aKey == null) {
continue;
}
break;
}
if (aKey == null) {
debugLog(() -> "getPrivateKey -> null");
throw new AS2KeyNotFoundException(aCert, sRealAlias, _getAllAliases(), null);
}
PrivateKey finalAKey = aKey;
debugLog(() -> "getPrivateKey -> " + finalAKey);
return aKey;
}
catch (final GeneralSecurityException ex) {
debugLog ( () -> "getPrivateKey -> " + _debug (ex));
throw new AS2KeyNotFoundException (aCert, sRealAlias, _getAllAliases (), ex);
}
finally
{
m_aRWLock.readLock ().unlock ();
}
}
Not the sexiest fix but it does the job. :)
I don't fully understand the consequences of your changes, so I need to take some time. Please be patient with me :)
Finally - I understand and I agree. Part of the 5.1.2 release
Hi Phillip,
I seem to have an issue when I try sending through peppol a message whose end client is myself. Seems that the same certificate gets added to the keystore after the smp lookup; this seems to cause a failure to locate the private key cos apparently it finds the public certificate alias and not the keypair. Is there anything I can do to solve it?