1 19 20 package com.sslexplorer.server; 21 22 import java.net.Socket ; 23 import java.security.Principal ; 24 import java.security.PrivateKey ; 25 import java.security.cert.Certificate ; 26 import java.security.cert.X509Certificate ; 27 import java.util.ArrayList ; 28 import java.util.List ; 29 30 import javax.net.ssl.X509KeyManager; 31 32 import org.apache.commons.logging.Log; 33 import org.apache.commons.logging.LogFactory; 34 35 import com.sslexplorer.boot.ContextHolder; 36 import com.sslexplorer.boot.ContextKey; 37 import com.sslexplorer.boot.KeyStoreManager; 38 import com.sslexplorer.boot.PropertyClass; 39 40 41 49 public class CustomKeyManager implements X509KeyManager { 50 51 final static Log log = LogFactory.getLog(CustomKeyManager.class); 52 private String keyPassword; 53 private PropertyClass contextConfig; 54 59 public CustomKeyManager(String keyPassword) { 60 this.keyPassword = keyPassword; 61 contextConfig = ContextHolder.getContext().getConfig(); 62 } 63 64 67 public String chooseClientAlias(String [] arg0, Principal [] arg1, Socket socket) { 68 return null; 69 } 70 71 74 public String chooseServerAlias(String keyType, Principal [] issuers, Socket socket) { 75 String alias = ContextHolder.getContext().getConfig().retrieveProperty(new ContextKey("webServer.alias")); 76 return alias; 77 } 78 79 82 public X509Certificate [] getCertificateChain(String certname) { 83 try { 84 Certificate [] f = KeyStoreManager.getInstance(KeyStoreManager.DEFAULT_KEY_STORE).getCertificateChain(certname); 85 List l = new ArrayList (); 86 for(int i = 0 ; i < f.length ; i++) { 87 if(f[i] instanceof X509Certificate ) { 88 l.add(f[i]); 89 } 90 } 91 return (X509Certificate [])l.toArray(new X509Certificate [l.size()]); 92 } catch (Exception e) { 93 Main.log.error(e); 94 } 95 return null; 96 } 97 98 101 public String [] getClientAliases(String keyType, Principal [] issuers) { 102 String str[] = { "" }; 103 return str; 104 } 105 106 109 public PrivateKey getPrivateKey(String alias) { 110 try { 111 return (PrivateKey ) KeyStoreManager.getInstance(KeyStoreManager.DEFAULT_KEY_STORE).getPrivateKey(contextConfig.retrieveProperty(new ContextKey("webServer.alias")), contextConfig.retrieveProperty(new ContextKey("webServer.keystore.sslCertificate.password")).toCharArray()); 112 } catch (Exception e) { 113 Main.log.error(e); 114 } 115 return null; 116 } 117 118 121 public String [] getServerAliases(String keyType, Principal [] issuers) { 122 String str[] = { contextConfig.retrieveProperty(new ContextKey("webServer.alias")) }; 123 return str; 124 } 125 126 } | Popular Tags |