@Test public void testPromoteDivert() throws Exception { PromoteKeyOperation op = new PromoteKeyOperation(RuntimeEnvironment.application, KeyWritableRepository.create(RuntimeEnvironment.application), null, null); byte[] aid = Hex.decode("D2760001240102000000012345670000"); PromoteKeyResult result = op.execute( PromoteKeyringParcel.createPromoteKeyringParcel(mStaticRing.getMasterKeyId(), aid, null), null); Assert.assertTrue("promotion must succeed", result.success()); { CanonicalizedSecretKeyRing ring = KeyWritableRepository.create(RuntimeEnvironment.application) .getCanonicalizedSecretKeyRing(mStaticRing.getMasterKeyId()); for (CanonicalizedSecretKey key : ring.secretKeyIterator()) { Assert.assertEquals("all subkeys must be divert-to-card", SecretKeyType.DIVERT_TO_CARD, key.getSecretKeyTypeSuperExpensive()); Assert.assertArrayEquals("all subkeys must have correct iv", aid, key.getIv()); } } }
@NonNull @Override public PromoteKeyResult execute(PromoteKeyringParcel promoteKeyringParcel, CryptoInputParcel cryptoInputParcel) { OperationLog log = new OperationLog(); log.add(LogType.MSG_PR, 0); UncachedKeyRing promotedRing; { try { log.add(LogType.MSG_PR_FETCHING, 1, KeyFormattingUtils.convertKeyIdToHex(promoteKeyringParcel.getMasterKeyId())); CanonicalizedPublicKeyRing pubRing = mKeyRepository.getCanonicalizedPublicKeyRing(promoteKeyringParcel.getMasterKeyId()); List<byte[]> fingerprints = promoteKeyringParcel.getFingerprints(); if (fingerprints == null) { log.add(LogType.MSG_PR_ALL, 1); } else { for (CanonicalizedPublicKey key : pubRing.publicKeyIterator()) { long subKeyId = key.getKeyId(); if (naiveArraySearch(fingerprints, key.getFingerprint())) { log.add(LogType.MSG_PR_SUBKEY_MATCH, 1, KeyFormattingUtils.convertKeyIdToHex(subKeyId)); } else { log.add(LogType.MSG_PR_SUBKEY_NOMATCH, 1, KeyFormattingUtils.convertKeyIdToHex(subKeyId)); } } } promotedRing = pubRing.createDivertSecretRing(promoteKeyringParcel.getCardAid(), fingerprints); } catch (NotFoundException e) { log.add(LogType.MSG_PR_ERROR_KEY_NOT_FOUND, 2); return new PromoteKeyResult(PromoteKeyResult.RESULT_ERROR, log, null); } } if (promotedRing == null) { return new PromoteKeyResult(PromoteKeyResult.RESULT_ERROR, log, null); } if (checkCancelled()) { log.add(LogType.MSG_OPERATION_CANCELLED, 0); return new PromoteKeyResult(PgpEditKeyResult.RESULT_CANCELLED, log, null); } setPreventCancel(); updateProgress(R.string.progress_saving, 80, 100); SaveKeyringResult saveResult = mKeyWritableRepository.saveSecretKeyRing(promotedRing); log.add(saveResult, 1); if (!saveResult.success()) { return new PromoteKeyResult(PromoteKeyResult.RESULT_ERROR, log, null); } updateProgress(R.string.progress_done, 100, 100); log.add(LogType.MSG_PR_SUCCESS, 0); return new PromoteKeyResult(PromoteKeyResult.RESULT_OK, log, promotedRing.getMasterKeyId()); }
PromoteKeyOperation extends BaseReadWriteOperation<PromoteKeyringParcel> { @NonNull @Override public PromoteKeyResult execute(PromoteKeyringParcel promoteKeyringParcel, CryptoInputParcel cryptoInputParcel) { OperationLog log = new OperationLog(); log.add(LogType.MSG_PR, 0); UncachedKeyRing promotedRing; { try { log.add(LogType.MSG_PR_FETCHING, 1, KeyFormattingUtils.convertKeyIdToHex(promoteKeyringParcel.getMasterKeyId())); CanonicalizedPublicKeyRing pubRing = mKeyRepository.getCanonicalizedPublicKeyRing(promoteKeyringParcel.getMasterKeyId()); List<byte[]> fingerprints = promoteKeyringParcel.getFingerprints(); if (fingerprints == null) { log.add(LogType.MSG_PR_ALL, 1); } else { for (CanonicalizedPublicKey key : pubRing.publicKeyIterator()) { long subKeyId = key.getKeyId(); if (naiveArraySearch(fingerprints, key.getFingerprint())) { log.add(LogType.MSG_PR_SUBKEY_MATCH, 1, KeyFormattingUtils.convertKeyIdToHex(subKeyId)); } else { log.add(LogType.MSG_PR_SUBKEY_NOMATCH, 1, KeyFormattingUtils.convertKeyIdToHex(subKeyId)); } } } promotedRing = pubRing.createDivertSecretRing(promoteKeyringParcel.getCardAid(), fingerprints); } catch (NotFoundException e) { log.add(LogType.MSG_PR_ERROR_KEY_NOT_FOUND, 2); return new PromoteKeyResult(PromoteKeyResult.RESULT_ERROR, log, null); } } if (promotedRing == null) { return new PromoteKeyResult(PromoteKeyResult.RESULT_ERROR, log, null); } if (checkCancelled()) { log.add(LogType.MSG_OPERATION_CANCELLED, 0); return new PromoteKeyResult(PgpEditKeyResult.RESULT_CANCELLED, log, null); } setPreventCancel(); updateProgress(R.string.progress_saving, 80, 100); SaveKeyringResult saveResult = mKeyWritableRepository.saveSecretKeyRing(promotedRing); log.add(saveResult, 1); if (!saveResult.success()) { return new PromoteKeyResult(PromoteKeyResult.RESULT_ERROR, log, null); } updateProgress(R.string.progress_done, 100, 100); log.add(LogType.MSG_PR_SUCCESS, 0); return new PromoteKeyResult(PromoteKeyResult.RESULT_OK, log, promotedRing.getMasterKeyId()); } }
PromoteKeyOperation extends BaseReadWriteOperation<PromoteKeyringParcel> { @NonNull @Override public PromoteKeyResult execute(PromoteKeyringParcel promoteKeyringParcel, CryptoInputParcel cryptoInputParcel) { OperationLog log = new OperationLog(); log.add(LogType.MSG_PR, 0); UncachedKeyRing promotedRing; { try { log.add(LogType.MSG_PR_FETCHING, 1, KeyFormattingUtils.convertKeyIdToHex(promoteKeyringParcel.getMasterKeyId())); CanonicalizedPublicKeyRing pubRing = mKeyRepository.getCanonicalizedPublicKeyRing(promoteKeyringParcel.getMasterKeyId()); List<byte[]> fingerprints = promoteKeyringParcel.getFingerprints(); if (fingerprints == null) { log.add(LogType.MSG_PR_ALL, 1); } else { for (CanonicalizedPublicKey key : pubRing.publicKeyIterator()) { long subKeyId = key.getKeyId(); if (naiveArraySearch(fingerprints, key.getFingerprint())) { log.add(LogType.MSG_PR_SUBKEY_MATCH, 1, KeyFormattingUtils.convertKeyIdToHex(subKeyId)); } else { log.add(LogType.MSG_PR_SUBKEY_NOMATCH, 1, KeyFormattingUtils.convertKeyIdToHex(subKeyId)); } } } promotedRing = pubRing.createDivertSecretRing(promoteKeyringParcel.getCardAid(), fingerprints); } catch (NotFoundException e) { log.add(LogType.MSG_PR_ERROR_KEY_NOT_FOUND, 2); return new PromoteKeyResult(PromoteKeyResult.RESULT_ERROR, log, null); } } if (promotedRing == null) { return new PromoteKeyResult(PromoteKeyResult.RESULT_ERROR, log, null); } if (checkCancelled()) { log.add(LogType.MSG_OPERATION_CANCELLED, 0); return new PromoteKeyResult(PgpEditKeyResult.RESULT_CANCELLED, log, null); } setPreventCancel(); updateProgress(R.string.progress_saving, 80, 100); SaveKeyringResult saveResult = mKeyWritableRepository.saveSecretKeyRing(promotedRing); log.add(saveResult, 1); if (!saveResult.success()) { return new PromoteKeyResult(PromoteKeyResult.RESULT_ERROR, log, null); } updateProgress(R.string.progress_done, 100, 100); log.add(LogType.MSG_PR_SUCCESS, 0); return new PromoteKeyResult(PromoteKeyResult.RESULT_OK, log, promotedRing.getMasterKeyId()); } PromoteKeyOperation(Context context, KeyWritableRepository databaseInteractor,
                               Progressable progressable, AtomicBoolean cancelled); }
PromoteKeyOperation extends BaseReadWriteOperation<PromoteKeyringParcel> { @NonNull @Override public PromoteKeyResult execute(PromoteKeyringParcel promoteKeyringParcel, CryptoInputParcel cryptoInputParcel) { OperationLog log = new OperationLog(); log.add(LogType.MSG_PR, 0); UncachedKeyRing promotedRing; { try { log.add(LogType.MSG_PR_FETCHING, 1, KeyFormattingUtils.convertKeyIdToHex(promoteKeyringParcel.getMasterKeyId())); CanonicalizedPublicKeyRing pubRing = mKeyRepository.getCanonicalizedPublicKeyRing(promoteKeyringParcel.getMasterKeyId()); List<byte[]> fingerprints = promoteKeyringParcel.getFingerprints(); if (fingerprints == null) { log.add(LogType.MSG_PR_ALL, 1); } else { for (CanonicalizedPublicKey key : pubRing.publicKeyIterator()) { long subKeyId = key.getKeyId(); if (naiveArraySearch(fingerprints, key.getFingerprint())) { log.add(LogType.MSG_PR_SUBKEY_MATCH, 1, KeyFormattingUtils.convertKeyIdToHex(subKeyId)); } else { log.add(LogType.MSG_PR_SUBKEY_NOMATCH, 1, KeyFormattingUtils.convertKeyIdToHex(subKeyId)); } } } promotedRing = pubRing.createDivertSecretRing(promoteKeyringParcel.getCardAid(), fingerprints); } catch (NotFoundException e) { log.add(LogType.MSG_PR_ERROR_KEY_NOT_FOUND, 2); return new PromoteKeyResult(PromoteKeyResult.RESULT_ERROR, log, null); } } if (promotedRing == null) { return new PromoteKeyResult(PromoteKeyResult.RESULT_ERROR, log, null); } if (checkCancelled()) { log.add(LogType.MSG_OPERATION_CANCELLED, 0); return new PromoteKeyResult(PgpEditKeyResult.RESULT_CANCELLED, log, null); } setPreventCancel(); updateProgress(R.string.progress_saving, 80, 100); SaveKeyringResult saveResult = mKeyWritableRepository.saveSecretKeyRing(promotedRing); log.add(saveResult, 1); if (!saveResult.success()) { return new PromoteKeyResult(PromoteKeyResult.RESULT_ERROR, log, null); } updateProgress(R.string.progress_done, 100, 100); log.add(LogType.MSG_PR_SUCCESS, 0); return new PromoteKeyResult(PromoteKeyResult.RESULT_OK, log, promotedRing.getMasterKeyId()); } PromoteKeyOperation(Context context, KeyWritableRepository databaseInteractor,
                               Progressable progressable, AtomicBoolean cancelled); @NonNull @Override PromoteKeyResult execute(PromoteKeyringParcel promoteKeyringParcel,
                                    CryptoInputParcel cryptoInputParcel); }
PromoteKeyOperation extends BaseReadWriteOperation<PromoteKeyringParcel> { @NonNull @Override public PromoteKeyResult execute(PromoteKeyringParcel promoteKeyringParcel, CryptoInputParcel cryptoInputParcel) { OperationLog log = new OperationLog(); log.add(LogType.MSG_PR, 0); UncachedKeyRing promotedRing; { try { log.add(LogType.MSG_PR_FETCHING, 1, KeyFormattingUtils.convertKeyIdToHex(promoteKeyringParcel.getMasterKeyId())); CanonicalizedPublicKeyRing pubRing = mKeyRepository.getCanonicalizedPublicKeyRing(promoteKeyringParcel.getMasterKeyId()); List<byte[]> fingerprints = promoteKeyringParcel.getFingerprints(); if (fingerprints == null) { log.add(LogType.MSG_PR_ALL, 1); } else { for (CanonicalizedPublicKey key : pubRing.publicKeyIterator()) { long subKeyId = key.getKeyId(); if (naiveArraySearch(fingerprints, key.getFingerprint())) { log.add(LogType.MSG_PR_SUBKEY_MATCH, 1, KeyFormattingUtils.convertKeyIdToHex(subKeyId)); } else { log.add(LogType.MSG_PR_SUBKEY_NOMATCH, 1, KeyFormattingUtils.convertKeyIdToHex(subKeyId)); } } } promotedRing = pubRing.createDivertSecretRing(promoteKeyringParcel.getCardAid(), fingerprints); } catch (NotFoundException e) { log.add(LogType.MSG_PR_ERROR_KEY_NOT_FOUND, 2); return new PromoteKeyResult(PromoteKeyResult.RESULT_ERROR, log, null); } } if (promotedRing == null) { return new PromoteKeyResult(PromoteKeyResult.RESULT_ERROR, log, null); } if (checkCancelled()) { log.add(LogType.MSG_OPERATION_CANCELLED, 0); return new PromoteKeyResult(PgpEditKeyResult.RESULT_CANCELLED, log, null); } setPreventCancel(); updateProgress(R.string.progress_saving, 80, 100); SaveKeyringResult saveResult = mKeyWritableRepository.saveSecretKeyRing(promotedRing); log.add(saveResult, 1); if (!saveResult.success()) { return new PromoteKeyResult(PromoteKeyResult.RESULT_ERROR, log, null); } updateProgress(R.string.progress_done, 100, 100); log.add(LogType.MSG_PR_SUCCESS, 0); return new PromoteKeyResult(PromoteKeyResult.RESULT_OK, log, promotedRing.getMasterKeyId()); } PromoteKeyOperation(Context context, KeyWritableRepository databaseInteractor,
                               Progressable progressable, AtomicBoolean cancelled); @NonNull @Override PromoteKeyResult execute(PromoteKeyringParcel promoteKeyringParcel,
                                    CryptoInputParcel cryptoInputParcel);  }