mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-11-02 18:26:43 +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,23 +132,29 @@ 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());
|
||||
}
|
||||
}
|
||||
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) {
|
||||
log.warn("Error loading user key rings: " + e.getMessage());
|
||||
}
|
||||
|
@ -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