mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-12-25 17:46:44 +00:00
match gpg behaviour for loading user public keyrings
This commit is contained in:
parent
9656603930
commit
f455d94a01
1 changed files with 14 additions and 25 deletions
|
@ -132,21 +132,27 @@ public class PGPUtils {
|
|||
return null;
|
||||
}
|
||||
|
||||
private static PGPPublicKeyRingCollection getUserKeyRingCollection() throws IOException {
|
||||
private static PGPPublicKeyRingCollection getUserKeyRingCollection() {
|
||||
try {
|
||||
File gnupgPubRing = getGnuPGPubRing();
|
||||
if(gnupgPubRing != null) {
|
||||
if(gnupgPubRing.getName().equals(PUBRING_GPG)) {
|
||||
return PGPainless.readKeyRing().publicKeyRingCollection(new FileInputStream(gnupgPubRing));
|
||||
} else if(gnupgPubRing.getName().equals(PUBRING_KBX)) {
|
||||
BcKeyBox bcKeyBox = new BcKeyBox(new FileInputStream(gnupgPubRing));
|
||||
File gnupgHome = getGnuPGHome();
|
||||
if(gnupgHome.exists()) {
|
||||
File kbxPubRing = new File(gnupgHome, PUBRING_KBX);
|
||||
if(kbxPubRing.exists()) {
|
||||
BcKeyBox bcKeyBox = new BcKeyBox(new FileInputStream(kbxPubRing));
|
||||
List<PGPPublicKeyRing> rings = new ArrayList<>();
|
||||
for(KeyBlob keyBlob : bcKeyBox.getKeyBlobs()) {
|
||||
if(keyBlob instanceof PublicKeyRingBlob publicKeyRingBlob) {
|
||||
rings.add(publicKeyRingBlob.getPGPPublicKeyRing());
|
||||
}
|
||||
}
|
||||
return new PGPPublicKeyRingCollection(rings);
|
||||
if(!rings.isEmpty()) {
|
||||
return new PGPPublicKeyRingCollection(rings);
|
||||
}
|
||||
}
|
||||
|
||||
File gpgPubRing = new File(gnupgHome, PUBRING_GPG);
|
||||
if(gpgPubRing.exists()) {
|
||||
return PGPainless.readKeyRing().publicKeyRingCollection(new FileInputStream(gpgPubRing));
|
||||
}
|
||||
}
|
||||
} catch(Exception e) {
|
||||
|
@ -156,23 +162,6 @@ public class PGPUtils {
|
|||
return null;
|
||||
}
|
||||
|
||||
private static File getGnuPGPubRing() {
|
||||
File gnupgHome = getGnuPGHome();
|
||||
if(gnupgHome.exists()) {
|
||||
File gpgPubRing = new File(gnupgHome, PUBRING_GPG);
|
||||
if(gpgPubRing.exists()) {
|
||||
return gpgPubRing;
|
||||
}
|
||||
|
||||
File kbxPubRing = new File(gnupgHome, PUBRING_KBX);
|
||||
if(kbxPubRing.exists()) {
|
||||
return kbxPubRing;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static File getGnuPGHome() {
|
||||
String gnupgHome = System.getenv("GNUPGHOME");
|
||||
if(gnupgHome != null && !gnupgHome.isEmpty()) {
|
||||
|
|
Loading…
Reference in a new issue