deliver the user id as well for secret key selection, so k9mail can use it to display the signature key

This commit is contained in:
Thialfihar 2010-06-01 14:59:06 +00:00
parent 4229b94270
commit 5547f61e4f
4 changed files with 54 additions and 13 deletions

View File

@ -81,6 +81,8 @@ import org.bouncycastle2.openpgp.PGPSignatureSubpacketVector;
import org.bouncycastle2.openpgp.PGPUtil; import org.bouncycastle2.openpgp.PGPUtil;
import org.thialfihar.android.apg.provider.Database; import org.thialfihar.android.apg.provider.Database;
import org.thialfihar.android.apg.provider.KeyRings; import org.thialfihar.android.apg.provider.KeyRings;
import org.thialfihar.android.apg.provider.Keys;
import org.thialfihar.android.apg.provider.UserIds;
import org.thialfihar.android.apg.ui.widget.KeyEditor; import org.thialfihar.android.apg.ui.widget.KeyEditor;
import org.thialfihar.android.apg.ui.widget.SectionView; import org.thialfihar.android.apg.ui.widget.SectionView;
import org.thialfihar.android.apg.ui.widget.UserIdEditor; import org.thialfihar.android.apg.ui.widget.UserIdEditor;
@ -116,6 +118,7 @@ public class Apg {
public static final String EXTRA_SIGNATURE_USER_ID = "signatureUserId"; public static final String EXTRA_SIGNATURE_USER_ID = "signatureUserId";
public static final String EXTRA_SIGNATURE_SUCCESS = "signatureSuccess"; public static final String EXTRA_SIGNATURE_SUCCESS = "signatureSuccess";
public static final String EXTRA_SIGNATURE_UNKNOWN = "signatureUnknown"; public static final String EXTRA_SIGNATURE_UNKNOWN = "signatureUnknown";
public static final String EXTRA_USER_ID = "userId";
public static final String EXTRA_KEY_ID = "keyId"; public static final String EXTRA_KEY_ID = "keyId";
public static final String EXTRA_REPLY_TO = "replyTo"; public static final String EXTRA_REPLY_TO = "replyTo";
public static final String EXTRA_SEND_TO = "sendTo"; public static final String EXTRA_SEND_TO = "sendTo";
@ -1042,6 +1045,41 @@ public class Apg {
return keyIds; 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, public static void encrypt(Context context,
InputStream inStream, OutputStream outStream, InputStream inStream, OutputStream outStream,
long dataLength, long dataLength,

View File

@ -346,7 +346,7 @@ public class EncryptActivity extends BaseActivity {
if (mMessage.getText().length() > 0 && if (mMessage.getText().length() > 0 &&
((mEncryptionKeyIds != null && ((mEncryptionKeyIds != null &&
mEncryptionKeyIds.length > 0) || mEncryptionKeyIds.length > 0) ||
getSecretKeyId() > 0)) { getSecretKeyId() != 0)) {
encryptClicked(); encryptClicked();
} }
} }
@ -467,7 +467,7 @@ public class EncryptActivity extends BaseActivity {
return; return;
} }
} else { } else {
boolean encryptIt = mEncryptionKeyIds != null && mEncryptionKeyIds.length > 0; boolean encryptIt = (mEncryptionKeyIds != null && mEncryptionKeyIds.length > 0);
// for now require at least one form of encryption for files // for now require at least one form of encryption for files
if (!encryptIt && mEncryptTarget == Id.target.file) { if (!encryptIt && mEncryptTarget == Id.target.file) {
Toast.makeText(this, R.string.selectEncryptionKey, Toast.LENGTH_SHORT).show(); Toast.makeText(this, R.string.selectEncryptionKey, Toast.LENGTH_SHORT).show();
@ -537,7 +537,7 @@ public class EncryptActivity extends BaseActivity {
} else { } else {
encryptionKeyIds = mEncryptionKeyIds; encryptionKeyIds = mEncryptionKeyIds;
signatureKeyId = getSecretKeyId(); signatureKeyId = getSecretKeyId();
signOnly = mEncryptionKeyIds == null || mEncryptionKeyIds.length == 0; signOnly = (mEncryptionKeyIds == null || mEncryptionKeyIds.length == 0);
} }
if (mEncryptTarget == Id.target.file) { if (mEncryptTarget == Id.target.file) {
@ -558,7 +558,9 @@ public class EncryptActivity extends BaseActivity {
} else { } else {
String message = mMessage.getText().toString(); String message = mMessage.getText().toString();
if (signOnly) { if (signOnly &&
!(mIntent != null &&
mIntent.getAction().equals(Apg.Intent.ENCRYPT_AND_RETURN))) {
// fix the message a bit, trailing spaces and newlines break stuff, // fix the message a bit, trailing spaces and newlines break stuff,
// because GMail sends as HTML and such things fuck up the signature, // because GMail sends as HTML and such things fuck up the signature,
// TODO: things like "<" and ">" also fuck up the signature // TODO: things like "<" and ">" also fuck up the signature

View File

@ -44,6 +44,7 @@ public class SelectSecretKeyListActivity extends BaseActivity {
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
Intent data = new Intent(); Intent data = new Intent();
data.putExtra(Apg.EXTRA_KEY_ID, id); data.putExtra(Apg.EXTRA_KEY_ID, id);
data.putExtra(Apg.EXTRA_USER_ID, Apg.getMainUserId(id, Id.database.type_secret));
setResult(RESULT_OK, data); setResult(RESULT_OK, data);
finish(); finish();
} }

View File

@ -248,9 +248,9 @@ public class Database extends SQLiteOpenHelper {
seenIdsStr += id; seenIdsStr += id;
} }
mDb.delete(Keys.TABLE_NAME, mDb.delete(Keys.TABLE_NAME,
Keys.KEY_RING_ID + " = ? AND " + Keys.KEY_RING_ID + " = ? AND " +
Keys._ID + " NOT IN (" + seenIdsStr + ")", Keys._ID + " NOT IN (" + seenIdsStr + ")",
new String[] { "" + rowId }); new String[] { "" + rowId });
mDb.setTransactionSuccessful(); mDb.setTransactionSuccessful();
mDb.endTransaction(); mDb.endTransaction();
@ -289,9 +289,9 @@ public class Database extends SQLiteOpenHelper {
seenIdsStr += id; seenIdsStr += id;
} }
mDb.delete(Keys.TABLE_NAME, mDb.delete(Keys.TABLE_NAME,
Keys.KEY_RING_ID + " = ? AND " + Keys.KEY_RING_ID + " = ? AND " +
Keys._ID + " NOT IN (" + seenIdsStr + ")", Keys._ID + " NOT IN (" + seenIdsStr + ")",
new String[] { "" + rowId }); new String[] { "" + rowId });
mDb.setTransactionSuccessful(); mDb.setTransactionSuccessful();
mDb.endTransaction(); mDb.endTransaction();
@ -340,9 +340,9 @@ public class Database extends SQLiteOpenHelper {
seenIdsStr += id; seenIdsStr += id;
} }
mDb.delete(UserIds.TABLE_NAME, mDb.delete(UserIds.TABLE_NAME,
UserIds.KEY_ID + " = ? AND " + UserIds.KEY_ID + " = ? AND " +
UserIds._ID + " NOT IN (" + seenIdsStr + ")", UserIds._ID + " NOT IN (" + seenIdsStr + ")",
new String[] { "" + rowId }); new String[] { "" + rowId });
return (int)rowId; return (int)rowId;
} }