update OpenPgpApi to version 12

This commit is contained in:
Vincent Breitmoser 2017-06-28 04:16:41 +02:00
parent 0466b985db
commit 6acc2a17bb
4 changed files with 210 additions and 44 deletions

View file

@ -154,7 +154,7 @@ public class PgpMessageBuilder extends MessageBuilder {
throw new MessagingException("encryption is enabled, but no recipient specified!");
}
pgpApiIntent.putExtra(OpenPgpApi.EXTRA_USER_IDS, encryptRecipientAddresses);
pgpApiIntent.putExtra(OpenPgpApi.EXTRA_ENCRYPT_OPPORTUNISTIC, cryptoStatus.isEncryptionOpportunistic());
pgpApiIntent.putExtra(OpenPgpApi.EXTRA_OPPORTUNISTIC_ENCRYPTION, cryptoStatus.isEncryptionOpportunistic());
}
} else {
pgpApiIntent = new Intent(isPgpInlineMode ? OpenPgpApi.ACTION_SIGN : OpenPgpApi.ACTION_DETACHED_SIGN);

View file

@ -277,7 +277,7 @@ public class PgpMessageBuilderTest {
expectedApiIntent.putExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, TEST_SIGN_KEY_ID);
expectedApiIntent.putExtra(OpenPgpApi.EXTRA_KEY_IDS, new long[] { TEST_SELF_ENCRYPT_KEY_ID });
expectedApiIntent.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
expectedApiIntent.putExtra(OpenPgpApi.EXTRA_ENCRYPT_OPPORTUNISTIC, false);
expectedApiIntent.putExtra(OpenPgpApi.EXTRA_OPPORTUNISTIC_ENCRYPTION, false);
expectedApiIntent.putExtra(OpenPgpApi.EXTRA_USER_IDS, cryptoStatus.getRecipientAddresses());
assertIntentEqualsActionAndExtras(expectedApiIntent, capturedApiIntent.getValue());
@ -330,7 +330,7 @@ public class PgpMessageBuilderTest {
expectedApiIntent.putExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, TEST_SIGN_KEY_ID);
expectedApiIntent.putExtra(OpenPgpApi.EXTRA_KEY_IDS, new long[] { TEST_SELF_ENCRYPT_KEY_ID });
expectedApiIntent.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
expectedApiIntent.putExtra(OpenPgpApi.EXTRA_ENCRYPT_OPPORTUNISTIC, false);
expectedApiIntent.putExtra(OpenPgpApi.EXTRA_OPPORTUNISTIC_ENCRYPTION, false);
expectedApiIntent.putExtra(OpenPgpApi.EXTRA_USER_IDS, cryptoStatus.getRecipientAddresses());
assertIntentEqualsActionAndExtras(expectedApiIntent, capturedApiIntent.getValue());

View file

@ -0,0 +1,131 @@
/*
* Copyright (C) 2014-2015 Dominik Schürmann <dominik@dominikschuermann.de>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openintents.openpgp;
import java.util.Date;
import android.os.Parcel;
import android.os.Parcelable;
@SuppressWarnings("unused")
public class AutocryptPeerUpdate implements Parcelable {
/**
* Since there might be a case where new versions of the client using the library getting
* old versions of the protocol (and thus old versions of this class), we need a versioning
* system for the parcels sent between the clients and the providers.
*/
private static final int PARCELABLE_VERSION = 1;
private final byte[] keyData;
private final Date effectiveDate;
private final PreferEncrypt preferEncrypt;
private AutocryptPeerUpdate(byte[] keyData, Date effectiveDate, PreferEncrypt preferEncrypt) {
this.keyData = keyData;
this.effectiveDate = effectiveDate;
this.preferEncrypt = preferEncrypt;
}
private AutocryptPeerUpdate(Parcel source, int version) {
this.keyData = source.createByteArray();
this.effectiveDate = source.readInt() != 0 ? new Date(source.readLong()) : null;
this.preferEncrypt = PreferEncrypt.values()[source.readInt()];
}
public static AutocryptPeerUpdate createAutocryptPeerUpdate(byte[] keyData, Date timestamp) {
return new AutocryptPeerUpdate(keyData, timestamp, PreferEncrypt.NOPREFERENCE);
}
public byte[] getKeyData() {
return keyData;
}
public boolean hasKeyData() {
return keyData != null;
}
public Date getEffectiveDate() {
return effectiveDate;
}
public PreferEncrypt getPreferEncrypt() {
return preferEncrypt;
}
public int describeContents() {
return 0;
}
public void writeToParcel(Parcel dest, int flags) {
/**
* NOTE: When adding fields in the process of updating this API, make sure to bump
* {@link #PARCELABLE_VERSION}.
*/
dest.writeInt(PARCELABLE_VERSION);
// Inject a placeholder that will store the parcel size from this point on
// (not including the size itself).
int sizePosition = dest.dataPosition();
dest.writeInt(0);
int startPosition = dest.dataPosition();
// version 1
dest.writeByteArray(keyData);
if (effectiveDate != null) {
dest.writeInt(1);
dest.writeLong(effectiveDate.getTime());
} else {
dest.writeInt(0);
}
dest.writeInt(preferEncrypt.ordinal());
// Go back and write the size
int parcelableSize = dest.dataPosition() - startPosition;
dest.setDataPosition(sizePosition);
dest.writeInt(parcelableSize);
dest.setDataPosition(startPosition + parcelableSize);
}
public static final Creator<AutocryptPeerUpdate> CREATOR = new Creator<AutocryptPeerUpdate>() {
public AutocryptPeerUpdate createFromParcel(final Parcel source) {
int version = source.readInt(); // parcelableVersion
int parcelableSize = source.readInt();
int startPosition = source.dataPosition();
AutocryptPeerUpdate vr = new AutocryptPeerUpdate(source, version);
// skip over all fields added in future versions of this parcel
source.setDataPosition(startPosition + parcelableSize);
return vr;
}
public AutocryptPeerUpdate[] newArray(final int size) {
return new AutocryptPeerUpdate[size];
}
};
public enum PreferEncrypt {
NOPREFERENCE, MUTUAL;
}
}

View file

@ -38,7 +38,6 @@ import org.openintents.openpgp.util.ParcelFileDescriptorUtil.DataSinkTransferThr
import org.openintents.openpgp.util.ParcelFileDescriptorUtil.DataSourceTransferThread;
@SuppressWarnings("unused")
public class OpenPgpApi {
public static final String TAG = "OpenPgp API";
@ -48,7 +47,7 @@ public class OpenPgpApi {
/**
* see CHANGELOG.md
*/
public static final int API_VERSION = 10;
public static final int API_VERSION = 12;
/**
* General extras
@ -63,16 +62,16 @@ public class OpenPgpApi {
* PendingIntent RESULT_INTENT (if RESULT_CODE == RESULT_CODE_USER_INTERACTION_REQUIRED)
*/
/**
* This action performs no operation, but can be used to check if the App has permission
* to access the API in general, returning a user interaction PendingIntent otherwise.
* This can be used to trigger the permission dialog explicitly.
*
* This action uses no extras.
*/
public static final String ACTION_CHECK_PERMISSION = "org.openintents.openpgp.action.CHECK_PERMISSION";
/**
* DEPRECATED
* Same as ACTION_CLEARTEXT_SIGN
* <p/>
* optional extras:
* boolean EXTRA_REQUEST_ASCII_ARMOR (DEPRECATED: this makes no sense here)
* char[] EXTRA_PASSPHRASE (key passphrase)
*/
@Deprecated
public static final String ACTION_SIGN = "org.openintents.openpgp.action.SIGN";
/**
@ -81,10 +80,10 @@ public class OpenPgpApi {
* cleartext signatures per RFC 4880 before the text is actually signed:
* - end cleartext with newline
* - remove whitespaces on line endings
* <p/>
*
* required extras:
* long EXTRA_SIGN_KEY_ID (key id of signing key)
* <p/>
*
* optional extras:
* char[] EXTRA_PASSPHRASE (key passphrase)
*/
@ -94,49 +93,50 @@ public class OpenPgpApi {
* Sign text or binary data resulting in a detached signature.
* No OutputStream necessary for ACTION_DETACHED_SIGN (No magic pre-processing like in ACTION_CLEARTEXT_SIGN)!
* The detached signature is returned separately in RESULT_DETACHED_SIGNATURE.
* <p/>
*
* required extras:
* long EXTRA_SIGN_KEY_ID (key id of signing key)
* <p/>
*
* optional extras:
* boolean EXTRA_REQUEST_ASCII_ARMOR (request ascii armor for detached signature)
* char[] EXTRA_PASSPHRASE (key passphrase)
* <p/>
*
* returned extras:
* byte[] RESULT_DETACHED_SIGNATURE
* String RESULT_SIGNATURE_MICALG (contains the name of the used signature algorithm as a string)
*/
public static final String ACTION_DETACHED_SIGN = "org.openintents.openpgp.action.DETACHED_SIGN";
/**
* Encrypt
* <p/>
*
* required extras:
* String[] EXTRA_USER_IDS (=emails of recipients, if more than one key has a user_id, a PendingIntent is returned via RESULT_INTENT)
* or
* long[] EXTRA_KEY_IDS
* <p/>
*
* optional extras:
* boolean EXTRA_REQUEST_ASCII_ARMOR (request ascii armor for output)
* char[] EXTRA_PASSPHRASE (key passphrase)
* String EXTRA_ORIGINAL_FILENAME (original filename to be encrypted as metadata)
* boolean EXTRA_ENABLE_COMPRESSION (enable ZLIB compression, default is true)
* boolean EXTRA_ENABLE_COMPRESSION (enable ZLIB compression, default ist true)
*/
public static final String ACTION_ENCRYPT = "org.openintents.openpgp.action.ENCRYPT";
/**
* Sign and encrypt
* <p/>
*
* required extras:
* String[] EXTRA_USER_IDS (=emails of recipients, if more than one key has a user_id, a PendingIntent is returned via RESULT_INTENT)
* or
* long[] EXTRA_KEY_IDS
* <p/>
*
* optional extras:
* long EXTRA_SIGN_KEY_ID (key id of signing key)
* boolean EXTRA_REQUEST_ASCII_ARMOR (request ascii armor for output)
* char[] EXTRA_PASSPHRASE (key passphrase)
* String EXTRA_ORIGINAL_FILENAME (original filename to be encrypted as metadata)
* boolean EXTRA_ENABLE_COMPRESSION (enable ZLIB compression, default is true)
* boolean EXTRA_ENABLE_COMPRESSION (enable ZLIB compression, default ist true)
*/
public static final String ACTION_SIGN_AND_ENCRYPT = "org.openintents.openpgp.action.SIGN_AND_ENCRYPT";
@ -144,15 +144,15 @@ public class OpenPgpApi {
* Decrypts and verifies given input stream. This methods handles encrypted-only, signed-and-encrypted,
* and also signed-only input.
* OutputStream is optional, e.g., for verifying detached signatures!
* <p/>
*
* If OpenPgpSignatureResult.getResult() == OpenPgpSignatureResult.RESULT_KEY_MISSING
* in addition a PendingIntent is returned via RESULT_INTENT to download missing keys.
* On all other status, in addition a PendingIntent is returned via RESULT_INTENT to open
* the key view in OpenKeychain.
* <p/>
*
* optional extras:
* byte[] EXTRA_DETACHED_SIGNATURE (detached signature)
* <p/>
*
* returned extras:
* OpenPgpSignatureResult RESULT_SIGNATURE
* OpenPgpDecryptionResult RESULT_DECRYPTION
@ -163,9 +163,9 @@ public class OpenPgpApi {
/**
* Decrypts the header of an encrypted file to retrieve metadata such as original filename.
* <p/>
*
* This does not decrypt the actual content of the file.
* <p/>
*
* returned extras:
* OpenPgpDecryptMetadata RESULT_METADATA
* String RESULT_CHARSET (charset which was specified in the headers of ascii armored input, if any)
@ -174,10 +174,10 @@ public class OpenPgpApi {
/**
* Select key id for signing
* <p/>
*
* optional extras:
* String EXTRA_USER_ID
* <p/>
*
* returned extras:
* long EXTRA_SIGN_KEY_ID
*/
@ -185,10 +185,10 @@ public class OpenPgpApi {
/**
* Get key ids based on given user ids (=emails)
* <p/>
*
* required extras:
* String[] EXTRA_USER_IDS
* <p/>
*
* returned extras:
* long[] RESULT_KEY_IDS
*/
@ -197,26 +197,43 @@ public class OpenPgpApi {
/**
* This action returns RESULT_CODE_SUCCESS if the OpenPGP Provider already has the key
* corresponding to the given key id in its database.
* <p/>
*
* It returns RESULT_CODE_USER_INTERACTION_REQUIRED if the Provider does not have the key.
* The PendingIntent from RESULT_INTENT can be used to retrieve those from a keyserver.
* <p/>
*
* If an Output stream has been defined the whole public key is returned.
* required extras:
* long EXTRA_KEY_ID
* <p/>
*
* optional extras:
* String EXTRA_REQUEST_ASCII_ARMOR (request that the returned key is encoded in ASCII Armor)
*
*/
public static final String ACTION_GET_KEY = "org.openintents.openpgp.action.GET_KEY";
/**
* Backup all keys given by EXTRA_KEY_IDS and if requested their secret parts.
* The encrypted backup will be written to the OutputStream.
* The client app has no access to the backup code used to encrypt the backup!
* This operation always requires user interaction with RESULT_CODE_USER_INTERACTION_REQUIRED!
*
* required extras:
* long[] EXTRA_KEY_IDS (keys that should be included in the backup)
* boolean EXTRA_BACKUP_SECRET (also backup secret keys)
*/
public static final String ACTION_BACKUP = "org.openintents.openpgp.action.BACKUP";
/**
* Update the status of some Autocrypt peer, identified by their peer id.
*
* required extras:
* String EXTRA_AUTOCRYPT_PEER_ID (autocrypt peer id to update)
* AutocryptPeerUpdate EXTRA_AUTOCRYPT_PEER_UPDATE (actual peer update)
*/
public static final String ACTION_UPDATE_AUTOCRYPT_PEER = "org.openintents.openpgp.action.UPDATE_AUTOCRYPT_PEER";
/* Intent extras */
public static final String EXTRA_API_VERSION = "api_version";
// DEPRECATED!!!
public static final String EXTRA_ACCOUNT_NAME = "account_name";
// ACTION_DETACHED_SIGN, ENCRYPT, SIGN_AND_ENCRYPT, DECRYPT_VERIFY
// request ASCII Armor for output
// OpenPGP Radix-64, 33 percent overhead compared to binary, see http://tools.ietf.org/html/rfc4880#page-53)
@ -226,23 +243,37 @@ public class OpenPgpApi {
public static final String RESULT_DETACHED_SIGNATURE = "detached_signature";
public static final String RESULT_SIGNATURE_MICALG = "signature_micalg";
// ENCRYPT, SIGN_AND_ENCRYPT
// ENCRYPT, SIGN_AND_ENCRYPT, QUERY_AUTOCRYPT_STATUS
public static final String EXTRA_USER_IDS = "user_ids";
public static final String EXTRA_KEY_IDS = "key_ids";
public static final String EXTRA_KEY_IDS_SELECTED = "key_ids_selected";
public static final String EXTRA_SIGN_KEY_ID = "sign_key_id";
public static final String RESULT_KEYS_CONFIRMED = "keys_confirmed";
public static final String RESULT_AUTOCRYPT_STATUS = "autocrypt_status";
public static final int AUTOCRYPT_STATUS_UNAVAILABLE = 0;
public static final int AUTOCRYPT_STATUS_DISCOURAGE = 1;
public static final int AUTOCRYPT_STATUS_AVAILABLE = 2;
public static final int AUTOCRYPT_STATUS_MUTUAL = 3;
// optional extras:
public static final String EXTRA_PASSPHRASE = "passphrase";
public static final String EXTRA_ORIGINAL_FILENAME = "original_filename";
public static final String EXTRA_ENABLE_COMPRESSION = "enable_compression";
public static final String EXTRA_ENCRYPT_OPPORTUNISTIC = "opportunistic";
public static final String EXTRA_OPPORTUNISTIC_ENCRYPTION = "opportunistic";
// GET_SIGN_KEY_ID
public static final String EXTRA_USER_ID = "user_id";
// GET_KEY
public static final String EXTRA_KEY_ID = "key_id";
public static final String EXTRA_MINIMIZE = "minimize";
public static final String EXTRA_MINIMIZE_USER_ID = "minimize_user_id";
public static final String RESULT_KEY_IDS = "key_ids";
// BACKUP
public static final String EXTRA_BACKUP_SECRET = "backup_secret";
/* Service Intent returns */
public static final String RESULT_CODE = "result_code";
@ -258,10 +289,10 @@ public class OpenPgpApi {
public static final String RESULT_INTENT = "intent";
// DECRYPT_VERIFY
public static final String EXTRA_DECRYPTION_RESULT = "decryption_result";
public static final String EXTRA_DETACHED_SIGNATURE = "detached_signature";
public static final String EXTRA_PROGRESS_MESSENGER = "progress_messenger";
public static final String EXTRA_DATA_LENGTH = "data_length";
public static final String EXTRA_DECRYPTION_RESULT = "decryption_result";
public static final String EXTRA_SENDER_ADDRESS = "sender_address";
public static final String EXTRA_SUPPORT_OVERRIDE_CRYPTO_WARNING = "support_override_crpto_warning";
public static final String RESULT_SIGNATURE = "signature";
@ -272,7 +303,11 @@ public class OpenPgpApi {
// This will be the charset which was specified in the headers of ascii armored input, if any
public static final String RESULT_CHARSET = "charset";
// INTERNAL, should not be used
// UPDATE_AUTOCRYPT_PEER
public static final String EXTRA_AUTOCRYPT_PEER_ID = "autocrypt_peer_id";
public static final String EXTRA_AUTOCRYPT_PEER_UPDATE = "autocrypt_peer_update";
// INTERNAL, must not be used
public static final String EXTRA_CALL_UUID1 = "call_uuid1";
public static final String EXTRA_CALL_UUID2 = "call_uuid2";