OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
com.mapd.common.SockTransportProperties Class Reference
+ Collaboration diagram for com.mapd.common.SockTransportProperties:

Classes

enum  TransportType
 

Public Member Functions

 SockTransportProperties (boolean load_trust) throws Exception
 
 SockTransportProperties (String truststore_name, String truststore_passwd) throws Exception
 
TTransport openHttpsClientTransport (String server_host, int port) throws Exception
 
TTransport openHttpClientTransport (String server_host, int port) throws org.apache.thrift.TException
 
TServerTransport openServerTransport (int port) throws org.apache.thrift.TException
 
TServerTransport openServerTransportEncrypted (int port) throws org.apache.thrift.TException
 
TTransport openClientTransport (String server_host, int port) throws org.apache.thrift.TException
 
TTransport openClientTransportEncrypted (String server_host, int port) throws org.apache.thrift.TException
 

Static Public Member Functions

static SockTransportProperties getUnencryptedClient () throws Exception
 
static SockTransportProperties getEncryptedClientPermisive () throws Exception
 
static SockTransportProperties getEncryptedClientDefaultTrustStore () throws Exception
 
static SockTransportProperties getEncryptedClientSpecifiedTrustStore (String trustStoreName, String trustStorePassword) throws Exception
 
static SockTransportProperties getEncryptedServer (String keyStoreName, String keyStorePassword) throws Exception
 
static SockTransportProperties getUnecryptedServer () throws Exception
 

Static Package Attributes

static final org.slf4j.Logger MAPDLOGGER
 

Private Member Functions

 SockTransportProperties (TransportType tT, String name, String passwd) throws Exception
 
 SockTransportProperties (TransportType transportType) throws Exception
 
void initializeAcceptedIssuers (KeyStore kS) throws Exception
 

Static Private Member Functions

static X509TrustManager createInsecureTrustManager ()
 

Private Attributes

TrustManager[] trustManagers
 
TransportType transportType = null
 
String trust_store_name = null
 
char[] trust_store_password = null
 
String key_store_name = null
 
char[] key_store_password = null
 

Detailed Description

Definition at line 23 of file SockTransportProperties.java.

Constructor & Destructor Documentation

com.mapd.common.SockTransportProperties.SockTransportProperties ( boolean  load_trust) throws Exception
inline
com.mapd.common.SockTransportProperties.SockTransportProperties ( String  truststore_name,
String  truststore_passwd 
) throws Exception
inline
com.mapd.common.SockTransportProperties.SockTransportProperties ( TransportType  tT,
String  name,
String  passwd 
) throws Exception
inlineprivate

Definition at line 85 of file SockTransportProperties.java.

References com.mapd.common.SockTransportProperties.TransportType.encryptedServer, com.mapd.common.SockTransportProperties.initializeAcceptedIssuers(), com.mapd.common.SockTransportProperties.key_store_name, com.mapd.common.SockTransportProperties.key_store_password, Experimental.String, com.mapd.common.SockTransportProperties.transportType, com.mapd.common.SockTransportProperties.trust_store_name, and com.mapd.common.SockTransportProperties.trust_store_password.

86  {
87  transportType = tT;
88  // Load the supplied file into a java keystore object to ensure it is okay. If
89  // the keystore
90  // contain client trust information it is used to initialize the TrustManager
91  // factory, otherwise it is discarded.
92  // The file name is stored in a member variable. When the required
93  // open method is called the stored file name is passed to the appropriate
94  // TSSLTransportParameters
95  // method.
96  KeyStore kS = KeyStore.getInstance(KeyStore.getDefaultType());
97  char[] store_password = null;
98  String store_name = null;
99  if (passwd != null && !passwd.isEmpty()) {
100  store_password = passwd.toCharArray();
101  }
102  if (name != null && !name.isEmpty()) {
103  store_name = name;
104  }
105  try {
106  java.io.FileInputStream fis = new java.io.FileInputStream(name);
107  kS.load(fis, store_password);
108  } catch (Exception eX) {
109  String err_str = new String("Error loading key/trut store [" + name + "]");
110  MAPDLOGGER.error(err_str, eX);
111  throw(eX);
112  }
113 
114  if (transportType == TransportType.encryptedServer) {
115  // key_store_set = true;
116  key_store_password = store_password;
117  key_store_name = store_name;
118  } else {
120  trust_store_password = store_password;
121  trust_store_name = store_name;
122  // trust_store_set = true;
123  }
124  }

+ Here is the call graph for this function:

com.mapd.common.SockTransportProperties.SockTransportProperties ( TransportType  transportType) throws Exception
inlineprivate

Definition at line 126 of file SockTransportProperties.java.

References com.mapd.common.SockTransportProperties.initializeAcceptedIssuers(), Experimental.String, and com.mapd.common.SockTransportProperties.transportType.

126  {
127  // This constructor will either not bother loading trust data (and then trust
128  // all server certs) or load from the java default trust stores.
129  this.transportType = transportType;
130  switch (transportType) {
131  case encryptedClientDefaultTrustStore:
132  initializeAcceptedIssuers((KeyStore) null);
133  break;
134  case encryptedClientPermissive:
135  // trust_all_certs = true;
136  case unencryptedClient:
137  // do nothing
138  case unencryptedServer:
139  // do nothing
140  break;
141  default:
142  String errStr = new String(
143  "Invalid transportType [" + transportType + "] used in constructor");
144  RuntimeException rE = new RuntimeException(errStr);
145  MAPDLOGGER.error(errStr, rE);
146  throw(rE);
147  }
148  }

+ Here is the call graph for this function:

Member Function Documentation

static X509TrustManager com.mapd.common.SockTransportProperties.createInsecureTrustManager ( )
inlinestaticprivate

Definition at line 161 of file SockTransportProperties.java.

References Experimental.String.

Referenced by com.mapd.common.SockTransportProperties.openHttpsClientTransport().

161  {
162  return new X509TrustManager() {
163  public X509Certificate[] getAcceptedIssuers() {
164  return null;
165  }
166 
167  public void checkClientTrusted(X509Certificate[] certs, String authType) {}
168 
169  public void checkServerTrusted(X509Certificate[] certs, String authType) {}
170  };
171  }

+ Here is the caller graph for this function:

static SockTransportProperties com.mapd.common.SockTransportProperties.getEncryptedClientDefaultTrustStore ( ) throws Exception
inlinestatic

Definition at line 41 of file SockTransportProperties.java.

References com.mapd.common.SockTransportProperties.TransportType.encryptedClientDefaultTrustStore, and com.mapd.common.SockTransportProperties.SockTransportProperties().

42  {
43  return new SockTransportProperties(TransportType.encryptedClientDefaultTrustStore);
44  }

+ Here is the call graph for this function:

static SockTransportProperties com.mapd.common.SockTransportProperties.getEncryptedClientPermisive ( ) throws Exception
inlinestatic

Definition at line 37 of file SockTransportProperties.java.

References com.mapd.common.SockTransportProperties.TransportType.encryptedClientPermissive, and com.mapd.common.SockTransportProperties.SockTransportProperties().

37  {
38  return new SockTransportProperties(TransportType.encryptedClientPermissive);
39  }

+ Here is the call graph for this function:

static SockTransportProperties com.mapd.common.SockTransportProperties.getEncryptedClientSpecifiedTrustStore ( String  trustStoreName,
String  trustStorePassword 
) throws Exception
inlinestatic

Definition at line 46 of file SockTransportProperties.java.

References com.mapd.common.SockTransportProperties.TransportType.encryptedClientSpecifiedTrustStore, and com.mapd.common.SockTransportProperties.SockTransportProperties().

47  {
48  return new SockTransportProperties(TransportType.encryptedClientSpecifiedTrustStore,
49  trustStoreName,
50  trustStorePassword);
51  }

+ Here is the call graph for this function:

static SockTransportProperties com.mapd.common.SockTransportProperties.getEncryptedServer ( String  keyStoreName,
String  keyStorePassword 
) throws Exception
inlinestatic

Definition at line 53 of file SockTransportProperties.java.

References com.mapd.common.SockTransportProperties.TransportType.encryptedServer, and com.mapd.common.SockTransportProperties.SockTransportProperties().

54  {
55  return new SockTransportProperties(
56  TransportType.encryptedServer, keyStoreName, keyStorePassword);
57  }

+ Here is the call graph for this function:

static SockTransportProperties com.mapd.common.SockTransportProperties.getUnecryptedServer ( ) throws Exception
inlinestatic

Definition at line 59 of file SockTransportProperties.java.

References com.mapd.common.SockTransportProperties.SockTransportProperties(), and com.mapd.common.SockTransportProperties.TransportType.unencryptedServer.

59  {
60  return new SockTransportProperties(TransportType.unencryptedServer);
61  }

+ Here is the call graph for this function:

static SockTransportProperties com.mapd.common.SockTransportProperties.getUnencryptedClient ( ) throws Exception
inlinestatic

Definition at line 33 of file SockTransportProperties.java.

References com.mapd.common.SockTransportProperties.SockTransportProperties(), and com.mapd.common.SockTransportProperties.TransportType.unencryptedClient.

33  {
34  return new SockTransportProperties(TransportType.unencryptedClient);
35  }

+ Here is the call graph for this function:

void com.mapd.common.SockTransportProperties.initializeAcceptedIssuers ( KeyStore  kS) throws Exception
inlineprivate

Definition at line 150 of file SockTransportProperties.java.

References com.mapd.common.SockTransportProperties.trustManagers.

Referenced by com.mapd.common.SockTransportProperties.SockTransportProperties().

150  {
151  TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("PKIX");
152  trustManagerFactory.init(kS);
153  trustManagers = trustManagerFactory.getTrustManagers();
154  X509TrustManager x509TrustManager = (X509TrustManager) trustManagers[0];
155  }

+ Here is the caller graph for this function:

TTransport com.mapd.common.SockTransportProperties.openClientTransport ( String  server_host,
int  port 
) throws org.apache.thrift.TException
inline

Definition at line 252 of file SockTransportProperties.java.

References com.mapd.common.SockTransportProperties.TransportType.encryptedClientSpecifiedTrustStore, com.mapd.common.SockTransportProperties.openClientTransportEncrypted(), and com.mapd.common.SockTransportProperties.transportType.

253  {
254  if (transportType == TransportType.encryptedClientSpecifiedTrustStore) {
255  return openClientTransportEncrypted(server_host, port);
256  } else {
257  return (new TSocket(server_host, port));
258  }
259  }
TTransport openClientTransportEncrypted(String server_host, int port)

+ Here is the call graph for this function:

TTransport com.mapd.common.SockTransportProperties.openClientTransportEncrypted ( String  server_host,
int  port 
) throws org.apache.thrift.TException
inline

Definition at line 261 of file SockTransportProperties.java.

References com.mapd.common.SockTransportProperties.TransportType.encryptedClientPermissive, Experimental.String, com.mapd.common.SockTransportProperties.transportType, com.mapd.common.SockTransportProperties.trust_store_name, and com.mapd.common.SockTransportProperties.trust_store_password.

Referenced by com.mapd.common.SockTransportProperties.openClientTransport().

262  {
263  // Used to set Socket.setSoTimeout ms. 0 == inifinite.
264  int socket_so_timeout_ms = 0;
265  if (transportType == TransportType.encryptedClientPermissive) {
266  return TSSLTransportFactory.getClientSocket(
267  server_host, port, socket_so_timeout_ms);
268  }
269  TSSLTransportFactory.TSSLTransportParameters params =
270  new TSSLTransportFactory.TSSLTransportParameters();
271  params.setTrustStore(trust_store_name,
272  (trust_store_password != null) ? new String(trust_store_password) : null);
273  params.requireClientAuth(false);
274 
275  return TSSLTransportFactory.getClientSocket(
276  server_host, port, socket_so_timeout_ms, params);
277  }

+ Here is the caller graph for this function:

TTransport com.mapd.common.SockTransportProperties.openHttpClientTransport ( String  server_host,
int  port 
) throws org.apache.thrift.TException
inline

Definition at line 214 of file SockTransportProperties.java.

References Experimental.String.

215  {
216  String url = "http://" + server_host + ":" + port;
217  return (new THttpClient(url));
218  }
TTransport com.mapd.common.SockTransportProperties.openHttpsClientTransport ( String  server_host,
int  port 
) throws Exception
inline

Definition at line 173 of file SockTransportProperties.java.

References com.mapd.common.SockTransportProperties.createInsecureTrustManager(), com.mapd.common.SockTransportProperties.TransportType.encryptedClientPermissive, Experimental.String, com.mapd.common.SockTransportProperties.transportType, and com.mapd.common.SockTransportProperties.trustManagers.

174  {
175  // Simple TrustManager to trust all certs
176  TrustManager[] trustAllCerts = {createInsecureTrustManager()};
177 
178  TTransport transport = null;
179  try {
180  // Build a regular apache ClosableHttpClient based on a SSL connection
181  // that can be passed to the apache thrift THttpClient constructor.
182 
183  SSLContext sc = null;
184  sc = SSLContexts.custom().useProtocol("SSL").build();
185  SSLConnectionSocketFactory sslConnectionSocketFactory = null;
186  if (transportType == TransportType.encryptedClientPermissive) {
187  sc.init(null, trustManagers, new java.security.SecureRandom());
188  sslConnectionSocketFactory = new SSLConnectionSocketFactory(
189  sc, SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
190  } else {
191  sc.init(null, trustAllCerts, new java.security.SecureRandom());
192  sslConnectionSocketFactory = new SSLConnectionSocketFactory(
193  sc, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
194  }
195  CloseableHttpClient closeableHttpClient =
196  HttpClients.custom()
197  .setSSLSocketFactory(sslConnectionSocketFactory)
198  .build();
199  transport =
200  new THttpClient("https://" + server_host + ":" + port, closeableHttpClient);
201  } catch (Exception ex) {
202  String err_str = new String("Exception:" + ex.getClass().getCanonicalName()
203  + " thown. Unable to create Secure socket for the HTTPS connection");
204  MAPDLOGGER.error(err_str, ex);
205  throw ex;
206  }
207 
208  return transport;
209  }

+ Here is the call graph for this function:

TServerTransport com.mapd.common.SockTransportProperties.openServerTransport ( int  port) throws org.apache.thrift.TException
inline

Definition at line 223 of file SockTransportProperties.java.

References com.mapd.common.SockTransportProperties.TransportType.encryptedServer, com.mapd.common.SockTransportProperties.openServerTransportEncrypted(), and com.mapd.common.SockTransportProperties.transportType.

224  {
225  if (transportType == TransportType.encryptedServer) {
226  return openServerTransportEncrypted(port);
227  } else {
228  return (new TServerSocket(port));
229  }
230  }
TServerTransport openServerTransportEncrypted(int port)

+ Here is the call graph for this function:

TServerTransport com.mapd.common.SockTransportProperties.openServerTransportEncrypted ( int  port) throws org.apache.thrift.TException
inline

Definition at line 232 of file SockTransportProperties.java.

References com.mapd.common.SockTransportProperties.key_store_name, com.mapd.common.SockTransportProperties.key_store_password, and Experimental.String.

Referenced by com.mapd.common.SockTransportProperties.openServerTransport().

233  {
234  // Used to set Socket.setSoTimeout ms. 0 == inifinite.
235  int socket_so_timeout_ms = 0;
236  TSSLTransportFactory.TSSLTransportParameters params =
237  new TSSLTransportFactory.TSSLTransportParameters();
238  params.setKeyStore(key_store_name,
239  (key_store_password != null) ? new String(key_store_password) : null);
240  params.requireClientAuth(false);
241 
242  // return TSSLTransportFactory.getClientSocket(server_host, port,
243  // socket_so_timeout_ms, params);
244  TServerTransport t = TSSLTransportFactory.getServerSocket(
245  port, socket_so_timeout_ms, null, params);
246  return t;
247  }

+ Here is the caller graph for this function:

Member Data Documentation

String com.mapd.common.SockTransportProperties.key_store_name = null
private
char [] com.mapd.common.SockTransportProperties.key_store_password = null
private
final org.slf4j.Logger com.mapd.common.SockTransportProperties.MAPDLOGGER
staticpackage
Initial value:
=
LoggerFactory.getLogger(SockTransportProperties.class)

Definition at line 24 of file SockTransportProperties.java.

String com.mapd.common.SockTransportProperties.trust_store_name = null
private
char [] com.mapd.common.SockTransportProperties.trust_store_password = null
private
TrustManager [] com.mapd.common.SockTransportProperties.trustManagers
private

The documentation for this class was generated from the following file: