Keys found on multiple servers are now imported from all of them

This commit is contained in:
Tim Bray 2014-09-13 21:15:14 -07:00
parent 7de86a09bc
commit c13ccda658
7 changed files with 49 additions and 38 deletions

View File

@ -278,7 +278,7 @@ public class HkpKeyserver extends Keyserver {
while (matcher.find()) {
final ImportKeysListEntry entry = new ImportKeysListEntry();
entry.setQuery(query);
entry.setOrigin(getUrlPrefix() + mHost + ":" + mPort);
entry.addOrigin(getUrlPrefix() + mHost + ":" + mPort);
int bitSize = Integer.parseInt(matcher.group(3));
entry.setBitStrength(bitSize);

View File

@ -67,6 +67,9 @@ public class ImportKeysList extends ArrayList<ImportKeysListEntry> {
existing.setExpired(true);
modified = true;
}
for (String origin : incoming.getOrigins()) {
existing.addOrigin(origin);
}
ArrayList<String> incomingIDs = incoming.getUserIds();
ArrayList<String> existingIDs = existing.getUserIds();
for (String incomingID : incomingIDs) {

View File

@ -46,7 +46,7 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
private String mPrimaryUserId;
private String mExtraData;
private String mQuery;
private String mOrigin;
private ArrayList<String> mOrigins;
private Integer mHashCode = null;
private boolean mSelected;
@ -70,7 +70,7 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
dest.writeByte((byte) (mSecretKey ? 1 : 0));
dest.writeByte((byte) (mSelected ? 1 : 0));
dest.writeString(mExtraData);
dest.writeString(mOrigin);
dest.writeStringList(mOrigins);
}
public static final Creator<ImportKeysListEntry> CREATOR = new Creator<ImportKeysListEntry>() {
@ -90,7 +90,8 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
vr.mSecretKey = source.readByte() == 1;
vr.mSelected = source.readByte() == 1;
vr.mExtraData = source.readString();
vr.mOrigin = source.readString();
vr.mOrigins = new ArrayList<String>();
source.readStringList(vr.mOrigins);
return vr;
}
@ -230,12 +231,12 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
mQuery = query;
}
public String getOrigin() {
return mOrigin;
public ArrayList<String> getOrigins() {
return mOrigins;
}
public void setOrigin(String origin) {
mOrigin = origin;
public void addOrigin(String origin) {
mOrigins.add(origin);
}
/**
@ -247,6 +248,7 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
// do not select by default
mSelected = false;
mUserIds = new ArrayList<String>();
mOrigins = new ArrayList<String>();
}
/**

View File

@ -63,7 +63,7 @@ public class KeybaseKeyserver extends Keyserver {
private ImportKeysListEntry makeEntry(Match match) throws KeybaseException {
final ImportKeysListEntry entry = new ImportKeysListEntry();
entry.setQuery(mQuery);
entry.setOrigin(ORIGIN);
entry.addOrigin(ORIGIN);
entry.setRevoked(false); // keybase doesnt say anything about revoked keys

View File

@ -652,27 +652,35 @@ public class KeychainIntentService extends IntentService implements Progressable
for (ImportKeysListEntry entry : entries) {
try {
Keyserver server;
if (entry.getOrigin() == null) {
server = new HkpKeyserver(keyServer);
} else if (KeybaseKeyserver.ORIGIN.equals(entry.getOrigin())) {
server = new KeybaseKeyserver();
} else {
server = new HkpKeyserver(entry.getOrigin());
ArrayList<String> origins = entry.getOrigins();
if (origins == null) {
origins = new ArrayList<String>();
}
// if available use complete fingerprint for get request
byte[] downloadedKeyBytes;
if (KeybaseKeyserver.ORIGIN.equals(entry.getOrigin())) {
downloadedKeyBytes = server.get(entry.getExtraData()).getBytes();
} else if (entry.getFingerprintHex() != null) {
downloadedKeyBytes = server.get("0x" + entry.getFingerprintHex()).getBytes();
} else {
downloadedKeyBytes = server.get(entry.getKeyIdHex()).getBytes();
if (origins.isEmpty()) {
origins.add(keyServer);
}
for (String origin : origins) {
if (KeybaseKeyserver.ORIGIN.equals(origin)) {
server = new KeybaseKeyserver();
} else {
server = new HkpKeyserver(origin);
}
Log.d(Constants.TAG, "IMPORTING " + entry.getKeyIdHex() + " FROM: " + server);
// save key bytes in entry object for doing the
// actual import afterwards
keyRings.add(new ParcelableKeyRing(downloadedKeyBytes, entry.getFingerprintHex()));
// if available use complete fingerprint for get request
byte[] downloadedKeyBytes;
if (KeybaseKeyserver.ORIGIN.equals(origin)) {
downloadedKeyBytes = server.get(entry.getExtraData()).getBytes();
} else if (entry.getFingerprintHex() != null) {
downloadedKeyBytes = server.get("0x" + entry.getFingerprintHex()).getBytes();
} else {
downloadedKeyBytes = server.get(entry.getKeyIdHex()).getBytes();
}
// save key bytes in entry object for doing the
// actual import afterwards
keyRings.add(new ParcelableKeyRing(downloadedKeyBytes, entry.getFingerprintHex()));
}
} catch (Exception e) {
sendErrorToHandler(e);
}

View File

@ -4,34 +4,34 @@
<item android:state_pressed="true" >
<shape android:shape="rectangle" >
<padding
android:bottom="2dip"
android:bottom="3dip"
android:left="2dip"
android:right="2dip"
android:top="2dip" />
android:top="1dip" />
<corners android:radius="6dip" />
<solid android:color="#4747a4" />
<solid android:color="#4444cc" />
</shape>
</item>
<item android:state_focused="true">
<shape android:shape="rectangle" >
<padding
android:bottom="2dip"
android:bottom="3dip"
android:left="2dip"
android:right="2dip"
android:top="2dip" />
android:top="1dip" />
<corners android:radius="6dip" />
<solid android:color="#4747a4"/>
<solid android:color="#4444cc"/>
</shape>
</item>
<item >
<shape android:shape="rectangle" >
<padding
android:bottom="2dip"
android:bottom="3dip"
android:left="2dip"
android:right="2dip"
android:top="2dip" />
android:top="1dip" />
<corners android:radius="6dip" />
<solid android:color="#5c5cb8" />
<solid android:color="#5555ee" />
</shape>
</item>
</selector>

View File

@ -48,8 +48,6 @@
android:text="rotate"
android:textColor="#ffffffff"
android:textStyle="bold"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:background="@drawable/button_rounded_blue"
/>
<ImageButton