show key fingerprint in key list

Fixes issue 76
This commit is contained in:
Thialfihar 2010-12-25 19:12:35 +00:00
parent 9e54b3d99d
commit 9e8b266bf0
9 changed files with 59 additions and 11 deletions

View File

@ -139,6 +139,7 @@
<string name="expired">expired</string> <string name="expired">expired</string>
<string name="notValid">not valid</string> <string name="notValid">not valid</string>
<string name="nKeyServers">%s key server(s)</string> <string name="nKeyServers">%s key server(s)</string>
<string name="fingerprint">fingerprint</string>
<!-- choice_lowerCase: capitalized first word, no punctuation --> <!-- choice_lowerCase: capitalized first word, no punctuation -->
<string name="choice_none">None</string> <string name="choice_none">None</string>

View File

@ -1031,6 +1031,34 @@ public class Apg {
} }
public static String getFingerPrint(long keyId) { public static String getFingerPrint(long keyId) {
PGPPublicKey key = Apg.getPublicKey(keyId);
if (key == null) {
PGPSecretKey secretKey = Apg.getSecretKey(keyId);
if (secretKey == null) {
return "";
}
key = secretKey.getPublicKey();
}
String fingerPrint = "";
byte fp[] = key.getFingerprint();
for (int i = 0; i < fp.length; ++i) {
if (i != 0 && i % 10 == 0) {
fingerPrint += " ";
} else if (i != 0 && i % 2 == 0) {
fingerPrint += " ";
}
String chunk = Integer.toHexString((((int)fp[i]) + 256) % 256).toUpperCase();
while (chunk.length() < 2) {
chunk = "0" + chunk;
}
fingerPrint += chunk;
}
return fingerPrint;
}
public static String getSmallFingerPrint(long keyId) {
String fingerPrint = Long.toHexString(keyId & 0xffffffffL).toUpperCase(); String fingerPrint = Long.toHexString(keyId & 0xffffffffL).toUpperCase();
while (fingerPrint.length() < 8) { while (fingerPrint.length() < 8) {
fingerPrint = "0" + fingerPrint; fingerPrint = "0" + fingerPrint;
@ -1039,7 +1067,7 @@ public class Apg {
} }
public static String keyToHex(long keyId) { public static String keyToHex(long keyId) {
return getFingerPrint(keyId >> 32) + getFingerPrint(keyId); return getSmallFingerPrint(keyId >> 32) + getSmallFingerPrint(keyId);
} }
public static long keyFromHex(String data) { public static long keyFromHex(String data) {

View File

@ -620,7 +620,7 @@ public class DecryptActivity extends BaseActivity {
if (data.getBoolean(Apg.EXTRA_SIGNATURE)) { if (data.getBoolean(Apg.EXTRA_SIGNATURE)) {
String userId = data.getString(Apg.EXTRA_SIGNATURE_USER_ID); String userId = data.getString(Apg.EXTRA_SIGNATURE_USER_ID);
mSignatureKeyId = data.getLong(Apg.EXTRA_SIGNATURE_KEY_ID); mSignatureKeyId = data.getLong(Apg.EXTRA_SIGNATURE_KEY_ID);
mUserIdRest.setText("id: " + Apg.getFingerPrint(mSignatureKeyId)); mUserIdRest.setText("id: " + Apg.getSmallFingerPrint(mSignatureKeyId));
if (userId == null) { if (userId == null) {
userId = getResources().getString(R.string.unknownUserId); userId = getResources().getString(R.string.unknownUserId);
} }
@ -727,7 +727,7 @@ public class DecryptActivity extends BaseActivity {
alert.setIcon(android.R.drawable.ic_dialog_alert); alert.setIcon(android.R.drawable.ic_dialog_alert);
alert.setTitle(R.string.title_unknownSignatureKey); alert.setTitle(R.string.title_unknownSignatureKey);
alert.setMessage(getString(R.string.lookupUnknownKey, Apg.getFingerPrint(mUnknownSignatureKeyId))); alert.setMessage(getString(R.string.lookupUnknownKey, Apg.getSmallFingerPrint(mUnknownSignatureKeyId)));
alert.setPositiveButton(android.R.string.ok, alert.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {

View File

@ -149,7 +149,7 @@ public class HkpKeyServer extends KeyServer {
info.size = Integer.parseInt(matcher.group(1)); info.size = Integer.parseInt(matcher.group(1));
info.algorithm = matcher.group(2); info.algorithm = matcher.group(2);
info.keyId = Apg.keyFromHex(matcher.group(3)); info.keyId = Apg.keyFromHex(matcher.group(3));
info.fingerPrint = Apg.getFingerPrint(info.keyId); info.fingerPrint = Apg.getSmallFingerPrint(info.keyId);
String chunks[] = matcher.group(4).split("-"); String chunks[] = matcher.group(4).split("-");
info.date = new GregorianCalendar(Integer.parseInt(chunks[0]), info.date = new GregorianCalendar(Integer.parseInt(chunks[0]),
Integer.parseInt(chunks[1]), Integer.parseInt(chunks[1]),

View File

@ -479,6 +479,7 @@ public class KeyListActivity extends BaseActivity {
private class KeyChild { private class KeyChild {
public static final int KEY = 0; public static final int KEY = 0;
public static final int USER_ID = 1; public static final int USER_ID = 1;
public static final int FINGER_PRINT = 2;
public int type; public int type;
public String userId; public String userId;
@ -488,9 +489,11 @@ public class KeyListActivity extends BaseActivity {
public int keySize; public int keySize;
public boolean canSign; public boolean canSign;
public boolean canEncrypt; public boolean canEncrypt;
public String fingerPrint;
public KeyChild(long keyId, boolean isMasterKey, int algorithm, int keySize, public KeyChild(long keyId, boolean isMasterKey, int algorithm, int keySize,
boolean canSign, boolean canEncrypt) { boolean canSign, boolean canEncrypt) {
this.type = KEY;
this.keyId = keyId; this.keyId = keyId;
this.isMasterKey = isMasterKey; this.isMasterKey = isMasterKey;
this.algorithm = algorithm; this.algorithm = algorithm;
@ -503,6 +506,11 @@ public class KeyListActivity extends BaseActivity {
type = USER_ID; type = USER_ID;
this.userId = userId; this.userId = userId;
} }
public KeyChild(String fingerPrint, boolean isFingerPrint) {
type = FINGER_PRINT;
this.fingerPrint = fingerPrint;
}
} }
public KeyListAdapter(Context context, String searchString) { public KeyListAdapter(Context context, String searchString) {
@ -604,18 +612,21 @@ public class KeyListActivity extends BaseActivity {
new String[] { mCursor.getString(0) }, new String[] { mCursor.getString(0) },
null, null, Keys.RANK + " ASC"); null, null, Keys.RANK + " ASC");
long masterKeyId = -1; int masterKeyId = -1;
long fingerPrintId = -1;
for (int i = 0; i < c.getCount(); ++i) { for (int i = 0; i < c.getCount(); ++i) {
c.moveToPosition(i); c.moveToPosition(i);
children.add(new KeyChild(c.getLong(1), c.getInt(2) == 1, c.getInt(3), c.getInt(4), children.add(new KeyChild(c.getLong(1), c.getInt(2) == 1, c.getInt(3), c.getInt(4),
c.getInt(5) == 1, c.getInt(6) == 1)); c.getInt(5) == 1, c.getInt(6) == 1));
if (i == 0) { if (i == 0) {
masterKeyId = c.getInt(0); masterKeyId = c.getInt(0);
fingerPrintId = c.getLong(1);
} }
} }
c.close(); c.close();
if (masterKeyId != -1) { if (masterKeyId != -1) {
children.insertElementAt(new KeyChild(Apg.getFingerPrint(fingerPrintId), true), 0);
c = mDatabase.query(UserIds.TABLE_NAME, c = mDatabase.query(UserIds.TABLE_NAME,
new String[] { new String[] {
UserIds.USER_ID, // 0 UserIds.USER_ID, // 0
@ -725,7 +736,7 @@ public class KeyListActivity extends BaseActivity {
} }
TextView keyId = (TextView) view.findViewById(R.id.keyId); TextView keyId = (TextView) view.findViewById(R.id.keyId);
String keyIdStr = Apg.getFingerPrint(child.keyId); String keyIdStr = Apg.getSmallFingerPrint(child.keyId);
keyId.setText(keyIdStr); keyId.setText(keyIdStr);
TextView keyDetails = (TextView) view.findViewById(R.id.keyDetails); TextView keyDetails = (TextView) view.findViewById(R.id.keyDetails);
String algorithmStr = Apg.getAlgorithmInfo(child.algorithm, child.keySize); String algorithmStr = Apg.getAlgorithmInfo(child.algorithm, child.keySize);
@ -749,6 +760,14 @@ public class KeyListActivity extends BaseActivity {
userId.setText(child.userId); userId.setText(child.userId);
break; break;
} }
case KeyChild.FINGER_PRINT: {
view = mInflater.inflate(R.layout.key_list_child_item_user_id, null);
TextView userId = (TextView) view.findViewById(R.id.userId);
userId.setText(getString(R.string.fingerprint) + ":\n" +
child.fingerPrint.replace(" ", "\n"));
break;
}
} }
return view; return view;
} }

View File

@ -253,7 +253,7 @@ public class KeyServerQueryActivity extends BaseActivity {
mainUserId.setText(userId); mainUserId.setText(userId);
} }
keyId.setText(Apg.getFingerPrint(keyInfo.keyId)); keyId.setText(Apg.getSmallFingerPrint(keyInfo.keyId));
if (mainUserIdRest.getText().length() == 0) { if (mainUserIdRest.getText().length() == 0) {
mainUserIdRest.setVisibility(View.GONE); mainUserIdRest.setVisibility(View.GONE);

View File

@ -187,7 +187,7 @@ public class SelectPublicKeyListAdapter extends BaseAdapter {
} }
long masterKeyId = mCursor.getLong(1); // MASTER_KEY_ID long masterKeyId = mCursor.getLong(1); // MASTER_KEY_ID
keyId.setText(Apg.getFingerPrint(masterKeyId)); keyId.setText(Apg.getSmallFingerPrint(masterKeyId));
if (mainUserIdRest.getText().length() == 0) { if (mainUserIdRest.getText().length() == 0) {
mainUserIdRest.setVisibility(View.GONE); mainUserIdRest.setVisibility(View.GONE);

View File

@ -146,7 +146,7 @@ public class SelectSecretKeyListAdapter extends BaseAdapter {
} }
long masterKeyId = mCursor.getLong(1); // MASTER_KEY_ID long masterKeyId = mCursor.getLong(1); // MASTER_KEY_ID
keyId.setText(Apg.getFingerPrint(masterKeyId)); keyId.setText(Apg.getSmallFingerPrint(masterKeyId));
if (mainUserIdRest.getText().length() == 0) { if (mainUserIdRest.getText().length() == 0) {
mainUserIdRest.setVisibility(View.GONE); mainUserIdRest.setVisibility(View.GONE);

View File

@ -141,8 +141,8 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
} }
mAlgorithm.setText(Apg.getAlgorithmInfo(key)); mAlgorithm.setText(Apg.getAlgorithmInfo(key));
String keyId1Str = Apg.getFingerPrint(key.getKeyID()); String keyId1Str = Apg.getSmallFingerPrint(key.getKeyID());
String keyId2Str = Apg.getFingerPrint(key.getKeyID() >> 32); String keyId2Str = Apg.getSmallFingerPrint(key.getKeyID() >> 32);
mKeyId.setText(keyId1Str + " " + keyId2Str); mKeyId.setText(keyId1Str + " " + keyId2Str);
Vector<Choice> choices = new Vector<Choice>(); Vector<Choice> choices = new Vector<Choice>();