changeset 10:e773d0952613 tn5250

adding tn5250 files
author Carl Byington <carl@five-ten-sg.com>
date Thu, 22 May 2014 16:11:14 -0700
parents 731e70088af0
children f3b3bbd227b8
files src/org/tn5250j/framework/tn5250/Screen5250.java src/org/tn5250j/framework/tn5250/tnvt.java src/org/tn5250j/framework/transport/SSL/X509CertificateTrustManager.java src/org/tn5250j/framework/transport/SocketConnector.java
diffstat 4 files changed, 39 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/src/org/tn5250j/framework/tn5250/Screen5250.java	Thu May 22 15:42:48 2014 -0700
+++ b/src/org/tn5250j/framework/tn5250/Screen5250.java	Thu May 22 16:11:14 2014 -0700
@@ -498,8 +498,7 @@
 						while (planes.getWhichGUI(pos++) != BUTTON_RIGHT_EB) {
 							eb.append(planes.getChar(pos));
 						}
-						org.tn5250j.tools.system.OperatingSystem.displayURL(eb
-								.toString());
+                        sessionVT.showURL(eb.toString());
 						// take out the log statement when we are sure it is
 						// working
 						log.info("Send to external Browser: " + eb.toString());
--- a/src/org/tn5250j/framework/tn5250/tnvt.java	Thu May 22 15:42:48 2014 -0700
+++ b/src/org/tn5250j/framework/tn5250/tnvt.java	Thu May 22 16:11:14 2014 -0700
@@ -83,7 +83,6 @@
 import com.five_ten_sg.connectbot.service.TerminalBridge;
 import com.five_ten_sg.connectbot.service.TerminalManager;
 
-import org.tn5250j.Session5250;
 import org.tn5250j.TN5250jConstants;
 import org.tn5250j.encoding.CharMappings;
 import org.tn5250j.encoding.ICodePage;
@@ -133,7 +132,7 @@
 	private int readType;
 	private boolean enhanced = true;
 	private boolean cursorOn = false;
-	private String session = "";
+	private String hostname = "";
 	private int port = 23;
 	private boolean connected = false;
 	private boolean support132 = true;
@@ -166,10 +165,11 @@
 	private final TN5250jLogger log = TN5250jLogFactory.getLogger(this.getClass());
 
 	/**
-	 * @param session
 	 * @param screen52
-	 * @param type
+	 * @param enhanced
 	 * @param support132
+     * @param bridge
+     * @param manager
 	 */
 	public tnvt(Screen5250 screen52, boolean enhanced, boolean support132, TerminalBridge bridge, TerminalManager manager) {
 		if (log.isInfoEnabled()) {
@@ -203,9 +203,15 @@
 		baosrsp = new ByteArrayOutputStream();
 	}
 
+    public void showURL(String url) {
+        if (url.indexOf("://") < 0) url = "http://" + url;
+        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
+        manager.startActivity(intent);
+    }
+
 	public String getHostName() {
 
-		return session;
+		return hostname;
 	}
 
 
@@ -257,12 +263,12 @@
 
 	public final boolean connect() {
 
-		return connect(session, port);
+		return connect(hostname, port);
 
 	}
 
 
-	public final boolean connect(String s, int port) {
+	public final boolean connect(String hostname, int port) {
 
 		// We will now see if there are any bypass signon parameters to be
 		//    processed. The system properties override these parameters so
@@ -283,8 +289,8 @@
 
 
 		try {
-			session = s;
-			this.port = port;
+			this.hostname = hostname;
+			this.port     = port;
 
 			try {
 				screen52.getOIA().setInputInhibited(ScreenOIA.INPUTINHIBITED_SYSTEM_WAIT,
@@ -297,7 +303,7 @@
 			//smk - For SSL compability
 			SocketConnector sc = new SocketConnector();
 			if (sslType != null) sc.setSSLType(sslType);
-			sock = sc.createSocket(s, port, bridge, manager);
+			sock = sc.createSocket(hostname, port, bridge, manager);
 
 			if (sock == null) {
 				log.warn("I did not get a socket");
--- 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");
 	      }
     	}
--- a/src/org/tn5250j/framework/transport/SocketConnector.java	Thu May 22 15:42:48 2014 -0700
+++ b/src/org/tn5250j/framework/transport/SocketConnector.java	Thu May 22 16:11:14 2014 -0700
@@ -25,6 +25,9 @@
 
 import java.net.Socket;
 
+import com.five_ten_sg.connectbot.service.TerminalBridge;
+import com.five_ten_sg.connectbot.service.TerminalManager;
+
 import org.tn5250j.framework.transport.SSL.SSLImplementation;
 import org.tn5250j.TN5250jConstants;
 import org.tn5250j.tools.logging.TN5250jLogFactory;
@@ -62,7 +65,7 @@
    * @param port
    * @return a new client socket, or null if
    */
-  public Socket createSocket(String destination, int port) {
+  public Socket createSocket(String destination, int port, TerminalBridge bridge, TerminalManager manager) {
 
   	Socket socket = null;
   	Exception ex = null;
@@ -83,7 +86,7 @@
       	SSLInterface sslIf = null;
 
 		try {
-			sslIf = (SSLInterface) new SSLImplementation();
+			sslIf = (SSLInterface) new SSLImplementation(bridge, manager);
 		} catch (Exception e) {
 			ex = new Exception("Failed to create SSLInterface Instance. " +
 					"Message is ["+e.getMessage()+"]");
@@ -91,7 +94,7 @@
 
       	if (sslIf != null) {
       		sslIf.init(sslType);
-      		socket = sslIf.createSSLSocket(destination,port);
+      		socket = sslIf.createSSLSocket(destination, port);
       	}
       }