diff src/org/tn5250j/framework/transport/SSL/X509CertificateTrustManager.java @ 10:e773d0952613 tn5250

adding tn5250 files
author Carl Byington <carl@five-ten-sg.com>
date Thu, 22 May 2014 16:11:14 -0700
parents e8d2a24e85c6
children 51f34b9de232
line wrap: on
line diff
--- a/src/org/tn5250j/framework/transport/SSL/X509CertificateTrustManager.java	Thu May 22 15:42:48 2014 -0700
+++ b/src/org/tn5250j/framework/transport/SSL/X509CertificateTrustManager.java	Thu May 22 16:11:14 2014 -0700
@@ -29,14 +29,16 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 
-import javax.swing.JOptionPane;
+import com.five_ten_sg.connectbot.service.TerminalBridge;
+import com.five_ten_sg.connectbot.service.TerminalManager;
+
 
 /**
  * This class is used to trust certificates exchanged during an SSL socket
  * handshake.  It allows the user to accept the certificate so that connections
  * can be made without requiring the server to have a certificate signed by a
  * CA (Verisign, Thawte, etc.).
- *  
+ *
  * @author Stephen M. Kennedy <skennedy@tenthpowertech.com>
  * @deprecated.  no longer used.
  *
@@ -45,9 +47,12 @@
 
   KeyStore ks = null;
   TrustManager[] trustManagers;
-  //X509TrustManager trustManager = null;
+  TerminalBridge  bridge = null;
+  TerminalManager manager = null;
 
-  public X509CertificateTrustManager(TrustManager[] managers, KeyStore keyStore) {
+  public X509CertificateTrustManager(TrustManager[] managers, KeyStore keyStore, TerminalBridge bridge, TerminalManager manager) {
+    this.bridge = bridge;
+    this.manager = manager;
     trustManagers = managers;
     ks = keyStore;
   }
@@ -55,14 +60,14 @@
   public void checkClientTrusted(X509Certificate[] chain, String type) throws CertificateException {
   	throw new SecurityException("checkClientTrusted unsupported");
   }
-  
-  
+
+
   /**
    * Checks the server certificate.  If it isn't trusted by the trust manager
    * passed to the constructor, then the user will be prompted to accept the
    * certificate.
    */
-  public void checkServerTrusted(X509Certificate[] chain, String type) 
+  public void checkServerTrusted(X509Certificate[] chain, String type)
   		throws CertificateException {
     try {
     	for (int i=0; i<trustManagers.length; i++) {
@@ -80,10 +85,10 @@
 	      certInfo = certInfo.concat("Valid To: " + cert.getNotAfter()+"\n");
 	      certInfo = certInfo.concat("Subject DN: " + cert.getSubjectDN().getName()+"\n");
 	      certInfo = certInfo.concat("Public Key: " + cert.getPublicKey().getFormat()+"\n");
-	
-	      int accept = JOptionPane.showConfirmDialog(null,certInfo,
-	                  "Accept Certificate",javax.swing.JOptionPane.YES_NO_OPTION);
-	      if (accept != JOptionPane.YES_OPTION) {
+
+          bridge.outputLine(manager.res.getString(R.string.host_certificate, certInfo));
+          Boolean result = bridge.promptHelper.requestBooleanPrompt(null, manager.res.getString(R.string.prompt_accept_certificate));
+          if ((result == null) || (!result.booleanValue())) {
 	        throw new java.security.cert.CertificateException("Certificate Not Accepted");
 	      }
     	}