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="repo_url">URL</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_last_update">Last update</string>
 | 
			
		||||
    <string name="repo_update">Update</string>
 | 
			
		||||
 | 
			
		||||
@ -18,26 +18,20 @@
 | 
			
		||||
 | 
			
		||||
package org.fdroid.fdroid;
 | 
			
		||||
 | 
			
		||||
import android.os.Build;
 | 
			
		||||
import android.util.Log;
 | 
			
		||||
import android.content.Context;
 | 
			
		||||
 | 
			
		||||
import com.nostra13.universalimageloader.utils.StorageUtils;
 | 
			
		||||
 | 
			
		||||
import java.io.BufferedReader;
 | 
			
		||||
import java.io.Closeable;
 | 
			
		||||
import java.io.File;
 | 
			
		||||
import java.io.FileReader;
 | 
			
		||||
import java.io.InputStream;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.io.InputStream;
 | 
			
		||||
import java.io.OutputStream;
 | 
			
		||||
import java.text.SimpleDateFormat;
 | 
			
		||||
import java.security.MessageDigest;
 | 
			
		||||
import java.util.Formatter;
 | 
			
		||||
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 static final int BUFFER_SIZE = 4096;
 | 
			
		||||
@ -48,8 +42,6 @@ public final class Utils {
 | 
			
		||||
    public static final SimpleDateFormat LOG_DATE_FORMAT =
 | 
			
		||||
            new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public static void copy(InputStream input, OutputStream output)
 | 
			
		||||
            throws IOException {
 | 
			
		||||
        copy(input, output, null, null);
 | 
			
		||||
@ -160,34 +152,14 @@ public final class Utils {
 | 
			
		||||
        return count;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static String formatFingerprint(Repo repo) {
 | 
			
		||||
        return formatFingerprint(repo.pubkey);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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;
 | 
			
		||||
    // return a fingerprint formatted for display
 | 
			
		||||
    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 File getApkCacheDir(Context context) {
 | 
			
		||||
 | 
			
		||||
@ -8,6 +8,7 @@ import android.os.Bundle;
 | 
			
		||||
import android.support.v4.app.Fragment;
 | 
			
		||||
import android.support.v4.view.MenuItemCompat;
 | 
			
		||||
import android.text.Editable;
 | 
			
		||||
import android.text.TextUtils;
 | 
			
		||||
import android.text.TextWatcher;
 | 
			
		||||
import android.util.Log;
 | 
			
		||||
import android.view.*;
 | 
			
		||||
@ -286,15 +287,17 @@ public class RepoDetailsFragment extends Fragment {
 | 
			
		||||
        String repoFingerprint;
 | 
			
		||||
        int repoFingerprintColor;
 | 
			
		||||
 | 
			
		||||
        if (repo.pubkey != null && repo.pubkey.length() > 0) {
 | 
			
		||||
            repoFingerprint       = Utils.formatFingerprint(repo.pubkey);
 | 
			
		||||
            repoFingerprintColor = getResources().getColor(R.color.signed);
 | 
			
		||||
            repoFingerprintDescView.setVisibility(View.GONE);
 | 
			
		||||
        } else {
 | 
			
		||||
            repoFingerprint       = getResources().getString(R.string.unsigned);
 | 
			
		||||
// TODO show the current state of the signature check, not just whether there is a key or not
 | 
			
		||||
        if (TextUtils.isEmpty(repo.fingerprint) && TextUtils.isEmpty(repo.pubkey)) {
 | 
			
		||||
            repoFingerprint = getResources().getString(R.string.unsigned);
 | 
			
		||||
            repoFingerprintColor = getResources().getColor(R.color.unsigned);
 | 
			
		||||
            repoFingerprintDescView.setVisibility(View.VISIBLE);
 | 
			
		||||
            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);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user