Mercurial > 510Connectbot
diff src/org/tn5250j/framework/transport/SSL/X509CertificateTrustManager.java @ 112:77ac18bc1b2f
cleanup java formatting
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Wed, 18 Jun 2014 13:03:01 -0700 |
parents | 51f34b9de232 |
children |
line wrap: on
line diff
--- a/src/org/tn5250j/framework/transport/SSL/X509CertificateTrustManager.java Wed Jun 18 13:00:19 2014 -0700 +++ b/src/org/tn5250j/framework/transport/SSL/X509CertificateTrustManager.java Wed Jun 18 13:03:01 2014 -0700 @@ -46,63 +46,67 @@ */ public class X509CertificateTrustManager implements X509TrustManager { - KeyStore ks = null; - TrustManager[] trustManagers; - TerminalBridge bridge = null; - TerminalManager manager = null; + KeyStore ks = null; + TrustManager[] trustManagers; + TerminalBridge bridge = null; + TerminalManager manager = null; - public X509CertificateTrustManager(TrustManager[] managers, KeyStore keyStore, TerminalBridge bridge, TerminalManager manager) { - this.bridge = bridge; - this.manager = manager; - trustManagers = managers; - ks = keyStore; - } + public X509CertificateTrustManager(TrustManager[] managers, KeyStore keyStore, TerminalBridge bridge, TerminalManager manager) { + this.bridge = bridge; + this.manager = manager; + trustManagers = managers; + ks = keyStore; + } - public void checkClientTrusted(X509Certificate[] chain, String type) throws CertificateException { - throw new SecurityException("checkClientTrusted unsupported"); - } + 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) - throws CertificateException { - try { - for (int i=0; i<trustManagers.length; i++) { - if (trustManagers[i] instanceof X509TrustManager) - ((X509TrustManager)trustManagers[i]).checkServerTrusted(chain,type); - } - return; - } catch (CertificateException ce) { - X509Certificate cert = chain[0]; - String certInfo = "Version: " + cert.getVersion() + "\n"; - certInfo = certInfo.concat("Serial Number: " + cert.getSerialNumber()+"\n"); - certInfo = certInfo.concat("Signature Algorithm: " + cert.getSigAlgName()+"\n"); - certInfo = certInfo.concat("Issuer: " + cert.getIssuerDN().getName()+"\n"); - certInfo = certInfo.concat("Valid From: " + cert.getNotBefore()+"\n"); - 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"); + /** + * 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) + throws CertificateException { + try { + for (int i = 0; i < trustManagers.length; i++) { + if (trustManagers[i] instanceof X509TrustManager) + ((X509TrustManager)trustManagers[i]).checkServerTrusted(chain, type); + } - 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"); - } - } - } + return; + } + catch (CertificateException ce) { + X509Certificate cert = chain[0]; + String certInfo = "Version: " + cert.getVersion() + "\n"; + certInfo = certInfo.concat("Serial Number: " + cert.getSerialNumber() + "\n"); + certInfo = certInfo.concat("Signature Algorithm: " + cert.getSigAlgName() + "\n"); + certInfo = certInfo.concat("Issuer: " + cert.getIssuerDN().getName() + "\n"); + certInfo = certInfo.concat("Valid From: " + cert.getNotBefore() + "\n"); + 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"); + bridge.outputLine(manager.res.getString(R.string.host_certificate, certInfo)); + Boolean result = bridge.promptHelper.requestBooleanPrompt(null, manager.res.getString(R.string.prompt_accept_certificate)); - public X509Certificate[] getAcceptedIssuers() { - ArrayList<X509Certificate> list = new ArrayList<X509Certificate>(10); - for (int i=0; i<trustManagers.length; i++) { - if (trustManagers[i] instanceof X509TrustManager) - list.addAll(Arrays.asList(((X509TrustManager)trustManagers[i]).getAcceptedIssuers())); - } - X509Certificate[] acceptedIssuers = new X509Certificate[list.size()]; - acceptedIssuers = list.toArray(acceptedIssuers); - return acceptedIssuers; - } + if ((result == null) || (!result.booleanValue())) { + throw new java.security.cert.CertificateException("Certificate Not Accepted"); + } + } + } + + public X509Certificate[] getAcceptedIssuers() { + ArrayList<X509Certificate> list = new ArrayList<X509Certificate>(10); + + for (int i = 0; i < trustManagers.length; i++) { + if (trustManagers[i] instanceof X509TrustManager) + list.addAll(Arrays.asList(((X509TrustManager)trustManagers[i]).getAcceptedIssuers())); + } + + X509Certificate[] acceptedIssuers = new X509Certificate[list.size()]; + acceptedIssuers = list.toArray(acceptedIssuers); + return acceptedIssuers; + } } \ No newline at end of file