mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-24 01:32:16 -05:00
working on decrypt and restructering...
This commit is contained in:
parent
437ec9c49a
commit
e9c01957f4
@ -42,7 +42,7 @@
|
||||
android:protectionLevel="dangerous" />
|
||||
|
||||
<application
|
||||
android:name="ApgApplication"
|
||||
android:name=".ApgApplication"
|
||||
android:hardwareAccelerated="true"
|
||||
android:icon="@drawable/icon"
|
||||
android:label="@string/app_name"
|
||||
@ -217,9 +217,11 @@
|
||||
android:configChanges="keyboardHidden|orientation|keyboard"
|
||||
android:label="@string/title_preferences" />
|
||||
<activity
|
||||
android:name=".ui.KeyServerPreferenceActivity"
|
||||
android:name=".ui.PreferencesKeyServerActivity"
|
||||
android:configChanges="keyboardHidden|orientation|keyboard"
|
||||
android:label="@string/title_keyServerPreference" />
|
||||
android:label="@string/title_keyServerPreference"
|
||||
android:uiOptions="splitActionBarWhenNarrow"
|
||||
android:windowSoftInputMode="stateHidden" />
|
||||
<activity
|
||||
android:name=".ui.SignKeyActivity"
|
||||
android:configChanges="keyboardHidden|orientation|keyboard"
|
||||
@ -237,7 +239,7 @@
|
||||
|
||||
<!-- TODO: need to be moved into new service model -->
|
||||
<service
|
||||
android:name=".service.ApgService2"
|
||||
android:name=".deprecated.ApgService2"
|
||||
android:enabled="true"
|
||||
android:exported="true"
|
||||
android:permission="org.thialfihar.android.apg.permission.READ_KEY_DETAILS"
|
||||
@ -256,7 +258,7 @@
|
||||
android:authorities="org.thialfihar.android.apg.provider"
|
||||
android:readPermission="org.thialfihar.android.apg.permission.READ_KEY_DETAILS" />
|
||||
<provider
|
||||
android:name=".provider.blob.ApgServiceBlobProvider"
|
||||
android:name=".deprecated.ApgServiceBlobProvider"
|
||||
android:authorities="org.thialfihar.android.apg.provider.apgserviceblobprovider"
|
||||
android:permission="org.thialfihar.android.apg.permission.STORE_BLOBS" />
|
||||
</application>
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2010 Thialfihar <thi@thialfihar.org>
|
||||
<!--
|
||||
Copyright (C) 2010 Thialfihar <thi@thialfihar.org>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@ -14,8 +15,7 @@
|
||||
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_height="fill_parent"
|
||||
android:orientation="vertical" >
|
||||
@ -24,20 +24,20 @@
|
||||
android:id="@+android:id/text_layout"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||
android:gravity="center_vertical">
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="6sp"
|
||||
android:layout_marginLeft="16sp"
|
||||
android:layout_marginRight="6sp"
|
||||
android:layout_marginTop="6sp"
|
||||
android:layout_marginBottom="6sp"
|
||||
android:layout_weight="1"
|
||||
android:focusable="true"
|
||||
android:background="@android:drawable/menuitem_background">
|
||||
android:background="@android:drawable/menuitem_background"
|
||||
android:focusable="true" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
@ -51,23 +51,21 @@
|
||||
android:id="@+id/summary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@android:id/title"
|
||||
android:layout_alignLeft="@android:id/title"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:maxLines="2" />
|
||||
|
||||
android:layout_below="@android:id/title"
|
||||
android:maxLines="2"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
</RelativeLayout>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/add"
|
||||
style="@style/PlusButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginLeft="4dip"
|
||||
android:layout_marginRight="6dip"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:clickable="true"
|
||||
style="@style/PlusButton"/>
|
||||
|
||||
android:clickable="true" />
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
@ -87,29 +85,6 @@
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical" />
|
||||
|
||||
</ScrollView>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@android:style/ButtonBar">
|
||||
|
||||
<Button
|
||||
android:text="@android:string/ok"
|
||||
android:id="@+id/btn_ok"
|
||||
android:layout_width="0dip"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<Button
|
||||
android:text="@android:string/cancel"
|
||||
android:id="@+id/btn_cancel"
|
||||
android:layout_width="0dip"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
@ -8,7 +8,7 @@ And don't add newlines before or after p tags because of transifex -->
|
||||
<p><a href="https://github.com/dschuermann/apg">https://github.com/dschuermann/apg</a></p>
|
||||
<p>Android Privacy Guard (APG) is a OpenPGP implementation for Android.</p>
|
||||
<p>License: Apache License v2</p>
|
||||
<p>Developer: Thialfihar (Main developer), Senecaso (QRCode, sign key, upload key), Markus Doits (AIDL), Oliver Runge, Dominik Schürmann (Version 2 and up)</p>
|
||||
<p>Developer: Thialfihar (Main developer v1.x), Senecaso (QRCode, sign key, upload key), Markus Doits (AIDL), Oliver Runge, Dominik Schürmann (Developer v2.x)</p>
|
||||
|
||||
<h2>Libraries</h2>
|
||||
<p>• <a href="http://actionbarsherlock.com/">ActionBarSherlock</a> (Apache License v2)
|
||||
|
@ -26,7 +26,7 @@ public class ApgApplication extends Application {
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
/** Start passphrase cache service */
|
||||
/* Start passphrase cache service */
|
||||
PassphraseCacheService.startCacheService(this);
|
||||
}
|
||||
|
||||
|
@ -27,8 +27,6 @@ public final class Constants {
|
||||
}
|
||||
|
||||
public static final class pref {
|
||||
public static final String HAS_SEEN_HELP = "seenHelp";
|
||||
public static final String HAS_SEEN_CHANGE_LOG = "seenChangeLogDialog";
|
||||
public static final String DEFAULT_ENCRYPTION_ALGORITHM = "defaultEncryptionAlgorithm";
|
||||
public static final String DEFAULT_HASH_ALGORITHM = "defaultHashAlgorithm";
|
||||
public static final String DEFAULT_ASCII_ARMOUR = "defaultAsciiArmour";
|
||||
@ -44,6 +42,7 @@ public final class Constants {
|
||||
public static final String KEY_SERVERS = "pool.sks-keyservers.net, subkeys.pgp.net, pgp.mit.edu";
|
||||
}
|
||||
|
||||
// TODO: rework!
|
||||
public static final class extras {
|
||||
public static final String PROGRESS = "progress";
|
||||
public static final String PROGRESS_MAX = "max";
|
||||
|
@ -1,99 +0,0 @@
|
||||
/*
|
||||
* 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.thialfihar.android.apg;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.thialfihar.android.apg.R;
|
||||
import org.thialfihar.android.apg.Apg.GeneralException;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Environment;
|
||||
|
||||
public class DataDestination implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -6478075911319320498L;
|
||||
|
||||
private String mStreamFilename;
|
||||
private String mFilename;
|
||||
private int mMode = Id.mode.undefined;
|
||||
|
||||
public DataDestination() {
|
||||
|
||||
}
|
||||
|
||||
public void setMode(int mode) {
|
||||
mMode = mode;
|
||||
}
|
||||
|
||||
public void setFilename(String filename) {
|
||||
mFilename = filename;
|
||||
}
|
||||
|
||||
public String getStreamFilename() {
|
||||
return mStreamFilename;
|
||||
}
|
||||
|
||||
public OutputStream getOutputStream(Context context) throws Apg.GeneralException,
|
||||
FileNotFoundException, IOException {
|
||||
OutputStream out = null;
|
||||
mStreamFilename = null;
|
||||
|
||||
switch (mMode) {
|
||||
case Id.mode.stream: {
|
||||
try {
|
||||
while (true) {
|
||||
mStreamFilename = Apg.generateRandomString(32);
|
||||
if (mStreamFilename == null) {
|
||||
throw new Apg.GeneralException("couldn't generate random file name");
|
||||
}
|
||||
context.openFileInput(mStreamFilename).close();
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
// found a name that isn't used yet
|
||||
}
|
||||
out = context.openFileOutput(mStreamFilename, Context.MODE_PRIVATE);
|
||||
break;
|
||||
}
|
||||
|
||||
case Id.mode.byte_array: {
|
||||
out = new ByteArrayOutputStream();
|
||||
break;
|
||||
}
|
||||
|
||||
case Id.mode.file: {
|
||||
if (mFilename.startsWith(Environment.getExternalStorageDirectory().getAbsolutePath())) {
|
||||
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
||||
throw new GeneralException(
|
||||
context.getString(R.string.error_externalStorageNotReady));
|
||||
}
|
||||
}
|
||||
out = new FileOutputStream(mFilename);
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
}
|
@ -1,137 +0,0 @@
|
||||
/*
|
||||
* 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.thialfihar.android.apg;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.thialfihar.android.apg.R;
|
||||
import org.thialfihar.android.apg.Apg.GeneralException;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.os.Environment;
|
||||
|
||||
public class DataSource implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 2377217399907415255L;
|
||||
|
||||
private Uri mContentUri = null;
|
||||
private String mText = null;
|
||||
private byte[] mData = null;
|
||||
|
||||
public DataSource() {
|
||||
|
||||
}
|
||||
|
||||
public void setUri(Uri uri) {
|
||||
mContentUri = uri;
|
||||
mText = null;
|
||||
mData = null;
|
||||
}
|
||||
|
||||
public void setUri(String uri) {
|
||||
if (uri.startsWith("/")) {
|
||||
setUri(Uri.parse("file://" + uri));
|
||||
} else {
|
||||
setUri(Uri.parse(uri));
|
||||
}
|
||||
}
|
||||
|
||||
public Uri getUri() {
|
||||
return mContentUri;
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
mText = text;
|
||||
mData = null;
|
||||
mContentUri = null;
|
||||
}
|
||||
|
||||
public void setData(byte[] data) {
|
||||
mData = data;
|
||||
mText = null;
|
||||
mContentUri = null;
|
||||
}
|
||||
|
||||
public boolean isText() {
|
||||
return mText != null;
|
||||
}
|
||||
|
||||
public boolean isBinary() {
|
||||
return mData != null || mContentUri != null;
|
||||
}
|
||||
|
||||
public byte[] getBytes() {
|
||||
byte[] bytes = null;
|
||||
if (mData != null) {
|
||||
bytes = mData;
|
||||
} else {
|
||||
bytes = mText.getBytes();
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public InputData getInputData(Context context, boolean withSize) throws GeneralException,
|
||||
FileNotFoundException, IOException {
|
||||
InputStream in = null;
|
||||
long size = 0;
|
||||
|
||||
if (mContentUri != null) {
|
||||
if (mContentUri.getScheme().equals("file")) {
|
||||
// get the rest after "file://"
|
||||
String path = Uri.decode(mContentUri.toString().substring(7));
|
||||
if (path.startsWith(Environment.getExternalStorageDirectory().getAbsolutePath())) {
|
||||
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
||||
throw new GeneralException(
|
||||
context.getString(R.string.error_externalStorageNotReady));
|
||||
}
|
||||
}
|
||||
in = new FileInputStream(path);
|
||||
File file = new File(path);
|
||||
if (withSize) {
|
||||
size = file.length();
|
||||
}
|
||||
} else {
|
||||
in = context.getContentResolver().openInputStream(mContentUri);
|
||||
if (withSize) {
|
||||
InputStream tmp = context.getContentResolver().openInputStream(mContentUri);
|
||||
size = Apg.getLengthOfStream(tmp);
|
||||
tmp.close();
|
||||
}
|
||||
}
|
||||
} else if (mText != null || mData != null) {
|
||||
byte[] bytes = null;
|
||||
if (mData != null) {
|
||||
bytes = mData;
|
||||
} else {
|
||||
bytes = mText.getBytes();
|
||||
}
|
||||
in = new ByteArrayInputStream(bytes);
|
||||
if (withSize) {
|
||||
size = bytes.length;
|
||||
}
|
||||
}
|
||||
|
||||
return new InputData(in, size);
|
||||
}
|
||||
|
||||
}
|
@ -1,138 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010 Thialfihar <thi@thialfihar.org>
|
||||
*
|
||||
* 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.thialfihar.android.apg;
|
||||
|
||||
import org.thialfihar.android.apg.R;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.Toast;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* SHOUDL BE DELTED, DileDialogFragment is the new implementation
|
||||
*
|
||||
*
|
||||
* @author ds1
|
||||
*
|
||||
*/
|
||||
public class FileDialog {
|
||||
private static EditText mFilename;
|
||||
private static ImageButton mBrowse;
|
||||
private static CheckBox mCheckBox;
|
||||
private static Activity mActivity;
|
||||
private static int mRequestCode;
|
||||
|
||||
public static interface OnClickListener {
|
||||
public void onCancelClick();
|
||||
|
||||
public void onOkClick(String filename, boolean checkbox);
|
||||
}
|
||||
|
||||
public static AlertDialog build(Activity activity, String title, String message,
|
||||
String defaultFile, OnClickListener onClickListener, String fileManagerTitle,
|
||||
String fileManagerButton, String checkboxText, int requestCode) {
|
||||
// TODO: fileManagerTitle and fileManagerButton are deprecated, no use for them right now,
|
||||
// but maybe the Intent now used will someday support them again, so leaving them in
|
||||
LayoutInflater inflater = (LayoutInflater) activity
|
||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(activity);
|
||||
|
||||
alert.setTitle(title);
|
||||
alert.setMessage(message);
|
||||
|
||||
View view = inflater.inflate(R.layout.file_dialog, null);
|
||||
|
||||
mActivity = activity;
|
||||
mFilename = (EditText) view.findViewById(R.id.input);
|
||||
mFilename.setText(defaultFile);
|
||||
mBrowse = (ImageButton) view.findViewById(R.id.btn_browse);
|
||||
mBrowse.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
openFile();
|
||||
}
|
||||
});
|
||||
mRequestCode = requestCode;
|
||||
mCheckBox = (CheckBox) view.findViewById(R.id.checkbox);
|
||||
if (checkboxText == null) {
|
||||
mCheckBox.setEnabled(false);
|
||||
mCheckBox.setVisibility(View.GONE);
|
||||
} else {
|
||||
mCheckBox.setEnabled(true);
|
||||
mCheckBox.setVisibility(View.VISIBLE);
|
||||
mCheckBox.setText(checkboxText);
|
||||
}
|
||||
|
||||
alert.setView(view);
|
||||
|
||||
final OnClickListener clickListener = onClickListener;
|
||||
|
||||
alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
boolean checked = false;
|
||||
if (mCheckBox.isEnabled()) {
|
||||
checked = mCheckBox.isChecked();
|
||||
}
|
||||
clickListener.onOkClick(mFilename.getText().toString(), checked);
|
||||
}
|
||||
});
|
||||
|
||||
alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
clickListener.onCancelClick();
|
||||
}
|
||||
});
|
||||
return alert.create();
|
||||
}
|
||||
|
||||
public static void setFilename(String filename) {
|
||||
if (mFilename != null) {
|
||||
mFilename.setText(filename);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the file manager to select a file to open.
|
||||
*/
|
||||
private static void openFile() {
|
||||
String filename = mFilename.getText().toString();
|
||||
|
||||
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
|
||||
intent.setData(Uri.parse("file://" + filename));
|
||||
intent.setType("text/plain"); // only .asc or .gpg files
|
||||
|
||||
try {
|
||||
mActivity.startActivityForResult(intent, mRequestCode);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
// No compatible file manager was found.
|
||||
Toast.makeText(mActivity, R.string.noFilemanagerInstalled, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Senecaso
|
||||
*
|
||||
* 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
|
||||
@ -42,6 +44,7 @@ import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.thialfihar.android.apg.helper.PGPHelper;
|
||||
|
||||
import android.text.Html;
|
||||
|
||||
@ -178,8 +181,8 @@ public class HkpKeyServer extends KeyServer {
|
||||
KeyInfo info = new KeyInfo();
|
||||
info.size = Integer.parseInt(matcher.group(1));
|
||||
info.algorithm = matcher.group(2);
|
||||
info.keyId = Apg.keyFromHex(matcher.group(3));
|
||||
info.fingerPrint = Apg.getSmallFingerPrint(info.keyId);
|
||||
info.keyId = PGPHelper.keyFromHex(matcher.group(3));
|
||||
info.fingerPrint = PGPHelper.getSmallFingerPrint(info.keyId);
|
||||
String chunks[] = matcher.group(4).split("-");
|
||||
info.date = new GregorianCalendar(Integer.parseInt(chunks[0]),
|
||||
Integer.parseInt(chunks[1]), Integer.parseInt(chunks[2])).getTime();
|
||||
@ -210,7 +213,7 @@ public class HkpKeyServer extends KeyServer {
|
||||
HttpClient client = new DefaultHttpClient();
|
||||
try {
|
||||
HttpGet get = new HttpGet("http://" + mHost + ":" + mPort
|
||||
+ "/pks/lookup?op=get&search=0x" + Apg.keyToHex(keyId));
|
||||
+ "/pks/lookup?op=get&search=0x" + PGPHelper.keyToHex(keyId));
|
||||
|
||||
HttpResponse response = client.execute(get);
|
||||
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
|
||||
@ -220,7 +223,7 @@ public class HkpKeyServer extends KeyServer {
|
||||
HttpEntity entity = response.getEntity();
|
||||
InputStream is = entity.getContent();
|
||||
String data = readAll(is, EntityUtils.getContentCharSet(entity));
|
||||
Matcher matcher = Apg.PGP_PUBLIC_KEY.matcher(data);
|
||||
Matcher matcher = PGPHelper.PGP_PUBLIC_KEY.matcher(data);
|
||||
if (matcher.find()) {
|
||||
return matcher.group(1);
|
||||
}
|
||||
@ -234,7 +237,7 @@ public class HkpKeyServer extends KeyServer {
|
||||
}
|
||||
|
||||
@Override
|
||||
void add(String armouredText) throws AddKeyException {
|
||||
public void add(String armouredText) throws AddKeyException {
|
||||
HttpClient client = new DefaultHttpClient();
|
||||
try {
|
||||
HttpPost post = new HttpPost("http://" + mHost + ":" + mPort + "/pks/add");
|
||||
|
@ -18,6 +18,13 @@ package org.thialfihar.android.apg;
|
||||
|
||||
import org.spongycastle.bcpg.CompressionAlgorithmTags;
|
||||
|
||||
/**
|
||||
*
|
||||
* TODO:
|
||||
*
|
||||
* - refactor ids, some are not needed and can be done with xml
|
||||
*
|
||||
*/
|
||||
public final class Id {
|
||||
|
||||
public static final String TAG = "APG";
|
||||
|
@ -1,4 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Senecaso
|
||||
*
|
||||
* 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
|
||||
|
@ -1,4 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) 2012 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||
* Copyright (C) 2010 Thialfihar <thi@thialfihar.org>
|
||||
*
|
||||
* 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
|
||||
@ -23,8 +26,7 @@ import android.content.SharedPreferences;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* Singelton Implementation of a Preference Helper
|
||||
*
|
||||
* Singleton Implementation of a Preference Helper
|
||||
*/
|
||||
public class Preferences {
|
||||
private static Preferences mPreferences;
|
||||
|
@ -14,10 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.thialfihar.android.apg.util;
|
||||
package org.thialfihar.android.apg.deprecated;
|
||||
|
||||
import org.thialfihar.android.apg.service.IApgService2;
|
||||
import org.thialfihar.android.apg.util.ApgConInterface.OnCallFinishListener;
|
||||
import org.thialfihar.android.apg.deprecated.ApgConInterface.OnCallFinishListener;
|
||||
import org.thialfihar.android.apg.deprecated.IApgService2;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.ContentResolver;
|
@ -12,7 +12,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.thialfihar.android.apg.util;
|
||||
package org.thialfihar.android.apg.deprecated;
|
||||
|
||||
public interface ApgConInterface {
|
||||
public static interface OnCallFinishListener {
|
@ -12,7 +12,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.thialfihar.android.apg.service;
|
||||
package org.thialfihar.android.apg.deprecated;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@ -25,19 +25,19 @@ import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.thialfihar.android.apg.Apg;
|
||||
import org.thialfihar.android.apg.service.IApgService2;
|
||||
import org.thialfihar.android.apg.deprecated.IApgService2;
|
||||
import org.thialfihar.android.apg.Id;
|
||||
import org.thialfihar.android.apg.InputData;
|
||||
import org.thialfihar.android.apg.Preferences;
|
||||
import org.thialfihar.android.apg.R;
|
||||
import org.thialfihar.android.apg.service.IApgService2.Stub;
|
||||
import org.thialfihar.android.apg.deprecated.IApgService2.Stub;
|
||||
import org.thialfihar.android.apg.Id.database;
|
||||
import org.thialfihar.android.apg.R.string;
|
||||
import org.thialfihar.android.apg.helper.PGPHelper;
|
||||
import org.thialfihar.android.apg.passphrase.PassphraseCacheService;
|
||||
import org.thialfihar.android.apg.provider.KeyRings;
|
||||
import org.thialfihar.android.apg.provider.Keys;
|
||||
import org.thialfihar.android.apg.provider.UserIds;
|
||||
import org.thialfihar.android.apg.util.InputData;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Intent;
|
||||
@ -204,7 +204,7 @@ public class ApgService2 extends PassphraseCacheService {
|
||||
typeWhere = KeyRings.TABLE_NAME + "." + KeyRings.TYPE + " = ?";
|
||||
typeVal = new String[] { "" + pParams.get("key_type") };
|
||||
}
|
||||
return qb.query(Apg.getDatabase().db(), (String[]) pParams.get("columns"), typeWhere,
|
||||
return qb.query(PGPHelper.getDatabase().db(), (String[]) pParams.get("columns"), typeWhere,
|
||||
typeVal, null, null, orderBy);
|
||||
}
|
||||
|
||||
@ -253,7 +253,7 @@ public class ApgService2 extends PassphraseCacheService {
|
||||
long curMkey = mCursor.getLong(0);
|
||||
String curUser = mCursor.getString(1);
|
||||
|
||||
String curFprint = Apg.getSmallFingerPrint(curMkey);
|
||||
String curFprint = PGPHelper.getSmallFingerPrint(curMkey);
|
||||
if (LOCAL_LOGV)
|
||||
Log.v(TAG, "current user: " + curUser + " (" + curFprint + ")");
|
||||
if (pSearchKeys.contains(curFprint) || pSearchKeys.contains(curUser)) {
|
||||
@ -427,7 +427,7 @@ public class ApgService2 extends PassphraseCacheService {
|
||||
}
|
||||
|
||||
private boolean prepareArgs(String pCall, Bundle pArgs, Bundle pReturn) {
|
||||
Apg.initialize(getBaseContext());
|
||||
PGPHelper.initialize(getBaseContext());
|
||||
|
||||
/* add default return values for all functions */
|
||||
addDefaultReturns(pReturn);
|
||||
@ -493,7 +493,7 @@ public class ApgService2 extends PassphraseCacheService {
|
||||
if (LOCAL_LOGV)
|
||||
Log.v(TAG, "About to encrypt");
|
||||
try {
|
||||
Apg.encrypt(getBaseContext(), // context
|
||||
PGPHelper.encrypt(getBaseContext(), // context
|
||||
in, // input stream
|
||||
out, // output stream
|
||||
pArgs.getBoolean(arg.ARMORED_OUTPUT.name()), // ARMORED_OUTPUT
|
||||
@ -569,8 +569,8 @@ public class ApgService2 extends PassphraseCacheService {
|
||||
ArrayList<String> ids = new ArrayList<String>();
|
||||
while (cursor.moveToNext()) {
|
||||
if (LOCAL_LOGV)
|
||||
Log.v(TAG, "adding key " + Apg.getSmallFingerPrint(cursor.getLong(0)));
|
||||
fPrints.add(Apg.getSmallFingerPrint(cursor.getLong(0)));
|
||||
Log.v(TAG, "adding key " + PGPHelper.getSmallFingerPrint(cursor.getLong(0)));
|
||||
fPrints.add(PGPHelper.getSmallFingerPrint(cursor.getLong(0)));
|
||||
ids.add(cursor.getString(1));
|
||||
}
|
||||
cursor.close();
|
||||
@ -625,7 +625,7 @@ public class ApgService2 extends PassphraseCacheService {
|
||||
if (LOCAL_LOGV)
|
||||
Log.v(TAG, "About to decrypt");
|
||||
try {
|
||||
Apg.decrypt(getBaseContext(), in, out, passphrase, null, // progress
|
||||
PGPHelper.decrypt(getBaseContext(), in, out, passphrase, null, // progress
|
||||
pArgs.getString(arg.SYMMETRIC_PASSPHRASE.name()) != null // symmetric
|
||||
);
|
||||
} catch (Exception e) {
|
@ -12,9 +12,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.thialfihar.android.apg.provider.blob;
|
||||
package org.thialfihar.android.apg.deprecated;
|
||||
|
||||
import org.thialfihar.android.apg.service.ApgService2;
|
||||
|
||||
import android.content.ContentUris;
|
||||
import android.content.ContentValues;
|
@ -12,10 +12,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.thialfihar.android.apg.provider.blob;
|
||||
package org.thialfihar.android.apg.deprecated;
|
||||
|
||||
import org.thialfihar.android.apg.Constants;
|
||||
import org.thialfihar.android.apg.service.ApgService2;
|
||||
|
||||
import android.content.ContentProvider;
|
||||
import android.content.ContentValues;
|
@ -1,3 +1,4 @@
|
||||
package org.thialfihar.android.apg.deprecated;
|
||||
//package org.thialfihar.android.apg.provider.blob;
|
||||
//
|
||||
//import android.net.Uri;
|
@ -1,4 +1,4 @@
|
||||
package org.thialfihar.android.apg.service;
|
||||
package org.thialfihar.android.apg.deprecated;
|
||||
|
||||
interface IApgService2 {
|
||||
|
@ -0,0 +1,57 @@
|
||||
package org.thialfihar.android.apg.helper;
|
||||
|
||||
import org.thialfihar.android.apg.R;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Environment;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class FileHelper {
|
||||
|
||||
/**
|
||||
* Checks if external storage is mounted if file is located on external storage
|
||||
*
|
||||
* @param file
|
||||
* @return true if storage is mounted
|
||||
*/
|
||||
public static boolean isStorageMounted(String file) {
|
||||
if (file.startsWith(Environment.getExternalStorageDirectory().getAbsolutePath())) {
|
||||
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the preferred installed file manager on Android and shows a toast if no manager is
|
||||
* installed.
|
||||
*
|
||||
* @param activity
|
||||
* @param filename
|
||||
* default selected file, not supported by all file managers
|
||||
* @param type
|
||||
* can be text/plain for example
|
||||
* @param requestCode
|
||||
* requestCode used to identify the result coming back from file manager to
|
||||
* onActivityResult() in your activity
|
||||
*/
|
||||
public static void openFile(Activity activity, String filename, String type, int requestCode) {
|
||||
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
|
||||
intent.setData(Uri.parse("file://" + filename));
|
||||
intent.setType(type);
|
||||
|
||||
try {
|
||||
activity.startActivityForResult(intent, requestCode);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
// No compatible file manager was found.
|
||||
Toast.makeText(activity, R.string.noFilemanagerInstalled, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (C) 2012 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||
*
|
||||
* 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.thialfihar.android.apg.helper;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import android.content.Context;
|
||||
|
||||
public class OtherHelper {
|
||||
|
||||
/**
|
||||
* Reads html files from /res/raw/example.html to output them as string. See
|
||||
* http://www.monocube.com/2011/02/08/android-tutorial-html-file-in-webview/
|
||||
*
|
||||
* @param context
|
||||
* current context
|
||||
* @param resourceID
|
||||
* of html file to read
|
||||
* @return content of html file with formatting
|
||||
*/
|
||||
public static String readContentFromResource(Context context, int resourceID) {
|
||||
InputStream raw = context.getResources().openRawResource(resourceID);
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
int i;
|
||||
try {
|
||||
i = raw.read();
|
||||
while (i != -1) {
|
||||
stream.write(i);
|
||||
i = raw.read();
|
||||
}
|
||||
raw.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return stream.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number if days between two dates
|
||||
*
|
||||
* @param first
|
||||
* @param second
|
||||
* @return number of days
|
||||
*/
|
||||
public static long getNumDaysBetween(GregorianCalendar first, GregorianCalendar second) {
|
||||
GregorianCalendar tmp = new GregorianCalendar();
|
||||
tmp.setTime(first.getTime());
|
||||
long numDays = (second.getTimeInMillis() - first.getTimeInMillis()) / 1000 / 86400;
|
||||
tmp.add(Calendar.DAY_OF_MONTH, (int) numDays);
|
||||
while (tmp.before(second)) {
|
||||
tmp.add(Calendar.DAY_OF_MONTH, 1);
|
||||
++numDays;
|
||||
}
|
||||
return numDays;
|
||||
}
|
||||
|
||||
}
|
@ -14,14 +14,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.thialfihar.android.apg.util;
|
||||
package org.thialfihar.android.apg.helper;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.Iterator;
|
||||
import java.util.Vector;
|
||||
|
||||
@ -29,82 +26,10 @@ import org.spongycastle.openpgp.PGPObjectFactory;
|
||||
import org.spongycastle.openpgp.PGPSecretKey;
|
||||
import org.spongycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.thialfihar.android.apg.Constants;
|
||||
import org.thialfihar.android.apg.R;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class Utils {
|
||||
|
||||
/**
|
||||
* Opens the file manager to select a file to open.
|
||||
*/
|
||||
public static void openFile(Activity activity, String filename, String type, int requestCode) {
|
||||
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
|
||||
intent.setData(Uri.parse("file://" + filename));
|
||||
intent.setType(type);
|
||||
|
||||
try {
|
||||
activity.startActivityForResult(intent, requestCode);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
// No compatible file manager was found.
|
||||
Toast.makeText(activity, R.string.noFilemanagerInstalled, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads html files from /res/raw/example.html to output them as string. See
|
||||
* http://www.monocube.com/2011/02/08/android-tutorial-html-file-in-webview/
|
||||
*
|
||||
* @param context
|
||||
* current context
|
||||
* @param resourceID
|
||||
* of html file to read
|
||||
* @return content of html file with formatting
|
||||
*/
|
||||
public static String readContentFromResource(Context context, int resourceID) {
|
||||
InputStream raw = context.getResources().openRawResource(resourceID);
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
int i;
|
||||
try {
|
||||
i = raw.read();
|
||||
while (i != -1) {
|
||||
stream.write(i);
|
||||
i = raw.read();
|
||||
}
|
||||
raw.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return stream.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number if days between two dates
|
||||
*
|
||||
* @param first
|
||||
* @param second
|
||||
* @return number of days
|
||||
*/
|
||||
public static long getNumDaysBetween(GregorianCalendar first, GregorianCalendar second) {
|
||||
GregorianCalendar tmp = new GregorianCalendar();
|
||||
tmp.setTime(first.getTime());
|
||||
long numDays = (second.getTimeInMillis() - first.getTimeInMillis()) / 1000 / 86400;
|
||||
tmp.add(Calendar.DAY_OF_MONTH, (int) numDays);
|
||||
while (tmp.before(second)) {
|
||||
tmp.add(Calendar.DAY_OF_MONTH, 1);
|
||||
++numDays;
|
||||
}
|
||||
return numDays;
|
||||
}
|
||||
|
||||
public class PGPConversionHelper {
|
||||
/**
|
||||
* Converts Vector<PGPSecretKey> to a byte[] array to send it by intent to service
|
||||
*
|
||||
@ -185,5 +110,4 @@ public class Utils {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2012 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||
* Copyright (C) 2010 Thialfihar <thi@thialfihar.org>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -14,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.thialfihar.android.apg;
|
||||
package org.thialfihar.android.apg.helper;
|
||||
|
||||
import org.spongycastle.bcpg.ArmoredInputStream;
|
||||
import org.spongycastle.bcpg.ArmoredOutputStream;
|
||||
@ -62,20 +63,37 @@ import org.spongycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBu
|
||||
import org.spongycastle.openpgp.operator.jcajce.JcaPGPKeyPair;
|
||||
import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder;
|
||||
import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder;
|
||||
import org.thialfihar.android.apg.Id.choice;
|
||||
import org.thialfihar.android.apg.Id.content;
|
||||
import org.thialfihar.android.apg.Id.database;
|
||||
import org.thialfihar.android.apg.Id.key;
|
||||
import org.thialfihar.android.apg.Id.return_value;
|
||||
import org.thialfihar.android.apg.Id.type;
|
||||
import org.thialfihar.android.apg.Id.choice.algorithm;
|
||||
import org.thialfihar.android.apg.Id.choice.compression;
|
||||
import org.thialfihar.android.apg.Id.choice.usage;
|
||||
import org.thialfihar.android.apg.KeyServer.AddKeyException;
|
||||
import org.thialfihar.android.apg.R.string;
|
||||
import org.thialfihar.android.apg.passphrase.CachedPassPhrase;
|
||||
import org.thialfihar.android.apg.provider.DataProvider;
|
||||
import org.thialfihar.android.apg.provider.Database;
|
||||
import org.thialfihar.android.apg.provider.KeyRings;
|
||||
import org.thialfihar.android.apg.provider.Keys;
|
||||
import org.thialfihar.android.apg.provider.UserIds;
|
||||
import org.thialfihar.android.apg.service.ApgService;
|
||||
import org.thialfihar.android.apg.ui.BaseActivity;
|
||||
import org.thialfihar.android.apg.ui.widget.KeyEditor;
|
||||
import org.thialfihar.android.apg.ui.widget.SectionView;
|
||||
import org.thialfihar.android.apg.ui.widget.UserIdEditor;
|
||||
import org.thialfihar.android.apg.util.InputData;
|
||||
import org.thialfihar.android.apg.util.IterableIterator;
|
||||
import org.thialfihar.android.apg.util.Utils;
|
||||
import org.thialfihar.android.apg.util.PositionAwareInputStream;
|
||||
import org.thialfihar.android.apg.util.Primes;
|
||||
import org.thialfihar.android.apg.Constants;
|
||||
import org.thialfihar.android.apg.HkpKeyServer;
|
||||
import org.thialfihar.android.apg.Id;
|
||||
import org.thialfihar.android.apg.KeyServer;
|
||||
import org.thialfihar.android.apg.ProgressDialogUpdater;
|
||||
import org.thialfihar.android.apg.R;
|
||||
|
||||
import android.app.Activity;
|
||||
@ -122,7 +140,15 @@ import java.util.Map;
|
||||
import java.util.Vector;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class Apg {
|
||||
/**
|
||||
* TODO:
|
||||
*
|
||||
* - Externalize the constants
|
||||
*
|
||||
* - Separate this file into different helpers
|
||||
*
|
||||
*/
|
||||
public class PGPHelper {
|
||||
|
||||
static {
|
||||
// register spongy castle provider
|
||||
@ -161,13 +187,9 @@ public class Apg {
|
||||
public static final String EXTRA_ENCRYPTED_MESSAGE = "encryptedMessage";
|
||||
public static final String EXTRA_ENCRYPTED_DATA = "encryptedData";
|
||||
public static final String EXTRA_RESULT_URI = "resultUri";
|
||||
public static final String EXTRA_SIGNATURE = "signature";
|
||||
public static final String EXTRA_SIGNATURE_KEY_ID = "signatureKeyId";
|
||||
public static final String EXTRA_SIGNATURE_USER_ID = "signatureUserId";
|
||||
public static final String EXTRA_SIGNATURE_SUCCESS = "signatureSuccess";
|
||||
public static final String EXTRA_SIGNATURE_UNKNOWN = "signatureUnknown";
|
||||
public static final String EXTRA_SIGNATURE_DATA = "signatureData";
|
||||
public static final String EXTRA_SIGNATURE_TEXT = "signatureText";
|
||||
public static final String EXTRA_SIGNATURE_KEY_ID = "signatureKeyId";
|
||||
public static final String EXTRA_USER_ID = "userId";
|
||||
public static final String EXTRA_USER_IDS = "userIds";
|
||||
public static final String EXTRA_KEY_ID = "keyId";
|
||||
@ -426,7 +448,7 @@ public class Apg {
|
||||
public static void buildSecretKey(Context context, ArrayList<String> userIds,
|
||||
ArrayList<PGPSecretKey> keys, ArrayList<Integer> keysUsages, long masterKeyId,
|
||||
String oldPassPhrase, String newPassPhrase, ProgressDialogUpdater progress)
|
||||
throws Apg.GeneralException, NoSuchProviderException, PGPException,
|
||||
throws PGPHelper.GeneralException, NoSuchProviderException, PGPException,
|
||||
NoSuchAlgorithmException, SignatureException, IOException, Database.GeneralException {
|
||||
|
||||
if (progress != null)
|
||||
@ -1143,9 +1165,9 @@ public class Apg {
|
||||
}
|
||||
|
||||
public static String getFingerPrint(long keyId) {
|
||||
PGPPublicKey key = Apg.getPublicKey(keyId);
|
||||
PGPPublicKey key = PGPHelper.getPublicKey(keyId);
|
||||
if (key == null) {
|
||||
PGPSecretKey secretKey = Apg.getSecretKey(keyId);
|
||||
PGPSecretKey secretKey = PGPHelper.getSecretKey(keyId);
|
||||
if (secretKey == null) {
|
||||
return "";
|
||||
}
|
||||
@ -1654,9 +1676,9 @@ public class Apg {
|
||||
progress.setProgress(R.string.progress_done, 100, 100);
|
||||
}
|
||||
|
||||
public static long getDecryptionKeyId(Context context, InputData data) throws GeneralException,
|
||||
NoAsymmetricEncryptionException, IOException {
|
||||
InputStream in = PGPUtil.getDecoderStream(data.getInputStream());
|
||||
public static long getDecryptionKeyId(Context context, InputStream inputStream)
|
||||
throws GeneralException, NoAsymmetricEncryptionException, IOException {
|
||||
InputStream in = PGPUtil.getDecoderStream(inputStream);
|
||||
PGPObjectFactory pgpF = new PGPObjectFactory(in);
|
||||
PGPEncryptedDataList enc;
|
||||
Object o = pgpF.nextObject();
|
||||
@ -1700,9 +1722,9 @@ public class Apg {
|
||||
return secretKey.getKeyID();
|
||||
}
|
||||
|
||||
public static boolean hasSymmetricEncryption(Context context, InputData data)
|
||||
public static boolean hasSymmetricEncryption(Context context, InputStream inputStream)
|
||||
throws GeneralException, IOException {
|
||||
InputStream in = PGPUtil.getDecoderStream(data.getInputStream());
|
||||
InputStream in = PGPUtil.getDecoderStream(inputStream);
|
||||
PGPObjectFactory pgpF = new PGPObjectFactory(in);
|
||||
PGPEncryptedDataList enc;
|
||||
Object o = pgpF.nextObject();
|
||||
@ -1850,7 +1872,7 @@ public class Apg {
|
||||
if (dataChunk instanceof PGPOnePassSignatureList) {
|
||||
if (progress != null)
|
||||
progress.setProgress(R.string.progress_processingSignature, currentProgress, 100);
|
||||
returnData.putBoolean(EXTRA_SIGNATURE, true);
|
||||
returnData.putBoolean(ApgService.EXTRA_SIGNATURE, true);
|
||||
PGPOnePassSignatureList sigList = (PGPOnePassSignatureList) dataChunk;
|
||||
for (int i = 0; i < sigList.size(); ++i) {
|
||||
signature = sigList.get(i);
|
||||
@ -1868,17 +1890,17 @@ public class Apg {
|
||||
if (sigKeyRing != null) {
|
||||
userId = getMainUserId(getMasterKey(sigKeyRing));
|
||||
}
|
||||
returnData.putString(EXTRA_SIGNATURE_USER_ID, userId);
|
||||
returnData.putString(ApgService.EXTRA_SIGNATURE_USER_ID, userId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
returnData.putLong(EXTRA_SIGNATURE_KEY_ID, signatureKeyId);
|
||||
returnData.putLong(ApgService.EXTRA_SIGNATURE_KEY_ID, signatureKeyId);
|
||||
|
||||
if (signature != null) {
|
||||
signature.initVerify(signatureKey, new BouncyCastleProvider());
|
||||
} else {
|
||||
returnData.putBoolean(EXTRA_SIGNATURE_UNKNOWN, true);
|
||||
returnData.putBoolean(ApgService.EXTRA_SIGNATURE_UNKNOWN, true);
|
||||
}
|
||||
|
||||
dataChunk = plainFact.nextObject();
|
||||
@ -1915,7 +1937,7 @@ public class Apg {
|
||||
try {
|
||||
signature.update(buffer, 0, n);
|
||||
} catch (SignatureException e) {
|
||||
returnData.putBoolean(EXTRA_SIGNATURE_SUCCESS, false);
|
||||
returnData.putBoolean(ApgService.EXTRA_SIGNATURE_SUCCESS, false);
|
||||
signature = null;
|
||||
}
|
||||
}
|
||||
@ -1938,9 +1960,9 @@ public class Apg {
|
||||
PGPSignatureList signatureList = (PGPSignatureList) plainFact.nextObject();
|
||||
PGPSignature messageSignature = signatureList.get(signatureIndex);
|
||||
if (signature.verify(messageSignature)) {
|
||||
returnData.putBoolean(EXTRA_SIGNATURE_SUCCESS, true);
|
||||
returnData.putBoolean(ApgService.EXTRA_SIGNATURE_SUCCESS, true);
|
||||
} else {
|
||||
returnData.putBoolean(EXTRA_SIGNATURE_SUCCESS, false);
|
||||
returnData.putBoolean(ApgService.EXTRA_SIGNATURE_SUCCESS, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1963,7 +1985,7 @@ public class Apg {
|
||||
return returnData;
|
||||
}
|
||||
|
||||
public static Bundle verifyText(BaseActivity context, InputData data, OutputStream outStream,
|
||||
public static Bundle verifyText(Context context, InputData data, OutputStream outStream,
|
||||
ProgressDialogUpdater progress) throws IOException, GeneralException, PGPException,
|
||||
SignatureException {
|
||||
Bundle returnData = new Bundle();
|
||||
@ -1995,7 +2017,7 @@ public class Apg {
|
||||
byte[] clearText = out.toByteArray();
|
||||
outStream.write(clearText);
|
||||
|
||||
returnData.putBoolean(EXTRA_SIGNATURE, true);
|
||||
returnData.putBoolean(ApgService.EXTRA_SIGNATURE, true);
|
||||
|
||||
if (progress != null)
|
||||
progress.setProgress(R.string.progress_processingSignature, 60, 100);
|
||||
@ -2015,16 +2037,17 @@ public class Apg {
|
||||
signatureKeyId = signature.getKeyID();
|
||||
}
|
||||
if (signatureKey == null) {
|
||||
Bundle pauseData = new Bundle();
|
||||
pauseData.putInt(Constants.extras.STATUS, Id.message.unknown_signature_key);
|
||||
pauseData.putLong(Constants.extras.KEY_ID, signatureKeyId);
|
||||
Message msg = new Message();
|
||||
msg.setData(pauseData);
|
||||
context.sendMessage(msg);
|
||||
// pause here
|
||||
context.getRunningThread().pause();
|
||||
// see whether the key was found in the meantime
|
||||
signatureKey = getPublicKey(signature.getKeyID());
|
||||
// TODO: reimplement!
|
||||
// Bundle pauseData = new Bundle();
|
||||
// pauseData.putInt(Constants.extras.STATUS, Id.message.unknown_signature_key);
|
||||
// pauseData.putLong(Constants.extras.KEY_ID, signatureKeyId);
|
||||
// Message msg = new Message();
|
||||
// msg.setData(pauseData);
|
||||
// context.sendMessage(msg);
|
||||
// // pause here
|
||||
// context.getRunningThread().pause();
|
||||
// // see whether the key was found in the meantime
|
||||
// signatureKey = getPublicKey(signature.getKeyID());
|
||||
}
|
||||
|
||||
if (signatureKey == null) {
|
||||
@ -2036,15 +2059,15 @@ public class Apg {
|
||||
if (sigKeyRing != null) {
|
||||
userId = getMainUserId(getMasterKey(sigKeyRing));
|
||||
}
|
||||
returnData.putString(EXTRA_SIGNATURE_USER_ID, userId);
|
||||
returnData.putString(ApgService.EXTRA_SIGNATURE_USER_ID, userId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
returnData.putLong(EXTRA_SIGNATURE_KEY_ID, signatureKeyId);
|
||||
returnData.putLong(ApgService.EXTRA_SIGNATURE_KEY_ID, signatureKeyId);
|
||||
|
||||
if (signature == null) {
|
||||
returnData.putBoolean(EXTRA_SIGNATURE_UNKNOWN, true);
|
||||
returnData.putBoolean(ApgService.EXTRA_SIGNATURE_UNKNOWN, true);
|
||||
if (progress != null)
|
||||
progress.setProgress(R.string.progress_done, 100, 100);
|
||||
return returnData;
|
||||
@ -2069,7 +2092,7 @@ public class Apg {
|
||||
} while (lookAhead != -1);
|
||||
}
|
||||
|
||||
returnData.putBoolean(EXTRA_SIGNATURE_SUCCESS, signature.verify());
|
||||
returnData.putBoolean(ApgService.EXTRA_SIGNATURE_SUCCESS, signature.verify());
|
||||
|
||||
if (progress != null)
|
||||
progress.setProgress(R.string.progress_done, 100, 100);
|
@ -20,9 +20,9 @@ import org.spongycastle.jce.provider.BouncyCastleProvider;
|
||||
import org.spongycastle.openpgp.PGPException;
|
||||
import org.spongycastle.openpgp.PGPPrivateKey;
|
||||
import org.spongycastle.openpgp.PGPSecretKey;
|
||||
import org.thialfihar.android.apg.Apg;
|
||||
import org.thialfihar.android.apg.Id;
|
||||
import org.thialfihar.android.apg.R;
|
||||
import org.thialfihar.android.apg.helper.PGPHelper;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
@ -55,7 +55,7 @@ public class AskForPassphrase {
|
||||
secretKey = null;
|
||||
alert.setMessage(context.getString(R.string.passPhraseForSymmetricEncryption));
|
||||
} else {
|
||||
secretKey = Apg.getMasterKey(Apg.getSecretKeyRing(secretKeyId));
|
||||
secretKey = PGPHelper.getMasterKey(PGPHelper.getSecretKeyRing(secretKeyId));
|
||||
if (secretKey == null) {
|
||||
alert.setTitle(R.string.title_keyNotFound);
|
||||
alert.setMessage(context.getString(R.string.keyNotFound, secretKeyId));
|
||||
@ -67,7 +67,7 @@ public class AskForPassphrase {
|
||||
alert.setCancelable(false);
|
||||
return alert.create();
|
||||
}
|
||||
String userId = Apg.getMainUserIdSafe(context, secretKey);
|
||||
String userId = PGPHelper.getMainUserIdSafe(context, secretKey);
|
||||
alert.setMessage(context.getString(R.string.passPhraseFor, userId));
|
||||
}
|
||||
|
||||
@ -111,7 +111,7 @@ public class AskForPassphrase {
|
||||
}
|
||||
|
||||
// cache again
|
||||
Apg.setCachedPassPhrase(keyId, passPhrase);
|
||||
PGPHelper.setCachedPassPhrase(keyId, passPhrase);
|
||||
// return by callback
|
||||
cb.passPhraseCallback(keyId, passPhrase);
|
||||
}
|
||||
@ -133,7 +133,7 @@ public class AskForPassphrase {
|
||||
Log.d("APG", "Key has no passphrase!");
|
||||
|
||||
// cache null
|
||||
Apg.setCachedPassPhrase(secretKey.getKeyID(), null);
|
||||
PGPHelper.setCachedPassPhrase(secretKey.getKeyID(), null);
|
||||
// return by callback
|
||||
cb.passPhraseCallback(secretKey.getKeyID(), null);
|
||||
|
||||
|
@ -14,8 +14,8 @@
|
||||
|
||||
package org.thialfihar.android.apg.passphrase;
|
||||
|
||||
import org.thialfihar.android.apg.Apg;
|
||||
import org.thialfihar.android.apg.Preferences;
|
||||
import org.thialfihar.android.apg.helper.PGPHelper;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
@ -47,7 +47,7 @@ public class PassphraseCacheService extends Service {
|
||||
delay = 60000;
|
||||
}
|
||||
|
||||
delay = Apg.cleanUpCache(mPassPhraseCacheTtl, delay);
|
||||
delay = PGPHelper.cleanUpCache(mPassPhraseCacheTtl, delay);
|
||||
// don't check too often, even if we were close
|
||||
if (delay < 5000) {
|
||||
delay = 5000;
|
||||
|
@ -19,8 +19,8 @@ import org.spongycastle.openpgp.PGPPublicKey;
|
||||
import org.spongycastle.openpgp.PGPPublicKeyRing;
|
||||
import org.spongycastle.openpgp.PGPSecretKey;
|
||||
import org.spongycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.thialfihar.android.apg.Apg;
|
||||
import org.thialfihar.android.apg.Id;
|
||||
import org.thialfihar.android.apg.helper.PGPHelper;
|
||||
import org.thialfihar.android.apg.util.IterableIterator;
|
||||
|
||||
import android.content.ContentValues;
|
||||
@ -318,11 +318,11 @@ public class Database extends SQLiteOpenHelper {
|
||||
values.put(Keys.IS_MASTER_KEY, key.isMasterKey());
|
||||
values.put(Keys.ALGORITHM, key.getAlgorithm());
|
||||
values.put(Keys.KEY_SIZE, key.getBitStrength());
|
||||
values.put(Keys.CAN_SIGN, Apg.isSigningKey(key));
|
||||
values.put(Keys.CAN_ENCRYPT, Apg.isEncryptionKey(key));
|
||||
values.put(Keys.CAN_SIGN, PGPHelper.isSigningKey(key));
|
||||
values.put(Keys.CAN_ENCRYPT, PGPHelper.isEncryptionKey(key));
|
||||
values.put(Keys.IS_REVOKED, key.isRevoked());
|
||||
values.put(Keys.CREATION, Apg.getCreationDate(key).getTime() / 1000);
|
||||
Date expiryDate = Apg.getExpiryDate(key);
|
||||
values.put(Keys.CREATION, PGPHelper.getCreationDate(key).getTime() / 1000);
|
||||
Date expiryDate = PGPHelper.getExpiryDate(key);
|
||||
if (expiryDate != null) {
|
||||
values.put(Keys.EXPIRY, expiryDate.getTime() / 1000);
|
||||
}
|
||||
@ -367,11 +367,11 @@ public class Database extends SQLiteOpenHelper {
|
||||
values.put(Keys.IS_MASTER_KEY, key.isMasterKey());
|
||||
values.put(Keys.ALGORITHM, key.getPublicKey().getAlgorithm());
|
||||
values.put(Keys.KEY_SIZE, key.getPublicKey().getBitStrength());
|
||||
values.put(Keys.CAN_SIGN, Apg.isSigningKey(key));
|
||||
values.put(Keys.CAN_ENCRYPT, Apg.isEncryptionKey(key));
|
||||
values.put(Keys.CAN_SIGN, PGPHelper.isSigningKey(key));
|
||||
values.put(Keys.CAN_ENCRYPT, PGPHelper.isEncryptionKey(key));
|
||||
values.put(Keys.IS_REVOKED, key.getPublicKey().isRevoked());
|
||||
values.put(Keys.CREATION, Apg.getCreationDate(key).getTime() / 1000);
|
||||
Date expiryDate = Apg.getExpiryDate(key);
|
||||
values.put(Keys.CREATION, PGPHelper.getCreationDate(key).getTime() / 1000);
|
||||
Date expiryDate = PGPHelper.getExpiryDate(key);
|
||||
if (expiryDate != null) {
|
||||
values.put(Keys.EXPIRY, expiryDate.getTime() / 1000);
|
||||
}
|
||||
|
@ -28,23 +28,23 @@ import java.util.ArrayList;
|
||||
|
||||
import org.spongycastle.openpgp.PGPSecretKey;
|
||||
import org.spongycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.thialfihar.android.apg.Apg;
|
||||
import org.thialfihar.android.apg.Constants;
|
||||
import org.thialfihar.android.apg.Id;
|
||||
import org.thialfihar.android.apg.InputData;
|
||||
import org.thialfihar.android.apg.Preferences;
|
||||
import org.thialfihar.android.apg.ProgressDialogUpdater;
|
||||
import org.thialfihar.android.apg.R;
|
||||
import org.thialfihar.android.apg.Apg.GeneralException;
|
||||
import org.thialfihar.android.apg.helper.FileHelper;
|
||||
import org.thialfihar.android.apg.helper.PGPHelper;
|
||||
import org.thialfihar.android.apg.helper.PGPHelper.GeneralException;
|
||||
import org.thialfihar.android.apg.helper.PGPConversionHelper;
|
||||
import org.thialfihar.android.apg.provider.DataProvider;
|
||||
import org.thialfihar.android.apg.util.Utils;
|
||||
import org.thialfihar.android.apg.util.InputData;
|
||||
|
||||
import android.app.IntentService;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.Message;
|
||||
import android.os.Messenger;
|
||||
import android.os.RemoteException;
|
||||
@ -55,7 +55,16 @@ import android.util.Log;
|
||||
* data from the activities or other apps, queues these intents, executes them, and stops itself
|
||||
* after doing them.
|
||||
*/
|
||||
// TODO: ProgressDialogUpdater rework???
|
||||
|
||||
/**
|
||||
* TODO:
|
||||
*
|
||||
* - ProgressDialogUpdater rework???
|
||||
*
|
||||
* - put recurring things into private functions when possible
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class ApgService extends IntentService implements ProgressDialogUpdater {
|
||||
|
||||
// extras that can be given by intent
|
||||
@ -64,6 +73,26 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
|
||||
public static final String EXTRA_DATA = "data";
|
||||
|
||||
// keys for data bundle
|
||||
|
||||
// encrypt
|
||||
public static final String SECRET_KEY_ID = "secret_key_id";
|
||||
public static final String USE_ASCII_AMOR = "use_ascii_amor";
|
||||
public static final String ENCRYPTION_KEYS_IDS = "encryption_keys_ids";
|
||||
public static final String SIGNATURE_KEY_ID = "signature_key_id";
|
||||
public static final String COMPRESSION_ID = "compression_id";
|
||||
public static final String GENERATE_SIGNATURE = "generate_signature";
|
||||
public static final String SIGN_ONLY = "sign_only";
|
||||
public static final String MESSAGE_BYTES = "message_bytes";
|
||||
public static final String INPUT_FILE = "input_file";
|
||||
public static final String OUTPUT_FILE = "output_file";
|
||||
public static final String PROVIDER_URI = "provider_uri";
|
||||
|
||||
// decrypt
|
||||
public static final String SIGNED_ONLY = "signed_only";
|
||||
public static final String RETURN_BYTES = "return_binary";
|
||||
public static final String CIPHERTEXT_BYTES = "ciphertext_bytes";
|
||||
public static final String ASSUME_SYMMETRIC = "assume_symmetric";
|
||||
|
||||
// edit keys
|
||||
public static final String NEW_PASSPHRASE = "new_passphrase";
|
||||
public static final String CURRENT_PASSPHRASE = "current_passphrase";
|
||||
@ -78,41 +107,44 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
|
||||
public static final String SYMMETRIC_PASSPHRASE = "passphrase";
|
||||
public static final String MASTER_KEY = "master_key";
|
||||
|
||||
// encrypt
|
||||
public static final String SECRET_KEY_ID = "secret_key_id";
|
||||
public static final String USE_ASCII_AMOR = "use_ascii_amor";
|
||||
public static final String ENCRYPTION_KEYS_IDS = "encryption_keys_ids";
|
||||
public static final String SIGNATURE_KEY_ID = "signature_key_id";
|
||||
public static final String COMPRESSION_ID = "compression_id";
|
||||
public static final String GENERATE_SIGNATURE = "generate_signature";
|
||||
public static final String SIGN_ONLY = "sign_only";
|
||||
public static final String BYTES = "bytes";
|
||||
public static final String INPUT_FILE = "input_file";
|
||||
public static final String OUTPUT_FILE = "output_file";
|
||||
public static final String PROVIDER_URI = "provider_uri";
|
||||
|
||||
// delete file securely
|
||||
public static final String DELETE_FILE = "delete_file";
|
||||
|
||||
// possible ints for EXTRA_ACTION
|
||||
public static final int ACTION_SAVE_KEYRING = 1;
|
||||
public static final int ACTION_GENERATE_KEY = 2;
|
||||
public static final int ACTION_GENERATE_DEFAULT_RSA_KEYS = 3;
|
||||
// possible EXTRA_ACTIONs
|
||||
public static final int ACTION_ENCRYPT_SIGN_BYTES = 10;
|
||||
public static final int ACTION_ENCRYPT_SIGN_FILE = 11;
|
||||
public static final int ACTION_ENCRYPT_SIGN_STREAM = 12;
|
||||
|
||||
public static final int ACTION_ENCRYPT_SIGN_BYTES = 4;
|
||||
public static final int ACTION_ENCRYPT_SIGN_FILE = 5;
|
||||
public static final int ACTION_ENCRYPT_SIGN_STREAM = 6;
|
||||
public static final int ACTION_DECRYPT_BYTES = 20;
|
||||
public static final int ACTION_DECRYPT_FILE = 21;
|
||||
public static final int ACTION_DECRYPT_STREAM = 22;
|
||||
|
||||
public static final int ACTION_DELETE_FILE_SECURELY = 7;
|
||||
public static final int ACTION_SAVE_KEYRING = 30;
|
||||
public static final int ACTION_GENERATE_KEY = 31;
|
||||
public static final int ACTION_GENERATE_DEFAULT_RSA_KEYS = 32;
|
||||
|
||||
public static final int ACTION_DELETE_FILE_SECURELY = 40;
|
||||
|
||||
// possible data keys as result
|
||||
// keys
|
||||
public static final String RESULT_NEW_KEY = "new_key";
|
||||
public static final String RESULT_NEW_KEY2 = "new_key2";
|
||||
public static final String RESULT_SIGNATURE_DATA = "signatureData";
|
||||
public static final String RESULT_SIGNATURE_TEXT = "signatureText";
|
||||
public static final String RESULT_ENCRYPTED_MESSAGE = "encryptedMessage";
|
||||
public static final String RESULT_ENCRYPTED_DATA = "encryptedData";
|
||||
public static final String RESULT_URI = "resultUri";
|
||||
|
||||
// encrypt
|
||||
public static final String RESULT_SIGNATURE_DATA = "signature_data";
|
||||
public static final String RESULT_SIGNATURE_TEXT = "signature_text";
|
||||
public static final String RESULT_ENCRYPTED_MESSAGE = "encrypted_message";
|
||||
public static final String RESULT_ENCRYPTED_DATA = "encrypted_data";
|
||||
public static final String RESULT_URI = "result_uri";
|
||||
|
||||
// decrypt
|
||||
public static final String RESULT_DECRYPTED_MESSAGE = "decrypted_message";
|
||||
public static final String RESULT_DECRYPTED_DATA = "decrypted_data";
|
||||
public static final String EXTRA_SIGNATURE = "signature";
|
||||
public static final String EXTRA_SIGNATURE_KEY_ID = "signature_key_id";
|
||||
public static final String EXTRA_SIGNATURE_USER_ID = "signature_user_id";
|
||||
public static final String EXTRA_SIGNATURE_SUCCESS = "signature_success";
|
||||
public static final String EXTRA_SIGNATURE_UNKNOWN = "signature_unknown";
|
||||
|
||||
Messenger mMessenger;
|
||||
|
||||
@ -149,7 +181,7 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
|
||||
case ACTION_SAVE_KEYRING:
|
||||
|
||||
try {
|
||||
// Input
|
||||
/* Input */
|
||||
String oldPassPhrase = data.getString(CURRENT_PASSPHRASE);
|
||||
String newPassPhrase = data.getString(NEW_PASSPHRASE);
|
||||
if (newPassPhrase == null) {
|
||||
@ -157,19 +189,19 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
ArrayList<String> userIds = (ArrayList<String>) data.getSerializable(USER_IDS);
|
||||
ArrayList<PGPSecretKey> keys = Utils.BytesToPGPSecretKeyList(data
|
||||
ArrayList<PGPSecretKey> keys = PGPConversionHelper.BytesToPGPSecretKeyList(data
|
||||
.getByteArray(KEYS));
|
||||
@SuppressWarnings("unchecked")
|
||||
ArrayList<Integer> keysUsages = (ArrayList<Integer>) data
|
||||
.getSerializable(KEYS_USAGES);
|
||||
long masterKeyId = data.getLong(MASTER_KEY_ID);
|
||||
|
||||
// Operation
|
||||
Apg.buildSecretKey(this, userIds, keys, keysUsages, masterKeyId, oldPassPhrase,
|
||||
newPassPhrase, this);
|
||||
Apg.setCachedPassPhrase(masterKeyId, newPassPhrase);
|
||||
/* Operation */
|
||||
PGPHelper.buildSecretKey(this, userIds, keys, keysUsages, masterKeyId,
|
||||
oldPassPhrase, newPassPhrase, this);
|
||||
PGPHelper.setCachedPassPhrase(masterKeyId, newPassPhrase);
|
||||
|
||||
// Output
|
||||
/* Output */
|
||||
sendMessageToHandler(ApgHandler.MESSAGE_OKAY);
|
||||
} catch (Exception e) {
|
||||
sendErrorToHandler(e);
|
||||
@ -180,22 +212,24 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
|
||||
case ACTION_GENERATE_KEY:
|
||||
|
||||
try {
|
||||
// Input
|
||||
/* Input */
|
||||
int algorithm = data.getInt(ALGORITHM);
|
||||
String passphrase = data.getString(SYMMETRIC_PASSPHRASE);
|
||||
int keysize = data.getInt(KEY_SIZE);
|
||||
PGPSecretKey masterKey = null;
|
||||
if (data.containsKey(MASTER_KEY)) {
|
||||
masterKey = Utils.BytesToPGPSecretKey(data.getByteArray(MASTER_KEY));
|
||||
masterKey = PGPConversionHelper.BytesToPGPSecretKey(data
|
||||
.getByteArray(MASTER_KEY));
|
||||
}
|
||||
|
||||
// Operation
|
||||
PGPSecretKeyRing newKeyRing = Apg.createKey(this, algorithm, keysize, passphrase,
|
||||
masterKey);
|
||||
/* Operation */
|
||||
PGPSecretKeyRing newKeyRing = PGPHelper.createKey(this, algorithm, keysize,
|
||||
passphrase, masterKey);
|
||||
|
||||
// Output
|
||||
/* Output */
|
||||
Bundle resultData = new Bundle();
|
||||
resultData.putByteArray(RESULT_NEW_KEY, Utils.PGPSecretKeyRingToBytes(newKeyRing));
|
||||
resultData.putByteArray(RESULT_NEW_KEY,
|
||||
PGPConversionHelper.PGPSecretKeyRingToBytes(newKeyRing));
|
||||
sendMessageToHandler(ApgHandler.MESSAGE_OKAY, resultData);
|
||||
} catch (Exception e) {
|
||||
sendErrorToHandler(e);
|
||||
@ -206,20 +240,22 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
|
||||
case ACTION_GENERATE_DEFAULT_RSA_KEYS:
|
||||
// generate one RSA 2048 key for signing and one subkey for encrypting!
|
||||
try {
|
||||
/* Input */
|
||||
String passphrase = data.getString(SYMMETRIC_PASSPHRASE);
|
||||
|
||||
// Operation
|
||||
PGPSecretKeyRing masterKeyRing = Apg.createKey(this, Id.choice.algorithm.rsa, 2048,
|
||||
passphrase, null);
|
||||
/* Operation */
|
||||
PGPSecretKeyRing masterKeyRing = PGPHelper.createKey(this, Id.choice.algorithm.rsa,
|
||||
2048, passphrase, null);
|
||||
|
||||
PGPSecretKeyRing subKeyRing = Apg.createKey(this, Id.choice.algorithm.rsa, 2048,
|
||||
passphrase, masterKeyRing.getSecretKey());
|
||||
PGPSecretKeyRing subKeyRing = PGPHelper.createKey(this, Id.choice.algorithm.rsa,
|
||||
2048, passphrase, masterKeyRing.getSecretKey());
|
||||
|
||||
// Output
|
||||
/* Output */
|
||||
Bundle resultData = new Bundle();
|
||||
resultData.putByteArray(RESULT_NEW_KEY,
|
||||
Utils.PGPSecretKeyRingToBytes(masterKeyRing));
|
||||
resultData.putByteArray(RESULT_NEW_KEY2, Utils.PGPSecretKeyRingToBytes(subKeyRing));
|
||||
PGPConversionHelper.PGPSecretKeyRingToBytes(masterKeyRing));
|
||||
resultData.putByteArray(RESULT_NEW_KEY2,
|
||||
PGPConversionHelper.PGPSecretKeyRingToBytes(subKeyRing));
|
||||
sendMessageToHandler(ApgHandler.MESSAGE_OKAY, resultData);
|
||||
} catch (Exception e) {
|
||||
sendErrorToHandler(e);
|
||||
@ -230,11 +266,11 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
|
||||
case ACTION_ENCRYPT_SIGN_BYTES:
|
||||
|
||||
try {
|
||||
// Input
|
||||
/* Input */
|
||||
long secretKeyId = data.getLong(SECRET_KEY_ID);
|
||||
String passphrase = data.getString(SYMMETRIC_PASSPHRASE);
|
||||
|
||||
byte[] bytes = data.getByteArray(BYTES);
|
||||
byte[] bytes = data.getByteArray(MESSAGE_BYTES);
|
||||
|
||||
boolean useAsciiArmour = data.getBoolean(USE_ASCII_AMOR);
|
||||
long encryptionKeyIds[] = data.getLongArray(ENCRYPTION_KEYS_IDS);
|
||||
@ -243,7 +279,7 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
|
||||
boolean generateSignature = data.getBoolean(GENERATE_SIGNATURE);
|
||||
boolean signOnly = data.getBoolean(SIGN_ONLY);
|
||||
|
||||
// Operation
|
||||
/* Operation */
|
||||
ByteArrayInputStream inStream = new ByteArrayInputStream(bytes);
|
||||
int inLength = bytes.length;
|
||||
|
||||
@ -252,20 +288,20 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
|
||||
|
||||
if (generateSignature) {
|
||||
Log.d(Constants.TAG, "generate signature...");
|
||||
Apg.generateSignature(this, inputData, outStream, useAsciiArmour, false,
|
||||
secretKeyId, Apg.getCachedPassPhrase(secretKeyId), Preferences
|
||||
PGPHelper.generateSignature(this, inputData, outStream, useAsciiArmour, false,
|
||||
secretKeyId, PGPHelper.getCachedPassPhrase(secretKeyId), Preferences
|
||||
.getPreferences(this).getDefaultHashAlgorithm(), Preferences
|
||||
.getPreferences(this).getForceV3Signatures(), this);
|
||||
} else if (signOnly) {
|
||||
Log.d(Constants.TAG, "sign only...");
|
||||
Apg.signText(this, inputData, outStream, secretKeyId, Apg
|
||||
PGPHelper.signText(this, inputData, outStream, secretKeyId, PGPHelper
|
||||
.getCachedPassPhrase(secretKeyId), Preferences.getPreferences(this)
|
||||
.getDefaultHashAlgorithm(), Preferences.getPreferences(this)
|
||||
.getForceV3Signatures(), this);
|
||||
} else {
|
||||
Log.d(Constants.TAG, "encrypt...");
|
||||
Apg.encrypt(this, inputData, outStream, useAsciiArmour, encryptionKeyIds,
|
||||
signatureKeyId, Apg.getCachedPassPhrase(signatureKeyId), this,
|
||||
PGPHelper.encrypt(this, inputData, outStream, useAsciiArmour, encryptionKeyIds,
|
||||
signatureKeyId, PGPHelper.getCachedPassPhrase(signatureKeyId), this,
|
||||
Preferences.getPreferences(this).getDefaultEncryptionAlgorithm(),
|
||||
Preferences.getPreferences(this).getDefaultHashAlgorithm(),
|
||||
compressionId, Preferences.getPreferences(this).getForceV3Signatures(),
|
||||
@ -274,7 +310,7 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
|
||||
|
||||
outStream.close();
|
||||
|
||||
// Output
|
||||
/* Output */
|
||||
Bundle resultData = new Bundle();
|
||||
|
||||
if (useAsciiArmour) {
|
||||
@ -302,7 +338,7 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
|
||||
|
||||
case ACTION_ENCRYPT_SIGN_FILE:
|
||||
try {
|
||||
// Input
|
||||
/* Input */
|
||||
long secretKeyId = data.getLong(SECRET_KEY_ID);
|
||||
String passphrase = data.getString(SYMMETRIC_PASSPHRASE);
|
||||
|
||||
@ -316,51 +352,41 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
|
||||
boolean generateSignature = data.getBoolean(GENERATE_SIGNATURE);
|
||||
boolean signOnly = data.getBoolean(SIGN_ONLY);
|
||||
|
||||
// InputStream
|
||||
long inLength = -1;
|
||||
FileInputStream inStream = null;
|
||||
if (inputFile.startsWith(Environment.getExternalStorageDirectory()
|
||||
.getAbsolutePath())) {
|
||||
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
||||
/* Operation */
|
||||
// check if storage is ready
|
||||
if (!FileHelper.isStorageMounted(inputFile)
|
||||
|| !FileHelper.isStorageMounted(outputFile)) {
|
||||
sendErrorToHandler(new GeneralException(
|
||||
getString(R.string.error_externalStorageNotReady)));
|
||||
return;
|
||||
}
|
||||
}
|
||||
inStream = new FileInputStream(inputFile);
|
||||
|
||||
// InputStream
|
||||
long inLength = -1;
|
||||
FileInputStream inStream = new FileInputStream(inputFile);
|
||||
File file = new File(inputFile);
|
||||
inLength = file.length();
|
||||
|
||||
InputData inputData = new InputData(inStream, inLength);
|
||||
|
||||
// OutputStream
|
||||
if (outputFile.startsWith(Environment.getExternalStorageDirectory()
|
||||
.getAbsolutePath())) {
|
||||
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
||||
sendErrorToHandler(new GeneralException(
|
||||
getString(R.string.error_externalStorageNotReady)));
|
||||
return;
|
||||
}
|
||||
}
|
||||
FileOutputStream outStream = new FileOutputStream(outputFile);
|
||||
|
||||
// Operation
|
||||
if (generateSignature) {
|
||||
Log.d(Constants.TAG, "generate signature...");
|
||||
Apg.generateSignature(this, inputData, outStream, useAsciiArmour, true,
|
||||
secretKeyId, Apg.getCachedPassPhrase(secretKeyId), Preferences
|
||||
PGPHelper.generateSignature(this, inputData, outStream, useAsciiArmour, true,
|
||||
secretKeyId, PGPHelper.getCachedPassPhrase(secretKeyId), Preferences
|
||||
.getPreferences(this).getDefaultHashAlgorithm(), Preferences
|
||||
.getPreferences(this).getForceV3Signatures(), this);
|
||||
} else if (signOnly) {
|
||||
Log.d(Constants.TAG, "sign only...");
|
||||
Apg.signText(this, inputData, outStream, secretKeyId, Apg
|
||||
PGPHelper.signText(this, inputData, outStream, secretKeyId, PGPHelper
|
||||
.getCachedPassPhrase(secretKeyId), Preferences.getPreferences(this)
|
||||
.getDefaultHashAlgorithm(), Preferences.getPreferences(this)
|
||||
.getForceV3Signatures(), this);
|
||||
} else {
|
||||
Log.d(Constants.TAG, "encrypt...");
|
||||
Apg.encrypt(this, inputData, outStream, useAsciiArmour, encryptionKeyIds,
|
||||
signatureKeyId, Apg.getCachedPassPhrase(signatureKeyId), this,
|
||||
PGPHelper.encrypt(this, inputData, outStream, useAsciiArmour, encryptionKeyIds,
|
||||
signatureKeyId, PGPHelper.getCachedPassPhrase(signatureKeyId), this,
|
||||
Preferences.getPreferences(this).getDefaultEncryptionAlgorithm(),
|
||||
Preferences.getPreferences(this).getDefaultHashAlgorithm(),
|
||||
compressionId, Preferences.getPreferences(this).getForceV3Signatures(),
|
||||
@ -369,6 +395,7 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
|
||||
|
||||
outStream.close();
|
||||
|
||||
/* Output */
|
||||
sendMessageToHandler(ApgHandler.MESSAGE_OKAY);
|
||||
} catch (Exception e) {
|
||||
sendErrorToHandler(e);
|
||||
@ -377,7 +404,7 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
|
||||
|
||||
case ACTION_ENCRYPT_SIGN_STREAM:
|
||||
try {
|
||||
// Input
|
||||
/* Input */
|
||||
long secretKeyId = data.getLong(SECRET_KEY_ID);
|
||||
String passphrase = data.getString(SYMMETRIC_PASSPHRASE);
|
||||
|
||||
@ -390,19 +417,20 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
|
||||
boolean generateSignature = data.getBoolean(GENERATE_SIGNATURE);
|
||||
boolean signOnly = data.getBoolean(SIGN_ONLY);
|
||||
|
||||
/* Operation */
|
||||
// InputStream
|
||||
InputStream in = getContentResolver().openInputStream(providerUri);
|
||||
long inLength = Apg.getLengthOfStream(in);
|
||||
|
||||
long inLength = PGPHelper.getLengthOfStream(in);
|
||||
InputData inputData = new InputData(in, inLength);
|
||||
|
||||
// OutputStream
|
||||
String streamFilename = null;
|
||||
try {
|
||||
while (true) {
|
||||
streamFilename = Apg.generateRandomString(32);
|
||||
streamFilename = PGPHelper.generateRandomString(32);
|
||||
if (streamFilename == null) {
|
||||
throw new Apg.GeneralException("couldn't generate random file name");
|
||||
throw new PGPHelper.GeneralException(
|
||||
"couldn't generate random file name");
|
||||
}
|
||||
openFileInput(streamFilename).close();
|
||||
}
|
||||
@ -411,20 +439,19 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
|
||||
}
|
||||
FileOutputStream outStream = openFileOutput(streamFilename, Context.MODE_PRIVATE);
|
||||
|
||||
// Operation
|
||||
if (generateSignature) {
|
||||
Apg.generateSignature(this, inputData, outStream, useAsciiArmour, true,
|
||||
secretKeyId, Apg.getCachedPassPhrase(secretKeyId), Preferences
|
||||
PGPHelper.generateSignature(this, inputData, outStream, useAsciiArmour, true,
|
||||
secretKeyId, PGPHelper.getCachedPassPhrase(secretKeyId), Preferences
|
||||
.getPreferences(this).getDefaultHashAlgorithm(), Preferences
|
||||
.getPreferences(this).getForceV3Signatures(), this);
|
||||
} else if (signOnly) {
|
||||
Apg.signText(this, inputData, outStream, secretKeyId, Apg
|
||||
PGPHelper.signText(this, inputData, outStream, secretKeyId, PGPHelper
|
||||
.getCachedPassPhrase(secretKeyId), Preferences.getPreferences(this)
|
||||
.getDefaultHashAlgorithm(), Preferences.getPreferences(this)
|
||||
.getForceV3Signatures(), this);
|
||||
} else {
|
||||
Apg.encrypt(this, inputData, outStream, useAsciiArmour, encryptionKeyIds,
|
||||
signatureKeyId, Apg.getCachedPassPhrase(signatureKeyId), this,
|
||||
PGPHelper.encrypt(this, inputData, outStream, useAsciiArmour, encryptionKeyIds,
|
||||
signatureKeyId, PGPHelper.getCachedPassPhrase(signatureKeyId), this,
|
||||
Preferences.getPreferences(this).getDefaultEncryptionAlgorithm(),
|
||||
Preferences.getPreferences(this).getDefaultHashAlgorithm(),
|
||||
compressionId, Preferences.getPreferences(this).getForceV3Signatures(),
|
||||
@ -433,7 +460,7 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
|
||||
|
||||
outStream.close();
|
||||
|
||||
// Output
|
||||
/* Output */
|
||||
Bundle resultData = new Bundle();
|
||||
|
||||
String uri = "content://" + DataProvider.AUTHORITY + "/data/" + streamFilename;
|
||||
@ -448,21 +475,21 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
|
||||
|
||||
case ACTION_DELETE_FILE_SECURELY:
|
||||
try {
|
||||
// Input
|
||||
/* Input */
|
||||
String deleteFile = data.getString(DELETE_FILE);
|
||||
|
||||
// Operation
|
||||
/* Operation */
|
||||
try {
|
||||
Apg.deleteFileSecurely(this, new File(deleteFile), this);
|
||||
PGPHelper.deleteFileSecurely(this, new File(deleteFile), this);
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new Apg.GeneralException(getString(R.string.error_fileNotFound,
|
||||
throw new PGPHelper.GeneralException(getString(R.string.error_fileNotFound,
|
||||
deleteFile));
|
||||
} catch (IOException e) {
|
||||
throw new Apg.GeneralException(getString(R.string.error_fileDeleteFailed,
|
||||
throw new PGPHelper.GeneralException(getString(R.string.error_fileDeleteFailed,
|
||||
deleteFile));
|
||||
}
|
||||
|
||||
// Output
|
||||
/* Output */
|
||||
sendMessageToHandler(ApgHandler.MESSAGE_OKAY);
|
||||
} catch (Exception e) {
|
||||
sendErrorToHandler(e);
|
||||
@ -470,6 +497,157 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
|
||||
|
||||
break;
|
||||
|
||||
case ACTION_DECRYPT_BYTES:
|
||||
try {
|
||||
/* Input */
|
||||
long secretKeyId = data.getLong(SECRET_KEY_ID);
|
||||
byte[] bytes = data.getByteArray(CIPHERTEXT_BYTES);
|
||||
boolean signedOnly = data.getBoolean(SIGNED_ONLY);
|
||||
boolean returnBytes = data.getBoolean(RETURN_BYTES);
|
||||
boolean assumeSymmetricEncryption = data.getBoolean(ASSUME_SYMMETRIC);
|
||||
|
||||
/* Operation */
|
||||
ByteArrayInputStream inStream = new ByteArrayInputStream(bytes);
|
||||
int inLength = bytes.length;
|
||||
|
||||
InputData inputData = new InputData(inStream, inLength);
|
||||
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
|
||||
|
||||
Bundle resultData = new Bundle();
|
||||
|
||||
// verifyText and decrypt returning additional resultData values for the
|
||||
// verification of signatures
|
||||
if (signedOnly) {
|
||||
resultData = PGPHelper.verifyText(this, inputData, outStream, this);
|
||||
} else {
|
||||
resultData = PGPHelper.decrypt(this, inputData, outStream,
|
||||
PGPHelper.getCachedPassPhrase(secretKeyId), this,
|
||||
assumeSymmetricEncryption);
|
||||
}
|
||||
|
||||
outStream.close();
|
||||
|
||||
/* Output */
|
||||
if (returnBytes) {
|
||||
byte output[] = outStream.toByteArray();
|
||||
resultData.putByteArray(RESULT_DECRYPTED_DATA, output);
|
||||
} else {
|
||||
String output = new String(outStream.toByteArray());
|
||||
resultData.putString(RESULT_DECRYPTED_MESSAGE, output);
|
||||
}
|
||||
|
||||
sendMessageToHandler(ApgHandler.MESSAGE_OKAY, resultData);
|
||||
} catch (Exception e) {
|
||||
sendErrorToHandler(e);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case ACTION_DECRYPT_FILE:
|
||||
try {
|
||||
/* Input */
|
||||
long secretKeyId = data.getLong(SECRET_KEY_ID);
|
||||
boolean signedOnly = data.getBoolean(SIGNED_ONLY);
|
||||
boolean assumeSymmetricEncryption = data.getBoolean(ASSUME_SYMMETRIC);
|
||||
|
||||
String inputFile = data.getString(INPUT_FILE);
|
||||
String outputFile = data.getString(OUTPUT_FILE);
|
||||
|
||||
/* Operation */
|
||||
// check if storage is ready
|
||||
if (!FileHelper.isStorageMounted(inputFile)
|
||||
|| !FileHelper.isStorageMounted(outputFile)) {
|
||||
sendErrorToHandler(new GeneralException(
|
||||
getString(R.string.error_externalStorageNotReady)));
|
||||
return;
|
||||
}
|
||||
|
||||
// InputStream
|
||||
long inLength = -1;
|
||||
FileInputStream inStream = new FileInputStream(inputFile);
|
||||
File file = new File(inputFile);
|
||||
inLength = file.length();
|
||||
InputData inputData = new InputData(inStream, inLength);
|
||||
|
||||
// OutputStream
|
||||
FileOutputStream outStream = new FileOutputStream(outputFile);
|
||||
|
||||
Bundle resultData = new Bundle();
|
||||
|
||||
// verifyText and decrypt returning additional output values for the
|
||||
// verification of signatures
|
||||
if (signedOnly) {
|
||||
resultData = PGPHelper.verifyText(this, inputData, outStream, this);
|
||||
} else {
|
||||
resultData = PGPHelper.decrypt(this, inputData, outStream,
|
||||
PGPHelper.getCachedPassPhrase(secretKeyId), this,
|
||||
assumeSymmetricEncryption);
|
||||
}
|
||||
|
||||
outStream.close();
|
||||
|
||||
/* Output */
|
||||
sendMessageToHandler(ApgHandler.MESSAGE_OKAY, resultData);
|
||||
} catch (Exception e) {
|
||||
sendErrorToHandler(e);
|
||||
}
|
||||
break;
|
||||
|
||||
case ACTION_DECRYPT_STREAM:
|
||||
try {
|
||||
/* Input */
|
||||
long secretKeyId = data.getLong(SECRET_KEY_ID);
|
||||
boolean signedOnly = data.getBoolean(SIGNED_ONLY);
|
||||
boolean assumeSymmetricEncryption = data.getBoolean(ASSUME_SYMMETRIC);
|
||||
Uri providerUri = Uri.parse(data.getString(PROVIDER_URI));
|
||||
|
||||
/* Operation */
|
||||
// InputStream
|
||||
InputStream in = getContentResolver().openInputStream(providerUri);
|
||||
long inLength = PGPHelper.getLengthOfStream(in);
|
||||
InputData inputData = new InputData(in, inLength);
|
||||
|
||||
// OutputStream
|
||||
String streamFilename = null;
|
||||
try {
|
||||
while (true) {
|
||||
streamFilename = PGPHelper.generateRandomString(32);
|
||||
if (streamFilename == null) {
|
||||
throw new PGPHelper.GeneralException(
|
||||
"couldn't generate random file name");
|
||||
}
|
||||
openFileInput(streamFilename).close();
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
// found a name that isn't used yet
|
||||
}
|
||||
FileOutputStream outStream = openFileOutput(streamFilename, Context.MODE_PRIVATE);
|
||||
|
||||
Bundle resultData = new Bundle();
|
||||
|
||||
// verifyText and decrypt returning additional output values for the
|
||||
// verification of signatures
|
||||
if (signedOnly) {
|
||||
resultData = PGPHelper.verifyText(this, inputData, outStream, this);
|
||||
} else {
|
||||
resultData = PGPHelper.decrypt(this, inputData, outStream,
|
||||
PGPHelper.getCachedPassPhrase(secretKeyId), this,
|
||||
assumeSymmetricEncryption);
|
||||
}
|
||||
|
||||
outStream.close();
|
||||
|
||||
/* Output */
|
||||
String uri = "content://" + DataProvider.AUTHORITY + "/data/" + streamFilename;
|
||||
resultData.putString(RESULT_URI, uri);
|
||||
|
||||
sendMessageToHandler(ApgHandler.MESSAGE_OKAY, resultData);
|
||||
} catch (Exception e) {
|
||||
sendErrorToHandler(e);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -21,12 +21,12 @@ import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.thialfihar.android.apg.R;
|
||||
import org.thialfihar.android.apg.Apg;
|
||||
import org.thialfihar.android.apg.Constants;
|
||||
import org.thialfihar.android.apg.Id;
|
||||
import org.thialfihar.android.apg.PausableThread;
|
||||
import org.thialfihar.android.apg.Preferences;
|
||||
import org.thialfihar.android.apg.ProgressDialogUpdater;
|
||||
import org.thialfihar.android.apg.helper.PGPHelper;
|
||||
import org.thialfihar.android.apg.passphrase.AskForPassphrase;
|
||||
import org.thialfihar.android.apg.passphrase.PassphraseCacheService;
|
||||
|
||||
@ -79,7 +79,7 @@ public class BaseActivity extends SherlockFragmentActivity implements Runnable,
|
||||
// not needed later:
|
||||
mPreferences = Preferences.getPreferences(this);
|
||||
|
||||
Apg.initialize(this);
|
||||
PGPHelper.initialize(this);
|
||||
|
||||
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
||||
File dir = new File(Constants.path.APP_DIR);
|
||||
@ -275,7 +275,7 @@ public class BaseActivity extends SherlockFragmentActivity implements Runnable,
|
||||
case Id.request.secret_keys: {
|
||||
if (resultCode == RESULT_OK) {
|
||||
Bundle bundle = data.getExtras();
|
||||
setSecretKeyId(bundle.getLong(Apg.EXTRA_KEY_ID));
|
||||
setSecretKeyId(bundle.getLong(PGPHelper.EXTRA_KEY_ID));
|
||||
} else {
|
||||
setSecretKeyId(Id.key.none);
|
||||
}
|
||||
@ -378,7 +378,7 @@ public class BaseActivity extends SherlockFragmentActivity implements Runnable,
|
||||
|
||||
public void passPhraseCallback(long keyId, String passPhrase) {
|
||||
// TODO: Not needed anymore, now implemented in AskForSecretKeyPass
|
||||
Apg.setCachedPassPhrase(keyId, passPhrase);
|
||||
PGPHelper.setCachedPassPhrase(keyId, passPhrase);
|
||||
}
|
||||
|
||||
public void sendMessage(Message msg) {
|
||||
|
@ -19,31 +19,40 @@ package org.thialfihar.android.apg.ui;
|
||||
import org.spongycastle.jce.provider.BouncyCastleProvider;
|
||||
import org.spongycastle.openpgp.PGPException;
|
||||
import org.spongycastle.openpgp.PGPPublicKeyRing;
|
||||
import org.thialfihar.android.apg.Apg;
|
||||
import org.thialfihar.android.apg.Constants;
|
||||
import org.thialfihar.android.apg.DataDestination;
|
||||
import org.thialfihar.android.apg.DataSource;
|
||||
import org.thialfihar.android.apg.FileDialog;
|
||||
import org.thialfihar.android.apg.Id;
|
||||
import org.thialfihar.android.apg.InputData;
|
||||
import org.thialfihar.android.apg.PausableThread;
|
||||
import org.thialfihar.android.apg.helper.FileHelper;
|
||||
import org.thialfihar.android.apg.helper.PGPHelper;
|
||||
import org.thialfihar.android.apg.helper.OtherHelper;
|
||||
import org.thialfihar.android.apg.helper.PGPHelper.GeneralException;
|
||||
import org.thialfihar.android.apg.provider.DataProvider;
|
||||
import org.thialfihar.android.apg.service.ApgHandler;
|
||||
import org.thialfihar.android.apg.service.ApgService;
|
||||
import org.thialfihar.android.apg.ui.dialog.DeleteFileDialogFragment;
|
||||
import org.thialfihar.android.apg.ui.dialog.FileDialogFragment;
|
||||
import org.thialfihar.android.apg.ui.dialog.PassphraseDialogFragment;
|
||||
import org.thialfihar.android.apg.ui.dialog.ProgressDialogFragment;
|
||||
import org.thialfihar.android.apg.util.Compatibility;
|
||||
import org.thialfihar.android.apg.util.Utils;
|
||||
import org.thialfihar.android.apg.util.InputData;
|
||||
import org.thialfihar.android.apg.R;
|
||||
|
||||
import com.actionbarsherlock.app.ActionBar;
|
||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
import com.actionbarsherlock.view.Menu;
|
||||
import com.actionbarsherlock.view.MenuItem;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.os.Messenger;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
@ -57,8 +66,10 @@ import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import android.widget.ViewFlipper;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@ -67,7 +78,7 @@ import java.security.Security;
|
||||
import java.security.SignatureException;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
public class DecryptActivity extends BaseActivity {
|
||||
public class DecryptActivity extends SherlockFragmentActivity {
|
||||
private long mSignatureKeyId = 0;
|
||||
|
||||
private Intent mIntent;
|
||||
@ -110,11 +121,24 @@ public class DecryptActivity extends BaseActivity {
|
||||
private byte[] mData = null;
|
||||
private boolean mReturnBinary = false;
|
||||
|
||||
private DataSource mDataSource = null;
|
||||
private DataDestination mDataDestination = null;
|
||||
// private DataSource mDataSource = null;
|
||||
// private DataDestination mDataDestination = null;
|
||||
|
||||
private long mUnknownSignatureKeyId = 0;
|
||||
|
||||
private long mSecretKeyId = Id.key.none;
|
||||
|
||||
private ProgressDialogFragment mDecryptingDialog;
|
||||
private FileDialogFragment mFileDialog;
|
||||
|
||||
public void setSecretKeyId(long id) {
|
||||
mSecretKeyId = id;
|
||||
}
|
||||
|
||||
public long getSecretKeyId() {
|
||||
return mSecretKeyId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
|
||||
@ -163,6 +187,18 @@ public class DecryptActivity extends BaseActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.decrypt);
|
||||
|
||||
// set actionbar without home button if called from another app
|
||||
final ActionBar actionBar = getSupportActionBar();
|
||||
Log.d(Constants.TAG, "calling package (only set when using startActivityForResult)="
|
||||
+ getCallingPackage());
|
||||
if (getCallingPackage() != null && getCallingPackage().equals(PGPHelper.PACKAGE_NAME)) {
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
actionBar.setHomeButtonEnabled(true);
|
||||
} else {
|
||||
actionBar.setDisplayHomeAsUpEnabled(false);
|
||||
actionBar.setHomeButtonEnabled(false);
|
||||
}
|
||||
|
||||
mSource = (ViewFlipper) findViewById(R.id.source);
|
||||
mSourceLabel = (TextView) findViewById(R.id.sourceLabel);
|
||||
mSourcePrevious = (ImageView) findViewById(R.id.sourcePrevious);
|
||||
@ -213,7 +249,7 @@ public class DecryptActivity extends BaseActivity {
|
||||
mBrowse = (ImageButton) findViewById(R.id.btn_browse);
|
||||
mBrowse.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
Utils.openFile(DecryptActivity.this, mFilename.getText().toString(), "*/*",
|
||||
FileHelper.openFile(DecryptActivity.this, mFilename.getText().toString(), "*/*",
|
||||
Id.request.filename);
|
||||
}
|
||||
});
|
||||
@ -246,7 +282,7 @@ public class DecryptActivity extends BaseActivity {
|
||||
} catch (IOException e) {
|
||||
// ignore, then
|
||||
}
|
||||
} else if (Apg.Intent.DECRYPT.equals(mIntent.getAction())) {
|
||||
} else if (PGPHelper.Intent.DECRYPT.equals(mIntent.getAction())) {
|
||||
Log.d(Constants.TAG, "Apg Intent DECRYPT startet");
|
||||
Bundle extras = mIntent.getExtras();
|
||||
if (extras == null) {
|
||||
@ -256,17 +292,17 @@ public class DecryptActivity extends BaseActivity {
|
||||
Log.d(Constants.TAG, "got extras");
|
||||
}
|
||||
|
||||
mData = extras.getByteArray(Apg.EXTRA_DATA);
|
||||
mData = extras.getByteArray(PGPHelper.EXTRA_DATA);
|
||||
String textData = null;
|
||||
if (mData == null) {
|
||||
Log.d(Constants.TAG, "EXTRA_DATA was null");
|
||||
textData = extras.getString(Apg.EXTRA_TEXT);
|
||||
textData = extras.getString(PGPHelper.EXTRA_TEXT);
|
||||
} else {
|
||||
Log.d(Constants.TAG, "Got data from EXTRA_DATA");
|
||||
}
|
||||
if (textData != null) {
|
||||
Log.d(Constants.TAG, "textData null, matching text ...");
|
||||
Matcher matcher = Apg.PGP_MESSAGE.matcher(textData);
|
||||
Matcher matcher = PGPHelper.PGP_MESSAGE.matcher(textData);
|
||||
if (matcher.matches()) {
|
||||
Log.d(Constants.TAG, "PGP_MESSAGE matched");
|
||||
textData = matcher.group(1);
|
||||
@ -274,7 +310,7 @@ public class DecryptActivity extends BaseActivity {
|
||||
textData = textData.replaceAll("\\xa0", " ");
|
||||
mMessage.setText(textData);
|
||||
} else {
|
||||
matcher = Apg.PGP_SIGNED_MESSAGE.matcher(textData);
|
||||
matcher = PGPHelper.PGP_SIGNED_MESSAGE.matcher(textData);
|
||||
if (matcher.matches()) {
|
||||
Log.d(Constants.TAG, "PGP_SIGNED_MESSAGE matched");
|
||||
textData = matcher.group(1);
|
||||
@ -290,9 +326,9 @@ public class DecryptActivity extends BaseActivity {
|
||||
}
|
||||
}
|
||||
}
|
||||
mReplyTo = extras.getString(Apg.EXTRA_REPLY_TO);
|
||||
mSubject = extras.getString(Apg.EXTRA_SUBJECT);
|
||||
} else if (Apg.Intent.DECRYPT_FILE.equals(mIntent.getAction())) {
|
||||
mReplyTo = extras.getString(PGPHelper.EXTRA_REPLY_TO);
|
||||
mSubject = extras.getString(PGPHelper.EXTRA_SUBJECT);
|
||||
} else if (PGPHelper.Intent.DECRYPT_FILE.equals(mIntent.getAction())) {
|
||||
mInputFilename = mIntent.getDataString();
|
||||
if ("file".equals(mIntent.getScheme())) {
|
||||
mInputFilename = Uri.decode(mInputFilename.substring(7));
|
||||
@ -304,37 +340,27 @@ public class DecryptActivity extends BaseActivity {
|
||||
while (mSource.getCurrentView().getId() != R.id.sourceFile) {
|
||||
mSource.showNext();
|
||||
}
|
||||
} else if (Apg.Intent.DECRYPT_AND_RETURN.equals(mIntent.getAction())) {
|
||||
} else if (PGPHelper.Intent.DECRYPT_AND_RETURN.equals(mIntent.getAction())) {
|
||||
mContentUri = mIntent.getData();
|
||||
Bundle extras = mIntent.getExtras();
|
||||
if (extras == null) {
|
||||
extras = new Bundle();
|
||||
}
|
||||
|
||||
// set actionbar without home button if called from another app
|
||||
final ActionBar actionBar = getSupportActionBar();
|
||||
if (getCallingPackage() != null && getCallingPackage().equals(Apg.PACKAGE_NAME)) {
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
actionBar.setHomeButtonEnabled(true);
|
||||
} else {
|
||||
actionBar.setDisplayHomeAsUpEnabled(false);
|
||||
actionBar.setHomeButtonEnabled(false);
|
||||
}
|
||||
|
||||
mReturnBinary = extras.getBoolean(Apg.EXTRA_BINARY, false);
|
||||
mReturnBinary = extras.getBoolean(PGPHelper.EXTRA_BINARY, false);
|
||||
|
||||
if (mContentUri == null) {
|
||||
mData = extras.getByteArray(Apg.EXTRA_DATA);
|
||||
String data = extras.getString(Apg.EXTRA_TEXT);
|
||||
mData = extras.getByteArray(PGPHelper.EXTRA_DATA);
|
||||
String data = extras.getString(PGPHelper.EXTRA_TEXT);
|
||||
if (data != null) {
|
||||
Matcher matcher = Apg.PGP_MESSAGE.matcher(data);
|
||||
Matcher matcher = PGPHelper.PGP_MESSAGE.matcher(data);
|
||||
if (matcher.matches()) {
|
||||
data = matcher.group(1);
|
||||
// replace non breakable spaces
|
||||
data = data.replaceAll("\\xa0", " ");
|
||||
mMessage.setText(data);
|
||||
} else {
|
||||
matcher = Apg.PGP_SIGNED_MESSAGE.matcher(data);
|
||||
matcher = PGPHelper.PGP_SIGNED_MESSAGE.matcher(data);
|
||||
if (matcher.matches()) {
|
||||
data = matcher.group(1);
|
||||
// replace non breakable spaces
|
||||
@ -358,9 +384,9 @@ public class DecryptActivity extends BaseActivity {
|
||||
|
||||
String data = "";
|
||||
if (clipboardText != null) {
|
||||
Matcher matcher = Apg.PGP_MESSAGE.matcher(clipboardText);
|
||||
Matcher matcher = PGPHelper.PGP_MESSAGE.matcher(clipboardText);
|
||||
if (!matcher.matches()) {
|
||||
matcher = Apg.PGP_SIGNED_MESSAGE.matcher(clipboardText);
|
||||
matcher = PGPHelper.PGP_SIGNED_MESSAGE.matcher(clipboardText);
|
||||
}
|
||||
if (matcher.matches()) {
|
||||
data = matcher.group(1);
|
||||
@ -376,11 +402,11 @@ public class DecryptActivity extends BaseActivity {
|
||||
if (mSignatureKeyId == 0) {
|
||||
return;
|
||||
}
|
||||
PGPPublicKeyRing key = Apg.getPublicKeyRing(mSignatureKeyId);
|
||||
PGPPublicKeyRing key = PGPHelper.getPublicKeyRing(mSignatureKeyId);
|
||||
if (key != null) {
|
||||
Intent intent = new Intent(DecryptActivity.this, KeyServerQueryActivity.class);
|
||||
intent.setAction(Apg.Intent.LOOK_UP_KEY_ID);
|
||||
intent.putExtra(Apg.EXTRA_KEY_ID, mSignatureKeyId);
|
||||
intent.setAction(PGPHelper.Intent.LOOK_UP_KEY_ID);
|
||||
intent.putExtra(PGPHelper.EXTRA_KEY_ID, mSignatureKeyId);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
@ -483,7 +509,7 @@ public class DecryptActivity extends BaseActivity {
|
||||
|
||||
if (mDecryptTarget == Id.target.message) {
|
||||
String messageData = mMessage.getText().toString();
|
||||
Matcher matcher = Apg.PGP_SIGNED_MESSAGE.matcher(messageData);
|
||||
Matcher matcher = PGPHelper.PGP_SIGNED_MESSAGE.matcher(messageData);
|
||||
if (matcher.matches()) {
|
||||
mSignedOnly = true;
|
||||
decryptStart();
|
||||
@ -493,28 +519,16 @@ public class DecryptActivity extends BaseActivity {
|
||||
|
||||
// else treat it as an decrypted message/file
|
||||
mSignedOnly = false;
|
||||
String error = null;
|
||||
fillDataSource();
|
||||
try {
|
||||
InputData in = mDataSource.getInputData(this, false);
|
||||
try {
|
||||
setSecretKeyId(Apg.getDecryptionKeyId(this, in));
|
||||
if (getSecretKeyId() == Id.key.none) {
|
||||
throw new Apg.GeneralException(getString(R.string.error_noSecretKeyFound));
|
||||
}
|
||||
mAssumeSymmetricEncryption = false;
|
||||
} catch (Apg.NoAsymmetricEncryptionException e) {
|
||||
setSecretKeyId(Id.key.symmetric);
|
||||
in = mDataSource.getInputData(this, false);
|
||||
if (!Apg.hasSymmetricEncryption(this, in)) {
|
||||
throw new Apg.GeneralException(getString(R.string.error_noKnownEncryptionFound));
|
||||
}
|
||||
mAssumeSymmetricEncryption = true;
|
||||
}
|
||||
|
||||
getDecryptionKeyFromInputStream();
|
||||
|
||||
Log.d(Constants.TAG, "secretKeyId: " + getSecretKeyId());
|
||||
|
||||
// if we need a symmetric passphrase or a passphrase to use a sekret key ask for it
|
||||
if (getSecretKeyId() == Id.key.symmetric
|
||||
|| Apg.getCachedPassPhrase(getSecretKeyId()) == null) {
|
||||
showDialog(Id.dialog.pass_phrase);
|
||||
|| PGPHelper.getCachedPassPhrase(getSecretKeyId()) == null) {
|
||||
// showDialog(Id.dialog.pass_phrase);
|
||||
showPassphraseDialog();
|
||||
} else {
|
||||
if (mDecryptTarget == Id.target.file) {
|
||||
askForOutputFilename();
|
||||
@ -522,128 +536,196 @@ public class DecryptActivity extends BaseActivity {
|
||||
decryptStart();
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
error = getString(R.string.error_fileNotFound);
|
||||
} catch (IOException e) {
|
||||
error = "" + e;
|
||||
} catch (Apg.GeneralException e) {
|
||||
error = "" + e;
|
||||
}
|
||||
if (error != null) {
|
||||
Toast.makeText(this, getString(R.string.errorMessage, error), Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
|
||||
/**
|
||||
* Shows passphrase dialog to cache a new passphrase the user enters for using it later for
|
||||
* encryption. Based on mSecretKeyId it asks for a passphrase to open a private key or it asks
|
||||
* for a symmetric passphrase
|
||||
*/
|
||||
private void showPassphraseDialog() {
|
||||
// Message is received after passphrase is cached
|
||||
Handler returnHandler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message message) {
|
||||
if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) {
|
||||
if (mDecryptTarget == Id.target.file) {
|
||||
askForOutputFilename();
|
||||
} else {
|
||||
decryptStart();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Create a new Messenger for the communication back
|
||||
Messenger messenger = new Messenger(returnHandler);
|
||||
|
||||
try {
|
||||
PassphraseDialogFragment passphraseDialog = PassphraseDialogFragment.newInstance(
|
||||
messenger, mSecretKeyId);
|
||||
|
||||
passphraseDialog.show(getSupportFragmentManager(), "passphraseDialog");
|
||||
} catch (PGPHelper.GeneralException e) {
|
||||
Log.d(Constants.TAG, "No passphrase for this secret key, encrypt directly!");
|
||||
// send message to handler to start encryption directly
|
||||
returnHandler.sendEmptyMessage(PassphraseDialogFragment.MESSAGE_OKAY);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: externalize this into ApgService???
|
||||
*/
|
||||
private void getDecryptionKeyFromInputStream() {
|
||||
InputStream inStream = null;
|
||||
if (mContentUri != null) {
|
||||
try {
|
||||
inStream = getContentResolver().openInputStream(mContentUri);
|
||||
} catch (FileNotFoundException e) {
|
||||
Log.e(Constants.TAG, "File not found!", e);
|
||||
Toast.makeText(this, getString(R.string.error_fileNotFound, e.getMessage()),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else if (mDecryptTarget == Id.target.file) {
|
||||
// check if storage is ready
|
||||
if (!FileHelper.isStorageMounted(mInputFilename)) {
|
||||
Toast.makeText(this, getString(R.string.error_externalStorageNotReady),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
inStream = new FileInputStream(mInputFilename);
|
||||
} catch (FileNotFoundException e) {
|
||||
Log.e(Constants.TAG, "File not found!", e);
|
||||
Toast.makeText(this, getString(R.string.error_fileNotFound, e.getMessage()),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else {
|
||||
if (mData != null) {
|
||||
inStream = new ByteArrayInputStream(mData);
|
||||
} else {
|
||||
inStream = new ByteArrayInputStream(mMessage.getText().toString().getBytes());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
try {
|
||||
setSecretKeyId(PGPHelper.getDecryptionKeyId(this, inStream));
|
||||
if (getSecretKeyId() == Id.key.none) {
|
||||
throw new PGPHelper.GeneralException(getString(R.string.error_noSecretKeyFound));
|
||||
}
|
||||
mAssumeSymmetricEncryption = false;
|
||||
} catch (PGPHelper.NoAsymmetricEncryptionException e) {
|
||||
setSecretKeyId(Id.key.symmetric);
|
||||
if (!PGPHelper.hasSymmetricEncryption(this, inStream)) {
|
||||
throw new PGPHelper.GeneralException(
|
||||
getString(R.string.error_noKnownEncryptionFound));
|
||||
}
|
||||
mAssumeSymmetricEncryption = true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Toast.makeText(this, getString(R.string.errorMessage, e.getMessage()),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
private void replyClicked() {
|
||||
Intent intent = new Intent(this, EncryptActivity.class);
|
||||
intent.setAction(Apg.Intent.ENCRYPT);
|
||||
intent.setAction(PGPHelper.Intent.ENCRYPT);
|
||||
String data = mMessage.getText().toString();
|
||||
data = data.replaceAll("(?m)^", "> ");
|
||||
data = "\n\n" + data;
|
||||
intent.putExtra(Apg.EXTRA_TEXT, data);
|
||||
intent.putExtra(Apg.EXTRA_SUBJECT, "Re: " + mSubject);
|
||||
intent.putExtra(Apg.EXTRA_SEND_TO, mReplyTo);
|
||||
intent.putExtra(Apg.EXTRA_SIGNATURE_KEY_ID, getSecretKeyId());
|
||||
intent.putExtra(Apg.EXTRA_ENCRYPTION_KEY_IDS, new long[] { mSignatureKeyId });
|
||||
intent.putExtra(PGPHelper.EXTRA_TEXT, data);
|
||||
intent.putExtra(PGPHelper.EXTRA_SUBJECT, "Re: " + mSubject);
|
||||
intent.putExtra(PGPHelper.EXTRA_SEND_TO, mReplyTo);
|
||||
intent.putExtra(PGPHelper.EXTRA_SIGNATURE_KEY_ID, getSecretKeyId());
|
||||
intent.putExtra(PGPHelper.EXTRA_ENCRYPTION_KEY_IDS, new long[] { mSignatureKeyId });
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
private void askForOutputFilename() {
|
||||
showDialog(Id.dialog.output_filename);
|
||||
}
|
||||
|
||||
// Message is received after passphrase is cached
|
||||
Handler returnHandler = new Handler() {
|
||||
@Override
|
||||
public void passPhraseCallback(long keyId, String passPhrase) {
|
||||
super.passPhraseCallback(keyId, passPhrase);
|
||||
if (mDecryptTarget == Id.target.file) {
|
||||
askForOutputFilename();
|
||||
} else {
|
||||
public void handleMessage(Message message) {
|
||||
if (message.what == FileDialogFragment.MESSAGE_OKAY) {
|
||||
Bundle data = message.getData();
|
||||
mOutputFilename = data.getString(FileDialogFragment.MESSAGE_DATA_FILENAME);
|
||||
decryptStart();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Create a new Messenger for the communication back
|
||||
Messenger messenger = new Messenger(returnHandler);
|
||||
|
||||
mFileDialog = FileDialogFragment.newInstance(messenger,
|
||||
getString(R.string.title_decryptToFile),
|
||||
getString(R.string.specifyFileToDecryptTo), mOutputFilename, null,
|
||||
Id.request.output_filename);
|
||||
|
||||
mFileDialog.show(getSupportFragmentManager(), "fileDialog");
|
||||
|
||||
}
|
||||
|
||||
private void decryptStart() {
|
||||
showDialog(Id.dialog.decrypting);
|
||||
startThread();
|
||||
}
|
||||
Log.d(Constants.TAG, "decryptStart");
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
String error = null;
|
||||
Security.addProvider(new BouncyCastleProvider());
|
||||
// Send all information needed to service to edit key in other thread
|
||||
Intent intent = new Intent(this, ApgService.class);
|
||||
|
||||
// fill values for this action
|
||||
Bundle data = new Bundle();
|
||||
Message msg = new Message();
|
||||
fillDataSource();
|
||||
fillDataDestination();
|
||||
try {
|
||||
InputData in = mDataSource.getInputData(this, true);
|
||||
OutputStream out = mDataDestination.getOutputStream(this);
|
||||
|
||||
if (mSignedOnly) {
|
||||
data = Apg.verifyText(this, in, out, this);
|
||||
// choose action based on input: decrypt stream, file or bytes
|
||||
if (mContentUri != null) {
|
||||
intent.putExtra(ApgService.EXTRA_ACTION, ApgService.ACTION_DECRYPT_STREAM);
|
||||
data.putString(ApgService.PROVIDER_URI, mContentUri.toString());
|
||||
|
||||
} else if (mDecryptTarget == Id.target.file) {
|
||||
intent.putExtra(ApgService.EXTRA_ACTION, ApgService.ACTION_DECRYPT_FILE);
|
||||
|
||||
Log.d(Constants.TAG, "mInputFilename=" + mInputFilename + ", mOutputFilename="
|
||||
+ mOutputFilename);
|
||||
|
||||
data.putString(ApgService.INPUT_FILE, mInputFilename);
|
||||
data.putString(ApgService.OUTPUT_FILE, mOutputFilename);
|
||||
|
||||
} else {
|
||||
data = Apg.decrypt(this, in, out, Apg.getCachedPassPhrase(getSecretKeyId()), this,
|
||||
mAssumeSymmetricEncryption);
|
||||
}
|
||||
intent.putExtra(ApgService.EXTRA_ACTION, ApgService.ACTION_DECRYPT_BYTES);
|
||||
|
||||
out.close();
|
||||
|
||||
if (mDataDestination.getStreamFilename() != null) {
|
||||
data.putString(Apg.EXTRA_RESULT_URI, "content://" + DataProvider.AUTHORITY
|
||||
+ "/data/" + mDataDestination.getStreamFilename());
|
||||
} else if (mDecryptTarget == Id.target.message) {
|
||||
if (mReturnBinary) {
|
||||
data.putByteArray(Apg.EXTRA_DECRYPTED_DATA,
|
||||
((ByteArrayOutputStream) out).toByteArray());
|
||||
if (mData != null) {
|
||||
data.putByteArray(ApgService.CIPHERTEXT_BYTES, mData);
|
||||
} else {
|
||||
data.putString(Apg.EXTRA_DECRYPTED_MESSAGE, new String(
|
||||
((ByteArrayOutputStream) out).toByteArray()));
|
||||
String message = mMessage.getText().toString();
|
||||
data.putByteArray(ApgService.CIPHERTEXT_BYTES, message.getBytes());
|
||||
}
|
||||
}
|
||||
} catch (PGPException e) {
|
||||
error = "" + e;
|
||||
} catch (IOException e) {
|
||||
error = "" + e;
|
||||
} catch (SignatureException e) {
|
||||
error = "" + e;
|
||||
} catch (Apg.GeneralException e) {
|
||||
error = "" + e;
|
||||
}
|
||||
|
||||
data.putInt(Constants.extras.STATUS, Id.message.done);
|
||||
data.putLong(ApgService.SECRET_KEY_ID, getSecretKeyId());
|
||||
|
||||
if (error != null) {
|
||||
data.putString(Apg.EXTRA_ERROR, error);
|
||||
}
|
||||
data.putBoolean(ApgService.SIGNED_ONLY, mSignedOnly);
|
||||
data.putBoolean(ApgService.RETURN_BYTES, mReturnBinary);
|
||||
data.putBoolean(ApgService.ASSUME_SYMMETRIC, mAssumeSymmetricEncryption);
|
||||
|
||||
msg.setData(data);
|
||||
sendMessage(msg);
|
||||
}
|
||||
intent.putExtra(ApgService.EXTRA_DATA, data);
|
||||
|
||||
@Override
|
||||
public void handlerCallback(Message msg) {
|
||||
Bundle data = msg.getData();
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
// create progress dialog
|
||||
mDecryptingDialog = ProgressDialogFragment.newInstance(R.string.progress_decrypting,
|
||||
ProgressDialog.STYLE_HORIZONTAL);
|
||||
|
||||
if (data.getInt(Constants.extras.STATUS) == Id.message.unknown_signature_key) {
|
||||
mUnknownSignatureKeyId = data.getLong(Constants.extras.KEY_ID);
|
||||
showDialog(Id.dialog.lookup_unknown_key);
|
||||
return;
|
||||
}
|
||||
// Message is received after encrypting is done in ApgService
|
||||
ApgHandler saveHandler = new ApgHandler(this, mDecryptingDialog) {
|
||||
public void handleMessage(Message message) {
|
||||
// handle messages by standard ApgHandler first
|
||||
super.handleMessage(message);
|
||||
|
||||
super.handlerCallback(msg);
|
||||
}
|
||||
if (message.arg1 == ApgHandler.MESSAGE_OKAY) {
|
||||
// get returned data bundle
|
||||
Bundle data = message.getData();
|
||||
|
||||
@Override
|
||||
public void doneCallback(Message msg) {
|
||||
super.doneCallback(msg);
|
||||
|
||||
Bundle data = msg.getData();
|
||||
removeDialog(Id.dialog.decrypting);
|
||||
mSignatureKeyId = 0;
|
||||
mSignatureLayout.setVisibility(View.GONE);
|
||||
mReplyEnabled = false;
|
||||
@ -651,14 +733,8 @@ public class DecryptActivity extends BaseActivity {
|
||||
// build new action bar
|
||||
invalidateOptionsMenu();
|
||||
|
||||
String error = data.getString(Apg.EXTRA_ERROR);
|
||||
if (error != null) {
|
||||
Toast.makeText(this, getString(R.string.errorMessage, error), Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
return;
|
||||
}
|
||||
|
||||
Toast.makeText(this, R.string.decryptionSuccessful, Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(DecryptActivity.this, R.string.decryptionSuccessful,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
if (mReturnResult) {
|
||||
Intent intent = new Intent();
|
||||
intent.putExtras(data);
|
||||
@ -669,7 +745,8 @@ public class DecryptActivity extends BaseActivity {
|
||||
|
||||
switch (mDecryptTarget) {
|
||||
case Id.target.message: {
|
||||
String decryptedMessage = data.getString(Apg.EXTRA_DECRYPTED_MESSAGE);
|
||||
String decryptedMessage = data
|
||||
.getString(ApgService.RESULT_DECRYPTED_MESSAGE);
|
||||
mMessage.setText(decryptedMessage);
|
||||
mMessage.setHorizontallyScrolling(false);
|
||||
mReplyEnabled = false;
|
||||
@ -681,8 +758,10 @@ public class DecryptActivity extends BaseActivity {
|
||||
|
||||
case Id.target.file: {
|
||||
if (mDeleteAfter.isChecked()) {
|
||||
setDeleteFile(mInputFilename);
|
||||
showDialog(Id.dialog.delete_file);
|
||||
// Create and show dialog to delete original file
|
||||
DeleteFileDialogFragment deleteFileDialog = DeleteFileDialogFragment
|
||||
.newInstance(mInputFilename);
|
||||
deleteFileDialog.show(getSupportFragmentManager(), "deleteDialog");
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -693,10 +772,11 @@ public class DecryptActivity extends BaseActivity {
|
||||
}
|
||||
}
|
||||
|
||||
if (data.getBoolean(Apg.EXTRA_SIGNATURE)) {
|
||||
String userId = data.getString(Apg.EXTRA_SIGNATURE_USER_ID);
|
||||
mSignatureKeyId = data.getLong(Apg.EXTRA_SIGNATURE_KEY_ID);
|
||||
mUserIdRest.setText("id: " + Apg.getSmallFingerPrint(mSignatureKeyId));
|
||||
if (data.getBoolean(ApgService.EXTRA_SIGNATURE)) {
|
||||
String userId = data.getString(ApgService.EXTRA_SIGNATURE_USER_ID);
|
||||
mSignatureKeyId = data.getLong(ApgService.EXTRA_SIGNATURE_KEY_ID);
|
||||
mUserIdRest
|
||||
.setText("id: " + PGPHelper.getSmallFingerPrint(mSignatureKeyId));
|
||||
if (userId == null) {
|
||||
userId = getResources().getString(R.string.unknownUserId);
|
||||
}
|
||||
@ -707,11 +787,12 @@ public class DecryptActivity extends BaseActivity {
|
||||
}
|
||||
mUserId.setText(userId);
|
||||
|
||||
if (data.getBoolean(Apg.EXTRA_SIGNATURE_SUCCESS)) {
|
||||
if (data.getBoolean(ApgService.EXTRA_SIGNATURE_SUCCESS)) {
|
||||
mSignatureStatusImage.setImageResource(R.drawable.overlay_ok);
|
||||
} else if (data.getBoolean(Apg.EXTRA_SIGNATURE_UNKNOWN)) {
|
||||
} else if (data.getBoolean(ApgService.EXTRA_SIGNATURE_UNKNOWN)) {
|
||||
mSignatureStatusImage.setImageResource(R.drawable.overlay_error);
|
||||
Toast.makeText(this, R.string.unknownSignatureKeyTouchToLookUp, Toast.LENGTH_LONG)
|
||||
Toast.makeText(DecryptActivity.this,
|
||||
R.string.unknownSignatureKeyTouchToLookUp, Toast.LENGTH_LONG)
|
||||
.show();
|
||||
} else {
|
||||
mSignatureStatusImage.setImageResource(R.drawable.overlay_error);
|
||||
@ -719,22 +800,185 @@ public class DecryptActivity extends BaseActivity {
|
||||
mSignatureLayout.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// Create a new Messenger for the communication back
|
||||
Messenger messenger = new Messenger(saveHandler);
|
||||
intent.putExtra(ApgService.EXTRA_MESSENGER, messenger);
|
||||
|
||||
// show progress dialog
|
||||
mDecryptingDialog.show(getSupportFragmentManager(), "decryptingDialog");
|
||||
|
||||
// start service with intent
|
||||
startService(intent);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void run() {
|
||||
// String error = null;
|
||||
// Security.addProvider(new BouncyCastleProvider());
|
||||
//
|
||||
// Bundle data = new Bundle();
|
||||
// Message msg = new Message();
|
||||
// fillDataSource();
|
||||
// fillDataDestination();
|
||||
// try {
|
||||
// InputData in = mDataSource.getInputData(this, true);
|
||||
// OutputStream out = mDataDestination.getOutputStream(this);
|
||||
//
|
||||
// if (mSignedOnly) {
|
||||
// data = Apg.verifyText(this, in, out, this);
|
||||
// } else {
|
||||
// data = Apg.decrypt(this, in, out, Apg.getCachedPassPhrase(getSecretKeyId()), this,
|
||||
// mAssumeSymmetricEncryption);
|
||||
// }
|
||||
//
|
||||
// out.close();
|
||||
//
|
||||
// if (mDataDestination.getStreamFilename() != null) {
|
||||
// data.putString(Apg.EXTRA_RESULT_URI, "content://" + DataProvider.AUTHORITY
|
||||
// + "/data/" + mDataDestination.getStreamFilename());
|
||||
// } else if (mDecryptTarget == Id.target.message) {
|
||||
// if (mReturnBinary) {
|
||||
// data.putByteArray(Apg.EXTRA_DECRYPTED_DATA,
|
||||
// ((ByteArrayOutputStream) out).toByteArray());
|
||||
// } else {
|
||||
// data.putString(Apg.EXTRA_DECRYPTED_MESSAGE, new String(
|
||||
// ((ByteArrayOutputStream) out).toByteArray()));
|
||||
// }
|
||||
// }
|
||||
// } catch (PGPException e) {
|
||||
// error = "" + e;
|
||||
// } catch (IOException e) {
|
||||
// error = "" + e;
|
||||
// } catch (SignatureException e) {
|
||||
// error = "" + e;
|
||||
// } catch (Apg.GeneralException e) {
|
||||
// error = "" + e;
|
||||
// }
|
||||
//
|
||||
// data.putInt(Constants.extras.STATUS, Id.message.done);
|
||||
//
|
||||
// if (error != null) {
|
||||
// data.putString(Apg.EXTRA_ERROR, error);
|
||||
// }
|
||||
//
|
||||
// msg.setData(data);
|
||||
// sendMessage(msg);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void handlerCallback(Message msg) {
|
||||
// Bundle data = msg.getData();
|
||||
// if (data == null) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// if (data.getInt(Constants.extras.STATUS) == Id.message.unknown_signature_key) {
|
||||
// mUnknownSignatureKeyId = data.getLong(Constants.extras.KEY_ID);
|
||||
// showDialog(Id.dialog.lookup_unknown_key);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// super.handlerCallback(msg);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void doneCallback(Message msg) {
|
||||
// super.doneCallback(msg);
|
||||
//
|
||||
// Bundle data = msg.getData();
|
||||
// removeDialog(Id.dialog.decrypting);
|
||||
// mSignatureKeyId = 0;
|
||||
// mSignatureLayout.setVisibility(View.GONE);
|
||||
// mReplyEnabled = false;
|
||||
//
|
||||
// // build new action bar
|
||||
// invalidateOptionsMenu();
|
||||
//
|
||||
// String error = data.getString(Apg.EXTRA_ERROR);
|
||||
// if (error != null) {
|
||||
// Toast.makeText(this, getString(R.string.errorMessage, error), Toast.LENGTH_SHORT)
|
||||
// .show();
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// Toast.makeText(this, R.string.decryptionSuccessful, Toast.LENGTH_SHORT).show();
|
||||
// if (mReturnResult) {
|
||||
// Intent intent = new Intent();
|
||||
// intent.putExtras(data);
|
||||
// setResult(RESULT_OK, intent);
|
||||
// finish();
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// switch (mDecryptTarget) {
|
||||
// case Id.target.message: {
|
||||
// String decryptedMessage = data.getString(Apg.EXTRA_DECRYPTED_MESSAGE);
|
||||
// mMessage.setText(decryptedMessage);
|
||||
// mMessage.setHorizontallyScrolling(false);
|
||||
// mReplyEnabled = false;
|
||||
//
|
||||
// // build new action bar
|
||||
// invalidateOptionsMenu();
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// case Id.target.file: {
|
||||
// if (mDeleteAfter.isChecked()) {
|
||||
// //TODO
|
||||
// // setDeleteFile(mInputFilename);
|
||||
// // showDialog(Id.dialog.delete_file);
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// default: {
|
||||
// // shouldn't happen
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (data.getBoolean(Apg.EXTRA_SIGNATURE)) {
|
||||
// String userId = data.getString(Apg.EXTRA_SIGNATURE_USER_ID);
|
||||
// mSignatureKeyId = data.getLong(Apg.EXTRA_SIGNATURE_KEY_ID);
|
||||
// mUserIdRest.setText("id: " + Apg.getSmallFingerPrint(mSignatureKeyId));
|
||||
// if (userId == null) {
|
||||
// userId = getResources().getString(R.string.unknownUserId);
|
||||
// }
|
||||
// String chunks[] = userId.split(" <", 2);
|
||||
// userId = chunks[0];
|
||||
// if (chunks.length > 1) {
|
||||
// mUserIdRest.setText("<" + chunks[1]);
|
||||
// }
|
||||
// mUserId.setText(userId);
|
||||
//
|
||||
// if (data.getBoolean(Apg.EXTRA_SIGNATURE_SUCCESS)) {
|
||||
// mSignatureStatusImage.setImageResource(R.drawable.overlay_ok);
|
||||
// } else if (data.getBoolean(Apg.EXTRA_SIGNATURE_UNKNOWN)) {
|
||||
// mSignatureStatusImage.setImageResource(R.drawable.overlay_error);
|
||||
// Toast.makeText(this, R.string.unknownSignatureKeyTouchToLookUp, Toast.LENGTH_LONG)
|
||||
// .show();
|
||||
// } else {
|
||||
// mSignatureStatusImage.setImageResource(R.drawable.overlay_error);
|
||||
// }
|
||||
// mSignatureLayout.setVisibility(View.VISIBLE);
|
||||
// }
|
||||
// }
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
switch (requestCode) {
|
||||
case Id.request.filename: {
|
||||
if (resultCode == RESULT_OK && data != null) {
|
||||
String filename = data.getDataString();
|
||||
if (filename != null) {
|
||||
// Get rid of URI prefix:
|
||||
if (filename.startsWith("file://")) {
|
||||
filename = filename.substring(7);
|
||||
}
|
||||
// replace %20 and so on
|
||||
filename = Uri.decode(filename);
|
||||
try {
|
||||
String path = data.getData().getPath();
|
||||
Log.d(Constants.TAG, "path=" + path);
|
||||
|
||||
mFilename.setText(filename);
|
||||
mFilename.setText(path);
|
||||
} catch (NullPointerException e) {
|
||||
Log.e(Constants.TAG, "Nullpointer while retrieving path!");
|
||||
}
|
||||
}
|
||||
return;
|
||||
@ -742,26 +986,24 @@ public class DecryptActivity extends BaseActivity {
|
||||
|
||||
case Id.request.output_filename: {
|
||||
if (resultCode == RESULT_OK && data != null) {
|
||||
String filename = data.getDataString();
|
||||
if (filename != null) {
|
||||
// Get rid of URI prefix:
|
||||
if (filename.startsWith("file://")) {
|
||||
filename = filename.substring(7);
|
||||
}
|
||||
// replace %20 and so on
|
||||
filename = Uri.decode(filename);
|
||||
try {
|
||||
String path = data.getData().getPath();
|
||||
Log.d(Constants.TAG, "path=" + path);
|
||||
|
||||
FileDialog.setFilename(filename);
|
||||
mFileDialog.setFilename(path);
|
||||
} catch (NullPointerException e) {
|
||||
Log.e(Constants.TAG, "Nullpointer while retrieving path!");
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
case Id.request.look_up_key_id: {
|
||||
PausableThread thread = getRunningThread();
|
||||
if (thread != null && thread.isPaused()) {
|
||||
thread.unpause();
|
||||
}
|
||||
// TODO
|
||||
// PausableThread thread = getRunningThread();
|
||||
// if (thread != null && thread.isPaused()) {
|
||||
// thread.unpause();
|
||||
// }
|
||||
return;
|
||||
}
|
||||
|
||||
@ -776,22 +1018,22 @@ public class DecryptActivity extends BaseActivity {
|
||||
@Override
|
||||
protected Dialog onCreateDialog(int id) {
|
||||
switch (id) {
|
||||
case Id.dialog.output_filename: {
|
||||
return FileDialog.build(this, getString(R.string.title_decryptToFile),
|
||||
getString(R.string.specifyFileToDecryptTo), mOutputFilename,
|
||||
new FileDialog.OnClickListener() {
|
||||
public void onOkClick(String filename, boolean checked) {
|
||||
removeDialog(Id.dialog.output_filename);
|
||||
mOutputFilename = filename;
|
||||
decryptStart();
|
||||
}
|
||||
|
||||
public void onCancelClick() {
|
||||
removeDialog(Id.dialog.output_filename);
|
||||
}
|
||||
}, getString(R.string.filemanager_titleSave),
|
||||
getString(R.string.filemanager_btnSave), null, Id.request.output_filename);
|
||||
}
|
||||
// case Id.dialog.output_filename: {
|
||||
// return FileDialog.build(this, getString(R.string.title_decryptToFile),
|
||||
// getString(R.string.specifyFileToDecryptTo), mOutputFilename,
|
||||
// new FileDialog.OnClickListener() {
|
||||
// public void onOkClick(String filename, boolean checked) {
|
||||
// removeDialog(Id.dialog.output_filename);
|
||||
// mOutputFilename = filename;
|
||||
// decryptStart();
|
||||
// }
|
||||
//
|
||||
// public void onCancelClick() {
|
||||
// removeDialog(Id.dialog.output_filename);
|
||||
// }
|
||||
// }, getString(R.string.filemanager_titleSave),
|
||||
// getString(R.string.filemanager_btnSave), null, Id.request.output_filename);
|
||||
// }
|
||||
|
||||
case Id.dialog.lookup_unknown_key: {
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(this);
|
||||
@ -799,24 +1041,25 @@ public class DecryptActivity extends BaseActivity {
|
||||
alert.setIcon(android.R.drawable.ic_dialog_alert);
|
||||
alert.setTitle(R.string.title_unknownSignatureKey);
|
||||
alert.setMessage(getString(R.string.lookupUnknownKey,
|
||||
Apg.getSmallFingerPrint(mUnknownSignatureKeyId)));
|
||||
PGPHelper.getSmallFingerPrint(mUnknownSignatureKeyId)));
|
||||
|
||||
alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
removeDialog(Id.dialog.lookup_unknown_key);
|
||||
Intent intent = new Intent(DecryptActivity.this, KeyServerQueryActivity.class);
|
||||
intent.setAction(Apg.Intent.LOOK_UP_KEY_ID);
|
||||
intent.putExtra(Apg.EXTRA_KEY_ID, mUnknownSignatureKeyId);
|
||||
intent.setAction(PGPHelper.Intent.LOOK_UP_KEY_ID);
|
||||
intent.putExtra(PGPHelper.EXTRA_KEY_ID, mUnknownSignatureKeyId);
|
||||
startActivityForResult(intent, Id.request.look_up_key_id);
|
||||
}
|
||||
});
|
||||
alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
removeDialog(Id.dialog.lookup_unknown_key);
|
||||
PausableThread thread = getRunningThread();
|
||||
if (thread != null && thread.isPaused()) {
|
||||
thread.unpause();
|
||||
}
|
||||
// TODO
|
||||
// PausableThread thread = getRunningThread();
|
||||
// if (thread != null && thread.isPaused()) {
|
||||
// thread.unpause();
|
||||
// }
|
||||
}
|
||||
});
|
||||
alert.setCancelable(true);
|
||||
@ -831,31 +1074,4 @@ public class DecryptActivity extends BaseActivity {
|
||||
|
||||
return super.onCreateDialog(id);
|
||||
}
|
||||
|
||||
protected void fillDataSource() {
|
||||
mDataSource = new DataSource();
|
||||
if (mContentUri != null) {
|
||||
mDataSource.setUri(mContentUri);
|
||||
} else if (mDecryptTarget == Id.target.file) {
|
||||
mDataSource.setUri(mInputFilename);
|
||||
} else {
|
||||
if (mData != null) {
|
||||
mDataSource.setData(mData);
|
||||
} else {
|
||||
mDataSource.setText(mMessage.getText().toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void fillDataDestination() {
|
||||
mDataDestination = new DataDestination();
|
||||
if (mContentUri != null) {
|
||||
mDataDestination.setMode(Id.mode.stream);
|
||||
} else if (mDecryptTarget == Id.target.file) {
|
||||
mDataDestination.setFilename(mOutputFilename);
|
||||
mDataDestination.setMode(Id.mode.file);
|
||||
} else {
|
||||
mDataDestination.setMode(Id.mode.byte_array);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,9 +19,11 @@ package org.thialfihar.android.apg.ui;
|
||||
|
||||
import org.spongycastle.openpgp.PGPSecretKey;
|
||||
import org.spongycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.thialfihar.android.apg.Apg;
|
||||
import org.thialfihar.android.apg.Constants;
|
||||
import org.thialfihar.android.apg.Id;
|
||||
import org.thialfihar.android.apg.helper.PGPHelper;
|
||||
import org.thialfihar.android.apg.helper.OtherHelper;
|
||||
import org.thialfihar.android.apg.helper.PGPConversionHelper;
|
||||
import org.thialfihar.android.apg.service.ApgHandler;
|
||||
import org.thialfihar.android.apg.service.ApgService;
|
||||
import org.thialfihar.android.apg.ui.dialog.ProgressDialogFragment;
|
||||
@ -29,7 +31,6 @@ import org.thialfihar.android.apg.ui.widget.KeyEditor;
|
||||
import org.thialfihar.android.apg.ui.widget.SectionView;
|
||||
import org.thialfihar.android.apg.ui.widget.UserIdEditor;
|
||||
import org.thialfihar.android.apg.util.IterableIterator;
|
||||
import org.thialfihar.android.apg.util.Utils;
|
||||
import org.thialfihar.android.apg.R;
|
||||
|
||||
import com.actionbarsherlock.app.ActionBar;
|
||||
@ -132,7 +133,7 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
||||
mActionBar.setDisplayShowTitleEnabled(true);
|
||||
|
||||
// set actionbar without home button if called from another app
|
||||
if (getCallingPackage() != null && getCallingPackage().equals(Apg.PACKAGE_NAME)) {
|
||||
if (getCallingPackage() != null && getCallingPackage().equals(PGPHelper.PACKAGE_NAME)) {
|
||||
mActionBar.setDisplayHomeAsUpEnabled(true);
|
||||
mActionBar.setHomeButtonEnabled(true);
|
||||
} else {
|
||||
@ -153,7 +154,7 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
||||
|
||||
// Handle intents
|
||||
Bundle extras = mIntent.getExtras();
|
||||
if (Apg.Intent.CREATE_KEY.equals(mIntent.getAction())) {
|
||||
if (PGPHelper.Intent.CREATE_KEY.equals(mIntent.getAction())) {
|
||||
|
||||
mActionBar.setTitle(R.string.title_createKey);
|
||||
|
||||
@ -161,14 +162,14 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
||||
|
||||
if (extras != null) {
|
||||
// if userId is given, prefill the fields
|
||||
if (extras.containsKey(Apg.EXTRA_USER_IDS)) {
|
||||
if (extras.containsKey(PGPHelper.EXTRA_USER_IDS)) {
|
||||
Log.d(Constants.TAG, "UserIds are given!");
|
||||
mUserIds.add(extras.getString(Apg.EXTRA_USER_IDS));
|
||||
mUserIds.add(extras.getString(PGPHelper.EXTRA_USER_IDS));
|
||||
}
|
||||
|
||||
// if no passphrase is given
|
||||
if (extras.containsKey(Apg.EXTRA_NO_PASSPHRASE)) {
|
||||
boolean noPassphrase = extras.getBoolean(Apg.EXTRA_NO_PASSPHRASE);
|
||||
if (extras.containsKey(PGPHelper.EXTRA_NO_PASSPHRASE)) {
|
||||
boolean noPassphrase = extras.getBoolean(PGPHelper.EXTRA_NO_PASSPHRASE);
|
||||
if (noPassphrase) {
|
||||
// check "no passphrase" checkbox and remove button
|
||||
mNoPassphrase.setChecked(true);
|
||||
@ -177,9 +178,9 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
||||
}
|
||||
|
||||
// generate key
|
||||
if (extras.containsKey(Apg.EXTRA_GENERATE_DEFAULT_KEYS)) {
|
||||
if (extras.containsKey(PGPHelper.EXTRA_GENERATE_DEFAULT_KEYS)) {
|
||||
boolean generateDefaultKeys = extras
|
||||
.getBoolean(Apg.EXTRA_GENERATE_DEFAULT_KEYS);
|
||||
.getBoolean(PGPHelper.EXTRA_GENERATE_DEFAULT_KEYS);
|
||||
if (generateDefaultKeys) {
|
||||
|
||||
// build layout in handler after generating keys not directly in onCreate
|
||||
@ -209,10 +210,10 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
||||
if (message.arg1 == ApgHandler.MESSAGE_OKAY) {
|
||||
// get new key from data bundle returned from service
|
||||
Bundle data = message.getData();
|
||||
PGPSecretKeyRing masterKeyRing = Utils
|
||||
PGPSecretKeyRing masterKeyRing = PGPConversionHelper
|
||||
.BytesToPGPSecretKeyRing(data
|
||||
.getByteArray(ApgService.RESULT_NEW_KEY));
|
||||
PGPSecretKeyRing subKeyRing = Utils
|
||||
PGPSecretKeyRing subKeyRing = PGPConversionHelper
|
||||
.BytesToPGPSecretKeyRing(data
|
||||
.getByteArray(ApgService.RESULT_NEW_KEY2));
|
||||
|
||||
@ -243,11 +244,11 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (Apg.Intent.EDIT_KEY.equals(mIntent.getAction())) {
|
||||
} else if (PGPHelper.Intent.EDIT_KEY.equals(mIntent.getAction())) {
|
||||
|
||||
mActionBar.setTitle(R.string.title_editKey);
|
||||
|
||||
mCurrentPassPhrase = Apg.getEditPassPhrase();
|
||||
mCurrentPassPhrase = PGPHelper.getEditPassPhrase();
|
||||
if (mCurrentPassPhrase == null) {
|
||||
mCurrentPassPhrase = "";
|
||||
}
|
||||
@ -260,14 +261,14 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
||||
|
||||
if (extras != null) {
|
||||
|
||||
if (extras.containsKey(Apg.EXTRA_KEY_ID)) {
|
||||
long keyId = mIntent.getExtras().getLong(Apg.EXTRA_KEY_ID);
|
||||
if (extras.containsKey(PGPHelper.EXTRA_KEY_ID)) {
|
||||
long keyId = mIntent.getExtras().getLong(PGPHelper.EXTRA_KEY_ID);
|
||||
|
||||
if (keyId != 0) {
|
||||
PGPSecretKey masterKey = null;
|
||||
mKeyRing = Apg.getSecretKeyRing(keyId);
|
||||
mKeyRing = PGPHelper.getSecretKeyRing(keyId);
|
||||
if (mKeyRing != null) {
|
||||
masterKey = Apg.getMasterKey(mKeyRing);
|
||||
masterKey = PGPHelper.getMasterKey(mKeyRing);
|
||||
for (PGPSecretKey key : new IterableIterator<PGPSecretKey>(
|
||||
mKeyRing.getSecretKeys())) {
|
||||
mKeys.add(key);
|
||||
@ -411,7 +412,7 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
||||
|
||||
try {
|
||||
if (!isPassphraseSet()) {
|
||||
throw new Apg.GeneralException(this.getString(R.string.setAPassPhrase));
|
||||
throw new PGPHelper.GeneralException(this.getString(R.string.setAPassPhrase));
|
||||
}
|
||||
|
||||
// Send all information needed to service to edit key in other thread
|
||||
@ -425,7 +426,7 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
||||
data.putString(ApgService.NEW_PASSPHRASE, mNewPassPhrase);
|
||||
data.putSerializable(ApgService.USER_IDS, getUserIds(mUserIdsView));
|
||||
Vector<PGPSecretKey> keys = getKeys(mKeysView);
|
||||
data.putByteArray(ApgService.KEYS, Utils.PGPSecretKeyListToBytes(keys));
|
||||
data.putByteArray(ApgService.KEYS, PGPConversionHelper.PGPSecretKeyListToBytes(keys));
|
||||
data.putSerializable(ApgService.KEYS_USAGES, getKeysUsages(mKeysView));
|
||||
data.putLong(ApgService.MASTER_KEY_ID, getMasterKeyId());
|
||||
|
||||
@ -455,7 +456,7 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
||||
|
||||
// start service with intent
|
||||
startService(intent);
|
||||
} catch (Apg.GeneralException e) {
|
||||
} catch (PGPHelper.GeneralException e) {
|
||||
Toast.makeText(this, getString(R.string.errorMessage, e.getMessage()),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
@ -467,7 +468,8 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
||||
* @param userIdsView
|
||||
* @return
|
||||
*/
|
||||
private Vector<String> getUserIds(SectionView userIdsView) throws Apg.GeneralException {
|
||||
private Vector<String> getUserIds(SectionView userIdsView)
|
||||
throws PGPHelper.GeneralException {
|
||||
Vector<String> userIds = new Vector<String>();
|
||||
|
||||
ViewGroup userIdEditors = userIdsView.getEditors();
|
||||
@ -479,12 +481,13 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
||||
try {
|
||||
userId = editor.getValue();
|
||||
} catch (UserIdEditor.NoNameException e) {
|
||||
throw new Apg.GeneralException(this.getString(R.string.error_userIdNeedsAName));
|
||||
throw new PGPHelper.GeneralException(
|
||||
this.getString(R.string.error_userIdNeedsAName));
|
||||
} catch (UserIdEditor.NoEmailException e) {
|
||||
throw new Apg.GeneralException(
|
||||
throw new PGPHelper.GeneralException(
|
||||
this.getString(R.string.error_userIdNeedsAnEmailAddress));
|
||||
} catch (UserIdEditor.InvalidEmailException e) {
|
||||
throw new Apg.GeneralException(e.getMessage());
|
||||
throw new PGPHelper.GeneralException(e.getMessage());
|
||||
}
|
||||
|
||||
if (userId.equals("")) {
|
||||
@ -500,11 +503,12 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
||||
}
|
||||
|
||||
if (userIds.size() == 0) {
|
||||
throw new Apg.GeneralException(getString(R.string.error_keyNeedsAUserId));
|
||||
throw new PGPHelper.GeneralException(getString(R.string.error_keyNeedsAUserId));
|
||||
}
|
||||
|
||||
if (!gotMainUserId) {
|
||||
throw new Apg.GeneralException(getString(R.string.error_mainUserIdMustNotBeEmpty));
|
||||
throw new PGPHelper.GeneralException(
|
||||
getString(R.string.error_mainUserIdMustNotBeEmpty));
|
||||
}
|
||||
|
||||
return userIds;
|
||||
@ -516,13 +520,14 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
||||
* @param keysView
|
||||
* @return
|
||||
*/
|
||||
private Vector<PGPSecretKey> getKeys(SectionView keysView) throws Apg.GeneralException {
|
||||
private Vector<PGPSecretKey> getKeys(SectionView keysView)
|
||||
throws PGPHelper.GeneralException {
|
||||
Vector<PGPSecretKey> keys = new Vector<PGPSecretKey>();
|
||||
|
||||
ViewGroup keyEditors = keysView.getEditors();
|
||||
|
||||
if (keyEditors.getChildCount() == 0) {
|
||||
throw new Apg.GeneralException(getString(R.string.error_keyNeedsMasterKey));
|
||||
throw new PGPHelper.GeneralException(getString(R.string.error_keyNeedsMasterKey));
|
||||
}
|
||||
|
||||
for (int i = 0; i < keyEditors.getChildCount(); ++i) {
|
||||
@ -539,13 +544,14 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
||||
* @param keysView
|
||||
* @return
|
||||
*/
|
||||
private Vector<Integer> getKeysUsages(SectionView keysView) throws Apg.GeneralException {
|
||||
private Vector<Integer> getKeysUsages(SectionView keysView)
|
||||
throws PGPHelper.GeneralException {
|
||||
Vector<Integer> getKeysUsages = new Vector<Integer>();
|
||||
|
||||
ViewGroup keyEditors = keysView.getEditors();
|
||||
|
||||
if (keyEditors.getChildCount() == 0) {
|
||||
throw new Apg.GeneralException(getString(R.string.error_keyNeedsMasterKey));
|
||||
throw new PGPHelper.GeneralException(getString(R.string.error_keyNeedsMasterKey));
|
||||
}
|
||||
|
||||
for (int i = 0; i < keyEditors.getChildCount(); ++i) {
|
||||
|
@ -21,10 +21,11 @@ import org.spongycastle.openpgp.PGPPublicKey;
|
||||
import org.spongycastle.openpgp.PGPPublicKeyRing;
|
||||
import org.spongycastle.openpgp.PGPSecretKey;
|
||||
import org.spongycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.thialfihar.android.apg.Apg;
|
||||
import org.thialfihar.android.apg.Constants;
|
||||
import org.thialfihar.android.apg.Id;
|
||||
import org.thialfihar.android.apg.Preferences;
|
||||
import org.thialfihar.android.apg.helper.FileHelper;
|
||||
import org.thialfihar.android.apg.helper.PGPHelper;
|
||||
import org.thialfihar.android.apg.service.ApgHandler;
|
||||
import org.thialfihar.android.apg.service.ApgService;
|
||||
import org.thialfihar.android.apg.ui.dialog.DeleteFileDialogFragment;
|
||||
@ -33,7 +34,6 @@ import org.thialfihar.android.apg.ui.dialog.PassphraseDialogFragment;
|
||||
import org.thialfihar.android.apg.ui.dialog.ProgressDialogFragment;
|
||||
import org.thialfihar.android.apg.util.Choice;
|
||||
import org.thialfihar.android.apg.util.Compatibility;
|
||||
import org.thialfihar.android.apg.util.Utils;
|
||||
import org.thialfihar.android.apg.R;
|
||||
|
||||
import com.actionbarsherlock.app.ActionBar;
|
||||
@ -181,6 +181,18 @@ public class EncryptActivity extends SherlockFragmentActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.encrypt);
|
||||
|
||||
// set actionbar without home button if called from another app
|
||||
final ActionBar actionBar = getSupportActionBar();
|
||||
Log.d(Constants.TAG, "calling package (only set when using startActivityForResult)="
|
||||
+ getCallingPackage());
|
||||
if (getCallingPackage() != null && getCallingPackage().equals(PGPHelper.PACKAGE_NAME)) {
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
actionBar.setHomeButtonEnabled(true);
|
||||
} else {
|
||||
actionBar.setDisplayHomeAsUpEnabled(false);
|
||||
actionBar.setHomeButtonEnabled(false);
|
||||
}
|
||||
|
||||
mGenerateSignature = false;
|
||||
|
||||
mSource = (ViewFlipper) findViewById(R.id.source);
|
||||
@ -268,7 +280,7 @@ public class EncryptActivity extends SherlockFragmentActivity {
|
||||
mBrowse = (ImageButton) findViewById(R.id.btn_browse);
|
||||
mBrowse.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
Utils.openFile(EncryptActivity.this, mFilename.getText().toString(), "*/*",
|
||||
FileHelper.openFile(EncryptActivity.this, mFilename.getText().toString(), "*/*",
|
||||
Id.request.filename);
|
||||
}
|
||||
});
|
||||
@ -323,61 +335,49 @@ public class EncryptActivity extends SherlockFragmentActivity {
|
||||
});
|
||||
|
||||
mIntent = getIntent();
|
||||
if (Apg.Intent.ENCRYPT.equals(mIntent.getAction())
|
||||
|| Apg.Intent.ENCRYPT_FILE.equals(mIntent.getAction())
|
||||
|| Apg.Intent.ENCRYPT_AND_RETURN.equals(mIntent.getAction())
|
||||
|| Apg.Intent.GENERATE_SIGNATURE.equals(mIntent.getAction())) {
|
||||
if (PGPHelper.Intent.ENCRYPT.equals(mIntent.getAction())
|
||||
|| PGPHelper.Intent.ENCRYPT_FILE.equals(mIntent.getAction())
|
||||
|| PGPHelper.Intent.ENCRYPT_AND_RETURN.equals(mIntent.getAction())
|
||||
|| PGPHelper.Intent.GENERATE_SIGNATURE.equals(mIntent.getAction())) {
|
||||
mContentUri = mIntent.getData();
|
||||
Bundle extras = mIntent.getExtras();
|
||||
if (extras == null) {
|
||||
extras = new Bundle();
|
||||
}
|
||||
|
||||
// set actionbar without home button if called from another app
|
||||
final ActionBar actionBar = getSupportActionBar();
|
||||
Log.d(Constants.TAG, "calling package (only set when using startActivityForResult)="
|
||||
+ getCallingPackage());
|
||||
if (getCallingPackage() != null && getCallingPackage().equals(Apg.PACKAGE_NAME)) {
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
actionBar.setHomeButtonEnabled(true);
|
||||
} else {
|
||||
actionBar.setDisplayHomeAsUpEnabled(false);
|
||||
actionBar.setHomeButtonEnabled(false);
|
||||
}
|
||||
|
||||
if (Apg.Intent.ENCRYPT_AND_RETURN.equals(mIntent.getAction())
|
||||
|| Apg.Intent.GENERATE_SIGNATURE.equals(mIntent.getAction())) {
|
||||
if (PGPHelper.Intent.ENCRYPT_AND_RETURN.equals(mIntent.getAction())
|
||||
|| PGPHelper.Intent.GENERATE_SIGNATURE.equals(mIntent.getAction())) {
|
||||
mReturnResult = true;
|
||||
}
|
||||
|
||||
if (Apg.Intent.GENERATE_SIGNATURE.equals(mIntent.getAction())) {
|
||||
if (PGPHelper.Intent.GENERATE_SIGNATURE.equals(mIntent.getAction())) {
|
||||
mGenerateSignature = true;
|
||||
mOverrideAsciiArmour = true;
|
||||
mAsciiArmourDemand = false;
|
||||
}
|
||||
|
||||
if (extras.containsKey(Apg.EXTRA_ASCII_ARMOUR)) {
|
||||
mAsciiArmourDemand = extras.getBoolean(Apg.EXTRA_ASCII_ARMOUR, true);
|
||||
if (extras.containsKey(PGPHelper.EXTRA_ASCII_ARMOUR)) {
|
||||
mAsciiArmourDemand = extras.getBoolean(PGPHelper.EXTRA_ASCII_ARMOUR, true);
|
||||
mOverrideAsciiArmour = true;
|
||||
mAsciiArmour.setChecked(mAsciiArmourDemand);
|
||||
}
|
||||
|
||||
mData = extras.getByteArray(Apg.EXTRA_DATA);
|
||||
mData = extras.getByteArray(PGPHelper.EXTRA_DATA);
|
||||
String textData = null;
|
||||
if (mData == null) {
|
||||
textData = extras.getString(Apg.EXTRA_TEXT);
|
||||
textData = extras.getString(PGPHelper.EXTRA_TEXT);
|
||||
}
|
||||
mSendTo = extras.getString(Apg.EXTRA_SEND_TO);
|
||||
mSubject = extras.getString(Apg.EXTRA_SUBJECT);
|
||||
long signatureKeyId = extras.getLong(Apg.EXTRA_SIGNATURE_KEY_ID);
|
||||
long encryptionKeyIds[] = extras.getLongArray(Apg.EXTRA_ENCRYPTION_KEY_IDS);
|
||||
mSendTo = extras.getString(PGPHelper.EXTRA_SEND_TO);
|
||||
mSubject = extras.getString(PGPHelper.EXTRA_SUBJECT);
|
||||
long signatureKeyId = extras.getLong(PGPHelper.EXTRA_SIGNATURE_KEY_ID);
|
||||
long encryptionKeyIds[] = extras.getLongArray(PGPHelper.EXTRA_ENCRYPTION_KEY_IDS);
|
||||
if (signatureKeyId != 0) {
|
||||
PGPSecretKeyRing keyRing = Apg.getSecretKeyRing(signatureKeyId);
|
||||
PGPSecretKeyRing keyRing = PGPHelper.getSecretKeyRing(signatureKeyId);
|
||||
PGPSecretKey masterKey = null;
|
||||
if (keyRing != null) {
|
||||
masterKey = Apg.getMasterKey(keyRing);
|
||||
masterKey = PGPHelper.getMasterKey(keyRing);
|
||||
if (masterKey != null) {
|
||||
Vector<PGPSecretKey> signKeys = Apg.getUsableSigningKeys(keyRing);
|
||||
Vector<PGPSecretKey> signKeys = PGPHelper.getUsableSigningKeys(keyRing);
|
||||
if (signKeys.size() > 0) {
|
||||
setSecretKeyId(masterKey.getKeyID());
|
||||
}
|
||||
@ -388,16 +388,16 @@ public class EncryptActivity extends SherlockFragmentActivity {
|
||||
if (encryptionKeyIds != null) {
|
||||
Vector<Long> goodIds = new Vector<Long>();
|
||||
for (int i = 0; i < encryptionKeyIds.length; ++i) {
|
||||
PGPPublicKeyRing keyRing = Apg.getPublicKeyRing(encryptionKeyIds[i]);
|
||||
PGPPublicKeyRing keyRing = PGPHelper.getPublicKeyRing(encryptionKeyIds[i]);
|
||||
PGPPublicKey masterKey = null;
|
||||
if (keyRing == null) {
|
||||
continue;
|
||||
}
|
||||
masterKey = Apg.getMasterKey(keyRing);
|
||||
masterKey = PGPHelper.getMasterKey(keyRing);
|
||||
if (masterKey == null) {
|
||||
continue;
|
||||
}
|
||||
Vector<PGPPublicKey> encryptKeys = Apg.getUsableEncryptKeys(keyRing);
|
||||
Vector<PGPPublicKey> encryptKeys = PGPHelper.getUsableEncryptKeys(keyRing);
|
||||
if (encryptKeys.size() == 0) {
|
||||
continue;
|
||||
}
|
||||
@ -411,9 +411,9 @@ public class EncryptActivity extends SherlockFragmentActivity {
|
||||
}
|
||||
}
|
||||
|
||||
if (Apg.Intent.ENCRYPT.equals(mIntent.getAction())
|
||||
|| Apg.Intent.ENCRYPT_AND_RETURN.equals(mIntent.getAction())
|
||||
|| Apg.Intent.GENERATE_SIGNATURE.equals(mIntent.getAction())) {
|
||||
if (PGPHelper.Intent.ENCRYPT.equals(mIntent.getAction())
|
||||
|| PGPHelper.Intent.ENCRYPT_AND_RETURN.equals(mIntent.getAction())
|
||||
|| PGPHelper.Intent.GENERATE_SIGNATURE.equals(mIntent.getAction())) {
|
||||
if (textData != null) {
|
||||
mMessage.setText(textData);
|
||||
}
|
||||
@ -422,7 +422,7 @@ public class EncryptActivity extends SherlockFragmentActivity {
|
||||
while (mSource.getCurrentView().getId() != R.id.sourceMessage) {
|
||||
mSource.showNext();
|
||||
}
|
||||
} else if (Apg.Intent.ENCRYPT_FILE.equals(mIntent.getAction())) {
|
||||
} else if (PGPHelper.Intent.ENCRYPT_FILE.equals(mIntent.getAction())) {
|
||||
if ("file".equals(mIntent.getScheme())) {
|
||||
mInputFilename = Uri.decode(mIntent.getDataString().replace("file://", ""));
|
||||
mFilename.setText(mInputFilename);
|
||||
@ -651,7 +651,7 @@ public class EncryptActivity extends SherlockFragmentActivity {
|
||||
return;
|
||||
}
|
||||
|
||||
if (getSecretKeyId() != 0 && Apg.getCachedPassPhrase(getSecretKeyId()) == null) {
|
||||
if (getSecretKeyId() != 0 && PGPHelper.getCachedPassPhrase(getSecretKeyId()) == null) {
|
||||
showPassphraseDialog();
|
||||
|
||||
return;
|
||||
@ -659,7 +659,7 @@ public class EncryptActivity extends SherlockFragmentActivity {
|
||||
}
|
||||
|
||||
if (mEncryptTarget == Id.target.file) {
|
||||
askForOutputFilename();
|
||||
showOutputFileDialog();
|
||||
} else {
|
||||
encryptStart();
|
||||
}
|
||||
@ -676,7 +676,7 @@ public class EncryptActivity extends SherlockFragmentActivity {
|
||||
public void handleMessage(Message message) {
|
||||
if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) {
|
||||
if (mEncryptTarget == Id.target.file) {
|
||||
askForOutputFilename();
|
||||
showOutputFileDialog();
|
||||
} else {
|
||||
encryptStart();
|
||||
}
|
||||
@ -692,15 +692,15 @@ public class EncryptActivity extends SherlockFragmentActivity {
|
||||
messenger, mSecretKeyId);
|
||||
|
||||
passphraseDialog.show(getSupportFragmentManager(), "passphraseDialog");
|
||||
} catch (Apg.GeneralException e) {
|
||||
} catch (PGPHelper.GeneralException e) {
|
||||
Log.d(Constants.TAG, "No passphrase for this secret key, encrypt directly!");
|
||||
// send message to handler to start encryption directly
|
||||
returnHandler.sendEmptyMessage(PassphraseDialogFragment.MESSAGE_OKAY);
|
||||
}
|
||||
}
|
||||
|
||||
private void askForOutputFilename() {
|
||||
// Message is received after passphrase is cached
|
||||
private void showOutputFileDialog() {
|
||||
// Message is received after file is selected
|
||||
Handler returnHandler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message message) {
|
||||
@ -721,7 +721,6 @@ public class EncryptActivity extends SherlockFragmentActivity {
|
||||
Id.request.output_filename);
|
||||
|
||||
mFileDialog.show(getSupportFragmentManager(), "fileDialog");
|
||||
|
||||
}
|
||||
|
||||
private void encryptStart() {
|
||||
@ -743,7 +742,6 @@ public class EncryptActivity extends SherlockFragmentActivity {
|
||||
if (passPhrase.length() == 0) {
|
||||
passPhrase = null;
|
||||
}
|
||||
// signatureKeyId = Id.key.symmetric;
|
||||
|
||||
data.putString(ApgService.SYMMETRIC_PASSPHRASE, passPhrase);
|
||||
} else {
|
||||
@ -776,13 +774,13 @@ public class EncryptActivity extends SherlockFragmentActivity {
|
||||
intent.putExtra(ApgService.EXTRA_ACTION, ApgService.ACTION_ENCRYPT_SIGN_BYTES);
|
||||
|
||||
if (mData != null) {
|
||||
data.putByteArray(ApgService.BYTES, mData);
|
||||
data.putByteArray(ApgService.MESSAGE_BYTES, mData);
|
||||
} else {
|
||||
String message = mMessage.getText().toString();
|
||||
if (signOnly && !mReturnResult) {
|
||||
fixBadCharactersForGmail(message);
|
||||
}
|
||||
data.putByteArray(ApgService.BYTES, message.getBytes());
|
||||
data.putByteArray(ApgService.MESSAGE_BYTES, message.getBytes());
|
||||
}
|
||||
}
|
||||
|
||||
@ -919,11 +917,11 @@ public class EncryptActivity extends SherlockFragmentActivity {
|
||||
} else {
|
||||
String uid = getResources().getString(R.string.unknownUserId);
|
||||
String uidExtra = "";
|
||||
PGPSecretKeyRing keyRing = Apg.getSecretKeyRing(getSecretKeyId());
|
||||
PGPSecretKeyRing keyRing = PGPHelper.getSecretKeyRing(getSecretKeyId());
|
||||
if (keyRing != null) {
|
||||
PGPSecretKey key = Apg.getMasterKey(keyRing);
|
||||
PGPSecretKey key = PGPHelper.getMasterKey(keyRing);
|
||||
if (key != null) {
|
||||
String userId = Apg.getMainUserIdSafe(this, key);
|
||||
String userId = PGPHelper.getMainUserIdSafe(this, key);
|
||||
String chunks[] = userId.split(" <", 2);
|
||||
uid = chunks[0];
|
||||
if (chunks.length > 1) {
|
||||
@ -957,7 +955,7 @@ public class EncryptActivity extends SherlockFragmentActivity {
|
||||
initialKeyIds[i] = keyIds.get(i);
|
||||
}
|
||||
}
|
||||
intent.putExtra(Apg.EXTRA_SELECTION, initialKeyIds);
|
||||
intent.putExtra(PGPHelper.EXTRA_SELECTION, initialKeyIds);
|
||||
startActivityForResult(intent, Id.request.public_keys);
|
||||
}
|
||||
|
||||
@ -1000,7 +998,7 @@ public class EncryptActivity extends SherlockFragmentActivity {
|
||||
case Id.request.public_keys: {
|
||||
if (resultCode == RESULT_OK) {
|
||||
Bundle bundle = data.getExtras();
|
||||
mEncryptionKeyIds = bundle.getLongArray(Apg.EXTRA_SELECTION);
|
||||
mEncryptionKeyIds = bundle.getLongArray(PGPHelper.EXTRA_SELECTION);
|
||||
}
|
||||
updateView();
|
||||
break;
|
||||
@ -1009,7 +1007,7 @@ public class EncryptActivity extends SherlockFragmentActivity {
|
||||
case Id.request.secret_keys: {
|
||||
if (resultCode == RESULT_OK) {
|
||||
Bundle bundle = data.getExtras();
|
||||
setSecretKeyId(bundle.getLong(Apg.EXTRA_KEY_ID));
|
||||
setSecretKeyId(bundle.getLong(PGPHelper.EXTRA_KEY_ID));
|
||||
} else {
|
||||
setSecretKeyId(Id.key.none);
|
||||
}
|
||||
|
@ -21,8 +21,8 @@ import java.io.InputStream;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.thialfihar.android.apg.R;
|
||||
import org.thialfihar.android.apg.Apg;
|
||||
import org.thialfihar.android.apg.Id;
|
||||
import org.thialfihar.android.apg.helper.PGPHelper;
|
||||
import org.thialfihar.android.apg.util.Choice;
|
||||
|
||||
import android.content.Intent;
|
||||
@ -83,7 +83,7 @@ public class GeneralActivity extends BaseActivity {
|
||||
|
||||
int contentType = Id.content.unknown;
|
||||
try {
|
||||
contentType = Apg.getStreamContent(this, inStream);
|
||||
contentType = PGPHelper.getStreamContent(this, inStream);
|
||||
inStream.close();
|
||||
} catch (IOException e) {
|
||||
// just means that there's no PGP data in there
|
||||
@ -134,10 +134,10 @@ public class GeneralActivity extends BaseActivity {
|
||||
case Id.choice.action.encrypt: {
|
||||
intent.setClass(this, EncryptActivity.class);
|
||||
if (mDataString != null) {
|
||||
intent.setAction(Apg.Intent.ENCRYPT);
|
||||
intent.putExtra(Apg.EXTRA_TEXT, mDataString);
|
||||
intent.setAction(PGPHelper.Intent.ENCRYPT);
|
||||
intent.putExtra(PGPHelper.EXTRA_TEXT, mDataString);
|
||||
} else if (mDataUri != null) {
|
||||
intent.setAction(Apg.Intent.ENCRYPT_FILE);
|
||||
intent.setAction(PGPHelper.Intent.ENCRYPT_FILE);
|
||||
intent.setDataAndType(mDataUri, mIntent.getType());
|
||||
}
|
||||
|
||||
@ -147,10 +147,10 @@ public class GeneralActivity extends BaseActivity {
|
||||
case Id.choice.action.decrypt: {
|
||||
intent.setClass(this, DecryptActivity.class);
|
||||
if (mDataString != null) {
|
||||
intent.setAction(Apg.Intent.DECRYPT);
|
||||
intent.putExtra(Apg.EXTRA_TEXT, mDataString);
|
||||
intent.setAction(PGPHelper.Intent.DECRYPT);
|
||||
intent.putExtra(PGPHelper.EXTRA_TEXT, mDataString);
|
||||
} else if (mDataUri != null) {
|
||||
intent.setAction(Apg.Intent.DECRYPT_FILE);
|
||||
intent.setAction(PGPHelper.Intent.DECRYPT_FILE);
|
||||
intent.setDataAndType(mDataUri, mIntent.getType());
|
||||
}
|
||||
|
||||
@ -159,9 +159,9 @@ public class GeneralActivity extends BaseActivity {
|
||||
|
||||
case Id.choice.action.import_public: {
|
||||
intent.setClass(this, PublicKeyListActivity.class);
|
||||
intent.setAction(Apg.Intent.IMPORT);
|
||||
intent.setAction(PGPHelper.Intent.IMPORT);
|
||||
if (mDataString != null) {
|
||||
intent.putExtra(Apg.EXTRA_TEXT, mDataString);
|
||||
intent.putExtra(PGPHelper.EXTRA_TEXT, mDataString);
|
||||
} else if (mDataUri != null) {
|
||||
intent.setDataAndType(mDataUri, mIntent.getType());
|
||||
}
|
||||
@ -170,9 +170,9 @@ public class GeneralActivity extends BaseActivity {
|
||||
|
||||
case Id.choice.action.import_secret: {
|
||||
intent.setClass(this, SecretKeyListActivity.class);
|
||||
intent.setAction(Apg.Intent.IMPORT);
|
||||
intent.setAction(PGPHelper.Intent.IMPORT);
|
||||
if (mDataString != null) {
|
||||
intent.putExtra(Apg.EXTRA_TEXT, mDataString);
|
||||
intent.putExtra(PGPHelper.EXTRA_TEXT, mDataString);
|
||||
} else if (mDataUri != null) {
|
||||
intent.setDataAndType(mDataUri, mIntent.getType());
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ package org.thialfihar.android.apg.ui;
|
||||
|
||||
import org.thialfihar.android.apg.Constants;
|
||||
import org.thialfihar.android.apg.R;
|
||||
import org.thialfihar.android.apg.util.Utils;
|
||||
import org.thialfihar.android.apg.helper.OtherHelper;
|
||||
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
@ -52,7 +52,7 @@ public class HelpFragmentAbout extends SherlockFragment {
|
||||
View view = inflater.inflate(R.layout.help_fragment_about, container, false);
|
||||
|
||||
// load html from html file from /res/raw
|
||||
String aboutText = Utils.readContentFromResource(this.getActivity(), R.raw.help_about);
|
||||
String aboutText = OtherHelper.readContentFromResource(this.getActivity(), R.raw.help_about);
|
||||
|
||||
TextView versionText = (TextView) view.findViewById(R.id.help_about_version);
|
||||
versionText.setText(getString(R.string.help_about_version) + " " + getVersion());
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
package org.thialfihar.android.apg.ui;
|
||||
|
||||
import org.thialfihar.android.apg.util.Utils;
|
||||
import org.thialfihar.android.apg.helper.OtherHelper;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
@ -68,7 +68,7 @@ public class HelpFragmentHtml extends SherlockFragment {
|
||||
htmlFile = getArguments().getInt(ARG_HTML_FILE);
|
||||
|
||||
// load html from html file from /res/raw
|
||||
String helpText = Utils.readContentFromResource(this.getActivity(), htmlFile);
|
||||
String helpText = OtherHelper.readContentFromResource(this.getActivity(), htmlFile);
|
||||
|
||||
mActivity = getActivity();
|
||||
|
||||
|
@ -1,4 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Senecaso
|
||||
*
|
||||
* 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
|
||||
@ -19,11 +21,11 @@ import java.io.IOException;
|
||||
|
||||
import org.spongycastle.openpgp.PGPKeyRing;
|
||||
import org.spongycastle.openpgp.PGPPublicKeyRing;
|
||||
import org.thialfihar.android.apg.Apg;
|
||||
import org.thialfihar.android.apg.Constants;
|
||||
import org.thialfihar.android.apg.HkpKeyServer;
|
||||
import org.thialfihar.android.apg.Id;
|
||||
import org.thialfihar.android.apg.KeyServer.QueryException;
|
||||
import org.thialfihar.android.apg.helper.PGPHelper;
|
||||
import org.thialfihar.android.apg.R;
|
||||
|
||||
import android.content.Intent;
|
||||
@ -60,33 +62,33 @@ public class ImportFromQRCodeActivity extends BaseActivity {
|
||||
HkpKeyServer server = new HkpKeyServer(mPreferences.getKeyServers()[0]); // TODO: there should be only 1
|
||||
String encodedKey = server.get(keyId);
|
||||
|
||||
PGPKeyRing keyring = Apg.decodeKeyRing(new ByteArrayInputStream(encodedKey.getBytes()));
|
||||
PGPKeyRing keyring = PGPHelper.decodeKeyRing(new ByteArrayInputStream(encodedKey.getBytes()));
|
||||
if (keyring != null && keyring instanceof PGPPublicKeyRing) {
|
||||
PGPPublicKeyRing publicKeyRing = (PGPPublicKeyRing) keyring;
|
||||
|
||||
// make sure the fingerprints match before we cache this thing
|
||||
String actualFingerprint = Apg.convertToHex(publicKeyRing.getPublicKey().getFingerprint());
|
||||
String actualFingerprint = PGPHelper.convertToHex(publicKeyRing.getPublicKey().getFingerprint());
|
||||
if (expectedFingerprint.equals(actualFingerprint)) {
|
||||
// store the signed key in our local cache
|
||||
int retval = Apg.storeKeyRingInCache(publicKeyRing);
|
||||
int retval = PGPHelper.storeKeyRingInCache(publicKeyRing);
|
||||
if (retval != Id.return_value.ok && retval != Id.return_value.updated) {
|
||||
status.putString(Apg.EXTRA_ERROR, "Failed to store signed key in local cache");
|
||||
status.putString(PGPHelper.EXTRA_ERROR, "Failed to store signed key in local cache");
|
||||
} else {
|
||||
Intent intent = new Intent(ImportFromQRCodeActivity.this, SignKeyActivity.class);
|
||||
intent.putExtra(Apg.EXTRA_KEY_ID, keyId);
|
||||
intent.putExtra(PGPHelper.EXTRA_KEY_ID, keyId);
|
||||
startActivityForResult(intent, Id.request.sign_key);
|
||||
}
|
||||
} else {
|
||||
status.putString(Apg.EXTRA_ERROR, "Scanned fingerprint does NOT match the fingerprint of the received key. You shouldnt trust this key.");
|
||||
status.putString(PGPHelper.EXTRA_ERROR, "Scanned fingerprint does NOT match the fingerprint of the received key. You shouldnt trust this key.");
|
||||
}
|
||||
}
|
||||
} catch (QueryException e) {
|
||||
Log.e(TAG, "Failed to query KeyServer", e);
|
||||
status.putString(Apg.EXTRA_ERROR, "Failed to query KeyServer");
|
||||
status.putString(PGPHelper.EXTRA_ERROR, "Failed to query KeyServer");
|
||||
status.putInt(Constants.extras.STATUS, Id.message.done);
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Failed to query KeyServer", e);
|
||||
status.putString(Apg.EXTRA_ERROR, "Failed to query KeyServer");
|
||||
status.putString(PGPHelper.EXTRA_ERROR, "Failed to query KeyServer");
|
||||
status.putInt(Constants.extras.STATUS, Id.message.done);
|
||||
}
|
||||
}
|
||||
@ -140,7 +142,7 @@ public class ImportFromQRCodeActivity extends BaseActivity {
|
||||
super.doneCallback(msg);
|
||||
|
||||
Bundle data = msg.getData();
|
||||
String error = data.getString(Apg.EXTRA_ERROR);
|
||||
String error = data.getString(PGPHelper.EXTRA_ERROR);
|
||||
if (error != null) {
|
||||
Toast.makeText(this, getString(R.string.errorMessage, error), Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
|
@ -19,14 +19,14 @@ package org.thialfihar.android.apg.ui;
|
||||
import org.spongycastle.openpgp.PGPException;
|
||||
import org.spongycastle.openpgp.PGPPublicKeyRing;
|
||||
import org.spongycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.thialfihar.android.apg.Apg;
|
||||
import org.thialfihar.android.apg.Constants;
|
||||
import org.thialfihar.android.apg.FileDialog;
|
||||
import org.thialfihar.android.apg.Id;
|
||||
import org.thialfihar.android.apg.InputData;
|
||||
import org.thialfihar.android.apg.helper.PGPHelper;
|
||||
import org.thialfihar.android.apg.provider.KeyRings;
|
||||
import org.thialfihar.android.apg.provider.Keys;
|
||||
import org.thialfihar.android.apg.provider.UserIds;
|
||||
import org.thialfihar.android.apg.ui.dialog.FileDialogFragment;
|
||||
import org.thialfihar.android.apg.util.InputData;
|
||||
import org.thialfihar.android.apg.R;
|
||||
|
||||
import com.actionbarsherlock.view.MenuItem;
|
||||
@ -42,7 +42,10 @@ import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteQueryBuilder;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.os.Messenger;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
@ -83,6 +86,8 @@ public class KeyListActivity extends BaseActivity {
|
||||
|
||||
protected int mKeyType = Id.type.public_key;
|
||||
|
||||
FileDialogFragment mFileDialog;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -134,11 +139,11 @@ public class KeyListActivity extends BaseActivity {
|
||||
mListAdapter = new KeyListAdapter(this, searchString);
|
||||
mList.setAdapter(mListAdapter);
|
||||
|
||||
if (Apg.Intent.IMPORT.equals(intent.getAction())) {
|
||||
if (PGPHelper.Intent.IMPORT.equals(intent.getAction())) {
|
||||
if ("file".equals(intent.getScheme()) && intent.getDataString() != null) {
|
||||
mImportFilename = Uri.decode(intent.getDataString().replace("file://", ""));
|
||||
} else {
|
||||
mImportData = intent.getStringExtra(Apg.EXTRA_TEXT);
|
||||
mImportData = intent.getStringExtra(PGPHelper.EXTRA_TEXT);
|
||||
}
|
||||
importKeys();
|
||||
}
|
||||
@ -148,12 +153,14 @@ public class KeyListActivity extends BaseActivity {
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case Id.menu.option.import_keys: {
|
||||
showDialog(Id.dialog.import_keys);
|
||||
// showDialog(Id.dialog.import_keys);
|
||||
showImportKeysDialog();
|
||||
return true;
|
||||
}
|
||||
|
||||
case Id.menu.option.export_keys: {
|
||||
showDialog(Id.dialog.export_keys);
|
||||
// showDialog(Id.dialog.export_keys);
|
||||
showExportKeysDialog(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -163,6 +170,59 @@ public class KeyListActivity extends BaseActivity {
|
||||
}
|
||||
}
|
||||
|
||||
private void showImportKeysDialog() {
|
||||
// Message is received after file is selected
|
||||
Handler returnHandler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message message) {
|
||||
if (message.what == FileDialogFragment.MESSAGE_OKAY) {
|
||||
Bundle data = message.getData();
|
||||
mImportFilename = data.getString(FileDialogFragment.MESSAGE_DATA_FILENAME);
|
||||
|
||||
mDeleteAfterImport = data.getBoolean(FileDialogFragment.MESSAGE_DATA_CHECKED);
|
||||
importKeys();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Create a new Messenger for the communication back
|
||||
Messenger messenger = new Messenger(returnHandler);
|
||||
|
||||
mFileDialog = FileDialogFragment.newInstance(messenger,
|
||||
getString(R.string.title_importKeys), getString(R.string.specifyFileToImportFrom),
|
||||
mImportFilename, null, Id.request.filename);
|
||||
|
||||
mFileDialog.show(getSupportFragmentManager(), "fileDialog");
|
||||
}
|
||||
|
||||
private void showExportKeysDialog(boolean singleKeyExport) {
|
||||
String title = (singleKeyExport ? getString(R.string.title_exportKey)
|
||||
: getString(R.string.title_exportKeys));
|
||||
String message = getString(mKeyType == Id.type.public_key ? R.string.specifyFileToExportTo
|
||||
: R.string.specifyFileToExportSecretKeysTo);
|
||||
|
||||
// Message is received after file is selected
|
||||
Handler returnHandler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message message) {
|
||||
if (message.what == FileDialogFragment.MESSAGE_OKAY) {
|
||||
Bundle data = message.getData();
|
||||
mExportFilename = data.getString(FileDialogFragment.MESSAGE_DATA_FILENAME);
|
||||
|
||||
exportKeys();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Create a new Messenger for the communication back
|
||||
Messenger messenger = new Messenger(returnHandler);
|
||||
|
||||
mFileDialog = FileDialogFragment.newInstance(messenger, title, message, mExportFilename,
|
||||
null, Id.request.filename);
|
||||
|
||||
mFileDialog.show(getSupportFragmentManager(), "fileDialog");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onContextItemSelected(android.view.MenuItem menuItem) {
|
||||
ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) menuItem.getMenuInfo();
|
||||
@ -176,7 +236,7 @@ public class KeyListActivity extends BaseActivity {
|
||||
switch (menuItem.getItemId()) {
|
||||
case Id.menu.export: {
|
||||
mSelectedItem = groupPosition;
|
||||
showDialog(Id.dialog.export_key);
|
||||
showExportKeysDialog(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -194,7 +254,6 @@ public class KeyListActivity extends BaseActivity {
|
||||
|
||||
@Override
|
||||
protected Dialog onCreateDialog(int id) {
|
||||
boolean singleKeyExport = false;
|
||||
|
||||
switch (id) {
|
||||
case Id.dialog.delete_key: {
|
||||
@ -202,14 +261,14 @@ public class KeyListActivity extends BaseActivity {
|
||||
mSelectedItem = -1;
|
||||
// TODO: better way to do this?
|
||||
String userId = "<unknown>";
|
||||
Object keyRing = Apg.getKeyRing(keyRingId);
|
||||
Object keyRing = PGPHelper.getKeyRing(keyRingId);
|
||||
if (keyRing != null) {
|
||||
if (keyRing instanceof PGPPublicKeyRing) {
|
||||
userId = Apg.getMainUserIdSafe(this,
|
||||
Apg.getMasterKey((PGPPublicKeyRing) keyRing));
|
||||
userId = PGPHelper.getMainUserIdSafe(this,
|
||||
PGPHelper.getMasterKey((PGPPublicKeyRing) keyRing));
|
||||
} else {
|
||||
userId = Apg.getMainUserIdSafe(this,
|
||||
Apg.getMasterKey((PGPSecretKeyRing) keyRing));
|
||||
userId = PGPHelper.getMainUserIdSafe(this,
|
||||
PGPHelper.getMasterKey((PGPSecretKeyRing) keyRing));
|
||||
}
|
||||
}
|
||||
|
||||
@ -234,54 +293,6 @@ public class KeyListActivity extends BaseActivity {
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
case Id.dialog.import_keys: {
|
||||
return FileDialog.build(this, getString(R.string.title_importKeys),
|
||||
getString(R.string.specifyFileToImportFrom), mImportFilename,
|
||||
new FileDialog.OnClickListener() {
|
||||
public void onOkClick(String filename, boolean checked) {
|
||||
removeDialog(Id.dialog.import_keys);
|
||||
mDeleteAfterImport = checked;
|
||||
mImportFilename = filename;
|
||||
importKeys();
|
||||
}
|
||||
|
||||
public void onCancelClick() {
|
||||
removeDialog(Id.dialog.import_keys);
|
||||
}
|
||||
}, getString(R.string.filemanager_titleOpen),
|
||||
getString(R.string.filemanager_btnOpen),
|
||||
getString(R.string.label_deleteAfterImport), Id.request.filename);
|
||||
}
|
||||
|
||||
case Id.dialog.export_key: {
|
||||
singleKeyExport = true;
|
||||
// break intentionally omitted, to use the Id.dialog.export_keys dialog
|
||||
}
|
||||
|
||||
case Id.dialog.export_keys: {
|
||||
String title = (singleKeyExport ? getString(R.string.title_exportKey)
|
||||
: getString(R.string.title_exportKeys));
|
||||
|
||||
final int thisDialogId = (singleKeyExport ? Id.dialog.export_key
|
||||
: Id.dialog.export_keys);
|
||||
|
||||
return FileDialog.build(this, title,
|
||||
getString(mKeyType == Id.type.public_key ? R.string.specifyFileToExportTo
|
||||
: R.string.specifyFileToExportSecretKeysTo), mExportFilename,
|
||||
new FileDialog.OnClickListener() {
|
||||
public void onOkClick(String filename, boolean checked) {
|
||||
removeDialog(thisDialogId);
|
||||
mExportFilename = filename;
|
||||
exportKeys();
|
||||
}
|
||||
|
||||
public void onCancelClick() {
|
||||
removeDialog(thisDialogId);
|
||||
}
|
||||
}, getString(R.string.filemanager_titleSave),
|
||||
getString(R.string.filemanager_btnSave), null, Id.request.filename);
|
||||
}
|
||||
|
||||
default: {
|
||||
return super.onCreateDialog(id);
|
||||
}
|
||||
@ -325,12 +336,12 @@ public class KeyListActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
if (mTask == Id.task.import_keys) {
|
||||
data = Apg.importKeyRings(this, mKeyType, new InputData(importInputStream, size),
|
||||
this);
|
||||
data = PGPHelper.importKeyRings(this, mKeyType, new InputData(importInputStream,
|
||||
size), this);
|
||||
} else {
|
||||
Vector<Integer> keyRingIds = new Vector<Integer>();
|
||||
if (mSelectedItem == -1) {
|
||||
keyRingIds = Apg
|
||||
keyRingIds = PGPHelper
|
||||
.getKeyRingIds(mKeyType == Id.type.public_key ? Id.database.type_public
|
||||
: Id.database.type_secret);
|
||||
} else {
|
||||
@ -338,7 +349,7 @@ public class KeyListActivity extends BaseActivity {
|
||||
keyRingIds.add(keyRingId);
|
||||
mSelectedItem = -1;
|
||||
}
|
||||
data = Apg.exportKeyRings(this, keyRingIds, exportOutputStream, this);
|
||||
data = PGPHelper.exportKeyRings(this, keyRingIds, exportOutputStream, this);
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
error = getString(R.string.error_fileNotFound);
|
||||
@ -346,7 +357,7 @@ public class KeyListActivity extends BaseActivity {
|
||||
error = "" + e;
|
||||
} catch (PGPException e) {
|
||||
error = "" + e;
|
||||
} catch (Apg.GeneralException e) {
|
||||
} catch (PGPHelper.GeneralException e) {
|
||||
error = "" + e;
|
||||
}
|
||||
|
||||
@ -359,7 +370,7 @@ public class KeyListActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
if (error != null) {
|
||||
data.putString(Apg.EXTRA_ERROR, error);
|
||||
data.putString(PGPHelper.EXTRA_ERROR, error);
|
||||
}
|
||||
|
||||
msg.setData(data);
|
||||
@ -367,7 +378,7 @@ public class KeyListActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
protected void deleteKey(int keyRingId) {
|
||||
Apg.deleteKey(keyRingId);
|
||||
PGPHelper.deleteKey(keyRingId);
|
||||
refreshList();
|
||||
}
|
||||
|
||||
@ -387,7 +398,7 @@ public class KeyListActivity extends BaseActivity {
|
||||
case Id.message.import_done: {
|
||||
removeDialog(Id.dialog.importing);
|
||||
|
||||
String error = data.getString(Apg.EXTRA_ERROR);
|
||||
String error = data.getString(PGPHelper.EXTRA_ERROR);
|
||||
if (error != null) {
|
||||
Toast.makeText(KeyListActivity.this, getString(R.string.errorMessage, error),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
@ -434,7 +445,7 @@ public class KeyListActivity extends BaseActivity {
|
||||
case Id.message.export_done: {
|
||||
removeDialog(Id.dialog.exporting);
|
||||
|
||||
String error = data.getString(Apg.EXTRA_ERROR);
|
||||
String error = data.getString(PGPHelper.EXTRA_ERROR);
|
||||
if (error != null) {
|
||||
Toast.makeText(KeyListActivity.this, getString(R.string.errorMessage, error),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
@ -508,7 +519,7 @@ public class KeyListActivity extends BaseActivity {
|
||||
mSearchString = searchString;
|
||||
|
||||
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
mDatabase = Apg.getDatabase().db();
|
||||
mDatabase = PGPHelper.getDatabase().db();
|
||||
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
|
||||
qb.setTables(KeyRings.TABLE_NAME + " INNER JOIN " + Keys.TABLE_NAME + " ON " + "("
|
||||
+ KeyRings.TABLE_NAME + "." + KeyRings._ID + " = " + Keys.TABLE_NAME + "."
|
||||
@ -600,7 +611,8 @@ public class KeyListActivity extends BaseActivity {
|
||||
c.close();
|
||||
|
||||
if (masterKeyId != -1) {
|
||||
children.insertElementAt(new KeyChild(Apg.getFingerPrint(fingerPrintId), true), 0);
|
||||
children.insertElementAt(
|
||||
new KeyChild(PGPHelper.getFingerPrint(fingerPrintId), true), 0);
|
||||
c = mDatabase.query(UserIds.TABLE_NAME, new String[] { UserIds.USER_ID, // 0
|
||||
}, UserIds.KEY_ID + " = ? AND " + UserIds.RANK + " > 0", new String[] { ""
|
||||
+ masterKeyId }, null, null, UserIds.RANK + " ASC");
|
||||
@ -703,10 +715,10 @@ public class KeyListActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
TextView keyId = (TextView) view.findViewById(R.id.keyId);
|
||||
String keyIdStr = Apg.getSmallFingerPrint(child.keyId);
|
||||
String keyIdStr = PGPHelper.getSmallFingerPrint(child.keyId);
|
||||
keyId.setText(keyIdStr);
|
||||
TextView keyDetails = (TextView) view.findViewById(R.id.keyDetails);
|
||||
String algorithmStr = Apg.getAlgorithmInfo(child.algorithm, child.keySize);
|
||||
String algorithmStr = PGPHelper.getAlgorithmInfo(child.algorithm, child.keySize);
|
||||
keyDetails.setText("(" + algorithmStr + ")");
|
||||
|
||||
ImageView encryptIcon = (ImageView) view.findViewById(R.id.ic_encryptKey);
|
||||
@ -745,16 +757,13 @@ public class KeyListActivity extends BaseActivity {
|
||||
switch (requestCode) {
|
||||
case Id.request.filename: {
|
||||
if (resultCode == RESULT_OK && data != null) {
|
||||
String filename = data.getDataString();
|
||||
if (filename != null) {
|
||||
// Get rid of URI prefix:
|
||||
if (filename.startsWith("file://")) {
|
||||
filename = filename.substring(7);
|
||||
}
|
||||
// replace %20 and so on
|
||||
filename = Uri.decode(filename);
|
||||
try {
|
||||
String path = data.getData().getPath();
|
||||
Log.d(Constants.TAG, "path=" + path);
|
||||
|
||||
FileDialog.setFilename(filename);
|
||||
mFileDialog.setFilename(path);
|
||||
} catch (NullPointerException e) {
|
||||
Log.e(Constants.TAG, "Nullpointer while retrieving path!");
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
@ -1,4 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Senecaso
|
||||
*
|
||||
* 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
|
||||
@ -16,11 +18,11 @@ package org.thialfihar.android.apg.ui;
|
||||
|
||||
import org.spongycastle.openpgp.PGPKeyRing;
|
||||
import org.spongycastle.openpgp.PGPPublicKeyRing;
|
||||
import org.thialfihar.android.apg.Apg;
|
||||
import org.thialfihar.android.apg.Constants;
|
||||
import org.thialfihar.android.apg.HkpKeyServer;
|
||||
import org.thialfihar.android.apg.Id;
|
||||
import org.thialfihar.android.apg.R;
|
||||
import org.thialfihar.android.apg.helper.PGPHelper;
|
||||
|
||||
import com.actionbarsherlock.view.MenuItem;
|
||||
|
||||
@ -49,7 +51,10 @@ public class KeyServerExportActivity extends BaseActivity {
|
||||
switch (item.getItemId()) {
|
||||
|
||||
case android.R.id.home:
|
||||
startActivity(new Intent(this, PublicKeyListActivity.class));
|
||||
// app icon in Action Bar clicked; go home
|
||||
Intent intent = new Intent(this, PublicKeyListActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
|
||||
default:
|
||||
@ -94,11 +99,11 @@ public class KeyServerExportActivity extends BaseActivity {
|
||||
|
||||
HkpKeyServer server = new HkpKeyServer((String) keyServer.getSelectedItem());
|
||||
|
||||
int keyRingId = getIntent().getIntExtra(Apg.EXTRA_KEY_ID, -1);
|
||||
int keyRingId = getIntent().getIntExtra(PGPHelper.EXTRA_KEY_ID, -1);
|
||||
|
||||
PGPKeyRing keyring = Apg.getKeyRing(keyRingId);
|
||||
PGPKeyRing keyring = PGPHelper.getKeyRing(keyRingId);
|
||||
if (keyring != null && keyring instanceof PGPPublicKeyRing) {
|
||||
boolean uploaded = Apg.uploadKeyRingToServer(server, (PGPPublicKeyRing) keyring);
|
||||
boolean uploaded = PGPHelper.uploadKeyRingToServer(server, (PGPPublicKeyRing) keyring);
|
||||
if (!uploaded) {
|
||||
error = "Unable to export key to selected server";
|
||||
}
|
||||
@ -107,7 +112,7 @@ public class KeyServerExportActivity extends BaseActivity {
|
||||
data.putInt(Constants.extras.STATUS, Id.message.export_done);
|
||||
|
||||
if (error != null) {
|
||||
data.putString(Apg.EXTRA_ERROR, error);
|
||||
data.putString(PGPHelper.EXTRA_ERROR, error);
|
||||
}
|
||||
|
||||
msg.setData(data);
|
||||
@ -119,7 +124,7 @@ public class KeyServerExportActivity extends BaseActivity {
|
||||
super.doneCallback(msg);
|
||||
|
||||
Bundle data = msg.getData();
|
||||
String error = data.getString(Apg.EXTRA_ERROR);
|
||||
String error = data.getString(PGPHelper.EXTRA_ERROR);
|
||||
if (error != null) {
|
||||
Toast.makeText(this, getString(R.string.errorMessage, error), Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
|
@ -18,7 +18,6 @@ import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.thialfihar.android.apg.R;
|
||||
import org.thialfihar.android.apg.Apg;
|
||||
import org.thialfihar.android.apg.Constants;
|
||||
import org.thialfihar.android.apg.HkpKeyServer;
|
||||
import org.thialfihar.android.apg.Id;
|
||||
@ -26,6 +25,7 @@ import org.thialfihar.android.apg.KeyServer.InsufficientQuery;
|
||||
import org.thialfihar.android.apg.KeyServer.KeyInfo;
|
||||
import org.thialfihar.android.apg.KeyServer.QueryException;
|
||||
import org.thialfihar.android.apg.KeyServer.TooManyResponses;
|
||||
import org.thialfihar.android.apg.helper.PGPHelper;
|
||||
|
||||
import com.actionbarsherlock.view.MenuItem;
|
||||
|
||||
@ -71,7 +71,10 @@ public class KeyServerQueryActivity extends BaseActivity {
|
||||
switch (item.getItemId()) {
|
||||
|
||||
case android.R.id.home:
|
||||
startActivity(new Intent(this, PublicKeyListActivity.class));
|
||||
// app icon in Action Bar clicked; go home
|
||||
Intent intent = new Intent(this, PublicKeyListActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
|
||||
default:
|
||||
@ -118,11 +121,11 @@ public class KeyServerQueryActivity extends BaseActivity {
|
||||
});
|
||||
|
||||
Intent intent = getIntent();
|
||||
if (Apg.Intent.LOOK_UP_KEY_ID.equals(intent.getAction())
|
||||
|| Apg.Intent.LOOK_UP_KEY_ID_AND_RETURN.equals(intent.getAction())) {
|
||||
long keyId = intent.getLongExtra(Apg.EXTRA_KEY_ID, 0);
|
||||
if (PGPHelper.Intent.LOOK_UP_KEY_ID.equals(intent.getAction())
|
||||
|| PGPHelper.Intent.LOOK_UP_KEY_ID_AND_RETURN.equals(intent.getAction())) {
|
||||
long keyId = intent.getLongExtra(PGPHelper.EXTRA_KEY_ID, 0);
|
||||
if (keyId != 0) {
|
||||
String query = "0x" + Apg.keyToHex(keyId);
|
||||
String query = "0x" + PGPHelper.keyToHex(keyId);
|
||||
mQuery.setText(query);
|
||||
search(query);
|
||||
}
|
||||
@ -176,7 +179,7 @@ public class KeyServerQueryActivity extends BaseActivity {
|
||||
data.putInt(Constants.extras.STATUS, Id.message.done);
|
||||
|
||||
if (error != null) {
|
||||
data.putString(Apg.EXTRA_ERROR, error);
|
||||
data.putString(PGPHelper.EXTRA_ERROR, error);
|
||||
}
|
||||
|
||||
msg.setData(data);
|
||||
@ -190,7 +193,7 @@ public class KeyServerQueryActivity extends BaseActivity {
|
||||
removeDialog(Id.dialog.querying);
|
||||
|
||||
Bundle data = msg.getData();
|
||||
String error = data.getString(Apg.EXTRA_ERROR);
|
||||
String error = data.getString(PGPHelper.EXTRA_ERROR);
|
||||
if (error != null) {
|
||||
Toast.makeText(this, getString(R.string.errorMessage, error), Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
@ -205,10 +208,10 @@ public class KeyServerQueryActivity extends BaseActivity {
|
||||
}
|
||||
} else if (mQueryType == Id.keyserver.get) {
|
||||
Intent orgIntent = getIntent();
|
||||
if (Apg.Intent.LOOK_UP_KEY_ID_AND_RETURN.equals(orgIntent.getAction())) {
|
||||
if (PGPHelper.Intent.LOOK_UP_KEY_ID_AND_RETURN.equals(orgIntent.getAction())) {
|
||||
if (mKeyData != null) {
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra(Apg.EXTRA_TEXT, mKeyData);
|
||||
intent.putExtra(PGPHelper.EXTRA_TEXT, mKeyData);
|
||||
setResult(RESULT_OK, intent);
|
||||
} else {
|
||||
setResult(RESULT_CANCELED);
|
||||
@ -217,8 +220,8 @@ public class KeyServerQueryActivity extends BaseActivity {
|
||||
} else {
|
||||
if (mKeyData != null) {
|
||||
Intent intent = new Intent(this, PublicKeyListActivity.class);
|
||||
intent.setAction(Apg.Intent.IMPORT);
|
||||
intent.putExtra(Apg.EXTRA_TEXT, mKeyData);
|
||||
intent.setAction(PGPHelper.Intent.IMPORT);
|
||||
intent.putExtra(PGPHelper.EXTRA_TEXT, mKeyData);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
@ -284,7 +287,7 @@ public class KeyServerQueryActivity extends BaseActivity {
|
||||
mainUserId.setText(userId);
|
||||
}
|
||||
|
||||
keyId.setText(Apg.getSmallFingerPrint(keyInfo.keyId));
|
||||
keyId.setText(PGPHelper.getSmallFingerPrint(keyInfo.keyId));
|
||||
|
||||
if (mainUserIdRest.getText().length() == 0) {
|
||||
mainUserIdRest.setVisibility(View.GONE);
|
||||
|
@ -20,8 +20,8 @@ import java.util.Vector;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import org.thialfihar.android.apg.R;
|
||||
import org.thialfihar.android.apg.Apg;
|
||||
import org.thialfihar.android.apg.Preferences;
|
||||
import org.thialfihar.android.apg.helper.PGPHelper;
|
||||
|
||||
import android.app.ListActivity;
|
||||
import android.content.Context;
|
||||
@ -121,11 +121,11 @@ public class MailListActivity extends ListActivity {
|
||||
String data = messageCursor.getString(bodyIndex);
|
||||
data = Html.fromHtml(data).toString();
|
||||
boolean signedOnly = false;
|
||||
Matcher matcher = Apg.PGP_MESSAGE.matcher(data);
|
||||
Matcher matcher = PGPHelper.PGP_MESSAGE.matcher(data);
|
||||
if (matcher.matches()) {
|
||||
data = matcher.group(1);
|
||||
} else {
|
||||
matcher = Apg.PGP_SIGNED_MESSAGE.matcher(data);
|
||||
matcher = PGPHelper.PGP_SIGNED_MESSAGE.matcher(data);
|
||||
if (matcher.matches()) {
|
||||
data = matcher.group(1);
|
||||
signedOnly = true;
|
||||
@ -149,11 +149,11 @@ public class MailListActivity extends ListActivity {
|
||||
getListView().setOnItemClickListener(new OnItemClickListener() {
|
||||
public void onItemClick(AdapterView<?> arg0, View v, int position, long id) {
|
||||
Intent intent = new Intent(MailListActivity.this, DecryptActivity.class);
|
||||
intent.setAction(Apg.Intent.DECRYPT);
|
||||
intent.setAction(PGPHelper.Intent.DECRYPT);
|
||||
Message message = (Message) ((MailboxAdapter) getListAdapter()).getItem(position);
|
||||
intent.putExtra(Apg.EXTRA_TEXT, message.data);
|
||||
intent.putExtra(Apg.EXTRA_SUBJECT, message.subject);
|
||||
intent.putExtra(Apg.EXTRA_REPLY_TO, message.replyTo);
|
||||
intent.putExtra(PGPHelper.EXTRA_TEXT, message.data);
|
||||
intent.putExtra(PGPHelper.EXTRA_SUBJECT, message.subject);
|
||||
intent.putExtra(PGPHelper.EXTRA_REPLY_TO, message.replyTo);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
@ -20,9 +20,9 @@ package org.thialfihar.android.apg.ui;
|
||||
import java.security.Security;
|
||||
|
||||
import org.spongycastle.jce.provider.BouncyCastleProvider;
|
||||
import org.thialfihar.android.apg.Apg;
|
||||
import org.thialfihar.android.apg.Id;
|
||||
import org.thialfihar.android.apg.R;
|
||||
import org.thialfihar.android.apg.helper.PGPHelper;
|
||||
|
||||
import com.actionbarsherlock.app.ActionBar;
|
||||
import com.actionbarsherlock.app.SherlockActivity;
|
||||
@ -48,19 +48,19 @@ public class MainActivity extends SherlockActivity {
|
||||
|
||||
public void encryptOnClick(View view) {
|
||||
Intent intent = new Intent(MainActivity.this, EncryptActivity.class);
|
||||
intent.setAction(Apg.Intent.ENCRYPT);
|
||||
intent.setAction(PGPHelper.Intent.ENCRYPT);
|
||||
startActivityForResult(intent, 0); // used instead of startActivity to get callingPackage
|
||||
}
|
||||
|
||||
public void decryptOnClick(View view) {
|
||||
Intent intent = new Intent(MainActivity.this, DecryptActivity.class);
|
||||
intent.setAction(Apg.Intent.DECRYPT);
|
||||
intent.setAction(PGPHelper.Intent.DECRYPT);
|
||||
startActivityForResult(intent, 0); // used instead of startActivity to get callingPackage
|
||||
}
|
||||
|
||||
public void scanQrcodeOnClick(View view) {
|
||||
Intent intent = new Intent(this, ImportFromQRCodeActivity.class);
|
||||
intent.setAction(Apg.Intent.IMPORT_FROM_QR_CODE);
|
||||
intent.setAction(PGPHelper.Intent.IMPORT_FROM_QR_CODE);
|
||||
startActivityForResult(intent, Id.request.import_from_qr_code);
|
||||
}
|
||||
|
||||
|
@ -18,10 +18,10 @@ package org.thialfihar.android.apg.ui;
|
||||
|
||||
import org.spongycastle.bcpg.HashAlgorithmTags;
|
||||
import org.spongycastle.openpgp.PGPEncryptedData;
|
||||
import org.thialfihar.android.apg.Apg;
|
||||
import org.thialfihar.android.apg.Constants;
|
||||
import org.thialfihar.android.apg.Id;
|
||||
import org.thialfihar.android.apg.Preferences;
|
||||
import org.thialfihar.android.apg.helper.PGPHelper;
|
||||
import org.thialfihar.android.apg.passphrase.PassphraseCacheService;
|
||||
import org.thialfihar.android.apg.ui.widget.IntegerListPreference;
|
||||
import org.thialfihar.android.apg.R;
|
||||
@ -36,7 +36,6 @@ import android.preference.CheckBoxPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceScreen;
|
||||
|
||||
|
||||
public class PreferencesActivity extends SherlockPreferenceActivity {
|
||||
private IntegerListPreference mPassPhraseCacheTtl = null;
|
||||
private IntegerListPreference mEncryptionAlgorithm = null;
|
||||
@ -56,6 +55,7 @@ public class PreferencesActivity extends SherlockPreferenceActivity {
|
||||
final ActionBar actionBar = getSupportActionBar();
|
||||
actionBar.setDisplayShowTitleEnabled(true);
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
actionBar.setHomeButtonEnabled(true);
|
||||
|
||||
addPreferencesFromResource(R.xml.apg_preferences);
|
||||
|
||||
@ -194,8 +194,8 @@ public class PreferencesActivity extends SherlockPreferenceActivity {
|
||||
.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
Intent intent = new Intent(PreferencesActivity.this,
|
||||
KeyServerPreferenceActivity.class);
|
||||
intent.putExtra(Apg.EXTRA_KEY_SERVERS, mPreferences.getKeyServers());
|
||||
PreferencesKeyServerActivity.class);
|
||||
intent.putExtra(PGPHelper.EXTRA_KEY_SERVERS, mPreferences.getKeyServers());
|
||||
startActivityForResult(intent, Id.request.key_server_preference);
|
||||
return false;
|
||||
}
|
||||
@ -209,7 +209,7 @@ public class PreferencesActivity extends SherlockPreferenceActivity {
|
||||
if (resultCode == RESULT_CANCELED || data == null) {
|
||||
return;
|
||||
}
|
||||
String servers[] = data.getStringArrayExtra(Apg.EXTRA_KEY_SERVERS);
|
||||
String servers[] = data.getStringArrayExtra(PGPHelper.EXTRA_KEY_SERVERS);
|
||||
mPreferences.setKeyServers(servers);
|
||||
mKeyServerPreference.setSummary(getResources().getString(R.string.nKeyServers,
|
||||
servers.length));
|
||||
@ -228,7 +228,10 @@ public class PreferencesActivity extends SherlockPreferenceActivity {
|
||||
switch (item.getItemId()) {
|
||||
|
||||
case android.R.id.home:
|
||||
startActivity(new Intent(this, MainActivity.class));
|
||||
// app icon in Action Bar clicked; go home
|
||||
Intent intent = new Intent(this, MainActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
|
||||
default:
|
||||
|
@ -18,13 +18,17 @@ package org.thialfihar.android.apg.ui;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import org.thialfihar.android.apg.Id;
|
||||
import org.thialfihar.android.apg.R;
|
||||
import org.thialfihar.android.apg.Apg;
|
||||
import org.thialfihar.android.apg.helper.PGPHelper;
|
||||
import org.thialfihar.android.apg.ui.widget.Editor;
|
||||
import org.thialfihar.android.apg.ui.widget.KeyServerEditor;
|
||||
import org.thialfihar.android.apg.ui.widget.Editor.EditorListener;
|
||||
|
||||
import com.actionbarsherlock.app.ActionBar;
|
||||
import com.actionbarsherlock.app.SherlockActivity;
|
||||
import com.actionbarsherlock.view.Menu;
|
||||
import com.actionbarsherlock.view.MenuItem;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@ -33,10 +37,9 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class KeyServerPreferenceActivity extends BaseActivity implements OnClickListener,
|
||||
public class PreferencesKeyServerActivity extends SherlockActivity implements OnClickListener,
|
||||
EditorListener {
|
||||
private LayoutInflater mInflater;
|
||||
private ViewGroup mEditors;
|
||||
@ -44,11 +47,61 @@ public class KeyServerPreferenceActivity extends BaseActivity implements OnClick
|
||||
private TextView mTitle;
|
||||
private TextView mSummary;
|
||||
|
||||
@Override
|
||||
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, PreferencesActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
startActivity(intent);
|
||||
|
||||
return true;
|
||||
|
||||
case Id.menu.option.okay:
|
||||
okClicked();
|
||||
|
||||
return true;
|
||||
|
||||
case Id.menu.option.cancel:
|
||||
cancelClicked();
|
||||
|
||||
return true;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* ActionBar menu is created based on class variables to change it at runtime
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
|
||||
menu.add(1, Id.menu.option.cancel, 0, android.R.string.cancel).setShowAsAction(
|
||||
MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||
|
||||
menu.add(1, Id.menu.option.okay, 1, android.R.string.ok).setShowAsAction(
|
||||
MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.key_server_preference);
|
||||
|
||||
final ActionBar actionBar = getSupportActionBar();
|
||||
actionBar.setDisplayShowTitleEnabled(true);
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
actionBar.setHomeButtonEnabled(true);
|
||||
|
||||
mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
|
||||
mTitle = (TextView) findViewById(R.id.title);
|
||||
@ -61,7 +114,7 @@ public class KeyServerPreferenceActivity extends BaseActivity implements OnClick
|
||||
mAdd.setOnClickListener(this);
|
||||
|
||||
Intent intent = getIntent();
|
||||
String servers[] = intent.getStringArrayExtra(Apg.EXTRA_KEY_SERVERS);
|
||||
String servers[] = intent.getStringArrayExtra(PGPHelper.EXTRA_KEY_SERVERS);
|
||||
if (servers != null) {
|
||||
for (int i = 0; i < servers.length; ++i) {
|
||||
KeyServerEditor view = (KeyServerEditor) mInflater.inflate(
|
||||
@ -71,20 +124,6 @@ public class KeyServerPreferenceActivity extends BaseActivity implements OnClick
|
||||
mEditors.addView(view);
|
||||
}
|
||||
}
|
||||
|
||||
Button okButton = (Button) findViewById(R.id.btn_ok);
|
||||
okButton.setOnClickListener(new OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
okClicked();
|
||||
}
|
||||
});
|
||||
|
||||
Button cancelButton = (Button) findViewById(R.id.btn_cancel);
|
||||
cancelButton.setOnClickListener(new OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
cancelClicked();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void onDeleted(Editor editor) {
|
||||
@ -114,15 +153,8 @@ public class KeyServerPreferenceActivity extends BaseActivity implements OnClick
|
||||
}
|
||||
}
|
||||
String[] dummy = new String[0];
|
||||
data.putExtra(Apg.EXTRA_KEY_SERVERS, servers.toArray(dummy));
|
||||
data.putExtra(PGPHelper.EXTRA_KEY_SERVERS, servers.toArray(dummy));
|
||||
setResult(RESULT_OK, data);
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// override this, so no option menu is added (as would be in BaseActivity), since
|
||||
// we're still in preferences
|
||||
return true;
|
||||
}
|
||||
}
|
@ -17,10 +17,10 @@
|
||||
package org.thialfihar.android.apg.ui;
|
||||
|
||||
import org.spongycastle.openpgp.PGPPublicKeyRing;
|
||||
import org.thialfihar.android.apg.Apg;
|
||||
import org.thialfihar.android.apg.Constants;
|
||||
import org.thialfihar.android.apg.Id;
|
||||
import org.thialfihar.android.apg.R;
|
||||
import org.thialfihar.android.apg.helper.PGPHelper;
|
||||
|
||||
import com.actionbarsherlock.view.Menu;
|
||||
import com.actionbarsherlock.view.MenuItem;
|
||||
@ -71,7 +71,7 @@ public class PublicKeyListActivity extends KeyListActivity {
|
||||
}
|
||||
case Id.menu.option.scanQRCode: {
|
||||
Intent intent = new Intent(this, ImportFromQRCodeActivity.class);
|
||||
intent.setAction(Apg.Intent.IMPORT_FROM_QR_CODE);
|
||||
intent.setAction(PGPHelper.Intent.IMPORT_FROM_QR_CODE);
|
||||
startActivityForResult(intent, Id.request.import_from_qr_code);
|
||||
|
||||
return true;
|
||||
@ -114,9 +114,9 @@ public class PublicKeyListActivity extends KeyListActivity {
|
||||
mSelectedItem = groupPosition;
|
||||
final int keyRingId = mListAdapter.getKeyRingId(groupPosition);
|
||||
long keyId = 0;
|
||||
Object keyRing = Apg.getKeyRing(keyRingId);
|
||||
Object keyRing = PGPHelper.getKeyRing(keyRingId);
|
||||
if (keyRing != null && keyRing instanceof PGPPublicKeyRing) {
|
||||
keyId = Apg.getMasterKey((PGPPublicKeyRing) keyRing).getKeyID();
|
||||
keyId = PGPHelper.getMasterKey((PGPPublicKeyRing) keyRing).getKeyID();
|
||||
}
|
||||
if (keyId == 0) {
|
||||
// this shouldn't happen
|
||||
@ -124,8 +124,8 @@ public class PublicKeyListActivity extends KeyListActivity {
|
||||
}
|
||||
|
||||
Intent intent = new Intent(this, KeyServerQueryActivity.class);
|
||||
intent.setAction(Apg.Intent.LOOK_UP_KEY_ID_AND_RETURN);
|
||||
intent.putExtra(Apg.EXTRA_KEY_ID, keyId);
|
||||
intent.setAction(PGPHelper.Intent.LOOK_UP_KEY_ID_AND_RETURN);
|
||||
intent.putExtra(PGPHelper.EXTRA_KEY_ID, keyId);
|
||||
startActivityForResult(intent, Id.request.look_up_key_id);
|
||||
|
||||
return true;
|
||||
@ -136,8 +136,8 @@ public class PublicKeyListActivity extends KeyListActivity {
|
||||
final int keyRingId = mListAdapter.getKeyRingId(groupPosition);
|
||||
|
||||
Intent intent = new Intent(this, KeyServerExportActivity.class);
|
||||
intent.setAction(Apg.Intent.EXPORT_KEY_TO_SERVER);
|
||||
intent.putExtra(Apg.EXTRA_KEY_ID, keyRingId);
|
||||
intent.setAction(PGPHelper.Intent.EXPORT_KEY_TO_SERVER);
|
||||
intent.putExtra(PGPHelper.EXTRA_KEY_ID, keyRingId);
|
||||
startActivityForResult(intent, Id.request.export_to_server);
|
||||
|
||||
return true;
|
||||
@ -147,9 +147,9 @@ public class PublicKeyListActivity extends KeyListActivity {
|
||||
mSelectedItem = groupPosition;
|
||||
final int keyRingId = mListAdapter.getKeyRingId(groupPosition);
|
||||
long keyId = 0;
|
||||
Object keyRing = Apg.getKeyRing(keyRingId);
|
||||
Object keyRing = PGPHelper.getKeyRing(keyRingId);
|
||||
if (keyRing != null && keyRing instanceof PGPPublicKeyRing) {
|
||||
keyId = Apg.getMasterKey((PGPPublicKeyRing) keyRing).getKeyID();
|
||||
keyId = PGPHelper.getMasterKey((PGPPublicKeyRing) keyRing).getKeyID();
|
||||
}
|
||||
|
||||
if (keyId == 0) {
|
||||
@ -158,7 +158,7 @@ public class PublicKeyListActivity extends KeyListActivity {
|
||||
}
|
||||
|
||||
Intent intent = new Intent(this, SignKeyActivity.class);
|
||||
intent.putExtra(Apg.EXTRA_KEY_ID, keyId);
|
||||
intent.putExtra(PGPHelper.EXTRA_KEY_ID, keyId);
|
||||
startActivity(intent);
|
||||
|
||||
return true;
|
||||
@ -175,13 +175,13 @@ public class PublicKeyListActivity extends KeyListActivity {
|
||||
switch (requestCode) {
|
||||
case Id.request.look_up_key_id: {
|
||||
if (resultCode == RESULT_CANCELED || data == null
|
||||
|| data.getStringExtra(Apg.EXTRA_TEXT) == null) {
|
||||
|| data.getStringExtra(PGPHelper.EXTRA_TEXT) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Intent intent = new Intent(this, PublicKeyListActivity.class);
|
||||
intent.setAction(Apg.Intent.IMPORT);
|
||||
intent.putExtra(Apg.EXTRA_TEXT, data.getStringExtra(Apg.EXTRA_TEXT));
|
||||
intent.setAction(PGPHelper.Intent.IMPORT);
|
||||
intent.putExtra(PGPHelper.EXTRA_TEXT, data.getStringExtra(PGPHelper.EXTRA_TEXT));
|
||||
handleIntent(intent);
|
||||
break;
|
||||
}
|
||||
|
@ -17,9 +17,9 @@
|
||||
package org.thialfihar.android.apg.ui;
|
||||
|
||||
import org.thialfihar.android.apg.R;
|
||||
import org.thialfihar.android.apg.Apg;
|
||||
import org.thialfihar.android.apg.Constants;
|
||||
import org.thialfihar.android.apg.Id;
|
||||
import org.thialfihar.android.apg.helper.PGPHelper;
|
||||
import org.thialfihar.android.apg.passphrase.AskForPassphrase;
|
||||
|
||||
import com.actionbarsherlock.view.Menu;
|
||||
@ -111,7 +111,7 @@ public class SecretKeyListActivity extends KeyListActivity implements OnChildCli
|
||||
|
||||
long keyId = ((KeyListAdapter) mList.getExpandableListAdapter())
|
||||
.getGroupId(mSelectedItem);
|
||||
String msg = keyId + "," + Apg.getFingerPrint(keyId);
|
||||
String msg = keyId + "," + PGPHelper.getFingerPrint(keyId);
|
||||
|
||||
new IntentIntegrator(this).shareText(msg);
|
||||
}
|
||||
@ -146,11 +146,11 @@ public class SecretKeyListActivity extends KeyListActivity implements OnChildCli
|
||||
|
||||
public void checkPassPhraseAndEdit() {
|
||||
long keyId = ((KeyListAdapter) mList.getExpandableListAdapter()).getGroupId(mSelectedItem);
|
||||
String passPhrase = Apg.getCachedPassPhrase(keyId);
|
||||
String passPhrase = PGPHelper.getCachedPassPhrase(keyId);
|
||||
if (passPhrase == null) {
|
||||
showDialog(Id.dialog.pass_phrase);
|
||||
} else {
|
||||
Apg.setEditPassPhrase(passPhrase);
|
||||
PGPHelper.setEditPassPhrase(passPhrase);
|
||||
editKey();
|
||||
}
|
||||
}
|
||||
@ -158,20 +158,20 @@ public class SecretKeyListActivity extends KeyListActivity implements OnChildCli
|
||||
@Override
|
||||
public void passPhraseCallback(long keyId, String passPhrase) {
|
||||
super.passPhraseCallback(keyId, passPhrase);
|
||||
Apg.setEditPassPhrase(passPhrase);
|
||||
PGPHelper.setEditPassPhrase(passPhrase);
|
||||
editKey();
|
||||
}
|
||||
|
||||
private void createKey() {
|
||||
Apg.setEditPassPhrase("");
|
||||
Intent intent = new Intent(Apg.Intent.CREATE_KEY);
|
||||
PGPHelper.setEditPassPhrase("");
|
||||
Intent intent = new Intent(PGPHelper.Intent.CREATE_KEY);
|
||||
startActivityForResult(intent, Id.message.create_key);
|
||||
}
|
||||
|
||||
private void editKey() {
|
||||
long keyId = ((KeyListAdapter) mList.getExpandableListAdapter()).getGroupId(mSelectedItem);
|
||||
Intent intent = new Intent(Apg.Intent.EDIT_KEY);
|
||||
intent.putExtra(Apg.EXTRA_KEY_ID, keyId);
|
||||
Intent intent = new Intent(PGPHelper.Intent.EDIT_KEY);
|
||||
intent.putExtra(PGPHelper.EXTRA_KEY_ID, keyId);
|
||||
startActivityForResult(intent, Id.message.edit_key);
|
||||
}
|
||||
|
||||
|
@ -19,8 +19,8 @@ package org.thialfihar.android.apg.ui;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.thialfihar.android.apg.R;
|
||||
import org.thialfihar.android.apg.Apg;
|
||||
import org.thialfihar.android.apg.Id;
|
||||
import org.thialfihar.android.apg.helper.PGPHelper;
|
||||
import org.thialfihar.android.apg.ui.widget.SelectPublicKeyListAdapter;
|
||||
|
||||
import com.actionbarsherlock.app.ActionBar;
|
||||
@ -89,7 +89,7 @@ public class SelectPublicKeyListActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
long selectedKeyIds[] = null;
|
||||
selectedKeyIds = intent.getLongArrayExtra(Apg.EXTRA_SELECTION);
|
||||
selectedKeyIds = intent.getLongArrayExtra(PGPHelper.EXTRA_SELECTION);
|
||||
|
||||
if (selectedKeyIds == null) {
|
||||
Vector<Long> vector = new Vector<Long>();
|
||||
@ -151,8 +151,8 @@ public class SelectPublicKeyListActivity extends BaseActivity {
|
||||
selectedKeyIds[i] = keys.get(i);
|
||||
}
|
||||
String userIdArray[] = new String[0];
|
||||
data.putExtra(Apg.EXTRA_SELECTION, selectedKeyIds);
|
||||
data.putExtra(Apg.EXTRA_USER_IDS, userIds.toArray(userIdArray));
|
||||
data.putExtra(PGPHelper.EXTRA_SELECTION, selectedKeyIds);
|
||||
data.putExtra(PGPHelper.EXTRA_USER_IDS, userIds.toArray(userIdArray));
|
||||
setResult(RESULT_OK, data);
|
||||
finish();
|
||||
}
|
||||
|
@ -17,8 +17,8 @@
|
||||
package org.thialfihar.android.apg.ui;
|
||||
|
||||
import org.thialfihar.android.apg.R;
|
||||
import org.thialfihar.android.apg.Apg;
|
||||
import org.thialfihar.android.apg.Id;
|
||||
import org.thialfihar.android.apg.helper.PGPHelper;
|
||||
import org.thialfihar.android.apg.ui.widget.SelectSecretKeyListAdapter;
|
||||
|
||||
import com.actionbarsherlock.app.ActionBar;
|
||||
@ -62,8 +62,8 @@ public class SelectSecretKeyListActivity extends BaseActivity {
|
||||
mList.setOnItemClickListener(new OnItemClickListener() {
|
||||
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
|
||||
Intent data = new Intent();
|
||||
data.putExtra(Apg.EXTRA_KEY_ID, id);
|
||||
data.putExtra(Apg.EXTRA_USER_ID, (String) mList.getItemAtPosition(position));
|
||||
data.putExtra(PGPHelper.EXTRA_KEY_ID, id);
|
||||
data.putExtra(PGPHelper.EXTRA_USER_ID, (String) mList.getItemAtPosition(position));
|
||||
setResult(RESULT_OK, data);
|
||||
finish();
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Senecaso
|
||||
*
|
||||
* 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
|
||||
@ -30,11 +32,11 @@ import org.spongycastle.openpgp.PGPSignatureGenerator;
|
||||
import org.spongycastle.openpgp.PGPSignatureSubpacketGenerator;
|
||||
import org.spongycastle.openpgp.PGPSignatureSubpacketVector;
|
||||
import org.spongycastle.openpgp.PGPUtil;
|
||||
import org.thialfihar.android.apg.Apg;
|
||||
import org.thialfihar.android.apg.Constants;
|
||||
import org.thialfihar.android.apg.HkpKeyServer;
|
||||
import org.thialfihar.android.apg.Id;
|
||||
import org.thialfihar.android.apg.R;
|
||||
import org.thialfihar.android.apg.helper.PGPHelper;
|
||||
|
||||
import com.actionbarsherlock.view.MenuItem;
|
||||
|
||||
@ -122,7 +124,7 @@ public class SignKeyActivity extends BaseActivity {
|
||||
}
|
||||
});
|
||||
|
||||
pubKeyId = getIntent().getLongExtra(Apg.EXTRA_KEY_ID, 0);
|
||||
pubKeyId = getIntent().getLongExtra(PGPHelper.EXTRA_KEY_ID, 0);
|
||||
if (pubKeyId == 0) {
|
||||
finish(); // nothing to do if we dont know what key to sign
|
||||
} else {
|
||||
@ -137,7 +139,7 @@ public class SignKeyActivity extends BaseActivity {
|
||||
* handles the UI bits of the signing process on the UI thread
|
||||
*/
|
||||
private void initiateSigning() {
|
||||
PGPPublicKeyRing pubring = Apg.getPublicKeyRing(pubKeyId);
|
||||
PGPPublicKeyRing pubring = PGPHelper.getPublicKeyRing(pubKeyId);
|
||||
if (pubring != null) {
|
||||
// if we have already signed this key, dont bother doing it again
|
||||
boolean alreadySigned = false;
|
||||
@ -156,7 +158,7 @@ public class SignKeyActivity extends BaseActivity {
|
||||
/*
|
||||
* get the user's passphrase for this key (if required)
|
||||
*/
|
||||
String passphrase = Apg.getCachedPassPhrase(masterKeyId);
|
||||
String passphrase = PGPHelper.getCachedPassPhrase(masterKeyId);
|
||||
if (passphrase == null) {
|
||||
showDialog(Id.dialog.pass_phrase);
|
||||
return; // bail out; need to wait until the user has entered the passphrase
|
||||
@ -168,7 +170,7 @@ public class SignKeyActivity extends BaseActivity {
|
||||
final Bundle status = new Bundle();
|
||||
Message msg = new Message();
|
||||
|
||||
status.putString(Apg.EXTRA_ERROR, "Key has already been signed");
|
||||
status.putString(PGPHelper.EXTRA_ERROR, "Key has already been signed");
|
||||
|
||||
status.putInt(Constants.extras.STATUS, Id.message.done);
|
||||
|
||||
@ -206,16 +208,16 @@ public class SignKeyActivity extends BaseActivity {
|
||||
Message msg = new Message();
|
||||
|
||||
try {
|
||||
String passphrase = Apg.getCachedPassPhrase(masterKeyId);
|
||||
String passphrase = PGPHelper.getCachedPassPhrase(masterKeyId);
|
||||
if (passphrase == null || passphrase.length() <= 0) {
|
||||
status.putString(Apg.EXTRA_ERROR, "Unable to obtain passphrase");
|
||||
status.putString(PGPHelper.EXTRA_ERROR, "Unable to obtain passphrase");
|
||||
} else {
|
||||
PGPPublicKeyRing pubring = Apg.getPublicKeyRing(pubKeyId);
|
||||
PGPPublicKeyRing pubring = PGPHelper.getPublicKeyRing(pubKeyId);
|
||||
|
||||
/*
|
||||
* sign the incoming key
|
||||
*/
|
||||
PGPSecretKey secretKey = Apg.getSecretKey(masterKeyId);
|
||||
PGPSecretKey secretKey = PGPHelper.getSecretKey(masterKeyId);
|
||||
PGPPrivateKey signingKey = secretKey.extractPrivateKey(passphrase.toCharArray(),
|
||||
BouncyCastleProvider.PROVIDER_NAME);
|
||||
PGPSignatureGenerator sGen = new PGPSignatureGenerator(secretKey.getPublicKey()
|
||||
@ -241,33 +243,33 @@ public class SignKeyActivity extends BaseActivity {
|
||||
* upload the newly signed key to the key server
|
||||
*/
|
||||
|
||||
Apg.uploadKeyRingToServer(server, pubring);
|
||||
PGPHelper.uploadKeyRingToServer(server, pubring);
|
||||
}
|
||||
|
||||
// store the signed key in our local cache
|
||||
int retval = Apg.storeKeyRingInCache(pubring);
|
||||
int retval = PGPHelper.storeKeyRingInCache(pubring);
|
||||
if (retval != Id.return_value.ok && retval != Id.return_value.updated) {
|
||||
status.putString(Apg.EXTRA_ERROR, "Failed to store signed key in local cache");
|
||||
status.putString(PGPHelper.EXTRA_ERROR, "Failed to store signed key in local cache");
|
||||
}
|
||||
}
|
||||
} catch (PGPException e) {
|
||||
Log.e(TAG, "Failed to sign key", e);
|
||||
status.putString(Apg.EXTRA_ERROR, "Failed to sign key");
|
||||
status.putString(PGPHelper.EXTRA_ERROR, "Failed to sign key");
|
||||
status.putInt(Constants.extras.STATUS, Id.message.done);
|
||||
return;
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
Log.e(TAG, "Failed to sign key", e);
|
||||
status.putString(Apg.EXTRA_ERROR, "Failed to sign key");
|
||||
status.putString(PGPHelper.EXTRA_ERROR, "Failed to sign key");
|
||||
status.putInt(Constants.extras.STATUS, Id.message.done);
|
||||
return;
|
||||
} catch (NoSuchProviderException e) {
|
||||
Log.e(TAG, "Failed to sign key", e);
|
||||
status.putString(Apg.EXTRA_ERROR, "Failed to sign key");
|
||||
status.putString(PGPHelper.EXTRA_ERROR, "Failed to sign key");
|
||||
status.putInt(Constants.extras.STATUS, Id.message.done);
|
||||
return;
|
||||
} catch (SignatureException e) {
|
||||
Log.e(TAG, "Failed to sign key", e);
|
||||
status.putString(Apg.EXTRA_ERROR, "Failed to sign key");
|
||||
status.putString(PGPHelper.EXTRA_ERROR, "Failed to sign key");
|
||||
status.putInt(Constants.extras.STATUS, Id.message.done);
|
||||
return;
|
||||
}
|
||||
@ -277,7 +279,7 @@ public class SignKeyActivity extends BaseActivity {
|
||||
msg.setData(status);
|
||||
sendMessage(msg);
|
||||
|
||||
if (status.containsKey(Apg.EXTRA_ERROR)) {
|
||||
if (status.containsKey(PGPHelper.EXTRA_ERROR)) {
|
||||
setResult(Id.return_value.error);
|
||||
} else {
|
||||
setResult(Id.return_value.ok);
|
||||
@ -291,7 +293,7 @@ public class SignKeyActivity extends BaseActivity {
|
||||
switch (requestCode) {
|
||||
case Id.request.secret_keys: {
|
||||
if (resultCode == RESULT_OK) {
|
||||
masterKeyId = data.getLongExtra(Apg.EXTRA_KEY_ID, 0);
|
||||
masterKeyId = data.getLongExtra(PGPHelper.EXTRA_KEY_ID, 0);
|
||||
|
||||
// re-enable the sign button so the user can initiate the sign process
|
||||
Button sign = (Button) findViewById(R.id.sign);
|
||||
@ -314,7 +316,7 @@ public class SignKeyActivity extends BaseActivity {
|
||||
removeDialog(Id.dialog.signing);
|
||||
|
||||
Bundle data = msg.getData();
|
||||
String error = data.getString(Apg.EXTRA_ERROR);
|
||||
String error = data.getString(PGPHelper.EXTRA_ERROR);
|
||||
if (error != null) {
|
||||
Toast.makeText(this, getString(R.string.errorMessage, error), Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
|
@ -18,7 +18,8 @@ package org.thialfihar.android.apg.ui.dialog;
|
||||
|
||||
import org.thialfihar.android.apg.Constants;
|
||||
import org.thialfihar.android.apg.R;
|
||||
import org.thialfihar.android.apg.util.Utils;
|
||||
import org.thialfihar.android.apg.helper.FileHelper;
|
||||
import org.thialfihar.android.apg.helper.OtherHelper;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
@ -51,7 +52,7 @@ public class FileDialogFragment extends DialogFragment {
|
||||
public static final int MESSAGE_OKAY = 1;
|
||||
|
||||
public static final String MESSAGE_DATA_FILENAME = "filename";
|
||||
public static final String MESSAGE_CHECKED = "checked";
|
||||
public static final String MESSAGE_DATA_CHECKED = "checked";
|
||||
|
||||
/**
|
||||
* Creates new instance of this file dialog fragment
|
||||
@ -107,7 +108,7 @@ public class FileDialogFragment extends DialogFragment {
|
||||
mBrowse.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
// only .asc or .gpg files
|
||||
Utils.openFile(activity, mFilename.getText().toString(), "text/plain", requestCode);
|
||||
FileHelper.openFile(activity, mFilename.getText().toString(), "text/plain", requestCode);
|
||||
}
|
||||
});
|
||||
|
||||
@ -135,7 +136,7 @@ public class FileDialogFragment extends DialogFragment {
|
||||
// return resulting data back to activity
|
||||
Bundle data = new Bundle();
|
||||
data.putString(MESSAGE_DATA_FILENAME, mFilename.getText().toString());
|
||||
data.putBoolean(MESSAGE_CHECKED, checked);
|
||||
data.putBoolean(MESSAGE_DATA_CHECKED, checked);
|
||||
|
||||
sendMessageToHandler(MESSAGE_OKAY, data);
|
||||
|
||||
|
@ -21,8 +21,8 @@ import org.spongycastle.openpgp.PGPPrivateKey;
|
||||
import org.spongycastle.openpgp.PGPSecretKey;
|
||||
import org.spongycastle.openpgp.operator.PBESecretKeyDecryptor;
|
||||
import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder;
|
||||
import org.thialfihar.android.apg.Apg;
|
||||
import org.thialfihar.android.apg.Apg.GeneralException;
|
||||
import org.thialfihar.android.apg.helper.PGPHelper;
|
||||
import org.thialfihar.android.apg.helper.PGPHelper.GeneralException;
|
||||
import org.thialfihar.android.apg.Constants;
|
||||
import org.thialfihar.android.apg.Id;
|
||||
import org.thialfihar.android.apg.R;
|
||||
@ -68,7 +68,7 @@ public class PassphraseDialogFragment extends DialogFragment {
|
||||
// check if secret key has a passphrase
|
||||
if (!(secretKeyId == Id.key.symmetric || secretKeyId == Id.key.none)) {
|
||||
if (!hasPassphrase(secretKeyId)) {
|
||||
throw new Apg.GeneralException("No passphrase! No passphrase dialog needed!");
|
||||
throw new PGPHelper.GeneralException("No passphrase! No passphrase dialog needed!");
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,7 +91,7 @@ public class PassphraseDialogFragment extends DialogFragment {
|
||||
private static boolean hasPassphrase(long secretKeyId) {
|
||||
// check if the key has no passphrase
|
||||
try {
|
||||
PGPSecretKey secretKey = Apg.getMasterKey(Apg.getSecretKeyRing(secretKeyId));
|
||||
PGPSecretKey secretKey = PGPHelper.getMasterKey(PGPHelper.getSecretKeyRing(secretKeyId));
|
||||
|
||||
Log.d(Constants.TAG, "Check if key has no passphrase...");
|
||||
PBESecretKeyDecryptor keyDecryptor = new JcePBESecretKeyDecryptorBuilder().setProvider(
|
||||
@ -101,7 +101,7 @@ public class PassphraseDialogFragment extends DialogFragment {
|
||||
Log.d(Constants.TAG, "Key has no passphrase! Caches empty passphrase!");
|
||||
|
||||
// cache empty passphrase
|
||||
Apg.setCachedPassPhrase(secretKey.getKeyID(), "");
|
||||
PGPHelper.setCachedPassPhrase(secretKey.getKeyID(), "");
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -132,7 +132,7 @@ public class PassphraseDialogFragment extends DialogFragment {
|
||||
secretKey = null;
|
||||
alert.setMessage(getString(R.string.passPhraseForSymmetricEncryption));
|
||||
} else {
|
||||
secretKey = Apg.getMasterKey(Apg.getSecretKeyRing(secretKeyId));
|
||||
secretKey = PGPHelper.getMasterKey(PGPHelper.getSecretKeyRing(secretKeyId));
|
||||
if (secretKey == null) {
|
||||
alert.setTitle(R.string.title_keyNotFound);
|
||||
alert.setMessage(getString(R.string.keyNotFound, secretKeyId));
|
||||
@ -144,7 +144,7 @@ public class PassphraseDialogFragment extends DialogFragment {
|
||||
alert.setCancelable(false);
|
||||
return alert.create();
|
||||
}
|
||||
String userId = Apg.getMainUserIdSafe(activity, secretKey);
|
||||
String userId = PGPHelper.getMainUserIdSafe(activity, secretKey);
|
||||
alert.setMessage(getString(R.string.passPhraseFor, userId));
|
||||
}
|
||||
|
||||
@ -189,7 +189,7 @@ public class PassphraseDialogFragment extends DialogFragment {
|
||||
|
||||
// cache the new passphrase
|
||||
Log.d(Constants.TAG, "Everything okay! Caching entered passphrase");
|
||||
Apg.setCachedPassPhrase(keyId, passPhrase);
|
||||
PGPHelper.setCachedPassPhrase(keyId, passPhrase);
|
||||
|
||||
sendMessageToHandler(MESSAGE_OKAY);
|
||||
}
|
||||
|
@ -18,8 +18,8 @@ package org.thialfihar.android.apg.ui.widget;
|
||||
|
||||
import org.spongycastle.openpgp.PGPPublicKey;
|
||||
import org.spongycastle.openpgp.PGPSecretKey;
|
||||
import org.thialfihar.android.apg.Apg;
|
||||
import org.thialfihar.android.apg.Id;
|
||||
import org.thialfihar.android.apg.helper.PGPHelper;
|
||||
import org.thialfihar.android.apg.util.Choice;
|
||||
import org.thialfihar.android.apg.R;
|
||||
|
||||
@ -133,9 +133,9 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
||||
mDeleteButton.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
|
||||
mAlgorithm.setText(Apg.getAlgorithmInfo(key));
|
||||
String keyId1Str = Apg.getSmallFingerPrint(key.getKeyID());
|
||||
String keyId2Str = Apg.getSmallFingerPrint(key.getKeyID() >> 32);
|
||||
mAlgorithm.setText(PGPHelper.getAlgorithmInfo(key));
|
||||
String keyId1Str = PGPHelper.getSmallFingerPrint(key.getKeyID());
|
||||
String keyId2Str = PGPHelper.getSmallFingerPrint(key.getKeyID() >> 32);
|
||||
mKeyId.setText(keyId1Str + " " + keyId2Str);
|
||||
|
||||
Vector<Choice> choices = new Vector<Choice>();
|
||||
@ -160,8 +160,8 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
||||
|
||||
// Set value in choice dropdown to key
|
||||
int selectId = 0;
|
||||
if (Apg.isEncryptionKey(key)) {
|
||||
if (Apg.isSigningKey(key)) {
|
||||
if (PGPHelper.isEncryptionKey(key)) {
|
||||
if (PGPHelper.isSigningKey(key)) {
|
||||
selectId = Id.choice.usage.sign_and_encrypt;
|
||||
} else {
|
||||
selectId = Id.choice.usage.encrypt_only;
|
||||
@ -184,14 +184,14 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
||||
}
|
||||
|
||||
GregorianCalendar cal = new GregorianCalendar();
|
||||
cal.setTime(Apg.getCreationDate(key));
|
||||
cal.setTime(PGPHelper.getCreationDate(key));
|
||||
mCreationDate.setText(DateFormat.getDateInstance().format(cal.getTime()));
|
||||
cal = new GregorianCalendar();
|
||||
Date date = Apg.getExpiryDate(key);
|
||||
Date date = PGPHelper.getExpiryDate(key);
|
||||
if (date == null) {
|
||||
setExpiryDate(null);
|
||||
} else {
|
||||
cal.setTime(Apg.getExpiryDate(key));
|
||||
cal.setTime(PGPHelper.getExpiryDate(key));
|
||||
setExpiryDate(cal);
|
||||
}
|
||||
|
||||
|
@ -18,14 +18,14 @@ package org.thialfihar.android.apg.ui.widget;
|
||||
|
||||
import org.spongycastle.openpgp.PGPSecretKey;
|
||||
import org.spongycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.thialfihar.android.apg.Apg;
|
||||
import org.thialfihar.android.apg.Id;
|
||||
import org.thialfihar.android.apg.helper.PGPHelper;
|
||||
import org.thialfihar.android.apg.helper.PGPConversionHelper;
|
||||
import org.thialfihar.android.apg.service.ApgHandler;
|
||||
import org.thialfihar.android.apg.service.ApgService;
|
||||
import org.thialfihar.android.apg.ui.dialog.ProgressDialogFragment;
|
||||
import org.thialfihar.android.apg.ui.widget.Editor.EditorListener;
|
||||
import org.thialfihar.android.apg.util.Choice;
|
||||
import org.thialfihar.android.apg.util.Utils;
|
||||
import org.thialfihar.android.apg.R;
|
||||
|
||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
@ -259,9 +259,10 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
|
||||
String passPhrase;
|
||||
if (mEditors.getChildCount() > 0) {
|
||||
PGPSecretKey masterKey = ((KeyEditor) mEditors.getChildAt(0)).getValue();
|
||||
passPhrase = Apg.getCachedPassPhrase(masterKey.getKeyID());
|
||||
passPhrase = PGPHelper.getCachedPassPhrase(masterKey.getKeyID());
|
||||
|
||||
data.putByteArray(ApgService.MASTER_KEY, Utils.PGPSecretKeyToBytes(masterKey));
|
||||
data.putByteArray(ApgService.MASTER_KEY,
|
||||
PGPConversionHelper.PGPSecretKeyToBytes(masterKey));
|
||||
} else {
|
||||
passPhrase = "";
|
||||
}
|
||||
@ -284,7 +285,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
|
||||
if (message.arg1 == ApgHandler.MESSAGE_OKAY) {
|
||||
// get new key from data bundle returned from service
|
||||
Bundle data = message.getData();
|
||||
PGPSecretKeyRing newKeyRing = Utils.BytesToPGPSecretKeyRing(data
|
||||
PGPSecretKeyRing newKeyRing = PGPConversionHelper.BytesToPGPSecretKeyRing(data
|
||||
.getByteArray(ApgService.RESULT_NEW_KEY));
|
||||
|
||||
boolean isMasterKey = (mEditors.getChildCount() == 0);
|
||||
|
@ -19,8 +19,8 @@ package org.thialfihar.android.apg.ui.widget;
|
||||
import java.util.Date;
|
||||
|
||||
import org.thialfihar.android.apg.R;
|
||||
import org.thialfihar.android.apg.Apg;
|
||||
import org.thialfihar.android.apg.Id;
|
||||
import org.thialfihar.android.apg.helper.PGPHelper;
|
||||
import org.thialfihar.android.apg.provider.KeyRings;
|
||||
import org.thialfihar.android.apg.provider.Keys;
|
||||
import org.thialfihar.android.apg.provider.UserIds;
|
||||
@ -53,7 +53,7 @@ public class SelectPublicKeyListAdapter extends BaseAdapter {
|
||||
|
||||
mActivity = activity;
|
||||
mParent = parent;
|
||||
mDatabase = Apg.getDatabase().db();
|
||||
mDatabase = PGPHelper.getDatabase().db();
|
||||
mInflater = (LayoutInflater) parent.getContext().getSystemService(
|
||||
Context.LAYOUT_INFLATER_SERVICE);
|
||||
long now = new Date().getTime() / 1000;
|
||||
@ -177,7 +177,7 @@ public class SelectPublicKeyListAdapter extends BaseAdapter {
|
||||
}
|
||||
|
||||
long masterKeyId = mCursor.getLong(1); // MASTER_KEY_ID
|
||||
keyId.setText(Apg.getSmallFingerPrint(masterKeyId));
|
||||
keyId.setText(PGPHelper.getSmallFingerPrint(masterKeyId));
|
||||
|
||||
if (mainUserIdRest.getText().length() == 0) {
|
||||
mainUserIdRest.setVisibility(View.GONE);
|
||||
|
@ -17,8 +17,8 @@ package org.thialfihar.android.apg.ui.widget;
|
||||
import java.util.Date;
|
||||
|
||||
import org.thialfihar.android.apg.R;
|
||||
import org.thialfihar.android.apg.Apg;
|
||||
import org.thialfihar.android.apg.Id;
|
||||
import org.thialfihar.android.apg.helper.PGPHelper;
|
||||
import org.thialfihar.android.apg.provider.KeyRings;
|
||||
import org.thialfihar.android.apg.provider.Keys;
|
||||
import org.thialfihar.android.apg.provider.UserIds;
|
||||
@ -48,7 +48,7 @@ public class SelectSecretKeyListAdapter extends BaseAdapter {
|
||||
|
||||
mActivity = activity;
|
||||
mParent = parent;
|
||||
mDatabase = Apg.getDatabase().db();
|
||||
mDatabase = PGPHelper.getDatabase().db();
|
||||
mInflater = (LayoutInflater) parent.getContext().getSystemService(
|
||||
Context.LAYOUT_INFLATER_SERVICE);
|
||||
long now = new Date().getTime() / 1000;
|
||||
@ -151,7 +151,7 @@ public class SelectSecretKeyListAdapter extends BaseAdapter {
|
||||
}
|
||||
|
||||
long masterKeyId = mCursor.getLong(1); // MASTER_KEY_ID
|
||||
keyId.setText(Apg.getSmallFingerPrint(masterKeyId));
|
||||
keyId.setText(PGPHelper.getSmallFingerPrint(masterKeyId));
|
||||
|
||||
if (mainUserIdRest.getText().length() == 0) {
|
||||
mainUserIdRest.setVisibility(View.GONE);
|
||||
|
@ -1,6 +0,0 @@
|
||||
package org.thialfihar.android.apg.util;
|
||||
|
||||
public class Constants {
|
||||
public static final String TAG = "APG";
|
||||
|
||||
}
|
@ -12,10 +12,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.thialfihar.android.apg;
|
||||
package org.thialfihar.android.apg.util;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
|
||||
public class InputData {
|
||||
private PositionAwareInputStream mInputStream;
|
||||
private long mSize;
|
@ -12,7 +12,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.thialfihar.android.apg;
|
||||
package org.thialfihar.android.apg.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.thialfihar.android.apg;
|
||||
package org.thialfihar.android.apg.util;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
Loading…
Reference in New Issue
Block a user