1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-22 20:32:05 +01:00

Fix animalsniffer bugs!

This commit is contained in:
Paul Schaub 2020-01-10 18:42:39 +01:00
parent b615ef74b0
commit 5134463883
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
2 changed files with 11 additions and 3 deletions

View file

@ -76,10 +76,18 @@ public class DecryptionBuilder implements DecryptionBuilderInterface {
public HandleMissingPublicKeys verifyWith(@Nonnull Set<OpenPgpV4Fingerprint> trustedKeyIds,
@Nonnull PGPPublicKeyRingCollection publicKeyRingCollection) {
Set<PGPPublicKeyRing> publicKeyRings = keyRingCollectionToSet(publicKeyRingCollection);
publicKeyRings.removeIf(p -> !trustedKeyIds.contains(new OpenPgpV4Fingerprint(p)));
removeUntrustedPublicKeys(publicKeyRings, trustedKeyIds);
return verifyWith(publicKeyRings);
}
private void removeUntrustedPublicKeys(Set<PGPPublicKeyRing> publicKeyRings, Set<OpenPgpV4Fingerprint> trustedKeyIds) {
for (PGPPublicKeyRing p : new HashSet<>(publicKeyRings)) {
if (!trustedKeyIds.contains(new OpenPgpV4Fingerprint(p))) {
publicKeyRings.remove(p);
}
}
}
private Set<PGPPublicKeyRing> keyRingCollectionToSet(PGPPublicKeyRingCollection publicKeyRingCollection) {
Set<PGPPublicKeyRing> publicKeyRings = new HashSet<>();
for (Iterator<PGPPublicKeyRing> i = publicKeyRingCollection.getKeyRings(); i.hasNext(); ) {

View file

@ -49,7 +49,7 @@ public class OpenPgpV4Fingerprint implements CharSequence, Comparable<OpenPgpV4F
}
public OpenPgpV4Fingerprint(@Nonnull byte[] bytes) {
this(new String(bytes, StandardCharsets.UTF_8));
this(new String(bytes, Charset.forName("UTF-8")));
}
public OpenPgpV4Fingerprint(@Nonnull PGPPublicKey key) {
@ -88,7 +88,7 @@ public class OpenPgpV4Fingerprint implements CharSequence, Comparable<OpenPgpV4F
* @return key id
*/
public long getKeyId() {
byte[] bytes = Hex.decode(toString().getBytes(StandardCharsets.UTF_8));
byte[] bytes = Hex.decode(toString().getBytes(Charset.forName("UTF-8")));
ByteBuffer buf = ByteBuffer.wrap(bytes);
buf.position(12);
return buf.getLong();