diff --git a/res/values/strings.xml b/res/values/strings.xml
index 763a5a6bd..5b29e4f12 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -139,6 +139,7 @@
expired
not valid
%s key server(s)
+ fingerprint
None
diff --git a/src/org/thialfihar/android/apg/Apg.java b/src/org/thialfihar/android/apg/Apg.java
index d3be3907c..b7d327077 100644
--- a/src/org/thialfihar/android/apg/Apg.java
+++ b/src/org/thialfihar/android/apg/Apg.java
@@ -1031,6 +1031,34 @@ public class Apg {
}
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();
while (fingerPrint.length() < 8) {
fingerPrint = "0" + fingerPrint;
@@ -1039,7 +1067,7 @@ public class Apg {
}
public static String keyToHex(long keyId) {
- return getFingerPrint(keyId >> 32) + getFingerPrint(keyId);
+ return getSmallFingerPrint(keyId >> 32) + getSmallFingerPrint(keyId);
}
public static long keyFromHex(String data) {
diff --git a/src/org/thialfihar/android/apg/DecryptActivity.java b/src/org/thialfihar/android/apg/DecryptActivity.java
index e126a4c12..b79645d46 100644
--- a/src/org/thialfihar/android/apg/DecryptActivity.java
+++ b/src/org/thialfihar/android/apg/DecryptActivity.java
@@ -620,7 +620,7 @@ public class DecryptActivity extends BaseActivity {
if (data.getBoolean(Apg.EXTRA_SIGNATURE)) {
String userId = data.getString(Apg.EXTRA_SIGNATURE_USER_ID);
mSignatureKeyId = data.getLong(Apg.EXTRA_SIGNATURE_KEY_ID);
- mUserIdRest.setText("id: " + Apg.getFingerPrint(mSignatureKeyId));
+ mUserIdRest.setText("id: " + Apg.getSmallFingerPrint(mSignatureKeyId));
if (userId == null) {
userId = getResources().getString(R.string.unknownUserId);
}
@@ -727,7 +727,7 @@ public class DecryptActivity extends BaseActivity {
alert.setIcon(android.R.drawable.ic_dialog_alert);
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,
new DialogInterface.OnClickListener() {
diff --git a/src/org/thialfihar/android/apg/HkpKeyServer.java b/src/org/thialfihar/android/apg/HkpKeyServer.java
index 472218096..9f363d2e0 100644
--- a/src/org/thialfihar/android/apg/HkpKeyServer.java
+++ b/src/org/thialfihar/android/apg/HkpKeyServer.java
@@ -149,7 +149,7 @@ public class HkpKeyServer extends KeyServer {
info.size = Integer.parseInt(matcher.group(1));
info.algorithm = matcher.group(2);
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("-");
info.date = new GregorianCalendar(Integer.parseInt(chunks[0]),
Integer.parseInt(chunks[1]),
diff --git a/src/org/thialfihar/android/apg/KeyListActivity.java b/src/org/thialfihar/android/apg/KeyListActivity.java
index 2f9d15326..57a7f5de1 100644
--- a/src/org/thialfihar/android/apg/KeyListActivity.java
+++ b/src/org/thialfihar/android/apg/KeyListActivity.java
@@ -479,6 +479,7 @@ public class KeyListActivity extends BaseActivity {
private class KeyChild {
public static final int KEY = 0;
public static final int USER_ID = 1;
+ public static final int FINGER_PRINT = 2;
public int type;
public String userId;
@@ -488,9 +489,11 @@ public class KeyListActivity extends BaseActivity {
public int keySize;
public boolean canSign;
public boolean canEncrypt;
+ public String fingerPrint;
public KeyChild(long keyId, boolean isMasterKey, int algorithm, int keySize,
boolean canSign, boolean canEncrypt) {
+ this.type = KEY;
this.keyId = keyId;
this.isMasterKey = isMasterKey;
this.algorithm = algorithm;
@@ -503,6 +506,11 @@ public class KeyListActivity extends BaseActivity {
type = USER_ID;
this.userId = userId;
}
+
+ public KeyChild(String fingerPrint, boolean isFingerPrint) {
+ type = FINGER_PRINT;
+ this.fingerPrint = fingerPrint;
+ }
}
public KeyListAdapter(Context context, String searchString) {
@@ -604,18 +612,21 @@ public class KeyListActivity extends BaseActivity {
new String[] { mCursor.getString(0) },
null, null, Keys.RANK + " ASC");
- long masterKeyId = -1;
+ int masterKeyId = -1;
+ long fingerPrintId = -1;
for (int i = 0; i < c.getCount(); ++i) {
c.moveToPosition(i);
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));
if (i == 0) {
masterKeyId = c.getInt(0);
+ fingerPrintId = c.getLong(1);
}
}
c.close();
if (masterKeyId != -1) {
+ children.insertElementAt(new KeyChild(Apg.getFingerPrint(fingerPrintId), true), 0);
c = mDatabase.query(UserIds.TABLE_NAME,
new String[] {
UserIds.USER_ID, // 0
@@ -725,7 +736,7 @@ public class KeyListActivity extends BaseActivity {
}
TextView keyId = (TextView) view.findViewById(R.id.keyId);
- String keyIdStr = Apg.getFingerPrint(child.keyId);
+ String keyIdStr = Apg.getSmallFingerPrint(child.keyId);
keyId.setText(keyIdStr);
TextView keyDetails = (TextView) view.findViewById(R.id.keyDetails);
String algorithmStr = Apg.getAlgorithmInfo(child.algorithm, child.keySize);
@@ -749,6 +760,14 @@ public class KeyListActivity extends BaseActivity {
userId.setText(child.userId);
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;
}
diff --git a/src/org/thialfihar/android/apg/KeyServerQueryActivity.java b/src/org/thialfihar/android/apg/KeyServerQueryActivity.java
index 53d6614b5..01cfec0c0 100644
--- a/src/org/thialfihar/android/apg/KeyServerQueryActivity.java
+++ b/src/org/thialfihar/android/apg/KeyServerQueryActivity.java
@@ -253,7 +253,7 @@ public class KeyServerQueryActivity extends BaseActivity {
mainUserId.setText(userId);
}
- keyId.setText(Apg.getFingerPrint(keyInfo.keyId));
+ keyId.setText(Apg.getSmallFingerPrint(keyInfo.keyId));
if (mainUserIdRest.getText().length() == 0) {
mainUserIdRest.setVisibility(View.GONE);
diff --git a/src/org/thialfihar/android/apg/SelectPublicKeyListAdapter.java b/src/org/thialfihar/android/apg/SelectPublicKeyListAdapter.java
index e1277a4b7..8eaa400ee 100644
--- a/src/org/thialfihar/android/apg/SelectPublicKeyListAdapter.java
+++ b/src/org/thialfihar/android/apg/SelectPublicKeyListAdapter.java
@@ -187,7 +187,7 @@ public class SelectPublicKeyListAdapter extends BaseAdapter {
}
long masterKeyId = mCursor.getLong(1); // MASTER_KEY_ID
- keyId.setText(Apg.getFingerPrint(masterKeyId));
+ keyId.setText(Apg.getSmallFingerPrint(masterKeyId));
if (mainUserIdRest.getText().length() == 0) {
mainUserIdRest.setVisibility(View.GONE);
diff --git a/src/org/thialfihar/android/apg/SelectSecretKeyListAdapter.java b/src/org/thialfihar/android/apg/SelectSecretKeyListAdapter.java
index 979518e68..3b41d1626 100644
--- a/src/org/thialfihar/android/apg/SelectSecretKeyListAdapter.java
+++ b/src/org/thialfihar/android/apg/SelectSecretKeyListAdapter.java
@@ -146,7 +146,7 @@ public class SelectSecretKeyListAdapter extends BaseAdapter {
}
long masterKeyId = mCursor.getLong(1); // MASTER_KEY_ID
- keyId.setText(Apg.getFingerPrint(masterKeyId));
+ keyId.setText(Apg.getSmallFingerPrint(masterKeyId));
if (mainUserIdRest.getText().length() == 0) {
mainUserIdRest.setVisibility(View.GONE);
diff --git a/src/org/thialfihar/android/apg/ui/widget/KeyEditor.java b/src/org/thialfihar/android/apg/ui/widget/KeyEditor.java
index e61451fc0..dbdae9def 100644
--- a/src/org/thialfihar/android/apg/ui/widget/KeyEditor.java
+++ b/src/org/thialfihar/android/apg/ui/widget/KeyEditor.java
@@ -141,8 +141,8 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
}
mAlgorithm.setText(Apg.getAlgorithmInfo(key));
- String keyId1Str = Apg.getFingerPrint(key.getKeyID());
- String keyId2Str = Apg.getFingerPrint(key.getKeyID() >> 32);
+ String keyId1Str = Apg.getSmallFingerPrint(key.getKeyID());
+ String keyId2Str = Apg.getSmallFingerPrint(key.getKeyID() >> 32);
mKeyId.setText(keyId1Str + " " + keyId2Str);
Vector choices = new Vector();