1 7 package org.jboss.security.ssl; 8 9 import java.io.IOException ; 10 import java.security.KeyManagementException ; 11 import java.security.NoSuchAlgorithmException ; 12 import javax.net.ssl.KeyManagerFactory; 13 import javax.net.ssl.SSLContext; 14 import javax.net.ssl.TrustManager; 15 import javax.net.ssl.TrustManagerFactory; 16 17 import org.jboss.logging.Logger; 18 import org.jboss.security.SecurityDomain; 19 20 35 class Context 36 { 37 private static Logger log = Logger.getLogger(Context.class); 38 39 44 static SSLContext forDomain(SecurityDomain securityDomain) 45 throws IOException 46 { 47 SSLContext sslCtx = null; 48 try 49 { 50 sslCtx = SSLContext.getInstance("TLS"); 51 KeyManagerFactory keyMgr = securityDomain.getKeyManagerFactory(); 52 if( keyMgr == null ) 53 throw new IOException ("KeyManagerFactory is null for security domain: "+securityDomain.getSecurityDomain()); 54 TrustManagerFactory trustMgr = securityDomain.getTrustManagerFactory(); 55 TrustManager[] trustMgrs = null; 56 if( trustMgr != null ) 57 trustMgrs = trustMgr.getTrustManagers(); 58 sslCtx.init(keyMgr.getKeyManagers(), trustMgrs, null); 59 return sslCtx; 60 } 61 catch(NoSuchAlgorithmException e) 62 { 63 log.error("Failed to get SSLContext for TLS algorithm", e); 64 throw new IOException ("Failed to get SSLContext for TLS algorithm"); 65 } 66 catch(KeyManagementException e) 67 { 68 log.error("Failed to init SSLContext", e); 69 throw new IOException ("Failed to init SSLContext"); 70 } 71 catch(SecurityException e) 72 { 73 log.error("Failed to init SSLContext", e); 74 throw new IOException ("Failed to init SSLContext"); 75 } 76 } 77 } 78 | Popular Tags |