Mercurial > 510Connectbot
comparison src/org/tn5250j/framework/transport/SSL/SSLImplementation.java @ 26:9ae1c889a64c tn5250
adding tn5250 files, native android logging
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Tue, 03 Jun 2014 12:16:46 -0700 |
parents | 5949eb469a79 |
children | 011462bddcf1 |
comparison
equal
deleted
inserted
replaced
25:5949eb469a79 | 26:9ae1c889a64c |
---|---|
55 * | 55 * |
56 * @author Stephen M. Kennedy <skennedy@tenthpowertech.com> | 56 * @author Stephen M. Kennedy <skennedy@tenthpowertech.com> |
57 * | 57 * |
58 */ | 58 */ |
59 public class SSLImplementation implements SSLInterface, X509TrustManager { | 59 public class SSLImplementation implements SSLInterface, X509TrustManager { |
60 | 60 private static final String TAG = "SSLImplementation"; |
61 SSLContext sslContext = null; | 61 SSLContext sslContext = null; |
62 | |
63 KeyStore userks = null; | 62 KeyStore userks = null; |
64 private String userKsPath; | 63 private String userKsPath; |
65 private char[] userksPassword = "changeit".toCharArray(); | 64 private char[] userksPassword = "changeit".toCharArray(); |
66 | 65 |
67 TerminalBridge bridge = null; | 66 TerminalBridge bridge = null; |
74 | 73 |
75 TrustManager[] userTrustManagers = null; | 74 TrustManager[] userTrustManagers = null; |
76 | 75 |
77 X509Certificate[] acceptedIssuers; | 76 X509Certificate[] acceptedIssuers; |
78 | 77 |
79 TN5250jLogger logger; | |
80 | |
81 public SSLImplementation(TerminalBridge bridge, TerminalManager manager) { | 78 public SSLImplementation(TerminalBridge bridge, TerminalManager manager) { |
82 this.bridge = bridge; | 79 this.bridge = bridge; |
83 this.manager = manager; | 80 this.manager = manager; |
84 | 81 |
85 } | 82 } |
86 | 83 |
87 public void init(String sslType) { | 84 public void init(String sslType) { |
88 try { | 85 try { |
89 logger.debug("Initializing User KeyStore"); | 86 Log.d(TAG,"Initializing User KeyStore"); |
90 userKsPath = System.getProperty("user.home") + File.separator | 87 userKsPath = System.getProperty("user.home") + File.separator |
91 + GlobalConfigure.TN5250J_FOLDER + File.separator + "keystore"; | 88 + GlobalConfigure.TN5250J_FOLDER + File.separator + "keystore"; |
92 File userKsFile = new File(userKsPath); | 89 File userKsFile = new File(userKsPath); |
93 userks = KeyStore.getInstance(KeyStore.getDefaultType()); | 90 userks = KeyStore.getInstance(KeyStore.getDefaultType()); |
94 userks.load(userKsFile.exists() ? new FileInputStream(userKsFile) | 91 userks.load(userKsFile.exists() ? new FileInputStream(userKsFile) |
95 : null, userksPassword); | 92 : null, userksPassword); |
96 logger.debug("Initializing User Key Manager Factory"); | 93 Log.d(TAG,"Initializing User Key Manager Factory"); |
97 userkmf = KeyManagerFactory.getInstance(KeyManagerFactory | 94 userkmf = KeyManagerFactory.getInstance(KeyManagerFactory |
98 .getDefaultAlgorithm()); | 95 .getDefaultAlgorithm()); |
99 userkmf.init(userks, userksPassword); | 96 userkmf.init(userks, userksPassword); |
100 logger.debug("Initializing User Trust Manager Factory"); | 97 Log.d(TAG,"Initializing User Trust Manager Factory"); |
101 usertmf = TrustManagerFactory.getInstance(TrustManagerFactory | 98 usertmf = TrustManagerFactory.getInstance(TrustManagerFactory |
102 .getDefaultAlgorithm()); | 99 .getDefaultAlgorithm()); |
103 usertmf.init(userks); | 100 usertmf.init(userks); |
104 userTrustManagers = usertmf.getTrustManagers(); | 101 userTrustManagers = usertmf.getTrustManagers(); |
105 logger.debug("Initializing SSL Context"); | 102 Log.d(TAG,"Initializing SSL Context"); |
106 sslContext = SSLContext.getInstance(sslType); | 103 sslContext = SSLContext.getInstance(sslType); |
107 sslContext.init(userkmf.getKeyManagers(), new TrustManager[] {this}, null); | 104 sslContext.init(userkmf.getKeyManagers(), new TrustManager[] {this}, null); |
108 } catch (Exception ex) { | 105 } catch (Exception ex) { |
109 logger.error("Error initializing SSL [" + ex.getMessage() + "]"); | 106 Log.e(TAG,"Error initializing SSL [" + ex.getMessage() + "]"); |
110 } | 107 } |
111 | 108 |
112 } | 109 } |
113 | 110 |
114 public Socket createSSLSocket(String destination, int port) { | 111 public Socket createSSLSocket(String destination, int port) { |
118 try { | 115 try { |
119 target = destination + ":" + String.valueOf(port); | 116 target = destination + ":" + String.valueOf(port); |
120 socket = (SSLSocket) sslContext.getSocketFactory().createSocket( | 117 socket = (SSLSocket) sslContext.getSocketFactory().createSocket( |
121 destination, port); | 118 destination, port); |
122 } catch (Exception e) { | 119 } catch (Exception e) { |
123 logger.error("Error creating ssl socket [" + e.getMessage() + "]"); | 120 Log.e(TAG,"Error creating ssl socket [" + e.getMessage() + "]"); |
124 } | 121 } |
125 return socket; | 122 return socket; |
126 } | 123 } |
127 | 124 |
128 // X509TrustManager Methods | 125 // X509TrustManager Methods |
205 userks.setCertificateEntry(cert.getSubjectDN().getName(), | 202 userks.setCertificateEntry(cert.getSubjectDN().getName(), |
206 cert); | 203 cert); |
207 userks.store(new FileOutputStream(userKsPath), | 204 userks.store(new FileOutputStream(userKsPath), |
208 userksPassword); | 205 userksPassword); |
209 } catch (Exception e) { | 206 } catch (Exception e) { |
210 logger.error("Error saving certificate [" + e.getMessage() | 207 Log.e(TAG,"Error saving certificate [" + e.getMessage() |
211 + "]"); | 208 + "]"); |
212 e.printStackTrace(); | 209 e.printStackTrace(); |
213 } | 210 } |
214 } | 211 } |
215 } | 212 } |