mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 19:22:14 -05:00
Merge branch 'master' of github.com:open-keychain/open-keychain
This commit is contained in:
commit
4db0194e6a
@ -46,6 +46,7 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
|||||||
private String mExtraData;
|
private String mExtraData;
|
||||||
private String mQuery;
|
private String mQuery;
|
||||||
private String mOrigin;
|
private String mOrigin;
|
||||||
|
private Integer mHashCode = null;
|
||||||
|
|
||||||
private boolean mSelected;
|
private boolean mSelected;
|
||||||
|
|
||||||
@ -98,6 +99,13 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public int hashCode() {
|
||||||
|
if (mHashCode != null) {
|
||||||
|
return mHashCode;
|
||||||
|
}
|
||||||
|
return super.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
public String getKeyIdHex() {
|
public String getKeyIdHex() {
|
||||||
return mKeyIdHex;
|
return mKeyIdHex;
|
||||||
}
|
}
|
||||||
@ -240,6 +248,8 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
|||||||
mSecretKey = ring.isSecret();
|
mSecretKey = ring.isSecret();
|
||||||
UncachedPublicKey key = ring.getPublicKey();
|
UncachedPublicKey key = ring.getPublicKey();
|
||||||
|
|
||||||
|
mHashCode = key.hashCode();
|
||||||
|
|
||||||
mPrimaryUserId = key.getPrimaryUserId();
|
mPrimaryUserId = key.getPrimaryUserId();
|
||||||
mUserIds = key.getUnorderedUserIds();
|
mUserIds = key.getUnorderedUserIds();
|
||||||
|
|
||||||
|
@ -27,7 +27,9 @@ public class ParcelableKeyRing implements Parcelable {
|
|||||||
|
|
||||||
public static final Creator<ParcelableKeyRing> CREATOR = new Creator<ParcelableKeyRing>() {
|
public static final Creator<ParcelableKeyRing> CREATOR = new Creator<ParcelableKeyRing>() {
|
||||||
public ParcelableKeyRing createFromParcel(final Parcel source) {
|
public ParcelableKeyRing createFromParcel(final Parcel source) {
|
||||||
return new ParcelableKeyRing(source.createByteArray());
|
byte[] bytes = source.createByteArray();
|
||||||
|
String expectedFingerprint = source.readString();
|
||||||
|
return new ParcelableKeyRing(bytes, expectedFingerprint);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ParcelableKeyRing[] newArray(final int size) {
|
public ParcelableKeyRing[] newArray(final int size) {
|
||||||
|
@ -481,58 +481,4 @@ public class PgpKeyOperation {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Certify the given pubkeyid with the given masterkeyid.
|
|
||||||
*
|
|
||||||
* @param certificationKey Certifying key
|
|
||||||
* @param publicKey public key to certify
|
|
||||||
* @param userIds User IDs to certify, must not be null or empty
|
|
||||||
* @param passphrase Passphrase of the secret key
|
|
||||||
* @return A keyring with added certifications
|
|
||||||
*/
|
|
||||||
public PGPPublicKey certifyKey(PGPSecretKey certificationKey, PGPPublicKey publicKey,
|
|
||||||
List<String> userIds, String passphrase)
|
|
||||||
throws PgpGeneralMsgIdException, NoSuchAlgorithmException, NoSuchProviderException,
|
|
||||||
PGPException, SignatureException {
|
|
||||||
|
|
||||||
// create a signatureGenerator from the supplied masterKeyId and passphrase
|
|
||||||
PGPSignatureGenerator signatureGenerator;
|
|
||||||
{
|
|
||||||
|
|
||||||
if (certificationKey == null) {
|
|
||||||
throw new PgpGeneralMsgIdException(R.string.error_no_signature_key);
|
|
||||||
}
|
|
||||||
|
|
||||||
PBESecretKeyDecryptor keyDecryptor = new JcePBESecretKeyDecryptorBuilder().setProvider(
|
|
||||||
Constants.BOUNCY_CASTLE_PROVIDER_NAME).build(passphrase.toCharArray());
|
|
||||||
PGPPrivateKey signaturePrivateKey = certificationKey.extractPrivateKey(keyDecryptor);
|
|
||||||
if (signaturePrivateKey == null) {
|
|
||||||
throw new PgpGeneralMsgIdException(R.string.error_could_not_extract_private_key);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: SHA256 fixed?
|
|
||||||
JcaPGPContentSignerBuilder contentSignerBuilder = new JcaPGPContentSignerBuilder(
|
|
||||||
certificationKey.getPublicKey().getAlgorithm(), PGPUtil.SHA256)
|
|
||||||
.setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME);
|
|
||||||
|
|
||||||
signatureGenerator = new PGPSignatureGenerator(contentSignerBuilder);
|
|
||||||
signatureGenerator.init(PGPSignature.DEFAULT_CERTIFICATION, signaturePrivateKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
{ // supply signatureGenerator with a SubpacketVector
|
|
||||||
PGPSignatureSubpacketGenerator spGen = new PGPSignatureSubpacketGenerator();
|
|
||||||
PGPSignatureSubpacketVector packetVector = spGen.generate();
|
|
||||||
signatureGenerator.setHashedSubpackets(packetVector);
|
|
||||||
}
|
|
||||||
|
|
||||||
// fetch public key ring, add the certification and return it
|
|
||||||
for (String userId : new IterableIterator<String>(userIds.iterator())) {
|
|
||||||
PGPSignature sig = signatureGenerator.generateCertification(userId, publicKey);
|
|
||||||
publicKey = PGPPublicKey.addCertification(publicKey, userId, sig);
|
|
||||||
}
|
|
||||||
|
|
||||||
return publicKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -498,13 +498,12 @@ public class ProviderHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mIndent -= 1;
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log(LogLevel.ERROR, LogType.MSG_IP_FAIL_IO_EXC);
|
log(LogLevel.ERROR, LogType.MSG_IP_FAIL_IO_EXC);
|
||||||
Log.e(Constants.TAG, "IOException during import", e);
|
Log.e(Constants.TAG, "IOException during import", e);
|
||||||
mIndent -= 1;
|
|
||||||
return SaveKeyringResult.RESULT_ERROR;
|
return SaveKeyringResult.RESULT_ERROR;
|
||||||
|
} finally {
|
||||||
|
mIndent -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -523,19 +522,16 @@ public class ProviderHelper {
|
|||||||
mContentResolver.applyBatch(KeychainContract.CONTENT_AUTHORITY, operations);
|
mContentResolver.applyBatch(KeychainContract.CONTENT_AUTHORITY, operations);
|
||||||
|
|
||||||
log(LogLevel.OK, LogType.MSG_IP_SUCCESS);
|
log(LogLevel.OK, LogType.MSG_IP_SUCCESS);
|
||||||
mIndent -= 1;
|
|
||||||
progress.setProgress(LogType.MSG_IP_SUCCESS.getMsgId(), 90, 100);
|
progress.setProgress(LogType.MSG_IP_SUCCESS.getMsgId(), 90, 100);
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
log(LogLevel.ERROR, LogType.MSG_IP_FAIL_REMOTE_EX);
|
log(LogLevel.ERROR, LogType.MSG_IP_FAIL_REMOTE_EX);
|
||||||
Log.e(Constants.TAG, "RemoteException during import", e);
|
Log.e(Constants.TAG, "RemoteException during import", e);
|
||||||
mIndent -= 1;
|
|
||||||
return SaveKeyringResult.RESULT_ERROR;
|
return SaveKeyringResult.RESULT_ERROR;
|
||||||
} catch (OperationApplicationException e) {
|
} catch (OperationApplicationException e) {
|
||||||
log(LogLevel.ERROR, LogType.MSG_IP_FAIL_OP_EXC);
|
log(LogLevel.ERROR, LogType.MSG_IP_FAIL_OP_EXC);
|
||||||
Log.e(Constants.TAG, "OperationApplicationException during import", e);
|
Log.e(Constants.TAG, "OperationApplicationException during import", e);
|
||||||
mIndent -= 1;
|
|
||||||
return SaveKeyringResult.RESULT_ERROR;
|
return SaveKeyringResult.RESULT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -581,6 +577,7 @@ public class ProviderHelper {
|
|||||||
log(LogLevel.START, LogType.MSG_IS,
|
log(LogLevel.START, LogType.MSG_IS,
|
||||||
new String[]{ PgpKeyHelper.convertKeyIdToHex(masterKeyId) });
|
new String[]{ PgpKeyHelper.convertKeyIdToHex(masterKeyId) });
|
||||||
mIndent += 1;
|
mIndent += 1;
|
||||||
|
try {
|
||||||
|
|
||||||
// Canonicalize this key, to assert a number of assumptions made about it.
|
// Canonicalize this key, to assert a number of assumptions made about it.
|
||||||
keyRing = keyRing.canonicalize(mLog, mIndent);
|
keyRing = keyRing.canonicalize(mLog, mIndent);
|
||||||
@ -651,6 +648,10 @@ public class ProviderHelper {
|
|||||||
log(LogLevel.OK, LogType.MSG_IS_SUCCESS);
|
log(LogLevel.OK, LogType.MSG_IS_SUCCESS);
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
mIndent -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -738,12 +739,13 @@ public class ProviderHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mIndent -= 1;
|
|
||||||
return new SaveKeyringResult(result, mLog);
|
return new SaveKeyringResult(result, mLog);
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log(LogLevel.ERROR, LogType.MSG_IP_FAIL_IO_EXC);
|
log(LogLevel.ERROR, LogType.MSG_IP_FAIL_IO_EXC);
|
||||||
return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog);
|
return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog);
|
||||||
|
} finally {
|
||||||
|
mIndent -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -833,6 +835,8 @@ public class ProviderHelper {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log(LogLevel.ERROR, LogType.MSG_IS_FAIL_IO_EXC, null);
|
log(LogLevel.ERROR, LogType.MSG_IS_FAIL_IO_EXC, null);
|
||||||
return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog);
|
return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog);
|
||||||
|
} finally {
|
||||||
|
mIndent -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import android.os.Parcel;
|
|||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.HashMap;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/** This class is a a transferable representation for a collection of changes
|
/** This class is a a transferable representation for a collection of changes
|
||||||
* to be done on a keyring.
|
* to be done on a keyring.
|
||||||
@ -29,14 +29,14 @@ public class SaveKeyringParcel implements Parcelable {
|
|||||||
|
|
||||||
public String newPassphrase;
|
public String newPassphrase;
|
||||||
|
|
||||||
public String[] addUserIds;
|
public ArrayList<String> addUserIds;
|
||||||
public SubkeyAdd[] addSubKeys;
|
public ArrayList<SubkeyAdd> addSubKeys;
|
||||||
|
|
||||||
public SubkeyChange[] changeSubKeys;
|
public ArrayList<SubkeyChange> changeSubKeys;
|
||||||
public String changePrimaryUserId;
|
public String changePrimaryUserId;
|
||||||
|
|
||||||
public String[] revokeUserIds;
|
public ArrayList<String> revokeUserIds;
|
||||||
public long[] revokeSubKeys;
|
public ArrayList<Long> revokeSubKeys;
|
||||||
|
|
||||||
public SaveKeyringParcel(long masterKeyId, byte[] fingerprint) {
|
public SaveKeyringParcel(long masterKeyId, byte[] fingerprint) {
|
||||||
mMasterKeyId = masterKeyId;
|
mMasterKeyId = masterKeyId;
|
||||||
@ -73,14 +73,14 @@ public class SaveKeyringParcel implements Parcelable {
|
|||||||
mMasterKeyId = source.readLong();
|
mMasterKeyId = source.readLong();
|
||||||
mFingerprint = source.createByteArray();
|
mFingerprint = source.createByteArray();
|
||||||
|
|
||||||
addUserIds = source.createStringArray();
|
addUserIds = source.createStringArrayList();
|
||||||
addSubKeys = (SubkeyAdd[]) source.readSerializable();
|
addSubKeys = (ArrayList<SubkeyAdd>) source.readSerializable();
|
||||||
|
|
||||||
changeSubKeys = (SubkeyChange[]) source.readSerializable();
|
changeSubKeys = (ArrayList<SubkeyChange>) source.readSerializable();
|
||||||
changePrimaryUserId = source.readString();
|
changePrimaryUserId = source.readString();
|
||||||
|
|
||||||
revokeUserIds = source.createStringArray();
|
revokeUserIds = source.createStringArrayList();
|
||||||
revokeSubKeys = source.createLongArray();
|
revokeSubKeys = (ArrayList<Long>) source.readSerializable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -88,14 +88,14 @@ public class SaveKeyringParcel implements Parcelable {
|
|||||||
destination.writeLong(mMasterKeyId);
|
destination.writeLong(mMasterKeyId);
|
||||||
destination.writeByteArray(mFingerprint);
|
destination.writeByteArray(mFingerprint);
|
||||||
|
|
||||||
destination.writeStringArray(addUserIds);
|
destination.writeStringList(addUserIds);
|
||||||
destination.writeSerializable(addSubKeys);
|
destination.writeSerializable(addSubKeys);
|
||||||
|
|
||||||
destination.writeSerializable(changeSubKeys);
|
destination.writeSerializable(changeSubKeys);
|
||||||
destination.writeString(changePrimaryUserId);
|
destination.writeString(changePrimaryUserId);
|
||||||
|
|
||||||
destination.writeStringArray(revokeUserIds);
|
destination.writeStringList(revokeUserIds);
|
||||||
destination.writeLongArray(revokeSubKeys);
|
destination.writeSerializable(revokeSubKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Creator<SaveKeyringParcel> CREATOR = new Creator<SaveKeyringParcel>() {
|
public static final Creator<SaveKeyringParcel> CREATOR = new Creator<SaveKeyringParcel>() {
|
||||||
|
@ -79,7 +79,7 @@ public class ImportKeysListFragment extends ListFragment implements
|
|||||||
public ArrayList<ParcelableKeyRing> getSelectedData() {
|
public ArrayList<ParcelableKeyRing> getSelectedData() {
|
||||||
ArrayList<ParcelableKeyRing> result = new ArrayList<ParcelableKeyRing>();
|
ArrayList<ParcelableKeyRing> result = new ArrayList<ParcelableKeyRing>();
|
||||||
for (ImportKeysListEntry entry : getSelectedEntries()) {
|
for (ImportKeysListEntry entry : getSelectedEntries()) {
|
||||||
result.add(mCachedKeyData.get(entry.getKeyId()));
|
result.add(mCachedKeyData.get(entry.hashCode()));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -138,7 +138,7 @@ public class ImportKeysListLoader
|
|||||||
for(UncachedKeyRing key : rings) {
|
for(UncachedKeyRing key : rings) {
|
||||||
ImportKeysListEntry item = new ImportKeysListEntry(getContext(), key);
|
ImportKeysListEntry item = new ImportKeysListEntry(getContext(), key);
|
||||||
mData.add(item);
|
mData.add(item);
|
||||||
mParcelableRings.put(key.getMasterKeyId(), new ParcelableKeyRing(key.getEncoded()));
|
mParcelableRings.put(item.hashCode(), new ParcelableKeyRing(key.getEncoded()));
|
||||||
isEmpty = false;
|
isEmpty = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user