mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-24 04:52:05 +01:00
Set primary fingerprint on backup import
This commit is contained in:
parent
9566f5ae65
commit
d86f3ef2e1
1 changed files with 10 additions and 8 deletions
|
@ -385,15 +385,17 @@ public class PainlessOpenPgpProvider implements OpenPgpProvider {
|
||||||
@Override
|
@Override
|
||||||
public OpenPgpV4Fingerprint importSecretKey(BareJid owner, byte[] bytes)
|
public OpenPgpV4Fingerprint importSecretKey(BareJid owner, byte[] bytes)
|
||||||
throws MissingUserIdOnKeyException, SmackOpenPgpException, IOException {
|
throws MissingUserIdOnKeyException, SmackOpenPgpException, IOException {
|
||||||
PGPSecretKeyRing secretKeys;
|
PGPSecretKeyRing importSecretKeys;
|
||||||
try {
|
try {
|
||||||
secretKeys = new PGPSecretKeyRing(bytes, new BcKeyFingerprintCalculator());
|
importSecretKeys = new PGPSecretKeyRing(bytes, new BcKeyFingerprintCalculator());
|
||||||
} catch (PGPException | IOException e) {
|
} catch (PGPException | IOException e) {
|
||||||
throw new SmackOpenPgpException("Could not deserialize PGP secret key of " + owner.toString(), e);
|
throw new SmackOpenPgpException("Could not deserialize PGP secret key of " + owner.toString(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!new BareJidUserId.SecRingSelectionStrategy().accept(owner, secretKeys)) {
|
store.setPrimaryOpenPgpKeyPairFingerprint(getFingerprint(importSecretKeys.getPublicKey()));
|
||||||
throw new MissingUserIdOnKeyException(owner, secretKeys.getPublicKey().getKeyID());
|
|
||||||
|
if (!new BareJidUserId.SecRingSelectionStrategy().accept(owner, importSecretKeys)) {
|
||||||
|
throw new MissingUserIdOnKeyException(owner, importSecretKeys.getPublicKey().getKeyID());
|
||||||
}
|
}
|
||||||
|
|
||||||
PGPSecretKeyRingCollection secretKeyRings;
|
PGPSecretKeyRingCollection secretKeyRings;
|
||||||
|
@ -404,21 +406,21 @@ public class PainlessOpenPgpProvider implements OpenPgpProvider {
|
||||||
}
|
}
|
||||||
if (secretKeyRings == null) {
|
if (secretKeyRings == null) {
|
||||||
try {
|
try {
|
||||||
secretKeyRings = new PGPSecretKeyRingCollection(Collections.singleton(secretKeys));
|
secretKeyRings = new PGPSecretKeyRingCollection(Collections.singleton(importSecretKeys));
|
||||||
} catch (IOException | PGPException e) {
|
} catch (IOException | PGPException e) {
|
||||||
throw new SmackOpenPgpException("Could not create SecretKeyRingCollection from SecretKeyRing.", e);
|
throw new SmackOpenPgpException("Could not create SecretKeyRingCollection from SecretKeyRing.", e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
secretKeyRings = PGPSecretKeyRingCollection.addSecretKeyRing(secretKeyRings, secretKeys);
|
secretKeyRings = PGPSecretKeyRingCollection.addSecretKeyRing(secretKeyRings, importSecretKeys);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
LOGGER.log(Level.INFO, "Skip key " + Long.toHexString(secretKeys.getPublicKey().getKeyID()) +
|
LOGGER.log(Level.INFO, "Skip key " + Long.toHexString(importSecretKeys.getPublicKey().getKeyID()) +
|
||||||
" as it is already part of the key ring.");
|
" as it is already part of the key ring.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
getStore().storeSecretKeyRing(owner, secretKeyRings);
|
getStore().storeSecretKeyRing(owner, secretKeyRings);
|
||||||
|
|
||||||
PGPPublicKeyRing publicKeys = BCUtil.publicKeyRingFromSecretKeyRing(secretKeys);
|
PGPPublicKeyRing publicKeys = BCUtil.publicKeyRingFromSecretKeyRing(importSecretKeys);
|
||||||
importPublicKey(owner, publicKeys);
|
importPublicKey(owner, publicKeys);
|
||||||
|
|
||||||
return getFingerprint(publicKeys.getPublicKey());
|
return getFingerprint(publicKeys.getPublicKey());
|
||||||
|
|
Loading…
Reference in a new issue