token-import: use entire fingerprint for promote operation
This commit is contained in:
@@ -20,7 +20,9 @@ package org.sufficientlysecure.keychain.pgp;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
@@ -32,6 +34,7 @@ import org.bouncycastle.openpgp.PGPSecretKey;
|
||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.bouncycastle.openpgp.operator.jcajce.JcaKeyFingerprintCalculator;
|
||||
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
|
||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||
import org.sufficientlysecure.keychain.util.IterableIterator;
|
||||
|
||||
|
||||
@@ -153,19 +156,19 @@ public class CanonicalizedPublicKeyRing extends CanonicalizedKeyRing {
|
||||
}
|
||||
|
||||
/** Create a dummy secret ring from this key */
|
||||
public UncachedKeyRing createDivertSecretRing (byte[] cardAid, long[] subKeyIds) {
|
||||
public UncachedKeyRing createDivertSecretRing(byte[] cardAid, List<byte[]> subKeyFingerprints) {
|
||||
PGPSecretKeyRing secRing = PGPSecretKeyRing.constructDummyFromPublic(getRing(), cardAid);
|
||||
|
||||
if (subKeyIds == null) {
|
||||
if (subKeyFingerprints == null) {
|
||||
return new UncachedKeyRing(secRing);
|
||||
}
|
||||
|
||||
// if only specific subkeys should be promoted, construct a
|
||||
// stripped dummy, then move divert-to-card keys over
|
||||
PGPSecretKeyRing newRing = PGPSecretKeyRing.constructDummyFromPublic(getRing());
|
||||
for (long subKeyId : subKeyIds) {
|
||||
PGPSecretKey key = secRing.getSecretKey(subKeyId);
|
||||
if (key != null) {
|
||||
for (byte[] subKeyFingerprint : subKeyFingerprints) {
|
||||
PGPSecretKey key = secRing.getSecretKey(KeyFormattingUtils.convertFingerprintToKeyId(subKeyFingerprint));
|
||||
if (key != null && Arrays.equals(subKeyFingerprint, key.getPublicKey().getFingerprint())) {
|
||||
newRing = PGPSecretKeyRing.insertSecretKey(newRing, key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
import java.util.TreeSet;
|
||||
@@ -171,7 +172,7 @@ public class UncachedKeyRing {
|
||||
|
||||
}
|
||||
|
||||
public boolean containsKeyWithAnyFingerprint(byte[]... expectedFingerprints) {
|
||||
public boolean containsKeyWithAnyFingerprint(List<byte[]> expectedFingerprints) {
|
||||
Iterator<UncachedPublicKey> publicKeys = getPublicKeys();
|
||||
|
||||
while (publicKeys.hasNext()) {
|
||||
|
||||
Reference in New Issue
Block a user