diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2014-11-01 13:51:05 +0100 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2014-11-01 13:51:05 +0100 |
commit | a0f694ea44b9d68390846b48d720f9a37fd679b8 (patch) | |
tree | 38ee04006e38197fd8009697b8975007ec0f45c8 /libs/MemorizingTrustManager/src/de/duenndns/ssl/MemorizingActivity.java | |
parent | 142384e5805d93887d185c9a5b74d4850e4ec719 (diff) | |
parent | 46f147a82c6b161e071f717c7686f8b78a20aaf1 (diff) |
Merge pull request #600 from SamWhited/gradle
Build system and library changes (Gradle / Subtree merging)
Diffstat (limited to 'libs/MemorizingTrustManager/src/de/duenndns/ssl/MemorizingActivity.java')
m--------- | libs/MemorizingTrustManager | 0 | ||||
-rw-r--r-- | libs/MemorizingTrustManager/src/de/duenndns/ssl/MemorizingActivity.java | 103 |
2 files changed, 103 insertions, 0 deletions
diff --git a/libs/MemorizingTrustManager b/libs/MemorizingTrustManager deleted file mode 160000 -Subproject fad835037adc1bd313bb56b694426fca4eb6734 diff --git a/libs/MemorizingTrustManager/src/de/duenndns/ssl/MemorizingActivity.java b/libs/MemorizingTrustManager/src/de/duenndns/ssl/MemorizingActivity.java new file mode 100644 index 00000000..013ac29b --- /dev/null +++ b/libs/MemorizingTrustManager/src/de/duenndns/ssl/MemorizingActivity.java @@ -0,0 +1,103 @@ +/* MemorizingTrustManager - a TrustManager which asks the user about invalid + * certificates and memorizes their decision. + * + * Copyright (c) 2010 Georg Lukas <georg@op-co.de> + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package de.duenndns.ssl; + + +import java.util.logging.Level; +import java.util.logging.Logger; + +import android.app.Activity; +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.content.DialogInterface.*; +import android.content.Intent; +import android.os.Bundle; + +public class MemorizingActivity extends Activity + implements OnClickListener,OnCancelListener { + + private final static Logger LOGGER = Logger.getLogger(MemorizingActivity.class.getName()); + + int decisionId; + + AlertDialog dialog; + + @Override + public void onCreate(Bundle savedInstanceState) { + LOGGER.log(Level.FINE, "onCreate"); + super.onCreate(savedInstanceState); + } + + @Override + public void onResume() { + super.onResume(); + Intent i = getIntent(); + decisionId = i.getIntExtra(MemorizingTrustManager.DECISION_INTENT_ID, MTMDecision.DECISION_INVALID); + int titleId = i.getIntExtra(MemorizingTrustManager.DECISION_TITLE_ID, R.string.mtm_accept_cert); + String cert = i.getStringExtra(MemorizingTrustManager.DECISION_INTENT_CERT); + LOGGER.log(Level.FINE, "onResume with " + i.getExtras() + " decId=" + decisionId + " data: " + i.getData()); + dialog = new AlertDialog.Builder(this).setTitle(titleId) + .setMessage(cert) + .setPositiveButton(R.string.mtm_decision_always, this) + .setNeutralButton(R.string.mtm_decision_once, this) + .setNegativeButton(R.string.mtm_decision_abort, this) + .setOnCancelListener(this) + .create(); + dialog.show(); + } + + @Override + protected void onPause() { + if (dialog.isShowing()) + dialog.dismiss(); + super.onPause(); + } + + void sendDecision(int decision) { + LOGGER.log(Level.FINE, "Sending decision: " + decision); + MemorizingTrustManager.interactResult(decisionId, decision); + finish(); + } + + // react on AlertDialog button press + public void onClick(DialogInterface dialog, int btnId) { + int decision; + dialog.dismiss(); + switch (btnId) { + case DialogInterface.BUTTON_POSITIVE: + decision = MTMDecision.DECISION_ALWAYS; + break; + case DialogInterface.BUTTON_NEUTRAL: + decision = MTMDecision.DECISION_ONCE; + break; + default: + decision = MTMDecision.DECISION_ABORT; + } + sendDecision(decision); + } + + public void onCancel(DialogInterface dialog) { + sendDecision(MTMDecision.DECISION_ABORT); + } +} |