mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-16 01:12:05 +01:00
Fix animalsniffer bugs!
This commit is contained in:
parent
b615ef74b0
commit
5134463883
2 changed files with 11 additions and 3 deletions
|
@ -76,10 +76,18 @@ public class DecryptionBuilder implements DecryptionBuilderInterface {
|
||||||
public HandleMissingPublicKeys verifyWith(@Nonnull Set<OpenPgpV4Fingerprint> trustedKeyIds,
|
public HandleMissingPublicKeys verifyWith(@Nonnull Set<OpenPgpV4Fingerprint> trustedKeyIds,
|
||||||
@Nonnull PGPPublicKeyRingCollection publicKeyRingCollection) {
|
@Nonnull PGPPublicKeyRingCollection publicKeyRingCollection) {
|
||||||
Set<PGPPublicKeyRing> publicKeyRings = keyRingCollectionToSet(publicKeyRingCollection);
|
Set<PGPPublicKeyRing> publicKeyRings = keyRingCollectionToSet(publicKeyRingCollection);
|
||||||
publicKeyRings.removeIf(p -> !trustedKeyIds.contains(new OpenPgpV4Fingerprint(p)));
|
removeUntrustedPublicKeys(publicKeyRings, trustedKeyIds);
|
||||||
return verifyWith(publicKeyRings);
|
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) {
|
private Set<PGPPublicKeyRing> keyRingCollectionToSet(PGPPublicKeyRingCollection publicKeyRingCollection) {
|
||||||
Set<PGPPublicKeyRing> publicKeyRings = new HashSet<>();
|
Set<PGPPublicKeyRing> publicKeyRings = new HashSet<>();
|
||||||
for (Iterator<PGPPublicKeyRing> i = publicKeyRingCollection.getKeyRings(); i.hasNext(); ) {
|
for (Iterator<PGPPublicKeyRing> i = publicKeyRingCollection.getKeyRings(); i.hasNext(); ) {
|
||||||
|
|
|
@ -49,7 +49,7 @@ public class OpenPgpV4Fingerprint implements CharSequence, Comparable<OpenPgpV4F
|
||||||
}
|
}
|
||||||
|
|
||||||
public OpenPgpV4Fingerprint(@Nonnull byte[] bytes) {
|
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) {
|
public OpenPgpV4Fingerprint(@Nonnull PGPPublicKey key) {
|
||||||
|
@ -88,7 +88,7 @@ public class OpenPgpV4Fingerprint implements CharSequence, Comparable<OpenPgpV4F
|
||||||
* @return key id
|
* @return key id
|
||||||
*/
|
*/
|
||||||
public long getKeyId() {
|
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);
|
ByteBuffer buf = ByteBuffer.wrap(bytes);
|
||||||
buf.position(12);
|
buf.position(12);
|
||||||
return buf.getLong();
|
return buf.getLong();
|
||||||
|
|
Loading…
Reference in a new issue