work on insecurity warning strings

This commit is contained in:
Vincent Breitmoser
2017-05-15 12:58:53 +02:00
parent 2ac1927cac
commit e424ad3f8e
3 changed files with 82 additions and 32 deletions

View File

@@ -39,7 +39,6 @@ import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.ViewAnimator;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.remote.ui.SecurityProblemPresenter.RemoteSecurityProblemView;
@@ -156,8 +155,10 @@ public class RemoteSecurityProblemDialogActivity extends FragmentActivity {
final LinearLayout insecureWarningLayout = (LinearLayout) view.findViewById(R.id.insecure_warning_layout);
final ImageView iconClientApp = (ImageView) view.findViewById(R.id.icon_client_app);
final TextView explanationText = (TextView) insecureWarningLayout.findViewById(R.id.dialog_insecure_text);
final TextView recommendText = (TextView) insecureWarningLayout.findViewById(R.id.dialog_insecure_recommend_text);
final TextView overrideText = (TextView) insecureWarningLayout.findViewById(R.id.dialog_insecure_override_text);
final TextView recommendText =
(TextView) insecureWarningLayout.findViewById(R.id.dialog_insecure_recommend_text);
final TextView overrideText =
(TextView) insecureWarningLayout.findViewById(R.id.dialog_insecure_override_text);
final ToolableViewAnimator secondaryLayoutAnimator =
(ToolableViewAnimator) insecureWarningLayout.findViewById(R.id.dialog_insecure_secondary_layout);
final ToolableViewAnimator buttonBarAnimator =
@@ -200,13 +201,6 @@ public class RemoteSecurityProblemDialogActivity extends FragmentActivity {
}
*/
private void showGeneric(@StringRes int explanationStringRes) {
explanationText.setText(explanationStringRes);
secondaryLayoutAnimator.setDisplayedChild(SECONDARY_CHILD_NONE, layoutInitialized);
buttonBarAnimator.setDisplayedChild(BUTTON_BAR_REGULAR, layoutInitialized);
layoutInitialized = true;
}
private void showGeneric(String explanationString) {
explanationText.setText(explanationString);
secondaryLayoutAnimator.setDisplayedChild(SECONDARY_CHILD_NONE, layoutInitialized);
@@ -239,12 +233,14 @@ public class RemoteSecurityProblemDialogActivity extends FragmentActivity {
@Override
public void showLayoutInsecureSymmetric(int symmetricAlgorithm) {
showGeneric(R.string.insecure_symmetric_algo);
showGeneric(getString(R.string.insecure_symmetric_algo,
KeyFormattingUtils.getSymmetricCipherName(symmetricAlgorithm)));
}
@Override
public void showLayoutInsecureHashAlgorithm(int hashAlgorithm) {
showGeneric(R.string.insecure_hash_algo);
showGeneric(getString(R.string.insecure_hash_algo,
KeyFormattingUtils.getHashAlgoName(hashAlgorithm)));
}
@Override
@@ -252,9 +248,8 @@ public class RemoteSecurityProblemDialogActivity extends FragmentActivity {
String algorithmName = KeyFormattingUtils.getAlgorithmInfo(algorithmId, null, null);
showGenericWithRecommendation(
getString(R.string.insecure_encrypt_bitstrength, algorithmName,
Integer.toString(bitStrength), "2010"),
R.string.insecure_sign_bitstrength_suggestion);
getString(R.string.insecure_encrypt_bitstrength, algorithmName),
R.string.insecure_encrypt_bitstrength_suggestion);
}
@Override
@@ -262,31 +257,40 @@ public class RemoteSecurityProblemDialogActivity extends FragmentActivity {
String algorithmName = KeyFormattingUtils.getAlgorithmInfo(algorithmId, null, null);
showGenericWithRecommendation(
getString(R.string.insecure_sign_bitstrength, algorithmName,
Integer.toString(bitStrength), "2010"),
getString(R.string.insecure_sign_bitstrength, algorithmName),
R.string.insecure_sign_bitstrength_suggestion);
}
@Override
public void showLayoutEncryptNotWhitelistedCurve(String curveOid) {
showGeneric(getString(R.string.insecure_encrypt_not_whitelisted_curve,
KeyFormattingUtils.getCurveInfo(getContext(), curveOid)));
showGenericWithRecommendation(
getString(R.string.insecure_encrypt_not_whitelisted_curve, curveOid),
R.string.insecure_report_suggestion
);
}
@Override
public void showLayoutSignNotWhitelistedCurve(String curveOid) {
showGeneric(getString(R.string.insecure_sign_not_whitelisted_curve,
KeyFormattingUtils.getCurveInfo(getContext(), curveOid)));
showGenericWithRecommendation(
getString(R.string.insecure_sign_not_whitelisted_curve, curveOid),
R.string.insecure_report_suggestion
);
}
@Override
public void showLayoutEncryptUnidentifiedKeyProblem() {
showGeneric(R.string.insecure_encrypt_unidentified);
showGenericWithRecommendation(
R.string.insecure_encrypt_unidentified,
R.string.insecure_report_suggestion
);
}
@Override
public void showLayoutSignUnidentifiedKeyProblem() {
showGeneric(R.string.insecure_sign_unidentified);
showGenericWithRecommendation(
R.string.insecure_sign_unidentified,
R.string.insecure_report_suggestion
);
}
@Override

View File

@@ -43,8 +43,12 @@ import android.widget.ViewAnimator;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.nist.NISTNamedCurves;
import org.bouncycastle.asn1.teletrust.TeleTrusTNamedCurves;
import org.bouncycastle.bcpg.HashAlgorithmTags;
import org.bouncycastle.bcpg.PublicKeyAlgorithmTags;
import org.bouncycastle.bcpg.SymmetricKeyAlgorithmTags;
import org.bouncycastle.crypto.ec.CustomNamedCurves;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.operator.jcajce.PGPUtil;
import org.bouncycastle.util.encoders.Hex;
import org.openintents.openpgp.OpenPgpDecryptionResult;
import org.openintents.openpgp.OpenPgpSignatureResult;
@@ -227,6 +231,47 @@ public class KeyFormattingUtils {
}
}
public static String getHashAlgoName(int hashAlgo) {
try {
return PGPUtil.getDigestName(hashAlgo);
} catch (PGPException e) {
return "#" + hashAlgo;
}
}
public static String getSymmetricCipherName(int algorithm) {
switch (algorithm) {
case SymmetricKeyAlgorithmTags.TRIPLE_DES:
return "Triple-DES";
case SymmetricKeyAlgorithmTags.IDEA:
return "IDEA";
case SymmetricKeyAlgorithmTags.CAST5:
return "CAST5";
case SymmetricKeyAlgorithmTags.BLOWFISH:
return "Blowfish";
case SymmetricKeyAlgorithmTags.SAFER:
return "SAFER";
case SymmetricKeyAlgorithmTags.DES:
return "DES";
case SymmetricKeyAlgorithmTags.AES_128:
return "AES-128";
case SymmetricKeyAlgorithmTags.AES_192:
return "AES-192";
case SymmetricKeyAlgorithmTags.AES_256:
return "AES-256";
case SymmetricKeyAlgorithmTags.CAMELLIA_128:
return "Camellia-128";
case SymmetricKeyAlgorithmTags.CAMELLIA_192:
return "Camellia-192";
case SymmetricKeyAlgorithmTags.CAMELLIA_256:
return "Camellia-256";
case SymmetricKeyAlgorithmTags.TWOFISH:
return "Twofish";
default:
return "#" + algorithm;
}
}
/**
* Converts fingerprint to hex
* <p/>