mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-26 00:02:06 +01:00
OpenPgpManager: Expose methods to generate and import keys
This commit is contained in:
parent
28dd56a13a
commit
1a9ac238e8
1 changed files with 20 additions and 8 deletions
|
@ -295,14 +295,9 @@ public final class OpenPgpManager extends Manager {
|
||||||
|
|
||||||
throwIfNoProviderSet();
|
throwIfNoProviderSet();
|
||||||
OpenPgpStore store = provider.getStore();
|
OpenPgpStore store = provider.getStore();
|
||||||
PGPKeyRing keys = store.generateKeyRing(ourJid);
|
|
||||||
try {
|
PGPKeyRing keys = generateKeyRing(ourJid);
|
||||||
store.importSecretKey(ourJid, keys.getSecretKeys());
|
importKeyRing(ourJid, keys);
|
||||||
store.importPublicKey(ourJid, keys.getPublicKeys());
|
|
||||||
} catch (MissingUserIdOnKeyException e) {
|
|
||||||
// This should never throw, since we set our jid literally one line above this comment.
|
|
||||||
throw new AssertionError(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
OpenPgpV4Fingerprint fingerprint = new OpenPgpV4Fingerprint(keys.getSecretKeys());
|
OpenPgpV4Fingerprint fingerprint = new OpenPgpV4Fingerprint(keys.getSecretKeys());
|
||||||
|
|
||||||
|
@ -311,6 +306,23 @@ public final class OpenPgpManager extends Manager {
|
||||||
return fingerprint;
|
return fingerprint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PGPKeyRing generateKeyRing(BareJid ourJid)
|
||||||
|
throws PGPException, NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException {
|
||||||
|
throwIfNoProviderSet();
|
||||||
|
PGPKeyRing keys = provider.getStore().generateKeyRing(ourJid);
|
||||||
|
return keys;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void importKeyRing(BareJid ourJid, PGPKeyRing keyRing) throws IOException, PGPException {
|
||||||
|
try {
|
||||||
|
provider.getStore().importSecretKey(ourJid, keyRing.getSecretKeys());
|
||||||
|
provider.getStore().importPublicKey(ourJid, keyRing.getPublicKeys());
|
||||||
|
} catch (MissingUserIdOnKeyException e) {
|
||||||
|
// This should never throw, since we set our jid literally one line above this comment.
|
||||||
|
throw new AssertionError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the upper-case hex encoded OpenPGP v4 fingerprint of our key pair.
|
* Return the upper-case hex encoded OpenPGP v4 fingerprint of our key pair.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue