mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 11:12:15 -05:00
Merge branch 'development' of github.com:open-keychain/open-keychain into development
This commit is contained in:
commit
80f2822dd8
@ -38,6 +38,7 @@ import org.sufficientlysecure.keychain.pgp.PgpKeyOperation;
|
||||
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
|
||||
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing.IteratorWithIOThrow;
|
||||
import org.sufficientlysecure.keychain.pgp.WrappedSignature;
|
||||
import org.sufficientlysecure.keychain.pgp.WrappedUserAttribute;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract.Certs;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.service.CertifyActionsParcel;
|
||||
@ -54,14 +55,15 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.security.Security;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@org.robolectric.annotation.Config(emulateSdk = 18) // Robolectric doesn't yet support 19
|
||||
public class CertifyOperationTest {
|
||||
|
||||
static String mPassphrase = TestingUtils.genPassphrase(true);
|
||||
|
||||
static UncachedKeyRing mStaticRing1, mStaticRing2;
|
||||
static String mKeyPhrase1 = TestingUtils.genPassphrase(true);
|
||||
static String mKeyPhrase2 = TestingUtils.genPassphrase(true);
|
||||
@ -74,6 +76,8 @@ public class CertifyOperationTest {
|
||||
oldShadowStream = ShadowLog.stream;
|
||||
// ShadowLog.stream = System.out;
|
||||
|
||||
Random random = new Random();
|
||||
|
||||
PgpKeyOperation op = new PgpKeyOperation(null);
|
||||
|
||||
{
|
||||
@ -102,8 +106,14 @@ public class CertifyOperationTest {
|
||||
Algorithm.DSA, 1024, null, KeyFlags.SIGN_DATA, 0L));
|
||||
parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(
|
||||
Algorithm.ELGAMAL, 1024, null, KeyFlags.ENCRYPT_COMMS, 0L));
|
||||
|
||||
parcel.mAddUserIds.add("ditz");
|
||||
parcel.mNewUnlock = new ChangeUnlockParcel(null, "1234");
|
||||
byte[] uatdata = new byte[random.nextInt(150)+10];
|
||||
random.nextBytes(uatdata);
|
||||
parcel.mAddUserAttribute.add(
|
||||
WrappedUserAttribute.fromSubpacket(random.nextInt(100)+1, uatdata));
|
||||
|
||||
parcel.mNewUnlock = new ChangeUnlockParcel(mKeyPhrase2);
|
||||
|
||||
PgpEditKeyResult result = op.createSecretKeyRing(parcel);
|
||||
Assert.assertTrue("initial test key creation must succeed", result.success());
|
||||
@ -140,7 +150,7 @@ public class CertifyOperationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCertify() throws Exception {
|
||||
public void testCertifyId() throws Exception {
|
||||
CertifyOperation op = operationWithFakePassphraseCache(
|
||||
mStaticRing1.getMasterKeyId(), mStaticRing1.getMasterKeyId(), mKeyPhrase1);
|
||||
|
||||
@ -152,7 +162,8 @@ public class CertifyOperationTest {
|
||||
}
|
||||
|
||||
CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId());
|
||||
actions.add(new CertifyAction(mStaticRing2.getMasterKeyId()));
|
||||
actions.add(new CertifyAction(mStaticRing2.getMasterKeyId(),
|
||||
mStaticRing2.getPublicKey().getUnorderedUserIds()));
|
||||
CertifyResult result = op.certify(actions, null);
|
||||
|
||||
Assert.assertTrue("certification must succeed", result.success());
|
||||
@ -166,13 +177,43 @@ public class CertifyOperationTest {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCertifyAttribute() throws Exception {
|
||||
CertifyOperation op = operationWithFakePassphraseCache(
|
||||
mStaticRing1.getMasterKeyId(), mStaticRing1.getMasterKeyId(), mKeyPhrase1);
|
||||
|
||||
{
|
||||
CanonicalizedPublicKeyRing ring = new ProviderHelper(Robolectric.application)
|
||||
.getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId());
|
||||
Assert.assertEquals("public key must not be marked verified prior to certification",
|
||||
Certs.UNVERIFIED, ring.getVerified());
|
||||
}
|
||||
|
||||
CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId());
|
||||
actions.add(new CertifyAction(mStaticRing2.getMasterKeyId(), null,
|
||||
mStaticRing2.getPublicKey().getUnorderedUserAttributes()));
|
||||
CertifyResult result = op.certify(actions, null);
|
||||
|
||||
Assert.assertTrue("certification must succeed", result.success());
|
||||
|
||||
{
|
||||
CanonicalizedPublicKeyRing ring = new ProviderHelper(Robolectric.application)
|
||||
.getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId());
|
||||
Assert.assertEquals("new key must be verified now",
|
||||
Certs.VERIFIED_SECRET, ring.getVerified());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCertifySelf() throws Exception {
|
||||
CertifyOperation op = operationWithFakePassphraseCache(
|
||||
mStaticRing1.getMasterKeyId(), mStaticRing1.getMasterKeyId(), mKeyPhrase1);
|
||||
|
||||
CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId());
|
||||
actions.add(new CertifyAction(mStaticRing1.getMasterKeyId()));
|
||||
actions.add(new CertifyAction(mStaticRing1.getMasterKeyId(),
|
||||
mStaticRing2.getPublicKey().getUnorderedUserIds()));
|
||||
|
||||
CertifyResult result = op.certify(actions, null);
|
||||
|
||||
@ -188,7 +229,9 @@ public class CertifyOperationTest {
|
||||
|
||||
{
|
||||
CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId());
|
||||
actions.add(new CertifyAction(1234L));
|
||||
ArrayList<String> uids = new ArrayList<String>();
|
||||
uids.add("nonexistent");
|
||||
actions.add(new CertifyAction(1234L, uids));
|
||||
|
||||
CertifyResult result = op.certify(actions, null);
|
||||
|
||||
@ -199,7 +242,8 @@ public class CertifyOperationTest {
|
||||
|
||||
{
|
||||
CertifyActionsParcel actions = new CertifyActionsParcel(1234L);
|
||||
actions.add(new CertifyAction(mStaticRing1.getMasterKeyId()));
|
||||
actions.add(new CertifyAction(mStaticRing1.getMasterKeyId(),
|
||||
mStaticRing2.getPublicKey().getUnorderedUserIds()));
|
||||
|
||||
CertifyResult result = op.certify(actions, null);
|
||||
|
||||
|
@ -101,18 +101,26 @@ public class CertifyOperation extends BaseOperation {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (action.mUserIds == null) {
|
||||
log.add(LogType.MSG_CRT_CERTIFY_ALL, 2,
|
||||
KeyFormattingUtils.convertKeyIdToHex(action.mMasterKeyId));
|
||||
} else {
|
||||
log.add(LogType.MSG_CRT_CERTIFY_SOME, 2, action.mUserIds.size(),
|
||||
KeyFormattingUtils.convertKeyIdToHex(action.mMasterKeyId));
|
||||
}
|
||||
|
||||
CanonicalizedPublicKeyRing publicRing =
|
||||
mProviderHelper.getCanonicalizedPublicKeyRing(action.mMasterKeyId);
|
||||
|
||||
UncachedKeyRing certifiedKey = certificationKey.certifyUserIds(publicRing, action.mUserIds, null, null);
|
||||
UncachedKeyRing certifiedKey = null;
|
||||
if (action.mUserIds != null) {
|
||||
log.add(LogType.MSG_CRT_CERTIFY_UIDS, 2, action.mUserIds.size(),
|
||||
KeyFormattingUtils.convertKeyIdToHex(action.mMasterKeyId));
|
||||
|
||||
certifiedKey = certificationKey.certifyUserIds(
|
||||
publicRing, action.mUserIds, null, null);
|
||||
}
|
||||
|
||||
if (action.mUserAttributes != null) {
|
||||
log.add(LogType.MSG_CRT_CERTIFY_UATS, 2, action.mUserAttributes.size(),
|
||||
KeyFormattingUtils.convertKeyIdToHex(action.mMasterKeyId));
|
||||
|
||||
certifiedKey = certificationKey.certifyUserAttributes(
|
||||
publicRing, action.mUserAttributes, null, null);
|
||||
}
|
||||
|
||||
if (certifiedKey == null) {
|
||||
certifyError += 1;
|
||||
log.add(LogType.MSG_CRT_WARN_CERT_FAILED, 3);
|
||||
|
@ -691,8 +691,8 @@ public abstract class OperationResult implements Parcelable {
|
||||
MSG_PSE_SYMMETRIC (LogLevel.INFO, R.string.msg_pse_symmetric),
|
||||
|
||||
MSG_CRT_CERTIFYING (LogLevel.DEBUG, R.string.msg_crt_certifying),
|
||||
MSG_CRT_CERTIFY_ALL (LogLevel.DEBUG, R.string.msg_crt_certify_all),
|
||||
MSG_CRT_CERTIFY_SOME (LogLevel.DEBUG, R.plurals.msg_crt_certify_some),
|
||||
MSG_CRT_CERTIFY_UIDS (LogLevel.DEBUG, R.plurals.msg_crt_certify_uids),
|
||||
MSG_CRT_CERTIFY_UATS (LogLevel.DEBUG, R.plurals.msg_crt_certify_uats),
|
||||
MSG_CRT_ERROR_SELF (LogLevel.ERROR, R.string.msg_crt_error_self),
|
||||
MSG_CRT_ERROR_MASTER_NOT_FOUND (LogLevel.ERROR, R.string.msg_crt_error_master_not_found),
|
||||
MSG_CRT_ERROR_NOTHING (LogLevel.ERROR, R.string.msg_crt_error_nothing),
|
||||
|
@ -30,6 +30,7 @@ import org.spongycastle.openpgp.PGPSignature;
|
||||
import org.spongycastle.openpgp.PGPSignatureGenerator;
|
||||
import org.spongycastle.openpgp.PGPSignatureSubpacketGenerator;
|
||||
import org.spongycastle.openpgp.PGPSignatureSubpacketVector;
|
||||
import org.spongycastle.openpgp.PGPUserAttributeSubpacketVector;
|
||||
import org.spongycastle.openpgp.PGPUtil;
|
||||
import org.spongycastle.openpgp.operator.PBESecretKeyDecryptor;
|
||||
import org.spongycastle.openpgp.operator.PGPContentSignerBuilder;
|
||||
@ -268,7 +269,7 @@ public class CanonicalizedSecretKey extends CanonicalizedPublicKey {
|
||||
* Certify the given pubkeyid with the given masterkeyid.
|
||||
*
|
||||
* @param publicKeyRing Keyring to add certification to.
|
||||
* @param userIds User IDs to certify, or all if null
|
||||
* @param userIds User IDs to certify
|
||||
* @return A keyring with added certifications
|
||||
*/
|
||||
public UncachedKeyRing certifyUserIds(CanonicalizedPublicKeyRing publicKeyRing, List<String> userIds,
|
||||
@ -313,10 +314,8 @@ public class CanonicalizedSecretKey extends CanonicalizedPublicKey {
|
||||
PGPPublicKey publicKey = publicKeyRing.getPublicKey().getPublicKey();
|
||||
|
||||
// fetch public key ring, add the certification and return it
|
||||
Iterable<String> it = userIds != null ? userIds
|
||||
: new IterableIterator<String>(publicKey.getUserIDs());
|
||||
try {
|
||||
for (String userId : it) {
|
||||
for (String userId : userIds) {
|
||||
PGPSignature sig = signatureGenerator.generateCertification(userId, publicKey);
|
||||
publicKey = PGPPublicKey.addCertification(publicKey, userId, sig);
|
||||
}
|
||||
@ -330,6 +329,71 @@ public class CanonicalizedSecretKey extends CanonicalizedPublicKey {
|
||||
return new UncachedKeyRing(ring);
|
||||
}
|
||||
|
||||
/**
|
||||
* Certify the given user attributes with the given masterkeyid.
|
||||
*
|
||||
* @param publicKeyRing Keyring to add certification to.
|
||||
* @param userAttributes User IDs to certify, or all if null
|
||||
* @return A keyring with added certifications
|
||||
*/
|
||||
public UncachedKeyRing certifyUserAttributes(CanonicalizedPublicKeyRing publicKeyRing,
|
||||
List<WrappedUserAttribute> userAttributes, byte[] nfcSignedHash, Date nfcCreationTimestamp) {
|
||||
if (mPrivateKeyState == PRIVATE_KEY_STATE_LOCKED) {
|
||||
throw new PrivateKeyNotUnlockedException();
|
||||
}
|
||||
if (!isMasterKey()) {
|
||||
throw new AssertionError("tried to certify with non-master key, this is a programming error!");
|
||||
}
|
||||
if (publicKeyRing.getMasterKeyId() == getKeyId()) {
|
||||
throw new AssertionError("key tried to self-certify, this is a programming error!");
|
||||
}
|
||||
|
||||
// create a signatureGenerator from the supplied masterKeyId and passphrase
|
||||
PGPSignatureGenerator signatureGenerator;
|
||||
{
|
||||
// TODO: SHA256 fixed?
|
||||
PGPContentSignerBuilder contentSignerBuilder = getContentSignerBuilder(PGPUtil.SHA256,
|
||||
nfcSignedHash, nfcCreationTimestamp);
|
||||
|
||||
signatureGenerator = new PGPSignatureGenerator(contentSignerBuilder);
|
||||
try {
|
||||
signatureGenerator.init(PGPSignature.DEFAULT_CERTIFICATION, mPrivateKey);
|
||||
} catch (PGPException e) {
|
||||
Log.e(Constants.TAG, "signing error", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
{ // supply signatureGenerator with a SubpacketVector
|
||||
PGPSignatureSubpacketGenerator spGen = new PGPSignatureSubpacketGenerator();
|
||||
if (nfcCreationTimestamp != null) {
|
||||
spGen.setSignatureCreationTime(false, nfcCreationTimestamp);
|
||||
Log.d(Constants.TAG, "For NFC: set sig creation time to " + nfcCreationTimestamp);
|
||||
}
|
||||
PGPSignatureSubpacketVector packetVector = spGen.generate();
|
||||
signatureGenerator.setHashedSubpackets(packetVector);
|
||||
}
|
||||
|
||||
// get the master subkey (which we certify for)
|
||||
PGPPublicKey publicKey = publicKeyRing.getPublicKey().getPublicKey();
|
||||
|
||||
// fetch public key ring, add the certification and return it
|
||||
try {
|
||||
for (WrappedUserAttribute userAttribute : userAttributes) {
|
||||
PGPUserAttributeSubpacketVector vector = userAttribute.getVector();
|
||||
PGPSignature sig = signatureGenerator.generateCertification(vector, publicKey);
|
||||
publicKey = PGPPublicKey.addCertification(publicKey, vector, sig);
|
||||
}
|
||||
} catch (PGPException e) {
|
||||
Log.e(Constants.TAG, "signing error", e);
|
||||
return null;
|
||||
}
|
||||
|
||||
PGPPublicKeyRing ring = PGPPublicKeyRing.insertPublicKey(publicKeyRing.getRing(), publicKey);
|
||||
|
||||
return new UncachedKeyRing(ring);
|
||||
}
|
||||
|
||||
static class PrivateKeyNotUnlockedException extends RuntimeException {
|
||||
// this exception is a programming error which happens when an operation which requires
|
||||
// the private key is called without a previous call to unlock()
|
||||
|
@ -24,6 +24,9 @@ import android.os.Parcelable;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.sufficientlysecure.keychain.pgp.WrappedUserAttribute;
|
||||
|
||||
|
||||
/**
|
||||
* This class is a a transferable representation for a number of keyrings to
|
||||
* be certified.
|
||||
@ -76,14 +79,19 @@ public class CertifyActionsParcel implements Parcelable {
|
||||
final public long mMasterKeyId;
|
||||
|
||||
final public ArrayList<String> mUserIds;
|
||||
|
||||
public CertifyAction(long masterKeyId) {
|
||||
this(masterKeyId, null);
|
||||
}
|
||||
final public ArrayList<WrappedUserAttribute> mUserAttributes;
|
||||
|
||||
public CertifyAction(long masterKeyId, ArrayList<String> userIds) {
|
||||
mMasterKeyId = masterKeyId;
|
||||
mUserIds = userIds;
|
||||
mUserAttributes = null;
|
||||
}
|
||||
|
||||
public CertifyAction(long masterKeyId, ArrayList<String> userIds,
|
||||
ArrayList<WrappedUserAttribute> attributes) {
|
||||
mMasterKeyId = masterKeyId;
|
||||
mUserIds = userIds;
|
||||
mUserAttributes = attributes;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,23 +31,19 @@ import android.widget.EditText;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.ui.CreateKeyActivity.FragAction;
|
||||
import org.sufficientlysecure.keychain.ui.widget.EmailEditText;
|
||||
import org.sufficientlysecure.keychain.ui.widget.PasswordEditText;
|
||||
import org.sufficientlysecure.keychain.ui.widget.passwordstrengthindicator.PasswordStrengthView;
|
||||
import org.sufficientlysecure.keychain.ui.widget.PassphraseEditText;
|
||||
import org.sufficientlysecure.keychain.util.ContactHelper;
|
||||
|
||||
public class CreateKeyInputFragment extends Fragment {
|
||||
|
||||
CreateKeyActivity mCreateKeyActivity;
|
||||
|
||||
PasswordStrengthView mPassphraseStrengthView;
|
||||
AutoCompleteTextView mNameEdit;
|
||||
EmailEditText mEmailEdit;
|
||||
PasswordEditText mPassphraseEdit;
|
||||
EditText mPassphraseEditAgain;
|
||||
View mCreateButton;
|
||||
|
||||
public static final String ARG_NAME = "name";
|
||||
public static final String ARG_EMAIL = "email";
|
||||
CreateKeyActivity mCreateKeyActivity;
|
||||
AutoCompleteTextView mNameEdit;
|
||||
EmailEditText mEmailEdit;
|
||||
PassphraseEditText mPassphraseEdit;
|
||||
EditText mPassphraseEditAgain;
|
||||
View mCreateButton;
|
||||
|
||||
/**
|
||||
* Creates new instance of this fragment
|
||||
@ -64,15 +60,47 @@ public class CreateKeyInputFragment extends Fragment {
|
||||
return frag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if text of given EditText is not empty. If it is empty an error is
|
||||
* set and the EditText gets the focus.
|
||||
*
|
||||
* @param context
|
||||
* @param editText
|
||||
* @return true if EditText is not empty
|
||||
*/
|
||||
private static boolean isEditTextNotEmpty(Context context, EditText editText) {
|
||||
boolean output = true;
|
||||
if (editText.getText().toString().length() == 0) {
|
||||
editText.setError(context.getString(R.string.create_key_empty));
|
||||
editText.requestFocus();
|
||||
output = false;
|
||||
} else {
|
||||
editText.setError(null);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
private static boolean areEditTextsEqual(Context context, EditText editText1, EditText editText2) {
|
||||
boolean output = true;
|
||||
if (!editText1.getText().toString().equals(editText2.getText().toString())) {
|
||||
editText2.setError(context.getString(R.string.create_key_passphrases_not_equal));
|
||||
editText2.requestFocus();
|
||||
output = false;
|
||||
} else {
|
||||
editText2.setError(null);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.create_key_input_fragment, container, false);
|
||||
|
||||
mPassphraseStrengthView = (PasswordStrengthView) view.findViewById(R.id
|
||||
.create_key_passphrase_strength);
|
||||
mNameEdit = (AutoCompleteTextView) view.findViewById(R.id.create_key_name);
|
||||
mPassphraseEdit = (PassphraseEditText) view.findViewById(R.id.create_key_passphrase);
|
||||
mEmailEdit = (EmailEditText) view.findViewById(R.id.create_key_email);
|
||||
mPassphraseEdit = (PasswordEditText) view.findViewById(R.id.create_key_passphrase);
|
||||
mPassphraseEditAgain = (EditText) view.findViewById(R.id.create_key_passphrase_again);
|
||||
mCreateButton = view.findViewById(R.id.create_key_button);
|
||||
|
||||
@ -106,15 +134,6 @@ public class CreateKeyInputFragment extends Fragment {
|
||||
)
|
||||
);
|
||||
|
||||
// Edit text padding doesn't work via xml (http://code.google.com/p/android/issues/detail?id=77982)
|
||||
// so we set the right padding programmatically.
|
||||
mPassphraseEdit.setPadding(mPassphraseEdit.getPaddingLeft(),
|
||||
mPassphraseEdit.getPaddingTop(),
|
||||
(int) (56 * getResources().getDisplayMetrics().density),
|
||||
mPassphraseEdit.getPaddingBottom());
|
||||
|
||||
mPassphraseEdit.setPasswordStrengthView(mPassphraseStrengthView);
|
||||
|
||||
mCreateButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
@ -165,38 +184,4 @@ public class CreateKeyInputFragment extends Fragment {
|
||||
inputManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if text of given EditText is not empty. If it is empty an error is
|
||||
* set and the EditText gets the focus.
|
||||
*
|
||||
* @param context
|
||||
* @param editText
|
||||
* @return true if EditText is not empty
|
||||
*/
|
||||
private static boolean isEditTextNotEmpty(Context context, EditText editText) {
|
||||
boolean output = true;
|
||||
if (editText.getText().toString().length() == 0) {
|
||||
editText.setError(context.getString(R.string.create_key_empty));
|
||||
editText.requestFocus();
|
||||
output = false;
|
||||
} else {
|
||||
editText.setError(null);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
private static boolean areEditTextsEqual(Context context, EditText editText1, EditText editText2) {
|
||||
boolean output = true;
|
||||
if (!editText1.getText().toString().equals(editText2.getText().toString())) {
|
||||
editText2.setError(context.getString(R.string.create_key_passphrases_not_equal));
|
||||
editText2.requestFocus();
|
||||
output = false;
|
||||
} else {
|
||||
editText2.setError(null);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -43,8 +43,7 @@ import android.widget.Toast;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.ui.widget.PasswordEditText;
|
||||
import org.sufficientlysecure.keychain.ui.widget.passwordstrengthindicator.PasswordStrengthView;
|
||||
import org.sufficientlysecure.keychain.ui.widget.PassphraseEditText;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
public class SetPassphraseDialogFragment extends DialogFragment implements OnEditorActionListener {
|
||||
@ -57,10 +56,9 @@ public class SetPassphraseDialogFragment extends DialogFragment implements OnEdi
|
||||
public static final String MESSAGE_NEW_PASSPHRASE = "new_passphrase";
|
||||
|
||||
private Messenger mMessenger;
|
||||
private PasswordEditText mPassphraseEditText;
|
||||
private PassphraseEditText mPassphraseEditText;
|
||||
private EditText mPassphraseAgainEditText;
|
||||
private CheckBox mNoPassphraseCheckBox;
|
||||
private PasswordStrengthView mPassphraseStrengthView;
|
||||
|
||||
/**
|
||||
* Creates new instance of this dialog fragment
|
||||
@ -100,11 +98,9 @@ public class SetPassphraseDialogFragment extends DialogFragment implements OnEdi
|
||||
View view = inflater.inflate(R.layout.passphrase_repeat_dialog, null);
|
||||
alert.setView(view);
|
||||
|
||||
mPassphraseEditText = (PasswordEditText) view.findViewById(R.id.passphrase_passphrase);
|
||||
mPassphraseEditText = (PassphraseEditText) view.findViewById(R.id.passphrase_passphrase);
|
||||
mPassphraseAgainEditText = (EditText) view.findViewById(R.id.passphrase_passphrase_again);
|
||||
mNoPassphraseCheckBox = (CheckBox) view.findViewById(R.id.passphrase_no_passphrase);
|
||||
mPassphraseStrengthView = (PasswordStrengthView) view.findViewById(R.id.passphrase_repeat_passphrase_strength);
|
||||
mPassphraseEditText.setPasswordStrengthView(mPassphraseStrengthView);
|
||||
|
||||
|
||||
if (TextUtils.isEmpty(oldPassphrase)) {
|
||||
|
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.sufficientlysecure.keychain.ui.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.TypedValue;
|
||||
import android.widget.EditText;
|
||||
|
||||
import org.sufficientlysecure.keychain.ui.widget.passwordstrengthindicator.PasswordStrengthBarView;
|
||||
|
||||
public class PassphraseEditText extends EditText {
|
||||
|
||||
PasswordStrengthBarView mPasswordStrengthBarView;
|
||||
int mPasswordBarWidth;
|
||||
int mPasswordBarHeight;
|
||||
float barGap;
|
||||
|
||||
public PassphraseEditText(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
mPasswordBarHeight = (int) (8 * getResources().getDisplayMetrics().density);
|
||||
mPasswordBarWidth = (int) (50 * getResources().getDisplayMetrics().density);
|
||||
|
||||
barGap = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
|
||||
getContext().getResources().getDisplayMetrics());
|
||||
|
||||
this.setPadding(getPaddingLeft(), getPaddingTop(),
|
||||
getPaddingRight() + (int) barGap + mPasswordBarWidth, getPaddingBottom());
|
||||
|
||||
mPasswordStrengthBarView = new PasswordStrengthBarView(context, attrs);
|
||||
mPasswordStrengthBarView.setShowGuides(false);
|
||||
|
||||
this.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
mPasswordStrengthBarView.setPassword(s.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
||||
super.onLayout(changed, left, top, right, bottom);
|
||||
mPasswordStrengthBarView.layout(0, 0, mPasswordBarWidth, mPasswordBarHeight);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
float translateX = getScrollX() + canvas.getWidth() - mPasswordBarWidth;
|
||||
float translateY = (canvas.getHeight() - mPasswordBarHeight) / 2;
|
||||
canvas.translate(translateX, translateY);
|
||||
mPasswordStrengthBarView.draw(canvas);
|
||||
canvas.translate(-translateX, -translateY);
|
||||
}
|
||||
}
|
@ -56,9 +56,6 @@ import org.sufficientlysecure.keychain.R;
|
||||
*/
|
||||
public class PasswordStrengthView extends View {
|
||||
|
||||
protected static final int COLOR_FAIL = Color.parseColor("#e74c3c");
|
||||
protected static final int COLOR_WEAK = Color.parseColor("#e67e22");
|
||||
protected static final int COLOR_STRONG = Color.parseColor("#2ecc71");
|
||||
|
||||
protected int mMinWidth;
|
||||
protected int mMinHeight;
|
||||
@ -100,6 +97,11 @@ public class PasswordStrengthView extends View {
|
||||
|
||||
public PasswordStrengthView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
int COLOR_FAIL = context.getResources().getColor(R.color.android_red_light);
|
||||
int COLOR_WEAK = context.getResources().getColor(R.color.android_orange_light);
|
||||
int COLOR_STRONG = context.getResources().getColor(R.color.android_green_light);
|
||||
|
||||
TypedArray style = context.getTheme().obtainStyledAttributes(
|
||||
attrs,
|
||||
R.styleable.PasswordStrengthView,
|
||||
|
@ -58,34 +58,16 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/label_passphrase" />
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="8dp">
|
||||
|
||||
<org.sufficientlysecure.keychain.ui.widget.PasswordEditText
|
||||
<org.sufficientlysecure.keychain.ui.widget.PassphraseEditText
|
||||
android:id="@+id/create_key_passphrase"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:imeOptions="actionNext"
|
||||
android:inputType="textPassword"
|
||||
android:hint="@string/label_passphrase"
|
||||
android:ems="10"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
|
||||
<org.sufficientlysecure.keychain.ui.widget.passwordstrengthindicator.PasswordStrengthBarView
|
||||
android:id="@+id/create_key_passphrase_strength"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="8dp"
|
||||
android:layout_gravity="end|center_vertical"
|
||||
custom:strength="medium"
|
||||
custom:showGuides="false"
|
||||
custom:color_fail="@color/android_red_light"
|
||||
custom:color_weak="@color/android_orange_light"
|
||||
custom:color_strong="@color/android_green_light" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/create_key_passphrase_again"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -21,7 +21,7 @@
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="8dp">
|
||||
|
||||
<org.sufficientlysecure.keychain.ui.widget.PasswordEditText
|
||||
<org.sufficientlysecure.keychain.ui.widget.PassphraseEditText
|
||||
android:id="@+id/passphrase_passphrase"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@ -29,6 +29,7 @@
|
||||
android:layout_marginBottom="8dp"
|
||||
android:imeOptions="actionNext"
|
||||
android:hint="@string/label_passphrase"
|
||||
android:inputType="textPassword"
|
||||
android:ems="10"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
|
||||
|
@ -1073,11 +1073,14 @@
|
||||
<string name="msg_pse_symmetric">"Preparing symmetric encryption"</string>
|
||||
|
||||
<string name="msg_crt_certifying">"Generating certifications"</string>
|
||||
<string name="msg_crt_certify_all">"Certifying all user IDs for key %s"</string>
|
||||
<plurals name="msg_crt_certify_some">
|
||||
<plurals name="msg_crt_certify_uids">
|
||||
<item quantity="one">"Certifying one user ID for key %2$s"</item>
|
||||
<item quantity="other">"Certifying %1$d user IDs for key %2$s"</item>
|
||||
</plurals>
|
||||
<plurals name="msg_crt_certify_uats">
|
||||
<item quantity="one">"Certifying one user attribute for key %2$s"</item>
|
||||
<item quantity="other">"Certifying %1$d user attributes for key %2$s"</item>
|
||||
</plurals>
|
||||
<string name="msg_crt_error_self">"Cannot issue self-certificate like this!"</string>
|
||||
<string name="msg_crt_error_master_not_found">"Master key not found!"</string>
|
||||
<string name="msg_crt_error_nothing">"No keys certified!"</string>
|
||||
|
Loading…
Reference in New Issue
Block a user