You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
I'm cannot use legacy keys that have been generated without email.
To Reproduce
Try to use keys generated without Email, just Realname. in GPG shell works, in java throws no key suitable found.
Expected behavior
Find the Key by the RealName if email is not present.
Additional context
To resolve it in my project, I implemented this strategy:
publicclassByEmailKeyAndJustRealnameKeySelectionStrategyextendsRfc4880KeySelectionStrategy {
privatestaticfinalStringENTRE_BRACKETS = "<.*>";
/** * @param dateOfTimestampVerification The date used for key expiration date * checks as "now". */publicByEmailKeyAndJustRealnameKeySelectionStrategy() {
super(Instant.now(), true, true);
}
/** * Return all keyrings that ARE valid keys for the given uid. * * If the uid does not already include '<...>' then wrap it in * "<uid>" * to filter for e-mails. E.g. "[email protected]" will be converted to * "<[email protected]>" but "Klaus <[email protected]>" or * "<[email protected]>" will be left untouched. * If the uids does not match with email format; will be left untouched. * * @param uid the userid as passed by upstream. * @param keyringConfig the keyring config * @param purpose what is the requested key to be used for * * @return Set with keyrings, never null. * * @throws PGPException Something with BouncyCastle went wrong * @throws IOException IO is dangerous */@SuppressWarnings({ "PMD.LawOfDemeter" })
@OverrideprotectedSet<PGPPublicKeyRing> publicKeyRingsForUid(finalPURPOSEpurpose, finalStringuid,
KeyringConfigkeyringConfig)
throwsIOException, PGPException {
finalSet<PGPPublicKeyRing> keyringsForUid = newHashSet<>();
StringuidQuery = uid;
finalbooleanuidAlreadyInBrackets = uidAlreadyInBrackets(uid);
finalbooleanisValidEmail = JMail.isValid(uid);
if (!uidAlreadyInBrackets && isValidEmail) {
uidQuery = "<" + uid + ">";
}
finalIterator<PGPPublicKeyRing> keyRings = keyringConfig.getPublicKeyRings()
.getKeyRings(uidQuery, true, true);
while (keyRings.hasNext()) {
keyringsForUid.add(keyRings.next());
}
returnkeyringsForUid;
}
protectedbooleanuidAlreadyInBrackets(Stringuid){
returnuid.matches(ENTRE_BRACKETS);
}
I wondering if this make sense (is it correct) and if open an Issue/Merge worths. Any thoughts?
The text was updated successfully, but these errors were encountered:
Hello everyone,
Describe the bug
I'm cannot use legacy keys that have been generated without email.
To Reproduce
Try to use keys generated without Email, just Realname. in GPG shell works, in java throws no key suitable found.
Expected behavior
Find the Key by the RealName if email is not present.
Additional context
To resolve it in my project, I implemented this strategy:
I wondering if this make sense (is it correct) and if open an Issue/Merge worths. Any thoughts?
The text was updated successfully, but these errors were encountered: