more Provider Helper methods

This commit is contained in:
Dominik 2012-09-20 17:13:45 +02:00
parent fb49f9e9c8
commit 95e35a4ffa
20 changed files with 1877 additions and 1760 deletions

View file

@ -20,7 +20,6 @@ import java.io.File;
import java.security.Security;
import org.spongycastle.jce.provider.BouncyCastleProvider;
import org.thialfihar.android.apg.helper.PGPMain;
import android.app.Application;
import android.os.Environment;
@ -36,10 +35,6 @@ public class ApgApplication extends Application {
public void 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
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
File dir = new File(Constants.path.APP_DIR);

View file

@ -1,71 +1,71 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thialfihar.android.apg.deprecated;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.net.Uri;
import org.thialfihar.android.apg.util.Log;
public class ApgServiceBlobDatabase extends SQLiteOpenHelper {
private static final String TAG = "ApgServiceBlobDatabase";
private static final int VERSION = 1;
private static final String NAME = "apg_service_blob_data";
private static final String TABLE = "data";
public ApgServiceBlobDatabase(Context context) {
super(context, NAME, null, VERSION);
if (ApgService2.LOCAL_LOGD)
Log.d(TAG, "constructor called");
}
@Override
public void onCreate(SQLiteDatabase db) {
if (ApgService2.LOCAL_LOGD)
Log.d(TAG, "onCreate() called");
db.execSQL("create table " + TABLE + " ( _id integer primary key autoincrement,"
+ "key text not null)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (ApgService2.LOCAL_LOGD)
Log.d(TAG, "onUpgrade() called");
// no upgrade necessary yet
}
public Uri insert(ContentValues vals) {
if (ApgService2.LOCAL_LOGD)
Log.d(TAG, "insert() called");
SQLiteDatabase db = this.getWritableDatabase();
long newId = db.insert(TABLE, null, vals);
return ContentUris.withAppendedId(ApgServiceBlobProvider.CONTENT_URI, newId);
}
public Cursor query(String id, String key) {
if (ApgService2.LOCAL_LOGD)
Log.d(TAG, "query() called");
SQLiteDatabase db = this.getReadableDatabase();
return db.query(TABLE, new String[] { "_id" }, "_id = ? and key = ?", new String[] { id,
key }, null, null, null);
}
}
///*
// * Licensed under the Apache License, Version 2.0 (the "License");
// * you may not use this file except in compliance with the License.
// * You may obtain a copy of the License at
// *
// * http://www.apache.org/licenses/LICENSE-2.0
// *
// * Unless required by applicable law or agreed to in writing, software
// * distributed under the License is distributed on an "AS IS" BASIS,
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// * See the License for the specific language governing permissions and
// * limitations under the License.
// */
//
//package org.thialfihar.android.apg.deprecated;
//
//
//import android.content.ContentUris;
//import android.content.ContentValues;
//import android.content.Context;
//import android.database.Cursor;
//import android.database.sqlite.SQLiteDatabase;
//import android.database.sqlite.SQLiteOpenHelper;
//import android.net.Uri;
//import org.thialfihar.android.apg.util.Log;
//
//public class ApgServiceBlobDatabase extends SQLiteOpenHelper {
//
// private static final String TAG = "ApgServiceBlobDatabase";
//
// private static final int VERSION = 1;
// private static final String NAME = "apg_service_blob_data";
// private static final String TABLE = "data";
//
// public ApgServiceBlobDatabase(Context context) {
// super(context, NAME, null, VERSION);
// if (ApgService2.LOCAL_LOGD)
// Log.d(TAG, "constructor called");
// }
//
// @Override
// public void onCreate(SQLiteDatabase db) {
// if (ApgService2.LOCAL_LOGD)
// Log.d(TAG, "onCreate() called");
// db.execSQL("create table " + TABLE + " ( _id integer primary key autoincrement,"
// + "key text not null)");
// }
//
// @Override
// public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// if (ApgService2.LOCAL_LOGD)
// Log.d(TAG, "onUpgrade() called");
// // no upgrade necessary yet
// }
//
// public Uri insert(ContentValues vals) {
// if (ApgService2.LOCAL_LOGD)
// Log.d(TAG, "insert() called");
// SQLiteDatabase db = this.getWritableDatabase();
// long newId = db.insert(TABLE, null, vals);
// return ContentUris.withAppendedId(ApgServiceBlobProvider.CONTENT_URI, newId);
// }
//
// public Cursor query(String id, String key) {
// if (ApgService2.LOCAL_LOGD)
// Log.d(TAG, "query() called");
// SQLiteDatabase db = this.getReadableDatabase();
// return db.query(TABLE, new String[] { "_id" }, "_id = ? and key = ?", new String[] { id,
// key }, null, null, null);
// }
//}

View file

@ -1,151 +1,151 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thialfihar.android.apg.deprecated;
import org.thialfihar.android.apg.Constants;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.os.ParcelFileDescriptor;
import org.thialfihar.android.apg.util.Log;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
import java.util.UUID;
public class ApgServiceBlobProvider extends ContentProvider {
private static final String TAG = "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 STORE_PATH = Constants.path.APP_DIR+"/ApgServiceBlobs";
private ApgServiceBlobDatabase mDb = null;
public ApgServiceBlobProvider() {
if(ApgService2.LOCAL_LOGD) Log.d(TAG, "Constructor called");
File dir = new File(STORE_PATH);
dir.mkdirs();
if(ApgService2.LOCAL_LOGD) Log.d(TAG, "Constructor finished");
}
@Override
public int delete(Uri arg0, String arg1, String[] arg2) {
if(ApgService2.LOCAL_LOGD) Log.d(TAG, "delete() called");
// TODO Auto-generated method stub
return 0;
}
@Override
public String getType(Uri arg0) {
if(ApgService2.LOCAL_LOGD) Log.d(TAG, "getType() called");
// not needed for now
return null;
}
@Override
public Uri insert(Uri uri, ContentValues ignored) {
if(ApgService2.LOCAL_LOGD) Log.d(TAG, "insert() called");
// 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
ContentValues vals = new ContentValues();
// Insert a random key in the database. This has to provided by the caller when updating or
// getting the blob
String password = UUID.randomUUID().toString();
vals.put(COLUMN_KEY, password);
Uri insertedUri = mDb.insert(vals);
return Uri.withAppendedPath(insertedUri, password);
}
@Override
public boolean onCreate() {
if(ApgService2.LOCAL_LOGD) Log.d(TAG, "onCreate() called");
mDb = new ApgServiceBlobDatabase(getContext());
// TODO Auto-generated method stub
return true;
}
@Override
public Cursor query(Uri arg0, String[] arg1, String arg2, String[] arg3, String arg4) {
if(ApgService2.LOCAL_LOGD) Log.d(TAG, "query() called");
// TODO Auto-generated method stub
return null;
}
@Override
public int update(Uri arg0, ContentValues arg1, String arg2, String[] arg3) {
if(ApgService2.LOCAL_LOGD) Log.d(TAG, "update() called");
// TODO Auto-generated method stub
return 0;
}
@Override
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, "... with uri: "+uri.toString());
if(ApgService2.LOCAL_LOGD) Log.d(TAG, "... with mode: "+mode);
List<String> segments = uri.getPathSegments();
if(segments.size() < 2) {
throw new SecurityException("Password not found in URI");
}
String id = segments.get(0);
String key = segments.get(1);
if(ApgService2.LOCAL_LOGD) Log.d(TAG, "... got id: "+id);
if(ApgService2.LOCAL_LOGD) Log.d(TAG, "... and key: "+key);
// get the data
Cursor result = mDb.query(id, key);
if(result.getCount() == 0) {
// either the key is wrong or no id exists
throw new FileNotFoundException("No file found with that ID and/or password");
}
File targetFile = new File(STORE_PATH, id);
if(mode.equals("w")) {
if(ApgService2.LOCAL_LOGD) Log.d(TAG, "... will try to open file w");
if( !targetFile.exists() ) {
try {
targetFile.createNewFile();
} catch (IOException e) {
Log.e(TAG, "... got IEOException on creating new file", e);
throw new FileNotFoundException("Could not create file to write to");
}
}
return ParcelFileDescriptor.open(targetFile, ParcelFileDescriptor.MODE_WRITE_ONLY | ParcelFileDescriptor.MODE_TRUNCATE );
} else if(mode.equals("r")) {
if(ApgService2.LOCAL_LOGD) Log.d(TAG, "... will try to open file r");
if( !targetFile.exists() ) {
throw new FileNotFoundException("Error: Could not find the file requested");
}
return ParcelFileDescriptor.open(targetFile, ParcelFileDescriptor.MODE_READ_ONLY);
}
return null;
}
}
///*
// * Licensed under the Apache License, Version 2.0 (the "License");
// * you may not use this file except in compliance with the License.
// * You may obtain a copy of the License at
// *
// * http://www.apache.org/licenses/LICENSE-2.0
// *
// * Unless required by applicable law or agreed to in writing, software
// * distributed under the License is distributed on an "AS IS" BASIS,
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// * See the License for the specific language governing permissions and
// * limitations under the License.
// */
//
//package org.thialfihar.android.apg.deprecated;
//
//import org.thialfihar.android.apg.Constants;
//
//import android.content.ContentProvider;
//import android.content.ContentValues;
//import android.database.Cursor;
//import android.net.Uri;
//import android.os.ParcelFileDescriptor;
//import org.thialfihar.android.apg.util.Log;
//
//import java.io.File;
//import java.io.FileNotFoundException;
//import java.io.IOException;
//import java.util.List;
//import java.util.UUID;
//
//public class ApgServiceBlobProvider extends ContentProvider {
//
// private static final String TAG = "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 STORE_PATH = Constants.path.APP_DIR+"/ApgServiceBlobs";
//
// private ApgServiceBlobDatabase mDb = null;
//
// public ApgServiceBlobProvider() {
// if(ApgService2.LOCAL_LOGD) Log.d(TAG, "Constructor called");
// File dir = new File(STORE_PATH);
// dir.mkdirs();
// if(ApgService2.LOCAL_LOGD) Log.d(TAG, "Constructor finished");
// }
//
// @Override
// public int delete(Uri arg0, String arg1, String[] arg2) {
// if(ApgService2.LOCAL_LOGD) Log.d(TAG, "delete() called");
// // TODO Auto-generated method stub
// return 0;
// }
//
// @Override
// public String getType(Uri arg0) {
// if(ApgService2.LOCAL_LOGD) Log.d(TAG, "getType() called");
// // not needed for now
// return null;
// }
//
// @Override
// public Uri insert(Uri uri, ContentValues ignored) {
// if(ApgService2.LOCAL_LOGD) Log.d(TAG, "insert() called");
// // 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
//
// ContentValues vals = new ContentValues();
//
// // Insert a random key in the database. This has to provided by the caller when updating or
// // getting the blob
// String password = UUID.randomUUID().toString();
// vals.put(COLUMN_KEY, password);
//
// Uri insertedUri = mDb.insert(vals);
// return Uri.withAppendedPath(insertedUri, password);
// }
//
// @Override
// public boolean onCreate() {
// if(ApgService2.LOCAL_LOGD) Log.d(TAG, "onCreate() called");
// mDb = new ApgServiceBlobDatabase(getContext());
// // TODO Auto-generated method stub
// return true;
// }
//
// @Override
// public Cursor query(Uri arg0, String[] arg1, String arg2, String[] arg3, String arg4) {
// if(ApgService2.LOCAL_LOGD) Log.d(TAG, "query() called");
// // TODO Auto-generated method stub
// return null;
// }
//
// @Override
// public int update(Uri arg0, ContentValues arg1, String arg2, String[] arg3) {
// if(ApgService2.LOCAL_LOGD) Log.d(TAG, "update() called");
// // TODO Auto-generated method stub
// return 0;
// }
//
// @Override
// 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, "... with uri: "+uri.toString());
// if(ApgService2.LOCAL_LOGD) Log.d(TAG, "... with mode: "+mode);
//
// List<String> segments = uri.getPathSegments();
// if(segments.size() < 2) {
// throw new SecurityException("Password not found in URI");
// }
// String id = segments.get(0);
// String key = segments.get(1);
//
// if(ApgService2.LOCAL_LOGD) Log.d(TAG, "... got id: "+id);
// if(ApgService2.LOCAL_LOGD) Log.d(TAG, "... and key: "+key);
//
// // get the data
// Cursor result = mDb.query(id, key);
//
// if(result.getCount() == 0) {
// // either the key is wrong or no id exists
// throw new FileNotFoundException("No file found with that ID and/or password");
// }
//
// File targetFile = new File(STORE_PATH, id);
// if(mode.equals("w")) {
// if(ApgService2.LOCAL_LOGD) Log.d(TAG, "... will try to open file w");
// if( !targetFile.exists() ) {
// try {
// targetFile.createNewFile();
// } catch (IOException e) {
// Log.e(TAG, "... got IEOException on creating new file", e);
// throw new FileNotFoundException("Could not create file to write to");
// }
// }
// return ParcelFileDescriptor.open(targetFile, ParcelFileDescriptor.MODE_WRITE_ONLY | ParcelFileDescriptor.MODE_TRUNCATE );
// } else if(mode.equals("r")) {
// if(ApgService2.LOCAL_LOGD) Log.d(TAG, "... will try to open file r");
// if( !targetFile.exists() ) {
// throw new FileNotFoundException("Error: Could not find the file requested");
// }
// return ParcelFileDescriptor.open(targetFile, ParcelFileDescriptor.MODE_READ_ONLY);
// }
//
// return null;
// }
//
//}

File diff suppressed because it is too large Load diff

View file

@ -38,6 +38,7 @@ import org.spongycastle.openpgp.PGPSignatureSubpacketVector;
import org.spongycastle.openpgp.PGPUtil;
import org.thialfihar.android.apg.Constants;
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.Log;
@ -189,9 +190,8 @@ public class PGPHelper {
return getExpiryDate(key.getPublicKey());
}
public static PGPPublicKey getEncryptPublicKey(long masterKeyId) {
// TODO: externalize getSecretKeyRing from PGPWrapper into a DatabaseHelper
PGPPublicKeyRing keyRing = PGPMain.getPublicKeyRing(masterKeyId);
public static PGPPublicKey getEncryptPublicKey(Context context, long masterKeyId) {
PGPPublicKeyRing keyRing = ProviderHelper.getPGPPublicKeyRing(context, masterKeyId);
if (keyRing == null) {
return null;
}
@ -202,9 +202,8 @@ public class PGPHelper {
return encryptKeys.get(0);
}
public static PGPSecretKey getSigningKey(long masterKeyId) {
// TODO: externalize getSecretKeyRing from PGPWrapper into a DatabaseHelper
PGPSecretKeyRing keyRing = PGPMain.getSecretKeyRing(masterKeyId);
public static PGPSecretKey getSigningKey(Context context, long masterKeyId) {
PGPSecretKeyRing keyRing = ProviderHelper.getPGPSecretKeyRing(context, masterKeyId);
if (keyRing == null) {
return null;
}
@ -385,10 +384,10 @@ public class PGPHelper {
}
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 (key == null) {
PGPSecretKey secretKey = PGPMain.getSecretKey(keyId);
PGPSecretKey secretKey = ProviderHelper.getPGPSecretKey(context, keyId);
if (secretKey == null) {
Log.e(Constants.TAG, "Key could not be found!");
return null;
@ -415,10 +414,11 @@ public class PGPHelper {
return armouredKey;
}
public static String getFingerPrint(long keyId) {
PGPPublicKey key = PGPMain.getPublicKey(keyId);
public static String getFingerPrint(Context context, long keyId) {
PGPPublicKey key = ProviderHelper.getPGPPublicKey(context, keyId);
// if it is no public key get it from your own keys...
if (key == null) {
PGPSecretKey secretKey = PGPMain.getSecretKey(keyId);
PGPSecretKey secretKey = ProviderHelper.getPGPSecretKey(context, keyId);
if (secretKey == null) {
Log.e(Constants.TAG, "Key could not be found!");
return null;

View file

@ -72,6 +72,7 @@ import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder;
import org.spongycastle.openpgp.operator.jcajce.JcePGPDataEncryptorBuilder;
import org.spongycastle.openpgp.operator.jcajce.JcePublicKeyDataDecryptorFactoryBuilder;
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.util.HkpKeyServer;
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://"
// + AUTHORITY + "/key_rings/public/emails/");
private static String VERSION = null;
private static final int[] PREFERRED_SYMMETRIC_ALGORITHMS = new int[] {
SymmetricKeyAlgorithmTags.AES_256, SymmetricKeyAlgorithmTags.AES_192,
SymmetricKeyAlgorithmTags.AES_128, SymmetricKeyAlgorithmTags.CAST5,
@ -521,8 +520,6 @@ public class PGPMain {
}
} catch (IOException e) {
status = Id.return_value.error;
} catch (ApgGeneralException.GeneralException e) {
status = Id.return_value.error;
}
return status;
@ -641,18 +638,20 @@ public class PGPMain {
int numKeys = 0;
for (int i = 0; i < keyRingIds.size(); ++i) {
updateProgress(progress, i * 100 / keyRingIds.size(), 100);
Object obj = mDatabase.getKeyRing(keyRingIds.get(i));
PGPPublicKeyRing publicKeyRing;
PGPSecretKeyRing secretKeyRing;
if (obj instanceof PGPSecretKeyRing) {
secretKeyRing = (PGPSecretKeyRing) obj;
secretKeyRing.encode(out);
} else if (obj instanceof PGPPublicKeyRing) {
publicKeyRing = (PGPPublicKeyRing) obj;
// try to get it as a PGPPublicKeyRing, if that fails try to get it as a SecretKeyRing
PGPPublicKeyRing publicKeyRing = ProviderHelper.getPGPPublicKeyRing(context,
keyRingIds.get(i));
if (publicKeyRing != null) {
publicKeyRing.encode(out);
} else {
continue;
PGPSecretKeyRing secretKeyRing = ProviderHelper.getPGPSecretKeyRing(context,
keyRingIds.get(i));
if (secretKeyRing != null) {
secretKeyRing.encode(out);
} else {
continue;
}
}
++numKeys;
}
@ -664,90 +663,69 @@ public class PGPMain {
return returnData;
}
public static void deleteKey(int keyRingId) {
mDatabase.deleteKeyRing(keyRingId);
}
// public static PGPKeyRing getKeyRing(int keyRingId) {
// return (PGPKeyRing) mDatabase.getKeyRing(keyRingId);
// }
public static PGPKeyRing getKeyRing(int keyRingId) {
return (PGPKeyRing) mDatabase.getKeyRing(keyRingId);
}
// public static PGPSecretKeyRing getSecretKeyRing(long keyId) {
// 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) {
byte[] data = mDatabase.getKeyRingDataFromKeyId(Id.database.type_secret, keyId);
if (data == null) {
return null;
}
return PGPConversionHelper.BytesToPGPSecretKeyRing(data);
}
// 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 PGPPublicKeyRing getPublicKeyRing(long keyId) {
byte[] data = mDatabase.getKeyRingDataFromKeyId(Id.database.type_public, keyId);
if (data == null) {
return null;
}
return PGPConversionHelper.BytesToPGPPublicKeyRing(data);
}
public static PGPSecretKey getSecretKey(long keyId) {
PGPSecretKeyRing keyRing = getSecretKeyRing(keyId);
if (keyRing == null) {
return null;
}
return keyRing.getSecretKey(keyId);
}
public static PGPPublicKey getPublicKey(long keyId) {
PGPPublicKeyRing keyRing = getPublicKeyRing(keyId);
if (keyRing == null) {
return null;
}
return keyRing.getPublicKey(keyId);
}
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 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,
boolean armored, long encryptionKeyIds[], long signatureKeyId,
@ -780,8 +758,8 @@ public class PGPMain {
}
if (signatureKeyId != Id.key.none) {
signingKeyRing = getSecretKeyRing(signatureKeyId);
signingKey = PGPHelper.getSigningKey(signatureKeyId);
signingKeyRing = ProviderHelper.getPGPSecretKeyRing(context, signatureKeyId);
signingKey = PGPHelper.getSigningKey(context, signatureKeyId);
if (signingKey == null) {
throw new ApgGeneralException(context.getString(R.string.error_signatureFailed));
}
@ -818,7 +796,7 @@ public class PGPMain {
cPk.addMethod(symmetricEncryptionGenerator);
}
for (int i = 0; i < encryptionKeyIds.length; ++i) {
PGPPublicKey key = PGPHelper.getEncryptPublicKey(encryptionKeyIds[i]);
PGPPublicKey key = PGPHelper.getEncryptPublicKey(context, encryptionKeyIds[i]);
if (key != null) {
JcePublicKeyKeyEncryptionMethodGenerator pubKeyEncryptionGenerator = new JcePublicKeyKeyEncryptionMethodGenerator(
@ -933,8 +911,8 @@ public class PGPMain {
throw new ApgGeneralException(context.getString(R.string.error_noSignatureKey));
}
signingKeyRing = getSecretKeyRing(signatureKeyId);
signingKey = PGPHelper.getSigningKey(signatureKeyId);
signingKeyRing = ProviderHelper.getPGPSecretKeyRing(context, signatureKeyId);
signingKey = PGPHelper.getSigningKey(context, signatureKeyId);
if (signingKey == null) {
armorOut.close();
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));
}
signingKeyRing = getSecretKeyRing(signatureKeyId);
signingKey = PGPHelper.getSigningKey(signatureKeyId);
signingKeyRing = ProviderHelper.getPGPSecretKeyRing(context, signatureKeyId);
signingKey = PGPHelper.getSigningKey(context, signatureKeyId);
if (signingKey == null) {
throw new ApgGeneralException(context.getString(R.string.error_signatureFailed));
}
@ -1149,9 +1127,9 @@ public class PGPMain {
if (passphrase == null || passphrase.length() <= 0) {
throw new ApgGeneralException("Unable to obtain passphrase");
} 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) {
throw new ApgGeneralException(context.getString(R.string.error_signatureFailed));
}
@ -1215,7 +1193,7 @@ public class PGPMain {
if (obj instanceof PGPPublicKeyEncryptedData) {
gotAsymmetricEncryption = true;
PGPPublicKeyEncryptedData pbe = (PGPPublicKeyEncryptedData) obj;
secretKey = getSecretKey(pbe.getKeyID());
secretKey = ProviderHelper.getPGPSecretKey(context, pbe.getKeyID());
if (secretKey != null) {
break;
}
@ -1336,7 +1314,7 @@ public class PGPMain {
Object obj = it.next();
if (obj instanceof PGPPublicKeyEncryptedData) {
PGPPublicKeyEncryptedData encData = (PGPPublicKeyEncryptedData) obj;
secretKey = getSecretKey(encData.getKeyID());
secretKey = ProviderHelper.getPGPSecretKey(context, encData.getKeyID());
if (secretKey != null) {
pbe = encData;
break;
@ -1397,7 +1375,7 @@ public class PGPMain {
PGPOnePassSignatureList sigList = (PGPOnePassSignatureList) dataChunk;
for (int i = 0; i < sigList.size(); ++i) {
signature = sigList.get(i);
signatureKey = getPublicKey(signature.getKeyID());
signatureKey = ProviderHelper.getPGPPublicKey(context, signature.getKeyID());
if (signatureKeyId == 0) {
signatureKeyId = signature.getKeyID();
}
@ -1407,7 +1385,8 @@ public class PGPMain {
signatureIndex = i;
signatureKeyId = signature.getKeyID();
String userId = null;
PGPPublicKeyRing sigKeyRing = getPublicKeyRing(signatureKeyId);
PGPPublicKeyRing sigKeyRing = ProviderHelper.getPGPPublicKeyRing(context,
signatureKeyId);
if (sigKeyRing != null) {
userId = PGPHelper.getMainUserId(PGPHelper.getMasterKey(sigKeyRing));
}
@ -1552,7 +1531,7 @@ public class PGPMain {
PGPPublicKey signatureKey = null;
for (int i = 0; i < sigList.size(); ++i) {
signature = sigList.get(i);
signatureKey = getPublicKey(signature.getKeyID());
signatureKey = ProviderHelper.getPGPPublicKey(context, signature.getKeyID());
if (signatureKeyId == 0) {
signatureKeyId = signature.getKeyID();
}
@ -1572,7 +1551,8 @@ public class PGPMain {
} else {
signatureKeyId = signature.getKeyID();
String userId = null;
PGPPublicKeyRing sigKeyRing = getPublicKeyRing(signatureKeyId);
PGPPublicKeyRing sigKeyRing = ProviderHelper.getPGPPublicKeyRing(context,
signatureKeyId);
if (sigKeyRing != null) {
userId = PGPHelper.getMainUserId(PGPHelper.getMasterKey(sigKeyRing));
}
@ -1799,15 +1779,13 @@ public class PGPMain {
}
public static String getVersion(Context context) {
if (VERSION != null) {
return VERSION;
}
String version = null;
try {
PackageInfo pi = context.getPackageManager().getPackageInfo(Constants.PACKAGE_NAME, 0);
VERSION = pi.versionName;
return VERSION;
version = pi.versionName;
return version;
} catch (NameNotFoundException e) {
// impossible!
Log.e(Constants.TAG, "Version could not be retrieved!", e);
return "0.0.0";
}
}

View file

@ -17,6 +17,8 @@
package org.thialfihar.android.apg.provider;
import org.thialfihar.android.apg.Constants;
import android.net.Uri;
import android.provider.BaseColumns;
@ -32,10 +34,12 @@ import android.provider.BaseColumns;
*/
public class ApgContract {
// APG1: all rows had a "c_" prefix
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 WHO_ID = "who_id";
String WHO_ID = "who_id"; // TODO: is this used?
String KEY_RING_DATA = "key_ring_data"; // blob
}
@ -51,8 +55,8 @@ public class ApgContract {
String CREATION = "creation";
String EXPIRY = "expiry";
String KEY_RING_ROW_ID = "key_ring_id"; // foreign key to key_rings._ID
String KEY_DATA = "key_data";
String RANK = "key_data"; // blob
String KEY_DATA = "key_data"; // blob
String RANK = "rank"; // APG1: this was "key_data", TODO: Bug? Is this even used?
}
interface UserIdsColumns {
@ -66,8 +70,8 @@ public class ApgContract {
public static final int SECRET = 1;
}
public static final String CONTENT_AUTHORITY = "org.thialfihar.android.apg.provider";
// public static final String CONTENT_AUTHORITY = Constants.PACKAGE_NAME;
// APG1: "org.thialfihar.android.apg.provider";
public static final String CONTENT_AUTHORITY = Constants.PACKAGE_NAME;
private static final Uri BASE_CONTENT_URI = Uri.parse("content://" + CONTENT_AUTHORITY);

View file

@ -30,18 +30,20 @@ import android.provider.BaseColumns;
import org.thialfihar.android.apg.util.Log;
public class ApgDatabase extends SQLiteOpenHelper {
// APG1: "apg"
private static final String DATABASE_NAME = "apg.db";
// Last APG 1 db version was 2
// APG1: 2
private static final int DATABASE_VERSION = 3;
public interface Tables {
String KEY_RINGS = "key_rings";
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
+ " (" + 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
+ " INTEGER, " + KeyRingsColumns.KEY_RING_DATA + " BLOB)";
@ -55,7 +57,7 @@ public class ApgDatabase extends SQLiteOpenHelper {
+ " INTEGER REFERENCES " + Tables.KEY_RINGS + " ON DELETE CASCADE, "
+ 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
+ " INTEGER REFERENCES " + Tables.KEYS + " ON DELETE CASCADE, "
+ 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);
switch (version) {
case 1:
break;
default:
break;

View file

@ -54,8 +54,8 @@ public class ApgProvider extends ContentProvider {
private static final UriMatcher sUriMatcher = buildUriMatcher();
private static final int PUBLIC_KEY_RING = 101;
private static final int PUBLIC_KEY_RING_ID = 102;
private static final int PUBLIC_KEY_RING_BY_KEY_ID = 103;
private static final int PUBLIC_KEY_RING_ROW_ID = 102;
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_KEY = 111;
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 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_EMAILS = 204;
private static final int SECRET_KEY_RING_KEY = 211;
@ -95,7 +95,7 @@ public class ApgProvider extends ContentProvider {
PUBLIC_KEY_RING);
matcher.addURI(authority,
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 + "/"
+ ApgContract.PATH_BY_KEY_ID + "/*", PUBLIC_KEY_RING_BY_KEY_ID);
matcher.addURI(authority, ApgContract.BASE_KEY_RINGS + "/" + ApgContract.PATH_PUBLIC + "/"
@ -143,7 +143,7 @@ public class ApgProvider extends ContentProvider {
SECRET_KEY_RING);
matcher.addURI(authority,
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 + "/"
+ ApgContract.PATH_BY_KEY_ID + "/*", SECRET_KEY_RING_BY_KEY_ID);
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:
return PublicKeyRings.CONTENT_TYPE;
case PUBLIC_KEY_RING_ID:
case PUBLIC_KEY_RING_ROW_ID:
case PUBLIC_KEY_RING_BY_KEY_ID:
return PublicKeyRings.CONTENT_ITEM_TYPE;
@ -228,7 +228,7 @@ public class ApgProvider extends ContentProvider {
case SECRET_KEY_RING_BY_EMAILS:
return SecretKeyRings.CONTENT_TYPE;
case SECRET_KEY_RING_ID:
case SECRET_KEY_RING_ROW_ID:
case SECRET_KEY_RING_BY_KEY_ID:
return SecretKeyRings.CONTENT_ITEM_TYPE;
@ -259,7 +259,7 @@ public class ApgProvider extends ContentProvider {
int type;
switch (match) {
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_EMAILS:
case PUBLIC_KEY_RING_KEY:
@ -270,7 +270,7 @@ public class ApgProvider extends ContentProvider {
break;
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_EMAILS:
case SECRET_KEY_RING_KEY:
@ -304,9 +304,10 @@ public class ApgProvider extends ContentProvider {
qb.appendWhere(Tables.KEY_RINGS + "." + KeyRingsColumns.TYPE + " = " + getKeyType(match));
switch (match) {
case PUBLIC_KEY_RING_ID:
case SECRET_KEY_RING_ID:
qb.appendWhere(" AND " + Tables.KEY_RINGS + "." + KeyRingsColumns.MASTER_KEY_ID + " = ");
case PUBLIC_KEY_RING_ROW_ID:
case SECRET_KEY_RING_ROW_ID:
qb.appendWhere(" AND " + Tables.KEY_RINGS + "." + KeyRingsColumns.MASTER_KEY_ROW_ID
+ " = ");
qb.appendWhereEscapeString(uri.getPathSegments().get(2));
// break omitted intentionally
@ -315,20 +316,19 @@ public class ApgProvider extends ContentProvider {
case SECRET_KEY_RING:
qb.setTables(Tables.KEY_RINGS + " INNER JOIN " + Tables.KEYS + " ON " + "("
+ Tables.KEY_RINGS + "." + BaseColumns._ID + " = " + Tables.KEYS + "."
+ KeysColumns.KEY_RING_ID + " AND " + Tables.KEYS + "."
+ KeysColumns.IS_MASTER_KEY + " = '1'" + ") " + " INNER JOIN "
+ Tables.USER_IDS + " ON " + "(" + Tables.KEYS + "." + BaseColumns._ID + " = "
+ Tables.USER_IDS + "." + UserIdsColumns.KEY_ID + " AND " + Tables.USER_IDS
+ "." + UserIdsColumns.RANK + " = '0') ");
+ KeysColumns.KEY_RING_ROW_ID + " AND " + Tables.KEYS + "."
+ KeysColumns.IS_MASTER_KEY + " = '1'" + ") " + " INNER JOIN " + Tables.USERS
+ " ON " + "(" + Tables.KEYS + "." + BaseColumns._ID + " = " + Tables.USERS
+ "." + UserIdsColumns.KEY_ROW_ID + " AND " + Tables.USERS + "."
+ UserIdsColumns.RANK + " = '0') ");
projectionMap.put(BaseColumns._ID, Tables.KEY_RINGS + "." + BaseColumns._ID);
projectionMap.put(KeyRingsColumns.MASTER_KEY_ID, Tables.KEY_RINGS + "."
+ KeyRingsColumns.MASTER_KEY_ID);
projectionMap.put(UserIdsColumns.USER_ID, Tables.USER_IDS + "."
+ UserIdsColumns.USER_ID);
projectionMap.put(KeyRingsColumns.MASTER_KEY_ROW_ID, Tables.KEY_RINGS + "."
+ KeyRingsColumns.MASTER_KEY_ROW_ID);
projectionMap.put(UserIdsColumns.USER_ID, Tables.USERS + "." + UserIdsColumns.USER_ID);
if (TextUtils.isEmpty(sortOrder)) {
sortOrder = Tables.USER_IDS + "." + UserIdsColumns.USER_ID + " ASC";
sortOrder = Tables.USERS + "." + UserIdsColumns.USER_ID + " ASC";
}
break;
@ -337,19 +337,18 @@ public class ApgProvider extends ContentProvider {
case PUBLIC_KEY_RING_BY_KEY_ID:
qb.setTables(Tables.KEYS + " AS tmp INNER JOIN " + Tables.KEY_RINGS + " ON ("
+ Tables.KEY_RINGS + "." + BaseColumns._ID + " = " + "tmp."
+ KeysColumns.KEY_RING_ID + ")" + " INNER JOIN " + Tables.KEYS + " ON " + "("
+ Tables.KEY_RINGS + "." + BaseColumns._ID + " = " + Tables.KEYS + "."
+ KeysColumns.KEY_RING_ID + " AND " + Tables.KEYS + "."
+ KeysColumns.IS_MASTER_KEY + " = '1'" + ") " + " INNER JOIN "
+ Tables.USER_IDS + " ON " + "(" + Tables.KEYS + "." + BaseColumns._ID + " = "
+ Tables.USER_IDS + "." + UserIdsColumns.KEY_ID + " AND " + Tables.USER_IDS
+ "." + UserIdsColumns.RANK + " = '0') ");
+ KeysColumns.KEY_RING_ROW_ID + ")" + " INNER JOIN " + Tables.KEYS + " ON "
+ "(" + Tables.KEY_RINGS + "." + BaseColumns._ID + " = " + Tables.KEYS + "."
+ KeysColumns.KEY_RING_ROW_ID + " AND " + Tables.KEYS + "."
+ KeysColumns.IS_MASTER_KEY + " = '1'" + ") " + " INNER JOIN " + Tables.USERS
+ " ON " + "(" + Tables.KEYS + "." + BaseColumns._ID + " = " + Tables.USERS
+ "." + UserIdsColumns.KEY_ROW_ID + " AND " + Tables.USERS + "."
+ UserIdsColumns.RANK + " = '0') ");
projectionMap.put(BaseColumns._ID, Tables.KEY_RINGS + "." + BaseColumns._ID);
projectionMap.put(KeyRingsColumns.MASTER_KEY_ID, Tables.KEY_RINGS + "."
+ KeyRingsColumns.MASTER_KEY_ID);
projectionMap.put(UserIdsColumns.USER_ID, Tables.USER_IDS + "."
+ UserIdsColumns.USER_ID);
projectionMap.put(KeyRingsColumns.MASTER_KEY_ROW_ID, Tables.KEY_RINGS + "."
+ KeyRingsColumns.MASTER_KEY_ROW_ID);
projectionMap.put(UserIdsColumns.USER_ID, Tables.USERS + "." + UserIdsColumns.USER_ID);
qb.appendWhere(" AND tmp." + KeysColumns.KEY_ID + " = ");
qb.appendWhereEscapeString(uri.getPathSegments().get(3));
@ -360,17 +359,16 @@ public class ApgProvider extends ContentProvider {
case PUBLIC_KEY_RING_BY_EMAILS:
qb.setTables(Tables.KEY_RINGS + " INNER JOIN " + Tables.KEYS + " ON " + "("
+ Tables.KEY_RINGS + "." + BaseColumns._ID + " = " + Tables.KEYS + "."
+ KeysColumns.KEY_RING_ID + " AND " + Tables.KEYS + "."
+ KeysColumns.IS_MASTER_KEY + " = '1'" + ") " + " INNER JOIN "
+ Tables.USER_IDS + " ON " + "(" + Tables.KEYS + "." + BaseColumns._ID + " = "
+ Tables.USER_IDS + "." + UserIdsColumns.KEY_ID + " AND " + Tables.USER_IDS
+ "." + UserIdsColumns.RANK + " = '0') ");
+ KeysColumns.KEY_RING_ROW_ID + " AND " + Tables.KEYS + "."
+ KeysColumns.IS_MASTER_KEY + " = '1'" + ") " + " INNER JOIN " + Tables.USERS
+ " ON " + "(" + Tables.KEYS + "." + BaseColumns._ID + " = " + Tables.USERS
+ "." + UserIdsColumns.KEY_ROW_ID + " AND " + Tables.USERS + "."
+ UserIdsColumns.RANK + " = '0') ");
projectionMap.put(BaseColumns._ID, Tables.KEY_RINGS + "." + BaseColumns._ID);
projectionMap.put(KeyRingsColumns.MASTER_KEY_ID, Tables.KEY_RINGS + "."
+ KeyRingsColumns.MASTER_KEY_ID);
projectionMap.put(UserIdsColumns.USER_ID, Tables.USER_IDS + "."
+ UserIdsColumns.USER_ID);
projectionMap.put(KeyRingsColumns.MASTER_KEY_ROW_ID, Tables.KEY_RINGS + "."
+ KeyRingsColumns.MASTER_KEY_ROW_ID);
projectionMap.put(UserIdsColumns.USER_ID, Tables.USERS + "." + UserIdsColumns.USER_ID);
String emails = uri.getPathSegments().get(3);
String chunks[] = emails.split(" *, *");
@ -391,7 +389,7 @@ public class ApgProvider extends ContentProvider {
if (gotCondition) {
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 + "))");
}
@ -450,7 +448,7 @@ public class ApgProvider extends ContentProvider {
break;
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));
break;
@ -470,7 +468,7 @@ public class ApgProvider extends ContentProvider {
break;
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));
break;
@ -498,16 +496,13 @@ public class ApgProvider extends ContentProvider {
final int match = sUriMatcher.match(uri);
switch (match) {
case PUBLIC_KEY_RING_ID:
// delete corresponding keys and userids
// db.delete(Tables.KEYS, whereClause, whereArgs)
// TODO
case PUBLIC_KEY_RING_ROW_ID:
// corresponding keys and userids are deleted by ON DELETE CASCADE
count = db.delete(Tables.KEY_RINGS,
buildDefaultSelection(uri, KeyTypes.PUBLIC, selection), selectionArgs);
break;
case SECRET_KEY_RING_ID:
// delete corresponding keys and userids
// TODO
case SECRET_KEY_RING_ROW_ID:
// corresponding keys and userids are deleted by ON DELETE CASCADE
count = db.delete(Tables.KEY_RINGS,
buildDefaultSelection(uri, KeyTypes.SECRET, selection), selectionArgs);
break;
@ -532,13 +527,13 @@ public class ApgProvider extends ContentProvider {
try {
final int match = sUriMatcher.match(uri);
switch (match) {
case PUBLIC_KEY_RING_ID:
case PUBLIC_KEY_RING_ROW_ID:
count = db.update(Tables.KEY_RINGS, values,
buildDefaultSelection(uri, KeyTypes.PUBLIC, selection), selectionArgs);
break;
case SECRET_KEY_RING_ID:
case SECRET_KEY_RING_ROW_ID:
count = db.update(Tables.KEY_RINGS, values,
buildDefaultSelection(uri, KeyTypes.PUBLIC, selection), selectionArgs);
buildDefaultSelection(uri, KeyTypes.SECRET, selection), selectionArgs);
break;
default:
throw new UnsupportedOperationException("Unknown uri: " + uri);

View file

@ -1,79 +1,207 @@
package org.thialfihar.android.apg.provider;
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.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.provider.ApgContract.PublicKeyRings;
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.util.Log;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
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 rowId
* @return
*/
public static void deleteKey(Context context, long rowId) {
context.getContentResolver().delete(PublicKeys.buildPublicKeysUri(Long.toString(rowId)),
null, null);
context.getContentResolver().delete(SecretKeys.buildSecretKeysUri(Long.toString(rowId)),
null, null);
public static PGPPublicKeyRing getPGPPublicKeyRing(Context context, long rowId) {
Uri queryUri = PublicKeyRings.buildPublicKeyRingsUri(Long.toString(rowId));
Cursor cursor = context.getContentResolver()
.query(queryUri, new String[] { PublicKeyRings._ID, PublicKeyRings.KEY_RING_DATA },
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);
}
}

View file

@ -35,7 +35,6 @@ import org.spongycastle.openpgp.PGPSecretKeyRing;
import org.thialfihar.android.apg.Constants;
import org.thialfihar.android.apg.Id;
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.OtherHelper;
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.PGPConversionHelper;
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.InputData;
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,
deleteFile));
} catch (IOException e) {
throw new PGPMain.ApgGeneralException(getString(R.string.error_fileDeleteFailed,
deleteFile));
throw new PGPMain.ApgGeneralException(getString(
R.string.error_fileDeleteFailed, deleteFile));
}
/* Output */
@ -715,9 +714,11 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
Vector<Integer> keyRingIds = new Vector<Integer>();
if (exportAll) {
keyRingIds = PGPMain
.getKeyRingIds(keyType == Id.type.public_key ? Id.database.type_public
: Id.database.type_secret);
if (keyType == Id.type.public_key) {
keyRingIds = ProviderHelper.getPublicKeyRingsRowIds(this);
} else {
keyRingIds = ProviderHelper.getSecretKeyRingsRowIds(this);
}
} else {
keyRingIds.add(keyRingId);
}
@ -742,8 +743,8 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
/* Operation */
HkpKeyServer server = new HkpKeyServer(keyServer);
PGPKeyRing keyring = PGPMain.getKeyRing(keyRingId);
if (keyring != null && keyring instanceof PGPPublicKeyRing) {
PGPPublicKeyRing keyring = ProviderHelper.getPGPPublicKeyRing(this, keyRingId);
if (keyring != null) {
boolean uploaded = PGPMain.uploadKeyRingToServer(server,
(PGPPublicKeyRing) keyring);
if (!uploaded) {

View file

@ -24,8 +24,8 @@ import org.spongycastle.openpgp.PGPSecretKeyRing;
import org.thialfihar.android.apg.Constants;
import org.thialfihar.android.apg.Id;
import org.thialfihar.android.apg.helper.PGPHelper;
import org.thialfihar.android.apg.helper.PGPMain;
import org.thialfihar.android.apg.helper.Preferences;
import org.thialfihar.android.apg.provider.ProviderHelper;
import android.app.AlarmManager;
import android.app.PendingIntent;
@ -88,7 +88,7 @@ public class PassphraseCacheService extends Service {
// try to get real key id
long realId = keyId;
if (realId != Id.key.symmetric) {
PGPSecretKeyRing keyRing = PGPMain.getSecretKeyRing(keyId);
PGPSecretKeyRing keyRing = ProviderHelper.getPGPSecretKeyRing(context, keyId);
if (keyRing == null) {
return null;
}

View file

@ -24,6 +24,7 @@ import org.thialfihar.android.apg.helper.FileHelper;
import org.thialfihar.android.apg.helper.OtherHelper;
import org.thialfihar.android.apg.helper.PGPHelper;
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.ApgService;
import org.thialfihar.android.apg.service.PassphraseCacheService;
@ -333,7 +334,8 @@ public class DecryptActivity extends SherlockFragmentActivity {
if (mSignatureKeyId == 0) {
return;
}
PGPPublicKeyRing key = PGPMain.getPublicKeyRing(mSignatureKeyId);
PGPPublicKeyRing key = ProviderHelper.getPGPPublicKeyRing(DecryptActivity.this,
mSignatureKeyId);
if (key != null) {
Intent intent = new Intent(DecryptActivity.this, KeyServerQueryActivity.class);
intent.setAction(KeyServerQueryActivity.ACTION_LOOK_UP_KEY_ID);
@ -655,7 +657,8 @@ public class DecryptActivity extends SherlockFragmentActivity {
try {
setSecretKeyId(PGPMain.getDecryptionKeyId(this, inStream));
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;
} catch (PGPMain.NoAsymmetricEncryptionException e) {

View file

@ -25,6 +25,7 @@ import org.thialfihar.android.apg.helper.OtherHelper;
import org.thialfihar.android.apg.helper.PGPHelper;
import org.thialfihar.android.apg.helper.PGPMain;
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.ApgService;
import org.thialfihar.android.apg.ui.dialog.SetPassphraseDialogFragment;
@ -308,7 +309,7 @@ public class EditKeyActivity extends SherlockFragmentActivity {
if (keyId != 0) {
PGPSecretKey masterKey = null;
mKeyRing = PGPMain.getSecretKeyRing(keyId);
mKeyRing = ProviderHelper.getPGPSecretKeyRing(this, keyId);
if (mKeyRing != null) {
masterKey = PGPHelper.getMasterKey(mKeyRing);
for (PGPSecretKey key : new IterableIterator<PGPSecretKey>(
@ -460,7 +461,8 @@ public class EditKeyActivity extends SherlockFragmentActivity {
* @param userIdsView
* @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>();
ViewGroup userIdEditors = userIdsView.getEditors();
@ -472,7 +474,8 @@ public class EditKeyActivity extends SherlockFragmentActivity {
try {
userId = editor.getValue();
} 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) {
throw new PGPMain.ApgGeneralException(
this.getString(R.string.error_userIdNeedsAnEmailAddress));
@ -497,7 +500,8 @@ public class EditKeyActivity extends SherlockFragmentActivity {
}
if (!gotMainUserId) {
throw new PGPMain.ApgGeneralException(getString(R.string.error_mainUserIdMustNotBeEmpty));
throw new PGPMain.ApgGeneralException(
getString(R.string.error_mainUserIdMustNotBeEmpty));
}
return userIds;
@ -509,7 +513,8 @@ public class EditKeyActivity extends SherlockFragmentActivity {
* @param keysView
* @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>();
ViewGroup keyEditors = keysView.getEditors();
@ -532,7 +537,8 @@ public class EditKeyActivity extends SherlockFragmentActivity {
* @param keysView
* @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>();
ViewGroup keyEditors = keysView.getEditors();

View file

@ -28,6 +28,7 @@ import org.thialfihar.android.apg.helper.OtherHelper;
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.provider.ProviderHelper;
import org.thialfihar.android.apg.service.ApgServiceHandler;
import org.thialfihar.android.apg.service.ApgService;
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 encryptionKeyIds[] = extras.getLongArray(EXTRA_ENCRYPTION_KEY_IDS);
if (signatureKeyId != 0) {
PGPSecretKeyRing keyRing = PGPMain.getSecretKeyRing(signatureKeyId);
PGPSecretKeyRing keyRing = ProviderHelper.getPGPSecretKeyRing(this, signatureKeyId);
PGPSecretKey masterKey = null;
if (keyRing != null) {
masterKey = PGPHelper.getMasterKey(keyRing);
@ -456,7 +457,8 @@ public class EncryptActivity extends SherlockFragmentActivity {
if (encryptionKeyIds != null) {
Vector<Long> goodIds = new Vector<Long>();
for (int i = 0; i < encryptionKeyIds.length; ++i) {
PGPPublicKeyRing keyRing = PGPMain.getPublicKeyRing(encryptionKeyIds[i]);
PGPPublicKeyRing keyRing = ProviderHelper.getPGPPublicKeyRing(this,
encryptionKeyIds[i]);
PGPPublicKey masterKey = null;
if (keyRing == null) {
continue;
@ -956,7 +958,7 @@ public class EncryptActivity extends SherlockFragmentActivity {
} else {
String uid = getResources().getString(R.string.unknownUserId);
String uidExtra = "";
PGPSecretKeyRing keyRing = PGPMain.getSecretKeyRing(getSecretKeyId());
PGPSecretKeyRing keyRing = ProviderHelper.getPGPSecretKeyRing(this, getSecretKeyId());
if (keyRing != null) {
PGPSecretKey key = PGPHelper.getMasterKey(keyRing);
if (key != null) {

View file

@ -601,7 +601,7 @@ public class KeyListActivity extends SherlockFragmentActivity {
if (masterKeyId != -1) {
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
}, UserIds.KEY_ID + " = ? AND " + UserIds.RANK + " > 0", new String[] { ""
+ masterKeyId }, null, null, UserIds.RANK + " ASC");

View file

@ -22,6 +22,7 @@ import org.thialfihar.android.apg.Id;
import org.thialfihar.android.apg.R;
import org.thialfihar.android.apg.helper.PGPHelper;
import org.thialfihar.android.apg.helper.PGPMain;
import org.thialfihar.android.apg.provider.ProviderHelper;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
@ -115,8 +116,8 @@ public class PublicKeyListActivity extends KeyListActivity {
mSelectedItem = groupPosition;
final int keyRingId = mListAdapter.getKeyRingId(groupPosition);
long keyId = 0;
Object keyRing = PGPMain.getKeyRing(keyRingId);
if (keyRing != null && keyRing instanceof PGPPublicKeyRing) {
PGPPublicKeyRing keyRing = ProviderHelper.getPGPPublicKeyRing(this, keyRingId);
if (keyRing != null) {
keyId = PGPHelper.getMasterKey((PGPPublicKeyRing) keyRing).getKeyID();
}
if (keyId == 0) {
@ -148,8 +149,8 @@ public class PublicKeyListActivity extends KeyListActivity {
mSelectedItem = groupPosition;
final int keyRingId = mListAdapter.getKeyRingId(groupPosition);
long keyId = 0;
Object keyRing = PGPMain.getKeyRing(keyRingId);
if (keyRing != null && keyRing instanceof PGPPublicKeyRing) {
PGPPublicKeyRing keyRing = ProviderHelper.getPGPPublicKeyRing(this, keyRingId);
if (keyRing != null) {
keyId = PGPHelper.getMasterKey((PGPPublicKeyRing) keyRing).getKeyID();
}

View file

@ -25,6 +25,7 @@ import org.thialfihar.android.apg.Id;
import org.thialfihar.android.apg.R;
import org.thialfihar.android.apg.helper.PGPMain;
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.ApgServiceHandler;
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
*/
private void initiateSigning() {
PGPPublicKeyRing pubring = PGPMain.getPublicKeyRing(mPubKeyId);
PGPPublicKeyRing pubring = ProviderHelper.getPGPPublicKeyRing(this, mPubKeyId);
if (pubring != null) {
// if we have already signed this key, dont bother doing it again
boolean alreadySigned = false;

View file

@ -23,6 +23,7 @@ import org.thialfihar.android.apg.Id;
import org.thialfihar.android.apg.R;
import org.thialfihar.android.apg.helper.PGPHelper;
import org.thialfihar.android.apg.helper.PGPMain;
import org.thialfihar.android.apg.provider.ProviderHelper;
import org.thialfihar.android.apg.util.Log;
import android.app.AlertDialog;
@ -93,8 +94,11 @@ public class DeleteKeyDialogFragment extends DialogFragment {
builder.setIcon(android.R.drawable.ic_dialog_alert);
builder.setPositiveButton(R.string.btn_delete, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// deleteKey(deleteKeyRingId);
PGPMain.deleteKey(deleteKeyRingId);
if (keyType == Id.type.public_key) {
ProviderHelper.deletePublicKeyRing(activity, deleteKeyRingId);
} else {
ProviderHelper.deleteSecretKeyRing(activity, deleteKeyRingId);
}
dismiss();