Rearrange too long lines

This commit is contained in:
Thialfihar 2014-04-02 01:56:58 +02:00
parent d5983b324f
commit 82e5d14fb1
28 changed files with 228 additions and 145 deletions

View File

@ -684,7 +684,8 @@ public class PgpDecryptVerify {
} }
private static boolean verifyPrimaryKeyBinding(PGPSignatureSubpacketVector pkts, private static boolean verifyPrimaryKeyBinding(PGPSignatureSubpacketVector pkts,
PGPPublicKey masterPublicKey, PGPPublicKey signingPublicKey) { PGPPublicKey masterPublicKey,
PGPPublicKey signingPublicKey) {
boolean validPrimaryKeyBinding = false; boolean validPrimaryKeyBinding = false;
JcaPGPContentVerifierBuilderProvider contentVerifierBuilderProvider = JcaPGPContentVerifierBuilderProvider contentVerifierBuilderProvider =
new JcaPGPContentVerifierBuilderProvider() new JcaPGPContentVerifierBuilderProvider()

View File

@ -51,9 +51,9 @@ public class PgpHelper {
".*?(-----BEGIN PGP MESSAGE-----.*?-----END PGP MESSAGE-----).*", Pattern.DOTALL); ".*?(-----BEGIN PGP MESSAGE-----.*?-----END PGP MESSAGE-----).*", Pattern.DOTALL);
public static final Pattern PGP_CLEARTEXT_SIGNATURE = Pattern public static final Pattern PGP_CLEARTEXT_SIGNATURE = Pattern
.compile( .compile(".*?(-----BEGIN PGP SIGNED MESSAGE-----.*?-----" +
".*?(-----BEGIN PGP SIGNED MESSAGE-----.*?-----BEGIN PGP SIGNATURE-----.*?-----END PGP SIGNATURE-----).*", "BEGIN PGP SIGNATURE-----.*?-----END PGP SIGNATURE-----).*",
Pattern.DOTALL); Pattern.DOTALL);
public static final Pattern PGP_PUBLIC_KEY = Pattern.compile( public static final Pattern PGP_PUBLIC_KEY = Pattern.compile(
".*?(-----BEGIN PGP PUBLIC KEY BLOCK-----.*?-----END PGP PUBLIC KEY BLOCK-----).*", ".*?(-----BEGIN PGP PUBLIC KEY BLOCK-----.*?-----END PGP PUBLIC KEY BLOCK-----).*",

View File

@ -168,7 +168,8 @@ public class PgpImportExport {
return returnData; return returnData;
} }
public Bundle exportKeyRings(ArrayList<Long> publicKeyRingMasterIds, ArrayList<Long> secretKeyRingMasterIds, public Bundle exportKeyRings(ArrayList<Long> publicKeyRingMasterIds,
ArrayList<Long> secretKeyRingMasterIds,
OutputStream outStream) throws PgpGeneralException, OutputStream outStream) throws PgpGeneralException,
PGPException, IOException { PGPException, IOException {
Bundle returnData = new Bundle(); Bundle returnData = new Bundle();

View File

@ -196,8 +196,8 @@ public class PgpKeyOperation {
} }
public PGPSecretKeyRing changeSecretKeyPassphrase(PGPSecretKeyRing keyRing, String oldPassPhrase, public PGPSecretKeyRing changeSecretKeyPassphrase(PGPSecretKeyRing keyRing, String oldPassPhrase,
String newPassPhrase) throws IOException, PGPException, String newPassPhrase)
NoSuchProviderException { throws IOException, PGPException, NoSuchProviderException {
updateProgress(R.string.progress_building_key, 0, 100); updateProgress(R.string.progress_building_key, 0, 100);
if (oldPassPhrase == null) { if (oldPassPhrase == null) {
@ -270,13 +270,16 @@ public class PgpKeyOperation {
GregorianCalendar expiryDate = keysExpiryDates.get(0); GregorianCalendar expiryDate = keysExpiryDates.get(0);
//note that the below, (a/c) - (b/c) is *not* the same as (a - b) /c //note that the below, (a/c) - (b/c) is *not* the same as (a - b) /c
//here we purposefully ignore partial days in each date - long type has no fractional part! //here we purposefully ignore partial days in each date - long type has no fractional part!
long numDays = (expiryDate.getTimeInMillis() / 86400000) - (creationDate.getTimeInMillis() / 86400000); long numDays = (expiryDate.getTimeInMillis() / 86400000) -
if (numDays <= 0) (creationDate.getTimeInMillis() / 86400000);
if (numDays <= 0) {
throw new PgpGeneralMsgIdException(R.string.error_expiry_must_come_after_creation); throw new PgpGeneralMsgIdException(R.string.error_expiry_must_come_after_creation);
}
hashedPacketsGen.setKeyExpirationTime(false, numDays * 86400); hashedPacketsGen.setKeyExpirationTime(false, numDays * 86400);
} else { } else {
hashedPacketsGen.setKeyExpirationTime(false, 0); //do this explicitly, although since we're rebuilding, hashedPacketsGen.setKeyExpirationTime(false, 0);
//this happens anyway // do this explicitly, although since we're rebuilding,
// this happens anyway
} }
updateProgress(R.string.progress_building_master_key, 30, 100); updateProgress(R.string.progress_building_master_key, 30, 100);
@ -342,15 +345,16 @@ public class PgpKeyOperation {
GregorianCalendar expiryDate = keysExpiryDates.get(i); GregorianCalendar expiryDate = keysExpiryDates.get(i);
//note that the below, (a/c) - (b/c) is *not* the same as (a - b) /c //note that the below, (a/c) - (b/c) is *not* the same as (a - b) /c
//here we purposefully ignore partial days in each date - long type has no fractional part! //here we purposefully ignore partial days in each date - long type has no fractional part!
long numDays = long numDays = (expiryDate.getTimeInMillis() / 86400000) -
(expiryDate.getTimeInMillis() / 86400000) - (creationDate.getTimeInMillis() / 86400000); (creationDate.getTimeInMillis() / 86400000);
if (numDays <= 0) { if (numDays <= 0) {
throw new PgpGeneralMsgIdException(R.string.error_expiry_must_come_after_creation); throw new PgpGeneralMsgIdException(R.string.error_expiry_must_come_after_creation);
} }
hashedPacketsGen.setKeyExpirationTime(false, numDays * 86400); hashedPacketsGen.setKeyExpirationTime(false, numDays * 86400);
} else { } else {
hashedPacketsGen.setKeyExpirationTime(false, 0); //do this explicitly, although since we're rebuilding, hashedPacketsGen.setKeyExpirationTime(false, 0);
//this happens anyway // do this explicitly, although since we're rebuilding,
// this happens anyway
} }
keyGen.addSubKey(subKeyPair, hashedPacketsGen.generate(), unhashedPacketsGen.generate()); keyGen.addSubKey(subKeyPair, hashedPacketsGen.generate(), unhashedPacketsGen.generate());
@ -447,22 +451,28 @@ public class PgpKeyOperation {
GregorianCalendar expiryDate = saveParcel.keysExpiryDates.get(0); GregorianCalendar expiryDate = saveParcel.keysExpiryDates.get(0);
//note that the below, (a/c) - (b/c) is *not* the same as (a - b) /c //note that the below, (a/c) - (b/c) is *not* the same as (a - b) /c
//here we purposefully ignore partial days in each date - long type has no fractional part! //here we purposefully ignore partial days in each date - long type has no fractional part!
long numDays = (expiryDate.getTimeInMillis() / 86400000) - (creationDate.getTimeInMillis() / 86400000); long numDays = (expiryDate.getTimeInMillis() / 86400000) -
if (numDays <= 0) (creationDate.getTimeInMillis() / 86400000);
if (numDays <= 0) {
throw new PgpGeneralMsgIdException(R.string.error_expiry_must_come_after_creation); throw new PgpGeneralMsgIdException(R.string.error_expiry_must_come_after_creation);
}
hashedPacketsGen.setKeyExpirationTime(false, numDays * 86400); hashedPacketsGen.setKeyExpirationTime(false, numDays * 86400);
} else { } else {
hashedPacketsGen.setKeyExpirationTime(false, 0); //do this explicitly, although since we're rebuilding, hashedPacketsGen.setKeyExpirationTime(false, 0);
//this happens anyway // do this explicitly, although since we're rebuilding,
// this happens anyway
} }
if (saveParcel.primaryIDChanged || !saveParcel.originalIDs.get(0).equals(saveParcel.userIDs.get(0))) { if (saveParcel.primaryIDChanged ||
!saveParcel.originalIDs.get(0).equals(saveParcel.userIDs.get(0))) {
anyIDChanged = true; anyIDChanged = true;
ArrayList<Pair<String, PGPSignature>> sigList = new ArrayList<Pair<String, PGPSignature>>(); ArrayList<Pair<String, PGPSignature>> sigList = new ArrayList<Pair<String, PGPSignature>>();
for (String userId : saveParcel.userIDs) { for (String userId : saveParcel.userIDs) {
String origID = saveParcel.originalIDs.get(userIDIndex); String origID = saveParcel.originalIDs.get(userIDIndex);
if ((origID.equals(userId) && !saveParcel.newIDs[userIDIndex]) && !userId.equals(saveParcel.originalPrimaryID) && userIDIndex != 0) { if (origID.equals(userId) && !saveParcel.newIDs[userIDIndex] &&
Iterator<PGPSignature> origSigs = masterPublicKey.getSignaturesForID(origID); //TODO: make sure this iterator only has signatures we are interested in !userId.equals(saveParcel.originalPrimaryID) && userIDIndex != 0) {
Iterator<PGPSignature> origSigs = masterPublicKey.getSignaturesForID(origID);
// TODO: make sure this iterator only has signatures we are interested in
while (origSigs.hasNext()) { while (origSigs.hasNext()) {
PGPSignature origSig = origSigs.next(); PGPSignature origSig = origSigs.next();
sigList.add(new Pair<String, PGPSignature>(origID, origSig)); sigList.add(new Pair<String, PGPSignature>(origID, origSig));
@ -487,7 +497,8 @@ public class PgpKeyOperation {
userIDIndex++; userIDIndex++;
} }
for (Pair<String, PGPSignature> toAdd : sigList) { for (Pair<String, PGPSignature> toAdd : sigList) {
masterPublicKey = PGPPublicKey.addCertification(masterPublicKey, toAdd.first, toAdd.second); masterPublicKey =
PGPPublicKey.addCertification(masterPublicKey, toAdd.first, toAdd.second);
} }
} else { } else {
for (String userId : saveParcel.userIDs) { for (String userId : saveParcel.userIDs) {
@ -508,7 +519,8 @@ public class PgpKeyOperation {
if (!saveParcel.newIDs[userIDIndex]) { if (!saveParcel.newIDs[userIDIndex]) {
masterPublicKey = PGPPublicKey.removeCertification(masterPublicKey, origID); masterPublicKey = PGPPublicKey.removeCertification(masterPublicKey, origID);
} }
masterPublicKey = PGPPublicKey.addCertification(masterPublicKey, userId, certification); masterPublicKey =
PGPPublicKey.addCertification(masterPublicKey, userId, certification);
} }
userIDIndex++; userIDIndex++;
} }
@ -520,7 +532,8 @@ public class PgpKeyOperation {
for (String userId : saveParcel.userIDs) { for (String userId : saveParcel.userIDs) {
String origID = saveParcel.originalIDs.get(userIDIndex); String origID = saveParcel.originalIDs.get(userIDIndex);
if (!(origID.equals(saveParcel.originalPrimaryID) && !saveParcel.primaryIDChanged)) { if (!(origID.equals(saveParcel.originalPrimaryID) && !saveParcel.primaryIDChanged)) {
Iterator<PGPSignature> sigs = masterPublicKey.getSignaturesForID(userId); //TODO: make sure this iterator only has signatures we are interested in Iterator<PGPSignature> sigs = masterPublicKey.getSignaturesForID(userId);
// TODO: make sure this iterator only has signatures we are interested in
while (sigs.hasNext()) { while (sigs.hasNext()) {
PGPSignature sig = sigs.next(); PGPSignature sig = sigs.next();
sigList.add(new Pair<String, PGPSignature>(userId, sig)); sigList.add(new Pair<String, PGPSignature>(userId, sig));
@ -605,23 +618,27 @@ public class PgpKeyOperation {
GregorianCalendar creationDate = new GregorianCalendar(TimeZone.getTimeZone("UTC")); GregorianCalendar creationDate = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
creationDate.setTime(subPublicKey.getCreationTime()); creationDate.setTime(subPublicKey.getCreationTime());
GregorianCalendar expiryDate = saveParcel.keysExpiryDates.get(i); GregorianCalendar expiryDate = saveParcel.keysExpiryDates.get(i);
//note that the below, (a/c) - (b/c) is *not* the same as (a - b) /c // note that the below, (a/c) - (b/c) is *not* the same as (a - b) /c
//here we purposefully ignore partial days in each date - long type has no fractional part! // here we purposefully ignore partial days in each date - long type has
long numDays = (expiryDate.getTimeInMillis() / 86400000) - (creationDate.getTimeInMillis() / 86400000); // no fractional part!
if (numDays <= 0) long numDays = (expiryDate.getTimeInMillis() / 86400000) -
(creationDate.getTimeInMillis() / 86400000);
if (numDays <= 0) {
throw new PgpGeneralMsgIdException(R.string.error_expiry_must_come_after_creation); throw new PgpGeneralMsgIdException(R.string.error_expiry_must_come_after_creation);
}
hashedPacketsGen.setKeyExpirationTime(false, numDays * 86400); hashedPacketsGen.setKeyExpirationTime(false, numDays * 86400);
} else { } else {
hashedPacketsGen.setKeyExpirationTime(false, 0); //do this explicitly, although since we're rebuilding, hashedPacketsGen.setKeyExpirationTime(false, 0);
//this happens anyway // do this explicitly, although since we're rebuilding,
// this happens anyway
} }
keyGen.addSubKey(subKeyPair, hashedPacketsGen.generate(), unhashedPacketsGen.generate()); keyGen.addSubKey(subKeyPair, hashedPacketsGen.generate(), unhashedPacketsGen.generate());
//certifications will be discarded if the key is changed, because I think, for a start, // certifications will be discarded if the key is changed, because I think, for a start,
//they will be invalid. Binding certs are regenerated anyway, and other certs which // they will be invalid. Binding certs are regenerated anyway, and other certs which
//need to be kept are on IDs and attributes // need to be kept are on IDs and attributes
//TODO: don't let revoked keys be edited, other than removed - changing one would result in the // TODO: don't let revoked keys be edited, other than removed - changing one would
//revocation being wrong? // result in the revocation being wrong?
} }
} }
@ -660,8 +677,10 @@ public class PgpKeyOperation {
Log.d(Constants.TAG, " ------- in private key -------"); Log.d(Constants.TAG, " ------- in private key -------");
for(String uid : new IterableIterator<String>(secretKeyRing.getPublicKey().getUserIDs())) { for(String uid : new IterableIterator<String>(secretKeyRing.getPublicKey().getUserIDs())) {
for(PGPSignature sig : new IterableIterator<PGPSignature>(secretKeyRing.getPublicKey().getSignaturesForID(uid))) { for(PGPSignature sig : new IterableIterator<PGPSignature>(
Log.d(Constants.TAG, "sig: " + PgpKeyHelper.convertKeyIdToHex(sig.getKeyID()) + " for " + uid); secretKeyRing.getPublicKey().getSignaturesForID(uid))) {
Log.d(Constants.TAG, "sig: " +
PgpKeyHelper.convertKeyIdToHex(sig.getKeyID()) + " for " + uid);
} }
} }
@ -669,8 +688,10 @@ public class PgpKeyOperation {
Log.d(Constants.TAG, " ------- in public key -------"); Log.d(Constants.TAG, " ------- in public key -------");
for(String uid : new IterableIterator<String>(publicKeyRing.getPublicKey().getUserIDs())) { for(String uid : new IterableIterator<String>(publicKeyRing.getPublicKey().getUserIDs())) {
for(PGPSignature sig : new IterableIterator<PGPSignature>(publicKeyRing.getPublicKey().getSignaturesForID(uid))) { for(PGPSignature sig : new IterableIterator<PGPSignature>(
Log.d(Constants.TAG, "sig: " + PgpKeyHelper.convertKeyIdToHex(sig.getKeyID()) + " for " + uid); publicKeyRing.getPublicKey().getSignaturesForID(uid))) {
Log.d(Constants.TAG, "sig: " +
PgpKeyHelper.convertKeyIdToHex(sig.getKeyID()) + " for " + uid);
} }
} }
@ -689,9 +710,10 @@ public class PgpKeyOperation {
* @param passphrase Passphrase of the secret key * @param passphrase Passphrase of the secret key
* @return A keyring with added certifications * @return A keyring with added certifications
*/ */
public PGPPublicKey certifyKey(PGPSecretKey certificationKey, PGPPublicKey publicKey, List<String> userIds, String passphrase) public PGPPublicKey certifyKey(PGPSecretKey certificationKey, PGPPublicKey publicKey,
List<String> userIds, String passphrase)
throws PgpGeneralMsgIdException, NoSuchAlgorithmException, NoSuchProviderException, throws PgpGeneralMsgIdException, NoSuchAlgorithmException, NoSuchProviderException,
PGPException, SignatureException { PGPException, SignatureException {
// create a signatureGenerator from the supplied masterKeyId and passphrase // create a signatureGenerator from the supplied masterKeyId and passphrase
PGPSignatureGenerator signatureGenerator; { PGPSignatureGenerator signatureGenerator; {

View File

@ -83,9 +83,10 @@ public class PgpToX509 {
* @throws Exception * @throws Exception
* @author Bruno Harbulot * @author Bruno Harbulot
*/ */
public static X509Certificate createSelfSignedCert(PublicKey pubKey, PrivateKey privKey, public static X509Certificate createSelfSignedCert(
X509Name subject, Date startDate, Date endDate, String subjAltNameURI) PublicKey pubKey, PrivateKey privKey, X509Name subject, Date startDate, Date endDate,
throws InvalidKeyException, IllegalStateException, NoSuchAlgorithmException, String subjAltNameURI)
throws InvalidKeyException, IllegalStateException, NoSuchAlgorithmException,
SignatureException, CertificateException, NoSuchProviderException { SignatureException, CertificateException, NoSuchProviderException {
X509V3CertificateGenerator certGenerator = new X509V3CertificateGenerator(); X509V3CertificateGenerator certGenerator = new X509V3CertificateGenerator();
@ -182,10 +183,10 @@ public class PgpToX509 {
/** /**
* Creates a self-signed certificate from a PGP Secret Key. * Creates a self-signed certificate from a PGP Secret Key.
* *
* @param pgpSecKey PGP Secret Key (from which one can extract the public and private keys and other * @param pgpSecKey PGP Secret Key (from which one can extract the public and private
* attributes). * keys and other attributes).
* @param pgpPrivKey PGP Private Key corresponding to the Secret Key (password callbacks should be done * @param pgpPrivKey PGP Private Key corresponding to the Secret Key (password callbacks
* before calling this method) * should be done before calling this method)
* @param subjAltNameURI optional URI to embed in the subject alternative-name * @param subjAltNameURI optional URI to embed in the subject alternative-name
* @return self-signed certificate * @return self-signed certificate
* @throws PGPException * @throws PGPException
@ -196,9 +197,9 @@ public class PgpToX509 {
* @throws CertificateException * @throws CertificateException
* @author Bruno Harbulot * @author Bruno Harbulot
*/ */
public static X509Certificate createSelfSignedCert(PGPSecretKey pgpSecKey, public static X509Certificate createSelfSignedCert(
PGPPrivateKey pgpPrivKey, String subjAltNameURI) throws PGPException, PGPSecretKey pgpSecKey, PGPPrivateKey pgpPrivKey, String subjAltNameURI)
NoSuchProviderException, InvalidKeyException, NoSuchAlgorithmException, throws PGPException, NoSuchProviderException, InvalidKeyException, NoSuchAlgorithmException,
SignatureException, CertificateException { SignatureException, CertificateException {
// get public key from secret key // get public key from secret key
PGPPublicKey pgpPubKey = pgpSecKey.getPublicKey(); PGPPublicKey pgpPubKey = pgpSecKey.getPublicKey();

View File

@ -283,12 +283,14 @@ public class KeychainContract {
/** /**
* Use if multiple items get returned * Use if multiple items get returned
*/ */
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.thialfihar.apg.api_app.accounts"; public static final String CONTENT_TYPE =
"vnd.android.cursor.dir/vnd.thialfihar.apg.api_app.accounts";
/** /**
* Use if a single item is returned * Use if a single item is returned
*/ */
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.thialfihar.apg.api_app.account"; public static final String CONTENT_ITEM_TYPE =
"vnd.android.cursor.item/vnd.thialfihar.apg.api_app.account";
public static Uri buildBaseUri(String packageName) { public static Uri buildBaseUri(String packageName) {
return CONTENT_URI.buildUpon().appendEncodedPath(packageName).appendPath(PATH_ACCOUNTS) return CONTENT_URI.buildUpon().appendEncodedPath(packageName).appendPath(PATH_ACCOUNTS)

View File

@ -296,8 +296,8 @@ public class ProviderHelper {
/** /**
* Build ContentProviderOperation to add PGPPublicKey to database corresponding to a keyRing * Build ContentProviderOperation to add PGPPublicKey to database corresponding to a keyRing
*/ */
private static ContentProviderOperation buildPublicKeyOperations(Context context, private static ContentProviderOperation buildPublicKeyOperations(
long keyRingRowId, PGPPublicKey key, int rank) throws IOException { Context context, long keyRingRowId, PGPPublicKey key, int rank) throws IOException {
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put(Keys.KEY_ID, key.getKeyID()); values.put(Keys.KEY_ID, key.getKeyID());
values.put(Keys.IS_MASTER_KEY, key.isMasterKey()); values.put(Keys.IS_MASTER_KEY, key.isMasterKey());
@ -324,8 +324,8 @@ public class ProviderHelper {
/** /**
* Build ContentProviderOperation to add PublicUserIds to database corresponding to a keyRing * Build ContentProviderOperation to add PublicUserIds to database corresponding to a keyRing
*/ */
private static ContentProviderOperation buildPublicUserIdOperations(Context context, private static ContentProviderOperation buildPublicUserIdOperations(
long keyRingRowId, String userId, int rank) { Context context, long keyRingRowId, String userId, int rank) {
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put(UserIds.KEY_RING_ROW_ID, keyRingRowId); values.put(UserIds.KEY_RING_ROW_ID, keyRingRowId);
values.put(UserIds.USER_ID, userId); values.put(UserIds.USER_ID, userId);
@ -339,8 +339,8 @@ public class ProviderHelper {
/** /**
* Build ContentProviderOperation to add PGPSecretKey to database corresponding to a keyRing * Build ContentProviderOperation to add PGPSecretKey to database corresponding to a keyRing
*/ */
private static ContentProviderOperation buildSecretKeyOperations(Context context, private static ContentProviderOperation buildSecretKeyOperations(
long keyRingRowId, PGPSecretKey key, int rank) throws IOException { Context context, long keyRingRowId, PGPSecretKey key, int rank) throws IOException {
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
boolean hasPrivate = true; boolean hasPrivate = true;
@ -376,8 +376,8 @@ public class ProviderHelper {
/** /**
* Build ContentProviderOperation to add SecretUserIds to database corresponding to a keyRing * Build ContentProviderOperation to add SecretUserIds to database corresponding to a keyRing
*/ */
private static ContentProviderOperation buildSecretUserIdOperations(Context context, private static ContentProviderOperation buildSecretUserIdOperations(
long keyRingRowId, String userId, int rank) { Context context, long keyRingRowId, String userId, int rank) {
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put(UserIds.KEY_RING_ROW_ID, keyRingRowId); values.put(UserIds.KEY_RING_ROW_ID, keyRingRowId);
values.put(UserIds.USER_ID, userId); values.put(UserIds.USER_ID, userId);

View File

@ -188,7 +188,8 @@ public class OpenPgpService extends RemoteService {
} }
private Intent encryptAndSignImpl(Intent data, ParcelFileDescriptor input, private Intent encryptAndSignImpl(Intent data, ParcelFileDescriptor input,
ParcelFileDescriptor output, AccountSettings accSettings, boolean sign) { ParcelFileDescriptor output, AccountSettings accSettings,
boolean sign) {
try { try {
boolean asciiArmor = data.getBooleanExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true); boolean asciiArmor = data.getBooleanExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
@ -292,7 +293,8 @@ public class OpenPgpService extends RemoteService {
PgpDecryptVerify.Builder builder = new PgpDecryptVerify.Builder(this, inputData, os); PgpDecryptVerify.Builder builder = new PgpDecryptVerify.Builder(this, inputData, os);
builder.allowSymmetricDecryption(false) // no support for symmetric encryption builder.allowSymmetricDecryption(false) // no support for symmetric encryption
.allowedKeyIds(allowedKeyIds) // allow only private keys associated with accounts of this app .allowedKeyIds(allowedKeyIds) // allow only private keys associated with
// accounts of this app
.passphrase(passphrase); .passphrase(passphrase);
// TODO: currently does not support binary signed-only content // TODO: currently does not support binary signed-only content
@ -300,9 +302,11 @@ public class OpenPgpService extends RemoteService {
if (PgpDecryptVerifyResult.KEY_PASSHRASE_NEEDED == decryptVerifyResult.getStatus()) { if (PgpDecryptVerifyResult.KEY_PASSHRASE_NEEDED == decryptVerifyResult.getStatus()) {
// get PendingIntent for passphrase input, add it to given params and return to client // get PendingIntent for passphrase input, add it to given params and return to client
Intent passphraseBundle = getPassphraseBundleIntent(data, decryptVerifyResult.getKeyIdPassphraseNeeded()); Intent passphraseBundle =
getPassphraseBundleIntent(data, decryptVerifyResult.getKeyIdPassphraseNeeded());
return passphraseBundle; return passphraseBundle;
} else if (PgpDecryptVerifyResult.SYMMETRIC_PASSHRASE_NEEDED == decryptVerifyResult.getStatus()) { } else if (PgpDecryptVerifyResult.SYMMETRIC_PASSHRASE_NEEDED ==
decryptVerifyResult.getStatus()) {
throw new PgpGeneralException("Decryption of symmetric content not supported by API!"); throw new PgpGeneralException("Decryption of symmetric content not supported by API!");
} }
@ -455,7 +459,8 @@ public class OpenPgpService extends RemoteService {
} else if (OpenPgpApi.ACTION_DECRYPT_VERIFY.equals(action)) { } else if (OpenPgpApi.ACTION_DECRYPT_VERIFY.equals(action)) {
String currentPkg = getCurrentCallingPackage(); String currentPkg = getCurrentCallingPackage();
Set<Long> allowedKeyIds = Set<Long> allowedKeyIds =
ProviderHelper.getAllKeyIdsForApp(mContext, KeychainContract.ApiAccounts.buildBaseUri(currentPkg)); ProviderHelper.getAllKeyIdsForApp(mContext,
KeychainContract.ApiAccounts.buildBaseUri(currentPkg));
return decryptAndVerifyImpl(data, input, output, allowedKeyIds); return decryptAndVerifyImpl(data, input, output, allowedKeyIds);
} else if (OpenPgpApi.ACTION_GET_KEY.equals(action)) { } else if (OpenPgpApi.ACTION_GET_KEY.equals(action)) {
return getKeyImpl(data); return getKeyImpl(data);

View File

@ -243,7 +243,8 @@ public abstract class RemoteService extends Service {
return true; return true;
} else { } else {
throw new WrongPackageSignatureException( throw new WrongPackageSignatureException(
"PACKAGE NOT ALLOWED! Signature wrong! (Signature not equals signature from database)"); "PACKAGE NOT ALLOWED! Signature wrong! (Signature not " +
"equals signature from database)");
} }
} }

View File

@ -69,7 +69,8 @@ public class AccountSettingsFragment extends Fragment implements
this.mAccSettings = accountSettings; this.mAccSettings = accountSettings;
mAccNameView.setText(accountSettings.getAccountName()); mAccNameView.setText(accountSettings.getAccountName());
Uri keyUri = KeychainContract.KeyRings.buildSecretKeyRingsByMasterKeyIdUri(String.valueOf(accountSettings.getKeyId())); Uri keyUri = KeychainContract.KeyRings.buildSecretKeyRingsByMasterKeyIdUri(
String.valueOf(accountSettings.getKeyId()));
mSelectKeyFragment.selectKey(keyUri); mSelectKeyFragment.selectKey(keyUri);
mEncryptionAlgorithm.setSelection(mEncryptionAdapter.getPosition(accountSettings mEncryptionAlgorithm.setSelection(mEncryptionAdapter.getPosition(accountSettings
.getEncryptionAlgorithm())); .getEncryptionAlgorithm()));

View File

@ -485,10 +485,13 @@ public class KeychainIntentService extends IntentService
ProviderHelper.saveKeyRing(this, keyRing); ProviderHelper.saveKeyRing(this, keyRing);
setProgress(R.string.progress_done, 100, 100); setProgress(R.string.progress_done, 100, 100);
} else { } else {
PgpKeyOperation keyOperations = new PgpKeyOperation(new ProgressScaler(this, 0, 90, 100)); PgpKeyOperation keyOperations =
PGPSecretKeyRing privkey = ProviderHelper.getPGPSecretKeyRingByMasterKeyId(this, masterKeyId); new PgpKeyOperation(new ProgressScaler(this, 0, 90, 100));
PGPPublicKeyRing pubkey = ProviderHelper.getPGPPublicKeyRingByMasterKeyId(this, masterKeyId); PGPSecretKeyRing privkey =
PgpKeyOperation.Pair<PGPSecretKeyRing,PGPPublicKeyRing> pair = ProviderHelper.getPGPSecretKeyRingByMasterKeyId(this, masterKeyId);
PGPPublicKeyRing pubkey =
ProviderHelper.getPGPPublicKeyRingByMasterKeyId(this, masterKeyId);
PgpKeyOperation.Pair<PGPSecretKeyRing, PGPPublicKeyRing> pair =
keyOperations.buildSecretKey(privkey, pubkey, saveParams); keyOperations.buildSecretKey(privkey, pubkey, saveParams);
setProgress(R.string.progress_saving_key_ring, 90, 100); setProgress(R.string.progress_saving_key_ring, 90, 100);
ProviderHelper.saveKeyRing(this, pair.first); ProviderHelper.saveKeyRing(this, pair.first);
@ -745,11 +748,14 @@ public class KeychainIntentService extends IntentService
// verify downloaded key by comparing fingerprints // verify downloaded key by comparing fingerprints
if (entry.getFingerPrintHex() != null) { if (entry.getFingerPrintHex() != null) {
String downloadedKeyFp = PgpKeyHelper.convertFingerprintToHex(downloadedKey.getPublicKey().getFingerprint()); String downloadedKeyFp = PgpKeyHelper.convertFingerprintToHex(
downloadedKey.getPublicKey().getFingerprint());
if (downloadedKeyFp.equals(entry.getFingerPrintHex())) { if (downloadedKeyFp.equals(entry.getFingerPrintHex())) {
Log.d(Constants.TAG, "fingerprint of downloaded key is the same as the requested fingerprint!"); Log.d(Constants.TAG, "fingerprint of downloaded key is the same as " +
"the requested fingerprint!");
} else { } else {
throw new PgpGeneralException("fingerprint of downloaded key is NOT the same as the requested fingerprint!"); throw new PgpGeneralException("fingerprint of downloaded key is " +
"NOT the same as the requested fingerprint!");
} }
} }

View File

@ -212,7 +212,8 @@ public class CertifyKeyActivity extends ActionBarActivity implements
fingerprintBlob = ProviderHelper.getFingerprint(this, mDataUri); fingerprintBlob = ProviderHelper.getFingerprint(this, mDataUri);
} }
String fingerprint = PgpKeyHelper.convertFingerprintToHex(fingerprintBlob); String fingerprint = PgpKeyHelper.convertFingerprintToHex(fingerprintBlob);
((TextView) findViewById(R.id.fingerprint)).setText(PgpKeyHelper.colorizeFingerprint(fingerprint)); ((TextView) findViewById(R.id.fingerprint))
.setText(PgpKeyHelper.colorizeFingerprint(fingerprint));
} }
break; break;
case LOADER_ID_USER_IDS: case LOADER_ID_USER_IDS:

View File

@ -77,8 +77,10 @@ public class DecryptActivity extends DrawerActivity {
// Handle intent actions, maybe changes the bundles // Handle intent actions, maybe changes the bundles
handleActions(getIntent()); handleActions(getIntent());
mTabsAdapter.addTab(DecryptMessageFragment.class, mMessageFragmentBundle, getString(R.string.label_message)); mTabsAdapter.addTab(DecryptMessageFragment.class,
mTabsAdapter.addTab(DecryptFileFragment.class, mFileFragmentBundle, getString(R.string.label_file)); mMessageFragmentBundle, getString(R.string.label_message));
mTabsAdapter.addTab(DecryptFileFragment.class,
mFileFragmentBundle, getString(R.string.label_file));
mViewPager.setCurrentItem(mSwitchToTab); mViewPager.setCurrentItem(mSwitchToTab);
} }
@ -164,7 +166,8 @@ public class DecryptActivity extends DrawerActivity {
mSwitchToTab = PAGER_TAB_FILE; mSwitchToTab = PAGER_TAB_FILE;
} else { } else {
Log.e(Constants.TAG, Log.e(Constants.TAG,
"Direct binary data without actual file in filesystem is not supported. Please use the Remote Service API!"); "Direct binary data without actual file in filesystem is not supported. " +
"Please use the Remote Service API!");
Toast.makeText(this, R.string.error_only_files_are_supported, Toast.LENGTH_LONG) Toast.makeText(this, R.string.error_only_files_are_supported, Toast.LENGTH_LONG)
.show(); .show();
// end activity // end activity

View File

@ -200,7 +200,8 @@ public class DecryptFileFragment extends DecryptFragment {
if (PgpDecryptVerifyResult.KEY_PASSHRASE_NEEDED == decryptVerifyResult.getStatus()) { if (PgpDecryptVerifyResult.KEY_PASSHRASE_NEEDED == decryptVerifyResult.getStatus()) {
showPassphraseDialog(decryptVerifyResult.getKeyIdPassphraseNeeded()); showPassphraseDialog(decryptVerifyResult.getKeyIdPassphraseNeeded());
} else if (PgpDecryptVerifyResult.SYMMETRIC_PASSHRASE_NEEDED == decryptVerifyResult.getStatus()) { } else if (PgpDecryptVerifyResult.SYMMETRIC_PASSHRASE_NEEDED ==
decryptVerifyResult.getStatus()) {
showPassphraseDialog(Id.key.symmetric); showPassphraseDialog(Id.key.symmetric);
} else { } else {
AppMsg.makeText(getActivity(), R.string.decryption_successful, AppMsg.makeText(getActivity(), R.string.decryption_successful,

View File

@ -154,7 +154,8 @@ public class DecryptMessageFragment extends DecryptFragment {
if (PgpDecryptVerifyResult.KEY_PASSHRASE_NEEDED == decryptVerifyResult.getStatus()) { if (PgpDecryptVerifyResult.KEY_PASSHRASE_NEEDED == decryptVerifyResult.getStatus()) {
showPassphraseDialog(decryptVerifyResult.getKeyIdPassphraseNeeded()); showPassphraseDialog(decryptVerifyResult.getKeyIdPassphraseNeeded());
} else if (PgpDecryptVerifyResult.SYMMETRIC_PASSHRASE_NEEDED == decryptVerifyResult.getStatus()) { } else if (PgpDecryptVerifyResult.SYMMETRIC_PASSHRASE_NEEDED ==
decryptVerifyResult.getStatus()) {
showPassphraseDialog(Id.key.symmetric); showPassphraseDialog(Id.key.symmetric);
} else { } else {
AppMsg.makeText(getActivity(), R.string.decryption_successful, AppMsg.makeText(getActivity(), R.string.decryption_successful,

View File

@ -125,7 +125,6 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
public void somethingChanged() { public void somethingChanged() {
ActivityCompat.invalidateOptionsMenu(this); ActivityCompat.invalidateOptionsMenu(this);
//Toast.makeText(this, "Needs saving: " + Boolean.toString(mNeedsSaving) + "(" + Boolean.toString(mUserIdsView.needsSaving()) + ", " + Boolean.toString(mKeysView.needsSaving()) + ")", Toast.LENGTH_LONG).show();
} }
public void onDeleted(Editor e, boolean wasNewItem) { public void onDeleted(Editor e, boolean wasNewItem) {
@ -329,7 +328,9 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case android.R.id.home: case android.R.id.home:
cancelClicked(); //TODO: why isn't this triggered on my tablet - one of many ui problems I've had with this device. A code compatibility issue or a Samsung fail? cancelClicked();
// TODO: why isn't this triggered on my tablet - one of many ui problems
// I've had with this device. A code compatibility issue or a Samsung fail?
return true; return true;
case R.id.menu_key_edit_cancel: case R.id.menu_key_edit_cancel:
cancelClicked(); cancelClicked();
@ -340,8 +341,8 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
} else { } else {
long masterKeyId = ProviderHelper.getMasterKeyId(this, mDataUri); long masterKeyId = ProviderHelper.getMasterKeyId(this, mDataUri);
long[] ids = new long[] {masterKeyId}; long[] ids = new long[] {masterKeyId};
mExportHelper.showExportKeysDialog(ids, Id.type.secret_key, Constants.Path.APP_DIR_FILE_SEC, mExportHelper.showExportKeysDialog(
null); ids, Id.type.secret_key, Constants.Path.APP_DIR_FILE_SEC, null);
return true; return true;
} }
return true; return true;

View File

@ -155,12 +155,16 @@ public class EncryptActivity extends DrawerActivity implements
// Handle intent actions // Handle intent actions
handleActions(getIntent()); handleActions(getIntent());
mTabsAdapterMode.addTab(EncryptAsymmetricFragment.class, mAsymmetricFragmentBundle, getString(R.string.label_asymmetric)); mTabsAdapterMode.addTab(EncryptAsymmetricFragment.class,
mTabsAdapterMode.addTab(EncryptSymmetricFragment.class, mSymmetricFragmentBundle, getString(R.string.label_symmetric)); mAsymmetricFragmentBundle, getString(R.string.label_asymmetric));
mTabsAdapterMode.addTab(EncryptSymmetricFragment.class,
mSymmetricFragmentBundle, getString(R.string.label_symmetric));
mViewPagerMode.setCurrentItem(mSwitchToMode); mViewPagerMode.setCurrentItem(mSwitchToMode);
mTabsAdapterContent.addTab(EncryptMessageFragment.class, mMessageFragmentBundle, getString(R.string.label_message)); mTabsAdapterContent.addTab(EncryptMessageFragment.class,
mTabsAdapterContent.addTab(EncryptFileFragment.class, mFileFragmentBundle, getString(R.string.label_file)); mMessageFragmentBundle, getString(R.string.label_message));
mTabsAdapterContent.addTab(EncryptFileFragment.class,
mFileFragmentBundle, getString(R.string.label_file));
mViewPagerContent.setCurrentItem(mSwitchToContent); mViewPagerContent.setCurrentItem(mSwitchToContent);
} }
@ -212,8 +216,10 @@ public class EncryptActivity extends DrawerActivity implements
long[] encryptionKeyIds = extras.getLongArray(EXTRA_ENCRYPTION_KEY_IDS); long[] encryptionKeyIds = extras.getLongArray(EXTRA_ENCRYPTION_KEY_IDS);
// preselect keys given by intent // preselect keys given by intent
mAsymmetricFragmentBundle.putLongArray(EncryptAsymmetricFragment.ARG_ENCRYPTION_KEY_IDS, encryptionKeyIds); mAsymmetricFragmentBundle.putLongArray(EncryptAsymmetricFragment.ARG_ENCRYPTION_KEY_IDS,
mAsymmetricFragmentBundle.putLong(EncryptAsymmetricFragment.ARG_SIGNATURE_KEY_ID, signatureKeyId); encryptionKeyIds);
mAsymmetricFragmentBundle.putLong(EncryptAsymmetricFragment.ARG_SIGNATURE_KEY_ID,
signatureKeyId);
mSwitchToMode = PAGER_MODE_ASYMMETRIC; mSwitchToMode = PAGER_MODE_ASYMMETRIC;
/** /**
@ -234,7 +240,8 @@ public class EncryptActivity extends DrawerActivity implements
mSwitchToContent = PAGER_CONTENT_FILE; mSwitchToContent = PAGER_CONTENT_FILE;
} else { } else {
Log.e(Constants.TAG, Log.e(Constants.TAG,
"Direct binary data without actual file in filesystem is not supported by Intents. Please use the Remote Service API!"); "Direct binary data without actual file in filesystem is not supported " +
"by Intents. Please use the Remote Service API!");
Toast.makeText(this, R.string.error_only_files_are_supported, Toast.LENGTH_LONG) Toast.makeText(this, R.string.error_only_files_are_supported, Toast.LENGTH_LONG)
.show(); .show();
// end activity // end activity

View File

@ -253,8 +253,9 @@ public class EncryptFileFragment extends Fragment {
return; return;
} }
if (mEncryptInterface.getSignatureKey() != 0 if (mEncryptInterface.getSignatureKey() != 0 &&
&& PassphraseCacheService.getCachedPassphrase(getActivity(), mEncryptInterface.getSignatureKey()) == null) { PassphraseCacheService.getCachedPassphrase(getActivity(),
mEncryptInterface.getSignatureKey()) == null) {
showPassphraseDialog(); showPassphraseDialog();
return; return;
@ -283,8 +284,10 @@ public class EncryptFileFragment extends Fragment {
} }
data.putString(KeychainIntentService.ENCRYPT_SYMMETRIC_PASSPHRASE, passphrase); data.putString(KeychainIntentService.ENCRYPT_SYMMETRIC_PASSPHRASE, passphrase);
} else { } else {
data.putLong(KeychainIntentService.ENCRYPT_SIGNATURE_KEY_ID, mEncryptInterface.getSignatureKey()); data.putLong(KeychainIntentService.ENCRYPT_SIGNATURE_KEY_ID,
data.putLongArray(KeychainIntentService.ENCRYPT_ENCRYPTION_KEYS_IDS, mEncryptInterface.getEncryptionKeys()); mEncryptInterface.getSignatureKey());
data.putLongArray(KeychainIntentService.ENCRYPT_ENCRYPTION_KEYS_IDS,
mEncryptInterface.getEncryptionKeys());
} }
Log.d(Constants.TAG, "mInputFilename=" + mInputFilename + ", mOutputFilename=" Log.d(Constants.TAG, "mInputFilename=" + mInputFilename + ", mOutputFilename="

View File

@ -150,8 +150,9 @@ public class EncryptMessageFragment extends Fragment {
return; return;
} }
if (mEncryptInterface.getSignatureKey() != 0 if (mEncryptInterface.getSignatureKey() != 0 &&
&& PassphraseCacheService.getCachedPassphrase(getActivity(), mEncryptInterface.getSignatureKey()) == null) { PassphraseCacheService.getCachedPassphrase(getActivity(),
mEncryptInterface.getSignatureKey()) == null) {
showPassphraseDialog(toClipboard); showPassphraseDialog(toClipboard);
return; return;
@ -182,8 +183,10 @@ public class EncryptMessageFragment extends Fragment {
} }
data.putString(KeychainIntentService.ENCRYPT_SYMMETRIC_PASSPHRASE, passphrase); data.putString(KeychainIntentService.ENCRYPT_SYMMETRIC_PASSPHRASE, passphrase);
} else { } else {
data.putLong(KeychainIntentService.ENCRYPT_SIGNATURE_KEY_ID, mEncryptInterface.getSignatureKey()); data.putLong(KeychainIntentService.ENCRYPT_SIGNATURE_KEY_ID,
data.putLongArray(KeychainIntentService.ENCRYPT_ENCRYPTION_KEYS_IDS, mEncryptInterface.getEncryptionKeys()); mEncryptInterface.getSignatureKey());
data.putLongArray(KeychainIntentService.ENCRYPT_ENCRYPTION_KEYS_IDS,
mEncryptInterface.getEncryptionKeys());
boolean signOnly = (mEncryptInterface.getEncryptionKeys() == null boolean signOnly = (mEncryptInterface.getEncryptionKeys() == null
|| mEncryptInterface.getEncryptionKeys().length == 0); || mEncryptInterface.getEncryptionKeys().length == 0);

View File

@ -168,7 +168,8 @@ public class ImportKeysActivity extends DrawerActivity implements ActionBar.OnNa
} }
} else { } else {
Log.e(Constants.TAG, Log.e(Constants.TAG,
"IMPORT_KEY_FROM_KEYSERVER action needs to contain the 'query', 'key_id', or 'fingerprint' extra!"); "IMPORT_KEY_FROM_KEYSERVER action needs to contain the 'query', 'key_id', or " +
"'fingerprint' extra!");
return; return;
} }
@ -233,7 +234,7 @@ public class ImportKeysActivity extends DrawerActivity implements ActionBar.OnNa
* onNavigationItemSelected() should check whether the Fragment is already in existence * onNavigationItemSelected() should check whether the Fragment is already in existence
* inside your Activity." * inside your Activity."
* <p/> * <p/>
* from http://stackoverflow.com/questions/10983396/fragment-oncreateview-and-onactivitycreated-called-twice/14295474#14295474 * from http://bit.ly/1dBYThO
* <p/> * <p/>
* In our case, if we start ImportKeysActivity with parameters to directly search using a fingerprint, * In our case, if we start ImportKeysActivity with parameters to directly search using a fingerprint,
* the fragment would be loaded twice resulting in the query being empty after the second load. * the fragment would be loaded twice resulting in the query being empty after the second load.
@ -337,7 +338,8 @@ public class ImportKeysActivity extends DrawerActivity implements ActionBar.OnNa
// } else { // } else {
// status.putString( // status.putString(
// EXTRA_ERROR, // EXTRA_ERROR,
// "Scanned fingerprint does NOT match the fingerprint of the received key. You shouldnt trust this key."); // "Scanned fingerprint does NOT match the fingerprint of the received key. " +
// "You shouldnt trust this key.");
// } // }
// } // }
// } catch (QueryException e) { // } catch (QueryException e) {

View File

@ -66,11 +66,13 @@ public class KeyListActivity extends DrawerActivity {
return true; return true;
case R.id.menu_key_list_export_public: case R.id.menu_key_list_export_public:
mExportHelper.showExportKeysDialog(null, Id.type.public_key, Constants.Path.APP_DIR_FILE_PUB, null); mExportHelper.showExportKeysDialog(null,
Id.type.public_key, Constants.Path.APP_DIR_FILE_PUB, null);
return true; return true;
case R.id.menu_key_list_secret_export: case R.id.menu_key_list_secret_export:
mExportHelper.showExportKeysDialog(null, Id.type.secret_key, Constants.Path.APP_DIR_FILE_SEC, null); mExportHelper.showExportKeysDialog(null, Id.type.secret_key,
Constants.Path.APP_DIR_FILE_SEC, null);
return true; return true;
default: default:

View File

@ -190,12 +190,15 @@ public class KeyListFragment extends Fragment
ProviderHelper.getPublicKeyRingsRowIds(getActivity()); ProviderHelper.getPublicKeyRingsRowIds(getActivity());
for (int i = 0; i < ids.length; i++) { for (int i = 0; i < ids.length; i++) {
if (allPubRowIds.contains(ids[i])) { if (allPubRowIds.contains(ids[i])) {
masterKeyIds[i] = ProviderHelper.getPublicMasterKeyId(getActivity(), ids[i]); masterKeyIds[i] =
ProviderHelper.getPublicMasterKeyId(getActivity(), ids[i]);
} else { } else {
masterKeyIds[i] = ProviderHelper.getSecretMasterKeyId(getActivity(), ids[i]); masterKeyIds[i] =
ProviderHelper.getSecretMasterKeyId(getActivity(), ids[i]);
} }
} }
ExportHelper mExportHelper = new ExportHelper((ActionBarActivity) getActivity()); ExportHelper mExportHelper =
new ExportHelper((ActionBarActivity) getActivity());
mExportHelper mExportHelper
.showExportKeysDialog(masterKeyIds, Id.type.public_key, .showExportKeysDialog(masterKeyIds, Id.type.public_key,
Constants.Path.APP_DIR_FILE_PUB, Constants.Path.APP_DIR_FILE_PUB,

View File

@ -124,7 +124,8 @@ public class ViewKeyActivity extends ActionBarActivity {
return true; return true;
case R.id.menu_key_view_export_file: case R.id.menu_key_view_export_file:
long masterKeyId = long masterKeyId =
ProviderHelper.getPublicMasterKeyId(this, Long.valueOf(mDataUri.getLastPathSegment())); ProviderHelper.getPublicMasterKeyId(this,
Long.valueOf(mDataUri.getLastPathSegment()));
long[] ids = new long[] {masterKeyId}; long[] ids = new long[] {masterKeyId};
mExportHelper.showExportKeysDialog(ids, Id.type.public_key, mExportHelper.showExportKeysDialog(ids, Id.type.public_key,
Constants.Path.APP_DIR_FILE_PUB, null); Constants.Path.APP_DIR_FILE_PUB, null);

View File

@ -267,6 +267,8 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
* Based on <a href="http://tools.ietf.org/html/rfc2440#section-9.1">OpenPGP Message Format</a> * Based on <a href="http://tools.ietf.org/html/rfc2440#section-9.1">OpenPGP Message Format</a>
*/ */
public static String getAlgorithmFromId(int algorithmId) { public static String getAlgorithmFromId(int algorithmId) {
return (ALGORITHM_IDS.get(algorithmId) != null ? ALGORITHM_IDS.get(algorithmId) : ALGORITHM_IDS.get(-1)); return (ALGORITHM_IDS.get(algorithmId) != null ?
ALGORITHM_IDS.get(algorithmId) :
ALGORITHM_IDS.get(-1));
} }
} }

View File

@ -166,9 +166,10 @@ public class DeleteKeyDialogFragment extends DialogFragment {
masterKeyId = cursor.getLong(0); masterKeyId = cursor.getLong(0);
keyType = cursor.getLong(1); keyType = cursor.getLong(1);
Log.d(Constants.TAG, "masterKeyId: " + masterKeyId Log.d(Constants.TAG, "masterKeyId: " + masterKeyId +
+ ", keyType:" + (keyType == KeychainContract.KeyTypes.PUBLIC ? "Public" : "Private")); ", keyType:" +
(keyType == KeychainContract.KeyTypes.PUBLIC ?
"Public" : "Private"));
if (keyType == KeychainContract.KeyTypes.SECRET) { if (keyType == KeychainContract.KeyTypes.SECRET) {
if (mCheckDeleteSecret.isChecked() || mIsSingleSelection) { if (mCheckDeleteSecret.isChecked() || mIsSingleSelection) {
@ -176,7 +177,8 @@ public class DeleteKeyDialogFragment extends DialogFragment {
String.valueOf(masterKeyId), true); String.valueOf(masterKeyId), true);
} }
} else { } else {
ProviderHelper.deleteUnifiedKeyRing(activity, String.valueOf(masterKeyId), false); ProviderHelper.deleteUnifiedKeyRing(activity,
String.valueOf(masterKeyId), false);
} }
} }

View File

@ -111,7 +111,7 @@ public class ShareQrCodeDialogFragment extends DialogFragment {
content = keyringArmored.get(0); content = keyringArmored.get(0);
// OnClickListener are set in onResume to prevent automatic dismissing of Dialogs // OnClickListener are set in onResume to prevent automatic dismissing of Dialogs
// http://stackoverflow.com/questions/2620444/how-to-prevent-a-dialog-from-closing-when-a-button-is-clicked // http://bit.ly/O5vfaR
alert.setPositiveButton(R.string.btn_next, null); alert.setPositiveButton(R.string.btn_next, null);
alert.setNegativeButton(android.R.string.cancel, null); alert.setNegativeButton(android.R.string.cancel, null);

View File

@ -94,11 +94,13 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
GregorianCalendar date = new GregorianCalendar(TimeZone.getTimeZone("UTC")); GregorianCalendar date = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
date.set(year, monthOfYear, dayOfMonth); date.set(year, monthOfYear, dayOfMonth);
if (mOriginalExpiryDate != null) { if (mOriginalExpiryDate != null) {
long numDays = (date.getTimeInMillis() / 86400000) - (mOriginalExpiryDate.getTimeInMillis() / 86400000); long numDays = (date.getTimeInMillis() / 86400000) -
if (numDays == 0) (mOriginalExpiryDate.getTimeInMillis() / 86400000);
if (numDays == 0) {
setExpiryDate(mOriginalExpiryDate); setExpiryDate(mOriginalExpiryDate);
else } else {
setExpiryDate(date); setExpiryDate(date);
}
} else { } else {
setExpiryDate(date); setExpiryDate(date);
} }
@ -316,11 +318,16 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
} }
public int getUsage() { public int getUsage() {
mUsage = (mUsage & ~KeyFlags.CERTIFY_OTHER) | (mChkCertify.isChecked() ? KeyFlags.CERTIFY_OTHER : 0); mUsage = (mUsage & ~KeyFlags.CERTIFY_OTHER) |
mUsage = (mUsage & ~KeyFlags.SIGN_DATA) | (mChkSign.isChecked() ? KeyFlags.SIGN_DATA : 0); (mChkCertify.isChecked() ? KeyFlags.CERTIFY_OTHER : 0);
mUsage = (mUsage & ~KeyFlags.ENCRYPT_COMMS) | (mChkEncrypt.isChecked() ? KeyFlags.ENCRYPT_COMMS : 0); mUsage = (mUsage & ~KeyFlags.SIGN_DATA) |
mUsage = (mUsage & ~KeyFlags.ENCRYPT_STORAGE) | (mChkEncrypt.isChecked() ? KeyFlags.ENCRYPT_STORAGE : 0); (mChkSign.isChecked() ? KeyFlags.SIGN_DATA : 0);
mUsage = (mUsage & ~KeyFlags.AUTHENTICATION) | (mChkAuthenticate.isChecked() ? KeyFlags.AUTHENTICATION : 0); mUsage = (mUsage & ~KeyFlags.ENCRYPT_COMMS) |
(mChkEncrypt.isChecked() ? KeyFlags.ENCRYPT_COMMS : 0);
mUsage = (mUsage & ~KeyFlags.ENCRYPT_STORAGE) |
(mChkEncrypt.isChecked() ? KeyFlags.ENCRYPT_STORAGE : 0);
mUsage = (mUsage & ~KeyFlags.AUTHENTICATION) |
(mChkAuthenticate.isChecked() ? KeyFlags.AUTHENTICATION : 0);
return mUsage; return mUsage;
} }

View File

@ -69,20 +69,22 @@ public class HkpKeyServer extends KeyServer {
/** /**
* pub:%keyid%:%algo%:%keylen%:%creationdate%:%expirationdate%:%flags% * pub:%keyid%:%algo%:%keylen%:%creationdate%:%expirationdate%:%flags%
* <ul> * <ul>
* <li>%<b>keyid</b>% = this is either the fingerprint or the key ID of the key. Either the 16-digit or 8-digit * <li>%<b>keyid</b>% = this is either the fingerprint or the key ID of the key.
* key IDs are acceptable, but obviously the fingerprint is best.</li> * Either the 16-digit or 8-digit key IDs are acceptable, but obviously the fingerprint is best.
* </li>
* <li>%<b>algo</b>% = the algorithm number, (i.e. 1==RSA, 17==DSA, etc). * <li>%<b>algo</b>% = the algorithm number, (i.e. 1==RSA, 17==DSA, etc).
* See <a href="http://tools.ietf.org/html/rfc2440#section-9.1">RFC-2440</a></li> * See <a href="http://tools.ietf.org/html/rfc2440#section-9.1">RFC-2440</a></li>
* <li>%<b>keylen</b>% = the key length (i.e. 1024, 2048, 4096, etc.)</li> * <li>%<b>keylen</b>% = the key length (i.e. 1024, 2048, 4096, etc.)</li>
* <li>%<b>creationdate</b>% = creation date of the key in standard * <li>%<b>creationdate</b>% = creation date of the key in standard
* <a href="http://tools.ietf.org/html/rfc2440#section-9.1">RFC-2440</a> form (i.e. number of seconds since * <a href="http://tools.ietf.org/html/rfc2440#section-9.1">RFC-2440</a> form (i.e. number of
* 1/1/1970 UTC time)</li> * seconds since 1/1/1970 UTC time)</li>
* <li>%<b>expirationdate</b>% = expiration date of the key in standard * <li>%<b>expirationdate</b>% = expiration date of the key in standard
* <a href="http://tools.ietf.org/html/rfc2440#section-9.1">RFC-2440</a> form (i.e. number of seconds since * <a href="http://tools.ietf.org/html/rfc2440#section-9.1">RFC-2440</a> form (i.e. number of
* 1/1/1970 UTC time)</li> * seconds since 1/1/1970 UTC time)</li>
* <li>%<b>flags</b>% = letter codes to indicate details of the key, if any. Flags may be in any order. The * <li>%<b>flags</b>% = letter codes to indicate details of the key, if any. Flags may be in any
* meaning of "disabled" is implementation-specific. Note that individual flags may be unimplemented, so * order. The meaning of "disabled" is implementation-specific. Note that individual flags may
* the absence of a given flag does not necessarily mean the absence of the detail. * be unimplemented, so the absence of a given flag does not necessarily mean the absence of the
* detail.
* <ul> * <ul>
* <li>r == revoked</li> * <li>r == revoked</li>
* <li>d == disabled</li> * <li>d == disabled</li>
@ -91,7 +93,8 @@ public class HkpKeyServer extends KeyServer {
* </li> * </li>
* </ul> * </ul>
* *
* @see <a href="http://tools.ietf.org/html/draft-shaw-openpgp-hkp-00#section-5.2">5.2. Machine Readable Indexes</a> * @see <a href="http://tools.ietf.org/html/draft-shaw-openpgp-hkp-00#section-5.2">
* 5.2. Machine Readable Indexes</a>
* in Internet-Draft OpenPGP HTTP Keyserver Protocol Document * in Internet-Draft OpenPGP HTTP Keyserver Protocol Document
*/ */
public static final Pattern PUB_KEY_LINE = Pattern public static final Pattern PUB_KEY_LINE = Pattern
@ -102,17 +105,19 @@ public class HkpKeyServer extends KeyServer {
/** /**
* uid:%escaped uid string%:%creationdate%:%expirationdate%:%flags% * uid:%escaped uid string%:%creationdate%:%expirationdate%:%flags%
* <ul> * <ul>
* <li>%<b>escaped uid string</b>% = the user ID string, with HTTP %-escaping for anything that isn't 7-bit * <li>%<b>escaped uid string</b>% = the user ID string, with HTTP %-escaping for anything that
* safe as well as for the ":" character. Any other characters may be escaped, as desired.</li> * isn't 7-bit safe as well as for the ":" character. Any other characters may be escaped, as
* desired.</li>
* <li>%<b>creationdate</b>% = creation date of the key in standard * <li>%<b>creationdate</b>% = creation date of the key in standard
* <a href="http://tools.ietf.org/html/rfc2440#section-9.1">RFC-2440</a> form (i.e. number of seconds since * <a href="http://tools.ietf.org/html/rfc2440#section-9.1">RFC-2440</a> form (i.e. number of
* 1/1/1970 UTC time)</li> * seconds since 1/1/1970 UTC time)</li>
* <li>%<b>expirationdate</b>% = expiration date of the key in standard * <li>%<b>expirationdate</b>% = expiration date of the key in standard
* <a href="http://tools.ietf.org/html/rfc2440#section-9.1">RFC-2440</a> form (i.e. number of seconds since * <a href="http://tools.ietf.org/html/rfc2440#section-9.1">RFC-2440</a> form (i.e. number of
* 1/1/1970 UTC time)</li> * seconds since 1/1/1970 UTC time)</li>
* <li>%<b>flags</b>% = letter codes to indicate details of the key, if any. Flags may be in any order. The * <li>%<b>flags</b>% = letter codes to indicate details of the key, if any. Flags may be in any
* meaning of "disabled" is implementation-specific. Note that individual flags may be unimplemented, so * order. The meaning of "disabled" is implementation-specific. Note that individual flags may
* the absence of a given flag does not necessarily mean the absence of the detail. * be unimplemented, so the absence of a given flag does not necessarily mean the absence of
* the detail.
* <ul> * <ul>
* <li>r == revoked</li> * <li>r == revoked</li>
* <li>d == disabled</li> * <li>d == disabled</li>
@ -244,8 +249,7 @@ public class HkpKeyServer extends KeyServer {
entry.setAlgorithm(ImportKeysListEntry.getAlgorithmFromId(algorithmId)); entry.setAlgorithm(ImportKeysListEntry.getAlgorithmFromId(algorithmId));
// group 1 contains the full fingerprint (v4) or the long key id if available // group 1 contains the full fingerprint (v4) or the long key id if available
// see https://bitbucket.org/skskeyserver/sks-keyserver/pull-request/12/fixes-for-machine-readable-indexes/diff // see http://bit.ly/1d4bxbk and http://bit.ly/1gD1wwr
// and https://github.com/openpgp-keychain/openpgp-keychain/issues/259#issuecomment-38168176
String fingerprintOrKeyId = matcher.group(1); String fingerprintOrKeyId = matcher.group(1);
if (fingerprintOrKeyId.length() > 16) { if (fingerprintOrKeyId.length() > 16) {
entry.setFingerPrintHex(fingerprintOrKeyId.toLowerCase(Locale.US)); entry.setFingerPrintHex(fingerprintOrKeyId.toLowerCase(Locale.US));