Search in sources :

Example 1 with PGPException

use of co.krypt.krypton.pgp.PGPException in project krypton-android by kryptco.

the class MeStorage method loadWithUserID.

public Profile loadWithUserID(@Nullable UserID userID) {
    synchronized (lock) {
        String meJSON = preferences.getString("ME", null);
        if (meJSON == null) {
            Log.i(TAG, "no profile found");
            return null;
        }
        Profile me = JSON.fromJson(meJSON, Profile.class);
        if (me == null) {
            Log.i(TAG, "no profile found");
            return null;
        }
        try {
            SSHKeyPairI kp = getOrLoadKeyPair(context);
            if (kp != null) {
                me.sshWirePublicKey = kp.publicKeySSHWireFormat();
                if (userID != null) {
                    try {
                        List<UserID> userIDs = getUserIDs();
                        // keep USER_ID_LIMIT most recent UserIDs
                        if (userIDs.remove(userID)) {
                            userIDs.add(userID);
                        } else {
                            if (userIDs.size() >= USER_ID_LIMIT) {
                                userIDs.remove(0);
                            }
                            userIDs.add(userID);
                            PGPPublicKey pgpPublicKey = PGPManager.publicKeyWithIdentities(kp, userIDs);
                            me.pgpPublicKey = pgpPublicKey.serializedBytes();
                            if (userIDs.size() == USER_ID_LIMIT) {
                                // detect abuse of exporting PGP userIDs
                                Notifications.notifyPGPKeyExport(context, pgpPublicKey);
                            }
                        }
                        set(me, userIDs);
                    } catch (PGPException | IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        } catch (InvalidKeyException | IOException | CryptoException e) {
            e.printStackTrace();
        }
        try {
            me.teamCheckpoint = TeamDataProvider.getTeamCheckpoint(context).success;
        } catch (Native.NotLinked notLinked) {
            notLinked.printStackTrace();
        }
        return me;
    }
}
Also used : SSHKeyPairI(co.krypt.krypton.crypto.SSHKeyPairI) PGPPublicKey(co.krypt.krypton.pgp.PGPPublicKey) IOException(java.io.IOException) InvalidKeyException(java.security.InvalidKeyException) Profile(co.krypt.krypton.protocol.Profile) PGPException(co.krypt.krypton.pgp.PGPException) Native(co.krypt.krypton.team.Native) UserID(co.krypt.krypton.pgp.UserID) CryptoException(co.krypt.krypton.exception.CryptoException)

Aggregations

SSHKeyPairI (co.krypt.krypton.crypto.SSHKeyPairI)1 CryptoException (co.krypt.krypton.exception.CryptoException)1 PGPException (co.krypt.krypton.pgp.PGPException)1 PGPPublicKey (co.krypt.krypton.pgp.PGPPublicKey)1 UserID (co.krypt.krypton.pgp.UserID)1 Profile (co.krypt.krypton.protocol.Profile)1 Native (co.krypt.krypton.team.Native)1 IOException (java.io.IOException)1 InvalidKeyException (java.security.InvalidKeyException)1