diff options
author | Dominik Schürmann <dominik@dominikschuermann.de> | 2015-09-24 14:11:20 +0200 |
---|---|---|
committer | Dominik Schürmann <dominik@dominikschuermann.de> | 2015-09-24 14:11:20 +0200 |
commit | fd80d48f5085032839aa5ddabe32eb4e7c06a1c6 (patch) | |
tree | 8789458527820e707797714d66b54e57014b5b18 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui | |
parent | de8eed664f32432ab214cb1a074dd28944fc3be9 (diff) | |
download | open-keychain-fd80d48f5085032839aa5ddabe32eb4e7c06a1c6.tar.gz open-keychain-fd80d48f5085032839aa5ddabe32eb4e7c06a1c6.tar.bz2 open-keychain-fd80d48f5085032839aa5ddabe32eb4e7c06a1c6.zip |
phrase confirmation
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui')
2 files changed, 12 insertions, 129 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyFingerprintFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyFingerprintFragment.java index 552fa34c0..d9bc08268 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyFingerprintFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyFingerprintFragment.java @@ -33,12 +33,14 @@ import android.widget.TextView; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; +import org.sufficientlysecure.keychain.experimental.SentenceConfirm; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.ProviderHelper; -import org.sufficientlysecure.keychain.ui.util.ExperimentalWordConfirm; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.util.Log; +import java.io.IOException; + public class CertifyFingerprintFragment extends LoaderFragment implements LoaderManager.LoaderCallbacks<Cursor> { @@ -180,9 +182,16 @@ public class CertifyFingerprintFragment extends LoaderFragment implements } private void displayWordConfirm(byte[] fingerprintBlob) { - String fingerprint = ExperimentalWordConfirm.getWords(getActivity(), fingerprintBlob); +// String fingerprint = ExperimentalWordConfirm.getWords(getActivity(), fingerprintBlob); + + String fingerprint; + try { + fingerprint = new SentenceConfirm(getActivity()).fromBytes(fingerprintBlob, 16); + } catch (IOException ioe) { + fingerprint = "-"; + } - mFingerprint.setTextSize(24); + mFingerprint.setTextSize(18); mFingerprint.setTypeface(Typeface.DEFAULT, Typeface.BOLD); mFingerprint.setText(fingerprint); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/ExperimentalWordConfirm.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/ExperimentalWordConfirm.java deleted file mode 100644 index 43ccac24f..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/ExperimentalWordConfirm.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (C) 2015 Dominik Schürmann <dominik@dominikschuermann.de> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package org.sufficientlysecure.keychain.ui.util; - -import android.content.Context; - -import org.spongycastle.util.Arrays; -import org.sufficientlysecure.keychain.Constants; -import org.sufficientlysecure.keychain.util.Log; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.BitSet; - -public class ExperimentalWordConfirm { - - public static String getWords(Context context, byte[] fingerprintBlob) { - ArrayList<String> words = new ArrayList<>(); - - BufferedReader reader = null; - try { - reader = new BufferedReader(new InputStreamReader( - context.getAssets().open("word_confirm_list.txt"), - "UTF-8" - )); - - String line = reader.readLine(); - while (line != null) { - words.add(line); - - line = reader.readLine(); - } - } catch (IOException e) { - throw new RuntimeException("IOException", e); - } finally { - if (reader != null) { - try { - reader.close(); - } catch (IOException ignored) { - } - } - } - - String fingerprint = ""; - - // NOTE: 160 bit SHA-1 truncated to 156 bit - byte[] fingerprintBlobTruncated = Arrays.copyOfRange(fingerprintBlob, 0, 156 / 8); - - // TODO: implement key stretching to minimize fp length? - - // BitSet bits = BitSet.valueOf(fingerprintBlob); // min API 19 and little endian! - BitSet bits = bitSetToByteArray(fingerprintBlobTruncated); - Log.d(Constants.TAG, "bits: " + bits.toString()); - - final int CHUNK_SIZE = 13; - final int LAST_CHUNK_INDEX = fingerprintBlobTruncated.length * 8 / CHUNK_SIZE; // 12 - Log.d(Constants.TAG, "LAST_CHUNK_INDEX: " + LAST_CHUNK_INDEX); - - int from = 0; - int to = CHUNK_SIZE; - for (int i = 0; i < (LAST_CHUNK_INDEX + 1); i++) { - Log.d(Constants.TAG, "from: " + from + " to: " + to); - - BitSet setIndex = bits.get(from, to); - int wordIndex = (int) bitSetToLong(setIndex); - // int wordIndex = (int) setIndex.toLongArray()[0]; // min API 19 - - fingerprint += words.get(wordIndex); - - if (i != LAST_CHUNK_INDEX) { - // line break every 3 words - if (to % (CHUNK_SIZE * 3) == 0) { - fingerprint += "\n"; - } else { - fingerprint += " "; - } - } - - from = to; - to += CHUNK_SIZE; - } - - return fingerprint; - } - - /** - * Returns a BitSet containing the values in bytes. - * BIG ENDIAN! - */ - private static BitSet bitSetToByteArray(byte[] bytes) { - int arrayLength = bytes.length * 8; - BitSet bits = new BitSet(); - - for (int i = 0; i < arrayLength; i++) { - if ((bytes[bytes.length - i / 8 - 1] & (1 << (i % 8))) > 0) { - bits.set(i); - } - } - return bits; - } - - private static long bitSetToLong(BitSet bits) { - long value = 0L; - for (int i = 0; i < bits.length(); ++i) { - value += bits.get(i) ? (1L << i) : 0L; - } - return value; - } -} |