token-import: bind only relevant subkeys

This commit is contained in:
Vincent Breitmoser
2017-09-11 01:55:03 +02:00
parent e0b5d97356
commit bd2e6aa698
5 changed files with 21 additions and 5 deletions

View File

@@ -18,6 +18,7 @@
package org.sufficientlysecure.keychain.operations;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicBoolean;
import android.content.Context;
@@ -77,6 +78,11 @@ public class PromoteKeyOperation extends BaseReadWriteOperation<PromoteKeyringPa
// sort for binary search
for (CanonicalizedPublicKey key : pubRing.publicKeyIterator()) {
long subKeyId = key.getKeyId();
// we ignore key ids from empty fingerprints here
if (subKeyId == 0L) {
continue;
}
if (naiveIndexOf(subKeyIds, subKeyId) != null) {
log.add(LogType.MSG_PR_SUBKEY_MATCH, 1,
KeyFormattingUtils.convertKeyIdToHex(subKeyId));

View File

@@ -24,6 +24,7 @@ import android.os.Parcelable;
import android.support.annotation.Nullable;
import com.google.auto.value.AutoValue;
import org.sufficientlysecure.keychain.securitytoken.SecurityTokenInfo;
@AutoValue

View File

@@ -79,7 +79,7 @@ class ManageSecurityTokenContract {
void hideAction();
void operationImportKey(byte[] importKeyData);
void operationPromote(long masterKeyId, byte[] cardAid);
void operationPromote(long masterKeyId, byte[] cardAid, long[] subKeyIds);
void operationResetSecurityToken();
void operationChangePinSecurityToken(String adminPin, String newPin);

View File

@@ -277,12 +277,12 @@ public class ManageSecurityTokenFragment extends Fragment implements ManageSecur
}
@Override
public void operationPromote(long masterKeyId, byte[] cardAid) {
public void operationPromote(long masterKeyId, byte[] cardAid, long[] subkeys) {
if (currentImportKeyringParcel != null) {
throw new IllegalStateException("Cannot trigger import operation twice!");
}
currentPromoteKeyringParcel = PromoteKeyringParcel.createPromoteKeyringParcel(masterKeyId, cardAid, null);
currentPromoteKeyringParcel = PromoteKeyringParcel.createPromoteKeyringParcel(masterKeyId, cardAid, subkeys);
cryptoPromoteOperationHelper.setOperationMinimumDelay(1000L);
cryptoPromoteOperationHelper.cryptoOperation();
}

View File

@@ -38,6 +38,7 @@ import org.sufficientlysecure.keychain.ui.token.PublicKeyRetrievalLoader.KeyRetr
import org.sufficientlysecure.keychain.ui.token.PublicKeyRetrievalLoader.KeyserverRetrievalLoader;
import org.sufficientlysecure.keychain.ui.token.PublicKeyRetrievalLoader.LocalKeyLookupLoader;
import org.sufficientlysecure.keychain.ui.token.PublicKeyRetrievalLoader.UriKeyRetrievalLoader;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
import org.sufficientlysecure.keychain.ui.util.PermissionsUtil;
@@ -276,13 +277,21 @@ class ManageSecurityTokenPresenter implements ManageSecurityTokenMvpPresenter {
if (masterKeyId != null) {
this.masterKeyId = masterKeyId;
view.statusLineAdd(StatusLine.TOKEN_CHECK);
view.operationPromote(masterKeyId, tokenInfo.getAid());
promoteKeyWithTokenInfo(masterKeyId);
return;
}
throw new IllegalArgumentException("Method can only be called with successful result!");
}
private void promoteKeyWithTokenInfo(Long masterKeyId) {
long signKeyId = KeyFormattingUtils.getKeyIdFromFingerprint(tokenInfo.getFingerprintSign());
long decryptKeyId = KeyFormattingUtils.getKeyIdFromFingerprint(tokenInfo.getFingerprintDecrypt());
long authKeyId = KeyFormattingUtils.getKeyIdFromFingerprint(tokenInfo.getFingerprintAuth());
view.operationPromote(masterKeyId, tokenInfo.getAid(), new long[] { signKeyId, decryptKeyId, authKeyId });
}
@Override
public void onClickImport() {
view.statusLineAdd(StatusLine.IMPORT);
@@ -296,7 +305,7 @@ class ManageSecurityTokenPresenter implements ManageSecurityTokenMvpPresenter {
view.statusLineOk();
view.statusLineAdd(StatusLine.TOKEN_PROMOTE);
view.operationPromote(masterKeyId, tokenInfo.getAid());
promoteKeyWithTokenInfo(masterKeyId);
}
@Override