Search in sources :

Example 11 with IdentityKeyPair

use of org.whispersystems.libsignal.IdentityKeyPair in project Conversations by siacs.

the class SQLiteAxolotlStore method loadIdentityKeyPair.

// --------------------------------------
// IdentityKeyStore
// --------------------------------------
private IdentityKeyPair loadIdentityKeyPair() {
    synchronized (mXmppConnectionService) {
        IdentityKeyPair ownKey = mXmppConnectionService.databaseBackend.loadOwnIdentityKeyPair(account);
        if (ownKey != null) {
            return ownKey;
        } else {
            Log.i(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Could not retrieve own IdentityKeyPair");
            ownKey = generateIdentityKeyPair();
            mXmppConnectionService.databaseBackend.storeOwnIdentityKeyPair(account, ownKey);
        }
        return ownKey;
    }
}
Also used : IdentityKeyPair(org.whispersystems.libsignal.IdentityKeyPair)

Example 12 with IdentityKeyPair

use of org.whispersystems.libsignal.IdentityKeyPair in project Signal-Android by WhisperSystems.

the class DeviceActivity method onLink.

@SuppressLint("StaticFieldLeak")
@Override
public void onLink(final Uri uri) {
    new ProgressDialogAsyncTask<Void, Void, Integer>(this, R.string.DeviceProvisioningActivity_content_progress_title, R.string.DeviceProvisioningActivity_content_progress_content) {

        private static final int SUCCESS = 0;

        private static final int NO_DEVICE = 1;

        private static final int NETWORK_ERROR = 2;

        private static final int KEY_ERROR = 3;

        private static final int LIMIT_EXCEEDED = 4;

        private static final int BAD_CODE = 5;

        @Override
        protected Integer doInBackground(Void... params) {
            boolean isMultiDevice = TextSecurePreferences.isMultiDevice(DeviceActivity.this);
            try {
                Context context = DeviceActivity.this;
                SignalServiceAccountManager accountManager = ApplicationDependencies.getSignalServiceAccountManager();
                String verificationCode = accountManager.getNewDeviceVerificationCode();
                String ephemeralId = uri.getQueryParameter("uuid");
                String publicKeyEncoded = uri.getQueryParameter("pub_key");
                if (TextUtils.isEmpty(ephemeralId) || TextUtils.isEmpty(publicKeyEncoded)) {
                    Log.w(TAG, "UUID or Key is empty!");
                    return BAD_CODE;
                }
                ECPublicKey publicKey = Curve.decodePoint(Base64.decode(publicKeyEncoded), 0);
                IdentityKeyPair aciIdentityKeyPair = SignalStore.account().getAciIdentityKey();
                IdentityKeyPair pniIdentityKeyPair = SignalStore.account().getPniIdentityKey();
                ProfileKey profileKey = ProfileKeyUtil.getSelfProfileKey();
                TextSecurePreferences.setMultiDevice(DeviceActivity.this, true);
                accountManager.addDevice(ephemeralId, publicKey, aciIdentityKeyPair, pniIdentityKeyPair, profileKey, verificationCode);
                return SUCCESS;
            } catch (NotFoundException e) {
                Log.w(TAG, e);
                TextSecurePreferences.setMultiDevice(DeviceActivity.this, isMultiDevice);
                return NO_DEVICE;
            } catch (DeviceLimitExceededException e) {
                Log.w(TAG, e);
                TextSecurePreferences.setMultiDevice(DeviceActivity.this, isMultiDevice);
                return LIMIT_EXCEEDED;
            } catch (IOException e) {
                Log.w(TAG, e);
                TextSecurePreferences.setMultiDevice(DeviceActivity.this, isMultiDevice);
                return NETWORK_ERROR;
            } catch (InvalidKeyException e) {
                Log.w(TAG, e);
                TextSecurePreferences.setMultiDevice(DeviceActivity.this, isMultiDevice);
                return KEY_ERROR;
            }
        }

        @Override
        protected void onPostExecute(Integer result) {
            super.onPostExecute(result);
            Context context = DeviceActivity.this;
            switch(result) {
                case SUCCESS:
                    Toast.makeText(context, R.string.DeviceProvisioningActivity_content_progress_success, Toast.LENGTH_SHORT).show();
                    finish();
                    return;
                case NO_DEVICE:
                    Toast.makeText(context, R.string.DeviceProvisioningActivity_content_progress_no_device, Toast.LENGTH_LONG).show();
                    break;
                case NETWORK_ERROR:
                    Toast.makeText(context, R.string.DeviceProvisioningActivity_content_progress_network_error, Toast.LENGTH_LONG).show();
                    break;
                case KEY_ERROR:
                    Toast.makeText(context, R.string.DeviceProvisioningActivity_content_progress_key_error, Toast.LENGTH_LONG).show();
                    break;
                case LIMIT_EXCEEDED:
                    Toast.makeText(context, R.string.DeviceProvisioningActivity_sorry_you_have_too_many_devices_linked_already, Toast.LENGTH_LONG).show();
                    break;
                case BAD_CODE:
                    Toast.makeText(context, R.string.DeviceActivity_sorry_this_is_not_a_valid_device_link_qr_code, Toast.LENGTH_LONG).show();
                    break;
            }
            getSupportFragmentManager().popBackStackImmediate();
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : Context(android.content.Context) SignalServiceAccountManager(org.whispersystems.signalservice.api.SignalServiceAccountManager) NotFoundException(org.whispersystems.signalservice.api.push.exceptions.NotFoundException) IOException(java.io.IOException) InvalidKeyException(org.whispersystems.libsignal.InvalidKeyException) SuppressLint(android.annotation.SuppressLint) ProfileKey(org.signal.zkgroup.profiles.ProfileKey) DeviceLimitExceededException(org.whispersystems.signalservice.internal.push.DeviceLimitExceededException) ECPublicKey(org.whispersystems.libsignal.ecc.ECPublicKey) IdentityKeyPair(org.whispersystems.libsignal.IdentityKeyPair) SuppressLint(android.annotation.SuppressLint)

Example 13 with IdentityKeyPair

use of org.whispersystems.libsignal.IdentityKeyPair in project Signal-Android by WhisperSystems.

the class MultiDevicePniIdentityUpdateJob method onRun.

@Override
public void onRun() throws IOException, UntrustedIdentityException {
    if (!Recipient.self().isRegistered()) {
        throw new NotPushRegisteredException();
    }
    if (!TextSecurePreferences.isMultiDevice(context)) {
        Log.i(TAG, "Not multi device, aborting...");
        return;
    }
    if (SignalStore.account().isLinkedDevice()) {
        Log.i(TAG, "Not primary device, aborting...");
        return;
    }
    IdentityKeyPair pniIdentityKeyPair = SignalStore.account().getPniIdentityKey();
    SignalServiceSyncMessage syncMessage = SignalServiceSyncMessage.forPniIdentity(PniIdentity.newBuilder().setPublicKey(ByteString.copyFrom(pniIdentityKeyPair.getPublicKey().serialize())).setPrivateKey(ByteString.copyFrom(pniIdentityKeyPair.getPrivateKey().serialize())).build());
    ApplicationDependencies.getSignalServiceMessageSender().sendSyncMessage(syncMessage, UnidentifiedAccessUtil.getAccessForSync(context));
}
Also used : NotPushRegisteredException(org.thoughtcrime.securesms.net.NotPushRegisteredException) IdentityKeyPair(org.whispersystems.libsignal.IdentityKeyPair) SignalServiceSyncMessage(org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage)

Example 14 with IdentityKeyPair

use of org.whispersystems.libsignal.IdentityKeyPair in project Signal-Android by WhisperSystems.

the class IdentityKeyUtil method generateIdentityKeyPair.

public static IdentityKeyPair generateIdentityKeyPair() {
    ECKeyPair djbKeyPair = Curve.generateKeyPair();
    IdentityKey djbIdentityKey = new IdentityKey(djbKeyPair.getPublicKey());
    ECPrivateKey djbPrivateKey = djbKeyPair.getPrivateKey();
    return new IdentityKeyPair(djbIdentityKey, djbPrivateKey);
}
Also used : ECPrivateKey(org.whispersystems.libsignal.ecc.ECPrivateKey) IdentityKey(org.whispersystems.libsignal.IdentityKey) ECKeyPair(org.whispersystems.libsignal.ecc.ECKeyPair) IdentityKeyPair(org.whispersystems.libsignal.IdentityKeyPair)

Example 15 with IdentityKeyPair

use of org.whispersystems.libsignal.IdentityKeyPair in project Signal-Android by WhisperSystems.

the class MobileCoinPublicAddressProfileUtilTest method can_verify_an_address.

@Test
public void can_verify_an_address() throws PaymentsAddressException {
    IdentityKeyPair identityKeyPair = IdentityKeyUtil.generateIdentityKeyPair();
    byte[] address = Util.getSecretBytes(100);
    SignalServiceProtos.PaymentAddress signedPaymentAddress = MobileCoinPublicAddressProfileUtil.signPaymentsAddress(address, identityKeyPair);
    byte[] paymentsAddress = MobileCoinPublicAddressProfileUtil.verifyPaymentsAddress(signedPaymentAddress, identityKeyPair.getPublicKey());
    assertArrayEquals(address, paymentsAddress);
}
Also used : SignalServiceProtos(org.whispersystems.signalservice.internal.push.SignalServiceProtos) IdentityKeyPair(org.whispersystems.libsignal.IdentityKeyPair) Test(org.junit.Test)

Aggregations

IdentityKeyPair (org.whispersystems.libsignal.IdentityKeyPair)40 SignedPreKeyRecord (org.whispersystems.libsignal.state.SignedPreKeyRecord)12 Test (org.junit.Test)9 IdentityKey (org.whispersystems.libsignal.IdentityKey)9 InvalidKeyException (org.whispersystems.libsignal.InvalidKeyException)8 PreKeyRecord (org.whispersystems.libsignal.state.PreKeyRecord)7 IOException (java.io.IOException)6 SignalServiceProtos (org.whispersystems.signalservice.internal.push.SignalServiceProtos)6 ECPrivateKey (org.whispersystems.libsignal.ecc.ECPrivateKey)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 SuppressLint (android.annotation.SuppressLint)3 ECKeyPair (org.whispersystems.libsignal.ecc.ECKeyPair)3 SignalServiceAccountManager (org.whispersystems.signalservice.api.SignalServiceAccountManager)3 ContentValues (android.content.ContentValues)2 Context (android.content.Context)2 Cursor (android.database.Cursor)2 NonNull (android.support.annotation.NonNull)2 Account (de.pixart.messenger.entities.Account)2 Account (eu.siacs.conversations.entities.Account)2