update display of signing key fingerprint
Update Utils.formatFingerprint() to create a more readible version of the SHA-256 fingerprint of the signing key of the repo.
This commit is contained in:
parent
a02f985efa
commit
04b5db1f4c
@ -168,7 +168,7 @@
|
|||||||
<string name="unsigned">Unsigned</string>
|
<string name="unsigned">Unsigned</string>
|
||||||
<string name="repo_url">URL</string>
|
<string name="repo_url">URL</string>
|
||||||
<string name="repo_num_apps">Number of apps</string>
|
<string name="repo_num_apps">Number of apps</string>
|
||||||
<string name="repo_fingerprint">Fingerprint of Repo Signing Key (SHA1)</string>
|
<string name="repo_fingerprint">Fingerprint of Repo Signing Key (SHA-256)</string>
|
||||||
<string name="repo_description">Description</string>
|
<string name="repo_description">Description</string>
|
||||||
<string name="repo_last_update">Last update</string>
|
<string name="repo_last_update">Last update</string>
|
||||||
<string name="repo_update">Update</string>
|
<string name="repo_update">Update</string>
|
||||||
|
@ -18,26 +18,20 @@
|
|||||||
|
|
||||||
package org.fdroid.fdroid;
|
package org.fdroid.fdroid;
|
||||||
|
|
||||||
import android.os.Build;
|
import android.content.Context;
|
||||||
import android.util.Log;
|
|
||||||
|
import com.nostra13.universalimageloader.utils.StorageUtils;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.security.MessageDigest;
|
|
||||||
import java.util.Formatter;
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import com.nostra13.universalimageloader.utils.StorageUtils;
|
|
||||||
import org.fdroid.fdroid.data.Repo;
|
|
||||||
|
|
||||||
public final class Utils {
|
public final class Utils {
|
||||||
|
|
||||||
public static final int BUFFER_SIZE = 4096;
|
public static final int BUFFER_SIZE = 4096;
|
||||||
@ -48,8 +42,6 @@ public final class Utils {
|
|||||||
public static final SimpleDateFormat LOG_DATE_FORMAT =
|
public static final SimpleDateFormat LOG_DATE_FORMAT =
|
||||||
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH);
|
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void copy(InputStream input, OutputStream output)
|
public static void copy(InputStream input, OutputStream output)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
copy(input, output, null, null);
|
copy(input, output, null, null);
|
||||||
@ -160,36 +152,16 @@ public final class Utils {
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String formatFingerprint(Repo repo) {
|
// return a fingerprint formatted for display
|
||||||
return formatFingerprint(repo.pubkey);
|
public static String formatFingerprint(String fingerprint) {
|
||||||
|
if (fingerprint.length() != 62) // SHA-256 is 62 hex chars
|
||||||
|
return "BAD FINGERPRINT";
|
||||||
|
String displayFP = fingerprint.substring(0, 2);
|
||||||
|
for (int i = 2; i < fingerprint.length(); i = i + 2)
|
||||||
|
displayFP += " " + fingerprint.substring(i, i + 2);
|
||||||
|
return displayFP;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String formatFingerprint(String key) {
|
|
||||||
String fingerprintString;
|
|
||||||
if (key == null) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
MessageDigest digest = MessageDigest.getInstance("SHA-1");
|
|
||||||
digest.update(Hasher.unhex(key));
|
|
||||||
byte[] fingerprint = digest.digest();
|
|
||||||
Formatter formatter = new Formatter(new StringBuilder());
|
|
||||||
formatter.format("%02X", fingerprint[0]);
|
|
||||||
for (int i = 1; i < fingerprint.length; i++) {
|
|
||||||
formatter.format(i % 5 == 0 ? " %02X" : ":%02X",
|
|
||||||
fingerprint[i]);
|
|
||||||
}
|
|
||||||
fingerprintString = formatter.toString();
|
|
||||||
formatter.close();
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.w("FDroid", "Unable to get certificate fingerprint.\n"
|
|
||||||
+ Log.getStackTraceString(e));
|
|
||||||
fingerprintString = "";
|
|
||||||
}
|
|
||||||
return fingerprintString;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static File getApkCacheDir(Context context) {
|
public static File getApkCacheDir(Context context) {
|
||||||
File apkCacheDir = new File(
|
File apkCacheDir = new File(
|
||||||
StorageUtils.getCacheDirectory(context, true), "apks");
|
StorageUtils.getCacheDirectory(context, true), "apks");
|
||||||
|
@ -8,6 +8,7 @@ import android.os.Bundle;
|
|||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.view.MenuItemCompat;
|
import android.support.v4.view.MenuItemCompat;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
@ -286,15 +287,17 @@ public class RepoDetailsFragment extends Fragment {
|
|||||||
String repoFingerprint;
|
String repoFingerprint;
|
||||||
int repoFingerprintColor;
|
int repoFingerprintColor;
|
||||||
|
|
||||||
if (repo.pubkey != null && repo.pubkey.length() > 0) {
|
// TODO show the current state of the signature check, not just whether there is a key or not
|
||||||
repoFingerprint = Utils.formatFingerprint(repo.pubkey);
|
if (TextUtils.isEmpty(repo.fingerprint) && TextUtils.isEmpty(repo.pubkey)) {
|
||||||
repoFingerprintColor = getResources().getColor(R.color.signed);
|
repoFingerprint = getResources().getString(R.string.unsigned);
|
||||||
repoFingerprintDescView.setVisibility(View.GONE);
|
|
||||||
} else {
|
|
||||||
repoFingerprint = getResources().getString(R.string.unsigned);
|
|
||||||
repoFingerprintColor = getResources().getColor(R.color.unsigned);
|
repoFingerprintColor = getResources().getColor(R.color.unsigned);
|
||||||
repoFingerprintDescView.setVisibility(View.VISIBLE);
|
repoFingerprintDescView.setVisibility(View.VISIBLE);
|
||||||
repoFingerprintDescView.setText(getResources().getString(R.string.unsigned_description));
|
repoFingerprintDescView.setText(getResources().getString(R.string.unsigned_description));
|
||||||
|
} else {
|
||||||
|
// this is based on repo.fingerprint always existing, which it should
|
||||||
|
repoFingerprint = Utils.formatFingerprint(repo.fingerprint);
|
||||||
|
repoFingerprintColor = getResources().getColor(R.color.signed);
|
||||||
|
repoFingerprintDescView.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
repoFingerprintView.setText(repoFingerprint);
|
repoFingerprintView.setText(repoFingerprint);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user