Search in sources :

Example 1 with NoBackupFoundException

use of org.jivesoftware.smackx.ox.exception.NoBackupFoundException in project Smack by igniterealtime.

the class OpenPgpManager method restoreSecretKeyServerBackup.

/**
 * Fetch a secret key backup from the server and try to restore a selected secret key from it.
 *
 * @param codeCallback callback for prompting the user to provide the secret backup code.
 * @return fingerprint of the restored secret key
 *
 * @throws InterruptedException if the thread gets interrupted.
 * @throws PubSubException.NotALeafNodeException if the private node is not a {@link LeafNode}.
 * @throws XMPPException.XMPPErrorException in case of an XMPP protocol error.
 * @throws SmackException.NotConnectedException if we are not connected.
 * @throws SmackException.NoResponseException if the server doesn't respond.
 * @throws InvalidBackupCodeException if the user-provided backup code is invalid.
 * @throws SmackException.NotLoggedInException if we are not logged in
 * @throws IOException IO is dangerous
 * @throws MissingUserIdOnKeyException if the key that is to be imported is missing a user-id with our jid
 * @throws NoBackupFoundException if no secret key backup has been found
 * @throws PGPException in case the restored secret key is damaged.
 */
public OpenPgpV4Fingerprint restoreSecretKeyServerBackup(AskForBackupCodeCallback codeCallback) throws InterruptedException, PubSubException.NotALeafNodeException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException, InvalidBackupCodeException, SmackException.NotLoggedInException, IOException, MissingUserIdOnKeyException, NoBackupFoundException, PGPException {
    throwIfNoProviderSet();
    throwIfNotAuthenticated();
    SecretkeyElement backup = OpenPgpPubSubUtil.fetchSecretKey(pepManager);
    if (backup == null) {
        throw new NoBackupFoundException();
    }
    OpenPgpSecretKeyBackupPassphrase backupCode = codeCallback.askForBackupCode();
    PGPSecretKeyRing secretKeys = SecretKeyBackupHelper.restoreSecretKeyBackup(backup, backupCode);
    OpenPgpV4Fingerprint fingerprint = new OpenPgpV4Fingerprint(secretKeys);
    provider.getStore().importSecretKey(getJidOrThrow(), secretKeys);
    provider.getStore().importPublicKey(getJidOrThrow(), KeyRingUtils.publicKeyRingFrom(secretKeys));
    getOpenPgpSelf().trust(fingerprint);
    return new OpenPgpV4Fingerprint(secretKeys);
}
Also used : SecretkeyElement(org.jivesoftware.smackx.ox.element.SecretkeyElement) NoBackupFoundException(org.jivesoftware.smackx.ox.exception.NoBackupFoundException) OpenPgpV4Fingerprint(org.pgpainless.key.OpenPgpV4Fingerprint) PGPSecretKeyRing(org.bouncycastle.openpgp.PGPSecretKeyRing)

Aggregations

PGPSecretKeyRing (org.bouncycastle.openpgp.PGPSecretKeyRing)1 SecretkeyElement (org.jivesoftware.smackx.ox.element.SecretkeyElement)1 NoBackupFoundException (org.jivesoftware.smackx.ox.exception.NoBackupFoundException)1 OpenPgpV4Fingerprint (org.pgpainless.key.OpenPgpV4Fingerprint)1