-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathSSLManager.java
More file actions
75 lines (66 loc) · 1.97 KB
/
SSLManager.java
File metadata and controls
75 lines (66 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package HTTPClient;
/**
* Title: Clases manejo SSL
* Description:
* Copyright: Copyright (c) 2001
* Company:
* @author gb
* @version 1.0
*/
public class SSLManager
{
private static ISSLConnection sslConnection = null;
/** Obtiene una instancia de ISSLConnection para ser pasada al HTTPConnection
* @see HTTPConnection.setSSLConnection
* @return ISSLConnection
*/
public static ISSLConnection getSSLConnection()
{
return getSSLConnection(true);
}
/** Obtiene una instancia de ISSLConnection
* Este metodo se llama directamente desde SMTPSession y POP3Session
* @param uniqueInstance Indica si se quiere obtener la instancia como un singleton
* @see SMTPSession y POP3Session
* @return ISSLConnection
*/
public static ISSLConnection getSSLConnection(boolean uniqueInstance)
{
if(uniqueInstance)
{
if (sslConnection != null)return (ISSLConnection) sslConnection.clone();
}
else
{
sslConnection = null;
}
//Si se quiere usar TLS retorno enseguida la conexion
if(Boolean.getBoolean("HTTPClient.sslUseTLS"))
{
try
{
sslConnection = new TLSConnection();
return sslConnection;
}catch(Throwable TLSNotAvailable){ TLSNotAvailable.printStackTrace(); }
}
// Primero probamos con JSSE
if(!Boolean.getBoolean("HTTPClient.sslDontUseJSSE"))
{
try
{
sslConnection = new JSSESSLConnection();
}catch(Throwable JSSENotAvailable){ ; }
}
// Sino, retornamos un DefaultSSLConnection (es decir, conexiones sin SSL)
if(sslConnection == null) sslConnection = new DefaultSSLConnection();
return (ISSLConnection)sslConnection.clone();
}
/** Indica si las conexiones SSL est�n disponibles
* @return true si se pueden realizar conexiones SSL
*/
public static boolean isSSLAvailable()
{
if(sslConnection == null)getSSLConnection();
return !(sslConnection instanceof DefaultSSLConnection);
}
}