mirror of
https://github.com/moparisthebest/open-keychain
synced 2025-01-31 23:20:20 -05:00
more Provider Helper methods
This commit is contained in:
parent
fb49f9e9c8
commit
95e35a4ffa
@ -20,7 +20,6 @@ import java.io.File;
|
|||||||
import java.security.Security;
|
import java.security.Security;
|
||||||
|
|
||||||
import org.spongycastle.jce.provider.BouncyCastleProvider;
|
import org.spongycastle.jce.provider.BouncyCastleProvider;
|
||||||
import org.thialfihar.android.apg.helper.PGPMain;
|
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
@ -36,10 +35,6 @@ public class ApgApplication extends Application {
|
|||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
|
|
||||||
// TODO: Do it better than this!
|
|
||||||
// this initializes the database to be used in PGPMain
|
|
||||||
PGPMain.initialize(this);
|
|
||||||
|
|
||||||
// Create APG directory on sdcard if not existing
|
// Create APG directory on sdcard if not existing
|
||||||
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
||||||
File dir = new File(Constants.path.APP_DIR);
|
File dir = new File(Constants.path.APP_DIR);
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,71 +1,71 @@
|
|||||||
/*
|
///*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
// * Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
// * you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
// * You may obtain a copy of the License at
|
||||||
*
|
// *
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
// * http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
// *
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
// * Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
// * distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
// * See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
// * limitations under the License.
|
||||||
*/
|
// */
|
||||||
|
//
|
||||||
package org.thialfihar.android.apg.deprecated;
|
//package org.thialfihar.android.apg.deprecated;
|
||||||
|
//
|
||||||
|
//
|
||||||
import android.content.ContentUris;
|
//import android.content.ContentUris;
|
||||||
import android.content.ContentValues;
|
//import android.content.ContentValues;
|
||||||
import android.content.Context;
|
//import android.content.Context;
|
||||||
import android.database.Cursor;
|
//import android.database.Cursor;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
//import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.database.sqlite.SQLiteOpenHelper;
|
//import android.database.sqlite.SQLiteOpenHelper;
|
||||||
import android.net.Uri;
|
//import android.net.Uri;
|
||||||
import org.thialfihar.android.apg.util.Log;
|
//import org.thialfihar.android.apg.util.Log;
|
||||||
|
//
|
||||||
public class ApgServiceBlobDatabase extends SQLiteOpenHelper {
|
//public class ApgServiceBlobDatabase extends SQLiteOpenHelper {
|
||||||
|
//
|
||||||
private static final String TAG = "ApgServiceBlobDatabase";
|
// private static final String TAG = "ApgServiceBlobDatabase";
|
||||||
|
//
|
||||||
private static final int VERSION = 1;
|
// private static final int VERSION = 1;
|
||||||
private static final String NAME = "apg_service_blob_data";
|
// private static final String NAME = "apg_service_blob_data";
|
||||||
private static final String TABLE = "data";
|
// private static final String TABLE = "data";
|
||||||
|
//
|
||||||
public ApgServiceBlobDatabase(Context context) {
|
// public ApgServiceBlobDatabase(Context context) {
|
||||||
super(context, NAME, null, VERSION);
|
// super(context, NAME, null, VERSION);
|
||||||
if (ApgService2.LOCAL_LOGD)
|
// if (ApgService2.LOCAL_LOGD)
|
||||||
Log.d(TAG, "constructor called");
|
// Log.d(TAG, "constructor called");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public void onCreate(SQLiteDatabase db) {
|
// public void onCreate(SQLiteDatabase db) {
|
||||||
if (ApgService2.LOCAL_LOGD)
|
// if (ApgService2.LOCAL_LOGD)
|
||||||
Log.d(TAG, "onCreate() called");
|
// Log.d(TAG, "onCreate() called");
|
||||||
db.execSQL("create table " + TABLE + " ( _id integer primary key autoincrement,"
|
// db.execSQL("create table " + TABLE + " ( _id integer primary key autoincrement,"
|
||||||
+ "key text not null)");
|
// + "key text not null)");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
// public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||||
if (ApgService2.LOCAL_LOGD)
|
// if (ApgService2.LOCAL_LOGD)
|
||||||
Log.d(TAG, "onUpgrade() called");
|
// Log.d(TAG, "onUpgrade() called");
|
||||||
// no upgrade necessary yet
|
// // no upgrade necessary yet
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public Uri insert(ContentValues vals) {
|
// public Uri insert(ContentValues vals) {
|
||||||
if (ApgService2.LOCAL_LOGD)
|
// if (ApgService2.LOCAL_LOGD)
|
||||||
Log.d(TAG, "insert() called");
|
// Log.d(TAG, "insert() called");
|
||||||
SQLiteDatabase db = this.getWritableDatabase();
|
// SQLiteDatabase db = this.getWritableDatabase();
|
||||||
long newId = db.insert(TABLE, null, vals);
|
// long newId = db.insert(TABLE, null, vals);
|
||||||
return ContentUris.withAppendedId(ApgServiceBlobProvider.CONTENT_URI, newId);
|
// return ContentUris.withAppendedId(ApgServiceBlobProvider.CONTENT_URI, newId);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public Cursor query(String id, String key) {
|
// public Cursor query(String id, String key) {
|
||||||
if (ApgService2.LOCAL_LOGD)
|
// if (ApgService2.LOCAL_LOGD)
|
||||||
Log.d(TAG, "query() called");
|
// Log.d(TAG, "query() called");
|
||||||
SQLiteDatabase db = this.getReadableDatabase();
|
// SQLiteDatabase db = this.getReadableDatabase();
|
||||||
return db.query(TABLE, new String[] { "_id" }, "_id = ? and key = ?", new String[] { id,
|
// return db.query(TABLE, new String[] { "_id" }, "_id = ? and key = ?", new String[] { id,
|
||||||
key }, null, null, null);
|
// key }, null, null, null);
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
@ -1,151 +1,151 @@
|
|||||||
/*
|
///*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
// * Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
// * you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
// * You may obtain a copy of the License at
|
||||||
*
|
// *
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
// * http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
// *
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
// * Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
// * distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
// * See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
// * limitations under the License.
|
||||||
*/
|
// */
|
||||||
|
//
|
||||||
package org.thialfihar.android.apg.deprecated;
|
//package org.thialfihar.android.apg.deprecated;
|
||||||
|
//
|
||||||
import org.thialfihar.android.apg.Constants;
|
//import org.thialfihar.android.apg.Constants;
|
||||||
|
//
|
||||||
import android.content.ContentProvider;
|
//import android.content.ContentProvider;
|
||||||
import android.content.ContentValues;
|
//import android.content.ContentValues;
|
||||||
import android.database.Cursor;
|
//import android.database.Cursor;
|
||||||
import android.net.Uri;
|
//import android.net.Uri;
|
||||||
import android.os.ParcelFileDescriptor;
|
//import android.os.ParcelFileDescriptor;
|
||||||
import org.thialfihar.android.apg.util.Log;
|
//import org.thialfihar.android.apg.util.Log;
|
||||||
|
//
|
||||||
import java.io.File;
|
//import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
//import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
//import java.io.IOException;
|
||||||
import java.util.List;
|
//import java.util.List;
|
||||||
import java.util.UUID;
|
//import java.util.UUID;
|
||||||
|
//
|
||||||
public class ApgServiceBlobProvider extends ContentProvider {
|
//public class ApgServiceBlobProvider extends ContentProvider {
|
||||||
|
//
|
||||||
private static final String TAG = "ApgServiceBlobProvider";
|
// private static final String TAG = "ApgServiceBlobProvider";
|
||||||
|
//
|
||||||
public static final Uri CONTENT_URI = Uri.parse("content://org.thialfihar.android.apg.provider.apgserviceblobprovider");
|
// public static final Uri CONTENT_URI = Uri.parse("content://org.thialfihar.android.apg.provider.apgserviceblobprovider");
|
||||||
|
//
|
||||||
private static final String COLUMN_KEY = "key";
|
// private static final String COLUMN_KEY = "key";
|
||||||
|
//
|
||||||
private static final String STORE_PATH = Constants.path.APP_DIR+"/ApgServiceBlobs";
|
// private static final String STORE_PATH = Constants.path.APP_DIR+"/ApgServiceBlobs";
|
||||||
|
//
|
||||||
private ApgServiceBlobDatabase mDb = null;
|
// private ApgServiceBlobDatabase mDb = null;
|
||||||
|
//
|
||||||
public ApgServiceBlobProvider() {
|
// public ApgServiceBlobProvider() {
|
||||||
if(ApgService2.LOCAL_LOGD) Log.d(TAG, "Constructor called");
|
// if(ApgService2.LOCAL_LOGD) Log.d(TAG, "Constructor called");
|
||||||
File dir = new File(STORE_PATH);
|
// File dir = new File(STORE_PATH);
|
||||||
dir.mkdirs();
|
// dir.mkdirs();
|
||||||
if(ApgService2.LOCAL_LOGD) Log.d(TAG, "Constructor finished");
|
// if(ApgService2.LOCAL_LOGD) Log.d(TAG, "Constructor finished");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public int delete(Uri arg0, String arg1, String[] arg2) {
|
// public int delete(Uri arg0, String arg1, String[] arg2) {
|
||||||
if(ApgService2.LOCAL_LOGD) Log.d(TAG, "delete() called");
|
// if(ApgService2.LOCAL_LOGD) Log.d(TAG, "delete() called");
|
||||||
// TODO Auto-generated method stub
|
// // TODO Auto-generated method stub
|
||||||
return 0;
|
// return 0;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public String getType(Uri arg0) {
|
// public String getType(Uri arg0) {
|
||||||
if(ApgService2.LOCAL_LOGD) Log.d(TAG, "getType() called");
|
// if(ApgService2.LOCAL_LOGD) Log.d(TAG, "getType() called");
|
||||||
// not needed for now
|
// // not needed for now
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public Uri insert(Uri uri, ContentValues ignored) {
|
// public Uri insert(Uri uri, ContentValues ignored) {
|
||||||
if(ApgService2.LOCAL_LOGD) Log.d(TAG, "insert() called");
|
// if(ApgService2.LOCAL_LOGD) Log.d(TAG, "insert() called");
|
||||||
// ContentValues are actually ignored, because we want to store a blob with no more information
|
// // ContentValues are actually ignored, because we want to store a blob with no more information
|
||||||
// but have to create an record with the password generated here first
|
// // but have to create an record with the password generated here first
|
||||||
|
//
|
||||||
ContentValues vals = new ContentValues();
|
// ContentValues vals = new ContentValues();
|
||||||
|
//
|
||||||
// Insert a random key in the database. This has to provided by the caller when updating or
|
// // Insert a random key in the database. This has to provided by the caller when updating or
|
||||||
// getting the blob
|
// // getting the blob
|
||||||
String password = UUID.randomUUID().toString();
|
// String password = UUID.randomUUID().toString();
|
||||||
vals.put(COLUMN_KEY, password);
|
// vals.put(COLUMN_KEY, password);
|
||||||
|
//
|
||||||
Uri insertedUri = mDb.insert(vals);
|
// Uri insertedUri = mDb.insert(vals);
|
||||||
return Uri.withAppendedPath(insertedUri, password);
|
// return Uri.withAppendedPath(insertedUri, password);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public boolean onCreate() {
|
// public boolean onCreate() {
|
||||||
if(ApgService2.LOCAL_LOGD) Log.d(TAG, "onCreate() called");
|
// if(ApgService2.LOCAL_LOGD) Log.d(TAG, "onCreate() called");
|
||||||
mDb = new ApgServiceBlobDatabase(getContext());
|
// mDb = new ApgServiceBlobDatabase(getContext());
|
||||||
// TODO Auto-generated method stub
|
// // TODO Auto-generated method stub
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public Cursor query(Uri arg0, String[] arg1, String arg2, String[] arg3, String arg4) {
|
// public Cursor query(Uri arg0, String[] arg1, String arg2, String[] arg3, String arg4) {
|
||||||
if(ApgService2.LOCAL_LOGD) Log.d(TAG, "query() called");
|
// if(ApgService2.LOCAL_LOGD) Log.d(TAG, "query() called");
|
||||||
// TODO Auto-generated method stub
|
// // TODO Auto-generated method stub
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public int update(Uri arg0, ContentValues arg1, String arg2, String[] arg3) {
|
// public int update(Uri arg0, ContentValues arg1, String arg2, String[] arg3) {
|
||||||
if(ApgService2.LOCAL_LOGD) Log.d(TAG, "update() called");
|
// if(ApgService2.LOCAL_LOGD) Log.d(TAG, "update() called");
|
||||||
// TODO Auto-generated method stub
|
// // TODO Auto-generated method stub
|
||||||
return 0;
|
// return 0;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public ParcelFileDescriptor openFile(Uri uri, String mode) throws SecurityException, FileNotFoundException {
|
// public ParcelFileDescriptor openFile(Uri uri, String mode) throws SecurityException, FileNotFoundException {
|
||||||
if(ApgService2.LOCAL_LOGD) Log.d(TAG, "openFile() called");
|
// if(ApgService2.LOCAL_LOGD) Log.d(TAG, "openFile() called");
|
||||||
if(ApgService2.LOCAL_LOGD) Log.d(TAG, "... with uri: "+uri.toString());
|
// if(ApgService2.LOCAL_LOGD) Log.d(TAG, "... with uri: "+uri.toString());
|
||||||
if(ApgService2.LOCAL_LOGD) Log.d(TAG, "... with mode: "+mode);
|
// if(ApgService2.LOCAL_LOGD) Log.d(TAG, "... with mode: "+mode);
|
||||||
|
//
|
||||||
List<String> segments = uri.getPathSegments();
|
// List<String> segments = uri.getPathSegments();
|
||||||
if(segments.size() < 2) {
|
// if(segments.size() < 2) {
|
||||||
throw new SecurityException("Password not found in URI");
|
// throw new SecurityException("Password not found in URI");
|
||||||
}
|
// }
|
||||||
String id = segments.get(0);
|
// String id = segments.get(0);
|
||||||
String key = segments.get(1);
|
// String key = segments.get(1);
|
||||||
|
//
|
||||||
if(ApgService2.LOCAL_LOGD) Log.d(TAG, "... got id: "+id);
|
// if(ApgService2.LOCAL_LOGD) Log.d(TAG, "... got id: "+id);
|
||||||
if(ApgService2.LOCAL_LOGD) Log.d(TAG, "... and key: "+key);
|
// if(ApgService2.LOCAL_LOGD) Log.d(TAG, "... and key: "+key);
|
||||||
|
//
|
||||||
// get the data
|
// // get the data
|
||||||
Cursor result = mDb.query(id, key);
|
// Cursor result = mDb.query(id, key);
|
||||||
|
//
|
||||||
if(result.getCount() == 0) {
|
// if(result.getCount() == 0) {
|
||||||
// either the key is wrong or no id exists
|
// // either the key is wrong or no id exists
|
||||||
throw new FileNotFoundException("No file found with that ID and/or password");
|
// throw new FileNotFoundException("No file found with that ID and/or password");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
File targetFile = new File(STORE_PATH, id);
|
// File targetFile = new File(STORE_PATH, id);
|
||||||
if(mode.equals("w")) {
|
// if(mode.equals("w")) {
|
||||||
if(ApgService2.LOCAL_LOGD) Log.d(TAG, "... will try to open file w");
|
// if(ApgService2.LOCAL_LOGD) Log.d(TAG, "... will try to open file w");
|
||||||
if( !targetFile.exists() ) {
|
// if( !targetFile.exists() ) {
|
||||||
try {
|
// try {
|
||||||
targetFile.createNewFile();
|
// targetFile.createNewFile();
|
||||||
} catch (IOException e) {
|
// } catch (IOException e) {
|
||||||
Log.e(TAG, "... got IEOException on creating new file", e);
|
// Log.e(TAG, "... got IEOException on creating new file", e);
|
||||||
throw new FileNotFoundException("Could not create file to write to");
|
// throw new FileNotFoundException("Could not create file to write to");
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return ParcelFileDescriptor.open(targetFile, ParcelFileDescriptor.MODE_WRITE_ONLY | ParcelFileDescriptor.MODE_TRUNCATE );
|
// return ParcelFileDescriptor.open(targetFile, ParcelFileDescriptor.MODE_WRITE_ONLY | ParcelFileDescriptor.MODE_TRUNCATE );
|
||||||
} else if(mode.equals("r")) {
|
// } else if(mode.equals("r")) {
|
||||||
if(ApgService2.LOCAL_LOGD) Log.d(TAG, "... will try to open file r");
|
// if(ApgService2.LOCAL_LOGD) Log.d(TAG, "... will try to open file r");
|
||||||
if( !targetFile.exists() ) {
|
// if( !targetFile.exists() ) {
|
||||||
throw new FileNotFoundException("Error: Could not find the file requested");
|
// throw new FileNotFoundException("Error: Could not find the file requested");
|
||||||
}
|
// }
|
||||||
return ParcelFileDescriptor.open(targetFile, ParcelFileDescriptor.MODE_READ_ONLY);
|
// return ParcelFileDescriptor.open(targetFile, ParcelFileDescriptor.MODE_READ_ONLY);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
//}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -38,6 +38,7 @@ import org.spongycastle.openpgp.PGPSignatureSubpacketVector;
|
|||||||
import org.spongycastle.openpgp.PGPUtil;
|
import org.spongycastle.openpgp.PGPUtil;
|
||||||
import org.thialfihar.android.apg.Constants;
|
import org.thialfihar.android.apg.Constants;
|
||||||
import org.thialfihar.android.apg.R;
|
import org.thialfihar.android.apg.R;
|
||||||
|
import org.thialfihar.android.apg.provider.ProviderHelper;
|
||||||
import org.thialfihar.android.apg.util.IterableIterator;
|
import org.thialfihar.android.apg.util.IterableIterator;
|
||||||
import org.thialfihar.android.apg.util.Log;
|
import org.thialfihar.android.apg.util.Log;
|
||||||
|
|
||||||
@ -189,9 +190,8 @@ public class PGPHelper {
|
|||||||
return getExpiryDate(key.getPublicKey());
|
return getExpiryDate(key.getPublicKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PGPPublicKey getEncryptPublicKey(long masterKeyId) {
|
public static PGPPublicKey getEncryptPublicKey(Context context, long masterKeyId) {
|
||||||
// TODO: externalize getSecretKeyRing from PGPWrapper into a DatabaseHelper
|
PGPPublicKeyRing keyRing = ProviderHelper.getPGPPublicKeyRing(context, masterKeyId);
|
||||||
PGPPublicKeyRing keyRing = PGPMain.getPublicKeyRing(masterKeyId);
|
|
||||||
if (keyRing == null) {
|
if (keyRing == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -202,9 +202,8 @@ public class PGPHelper {
|
|||||||
return encryptKeys.get(0);
|
return encryptKeys.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PGPSecretKey getSigningKey(long masterKeyId) {
|
public static PGPSecretKey getSigningKey(Context context, long masterKeyId) {
|
||||||
// TODO: externalize getSecretKeyRing from PGPWrapper into a DatabaseHelper
|
PGPSecretKeyRing keyRing = ProviderHelper.getPGPSecretKeyRing(context, masterKeyId);
|
||||||
PGPSecretKeyRing keyRing = PGPMain.getSecretKeyRing(masterKeyId);
|
|
||||||
if (keyRing == null) {
|
if (keyRing == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -385,10 +384,10 @@ public class PGPHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getPubkeyAsArmoredString(Context context, long keyId) {
|
public static String getPubkeyAsArmoredString(Context context, long keyId) {
|
||||||
PGPPublicKey key = PGPMain.getPublicKey(keyId);
|
PGPPublicKey key = ProviderHelper.getPGPPublicKey(context, keyId);
|
||||||
// if it is no public key get it from your own keys...
|
// if it is no public key get it from your own keys...
|
||||||
if (key == null) {
|
if (key == null) {
|
||||||
PGPSecretKey secretKey = PGPMain.getSecretKey(keyId);
|
PGPSecretKey secretKey = ProviderHelper.getPGPSecretKey(context, keyId);
|
||||||
if (secretKey == null) {
|
if (secretKey == null) {
|
||||||
Log.e(Constants.TAG, "Key could not be found!");
|
Log.e(Constants.TAG, "Key could not be found!");
|
||||||
return null;
|
return null;
|
||||||
@ -415,10 +414,11 @@ public class PGPHelper {
|
|||||||
return armouredKey;
|
return armouredKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getFingerPrint(long keyId) {
|
public static String getFingerPrint(Context context, long keyId) {
|
||||||
PGPPublicKey key = PGPMain.getPublicKey(keyId);
|
PGPPublicKey key = ProviderHelper.getPGPPublicKey(context, keyId);
|
||||||
|
// if it is no public key get it from your own keys...
|
||||||
if (key == null) {
|
if (key == null) {
|
||||||
PGPSecretKey secretKey = PGPMain.getSecretKey(keyId);
|
PGPSecretKey secretKey = ProviderHelper.getPGPSecretKey(context, keyId);
|
||||||
if (secretKey == null) {
|
if (secretKey == null) {
|
||||||
Log.e(Constants.TAG, "Key could not be found!");
|
Log.e(Constants.TAG, "Key could not be found!");
|
||||||
return null;
|
return null;
|
||||||
|
@ -72,6 +72,7 @@ import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder;
|
|||||||
import org.spongycastle.openpgp.operator.jcajce.JcePGPDataEncryptorBuilder;
|
import org.spongycastle.openpgp.operator.jcajce.JcePGPDataEncryptorBuilder;
|
||||||
import org.spongycastle.openpgp.operator.jcajce.JcePublicKeyDataDecryptorFactoryBuilder;
|
import org.spongycastle.openpgp.operator.jcajce.JcePublicKeyDataDecryptorFactoryBuilder;
|
||||||
import org.spongycastle.openpgp.operator.jcajce.JcePublicKeyKeyEncryptionMethodGenerator;
|
import org.spongycastle.openpgp.operator.jcajce.JcePublicKeyKeyEncryptionMethodGenerator;
|
||||||
|
import org.thialfihar.android.apg.provider.ProviderHelper;
|
||||||
import org.thialfihar.android.apg.service.ApgService;
|
import org.thialfihar.android.apg.service.ApgService;
|
||||||
import org.thialfihar.android.apg.util.HkpKeyServer;
|
import org.thialfihar.android.apg.util.HkpKeyServer;
|
||||||
import org.thialfihar.android.apg.util.InputData;
|
import org.thialfihar.android.apg.util.InputData;
|
||||||
@ -153,8 +154,6 @@ public class PGPMain {
|
|||||||
// public static final Uri CONTENT_URI_PUBLIC_KEY_RING_BY_EMAILS = Uri.parse("content://"
|
// public static final Uri CONTENT_URI_PUBLIC_KEY_RING_BY_EMAILS = Uri.parse("content://"
|
||||||
// + AUTHORITY + "/key_rings/public/emails/");
|
// + AUTHORITY + "/key_rings/public/emails/");
|
||||||
|
|
||||||
private static String VERSION = null;
|
|
||||||
|
|
||||||
private static final int[] PREFERRED_SYMMETRIC_ALGORITHMS = new int[] {
|
private static final int[] PREFERRED_SYMMETRIC_ALGORITHMS = new int[] {
|
||||||
SymmetricKeyAlgorithmTags.AES_256, SymmetricKeyAlgorithmTags.AES_192,
|
SymmetricKeyAlgorithmTags.AES_256, SymmetricKeyAlgorithmTags.AES_192,
|
||||||
SymmetricKeyAlgorithmTags.AES_128, SymmetricKeyAlgorithmTags.CAST5,
|
SymmetricKeyAlgorithmTags.AES_128, SymmetricKeyAlgorithmTags.CAST5,
|
||||||
@ -521,8 +520,6 @@ public class PGPMain {
|
|||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
status = Id.return_value.error;
|
status = Id.return_value.error;
|
||||||
} catch (ApgGeneralException.GeneralException e) {
|
|
||||||
status = Id.return_value.error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
@ -641,19 +638,21 @@ public class PGPMain {
|
|||||||
int numKeys = 0;
|
int numKeys = 0;
|
||||||
for (int i = 0; i < keyRingIds.size(); ++i) {
|
for (int i = 0; i < keyRingIds.size(); ++i) {
|
||||||
updateProgress(progress, i * 100 / keyRingIds.size(), 100);
|
updateProgress(progress, i * 100 / keyRingIds.size(), 100);
|
||||||
Object obj = mDatabase.getKeyRing(keyRingIds.get(i));
|
|
||||||
PGPPublicKeyRing publicKeyRing;
|
|
||||||
PGPSecretKeyRing secretKeyRing;
|
|
||||||
|
|
||||||
if (obj instanceof PGPSecretKeyRing) {
|
// try to get it as a PGPPublicKeyRing, if that fails try to get it as a SecretKeyRing
|
||||||
secretKeyRing = (PGPSecretKeyRing) obj;
|
PGPPublicKeyRing publicKeyRing = ProviderHelper.getPGPPublicKeyRing(context,
|
||||||
secretKeyRing.encode(out);
|
keyRingIds.get(i));
|
||||||
} else if (obj instanceof PGPPublicKeyRing) {
|
if (publicKeyRing != null) {
|
||||||
publicKeyRing = (PGPPublicKeyRing) obj;
|
|
||||||
publicKeyRing.encode(out);
|
publicKeyRing.encode(out);
|
||||||
|
} else {
|
||||||
|
PGPSecretKeyRing secretKeyRing = ProviderHelper.getPGPSecretKeyRing(context,
|
||||||
|
keyRingIds.get(i));
|
||||||
|
if (secretKeyRing != null) {
|
||||||
|
secretKeyRing.encode(out);
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
++numKeys;
|
++numKeys;
|
||||||
}
|
}
|
||||||
out.close();
|
out.close();
|
||||||
@ -664,90 +663,69 @@ public class PGPMain {
|
|||||||
return returnData;
|
return returnData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void deleteKey(int keyRingId) {
|
// public static PGPKeyRing getKeyRing(int keyRingId) {
|
||||||
mDatabase.deleteKeyRing(keyRingId);
|
// return (PGPKeyRing) mDatabase.getKeyRing(keyRingId);
|
||||||
}
|
// }
|
||||||
|
|
||||||
public static PGPKeyRing getKeyRing(int keyRingId) {
|
// public static PGPSecretKeyRing getSecretKeyRing(long keyId) {
|
||||||
return (PGPKeyRing) mDatabase.getKeyRing(keyRingId);
|
// byte[] data = mDatabase.getKeyRingDataFromKeyId(Id.database.type_secret, keyId);
|
||||||
}
|
// if (data == null) {
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
// return PGPConversionHelper.BytesToPGPSecretKeyRing(data);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public static PGPPublicKeyRing getPublicKeyRing(long keyId) {
|
||||||
|
// byte[] data = mDatabase.getKeyRingDataFromKeyId(Id.database.type_public, keyId);
|
||||||
|
// if (data == null) {
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
// return PGPConversionHelper.BytesToPGPPublicKeyRing(data);
|
||||||
|
// }
|
||||||
|
|
||||||
public static PGPSecretKeyRing getSecretKeyRing(long keyId) {
|
// public static Vector<Integer> getKeyRingIds(int type) {
|
||||||
byte[] data = mDatabase.getKeyRingDataFromKeyId(Id.database.type_secret, keyId);
|
// SQLiteDatabase db = mDatabase.db();
|
||||||
if (data == null) {
|
// Vector<Integer> keyIds = new Vector<Integer>();
|
||||||
return null;
|
// Cursor c = db.query(KeyRings.TABLE_NAME, new String[] { KeyRings._ID }, KeyRings.TYPE
|
||||||
}
|
// + " = ?", new String[] { "" + type }, null, null, null);
|
||||||
return PGPConversionHelper.BytesToPGPSecretKeyRing(data);
|
// if (c != null && c.moveToFirst()) {
|
||||||
}
|
// do {
|
||||||
|
// keyIds.add(c.getInt(0));
|
||||||
|
// } while (c.moveToNext());
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (c != null) {
|
||||||
|
// c.close();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return keyIds;
|
||||||
|
// }
|
||||||
|
|
||||||
public static PGPPublicKeyRing getPublicKeyRing(long keyId) {
|
// public static String getMainUserId(long keyId, int type) {
|
||||||
byte[] data = mDatabase.getKeyRingDataFromKeyId(Id.database.type_public, keyId);
|
// SQLiteDatabase db = mDatabase.db();
|
||||||
if (data == null) {
|
// Cursor c = db.query(Keys.TABLE_NAME + " INNER JOIN " + KeyRings.TABLE_NAME + " ON ("
|
||||||
return null;
|
// + KeyRings.TABLE_NAME + "." + KeyRings._ID + " = " + Keys.TABLE_NAME + "."
|
||||||
}
|
// + Keys.KEY_RING_ID + ") " + " INNER JOIN " + Keys.TABLE_NAME + " AS masterKey ON ("
|
||||||
return PGPConversionHelper.BytesToPGPPublicKeyRing(data);
|
// + KeyRings.TABLE_NAME + "." + KeyRings._ID + " = " + "masterKey."
|
||||||
}
|
// + Keys.KEY_RING_ID + " AND " + "masterKey." + Keys.IS_MASTER_KEY + " = '1') "
|
||||||
|
// + " INNER JOIN " + UserIds.TABLE_NAME + " ON (" + UserIds.TABLE_NAME + "."
|
||||||
public static PGPSecretKey getSecretKey(long keyId) {
|
// + UserIds.KEY_ID + " = " + "masterKey." + Keys._ID + " AND " + UserIds.TABLE_NAME
|
||||||
PGPSecretKeyRing keyRing = getSecretKeyRing(keyId);
|
// + "." + UserIds.RANK + " = '0')", new String[] { UserIds.USER_ID }, Keys.TABLE_NAME
|
||||||
if (keyRing == null) {
|
// + "." + Keys.KEY_ID + " = ? AND " + KeyRings.TABLE_NAME + "." + KeyRings.TYPE
|
||||||
return null;
|
// + " = ?", new String[] { "" + keyId, "" + type, }, null, null, null);
|
||||||
}
|
// String userId = "";
|
||||||
return keyRing.getSecretKey(keyId);
|
// if (c != null && c.moveToFirst()) {
|
||||||
}
|
// do {
|
||||||
|
// userId = c.getString(0);
|
||||||
public static PGPPublicKey getPublicKey(long keyId) {
|
// } while (c.moveToNext());
|
||||||
PGPPublicKeyRing keyRing = getPublicKeyRing(keyId);
|
// }
|
||||||
if (keyRing == null) {
|
//
|
||||||
return null;
|
// if (c != null) {
|
||||||
}
|
// c.close();
|
||||||
|
// }
|
||||||
return keyRing.getPublicKey(keyId);
|
//
|
||||||
}
|
// return userId;
|
||||||
|
// }
|
||||||
public static Vector<Integer> getKeyRingIds(int type) {
|
|
||||||
SQLiteDatabase db = mDatabase.db();
|
|
||||||
Vector<Integer> keyIds = new Vector<Integer>();
|
|
||||||
Cursor c = db.query(KeyRings.TABLE_NAME, new String[] { KeyRings._ID }, KeyRings.TYPE
|
|
||||||
+ " = ?", new String[] { "" + type }, null, null, null);
|
|
||||||
if (c != null && c.moveToFirst()) {
|
|
||||||
do {
|
|
||||||
keyIds.add(c.getInt(0));
|
|
||||||
} while (c.moveToNext());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c != null) {
|
|
||||||
c.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
return keyIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getMainUserId(long keyId, int type) {
|
|
||||||
SQLiteDatabase db = mDatabase.db();
|
|
||||||
Cursor c = db.query(Keys.TABLE_NAME + " INNER JOIN " + KeyRings.TABLE_NAME + " ON ("
|
|
||||||
+ KeyRings.TABLE_NAME + "." + KeyRings._ID + " = " + Keys.TABLE_NAME + "."
|
|
||||||
+ Keys.KEY_RING_ID + ") " + " INNER JOIN " + Keys.TABLE_NAME + " AS masterKey ON ("
|
|
||||||
+ KeyRings.TABLE_NAME + "." + KeyRings._ID + " = " + "masterKey."
|
|
||||||
+ Keys.KEY_RING_ID + " AND " + "masterKey." + Keys.IS_MASTER_KEY + " = '1') "
|
|
||||||
+ " INNER JOIN " + UserIds.TABLE_NAME + " ON (" + UserIds.TABLE_NAME + "."
|
|
||||||
+ UserIds.KEY_ID + " = " + "masterKey." + Keys._ID + " AND " + UserIds.TABLE_NAME
|
|
||||||
+ "." + UserIds.RANK + " = '0')", new String[] { UserIds.USER_ID }, Keys.TABLE_NAME
|
|
||||||
+ "." + Keys.KEY_ID + " = ? AND " + KeyRings.TABLE_NAME + "." + KeyRings.TYPE
|
|
||||||
+ " = ?", new String[] { "" + keyId, "" + type, }, null, null, null);
|
|
||||||
String userId = "";
|
|
||||||
if (c != null && c.moveToFirst()) {
|
|
||||||
do {
|
|
||||||
userId = c.getString(0);
|
|
||||||
} while (c.moveToNext());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c != null) {
|
|
||||||
c.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
return userId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void encrypt(Context context, InputData data, OutputStream outStream,
|
public static void encrypt(Context context, InputData data, OutputStream outStream,
|
||||||
boolean armored, long encryptionKeyIds[], long signatureKeyId,
|
boolean armored, long encryptionKeyIds[], long signatureKeyId,
|
||||||
@ -780,8 +758,8 @@ public class PGPMain {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (signatureKeyId != Id.key.none) {
|
if (signatureKeyId != Id.key.none) {
|
||||||
signingKeyRing = getSecretKeyRing(signatureKeyId);
|
signingKeyRing = ProviderHelper.getPGPSecretKeyRing(context, signatureKeyId);
|
||||||
signingKey = PGPHelper.getSigningKey(signatureKeyId);
|
signingKey = PGPHelper.getSigningKey(context, signatureKeyId);
|
||||||
if (signingKey == null) {
|
if (signingKey == null) {
|
||||||
throw new ApgGeneralException(context.getString(R.string.error_signatureFailed));
|
throw new ApgGeneralException(context.getString(R.string.error_signatureFailed));
|
||||||
}
|
}
|
||||||
@ -818,7 +796,7 @@ public class PGPMain {
|
|||||||
cPk.addMethod(symmetricEncryptionGenerator);
|
cPk.addMethod(symmetricEncryptionGenerator);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < encryptionKeyIds.length; ++i) {
|
for (int i = 0; i < encryptionKeyIds.length; ++i) {
|
||||||
PGPPublicKey key = PGPHelper.getEncryptPublicKey(encryptionKeyIds[i]);
|
PGPPublicKey key = PGPHelper.getEncryptPublicKey(context, encryptionKeyIds[i]);
|
||||||
if (key != null) {
|
if (key != null) {
|
||||||
|
|
||||||
JcePublicKeyKeyEncryptionMethodGenerator pubKeyEncryptionGenerator = new JcePublicKeyKeyEncryptionMethodGenerator(
|
JcePublicKeyKeyEncryptionMethodGenerator pubKeyEncryptionGenerator = new JcePublicKeyKeyEncryptionMethodGenerator(
|
||||||
@ -933,8 +911,8 @@ public class PGPMain {
|
|||||||
throw new ApgGeneralException(context.getString(R.string.error_noSignatureKey));
|
throw new ApgGeneralException(context.getString(R.string.error_noSignatureKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
signingKeyRing = getSecretKeyRing(signatureKeyId);
|
signingKeyRing = ProviderHelper.getPGPSecretKeyRing(context, signatureKeyId);
|
||||||
signingKey = PGPHelper.getSigningKey(signatureKeyId);
|
signingKey = PGPHelper.getSigningKey(context, signatureKeyId);
|
||||||
if (signingKey == null) {
|
if (signingKey == null) {
|
||||||
armorOut.close();
|
armorOut.close();
|
||||||
throw new ApgGeneralException(context.getString(R.string.error_signatureFailed));
|
throw new ApgGeneralException(context.getString(R.string.error_signatureFailed));
|
||||||
@ -1049,8 +1027,8 @@ public class PGPMain {
|
|||||||
throw new ApgGeneralException(context.getString(R.string.error_noSignatureKey));
|
throw new ApgGeneralException(context.getString(R.string.error_noSignatureKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
signingKeyRing = getSecretKeyRing(signatureKeyId);
|
signingKeyRing = ProviderHelper.getPGPSecretKeyRing(context, signatureKeyId);
|
||||||
signingKey = PGPHelper.getSigningKey(signatureKeyId);
|
signingKey = PGPHelper.getSigningKey(context, signatureKeyId);
|
||||||
if (signingKey == null) {
|
if (signingKey == null) {
|
||||||
throw new ApgGeneralException(context.getString(R.string.error_signatureFailed));
|
throw new ApgGeneralException(context.getString(R.string.error_signatureFailed));
|
||||||
}
|
}
|
||||||
@ -1149,9 +1127,9 @@ public class PGPMain {
|
|||||||
if (passphrase == null || passphrase.length() <= 0) {
|
if (passphrase == null || passphrase.length() <= 0) {
|
||||||
throw new ApgGeneralException("Unable to obtain passphrase");
|
throw new ApgGeneralException("Unable to obtain passphrase");
|
||||||
} else {
|
} else {
|
||||||
PGPPublicKeyRing pubring = PGPMain.getPublicKeyRing(pubKeyId);
|
PGPPublicKeyRing pubring = ProviderHelper.getPGPPublicKeyRing(context, pubKeyId);
|
||||||
|
|
||||||
PGPSecretKey signingKey = PGPHelper.getSigningKey(masterKeyId);
|
PGPSecretKey signingKey = PGPHelper.getSigningKey(context, masterKeyId);
|
||||||
if (signingKey == null) {
|
if (signingKey == null) {
|
||||||
throw new ApgGeneralException(context.getString(R.string.error_signatureFailed));
|
throw new ApgGeneralException(context.getString(R.string.error_signatureFailed));
|
||||||
}
|
}
|
||||||
@ -1215,7 +1193,7 @@ public class PGPMain {
|
|||||||
if (obj instanceof PGPPublicKeyEncryptedData) {
|
if (obj instanceof PGPPublicKeyEncryptedData) {
|
||||||
gotAsymmetricEncryption = true;
|
gotAsymmetricEncryption = true;
|
||||||
PGPPublicKeyEncryptedData pbe = (PGPPublicKeyEncryptedData) obj;
|
PGPPublicKeyEncryptedData pbe = (PGPPublicKeyEncryptedData) obj;
|
||||||
secretKey = getSecretKey(pbe.getKeyID());
|
secretKey = ProviderHelper.getPGPSecretKey(context, pbe.getKeyID());
|
||||||
if (secretKey != null) {
|
if (secretKey != null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1336,7 +1314,7 @@ public class PGPMain {
|
|||||||
Object obj = it.next();
|
Object obj = it.next();
|
||||||
if (obj instanceof PGPPublicKeyEncryptedData) {
|
if (obj instanceof PGPPublicKeyEncryptedData) {
|
||||||
PGPPublicKeyEncryptedData encData = (PGPPublicKeyEncryptedData) obj;
|
PGPPublicKeyEncryptedData encData = (PGPPublicKeyEncryptedData) obj;
|
||||||
secretKey = getSecretKey(encData.getKeyID());
|
secretKey = ProviderHelper.getPGPSecretKey(context, encData.getKeyID());
|
||||||
if (secretKey != null) {
|
if (secretKey != null) {
|
||||||
pbe = encData;
|
pbe = encData;
|
||||||
break;
|
break;
|
||||||
@ -1397,7 +1375,7 @@ public class PGPMain {
|
|||||||
PGPOnePassSignatureList sigList = (PGPOnePassSignatureList) dataChunk;
|
PGPOnePassSignatureList sigList = (PGPOnePassSignatureList) dataChunk;
|
||||||
for (int i = 0; i < sigList.size(); ++i) {
|
for (int i = 0; i < sigList.size(); ++i) {
|
||||||
signature = sigList.get(i);
|
signature = sigList.get(i);
|
||||||
signatureKey = getPublicKey(signature.getKeyID());
|
signatureKey = ProviderHelper.getPGPPublicKey(context, signature.getKeyID());
|
||||||
if (signatureKeyId == 0) {
|
if (signatureKeyId == 0) {
|
||||||
signatureKeyId = signature.getKeyID();
|
signatureKeyId = signature.getKeyID();
|
||||||
}
|
}
|
||||||
@ -1407,7 +1385,8 @@ public class PGPMain {
|
|||||||
signatureIndex = i;
|
signatureIndex = i;
|
||||||
signatureKeyId = signature.getKeyID();
|
signatureKeyId = signature.getKeyID();
|
||||||
String userId = null;
|
String userId = null;
|
||||||
PGPPublicKeyRing sigKeyRing = getPublicKeyRing(signatureKeyId);
|
PGPPublicKeyRing sigKeyRing = ProviderHelper.getPGPPublicKeyRing(context,
|
||||||
|
signatureKeyId);
|
||||||
if (sigKeyRing != null) {
|
if (sigKeyRing != null) {
|
||||||
userId = PGPHelper.getMainUserId(PGPHelper.getMasterKey(sigKeyRing));
|
userId = PGPHelper.getMainUserId(PGPHelper.getMasterKey(sigKeyRing));
|
||||||
}
|
}
|
||||||
@ -1552,7 +1531,7 @@ public class PGPMain {
|
|||||||
PGPPublicKey signatureKey = null;
|
PGPPublicKey signatureKey = null;
|
||||||
for (int i = 0; i < sigList.size(); ++i) {
|
for (int i = 0; i < sigList.size(); ++i) {
|
||||||
signature = sigList.get(i);
|
signature = sigList.get(i);
|
||||||
signatureKey = getPublicKey(signature.getKeyID());
|
signatureKey = ProviderHelper.getPGPPublicKey(context, signature.getKeyID());
|
||||||
if (signatureKeyId == 0) {
|
if (signatureKeyId == 0) {
|
||||||
signatureKeyId = signature.getKeyID();
|
signatureKeyId = signature.getKeyID();
|
||||||
}
|
}
|
||||||
@ -1572,7 +1551,8 @@ public class PGPMain {
|
|||||||
} else {
|
} else {
|
||||||
signatureKeyId = signature.getKeyID();
|
signatureKeyId = signature.getKeyID();
|
||||||
String userId = null;
|
String userId = null;
|
||||||
PGPPublicKeyRing sigKeyRing = getPublicKeyRing(signatureKeyId);
|
PGPPublicKeyRing sigKeyRing = ProviderHelper.getPGPPublicKeyRing(context,
|
||||||
|
signatureKeyId);
|
||||||
if (sigKeyRing != null) {
|
if (sigKeyRing != null) {
|
||||||
userId = PGPHelper.getMainUserId(PGPHelper.getMasterKey(sigKeyRing));
|
userId = PGPHelper.getMainUserId(PGPHelper.getMasterKey(sigKeyRing));
|
||||||
}
|
}
|
||||||
@ -1799,15 +1779,13 @@ public class PGPMain {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getVersion(Context context) {
|
public static String getVersion(Context context) {
|
||||||
if (VERSION != null) {
|
String version = null;
|
||||||
return VERSION;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
PackageInfo pi = context.getPackageManager().getPackageInfo(Constants.PACKAGE_NAME, 0);
|
PackageInfo pi = context.getPackageManager().getPackageInfo(Constants.PACKAGE_NAME, 0);
|
||||||
VERSION = pi.versionName;
|
version = pi.versionName;
|
||||||
return VERSION;
|
return version;
|
||||||
} catch (NameNotFoundException e) {
|
} catch (NameNotFoundException e) {
|
||||||
// impossible!
|
Log.e(Constants.TAG, "Version could not be retrieved!", e);
|
||||||
return "0.0.0";
|
return "0.0.0";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
package org.thialfihar.android.apg.provider;
|
package org.thialfihar.android.apg.provider;
|
||||||
|
|
||||||
|
import org.thialfihar.android.apg.Constants;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.provider.BaseColumns;
|
import android.provider.BaseColumns;
|
||||||
|
|
||||||
@ -32,10 +34,12 @@ import android.provider.BaseColumns;
|
|||||||
*/
|
*/
|
||||||
public class ApgContract {
|
public class ApgContract {
|
||||||
|
|
||||||
|
// APG1: all rows had a "c_" prefix
|
||||||
|
|
||||||
interface KeyRingsColumns {
|
interface KeyRingsColumns {
|
||||||
String MASTER_KEY_ID = "master_key_id"; // TODO: clarify
|
String MASTER_KEY_ROW_ID = "master_key_id"; // TODO: clarify
|
||||||
String TYPE = "type"; // see KeyTypes
|
String TYPE = "type"; // see KeyTypes
|
||||||
String WHO_ID = "who_id";
|
String WHO_ID = "who_id"; // TODO: is this used?
|
||||||
String KEY_RING_DATA = "key_ring_data"; // blob
|
String KEY_RING_DATA = "key_ring_data"; // blob
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,8 +55,8 @@ public class ApgContract {
|
|||||||
String CREATION = "creation";
|
String CREATION = "creation";
|
||||||
String EXPIRY = "expiry";
|
String EXPIRY = "expiry";
|
||||||
String KEY_RING_ROW_ID = "key_ring_id"; // foreign key to key_rings._ID
|
String KEY_RING_ROW_ID = "key_ring_id"; // foreign key to key_rings._ID
|
||||||
String KEY_DATA = "key_data";
|
String KEY_DATA = "key_data"; // blob
|
||||||
String RANK = "key_data"; // blob
|
String RANK = "rank"; // APG1: this was "key_data", TODO: Bug? Is this even used?
|
||||||
}
|
}
|
||||||
|
|
||||||
interface UserIdsColumns {
|
interface UserIdsColumns {
|
||||||
@ -66,8 +70,8 @@ public class ApgContract {
|
|||||||
public static final int SECRET = 1;
|
public static final int SECRET = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String CONTENT_AUTHORITY = "org.thialfihar.android.apg.provider";
|
// APG1: "org.thialfihar.android.apg.provider";
|
||||||
// public static final String CONTENT_AUTHORITY = Constants.PACKAGE_NAME;
|
public static final String CONTENT_AUTHORITY = Constants.PACKAGE_NAME;
|
||||||
|
|
||||||
private static final Uri BASE_CONTENT_URI = Uri.parse("content://" + CONTENT_AUTHORITY);
|
private static final Uri BASE_CONTENT_URI = Uri.parse("content://" + CONTENT_AUTHORITY);
|
||||||
|
|
||||||
|
@ -30,18 +30,20 @@ import android.provider.BaseColumns;
|
|||||||
import org.thialfihar.android.apg.util.Log;
|
import org.thialfihar.android.apg.util.Log;
|
||||||
|
|
||||||
public class ApgDatabase extends SQLiteOpenHelper {
|
public class ApgDatabase extends SQLiteOpenHelper {
|
||||||
|
// APG1: "apg"
|
||||||
private static final String DATABASE_NAME = "apg.db";
|
private static final String DATABASE_NAME = "apg.db";
|
||||||
// Last APG 1 db version was 2
|
// APG1: 2
|
||||||
private static final int DATABASE_VERSION = 3;
|
private static final int DATABASE_VERSION = 3;
|
||||||
|
|
||||||
public interface Tables {
|
public interface Tables {
|
||||||
String KEY_RINGS = "key_rings";
|
String KEY_RINGS = "key_rings";
|
||||||
String KEYS = "keys";
|
String KEYS = "keys";
|
||||||
String USER_IDS = "user_ids";
|
String USERS = "user_ids";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// APG1: REFERENCES where not implemented
|
||||||
private static final String CREATE_KEY_RINGS = "CREATE TABLE IF NOT EXISTS " + Tables.KEY_RINGS
|
private static final String CREATE_KEY_RINGS = "CREATE TABLE IF NOT EXISTS " + Tables.KEY_RINGS
|
||||||
+ " (" + BaseColumns._ID + " INTEGER PRIMARY KEY, " + KeyRingsColumns.MASTER_KEY_ID
|
+ " (" + BaseColumns._ID + " INTEGER PRIMARY KEY, " + KeyRingsColumns.MASTER_KEY_ROW_ID
|
||||||
+ " INT64, " + KeyRingsColumns.TYPE + " INTEGER, " + KeyRingsColumns.WHO_ID
|
+ " INT64, " + KeyRingsColumns.TYPE + " INTEGER, " + KeyRingsColumns.WHO_ID
|
||||||
+ " INTEGER, " + KeyRingsColumns.KEY_RING_DATA + " BLOB)";
|
+ " INTEGER, " + KeyRingsColumns.KEY_RING_DATA + " BLOB)";
|
||||||
|
|
||||||
@ -55,7 +57,7 @@ public class ApgDatabase extends SQLiteOpenHelper {
|
|||||||
+ " INTEGER REFERENCES " + Tables.KEY_RINGS + " ON DELETE CASCADE, "
|
+ " INTEGER REFERENCES " + Tables.KEY_RINGS + " ON DELETE CASCADE, "
|
||||||
+ KeysColumns.KEY_DATA + " BLOB," + KeysColumns.RANK + " INTEGER)";
|
+ KeysColumns.KEY_DATA + " BLOB," + KeysColumns.RANK + " INTEGER)";
|
||||||
|
|
||||||
private static final String CREATE_USER_IDS = "CREATE TABLE IF NOT EXISTS " + Tables.USER_IDS
|
private static final String CREATE_USER_IDS = "CREATE TABLE IF NOT EXISTS " + Tables.USERS
|
||||||
+ " (" + BaseColumns._ID + " INTEGER PRIMARY KEY, " + UserIdsColumns.KEY_ROW_ID
|
+ " (" + BaseColumns._ID + " INTEGER PRIMARY KEY, " + UserIdsColumns.KEY_ROW_ID
|
||||||
+ " INTEGER REFERENCES " + Tables.KEYS + " ON DELETE CASCADE, "
|
+ " INTEGER REFERENCES " + Tables.KEYS + " ON DELETE CASCADE, "
|
||||||
+ UserIdsColumns.USER_ID + " TEXT, " + UserIdsColumns.RANK + " INTEGER)";
|
+ UserIdsColumns.USER_ID + " TEXT, " + UserIdsColumns.RANK + " INTEGER)";
|
||||||
@ -129,9 +131,6 @@ public class ApgDatabase extends SQLiteOpenHelper {
|
|||||||
Log.w(Constants.TAG, "Upgrading database to version " + version);
|
Log.w(Constants.TAG, "Upgrading database to version " + version);
|
||||||
|
|
||||||
switch (version) {
|
switch (version) {
|
||||||
case 1:
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -54,8 +54,8 @@ public class ApgProvider extends ContentProvider {
|
|||||||
private static final UriMatcher sUriMatcher = buildUriMatcher();
|
private static final UriMatcher sUriMatcher = buildUriMatcher();
|
||||||
|
|
||||||
private static final int PUBLIC_KEY_RING = 101;
|
private static final int PUBLIC_KEY_RING = 101;
|
||||||
private static final int PUBLIC_KEY_RING_ID = 102;
|
private static final int PUBLIC_KEY_RING_ROW_ID = 102;
|
||||||
private static final int PUBLIC_KEY_RING_BY_KEY_ID = 103;
|
private static final int PUBLIC_KEY_RING_BY_KEY_ID = 103; // TODO: Is this row id???
|
||||||
private static final int PUBLIC_KEY_RING_BY_EMAILS = 104;
|
private static final int PUBLIC_KEY_RING_BY_EMAILS = 104;
|
||||||
private static final int PUBLIC_KEY_RING_KEY = 111;
|
private static final int PUBLIC_KEY_RING_KEY = 111;
|
||||||
private static final int PUBLIC_KEY_RING_KEY_RANK = 112;
|
private static final int PUBLIC_KEY_RING_KEY_RANK = 112;
|
||||||
@ -63,7 +63,7 @@ public class ApgProvider extends ContentProvider {
|
|||||||
private static final int PUBLIC_KEY_RING_USER_ID_RANK = 122;
|
private static final int PUBLIC_KEY_RING_USER_ID_RANK = 122;
|
||||||
|
|
||||||
private static final int SECRET_KEY_RING = 201;
|
private static final int SECRET_KEY_RING = 201;
|
||||||
private static final int SECRET_KEY_RING_ID = 202;
|
private static final int SECRET_KEY_RING_ROW_ID = 202;
|
||||||
private static final int SECRET_KEY_RING_BY_KEY_ID = 203;
|
private static final int SECRET_KEY_RING_BY_KEY_ID = 203;
|
||||||
private static final int SECRET_KEY_RING_BY_EMAILS = 204;
|
private static final int SECRET_KEY_RING_BY_EMAILS = 204;
|
||||||
private static final int SECRET_KEY_RING_KEY = 211;
|
private static final int SECRET_KEY_RING_KEY = 211;
|
||||||
@ -95,7 +95,7 @@ public class ApgProvider extends ContentProvider {
|
|||||||
PUBLIC_KEY_RING);
|
PUBLIC_KEY_RING);
|
||||||
matcher.addURI(authority,
|
matcher.addURI(authority,
|
||||||
ApgContract.BASE_KEY_RINGS + "/" + ApgContract.PATH_PUBLIC + "/*",
|
ApgContract.BASE_KEY_RINGS + "/" + ApgContract.PATH_PUBLIC + "/*",
|
||||||
PUBLIC_KEY_RING_ID);
|
PUBLIC_KEY_RING_ROW_ID);
|
||||||
matcher.addURI(authority, ApgContract.BASE_KEY_RINGS + "/" + ApgContract.PATH_PUBLIC + "/"
|
matcher.addURI(authority, ApgContract.BASE_KEY_RINGS + "/" + ApgContract.PATH_PUBLIC + "/"
|
||||||
+ ApgContract.PATH_BY_KEY_ID + "/*", PUBLIC_KEY_RING_BY_KEY_ID);
|
+ ApgContract.PATH_BY_KEY_ID + "/*", PUBLIC_KEY_RING_BY_KEY_ID);
|
||||||
matcher.addURI(authority, ApgContract.BASE_KEY_RINGS + "/" + ApgContract.PATH_PUBLIC + "/"
|
matcher.addURI(authority, ApgContract.BASE_KEY_RINGS + "/" + ApgContract.PATH_PUBLIC + "/"
|
||||||
@ -143,7 +143,7 @@ public class ApgProvider extends ContentProvider {
|
|||||||
SECRET_KEY_RING);
|
SECRET_KEY_RING);
|
||||||
matcher.addURI(authority,
|
matcher.addURI(authority,
|
||||||
ApgContract.BASE_KEY_RINGS + "/" + ApgContract.PATH_SECRET + "/*",
|
ApgContract.BASE_KEY_RINGS + "/" + ApgContract.PATH_SECRET + "/*",
|
||||||
SECRET_KEY_RING_ID);
|
SECRET_KEY_RING_ROW_ID);
|
||||||
matcher.addURI(authority, ApgContract.BASE_KEY_RINGS + "/" + ApgContract.PATH_SECRET + "/"
|
matcher.addURI(authority, ApgContract.BASE_KEY_RINGS + "/" + ApgContract.PATH_SECRET + "/"
|
||||||
+ ApgContract.PATH_BY_KEY_ID + "/*", SECRET_KEY_RING_BY_KEY_ID);
|
+ ApgContract.PATH_BY_KEY_ID + "/*", SECRET_KEY_RING_BY_KEY_ID);
|
||||||
matcher.addURI(authority, ApgContract.BASE_KEY_RINGS + "/" + ApgContract.PATH_SECRET + "/"
|
matcher.addURI(authority, ApgContract.BASE_KEY_RINGS + "/" + ApgContract.PATH_SECRET + "/"
|
||||||
@ -208,7 +208,7 @@ public class ApgProvider extends ContentProvider {
|
|||||||
case PUBLIC_KEY_RING_BY_EMAILS:
|
case PUBLIC_KEY_RING_BY_EMAILS:
|
||||||
return PublicKeyRings.CONTENT_TYPE;
|
return PublicKeyRings.CONTENT_TYPE;
|
||||||
|
|
||||||
case PUBLIC_KEY_RING_ID:
|
case PUBLIC_KEY_RING_ROW_ID:
|
||||||
case PUBLIC_KEY_RING_BY_KEY_ID:
|
case PUBLIC_KEY_RING_BY_KEY_ID:
|
||||||
return PublicKeyRings.CONTENT_ITEM_TYPE;
|
return PublicKeyRings.CONTENT_ITEM_TYPE;
|
||||||
|
|
||||||
@ -228,7 +228,7 @@ public class ApgProvider extends ContentProvider {
|
|||||||
case SECRET_KEY_RING_BY_EMAILS:
|
case SECRET_KEY_RING_BY_EMAILS:
|
||||||
return SecretKeyRings.CONTENT_TYPE;
|
return SecretKeyRings.CONTENT_TYPE;
|
||||||
|
|
||||||
case SECRET_KEY_RING_ID:
|
case SECRET_KEY_RING_ROW_ID:
|
||||||
case SECRET_KEY_RING_BY_KEY_ID:
|
case SECRET_KEY_RING_BY_KEY_ID:
|
||||||
return SecretKeyRings.CONTENT_ITEM_TYPE;
|
return SecretKeyRings.CONTENT_ITEM_TYPE;
|
||||||
|
|
||||||
@ -259,7 +259,7 @@ public class ApgProvider extends ContentProvider {
|
|||||||
int type;
|
int type;
|
||||||
switch (match) {
|
switch (match) {
|
||||||
case PUBLIC_KEY_RING:
|
case PUBLIC_KEY_RING:
|
||||||
case PUBLIC_KEY_RING_ID:
|
case PUBLIC_KEY_RING_ROW_ID:
|
||||||
case PUBLIC_KEY_RING_BY_KEY_ID:
|
case PUBLIC_KEY_RING_BY_KEY_ID:
|
||||||
case PUBLIC_KEY_RING_BY_EMAILS:
|
case PUBLIC_KEY_RING_BY_EMAILS:
|
||||||
case PUBLIC_KEY_RING_KEY:
|
case PUBLIC_KEY_RING_KEY:
|
||||||
@ -270,7 +270,7 @@ public class ApgProvider extends ContentProvider {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case SECRET_KEY_RING:
|
case SECRET_KEY_RING:
|
||||||
case SECRET_KEY_RING_ID:
|
case SECRET_KEY_RING_ROW_ID:
|
||||||
case SECRET_KEY_RING_BY_KEY_ID:
|
case SECRET_KEY_RING_BY_KEY_ID:
|
||||||
case SECRET_KEY_RING_BY_EMAILS:
|
case SECRET_KEY_RING_BY_EMAILS:
|
||||||
case SECRET_KEY_RING_KEY:
|
case SECRET_KEY_RING_KEY:
|
||||||
@ -304,9 +304,10 @@ public class ApgProvider extends ContentProvider {
|
|||||||
qb.appendWhere(Tables.KEY_RINGS + "." + KeyRingsColumns.TYPE + " = " + getKeyType(match));
|
qb.appendWhere(Tables.KEY_RINGS + "." + KeyRingsColumns.TYPE + " = " + getKeyType(match));
|
||||||
|
|
||||||
switch (match) {
|
switch (match) {
|
||||||
case PUBLIC_KEY_RING_ID:
|
case PUBLIC_KEY_RING_ROW_ID:
|
||||||
case SECRET_KEY_RING_ID:
|
case SECRET_KEY_RING_ROW_ID:
|
||||||
qb.appendWhere(" AND " + Tables.KEY_RINGS + "." + KeyRingsColumns.MASTER_KEY_ID + " = ");
|
qb.appendWhere(" AND " + Tables.KEY_RINGS + "." + KeyRingsColumns.MASTER_KEY_ROW_ID
|
||||||
|
+ " = ");
|
||||||
qb.appendWhereEscapeString(uri.getPathSegments().get(2));
|
qb.appendWhereEscapeString(uri.getPathSegments().get(2));
|
||||||
|
|
||||||
// break omitted intentionally
|
// break omitted intentionally
|
||||||
@ -315,20 +316,19 @@ public class ApgProvider extends ContentProvider {
|
|||||||
case SECRET_KEY_RING:
|
case SECRET_KEY_RING:
|
||||||
qb.setTables(Tables.KEY_RINGS + " INNER JOIN " + Tables.KEYS + " ON " + "("
|
qb.setTables(Tables.KEY_RINGS + " INNER JOIN " + Tables.KEYS + " ON " + "("
|
||||||
+ Tables.KEY_RINGS + "." + BaseColumns._ID + " = " + Tables.KEYS + "."
|
+ Tables.KEY_RINGS + "." + BaseColumns._ID + " = " + Tables.KEYS + "."
|
||||||
+ KeysColumns.KEY_RING_ID + " AND " + Tables.KEYS + "."
|
+ KeysColumns.KEY_RING_ROW_ID + " AND " + Tables.KEYS + "."
|
||||||
+ KeysColumns.IS_MASTER_KEY + " = '1'" + ") " + " INNER JOIN "
|
+ KeysColumns.IS_MASTER_KEY + " = '1'" + ") " + " INNER JOIN " + Tables.USERS
|
||||||
+ Tables.USER_IDS + " ON " + "(" + Tables.KEYS + "." + BaseColumns._ID + " = "
|
+ " ON " + "(" + Tables.KEYS + "." + BaseColumns._ID + " = " + Tables.USERS
|
||||||
+ Tables.USER_IDS + "." + UserIdsColumns.KEY_ID + " AND " + Tables.USER_IDS
|
+ "." + UserIdsColumns.KEY_ROW_ID + " AND " + Tables.USERS + "."
|
||||||
+ "." + UserIdsColumns.RANK + " = '0') ");
|
+ UserIdsColumns.RANK + " = '0') ");
|
||||||
|
|
||||||
projectionMap.put(BaseColumns._ID, Tables.KEY_RINGS + "." + BaseColumns._ID);
|
projectionMap.put(BaseColumns._ID, Tables.KEY_RINGS + "." + BaseColumns._ID);
|
||||||
projectionMap.put(KeyRingsColumns.MASTER_KEY_ID, Tables.KEY_RINGS + "."
|
projectionMap.put(KeyRingsColumns.MASTER_KEY_ROW_ID, Tables.KEY_RINGS + "."
|
||||||
+ KeyRingsColumns.MASTER_KEY_ID);
|
+ KeyRingsColumns.MASTER_KEY_ROW_ID);
|
||||||
projectionMap.put(UserIdsColumns.USER_ID, Tables.USER_IDS + "."
|
projectionMap.put(UserIdsColumns.USER_ID, Tables.USERS + "." + UserIdsColumns.USER_ID);
|
||||||
+ UserIdsColumns.USER_ID);
|
|
||||||
|
|
||||||
if (TextUtils.isEmpty(sortOrder)) {
|
if (TextUtils.isEmpty(sortOrder)) {
|
||||||
sortOrder = Tables.USER_IDS + "." + UserIdsColumns.USER_ID + " ASC";
|
sortOrder = Tables.USERS + "." + UserIdsColumns.USER_ID + " ASC";
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -337,19 +337,18 @@ public class ApgProvider extends ContentProvider {
|
|||||||
case PUBLIC_KEY_RING_BY_KEY_ID:
|
case PUBLIC_KEY_RING_BY_KEY_ID:
|
||||||
qb.setTables(Tables.KEYS + " AS tmp INNER JOIN " + Tables.KEY_RINGS + " ON ("
|
qb.setTables(Tables.KEYS + " AS tmp INNER JOIN " + Tables.KEY_RINGS + " ON ("
|
||||||
+ Tables.KEY_RINGS + "." + BaseColumns._ID + " = " + "tmp."
|
+ Tables.KEY_RINGS + "." + BaseColumns._ID + " = " + "tmp."
|
||||||
+ KeysColumns.KEY_RING_ID + ")" + " INNER JOIN " + Tables.KEYS + " ON " + "("
|
+ KeysColumns.KEY_RING_ROW_ID + ")" + " INNER JOIN " + Tables.KEYS + " ON "
|
||||||
+ Tables.KEY_RINGS + "." + BaseColumns._ID + " = " + Tables.KEYS + "."
|
+ "(" + Tables.KEY_RINGS + "." + BaseColumns._ID + " = " + Tables.KEYS + "."
|
||||||
+ KeysColumns.KEY_RING_ID + " AND " + Tables.KEYS + "."
|
+ KeysColumns.KEY_RING_ROW_ID + " AND " + Tables.KEYS + "."
|
||||||
+ KeysColumns.IS_MASTER_KEY + " = '1'" + ") " + " INNER JOIN "
|
+ KeysColumns.IS_MASTER_KEY + " = '1'" + ") " + " INNER JOIN " + Tables.USERS
|
||||||
+ Tables.USER_IDS + " ON " + "(" + Tables.KEYS + "." + BaseColumns._ID + " = "
|
+ " ON " + "(" + Tables.KEYS + "." + BaseColumns._ID + " = " + Tables.USERS
|
||||||
+ Tables.USER_IDS + "." + UserIdsColumns.KEY_ID + " AND " + Tables.USER_IDS
|
+ "." + UserIdsColumns.KEY_ROW_ID + " AND " + Tables.USERS + "."
|
||||||
+ "." + UserIdsColumns.RANK + " = '0') ");
|
+ UserIdsColumns.RANK + " = '0') ");
|
||||||
|
|
||||||
projectionMap.put(BaseColumns._ID, Tables.KEY_RINGS + "." + BaseColumns._ID);
|
projectionMap.put(BaseColumns._ID, Tables.KEY_RINGS + "." + BaseColumns._ID);
|
||||||
projectionMap.put(KeyRingsColumns.MASTER_KEY_ID, Tables.KEY_RINGS + "."
|
projectionMap.put(KeyRingsColumns.MASTER_KEY_ROW_ID, Tables.KEY_RINGS + "."
|
||||||
+ KeyRingsColumns.MASTER_KEY_ID);
|
+ KeyRingsColumns.MASTER_KEY_ROW_ID);
|
||||||
projectionMap.put(UserIdsColumns.USER_ID, Tables.USER_IDS + "."
|
projectionMap.put(UserIdsColumns.USER_ID, Tables.USERS + "." + UserIdsColumns.USER_ID);
|
||||||
+ UserIdsColumns.USER_ID);
|
|
||||||
|
|
||||||
qb.appendWhere(" AND tmp." + KeysColumns.KEY_ID + " = ");
|
qb.appendWhere(" AND tmp." + KeysColumns.KEY_ID + " = ");
|
||||||
qb.appendWhereEscapeString(uri.getPathSegments().get(3));
|
qb.appendWhereEscapeString(uri.getPathSegments().get(3));
|
||||||
@ -360,17 +359,16 @@ public class ApgProvider extends ContentProvider {
|
|||||||
case PUBLIC_KEY_RING_BY_EMAILS:
|
case PUBLIC_KEY_RING_BY_EMAILS:
|
||||||
qb.setTables(Tables.KEY_RINGS + " INNER JOIN " + Tables.KEYS + " ON " + "("
|
qb.setTables(Tables.KEY_RINGS + " INNER JOIN " + Tables.KEYS + " ON " + "("
|
||||||
+ Tables.KEY_RINGS + "." + BaseColumns._ID + " = " + Tables.KEYS + "."
|
+ Tables.KEY_RINGS + "." + BaseColumns._ID + " = " + Tables.KEYS + "."
|
||||||
+ KeysColumns.KEY_RING_ID + " AND " + Tables.KEYS + "."
|
+ KeysColumns.KEY_RING_ROW_ID + " AND " + Tables.KEYS + "."
|
||||||
+ KeysColumns.IS_MASTER_KEY + " = '1'" + ") " + " INNER JOIN "
|
+ KeysColumns.IS_MASTER_KEY + " = '1'" + ") " + " INNER JOIN " + Tables.USERS
|
||||||
+ Tables.USER_IDS + " ON " + "(" + Tables.KEYS + "." + BaseColumns._ID + " = "
|
+ " ON " + "(" + Tables.KEYS + "." + BaseColumns._ID + " = " + Tables.USERS
|
||||||
+ Tables.USER_IDS + "." + UserIdsColumns.KEY_ID + " AND " + Tables.USER_IDS
|
+ "." + UserIdsColumns.KEY_ROW_ID + " AND " + Tables.USERS + "."
|
||||||
+ "." + UserIdsColumns.RANK + " = '0') ");
|
+ UserIdsColumns.RANK + " = '0') ");
|
||||||
|
|
||||||
projectionMap.put(BaseColumns._ID, Tables.KEY_RINGS + "." + BaseColumns._ID);
|
projectionMap.put(BaseColumns._ID, Tables.KEY_RINGS + "." + BaseColumns._ID);
|
||||||
projectionMap.put(KeyRingsColumns.MASTER_KEY_ID, Tables.KEY_RINGS + "."
|
projectionMap.put(KeyRingsColumns.MASTER_KEY_ROW_ID, Tables.KEY_RINGS + "."
|
||||||
+ KeyRingsColumns.MASTER_KEY_ID);
|
+ KeyRingsColumns.MASTER_KEY_ROW_ID);
|
||||||
projectionMap.put(UserIdsColumns.USER_ID, Tables.USER_IDS + "."
|
projectionMap.put(UserIdsColumns.USER_ID, Tables.USERS + "." + UserIdsColumns.USER_ID);
|
||||||
+ UserIdsColumns.USER_ID);
|
|
||||||
|
|
||||||
String emails = uri.getPathSegments().get(3);
|
String emails = uri.getPathSegments().get(3);
|
||||||
String chunks[] = emails.split(" *, *");
|
String chunks[] = emails.split(" *, *");
|
||||||
@ -391,7 +389,7 @@ public class ApgProvider extends ContentProvider {
|
|||||||
|
|
||||||
if (gotCondition) {
|
if (gotCondition) {
|
||||||
qb.appendWhere(" AND EXISTS (SELECT tmp." + BaseColumns._ID + " FROM "
|
qb.appendWhere(" AND EXISTS (SELECT tmp." + BaseColumns._ID + " FROM "
|
||||||
+ Tables.USER_IDS + " AS tmp WHERE tmp." + UserIdsColumns.KEY_ID + " = "
|
+ Tables.USERS + " AS tmp WHERE tmp." + UserIdsColumns.KEY_ROW_ID + " = "
|
||||||
+ Tables.KEYS + "." + BaseColumns._ID + " AND (" + emailWhere + "))");
|
+ Tables.KEYS + "." + BaseColumns._ID + " AND (" + emailWhere + "))");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -450,7 +448,7 @@ public class ApgProvider extends ContentProvider {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
case PUBLIC_KEY_RING_USER_ID:
|
case PUBLIC_KEY_RING_USER_ID:
|
||||||
db.insertOrThrow(Tables.USER_IDS, null, values);
|
db.insertOrThrow(Tables.USERS, null, values);
|
||||||
rowUri = PublicUserIds.buildPublicUserIdsUri(values.getAsString(PublicUserIds._ID));
|
rowUri = PublicUserIds.buildPublicUserIdsUri(values.getAsString(PublicUserIds._ID));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -470,7 +468,7 @@ public class ApgProvider extends ContentProvider {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
case SECRET_KEY_RING_USER_ID:
|
case SECRET_KEY_RING_USER_ID:
|
||||||
db.insertOrThrow(Tables.USER_IDS, null, values);
|
db.insertOrThrow(Tables.USERS, null, values);
|
||||||
rowUri = SecretUserIds.buildSecretUserIdsUri(values.getAsString(SecretUserIds._ID));
|
rowUri = SecretUserIds.buildSecretUserIdsUri(values.getAsString(SecretUserIds._ID));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -498,16 +496,13 @@ public class ApgProvider extends ContentProvider {
|
|||||||
final int match = sUriMatcher.match(uri);
|
final int match = sUriMatcher.match(uri);
|
||||||
|
|
||||||
switch (match) {
|
switch (match) {
|
||||||
case PUBLIC_KEY_RING_ID:
|
case PUBLIC_KEY_RING_ROW_ID:
|
||||||
// delete corresponding keys and userids
|
// corresponding keys and userids are deleted by ON DELETE CASCADE
|
||||||
// db.delete(Tables.KEYS, whereClause, whereArgs)
|
|
||||||
// TODO
|
|
||||||
count = db.delete(Tables.KEY_RINGS,
|
count = db.delete(Tables.KEY_RINGS,
|
||||||
buildDefaultSelection(uri, KeyTypes.PUBLIC, selection), selectionArgs);
|
buildDefaultSelection(uri, KeyTypes.PUBLIC, selection), selectionArgs);
|
||||||
break;
|
break;
|
||||||
case SECRET_KEY_RING_ID:
|
case SECRET_KEY_RING_ROW_ID:
|
||||||
// delete corresponding keys and userids
|
// corresponding keys and userids are deleted by ON DELETE CASCADE
|
||||||
// TODO
|
|
||||||
count = db.delete(Tables.KEY_RINGS,
|
count = db.delete(Tables.KEY_RINGS,
|
||||||
buildDefaultSelection(uri, KeyTypes.SECRET, selection), selectionArgs);
|
buildDefaultSelection(uri, KeyTypes.SECRET, selection), selectionArgs);
|
||||||
break;
|
break;
|
||||||
@ -532,13 +527,13 @@ public class ApgProvider extends ContentProvider {
|
|||||||
try {
|
try {
|
||||||
final int match = sUriMatcher.match(uri);
|
final int match = sUriMatcher.match(uri);
|
||||||
switch (match) {
|
switch (match) {
|
||||||
case PUBLIC_KEY_RING_ID:
|
case PUBLIC_KEY_RING_ROW_ID:
|
||||||
count = db.update(Tables.KEY_RINGS, values,
|
count = db.update(Tables.KEY_RINGS, values,
|
||||||
buildDefaultSelection(uri, KeyTypes.PUBLIC, selection), selectionArgs);
|
buildDefaultSelection(uri, KeyTypes.PUBLIC, selection), selectionArgs);
|
||||||
break;
|
break;
|
||||||
case SECRET_KEY_RING_ID:
|
case SECRET_KEY_RING_ROW_ID:
|
||||||
count = db.update(Tables.KEY_RINGS, values,
|
count = db.update(Tables.KEY_RINGS, values,
|
||||||
buildDefaultSelection(uri, KeyTypes.PUBLIC, selection), selectionArgs);
|
buildDefaultSelection(uri, KeyTypes.SECRET, selection), selectionArgs);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new UnsupportedOperationException("Unknown uri: " + uri);
|
throw new UnsupportedOperationException("Unknown uri: " + uri);
|
||||||
|
@ -1,79 +1,207 @@
|
|||||||
package org.thialfihar.android.apg.provider;
|
package org.thialfihar.android.apg.provider;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
|
import org.spongycastle.openpgp.PGPException;
|
||||||
|
import org.spongycastle.openpgp.PGPKeyRing;
|
||||||
import org.spongycastle.openpgp.PGPPublicKey;
|
import org.spongycastle.openpgp.PGPPublicKey;
|
||||||
import org.spongycastle.openpgp.PGPPublicKeyRing;
|
import org.spongycastle.openpgp.PGPPublicKeyRing;
|
||||||
|
import org.spongycastle.openpgp.PGPSecretKey;
|
||||||
|
import org.spongycastle.openpgp.PGPSecretKeyRing;
|
||||||
|
import org.thialfihar.android.apg.Constants;
|
||||||
|
import org.thialfihar.android.apg.Id;
|
||||||
|
import org.thialfihar.android.apg.helper.PGPConversionHelper;
|
||||||
|
import org.thialfihar.android.apg.helper.PGPHelper;
|
||||||
import org.thialfihar.android.apg.helper.PGPMain.ApgGeneralException;
|
import org.thialfihar.android.apg.helper.PGPMain.ApgGeneralException;
|
||||||
import org.thialfihar.android.apg.provider.ApgContract.PublicKeyRings;
|
import org.thialfihar.android.apg.provider.ApgContract.PublicKeyRings;
|
||||||
import org.thialfihar.android.apg.provider.ApgContract.PublicKeys;
|
import org.thialfihar.android.apg.provider.ApgContract.PublicKeys;
|
||||||
|
import org.thialfihar.android.apg.provider.ApgContract.SecretKeyRings;
|
||||||
import org.thialfihar.android.apg.provider.ApgContract.SecretKeys;
|
import org.thialfihar.android.apg.provider.ApgContract.SecretKeys;
|
||||||
|
import org.thialfihar.android.apg.util.Log;
|
||||||
|
|
||||||
|
import android.content.ContentResolver;
|
||||||
|
import android.content.ContentUris;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
import android.net.Uri;
|
||||||
|
|
||||||
public class ProviderHelper {
|
public class ProviderHelper {
|
||||||
// public static void insertHostsSource(Context context, String url) {
|
|
||||||
// ContentValues values = new ContentValues();
|
|
||||||
// values.put(HostsSources.URL, url);
|
|
||||||
// values.put(HostsSources.ENABLED, true); // default is enabled
|
|
||||||
// values.put(HostsSources.LAST_MODIFIED_LOCAL, 0); // last_modified_local starts at 0
|
|
||||||
// values.put(HostsSources.LAST_MODIFIED_ONLINE, 0); // last_modified_onlinestarts at 0
|
|
||||||
// context.getContentResolver().insert(HostsSources.CONTENT_URI, values);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public int saveKeyRing(Context context, PGPPublicKeyRing keyRing) throws IOException,
|
|
||||||
// ApgGeneralException {
|
|
||||||
// // mDb.beginTransaction();
|
|
||||||
// ContentValues values = new ContentValues();
|
|
||||||
// PGPPublicKey masterKey = keyRing.getPublicKey();
|
|
||||||
// long masterKeyId = masterKey.getKeyID();
|
|
||||||
//
|
|
||||||
// values.put(PublicKeyRings.MASTER_KEY_ID, masterKeyId);
|
|
||||||
// // values.put(KeyRings.TYPE, Id.database.type_public);
|
|
||||||
// values.put(PublicKeyRings.KEY_RING_DATA, keyRing.getEncoded());
|
|
||||||
//
|
|
||||||
// context.getContentResolver().insert(PublicKeyRings.CONTENT_URI, values);
|
|
||||||
//
|
|
||||||
// long rowId = insertOrUpdateKeyRing(values);
|
|
||||||
// int returnValue = mStatus;
|
|
||||||
//
|
|
||||||
// if (rowId == -1) {
|
|
||||||
// throw new ApgGeneralException("saving public key ring " + masterKeyId + " failed");
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// Vector<Integer> seenIds = new Vector<Integer>();
|
|
||||||
// int rank = 0;
|
|
||||||
// for (PGPPublicKey key : new IterableIterator<PGPPublicKey>(keyRing.getPublicKeys())) {
|
|
||||||
// seenIds.add(saveKey(rowId, key, rank));
|
|
||||||
// ++rank;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// String seenIdsStr = "";
|
|
||||||
// for (Integer id : seenIds) {
|
|
||||||
// if (seenIdsStr.length() > 0) {
|
|
||||||
// seenIdsStr += ",";
|
|
||||||
// }
|
|
||||||
// seenIdsStr += id;
|
|
||||||
// }
|
|
||||||
// mDb.delete(Keys.TABLE_NAME, Keys.KEY_RING_ID + " = ? AND " + Keys._ID + " NOT IN ("
|
|
||||||
// + seenIdsStr + ")", new String[] { "" + rowId });
|
|
||||||
//
|
|
||||||
// mDb.setTransactionSuccessful();
|
|
||||||
// mDb.endTransaction();
|
|
||||||
// return returnValue;
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes public and secret keys
|
* Retrieves the actual PGPPublicKeyRing object from the database blob associated with the rowId
|
||||||
*
|
*
|
||||||
* @param context
|
* @param context
|
||||||
* @param rowId
|
* @param rowId
|
||||||
|
* @return
|
||||||
*/
|
*/
|
||||||
public static void deleteKey(Context context, long rowId) {
|
public static PGPPublicKeyRing getPGPPublicKeyRing(Context context, long rowId) {
|
||||||
context.getContentResolver().delete(PublicKeys.buildPublicKeysUri(Long.toString(rowId)),
|
Uri queryUri = PublicKeyRings.buildPublicKeyRingsUri(Long.toString(rowId));
|
||||||
null, null);
|
Cursor cursor = context.getContentResolver()
|
||||||
context.getContentResolver().delete(SecretKeys.buildSecretKeysUri(Long.toString(rowId)),
|
.query(queryUri, new String[] { PublicKeyRings._ID, PublicKeyRings.KEY_RING_DATA },
|
||||||
null, null);
|
null, null, null);
|
||||||
|
|
||||||
|
PGPPublicKeyRing keyRing = null;
|
||||||
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
|
int keyRingDataCol = cursor.getColumnIndex(PublicKeyRings.KEY_RING_DATA);
|
||||||
|
|
||||||
|
byte[] data = cursor.getBlob(keyRingDataCol);
|
||||||
|
if (data != null) {
|
||||||
|
keyRing = PGPConversionHelper.BytesToPGPPublicKeyRing(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cursor != null) {
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
return keyRing;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the actual PGPSecretKeyRing object from the database blob associated with the rowId
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param rowId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static PGPSecretKeyRing getPGPSecretKeyRing(Context context, long rowId) {
|
||||||
|
Uri queryUri = SecretKeyRings.buildSecretKeyRingsUri(Long.toString(rowId));
|
||||||
|
Cursor cursor = context.getContentResolver()
|
||||||
|
.query(queryUri, new String[] { SecretKeyRings._ID, SecretKeyRings.KEY_RING_DATA },
|
||||||
|
null, null, null);
|
||||||
|
|
||||||
|
PGPSecretKeyRing keyRing = null;
|
||||||
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
|
int keyRingDataCol = cursor.getColumnIndex(SecretKeyRings.KEY_RING_DATA);
|
||||||
|
|
||||||
|
byte[] data = cursor.getBlob(keyRingDataCol);
|
||||||
|
if (data != null) {
|
||||||
|
keyRing = PGPConversionHelper.BytesToPGPSecretKeyRing(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cursor != null) {
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
return keyRing;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PGPSecretKey getPGPSecretKey(Context context, long keyId) {
|
||||||
|
PGPSecretKeyRing keyRing = ProviderHelper.getPGPSecretKeyRing(context, keyId);
|
||||||
|
if (keyRing == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return keyRing.getSecretKey(keyId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PGPPublicKey getPGPPublicKey(Context context, long keyId) {
|
||||||
|
PGPPublicKeyRing keyRing = ProviderHelper.getPGPPublicKeyRing(context, keyId);
|
||||||
|
if (keyRing == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return keyRing.getPublicKey(keyId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// public static String getMainUserId(long keyRowId, int type) {
|
||||||
|
// Uri queryUri = SecretKeyRings.buildSecretKeyRingsUri(Long.toString(rowId));
|
||||||
|
// Cursor cursor = context.getContentResolver()
|
||||||
|
// .query(queryUri, new String[] { SecretKeyRings._ID, SecretKeyRings.KEY_RING_DATA },
|
||||||
|
// null, null, null);
|
||||||
|
|
||||||
|
// SQLiteDatabase db = mDatabase.db();
|
||||||
|
// Cursor c = db.query(Keys.TABLE_NAME + " INNER JOIN " + KeyRings.TABLE_NAME + " ON ("
|
||||||
|
// + KeyRings.TABLE_NAME + "." + KeyRings._ID + " = " + Keys.TABLE_NAME + "."
|
||||||
|
// + Keys.KEY_RING_ID + ") " + " INNER JOIN " + Keys.TABLE_NAME + " AS masterKey ON ("
|
||||||
|
// + KeyRings.TABLE_NAME + "." + KeyRings._ID + " = " + "masterKey."
|
||||||
|
// + Keys.KEY_RING_ID + " AND " + "masterKey." + Keys.IS_MASTER_KEY + " = '1') "
|
||||||
|
// + " INNER JOIN " + UserIds.TABLE_NAME + " ON (" + UserIds.TABLE_NAME + "."
|
||||||
|
// + UserIds.KEY_ID + " = " + "masterKey." + Keys._ID + " AND " + UserIds.TABLE_NAME
|
||||||
|
// + "." + UserIds.RANK + " = '0')", new String[] { UserIds.USER_ID }, Keys.TABLE_NAME
|
||||||
|
// + "." + Keys.KEY_ID + " = ? AND " + KeyRings.TABLE_NAME + "." + KeyRings.TYPE
|
||||||
|
// + " = ?", new String[] { "" + keyRowId, "" + type, }, null, null, null);
|
||||||
|
// String userId = "";
|
||||||
|
// if (c != null && c.moveToFirst()) {
|
||||||
|
// do {
|
||||||
|
// userId = c.getString(0);
|
||||||
|
// } while (c.moveToNext());
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (c != null) {
|
||||||
|
// c.close();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return userId;
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves ids of all SecretKeyRings
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Vector<Integer> getSecretKeyRingsRowIds(Context context) {
|
||||||
|
Uri queryUri = SecretKeyRings.buildSecretKeyRingsUri();
|
||||||
|
Cursor cursor = context.getContentResolver().query(queryUri,
|
||||||
|
new String[] { SecretKeyRings._ID }, null, null, null);
|
||||||
|
|
||||||
|
Vector<Integer> keyIds = new Vector<Integer>();
|
||||||
|
if (cursor != null) {
|
||||||
|
int idCol = cursor.getColumnIndex(SecretKeyRings._ID);
|
||||||
|
if (cursor.moveToFirst()) {
|
||||||
|
do {
|
||||||
|
keyIds.add(cursor.getInt(idCol));
|
||||||
|
} while (cursor.moveToNext());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cursor != null) {
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
return keyIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves ids of all PublicKeyRings
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Vector<Integer> getPublicKeyRingsRowIds(Context context) {
|
||||||
|
Uri queryUri = PublicKeyRings.buildPublicKeyRingsUri();
|
||||||
|
Cursor cursor = context.getContentResolver().query(queryUri,
|
||||||
|
new String[] { PublicKeyRings._ID }, null, null, null);
|
||||||
|
|
||||||
|
Vector<Integer> keyIds = new Vector<Integer>();
|
||||||
|
if (cursor != null) {
|
||||||
|
int idCol = cursor.getColumnIndex(PublicKeyRings._ID);
|
||||||
|
if (cursor.moveToFirst()) {
|
||||||
|
do {
|
||||||
|
keyIds.add(cursor.getInt(idCol));
|
||||||
|
} while (cursor.moveToNext());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cursor != null) {
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
return keyIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void deletePublicKeyRing(Context context, long rowId) {
|
||||||
|
ContentResolver cr = context.getContentResolver();
|
||||||
|
cr.delete(PublicKeyRings.buildPublicKeyRingsUri(Long.toString(rowId)), null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void deleteSecretKeyRing(Context context, long rowId) {
|
||||||
|
ContentResolver cr = context.getContentResolver();
|
||||||
|
cr.delete(SecretKeyRings.buildSecretKeyRingsUri(Long.toString(rowId)), null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -35,7 +35,6 @@ import org.spongycastle.openpgp.PGPSecretKeyRing;
|
|||||||
import org.thialfihar.android.apg.Constants;
|
import org.thialfihar.android.apg.Constants;
|
||||||
import org.thialfihar.android.apg.Id;
|
import org.thialfihar.android.apg.Id;
|
||||||
import org.thialfihar.android.apg.R;
|
import org.thialfihar.android.apg.R;
|
||||||
import org.thialfihar.android.apg.deprecated.DataProvider;
|
|
||||||
import org.thialfihar.android.apg.helper.FileHelper;
|
import org.thialfihar.android.apg.helper.FileHelper;
|
||||||
import org.thialfihar.android.apg.helper.OtherHelper;
|
import org.thialfihar.android.apg.helper.OtherHelper;
|
||||||
import org.thialfihar.android.apg.helper.PGPMain;
|
import org.thialfihar.android.apg.helper.PGPMain;
|
||||||
@ -43,7 +42,7 @@ import org.thialfihar.android.apg.helper.Preferences;
|
|||||||
import org.thialfihar.android.apg.helper.PGPMain.ApgGeneralException;
|
import org.thialfihar.android.apg.helper.PGPMain.ApgGeneralException;
|
||||||
import org.thialfihar.android.apg.helper.PGPConversionHelper;
|
import org.thialfihar.android.apg.helper.PGPConversionHelper;
|
||||||
import org.thialfihar.android.apg.provider.ApgContract.DataStream;
|
import org.thialfihar.android.apg.provider.ApgContract.DataStream;
|
||||||
import org.thialfihar.android.apg.provider.ApgProvider;
|
import org.thialfihar.android.apg.provider.ProviderHelper;
|
||||||
import org.thialfihar.android.apg.util.HkpKeyServer;
|
import org.thialfihar.android.apg.util.HkpKeyServer;
|
||||||
import org.thialfihar.android.apg.util.InputData;
|
import org.thialfihar.android.apg.util.InputData;
|
||||||
import org.thialfihar.android.apg.util.KeyServer.KeyInfo;
|
import org.thialfihar.android.apg.util.KeyServer.KeyInfo;
|
||||||
@ -622,8 +621,8 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
|
|||||||
throw new PGPMain.ApgGeneralException(getString(R.string.error_fileNotFound,
|
throw new PGPMain.ApgGeneralException(getString(R.string.error_fileNotFound,
|
||||||
deleteFile));
|
deleteFile));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new PGPMain.ApgGeneralException(getString(R.string.error_fileDeleteFailed,
|
throw new PGPMain.ApgGeneralException(getString(
|
||||||
deleteFile));
|
R.string.error_fileDeleteFailed, deleteFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Output */
|
/* Output */
|
||||||
@ -715,9 +714,11 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
|
|||||||
|
|
||||||
Vector<Integer> keyRingIds = new Vector<Integer>();
|
Vector<Integer> keyRingIds = new Vector<Integer>();
|
||||||
if (exportAll) {
|
if (exportAll) {
|
||||||
keyRingIds = PGPMain
|
if (keyType == Id.type.public_key) {
|
||||||
.getKeyRingIds(keyType == Id.type.public_key ? Id.database.type_public
|
keyRingIds = ProviderHelper.getPublicKeyRingsRowIds(this);
|
||||||
: Id.database.type_secret);
|
} else {
|
||||||
|
keyRingIds = ProviderHelper.getSecretKeyRingsRowIds(this);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
keyRingIds.add(keyRingId);
|
keyRingIds.add(keyRingId);
|
||||||
}
|
}
|
||||||
@ -742,8 +743,8 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
|
|||||||
/* Operation */
|
/* Operation */
|
||||||
HkpKeyServer server = new HkpKeyServer(keyServer);
|
HkpKeyServer server = new HkpKeyServer(keyServer);
|
||||||
|
|
||||||
PGPKeyRing keyring = PGPMain.getKeyRing(keyRingId);
|
PGPPublicKeyRing keyring = ProviderHelper.getPGPPublicKeyRing(this, keyRingId);
|
||||||
if (keyring != null && keyring instanceof PGPPublicKeyRing) {
|
if (keyring != null) {
|
||||||
boolean uploaded = PGPMain.uploadKeyRingToServer(server,
|
boolean uploaded = PGPMain.uploadKeyRingToServer(server,
|
||||||
(PGPPublicKeyRing) keyring);
|
(PGPPublicKeyRing) keyring);
|
||||||
if (!uploaded) {
|
if (!uploaded) {
|
||||||
|
@ -24,8 +24,8 @@ import org.spongycastle.openpgp.PGPSecretKeyRing;
|
|||||||
import org.thialfihar.android.apg.Constants;
|
import org.thialfihar.android.apg.Constants;
|
||||||
import org.thialfihar.android.apg.Id;
|
import org.thialfihar.android.apg.Id;
|
||||||
import org.thialfihar.android.apg.helper.PGPHelper;
|
import org.thialfihar.android.apg.helper.PGPHelper;
|
||||||
import org.thialfihar.android.apg.helper.PGPMain;
|
|
||||||
import org.thialfihar.android.apg.helper.Preferences;
|
import org.thialfihar.android.apg.helper.Preferences;
|
||||||
|
import org.thialfihar.android.apg.provider.ProviderHelper;
|
||||||
|
|
||||||
import android.app.AlarmManager;
|
import android.app.AlarmManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
@ -88,7 +88,7 @@ public class PassphraseCacheService extends Service {
|
|||||||
// try to get real key id
|
// try to get real key id
|
||||||
long realId = keyId;
|
long realId = keyId;
|
||||||
if (realId != Id.key.symmetric) {
|
if (realId != Id.key.symmetric) {
|
||||||
PGPSecretKeyRing keyRing = PGPMain.getSecretKeyRing(keyId);
|
PGPSecretKeyRing keyRing = ProviderHelper.getPGPSecretKeyRing(context, keyId);
|
||||||
if (keyRing == null) {
|
if (keyRing == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ import org.thialfihar.android.apg.helper.FileHelper;
|
|||||||
import org.thialfihar.android.apg.helper.OtherHelper;
|
import org.thialfihar.android.apg.helper.OtherHelper;
|
||||||
import org.thialfihar.android.apg.helper.PGPHelper;
|
import org.thialfihar.android.apg.helper.PGPHelper;
|
||||||
import org.thialfihar.android.apg.helper.PGPMain;
|
import org.thialfihar.android.apg.helper.PGPMain;
|
||||||
|
import org.thialfihar.android.apg.provider.ProviderHelper;
|
||||||
import org.thialfihar.android.apg.service.ApgServiceHandler;
|
import org.thialfihar.android.apg.service.ApgServiceHandler;
|
||||||
import org.thialfihar.android.apg.service.ApgService;
|
import org.thialfihar.android.apg.service.ApgService;
|
||||||
import org.thialfihar.android.apg.service.PassphraseCacheService;
|
import org.thialfihar.android.apg.service.PassphraseCacheService;
|
||||||
@ -333,7 +334,8 @@ public class DecryptActivity extends SherlockFragmentActivity {
|
|||||||
if (mSignatureKeyId == 0) {
|
if (mSignatureKeyId == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PGPPublicKeyRing key = PGPMain.getPublicKeyRing(mSignatureKeyId);
|
PGPPublicKeyRing key = ProviderHelper.getPGPPublicKeyRing(DecryptActivity.this,
|
||||||
|
mSignatureKeyId);
|
||||||
if (key != null) {
|
if (key != null) {
|
||||||
Intent intent = new Intent(DecryptActivity.this, KeyServerQueryActivity.class);
|
Intent intent = new Intent(DecryptActivity.this, KeyServerQueryActivity.class);
|
||||||
intent.setAction(KeyServerQueryActivity.ACTION_LOOK_UP_KEY_ID);
|
intent.setAction(KeyServerQueryActivity.ACTION_LOOK_UP_KEY_ID);
|
||||||
@ -655,7 +657,8 @@ public class DecryptActivity extends SherlockFragmentActivity {
|
|||||||
try {
|
try {
|
||||||
setSecretKeyId(PGPMain.getDecryptionKeyId(this, inStream));
|
setSecretKeyId(PGPMain.getDecryptionKeyId(this, inStream));
|
||||||
if (getSecretKeyId() == Id.key.none) {
|
if (getSecretKeyId() == Id.key.none) {
|
||||||
throw new PGPMain.ApgGeneralException(getString(R.string.error_noSecretKeyFound));
|
throw new PGPMain.ApgGeneralException(
|
||||||
|
getString(R.string.error_noSecretKeyFound));
|
||||||
}
|
}
|
||||||
mAssumeSymmetricEncryption = false;
|
mAssumeSymmetricEncryption = false;
|
||||||
} catch (PGPMain.NoAsymmetricEncryptionException e) {
|
} catch (PGPMain.NoAsymmetricEncryptionException e) {
|
||||||
|
@ -25,6 +25,7 @@ import org.thialfihar.android.apg.helper.OtherHelper;
|
|||||||
import org.thialfihar.android.apg.helper.PGPHelper;
|
import org.thialfihar.android.apg.helper.PGPHelper;
|
||||||
import org.thialfihar.android.apg.helper.PGPMain;
|
import org.thialfihar.android.apg.helper.PGPMain;
|
||||||
import org.thialfihar.android.apg.helper.PGPConversionHelper;
|
import org.thialfihar.android.apg.helper.PGPConversionHelper;
|
||||||
|
import org.thialfihar.android.apg.provider.ProviderHelper;
|
||||||
import org.thialfihar.android.apg.service.ApgServiceHandler;
|
import org.thialfihar.android.apg.service.ApgServiceHandler;
|
||||||
import org.thialfihar.android.apg.service.ApgService;
|
import org.thialfihar.android.apg.service.ApgService;
|
||||||
import org.thialfihar.android.apg.ui.dialog.SetPassphraseDialogFragment;
|
import org.thialfihar.android.apg.ui.dialog.SetPassphraseDialogFragment;
|
||||||
@ -308,7 +309,7 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
|||||||
|
|
||||||
if (keyId != 0) {
|
if (keyId != 0) {
|
||||||
PGPSecretKey masterKey = null;
|
PGPSecretKey masterKey = null;
|
||||||
mKeyRing = PGPMain.getSecretKeyRing(keyId);
|
mKeyRing = ProviderHelper.getPGPSecretKeyRing(this, keyId);
|
||||||
if (mKeyRing != null) {
|
if (mKeyRing != null) {
|
||||||
masterKey = PGPHelper.getMasterKey(mKeyRing);
|
masterKey = PGPHelper.getMasterKey(mKeyRing);
|
||||||
for (PGPSecretKey key : new IterableIterator<PGPSecretKey>(
|
for (PGPSecretKey key : new IterableIterator<PGPSecretKey>(
|
||||||
@ -460,7 +461,8 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
|||||||
* @param userIdsView
|
* @param userIdsView
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private ArrayList<String> getUserIds(SectionView userIdsView) throws PGPMain.ApgGeneralException {
|
private ArrayList<String> getUserIds(SectionView userIdsView)
|
||||||
|
throws PGPMain.ApgGeneralException {
|
||||||
ArrayList<String> userIds = new ArrayList<String>();
|
ArrayList<String> userIds = new ArrayList<String>();
|
||||||
|
|
||||||
ViewGroup userIdEditors = userIdsView.getEditors();
|
ViewGroup userIdEditors = userIdsView.getEditors();
|
||||||
@ -472,7 +474,8 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
|||||||
try {
|
try {
|
||||||
userId = editor.getValue();
|
userId = editor.getValue();
|
||||||
} catch (UserIdEditor.NoNameException e) {
|
} catch (UserIdEditor.NoNameException e) {
|
||||||
throw new PGPMain.ApgGeneralException(this.getString(R.string.error_userIdNeedsAName));
|
throw new PGPMain.ApgGeneralException(
|
||||||
|
this.getString(R.string.error_userIdNeedsAName));
|
||||||
} catch (UserIdEditor.NoEmailException e) {
|
} catch (UserIdEditor.NoEmailException e) {
|
||||||
throw new PGPMain.ApgGeneralException(
|
throw new PGPMain.ApgGeneralException(
|
||||||
this.getString(R.string.error_userIdNeedsAnEmailAddress));
|
this.getString(R.string.error_userIdNeedsAnEmailAddress));
|
||||||
@ -497,7 +500,8 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!gotMainUserId) {
|
if (!gotMainUserId) {
|
||||||
throw new PGPMain.ApgGeneralException(getString(R.string.error_mainUserIdMustNotBeEmpty));
|
throw new PGPMain.ApgGeneralException(
|
||||||
|
getString(R.string.error_mainUserIdMustNotBeEmpty));
|
||||||
}
|
}
|
||||||
|
|
||||||
return userIds;
|
return userIds;
|
||||||
@ -509,7 +513,8 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
|||||||
* @param keysView
|
* @param keysView
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private ArrayList<PGPSecretKey> getKeys(SectionView keysView) throws PGPMain.ApgGeneralException {
|
private ArrayList<PGPSecretKey> getKeys(SectionView keysView)
|
||||||
|
throws PGPMain.ApgGeneralException {
|
||||||
ArrayList<PGPSecretKey> keys = new ArrayList<PGPSecretKey>();
|
ArrayList<PGPSecretKey> keys = new ArrayList<PGPSecretKey>();
|
||||||
|
|
||||||
ViewGroup keyEditors = keysView.getEditors();
|
ViewGroup keyEditors = keysView.getEditors();
|
||||||
@ -532,7 +537,8 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
|||||||
* @param keysView
|
* @param keysView
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private ArrayList<Integer> getKeysUsages(SectionView keysView) throws PGPMain.ApgGeneralException {
|
private ArrayList<Integer> getKeysUsages(SectionView keysView)
|
||||||
|
throws PGPMain.ApgGeneralException {
|
||||||
ArrayList<Integer> getKeysUsages = new ArrayList<Integer>();
|
ArrayList<Integer> getKeysUsages = new ArrayList<Integer>();
|
||||||
|
|
||||||
ViewGroup keyEditors = keysView.getEditors();
|
ViewGroup keyEditors = keysView.getEditors();
|
||||||
|
@ -28,6 +28,7 @@ import org.thialfihar.android.apg.helper.OtherHelper;
|
|||||||
import org.thialfihar.android.apg.helper.PGPHelper;
|
import org.thialfihar.android.apg.helper.PGPHelper;
|
||||||
import org.thialfihar.android.apg.helper.PGPMain;
|
import org.thialfihar.android.apg.helper.PGPMain;
|
||||||
import org.thialfihar.android.apg.helper.Preferences;
|
import org.thialfihar.android.apg.helper.Preferences;
|
||||||
|
import org.thialfihar.android.apg.provider.ProviderHelper;
|
||||||
import org.thialfihar.android.apg.service.ApgServiceHandler;
|
import org.thialfihar.android.apg.service.ApgServiceHandler;
|
||||||
import org.thialfihar.android.apg.service.ApgService;
|
import org.thialfihar.android.apg.service.ApgService;
|
||||||
import org.thialfihar.android.apg.service.PassphraseCacheService;
|
import org.thialfihar.android.apg.service.PassphraseCacheService;
|
||||||
@ -440,7 +441,7 @@ public class EncryptActivity extends SherlockFragmentActivity {
|
|||||||
long signatureKeyId = extras.getLong(EXTRA_SIGNATURE_KEY_ID);
|
long signatureKeyId = extras.getLong(EXTRA_SIGNATURE_KEY_ID);
|
||||||
long encryptionKeyIds[] = extras.getLongArray(EXTRA_ENCRYPTION_KEY_IDS);
|
long encryptionKeyIds[] = extras.getLongArray(EXTRA_ENCRYPTION_KEY_IDS);
|
||||||
if (signatureKeyId != 0) {
|
if (signatureKeyId != 0) {
|
||||||
PGPSecretKeyRing keyRing = PGPMain.getSecretKeyRing(signatureKeyId);
|
PGPSecretKeyRing keyRing = ProviderHelper.getPGPSecretKeyRing(this, signatureKeyId);
|
||||||
PGPSecretKey masterKey = null;
|
PGPSecretKey masterKey = null;
|
||||||
if (keyRing != null) {
|
if (keyRing != null) {
|
||||||
masterKey = PGPHelper.getMasterKey(keyRing);
|
masterKey = PGPHelper.getMasterKey(keyRing);
|
||||||
@ -456,7 +457,8 @@ public class EncryptActivity extends SherlockFragmentActivity {
|
|||||||
if (encryptionKeyIds != null) {
|
if (encryptionKeyIds != null) {
|
||||||
Vector<Long> goodIds = new Vector<Long>();
|
Vector<Long> goodIds = new Vector<Long>();
|
||||||
for (int i = 0; i < encryptionKeyIds.length; ++i) {
|
for (int i = 0; i < encryptionKeyIds.length; ++i) {
|
||||||
PGPPublicKeyRing keyRing = PGPMain.getPublicKeyRing(encryptionKeyIds[i]);
|
PGPPublicKeyRing keyRing = ProviderHelper.getPGPPublicKeyRing(this,
|
||||||
|
encryptionKeyIds[i]);
|
||||||
PGPPublicKey masterKey = null;
|
PGPPublicKey masterKey = null;
|
||||||
if (keyRing == null) {
|
if (keyRing == null) {
|
||||||
continue;
|
continue;
|
||||||
@ -956,7 +958,7 @@ public class EncryptActivity extends SherlockFragmentActivity {
|
|||||||
} else {
|
} else {
|
||||||
String uid = getResources().getString(R.string.unknownUserId);
|
String uid = getResources().getString(R.string.unknownUserId);
|
||||||
String uidExtra = "";
|
String uidExtra = "";
|
||||||
PGPSecretKeyRing keyRing = PGPMain.getSecretKeyRing(getSecretKeyId());
|
PGPSecretKeyRing keyRing = ProviderHelper.getPGPSecretKeyRing(this, getSecretKeyId());
|
||||||
if (keyRing != null) {
|
if (keyRing != null) {
|
||||||
PGPSecretKey key = PGPHelper.getMasterKey(keyRing);
|
PGPSecretKey key = PGPHelper.getMasterKey(keyRing);
|
||||||
if (key != null) {
|
if (key != null) {
|
||||||
|
@ -601,7 +601,7 @@ public class KeyListActivity extends SherlockFragmentActivity {
|
|||||||
|
|
||||||
if (masterKeyId != -1) {
|
if (masterKeyId != -1) {
|
||||||
children.insertElementAt(
|
children.insertElementAt(
|
||||||
new KeyChild(PGPHelper.getFingerPrint(fingerPrintId), true), 0);
|
new KeyChild(PGPHelper.getFingerPrint(KeyListActivity.this, fingerPrintId), true), 0);
|
||||||
c = mDatabase.query(UserIds.TABLE_NAME, new String[] { UserIds.USER_ID, // 0
|
c = mDatabase.query(UserIds.TABLE_NAME, new String[] { UserIds.USER_ID, // 0
|
||||||
}, UserIds.KEY_ID + " = ? AND " + UserIds.RANK + " > 0", new String[] { ""
|
}, UserIds.KEY_ID + " = ? AND " + UserIds.RANK + " > 0", new String[] { ""
|
||||||
+ masterKeyId }, null, null, UserIds.RANK + " ASC");
|
+ masterKeyId }, null, null, UserIds.RANK + " ASC");
|
||||||
|
@ -22,6 +22,7 @@ import org.thialfihar.android.apg.Id;
|
|||||||
import org.thialfihar.android.apg.R;
|
import org.thialfihar.android.apg.R;
|
||||||
import org.thialfihar.android.apg.helper.PGPHelper;
|
import org.thialfihar.android.apg.helper.PGPHelper;
|
||||||
import org.thialfihar.android.apg.helper.PGPMain;
|
import org.thialfihar.android.apg.helper.PGPMain;
|
||||||
|
import org.thialfihar.android.apg.provider.ProviderHelper;
|
||||||
|
|
||||||
import com.actionbarsherlock.view.Menu;
|
import com.actionbarsherlock.view.Menu;
|
||||||
import com.actionbarsherlock.view.MenuItem;
|
import com.actionbarsherlock.view.MenuItem;
|
||||||
@ -115,8 +116,8 @@ public class PublicKeyListActivity extends KeyListActivity {
|
|||||||
mSelectedItem = groupPosition;
|
mSelectedItem = groupPosition;
|
||||||
final int keyRingId = mListAdapter.getKeyRingId(groupPosition);
|
final int keyRingId = mListAdapter.getKeyRingId(groupPosition);
|
||||||
long keyId = 0;
|
long keyId = 0;
|
||||||
Object keyRing = PGPMain.getKeyRing(keyRingId);
|
PGPPublicKeyRing keyRing = ProviderHelper.getPGPPublicKeyRing(this, keyRingId);
|
||||||
if (keyRing != null && keyRing instanceof PGPPublicKeyRing) {
|
if (keyRing != null) {
|
||||||
keyId = PGPHelper.getMasterKey((PGPPublicKeyRing) keyRing).getKeyID();
|
keyId = PGPHelper.getMasterKey((PGPPublicKeyRing) keyRing).getKeyID();
|
||||||
}
|
}
|
||||||
if (keyId == 0) {
|
if (keyId == 0) {
|
||||||
@ -148,8 +149,8 @@ public class PublicKeyListActivity extends KeyListActivity {
|
|||||||
mSelectedItem = groupPosition;
|
mSelectedItem = groupPosition;
|
||||||
final int keyRingId = mListAdapter.getKeyRingId(groupPosition);
|
final int keyRingId = mListAdapter.getKeyRingId(groupPosition);
|
||||||
long keyId = 0;
|
long keyId = 0;
|
||||||
Object keyRing = PGPMain.getKeyRing(keyRingId);
|
PGPPublicKeyRing keyRing = ProviderHelper.getPGPPublicKeyRing(this, keyRingId);
|
||||||
if (keyRing != null && keyRing instanceof PGPPublicKeyRing) {
|
if (keyRing != null) {
|
||||||
keyId = PGPHelper.getMasterKey((PGPPublicKeyRing) keyRing).getKeyID();
|
keyId = PGPHelper.getMasterKey((PGPPublicKeyRing) keyRing).getKeyID();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ import org.thialfihar.android.apg.Id;
|
|||||||
import org.thialfihar.android.apg.R;
|
import org.thialfihar.android.apg.R;
|
||||||
import org.thialfihar.android.apg.helper.PGPMain;
|
import org.thialfihar.android.apg.helper.PGPMain;
|
||||||
import org.thialfihar.android.apg.helper.Preferences;
|
import org.thialfihar.android.apg.helper.Preferences;
|
||||||
|
import org.thialfihar.android.apg.provider.ProviderHelper;
|
||||||
import org.thialfihar.android.apg.service.ApgService;
|
import org.thialfihar.android.apg.service.ApgService;
|
||||||
import org.thialfihar.android.apg.service.ApgServiceHandler;
|
import org.thialfihar.android.apg.service.ApgServiceHandler;
|
||||||
import org.thialfihar.android.apg.service.PassphraseCacheService;
|
import org.thialfihar.android.apg.service.PassphraseCacheService;
|
||||||
@ -154,7 +155,7 @@ public class SignKeyActivity extends SherlockFragmentActivity {
|
|||||||
* handles the UI bits of the signing process on the UI thread
|
* handles the UI bits of the signing process on the UI thread
|
||||||
*/
|
*/
|
||||||
private void initiateSigning() {
|
private void initiateSigning() {
|
||||||
PGPPublicKeyRing pubring = PGPMain.getPublicKeyRing(mPubKeyId);
|
PGPPublicKeyRing pubring = ProviderHelper.getPGPPublicKeyRing(this, mPubKeyId);
|
||||||
if (pubring != null) {
|
if (pubring != null) {
|
||||||
// if we have already signed this key, dont bother doing it again
|
// if we have already signed this key, dont bother doing it again
|
||||||
boolean alreadySigned = false;
|
boolean alreadySigned = false;
|
||||||
|
@ -23,6 +23,7 @@ import org.thialfihar.android.apg.Id;
|
|||||||
import org.thialfihar.android.apg.R;
|
import org.thialfihar.android.apg.R;
|
||||||
import org.thialfihar.android.apg.helper.PGPHelper;
|
import org.thialfihar.android.apg.helper.PGPHelper;
|
||||||
import org.thialfihar.android.apg.helper.PGPMain;
|
import org.thialfihar.android.apg.helper.PGPMain;
|
||||||
|
import org.thialfihar.android.apg.provider.ProviderHelper;
|
||||||
import org.thialfihar.android.apg.util.Log;
|
import org.thialfihar.android.apg.util.Log;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
@ -93,8 +94,11 @@ public class DeleteKeyDialogFragment extends DialogFragment {
|
|||||||
builder.setIcon(android.R.drawable.ic_dialog_alert);
|
builder.setIcon(android.R.drawable.ic_dialog_alert);
|
||||||
builder.setPositiveButton(R.string.btn_delete, new DialogInterface.OnClickListener() {
|
builder.setPositiveButton(R.string.btn_delete, new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
// deleteKey(deleteKeyRingId);
|
if (keyType == Id.type.public_key) {
|
||||||
PGPMain.deleteKey(deleteKeyRingId);
|
ProviderHelper.deletePublicKeyRing(activity, deleteKeyRingId);
|
||||||
|
} else {
|
||||||
|
ProviderHelper.deleteSecretKeyRing(activity, deleteKeyRingId);
|
||||||
|
}
|
||||||
|
|
||||||
dismiss();
|
dismiss();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user