Fix fingerprint handling

This commit is contained in:
Dominik Schürmann 2014-03-20 19:48:18 +01:00
parent df6fff93f0
commit 59d51fe68e
9 changed files with 19 additions and 21 deletions

View File

@ -452,7 +452,7 @@ public class PgpKeyHelper {
key = secretKey.getPublicKey(); key = secretKey.getPublicKey();
} }
return convertFingerprintToHex(key.getFingerprint(), true); return convertFingerprintToHex(key.getFingerprint());
} }
/** /**
@ -465,19 +465,12 @@ public class PgpKeyHelper {
* @param split split into 4 character chunks * @param split split into 4 character chunks
* @return * @return
*/ */
public static String convertFingerprintToHex(byte[] fingerprint, boolean split) { public static String convertFingerprintToHex(byte[] fingerprint) {
String hexString = Hex.toHexString(fingerprint); String hexString = Hex.toHexString(fingerprint);
if (split) {
hexString = splitFingerprintHex(hexString);
}
return hexString; return hexString;
} }
public static String splitFingerprintHex(String hexString) {
return hexString.replaceAll("(.{4})(?!$)", "$1 ");
}
/** /**
* Convert key id from long to 64 bit hex string * Convert key id from long to 64 bit hex string
* <p/> * <p/>
@ -511,6 +504,9 @@ public class PgpKeyHelper {
public static SpannableStringBuilder colorizeFingerprint(String fingerprint) { public static SpannableStringBuilder colorizeFingerprint(String fingerprint) {
// split by 4 characters
fingerprint = fingerprint.replaceAll("(.{4})(?!$)", "$1 ");
// add line breaks to have a consistent "image" that can be recognized // add line breaks to have a consistent "image" that can be recognized
char[] chars = fingerprint.toCharArray(); char[] chars = fingerprint.toCharArray();
chars[24] = '\n'; chars[24] = '\n';

View File

@ -756,7 +756,7 @@ public class KeychainIntentService extends IntentService
// if available use complete fingerprint for get request // if available use complete fingerprint for get request
byte[] downloadedKeyBytes; byte[] downloadedKeyBytes;
if (entry.getFingerPrintHex() != null) { if (entry.getFingerPrintHex() != null) {
downloadedKeyBytes = server.get(entry.getFingerPrintHex()).getBytes(); downloadedKeyBytes = server.get("0x" + entry.getFingerPrintHex()).getBytes();
} else { } else {
downloadedKeyBytes = server.get(entry.getKeyIdHex()).getBytes(); downloadedKeyBytes = server.get(entry.getKeyIdHex()).getBytes();
} }
@ -784,7 +784,7 @@ public class KeychainIntentService extends IntentService
// verify downloaded key by comparing fingerprints // verify downloaded key by comparing fingerprints
if (entry.getFingerPrintHex() != null) { if (entry.getFingerPrintHex() != null) {
String downloadedKeyFp = PgpKeyHelper.convertFingerprintToHex(downloadedKey.getPublicKey().getFingerprint(), false); String downloadedKeyFp = PgpKeyHelper.convertFingerprintToHex(downloadedKey.getPublicKey().getFingerprint());
if (downloadedKeyFp.equals(entry.getFingerPrintHex())) { if (downloadedKeyFp.equals(entry.getFingerPrintHex())) {
Log.d(Constants.TAG, "fingerprint of downloaded key is the same as the requested fingerprint!"); Log.d(Constants.TAG, "fingerprint of downloaded key is the same as the requested fingerprint!");
} else { } else {

View File

@ -198,6 +198,8 @@ public class CertifyKeyActivity extends ActionBarActivity implements
case LOADER_ID_KEYRING: case LOADER_ID_KEYRING:
// the first key here is our master key // the first key here is our master key
if (data.moveToFirst()) { if (data.moveToFirst()) {
// TODO: put findViewById in onCreate!
long keyId = data.getLong(INDEX_MASTER_KEY_ID); long keyId = data.getLong(INDEX_MASTER_KEY_ID);
String keyIdStr = PgpKeyHelper.convertKeyIdToHexShort(keyId); String keyIdStr = PgpKeyHelper.convertKeyIdToHexShort(keyId);
((TextView) findViewById(R.id.key_id)).setText(keyIdStr); ((TextView) findViewById(R.id.key_id)).setText(keyIdStr);
@ -210,7 +212,7 @@ public class CertifyKeyActivity extends ActionBarActivity implements
// FALLBACK for old database entries // FALLBACK for old database entries
fingerprintBlob = ProviderHelper.getFingerprint(this, mDataUri); fingerprintBlob = ProviderHelper.getFingerprint(this, mDataUri);
} }
String fingerprint = PgpKeyHelper.convertFingerprintToHex(fingerprintBlob, true); String fingerprint = PgpKeyHelper.convertFingerprintToHex(fingerprintBlob);
((TextView) findViewById(R.id.fingerprint)).setText(PgpKeyHelper.colorizeFingerprint(fingerprint)); ((TextView) findViewById(R.id.fingerprint)).setText(PgpKeyHelper.colorizeFingerprint(fingerprint));
} }
break; break;

View File

@ -182,7 +182,7 @@ public class ViewKeyActivity extends ActionBarActivity {
String content; String content;
if (fingerprintOnly) { if (fingerprintOnly) {
byte[] fingerprintBlob = ProviderHelper.getFingerprint(this, dataUri); byte[] fingerprintBlob = ProviderHelper.getFingerprint(this, dataUri);
String fingerprint = PgpKeyHelper.convertFingerprintToHex(fingerprintBlob, false); String fingerprint = PgpKeyHelper.convertFingerprintToHex(fingerprintBlob);
content = Constants.FINGERPRINT_SCHEME + ":" + fingerprint; content = Constants.FINGERPRINT_SCHEME + ":" + fingerprint;
} else { } else {

View File

@ -320,7 +320,7 @@ public class ViewKeyMainFragment extends Fragment implements
// FALLBACK for old database entries // FALLBACK for old database entries
fingerprintBlob = ProviderHelper.getFingerprint(getActivity(), mDataUri); fingerprintBlob = ProviderHelper.getFingerprint(getActivity(), mDataUri);
} }
String fingerprint = PgpKeyHelper.convertFingerprintToHex(fingerprintBlob, true); String fingerprint = PgpKeyHelper.convertFingerprintToHex(fingerprintBlob);
mFingerprint.setText(PgpKeyHelper.colorizeFingerprint(fingerprint)); mFingerprint.setText(PgpKeyHelper.colorizeFingerprint(fingerprint));
} }

View File

@ -240,7 +240,7 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
this.revoked = pgpKeyRing.getPublicKey().isRevoked(); this.revoked = pgpKeyRing.getPublicKey().isRevoked();
this.fingerPrintHex = PgpKeyHelper.convertFingerprintToHex(pgpKeyRing.getPublicKey() this.fingerPrintHex = PgpKeyHelper.convertFingerprintToHex(pgpKeyRing.getPublicKey()
.getFingerprint(), true); .getFingerprint());
this.bitStrength = pgpKeyRing.getPublicKey().getBitStrength(); this.bitStrength = pgpKeyRing.getPublicKey().getBitStrength();
final int algorithm = pgpKeyRing.getPublicKey().getAlgorithm(); final int algorithm = pgpKeyRing.getPublicKey().getAlgorithm();
this.algorithm = getAlgorithmFromId(algorithm); this.algorithm = getAlgorithmFromId(algorithm);

View File

@ -90,7 +90,7 @@ public class ShareQrCodeDialogFragment extends DialogFragment {
alert.setPositiveButton(R.string.btn_okay, null); alert.setPositiveButton(R.string.btn_okay, null);
byte[] fingerprintBlob = ProviderHelper.getFingerprint(getActivity(), dataUri); byte[] fingerprintBlob = ProviderHelper.getFingerprint(getActivity(), dataUri);
String fingerprint = PgpKeyHelper.convertFingerprintToHex(fingerprintBlob, false); String fingerprint = PgpKeyHelper.convertFingerprintToHex(fingerprintBlob);
mText.setText(getString(R.string.share_qr_code_dialog_fingerprint_text) + " " + fingerprint); mText.setText(getString(R.string.share_qr_code_dialog_fingerprint_text) + " " + fingerprint);

View File

@ -251,8 +251,7 @@ public class HkpKeyServer extends KeyServer {
// and https://github.com/openpgp-keychain/openpgp-keychain/issues/259#issuecomment-38168176 // and https://github.com/openpgp-keychain/openpgp-keychain/issues/259#issuecomment-38168176
String fingerprintOrKeyId = matcher.group(1); String fingerprintOrKeyId = matcher.group(1);
if (fingerprintOrKeyId.length() > 16) { if (fingerprintOrKeyId.length() > 16) {
entry.setFingerPrintHex(PgpKeyHelper.splitFingerprintHex( entry.setFingerPrintHex(fingerprintOrKeyId.toLowerCase(Locale.US));
fingerprintOrKeyId.toLowerCase(Locale.US)));
entry.setKeyIdHex("0x" + fingerprintOrKeyId.substring(fingerprintOrKeyId.length() entry.setKeyIdHex("0x" + fingerprintOrKeyId.substring(fingerprintOrKeyId.length()
- 16, fingerprintOrKeyId.length())); - 16, fingerprintOrKeyId.length()));
} else { } else {

View File

@ -15,7 +15,7 @@
limitations under the License. limitations under the License.
--> -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
android:paddingLeft="3dip" android:paddingLeft="3dip"
@ -23,7 +23,7 @@
android:singleLine="true" > android:singleLine="true" >
<LinearLayout <LinearLayout
android:layout_width="fill_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal" > android:orientation="horizontal" >
@ -87,6 +87,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="fingerprint" android:text="fingerprint"
android:typeface="monospace"
android:textAppearance="?android:attr/textAppearanceSmall" /> android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView <TextView
@ -100,7 +101,7 @@
<LinearLayout <LinearLayout
android:id="@+id/list" android:id="@+id/list"
android:layout_width="fill_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="36dip" android:layout_marginLeft="36dip"
android:orientation="vertical" > android:orientation="vertical" >