mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-30 12:32:17 -05:00
show key fingerprint in key list
Fixes issue 76
This commit is contained in:
parent
9e54b3d99d
commit
9e8b266bf0
@ -139,6 +139,7 @@
|
||||
<string name="expired">expired</string>
|
||||
<string name="notValid">not valid</string>
|
||||
<string name="nKeyServers">%s key server(s)</string>
|
||||
<string name="fingerprint">fingerprint</string>
|
||||
|
||||
<!-- choice_lowerCase: capitalized first word, no punctuation -->
|
||||
<string name="choice_none">None</string>
|
||||
|
@ -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) {
|
||||
|
@ -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() {
|
||||
|
@ -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]),
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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<Choice> choices = new Vector<Choice>();
|
||||
|
Loading…
Reference in New Issue
Block a user