aboutsummaryrefslogtreecommitdiffstats
path: root/OpenPGP-Keychain/src/org
diff options
context:
space:
mode:
authorDominik Schürmann <dominik@dominikschuermann.de>2014-01-19 00:45:53 +0100
committerDominik Schürmann <dominik@dominikschuermann.de>2014-01-19 00:45:53 +0100
commit88aa439ea71d49462616e20aa4042052d0290647 (patch)
treedeb9474fbf5997df1fbfc60efb8287a7e0ba76d3 /OpenPGP-Keychain/src/org
parent1bac2849b8ed8c5ab05e846c1e4b2e1aff5269aa (diff)
downloadopen-keychain-88aa439ea71d49462616e20aa4042052d0290647.tar.gz
open-keychain-88aa439ea71d49462616e20aa4042052d0290647.tar.bz2
open-keychain-88aa439ea71d49462616e20aa4042052d0290647.zip
fix qr code scanning, implement basic scanning of fingerprint only
Diffstat (limited to 'OpenPGP-Keychain/src/org')
-rw-r--r--OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/ImportKeysQrCodeFragment.java160
-rw-r--r--OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/KeyServerQueryActivity.java58
-rw-r--r--OpenPGP-Keychain/src/org/sufficientlysecure/keychain/util/IntentIntegratorSupportV4.java47
3 files changed, 172 insertions, 93 deletions
diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/ImportKeysQrCodeFragment.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/ImportKeysQrCodeFragment.java
index 58a1400b0..3ede641d3 100644
--- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/ImportKeysQrCodeFragment.java
+++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/ImportKeysQrCodeFragment.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de>
+ * Copyright (C) 2013-2014 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
@@ -18,9 +18,11 @@
package org.sufficientlysecure.keychain.ui;
import java.util.ArrayList;
+import java.util.Locale;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
+import org.sufficientlysecure.keychain.util.IntentIntegratorSupportV4;
import org.sufficientlysecure.keychain.util.Log;
import android.content.Intent;
@@ -35,7 +37,6 @@ import android.widget.TextView;
import android.widget.Toast;
import com.beardedhen.androidbootstrap.BootstrapButton;
-import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;
public class ImportKeysQrCodeFragment extends Fragment {
@@ -75,7 +76,7 @@ public class ImportKeysQrCodeFragment extends Fragment {
@Override
public void onClick(View v) {
// scan using xzing's Barcode Scanner
- new IntentIntegrator(getActivity()).initiateScan();
+ new IntentIntegratorSupportV4(ImportKeysQrCodeFragment.this).initiateScan();
}
});
@@ -92,88 +93,117 @@ public class ImportKeysQrCodeFragment extends Fragment {
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode & 0xFFFF) {
- case IntentIntegrator.REQUEST_CODE: {
- IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode,
- data);
+ case IntentIntegratorSupportV4.REQUEST_CODE: {
+ IntentResult scanResult = IntentIntegratorSupportV4.parseActivityResult(requestCode,
+ resultCode, data);
if (scanResult != null && scanResult.getFormatName() != null) {
- Log.d(Constants.TAG, scanResult.getContents());
+ Log.d(Constants.TAG, "scanResult content: " + scanResult.getContents());
- String[] parts = scanResult.getContents().split(",");
+ // look if it's fingerprint only
+ if (scanResult.getContents().toLowerCase(Locale.ENGLISH).startsWith("openpgp4fpr")) {
+ importFingerprint(scanResult.getContents().toLowerCase(Locale.ENGLISH));
+ return;
+ }
- if (parts.length != 3) {
- Toast.makeText(getActivity(), R.string.import_qr_code_wrong, Toast.LENGTH_LONG)
- .show();
+ // look if it is the whole key
+ String[] parts = scanResult.getContents().split(",");
+ if (parts.length == 3) {
+ importParts(parts);
return;
}
- int counter = Integer.valueOf(parts[0]);
- int size = Integer.valueOf(parts[1]);
- String content = parts[2];
+ // fail...
+ Toast.makeText(getActivity(), R.string.import_qr_code_wrong, Toast.LENGTH_LONG)
+ .show();
+ }
- Log.d(Constants.TAG, "" + counter);
- Log.d(Constants.TAG, "" + size);
- Log.d(Constants.TAG, "" + content);
+ break;
+ }
- // first qr code -> setup
- if (counter == 0) {
- mScannedContent = new String[size];
- mProgress.setMax(size);
- mProgress.setVisibility(View.VISIBLE);
- mText.setVisibility(View.VISIBLE);
- }
+ default:
+ super.onActivityResult(requestCode, resultCode, data);
- if (mScannedContent == null || counter > mScannedContent.length) {
- Toast.makeText(getActivity(), R.string.import_qr_code_start_with_one,
- Toast.LENGTH_LONG).show();
- return;
- }
+ break;
+ }
+ }
- // save scanned content
- mScannedContent[counter] = content;
+ private void importFingerprint(String uri) {
+ String fingerprint = uri.split(":")[1];
- // get missing numbers
- ArrayList<Integer> missing = new ArrayList<Integer>();
- for (int i = 0; i < mScannedContent.length; i++) {
- if (mScannedContent[i] == null) {
- missing.add(i);
- }
- }
+ Log.d(Constants.TAG, "fingerprint: " + fingerprint);
+
+ if (fingerprint.length() < 16) {
+ Toast.makeText(getActivity(), R.string.import_qr_code_too_short_fingerprint,
+ Toast.LENGTH_LONG).show();
+ return;
+ }
- // update progress and text
- int alreadyScanned = mScannedContent.length - missing.size();
- mProgress.setProgress(alreadyScanned);
+ Intent queryIntent = new Intent(getActivity(), KeyServerQueryActivity.class);
+ queryIntent.setAction(KeyServerQueryActivity.ACTION_LOOK_UP_KEY_ID);
+ queryIntent.putExtra(KeyServerQueryActivity.EXTRA_FINGERPRINT, fingerprint);
+ startActivity(queryIntent);
+ }
- String missingString = "";
- for (int m : missing) {
- if (!missingString.equals("")) {
- missingString += ", ";
- }
- missingString += String.valueOf(m + 1);
- }
+ private void importParts(String[] parts) {
+ int counter = Integer.valueOf(parts[0]);
+ int size = Integer.valueOf(parts[1]);
+ String content = parts[2];
+
+ Log.d(Constants.TAG, "" + counter);
+ Log.d(Constants.TAG, "" + size);
+ Log.d(Constants.TAG, "" + content);
+
+ // first qr code -> setup
+ if (counter == 0) {
+ mScannedContent = new String[size];
+ mProgress.setMax(size);
+ mProgress.setVisibility(View.VISIBLE);
+ mText.setVisibility(View.VISIBLE);
+ }
- String missingText = getResources().getQuantityString(
- R.plurals.import_qr_code_missing, missing.size(), missingString);
- mText.setText(missingText);
-
- // finished!
- if (missing.size() == 0) {
- mText.setText(R.string.import_qr_code_finished);
- String result = "";
- for (String in : mScannedContent) {
- result += in;
- }
- mImportActivity.loadCallback(result.getBytes(), null);
- }
+ if (mScannedContent == null || counter > mScannedContent.length) {
+ Toast.makeText(getActivity(), R.string.import_qr_code_start_with_one, Toast.LENGTH_LONG)
+ .show();
+ return;
+ }
+
+ // save scanned content
+ mScannedContent[counter] = content;
+
+ // get missing numbers
+ ArrayList<Integer> missing = new ArrayList<Integer>();
+ for (int i = 0; i < mScannedContent.length; i++) {
+ if (mScannedContent[i] == null) {
+ missing.add(i);
}
+ }
- break;
+ // update progress and text
+ int alreadyScanned = mScannedContent.length - missing.size();
+ mProgress.setProgress(alreadyScanned);
+
+ String missingString = "";
+ for (int m : missing) {
+ if (!missingString.equals("")) {
+ missingString += ", ";
+ }
+ missingString += String.valueOf(m + 1);
}
- default:
- super.onActivityResult(requestCode, resultCode, data);
+ String missingText = getResources().getQuantityString(R.plurals.import_qr_code_missing,
+ missing.size(), missingString);
+ mText.setText(missingText);
- break;
+ // finished!
+ if (missing.size() == 0) {
+ mText.setText(R.string.import_qr_code_finished);
+ String result = "";
+ for (String in : mScannedContent) {
+ result += in;
+ }
+ mImportActivity.loadCallback(result.getBytes(), null);
}
}
+
}
diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/KeyServerQueryActivity.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/KeyServerQueryActivity.java
index c3ec7b9c3..5e3b3d052 100644
--- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/KeyServerQueryActivity.java
+++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/KeyServerQueryActivity.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2012 Dominik Schürmann <dominik@dominikschuermann.de>
+ * Copyright (C) 2012-2014 Dominik Schürmann <dominik@dominikschuermann.de>
* Copyright (C) 2010 Thialfihar <thi@thialfihar.org>
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -66,23 +66,19 @@ public class KeyServerQueryActivity extends SherlockFragmentActivity {
+ "LOOK_UP_KEY_ID_AND_RETURN";
public static final String EXTRA_KEY_ID = "key_id";
+ public static final String EXTRA_FINGERPRINT = "fingerprint";
public static final String RESULT_EXTRA_TEXT = "text";
private ListView mList;
-
private EditText mQuery;
-
private Button mSearch;
+ private Spinner mKeyServer;
private KeyInfoListAdapter mAdapter;
- private Spinner mKeyServer;
-
private int mQueryType;
-
private String mQueryString;
-
private long mQueryId;
private volatile List<KeyInfo> mSearchResult;
@@ -93,15 +89,15 @@ public class KeyServerQueryActivity extends SherlockFragmentActivity {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
- case android.R.id.home:
- // app icon in Action Bar clicked; go home
- Intent intent = new Intent(this, KeyListPublicActivity.class);
- intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- startActivity(intent);
- return true;
+ case android.R.id.home:
+ // app icon in Action Bar clicked; go home
+ Intent intent = new Intent(this, KeyListPublicActivity.class);
+ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ startActivity(intent);
+ return true;
- default:
- break;
+ default:
+ break;
}
return false;
@@ -113,13 +109,13 @@ public class KeyServerQueryActivity extends SherlockFragmentActivity {
setContentView(R.layout.key_server_query);
- mQuery = (EditText)findViewById(R.id.query);
- mSearch = (Button)findViewById(R.id.btn_search);
- mList = (ListView)findViewById(R.id.list);
+ mQuery = (EditText) findViewById(R.id.query);
+ mSearch = (Button) findViewById(R.id.btn_search);
+ mList = (ListView) findViewById(R.id.list);
mAdapter = new KeyInfoListAdapter(this);
mList.setAdapter(mAdapter);
- mKeyServer = (Spinner)findViewById(R.id.sign_key_keyserver);
+ mKeyServer = (Spinner) findViewById(R.id.sign_key_keyserver);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, Preferences.getPreferences(this)
.getKeyServers());
@@ -168,6 +164,12 @@ public class KeyServerQueryActivity extends SherlockFragmentActivity {
mQuery.setText(query);
search(query);
}
+ String fingerprint = intent.getStringExtra(EXTRA_FINGERPRINT);
+ if (fingerprint != null) {
+ fingerprint = "0x" + fingerprint;
+ mQuery.setText(fingerprint);
+ search(fingerprint);
+ }
}
}
@@ -197,7 +199,7 @@ public class KeyServerQueryActivity extends SherlockFragmentActivity {
// fill values for this action
Bundle data = new Bundle();
- String server = (String)mKeyServer.getSelectedItem();
+ String server = (String) mKeyServer.getSelectedItem();
data.putString(KeychainIntentService.QUERY_KEY_SERVER, server);
data.putInt(KeychainIntentService.QUERY_KEY_TYPE, mQueryType);
@@ -286,7 +288,7 @@ public class KeyServerQueryActivity extends SherlockFragmentActivity {
public KeyInfoListAdapter(Activity activity) {
mActivity = activity;
- mInflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ mInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mKeys = new ArrayList<KeyInfo>();
}
@@ -321,15 +323,15 @@ public class KeyServerQueryActivity extends SherlockFragmentActivity {
View view = mInflater.inflate(R.layout.key_server_query_result_item, null);
- TextView mainUserId = (TextView)view.findViewById(R.id.mainUserId);
+ TextView mainUserId = (TextView) view.findViewById(R.id.mainUserId);
mainUserId.setText(R.string.unknown_user_id);
- TextView mainUserIdRest = (TextView)view.findViewById(R.id.mainUserIdRest);
+ TextView mainUserIdRest = (TextView) view.findViewById(R.id.mainUserIdRest);
mainUserIdRest.setText("");
- TextView keyId = (TextView)view.findViewById(R.id.keyId);
+ TextView keyId = (TextView) view.findViewById(R.id.keyId);
keyId.setText(R.string.no_key);
- TextView algorithm = (TextView)view.findViewById(R.id.algorithm);
+ TextView algorithm = (TextView) view.findViewById(R.id.algorithm);
algorithm.setText("");
- TextView status = (TextView)view.findViewById(R.id.status);
+ TextView status = (TextView) view.findViewById(R.id.status);
status.setText("");
String userId = keyInfo.userIds.get(0);
@@ -356,7 +358,7 @@ public class KeyServerQueryActivity extends SherlockFragmentActivity {
status.setVisibility(View.GONE);
}
- LinearLayout ll = (LinearLayout)view.findViewById(R.id.list);
+ LinearLayout ll = (LinearLayout) view.findViewById(R.id.list);
if (keyInfo.userIds.size() == 1) {
ll.setVisibility(View.GONE);
} else {
@@ -373,7 +375,7 @@ public class KeyServerQueryActivity extends SherlockFragmentActivity {
sep.setBackgroundResource(android.R.drawable.divider_horizontal_dark);
ll.addView(sep);
}
- TextView uidView = (TextView)mInflater.inflate(
+ TextView uidView = (TextView) mInflater.inflate(
R.layout.key_server_query_result_user_id, null);
uidView.setText(uid);
ll.addView(uidView);
diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/util/IntentIntegratorSupportV4.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/util/IntentIntegratorSupportV4.java
new file mode 100644
index 000000000..a43c03e3e
--- /dev/null
+++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/util/IntentIntegratorSupportV4.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2012 ZXing authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.sufficientlysecure.keychain.util;
+
+import android.content.Intent;
+import android.support.v4.app.Fragment;
+
+import com.google.zxing.integration.android.IntentIntegrator;
+
+/**
+ * IntentIntegrator for the V4 Android compatibility package.
+ *
+ * @author Lachezar Dobrev
+ */
+public final class IntentIntegratorSupportV4 extends IntentIntegrator {
+
+ private final Fragment fragment;
+
+ /**
+ * @param fragment
+ * Fragment to handle activity response.
+ */
+ public IntentIntegratorSupportV4(Fragment fragment) {
+ super(fragment.getActivity());
+ this.fragment = fragment;
+ }
+
+ @Override
+ protected void startActivityForResult(Intent intent, int code) {
+ fragment.startActivityForResult(intent, code);
+ }
+
+}