diff --git a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/operations/CertifyOperationTest.java b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/operations/CertifyOperationTest.java index c05f4a029..0af87ada4 100644 --- a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/operations/CertifyOperationTest.java +++ b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/operations/CertifyOperationTest.java @@ -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 uids = new ArrayList(); + 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); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CertifyOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CertifyOperation.java index 025f45f7f..2e9551826 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CertifyOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CertifyOperation.java @@ -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); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java index a96cec8cf..068e314d5 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java @@ -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), diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java index fe5db8c6d..c3fccc789 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java @@ -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 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 it = userIds != null ? userIds - : new IterableIterator(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 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() diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/CertifyActionsParcel.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/CertifyActionsParcel.java index f0dbf0820..f4b941109 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/CertifyActionsParcel.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/CertifyActionsParcel.java @@ -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 mUserIds; - - public CertifyAction(long masterKeyId) { - this(masterKeyId, null); - } + final public ArrayList mUserAttributes; public CertifyAction(long masterKeyId, ArrayList userIds) { mMasterKeyId = masterKeyId; mUserIds = userIds; + mUserAttributes = null; + } + + public CertifyAction(long masterKeyId, ArrayList userIds, + ArrayList attributes) { + mMasterKeyId = masterKeyId; + mUserIds = userIds; + mUserAttributes = attributes; } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyInputFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyInputFragment.java index b496d40fd..ecc609212 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyInputFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyInputFragment.java @@ -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; - } - } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/SetPassphraseDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/SetPassphraseDialogFragment.java index 9e1f21f60..b34dc2edc 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/SetPassphraseDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/SetPassphraseDialogFragment.java @@ -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)) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/PassphraseEditText.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/PassphraseEditText.java new file mode 100644 index 000000000..11d9e8fd0 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/PassphraseEditText.java @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2014 Dominik Schürmann + * + * 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 . + */ + +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); + } +} \ No newline at end of file diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/passwordstrengthindicator/PasswordStrengthView.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/passwordstrengthindicator/PasswordStrengthView.java index d7270ff58..bc5018497 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/passwordstrengthindicator/PasswordStrengthView.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/passwordstrengthindicator/PasswordStrengthView.java @@ -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, diff --git a/OpenKeychain/src/main/res/layout/create_key_input_fragment.xml b/OpenKeychain/src/main/res/layout/create_key_input_fragment.xml index b320885d0..850f22716 100644 --- a/OpenKeychain/src/main/res/layout/create_key_input_fragment.xml +++ b/OpenKeychain/src/main/res/layout/create_key_input_fragment.xml @@ -58,33 +58,15 @@ android:layout_height="wrap_content" android:text="@string/label_passphrase" /> - - - - - - - + android:imeOptions="actionNext" + android:inputType="textPassword" + android:hint="@string/label_passphrase" + android:ems="10" + android:layout_gravity="center_horizontal" /> - diff --git a/OpenKeychain/src/main/res/values/strings.xml b/OpenKeychain/src/main/res/values/strings.xml index c0540082c..a53558532 100644 --- a/OpenKeychain/src/main/res/values/strings.xml +++ b/OpenKeychain/src/main/res/values/strings.xml @@ -1073,11 +1073,14 @@ "Preparing symmetric encryption" "Generating certifications" - "Certifying all user IDs for key %s" - + "Certifying one user ID for key %2$s" "Certifying %1$d user IDs for key %2$s" + + "Certifying one user attribute for key %2$s" + "Certifying %1$d user attributes for key %2$s" + "Cannot issue self-certificate like this!" "Master key not found!" "No keys certified!"