Java Code Examples for java.security.KeyManagementException

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project Bit4Tat, under directory /Bit4Tat/src/com/Bit4Tat/.

Source file: PaymentProcessorForMtGox.java

  21 
vote

HttpsURLConnection setupConnection(String urlString){
  SSLContext ctx=null;
  try {
    ctx=SSLContext.getInstance("TLS");
  }
 catch (  NoSuchAlgorithmException e1) {
    e1.printStackTrace();
  }
  try {
    ctx.init(new KeyManager[0],new TrustManager[]{new DefaultTrustManager()},new SecureRandom());
  }
 catch (  KeyManagementException e) {
    e.printStackTrace();
  }
  SSLContext.setDefault(ctx);
  URL url=null;
  try {
    url=new URL(urlString);
  }
 catch (  MalformedURLException e) {
    e.printStackTrace();
  }
  HttpsURLConnection conn=null;
  try {
    conn=(HttpsURLConnection)url.openConnection();
  }
 catch (  IOException e1) {
    e1.printStackTrace();
  }
  conn.setDoOutput(true);
  conn.setDoInput(true);
  conn.setHostnameVerifier(new HostnameVerifier(){
    @Override public boolean verify(    String arg0,    SSLSession arg1){
      return true;
    }
  }
);
  return conn;
}
 

Example 2

From project activemq-apollo, under directory /apollo-util/src/main/scala/org/apache/activemq/apollo/util/.

Source file: SslContext.java

  19 
vote

public SSLContext getSSLContext() throws NoSuchProviderException, NoSuchAlgorithmException, KeyManagementException {
  if (sslContext == null) {
    if (provider == null) {
      sslContext=SSLContext.getInstance(protocol);
    }
 else {
      sslContext=SSLContext.getInstance(protocol,provider);
    }
    sslContext.init(getKeyManagersAsArray(),getTrustManagersAsArray(),getSecureRandom());
  }
  return sslContext;
}
 

Example 3

From project AmDroid, under directory /AmenLib/src/main/java/com.jaeckel/amenoid/api/.

Source file: AmenHttpClient.java

  19 
vote

@Override protected ClientConnectionManager createClientConnectionManager(){
  SchemeRegistry registry=new SchemeRegistry();
  registry.register(new Scheme("http",80,PlainSocketFactory.getSocketFactory()));
  if (keyStoreStream != null) {
    registry.register(new Scheme("https",443,newSslSocketFactory()));
  }
 else {
    try {
      registry.register(new Scheme("https",443,new SSLSocketFactory(SSLContext.getInstance("Default"),new AllowAllHostnameVerifier())));
    }
 catch (    NoSuchAlgorithmException e) {
      e.printStackTrace();
      try {
        final SSLContext sslContext=SSLContext.getInstance("TLS");
        sslContext.init(null,null,null);
        registry.register(new Scheme("https",443,newSslSocketFactory()));
      }
 catch (      KeyManagementException e1) {
        throw new RuntimeException(e1);
      }
catch (      NoSuchAlgorithmException e1) {
        throw new RuntimeException(e1);
      }
    }
  }
  ThreadSafeClientConnManager connMgr=new ThreadSafeClientConnManager(registry);
  connMgr.setDefaultMaxPerRoute(10);
  return connMgr;
}
 

Example 4

From project android-client_1, under directory /src/com/googlecode/asmack/connection/impl/.

Source file: FeatureNegotiationEngine.java

  19 
vote

/** 
 * <p>Start TLS on the given connection.</p> <p><b>TODO:</b> This method uses a non-validating key manager.</p>
 * @throws NoSuchAlgorithmException If the requested encryption algorithmis not supported.
 * @throws KeyManagementException In case of a key managment error.
 * @throws IOException If the underlying stream dies.
 * @throws XmppTransportException In case of XML/XMPP related errors.
 */
protected void startTLS() throws NoSuchAlgorithmException, KeyManagementException, IOException, XmppTransportException {
  Log.d("BC/XMPP/Negotiation","StartTLS");
  xmppOutput.detach();
  xmppInput.detach();
  SSLContext context=SSLContext.getInstance("TLS");
  context.init(new KeyManager[]{},new javax.net.ssl.TrustManager[]{new UnTrustManager()},new java.security.SecureRandom());
  socket=context.getSocketFactory().createSocket(socket,socket.getInetAddress().getHostName(),socket.getPort(),true);
  socket.setKeepAlive(false);
  socket.setSoTimeout(0);
  inputStream=socket.getInputStream();
  outputStream=socket.getOutputStream();
  xmppOutput.attach(outputStream,true,false);
  xmppInput.attach(inputStream);
}
 

Example 5

From project android-rackspacecloud, under directory /extensions/apachehc/src/main/java/org/jclouds/http/apachehc/config/.

Source file: ApacheHCHttpCommandExecutorServiceModule.java

  19 
vote

@Singleton @Provides ClientConnectionManager newClientConnectionManager(HttpParams params,X509HostnameVerifier verifier,Closer closer) throws NoSuchAlgorithmException, KeyManagementException {
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  Scheme http=new Scheme("http",PlainSocketFactory.getSocketFactory(),80);
  SSLContext context=SSLContext.getInstance("TLS");
  context.init(null,null,null);
  SSLSocketFactory sf=new SSLSocketFactory(context);
  sf.setHostnameVerifier(verifier);
  Scheme https=new Scheme("https",sf,443);
  SchemeRegistry sr=new SchemeRegistry();
  sr.register(http);
  sr.register(https);
  schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443));
  final ClientConnectionManager cm=new ThreadSafeClientConnManager(params,schemeRegistry);
  closer.addToClose(new Closeable(){
    @Override public void close() throws IOException {
      cm.shutdown();
    }
  }
);
  return cm;
}
 

Example 6

From project AsmackService, under directory /src/com/googlecode/asmack/connection/impl/.

Source file: FeatureNegotiationEngine.java

  19 
vote

/** 
 * <p>Start TLS on the given connection.</p> <p><b>TODO:</b> This method uses a non-validating key manager.</p>
 * @throws NoSuchAlgorithmException If the requested encryption algorithmis not supported.
 * @throws KeyManagementException In case of a key managment error.
 * @throws IOException If the underlying stream dies.
 * @throws XmppTransportException In case of XML/XMPP related errors.
 */
protected void startTLS() throws NoSuchAlgorithmException, KeyManagementException, IOException, XmppTransportException {
  xmppOutput.detach();
  xmppInput.detach();
  SSLContext context=SSLContext.getInstance("TLS");
  context.init(new KeyManager[]{},new javax.net.ssl.TrustManager[]{new UnTrustManager()},new java.security.SecureRandom());
  socket=context.getSocketFactory().createSocket(socket,socket.getInetAddress().getHostName(),socket.getPort(),true);
  socket.setKeepAlive(false);
  socket.setSoTimeout(0);
  inputStream=socket.getInputStream();
  outputStream=socket.getOutputStream();
  xmppOutput.attach(outputStream,true,false);
  xmppInput.attach(inputStream);
}
 

Example 7

From project BombusLime, under directory /src/org/bombusim/networking/.

Source file: AndroidSSLSocketFactory.java

  19 
vote

public AndroidSSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
  super(truststore);
  TrustManager tm=new X509TrustManager(){
    public void checkClientTrusted(    X509Certificate[] chain,    String authType) throws CertificateException {
    }
    public void checkServerTrusted(    X509Certificate[] chain,    String authType) throws CertificateException {
    }
    public X509Certificate[] getAcceptedIssuers(){
      return null;
    }
  }
;
  sslContext.init(null,new TrustManager[]{tm},null);
}
 

Example 8

From project cloudbees-api-client, under directory /cloudbees-api-client/src/main/java/com/cloudbees/api/.

Source file: TrustAllSocketFactory.java

  19 
vote

public static SSLSocketFactory create(){
  try {
    SSLContext context=SSLContext.getInstance("SSL");
    context.init(null,new TrustManager[]{new X509TrustManager(){
      public void checkClientTrusted(      X509Certificate[] x509Certificates,      String authType) throws CertificateException {
      }
      public void checkServerTrusted(      X509Certificate[] x509Certificates,      String authType) throws CertificateException {
        if (LOGGER.isLoggable(FINE))         LOGGER.fine("Got the certificate: " + Arrays.asList(x509Certificates));
      }
      public X509Certificate[] getAcceptedIssuers(){
        return new X509Certificate[0];
      }
    }
},new SecureRandom());
    return context.getSocketFactory();
  }
 catch (  NoSuchAlgorithmException e) {
    throw new Error(e);
  }
catch (  KeyManagementException e) {
    throw new Error(e);
  }
}
 

Example 9

From project cloudify, under directory /esc/src/main/java/org/cloudifysource/esc/driver/provisioning/azure/client/.

Source file: MicrosoftAzureSSLHelper.java

  19 
vote

/** 
 * @return .
 * @throws NoSuchAlgorithmException .
 * @throws KeyStoreException .
 * @throws CertificateException .
 * @throws IOException .
 * @throws UnrecoverableKeyException .
 * @throws KeyManagementException .
 */
public SSLContext createSSLContext() throws NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException, UnrecoverableKeyException, KeyManagementException {
  InputStream pfxFile=null;
  SSLContext context=null;
  try {
    pfxFile=new FileInputStream(new File(pathToPfxFile));
    KeyManagerFactory keyManagerFactory=KeyManagerFactory.getInstance(SUN_X_509_ALGORITHM);
    KeyStore keyStore=KeyStore.getInstance(KEY_STORE_CONTEXT);
    keyStore.load(pfxFile,pfxPassword.toCharArray());
    pfxFile.close();
    keyManagerFactory.init(keyStore,pfxPassword.toCharArray());
    context=SSLContext.getInstance("SSL");
    context.init(keyManagerFactory.getKeyManagers(),null,new SecureRandom());
    return context;
  }
  finally {
    if (pfxFile != null) {
      pfxFile.close();
    }
  }
}
 

Example 10

From project Cours-3eme-ann-e, under directory /Java/FerryInpres/src/identity_server/.

Source file: IdentityServer.java

  19 
vote

private void login(ObjectInputStream in,ObjectOutputStream out,Cipher cryptor,Cipher decryptor) throws IOException, IllegalBlockSizeException, BadPaddingException, ClassNotFoundException, SQLException, NoSuchAlgorithmException, KeyStoreException, CertificateException, UnrecoverableKeyException, KeyManagementException {
  int serverSalt=(new Random()).nextInt();
  byte[] d=Utils.cryptObject(new LoginServer(serverSalt),cryptor);
  out.writeObject(d);
  out.flush();
  LoginClient response=(LoginClient)Utils.decryptObject((byte[])in.readObject(),decryptor);
  PreparedStatement instruc=this._con.prepareStatement("SELECT mot_de_passe " + "FROM agent " + "WHERE nom = ?");
  instruc.setString(1,response.getName());
  ResultSet rs=instruc.executeQuery();
  byte[] hashedPassword;
  if (rs.next()) {
    String password=rs.getString("mot_de_passe");
    hashedPassword=Utils.hashPassword(password,response.getClient_salt(),serverSalt);
  }
 else {
    hashedPassword=null;
  }
  if (hashedPassword != null && Arrays.equals(hashedPassword,response.getPassword_hashed())) {
    out.writeObject(Utils.cryptObject(new Ack(),cryptor));
    out.flush();
    verifId(in,out,cryptor,decryptor);
  }
 else {
    out.writeObject(Utils.cryptObject(new Fail(),cryptor));
    out.flush();
  }
}
 

Example 11

From project evodroid, under directory /src/com/sonorth/evodroid/util/.

Source file: TrustAllSSLSocketFactory.java

  19 
vote

public TrustAllSSLSocketFactory() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException {
  super(null);
  try {
    SSLContext sslcontext=SSLContext.getInstance("TLS");
    sslcontext.init(null,new TrustManager[]{new TrustAllManager()},null);
    factory=sslcontext.getSocketFactory();
    setHostnameVerifier(new AllowAllHostnameVerifier());
  }
 catch (  Exception ex) {
  }
}
 

Example 12

From project fedora-client, under directory /fedora-client-core/src/main/java/com/yourmediashelf/fedora/client/.

Source file: FedoraClient.java

  19 
vote

/** 
 * Constructor for FedoraClient.
 * @param fc credentials for a Fedora repository
 */
public FedoraClient(FedoraCredentials fc){
  this.fc=fc;
  if (fc.getBaseUrl().toString().startsWith("https")) {
    SSLContext ctx=null;
    try {
      ctx=SSLContext.getInstance("SSL");
      ctx.init(null,null,null);
    }
 catch (    NoSuchAlgorithmException e) {
      logger.error(e.getMessage(),e);
    }
catch (    KeyManagementException e) {
      logger.error(e.getMessage(),e);
    }
    ClientConfig config=new DefaultClientConfig();
    config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES,new HTTPSProperties(null,ctx));
    client=Client.create(config);
  }
 else {
    client=Client.create();
  }
  client.setFollowRedirects(true);
  client.addFilter(new HTTPBasicAuthFilter(fc.getUsername(),fc.getPassword()));
}
 

Example 13

From project friendica-for-android, under directory /mw-android-friendica-01/src/de/wikilab/android/friendica01/.

Source file: TwAjax.java

  19 
vote

public IgnoreCertsSSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
  super(truststore);
  TrustManager tm=new X509TrustManager(){
    public void checkClientTrusted(    X509Certificate[] chain,    String authType) throws CertificateException {
    }
    public void checkServerTrusted(    X509Certificate[] chain,    String authType) throws CertificateException {
    }
    public X509Certificate[] getAcceptedIssuers(){
      return null;
    }
  }
;
  sslContext.init(null,new TrustManager[]{tm},null);
}
 

Example 14

From project generic-store-for-android, under directory /src/com/wareninja/opensource/common/.

Source file: HttpUtils.java

  19 
vote

/** 
 * Send an HTTP(s) request with POST parameters.
 * @param parameters
 * @param url
 * @throws UnsupportedEncodingException
 * @throws IOException
 * @throws KeyManagementException
 * @throws NoSuchAlgorithmException
 */
public static void doPost(Map<?,?> parameters,URL url) throws UnsupportedEncodingException, IOException, KeyManagementException, NoSuchAlgorithmException {
  URLConnection cnx=getConnection(url);
  StringBuilder dataBfr=new StringBuilder();
  Iterator<?> iKeys=parameters.keySet().iterator();
  while (iKeys.hasNext()) {
    if (dataBfr.length() != 0) {
      dataBfr.append('&');
    }
    String key=(String)iKeys.next();
    dataBfr.append(URLEncoder.encode(key,"UTF-8")).append('=').append(URLEncoder.encode((String)parameters.get(key),"UTF-8"));
  }
  cnx.setDoOutput(true);
  OutputStreamWriter wr=new OutputStreamWriter(cnx.getOutputStream());
  if (LOGGING.DEBUG)   Log.d(LOG_TAG,"Posting crash report data");
  wr.write(dataBfr.toString());
  wr.flush();
  wr.close();
  if (LOGGING.DEBUG)   Log.d(LOG_TAG,"Reading response");
  BufferedReader rd=new BufferedReader(new InputStreamReader(cnx.getInputStream()));
  String line;
  int linecount=0;
  while ((line=rd.readLine()) != null) {
    linecount++;
    if (linecount <= 2) {
      if (LOGGING.DEBUG)       Log.d(LOG_TAG,line);
    }
  }
  rd.close();
}
 

Example 15

From project GNDMS, under directory /gndmc-rest/src/de/zib/gndms/gndmc/dspace/.

Source file: SliceClient.java

  19 
vote

@Override public ResponseEntity<Integer> listFileContent(final Specifier<Void> slice,final String fileName,final List<String> attrs,final String dn,final OutputStream out) throws NoSuchAlgorithmException, KeyManagementException, IOException {
  HTTPGetter httpGetter=new HTTPGetter();
  GNDMSResponseHeader headers=new GNDMSResponseHeader();
  if (dn != null)   headers.setDN(dn);
  EnhancedResponseExtractor responseExtractor=new DefaultResponseExtractor(){
    @Override public void extractData(    String url,    ClientHttpResponse response) throws IOException {
      super.extractData(url,response);
      FileCopyUtils.copy(getBody(),out);
    }
  }
;
  httpGetter.setExtractor(200,responseExtractor);
  httpGetter.get(makeFileNameFacet(slice.getUrl(),fileName),headers);
  return new ResponseEntity<Integer>(0,responseExtractor.getHeaders(),HttpStatus.valueOf(responseExtractor.getStatusCode()));
}
 

Example 16

From project Haven-and-Hearth-client-modified-by-Ender, under directory /src/haven/.

Source file: SslHelper.java

  19 
vote

private synchronized SSLContext ctx(){
  if (ctx == null) {
    TrustManagerFactory tmf;
    KeyManagerFactory kmf;
    try {
      ctx=SSLContext.getInstance("TLS");
      tmf=TrustManagerFactory.getInstance("PKIX");
      kmf=KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
      KeyManager[] kms=null;
      tmf.init(trusted);
      if (creds != null) {
        kmf.init(creds,pw);
        kms=kmf.getKeyManagers();
      }
      ctx.init(kms,tmf.getTrustManagers(),new SecureRandom());
    }
 catch (    NoSuchAlgorithmException e) {
      throw (new Error(e));
    }
catch (    KeyStoreException e) {
      throw (new RuntimeException(e));
    }
catch (    UnrecoverableKeyException e) {
      throw (new RuntimeException(e));
    }
catch (    KeyManagementException e) {
      throw (new RuntimeException(e));
    }
  }
  return (ctx);
}
 

Example 17

From project httpClient, under directory /httpclient/src/main/java/org/apache/http/conn/ssl/.

Source file: SSLSocketFactory.java

  19 
vote

private static SSLContext createSSLContext(String algorithm,final KeyStore keystore,final String keystorePassword,final KeyStore truststore,final SecureRandom random,final TrustStrategy trustStrategy) throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException, KeyManagementException {
  if (algorithm == null) {
    algorithm=TLS;
  }
  KeyManagerFactory kmfactory=KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
  kmfactory.init(keystore,keystorePassword != null ? keystorePassword.toCharArray() : null);
  KeyManager[] keymanagers=kmfactory.getKeyManagers();
  TrustManagerFactory tmfactory=TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
  tmfactory.init(truststore);
  TrustManager[] trustmanagers=tmfactory.getTrustManagers();
  if (trustmanagers != null && trustStrategy != null) {
    for (int i=0; i < trustmanagers.length; i++) {
      TrustManager tm=trustmanagers[i];
      if (tm instanceof X509TrustManager) {
        trustmanagers[i]=new TrustManagerDecorator((X509TrustManager)tm,trustStrategy);
      }
    }
  }
  SSLContext sslcontext=SSLContext.getInstance(algorithm);
  sslcontext.init(keymanagers,trustmanagers,random);
  return sslcontext;
}
 

Example 18

From project https-utils, under directory /src/test/java/org/italiangrid/utils/test/.

Source file: ConnectionTest.java

  19 
vote

/** 
 * Connect using a certificate released from a trusted CA.
 */
@Test public void trustedCertificateAgain() throws IOException, KeyStoreException, NoSuchAlgorithmException, CertificateException, KeyManagementException, UnrecoverableKeyException {
  HttpsURLConnection.setDefaultHostnameVerifier(new javax.net.ssl.HostnameVerifier(){
    public boolean verify(    String hostname,    javax.net.ssl.SSLSession sslSession){
      if (hostname.equals("localhost")) {
        return true;
      }
      return false;
    }
  }
);
  PEMCredential credential=new PEMCredential("certs/voms-client-key.pem","certs/voms-client-cert.pem","pass".toCharArray());
  OpensslCertChainValidator validator=new OpensslCertChainValidator("certs/ca",NamespaceCheckingMode.EUGRIDPMA_AND_GLOBUS,60000L);
  SSLContext context=SocketFactoryCreator.getSSLContext(credential,validator,null);
  URL url=new URL("https://localhost:" + port);
  HttpsURLConnection connection=(HttpsURLConnection)url.openConnection();
  connection.setSSLSocketFactory(context.getSocketFactory());
  connection.connect();
  Assert.assertEquals(200,connection.getResponseCode());
  connection.disconnect();
}
 

Example 19

From project httpserver, under directory /src/test/java/.

Source file: SimpleSSLContext.java

  19 
vote

SimpleSSLContext(String dir) throws IOException {
  try {
    String file=dir + "/testkeys";
    char[] passphrase="passphrase".toCharArray();
    KeyStore ks=KeyStore.getInstance("JKS");
    ks.load(new FileInputStream(file),passphrase);
    KeyManagerFactory kmf=KeyManagerFactory.getInstance("SunX509");
    kmf.init(ks,passphrase);
    TrustManagerFactory tmf=TrustManagerFactory.getInstance("SunX509");
    tmf.init(ks);
    ssl=SSLContext.getInstance("TLS");
    ssl.init(kmf.getKeyManagers(),tmf.getTrustManagers(),null);
  }
 catch (  KeyManagementException e) {
    throw new RuntimeException(e.getMessage());
  }
catch (  KeyStoreException e) {
    throw new RuntimeException(e.getMessage());
  }
catch (  UnrecoverableKeyException e) {
    throw new RuntimeException(e.getMessage());
  }
catch (  CertificateException e) {
    throw new RuntimeException(e.getMessage());
  }
catch (  NoSuchAlgorithmException e) {
    throw new RuntimeException(e.getMessage());
  }
}
 

Example 20

From project iSpace, under directory /base/httpcrawler/src/main/java/com/villemos/ispace/httpcrawler/.

Source file: HttpClientConfigurer.java

  19 
vote

public static HttpClient setupClient(boolean ignoreAuthenticationFailure,String domain,Integer port,String proxyHost,Integer proxyPort,String authUser,String authPassword,CookieStore cookieStore) throws NoSuchAlgorithmException, KeyManagementException {
  DefaultHttpClient client=null;
  if (ignoreAuthenticationFailure) {
    SSLContext sslContext=SSLContext.getInstance("SSL");
    sslContext.init(null,new TrustManager[]{new EasyX509TrustManager()},new SecureRandom());
    SchemeRegistry schemeRegistry=new SchemeRegistry();
    SSLSocketFactory sf=new SSLSocketFactory(sslContext);
    Scheme httpsScheme=new Scheme("https",sf,443);
    schemeRegistry.register(httpsScheme);
    SocketFactory sfa=new PlainSocketFactory();
    Scheme httpScheme=new Scheme("http",sfa,80);
    schemeRegistry.register(httpScheme);
    HttpParams params=new BasicHttpParams();
    ClientConnectionManager cm=new SingleClientConnManager(params,schemeRegistry);
    client=new DefaultHttpClient(cm,params);
  }
 else {
    client=new DefaultHttpClient();
  }
  if (proxyHost != null && proxyPort != null) {
    HttpHost proxy=new HttpHost(proxyHost,proxyPort);
    client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,proxy);
  }
 else {
    ProxySelectorRoutePlanner routePlanner=new ProxySelectorRoutePlanner(client.getConnectionManager().getSchemeRegistry(),ProxySelector.getDefault());
    client.setRoutePlanner(routePlanner);
  }
  if (authUser != null && authPassword != null) {
    client.getCredentialsProvider().setCredentials(new AuthScope(domain,port),new UsernamePasswordCredentials(authUser,authPassword));
  }
  client.setCookieStore(cookieStore);
  client.getParams().setParameter(ClientPNames.COOKIE_POLICY,CookiePolicy.BEST_MATCH);
  return client;
}
 

Example 21

From project JGlobus, under directory /jsse/src/main/java/org/globus/gsi/jsse/.

Source file: SSLConfigurator.java

  19 
vote

private void configureContext() throws GlobusSSLConfigurationException {
  ManagerFactoryParameters parameters=getCertPathParameters();
  TrustManager[] trustManagers;
  try {
    TrustManagerFactory fact=TrustManagerFactory.getInstance("GSI");
    fact.init(parameters);
    trustManagers=fact.getTrustManagers();
  }
 catch (  NoSuchAlgorithmException e1) {
    throw new GlobusSSLConfigurationException(e1);
  }
catch (  InvalidAlgorithmParameterException e) {
    throw new GlobusSSLConfigurationException(e);
  }
  KeyManager[] keyManagers=loadKeyManagers();
  SecureRandom secureRandom=loadSecureRandom();
  sslContext=loadSSLContext();
  try {
    sslContext.init(keyManagers,trustManagers,secureRandom);
  }
 catch (  KeyManagementException e) {
    throw new GlobusSSLConfigurationException(e);
  }
}
 

Example 22

From project jnrpe-lib, under directory /jnrpe-lib/src/main/java/it/jnrpe/.

Source file: JNRPEListenerThread.java

  19 
vote

/** 
 * Creates an SSLServerSocketFactory.
 * @return the newly creates SSL Server Socket Factory
 * @throws KeyStoreException
 * @throws CertificateException
 * @throws IOException
 * @throws UnrecoverableKeyException
 * @throws KeyManagementException
 */
private SSLServerSocketFactory getSSLSocketFactory() throws KeyStoreException, CertificateException, IOException, UnrecoverableKeyException, KeyManagementException {
  StreamManager h=new StreamManager();
  SSLContext ctx;
  KeyManagerFactory kmf;
  try {
    InputStream ksStream=getClass().getClassLoader().getResourceAsStream(KEYSTORE_NAME);
    h.handle(ksStream);
    ctx=SSLContext.getInstance("SSLv3");
    kmf=KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
    KeyStore ks=KeyStore.getInstance("JKS");
    char[] passphrase=KEYSTORE_PWD.toCharArray();
    ks.load(ksStream,passphrase);
    kmf.init(ks,passphrase);
    ctx.init(kmf.getKeyManagers(),null,new java.security.SecureRandom());
  }
 catch (  NoSuchAlgorithmException e) {
    throw new SSLException("Unable to initialize SSLSocketFactory.\n" + e.getMessage());
  }
 finally {
    h.closeAll();
  }
  return ctx.getServerSocketFactory();
}
 

Example 23

From project k-9, under directory /src/com/fsck/k9/mail/store/.

Source file: WebDavStore.java

  19 
vote

public WebDavHttpClient getHttpClient() throws MessagingException {
  if (mHttpClient == null) {
    mHttpClient=new WebDavHttpClient();
    mHttpClient.getParams().setBooleanParameter("http.protocol.handle-redirects",false);
    mContext=new BasicHttpContext();
    mAuthCookies=new BasicCookieStore();
    mContext.setAttribute(ClientContext.COOKIE_STORE,mAuthCookies);
    SchemeRegistry reg=mHttpClient.getConnectionManager().getSchemeRegistry();
    try {
      Scheme s=new Scheme("https",new TrustedSocketFactory(mHost,mSecure),443);
      reg.register(s);
    }
 catch (    NoSuchAlgorithmException nsa) {
      Log.e(K9.LOG_TAG,"NoSuchAlgorithmException in getHttpClient: " + nsa);
      throw new MessagingException("NoSuchAlgorithmException in getHttpClient: " + nsa);
    }
catch (    KeyManagementException kme) {
      Log.e(K9.LOG_TAG,"KeyManagementException in getHttpClient: " + kme);
      throw new MessagingException("KeyManagementException in getHttpClient: " + kme);
    }
  }
  return mHttpClient;
}
 

Example 24

From project lightfish, under directory /lightfish/src/main/java/org/lightfish/business/authenticator/.

Source file: GlassfishAuthenticator.java

  19 
vote

public void addAuthenticator(Client client,String username,String password){
  client.addFilter(new HTTPBasicAuthFilter(username,password));
  HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier(){
    @Override public boolean verify(    String string,    SSLSession ssls){
      return true;
    }
  }
);
  try {
    SSLContext sc=SSLContext.getInstance("SSL");
    sc.init(null,trustAllCerts,new java.security.SecureRandom());
    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
  }
 catch (  KeyManagementException|NoSuchAlgorithmException ex) {
    Logger.getLogger(SnapshotProvider.class.getName()).log(Level.SEVERE,null,ex);
  }
}
 

Example 25

From project LoL-Chat, under directory /src/com/rei/lolchat/.

Source file: BeemService.java

  19 
vote

public static void allowAllSSL(){
  HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier(){
    public boolean verify(    String hostname,    SSLSession session){
      return true;
    }
  }
);
  if (trustManagers == null) {
    trustManagers=new TrustManager[]{new FakeX509TrustManager()};
  }
  try {
    context=SSLContext.getInstance("TLS");
    context.init(null,trustManagers,new SecureRandom());
  }
 catch (  NoSuchAlgorithmException e) {
    e.printStackTrace();
  }
catch (  KeyManagementException e) {
    e.printStackTrace();
  }
  HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
}
 

Example 26

From project LRJavaLib, under directory /src/com/navnorth/learningregistry/util/.

Source file: SelfSignSSLSocketFactory.java

  19 
vote

public SelfSignSSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
  super(truststore);
  TrustManager tm=new X509TrustManager(){
    public void checkClientTrusted(    X509Certificate[] chain,    String authType) throws CertificateException {
    }
    public void checkServerTrusted(    X509Certificate[] chain,    String authType) throws CertificateException {
    }
    public X509Certificate[] getAcceptedIssuers(){
      return null;
    }
  }
;
  sslContext.init(null,new TrustManager[]{tm},null);
}
 

Example 27

From project lyo.testsuite, under directory /org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/util/.

Source file: OSLCUtils.java

  19 
vote

static public void setupLazySSLSupport(HttpClient httpClient){
  ClientConnectionManager connManager=httpClient.getConnectionManager();
  SchemeRegistry schemeRegistry=connManager.getSchemeRegistry();
  schemeRegistry.unregister("https");
  TrustManager[] trustAllCerts=new TrustManager[]{new X509TrustManager(){
    public void checkClientTrusted(    java.security.cert.X509Certificate[] certs,    String authType){
    }
    public void checkServerTrusted(    java.security.cert.X509Certificate[] certs,    String authType){
    }
    public java.security.cert.X509Certificate[] getAcceptedIssuers(){
      return null;
    }
  }
};
  SSLContext sc=null;
  try {
    sc=SSLContext.getInstance("SSL");
    sc.init(null,trustAllCerts,new java.security.SecureRandom());
  }
 catch (  NoSuchAlgorithmException e) {
  }
catch (  KeyManagementException e) {
  }
  SSLSocketFactory sf=new SSLSocketFactory(sc);
  sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
  Scheme https=new Scheme("https",sf,443);
  schemeRegistry.register(https);
}
 

Example 28

From project MobiPerf, under directory /android/src/com/mobiperf/speedometer/.

Source file: Checkin.java

  19 
vote

public MySSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
  super(truststore);
  X509TrustManager tm=new X509TrustManager(){
    public X509Certificate[] getAcceptedIssuers(){
      return null;
    }
    @Override public void checkClientTrusted(    X509Certificate[] chain,    String authType) throws CertificateException {
    }
    @Override public void checkServerTrusted(    X509Certificate[] chain,    String authType) throws CertificateException {
    }
  }
;
  sslContext.init(null,new TrustManager[]{tm},null);
}
 

Example 29

From project nuxeo-services, under directory /nuxeo-platform-directory/nuxeo-platform-directory-ldap/src/main/java/org/nuxeo/ecm/directory/ldap/.

Source file: LDAPDirectory.java

  19 
vote

/** 
 * Create a new SSLSocketFactory that creates a Socket regardless of the certificate used.
 * @throws SSLException if initialization fails.
 */
public TrustingSSLSocketFactory(){
  try {
    SSLContext sslContext=SSLContext.getInstance("TLS");
    sslContext.init(null,new TrustManager[]{new TrustingX509TrustManager()},new SecureRandom());
    factory=sslContext.getSocketFactory();
  }
 catch (  NoSuchAlgorithmException nsae) {
    throw new RuntimeException("Unable to initialize the SSL context:  ",nsae);
  }
catch (  KeyManagementException kme) {
    throw new RuntimeException("Unable to register a trust manager:  ",kme);
  }
}
 

Example 30

From project OpenMEAP, under directory /java-shared/openmeap-shared-jdk5/src/com/openmeap/util/.

Source file: SSLUtils.java

  19 
vote

public MySSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
  super(truststore);
  X509TrustManager tm=new X509TrustManager(){
    public void checkClientTrusted(    X509Certificate[] chain,    String authType) throws CertificateException {
    }
    public void checkServerTrusted(    X509Certificate[] chain,    String authType) throws CertificateException {
    }
    public X509Certificate[] getAcceptedIssuers(){
      return null;
    }
  }
;
  sslContext.init(null,new TrustManager[]{tm},null);
}
 

Example 31

From project openshift-java-client, under directory /src/main/java/com/openshift/internal/client/httpclient/.

Source file: UrlConnectionHttpClient.java

  19 
vote

/** 
 * Sets a trust manager that will always trust. <p> TODO: dont swallog exceptions and setup things so that they dont disturb other components.
 */
private void setPermissiveSSLSocketFactory(HttpsURLConnection connection){
  try {
    SSLContext sslContext=SSLContext.getInstance("SSL");
    sslContext.init(new KeyManager[0],new TrustManager[]{new PermissiveTrustManager()},new SecureRandom());
    SSLSocketFactory socketFactory=sslContext.getSocketFactory();
    ((HttpsURLConnection)connection).setSSLSocketFactory(socketFactory);
  }
 catch (  KeyManagementException e) {
  }
catch (  NoSuchAlgorithmException e) {
  }
}
 

Example 32

From project Orweb, under directory /src/info/guardianproject/browser/.

Source file: ModSSLSocketFactory.java

  19 
vote

public ModSSLSocketFactory(String algorithm,final KeyStore keystore,final String keystorePassword,final KeyStore truststore,final SecureRandom random,final HostNameResolver nameResolver) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
  super();
  if (algorithm == null) {
    algorithm=TLS;
  }
  KeyManager[] keymanagers=null;
  if (keystore != null) {
    keymanagers=createKeyManagers(keystore,keystorePassword);
  }
  TrustManager[] trustmanagers=null;
  if (truststore != null) {
    trustmanagers=createTrustManagers(truststore);
  }
  this.sslcontext=SSLContext.getInstance(algorithm);
  this.sslcontext.init(keymanagers,trustmanagers,random);
  this.socketfactory=this.sslcontext.getSocketFactory();
  this.nameResolver=nameResolver;
}
 

Example 33

From project osgi-tests, under directory /test/glassfish-derby/src/test/java/org/ancoron/osgi/test/glassfish/.

Source file: GlassfishDerbyTest.java

  19 
vote

protected DefaultHttpClient getHTTPClient() throws NoSuchAlgorithmException, KeyManagementException {
  SSLContext sslContext=SSLContext.getInstance("SSL");
  sslContext.init(null,new TrustManager[]{new X509TrustManager(){
    @Override public X509Certificate[] getAcceptedIssuers(){
      System.out.println("getAcceptedIssuers =============");
      return null;
    }
    @Override public void checkClientTrusted(    X509Certificate[] certs,    String authType){
      System.out.println("checkClientTrusted =============");
    }
    @Override public void checkServerTrusted(    X509Certificate[] certs,    String authType){
      System.out.println("checkServerTrusted =============");
    }
  }
},new SecureRandom());
  SSLSocketFactory sf=new SSLSocketFactory(sslContext,SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
  Scheme httpsScheme=new Scheme("https",8181,sf);
  PlainSocketFactory plain=new PlainSocketFactory();
  Scheme httpScheme=new Scheme("http",8080,plain);
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  schemeRegistry.register(httpsScheme);
  schemeRegistry.register(httpScheme);
  HttpParams params=new BasicHttpParams();
  ThreadSafeClientConnManager cm=new ThreadSafeClientConnManager(schemeRegistry);
  cm.setMaxTotal(200);
  cm.setDefaultMaxPerRoute(20);
  DefaultHttpClient httpClient=new DefaultHttpClient(cm,params);
  httpClient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION,HttpVersion.HTTP_1_1);
  httpClient.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET,"UTF-8");
  return httpClient;
}
 

Example 34

From project overthere, under directory /src/main/java/com/xebialabs/overthere/cifs/winrm/connector/.

Source file: ApacheHttpComponentsHttpClientHttpConnector.java

  19 
vote

/** 
 * Configure the httpclient for use in all requests.
 */
private void configureHttpClient(final DefaultHttpClient httpclient) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
  configureTrust(httpclient);
  configureAuthentication(httpclient,"Basic",new BasicUserPrincipal(username));
  if (useKerberos) {
    configureAuthentication(httpclient,"Kerberos",new KerberosPrincipal(username));
  }
  httpclient.getParams().setBooleanParameter(HANDLE_AUTHENTICATION,true);
}
 

Example 35

From project OWASP-WebScarab, under directory /src/org/owasp/webscarab/httpclient/.

Source file: SSLContextManager.java

  19 
vote

/** 
 * Creates a new instance of SSLContextManager 
 */
public SSLContextManager(){
  System.setProperty("sun.security.ssl.allowUnsafeRenegotiation","true");
  try {
    _noClientCertContext=SSLContext.getInstance("SSL");
    _noClientCertContext.init(null,_trustAllCerts,new SecureRandom());
  }
 catch (  NoSuchAlgorithmException nsao) {
    _logger.severe("Could not get an instance of the SSL algorithm: " + nsao.getMessage());
  }
catch (  KeyManagementException kme) {
    _logger.severe("Error initialising the SSL Context: " + kme);
  }
  try {
    if (System.getProperty("os.name").toLowerCase().indexOf("win") >= 0) {
      initPKCS11("P11-CAPI","lib/p11-capi.dll",0,"");
    }
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
}
 

Example 36

From project platform_external_apache-http, under directory /src/org/apache/http/conn/ssl/.

Source file: SSLSocketFactory.java

  19 
vote

public SSLSocketFactory(String algorithm,final KeyStore keystore,final String keystorePassword,final KeyStore truststore,final SecureRandom random,final HostNameResolver nameResolver) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
  super();
  if (algorithm == null) {
    algorithm=TLS;
  }
  KeyManager[] keymanagers=null;
  if (keystore != null) {
    keymanagers=createKeyManagers(keystore,keystorePassword);
  }
  TrustManager[] trustmanagers=null;
  if (truststore != null) {
    trustmanagers=createTrustManagers(truststore);
  }
  this.sslcontext=SSLContext.getInstance(algorithm);
  this.sslcontext.init(keymanagers,trustmanagers,random);
  this.socketfactory=this.sslcontext.getSocketFactory();
  this.nameResolver=nameResolver;
}
 

Example 37

From project QuotaForAndroid, under directory /Quota/src/com/southfreo/quota/utils/.

Source file: OpenSSLFactory.java

  19 
vote

public OpenSSLFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
  super(truststore);
  TrustManager tm=new X509TrustManager(){
    public void checkClientTrusted(    X509Certificate[] chain,    String authType) throws CertificateException {
    }
    public void checkServerTrusted(    X509Certificate[] chain,    String authType) throws CertificateException {
    }
    public X509Certificate[] getAcceptedIssuers(){
      return null;
    }
  }
;
  sslContext.init(null,new TrustManager[]{tm},null);
}
 

Example 38

From project rabbitmq-java-client, under directory /src/com/rabbitmq/client/.

Source file: ConnectionFactory.java

  19 
vote

/** 
 * Convenience method for setting the fields in an AMQP URI: host, port, username, password and virtual host.  If any part of the URI is ommited, the ConnectionFactory's corresponding variable is left unchanged.
 * @param uri is the AMQP URI containing the data
 */
public void setUri(URI uri) throws URISyntaxException, NoSuchAlgorithmException, KeyManagementException {
  if ("amqp".equals(uri.getScheme().toLowerCase())) {
  }
 else   if ("amqps".equals(uri.getScheme().toLowerCase())) {
    setPort(DEFAULT_AMQP_OVER_SSL_PORT);
    useSslProtocol();
  }
 else {
    throw new IllegalArgumentException("Wrong scheme in AMQP URI: " + uri.getScheme());
  }
  String host=uri.getHost();
  if (host != null) {
    setHost(host);
  }
  int port=uri.getPort();
  if (port != -1) {
    setPort(port);
  }
  String userInfo=uri.getRawUserInfo();
  if (userInfo != null) {
    String userPass[]=userInfo.split(":");
    if (userPass.length > 2) {
      throw new IllegalArgumentException("Bad user info in AMQP " + "URI: " + userInfo);
    }
    setUsername(uriDecode(userPass[0]));
    if (userPass.length == 2) {
      setPassword(uriDecode(userPass[1]));
    }
  }
  String path=uri.getRawPath();
  if (path != null && path.length() > 0) {
    if (path.indexOf('/',1) != -1) {
      throw new IllegalArgumentException("Multiple segments in " + "path of AMQP URI: " + path);
    }
    setVirtualHost(uriDecode(uri.getPath().substring(1)));
  }
}
 

Example 39

From project recordloader, under directory /src/java/com/marklogic/recordloader/xcc/.

Source file: XccAbstractContentFactory.java

  19 
vote

public String getVersionString(){
  try {
    return "client = " + configuration.getDriverVersionString() + ", server = "+ configuration.getServerVersionString();
  }
 catch (  XccException e) {
    throw new FatalException(e);
  }
catch (  KeyManagementException e) {
    throw new FatalException(e);
  }
catch (  NoSuchAlgorithmException e) {
    throw new FatalException(e);
  }
}
 

Example 40

From project remoting, under directory /src/main/java/hudson/remoting/.

Source file: Launcher.java

  19 
vote

/** 
 * Bypass HTTPS security check by using free-for-all trust manager.
 * @param _ This is ignored.
 */
@Option(name="-noCertificateCheck") public void setNoCertificateCheck(boolean _) throws NoSuchAlgorithmException, KeyManagementException {
  System.out.println("Skipping HTTPS certificate checks altoghether. Note that this is not secure at all.");
  SSLContext context=SSLContext.getInstance("TLS");
  context.init(null,new TrustManager[]{new NoCheckTrustManager()},new java.security.SecureRandom());
  HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
  HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier(){
    public boolean verify(    String s,    SSLSession sslSession){
      return true;
    }
  }
);
}
 

Example 41

From project rest-client, under directory /src/main/java/org/hudsonci/rest/client/internal/ssl/.

Source file: TrustAllX509TrustManager.java

  19 
vote

public static synchronized void install() throws KeyManagementException, NoSuchAlgorithmException {
  SSLContext context=SSLContext.getInstance("SSL");
  context.init(null,new TrustManager[]{new TrustAllX509TrustManager()},new SecureRandom());
  HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
  log.warn("Trust-all SSL trust manager installed");
}
 

Example 42

From project Rhybudd, under directory /src/net/networksaremadeofstring/rhybudd/.

Source file: TrustAllSSLSocketFactory.java

  19 
vote

public TrustAllSSLSocketFactory() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException {
  super(null);
  try {
    SSLContext sslcontext=SSLContext.getInstance("TLS");
    sslcontext.init(null,new TrustManager[]{new TrustAllManager()},null);
    factory=sslcontext.getSocketFactory();
    setHostnameVerifier(new AllowAllHostnameVerifier());
  }
 catch (  Exception ex) {
  }
}
 

Example 43

From project rundeck-api-java-client, under directory /src/main/java/org/rundeck/api/.

Source file: ApiCall.java

  19 
vote

/** 
 * Instantiate a new  {@link HttpClient} instance, configured to accept all SSL certificates
 * @return an {@link HttpClient} instance - won't be null
 */
private HttpClient instantiateHttpClient(){
  DefaultHttpClient httpClient=new DefaultHttpClient();
  HttpProtocolParams.setUserAgent(httpClient.getParams(),"RunDeck API Java Client " + RundeckClient.API_VERSION);
  SSLSocketFactory socketFactory=null;
  try {
    socketFactory=new SSLSocketFactory(new TrustStrategy(){
      @Override public boolean isTrusted(      X509Certificate[] chain,      String authType) throws CertificateException {
        return true;
      }
    }
,SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
  }
 catch (  KeyManagementException e) {
    throw new RuntimeException(e);
  }
catch (  UnrecoverableKeyException e) {
    throw new RuntimeException(e);
  }
catch (  NoSuchAlgorithmException e) {
    throw new RuntimeException(e);
  }
catch (  KeyStoreException e) {
    throw new RuntimeException(e);
  }
  httpClient.getConnectionManager().getSchemeRegistry().register(new Scheme("https",443,socketFactory));
  System.setProperty("java.net.useSystemProxies","true");
  httpClient.setRoutePlanner(new ProxySelectorRoutePlanner(httpClient.getConnectionManager().getSchemeRegistry(),ProxySelector.getDefault()));
  httpClient.addRequestInterceptor(new HttpRequestInterceptor(){
    @Override public void process(    HttpRequest request,    HttpContext context) throws HttpException, IOException {
      if (client.getToken() != null) {
        request.addHeader(AUTH_TOKEN_HEADER,client.getToken());
      }
    }
  }
);
  return httpClient;
}
 

Example 44

From project salem, under directory /src/haven/.

Source file: SslHelper.java

  19 
vote

private synchronized SSLContext ctx(){
  if (ctx == null) {
    TrustManagerFactory tmf;
    KeyManagerFactory kmf;
    try {
      ctx=SSLContext.getInstance("TLS");
      tmf=TrustManagerFactory.getInstance("PKIX");
      kmf=KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
      KeyManager[] kms=null;
      tmf.init(trusted);
      if (creds != null) {
        kmf.init(creds,pw);
        kms=kmf.getKeyManagers();
      }
      ctx.init(kms,tmf.getTrustManagers(),new SecureRandom());
    }
 catch (    NoSuchAlgorithmException e) {
      throw (new Error(e));
    }
catch (    KeyStoreException e) {
      throw (new RuntimeException(e));
    }
catch (    UnrecoverableKeyException e) {
      throw (new RuntimeException(e));
    }
catch (    KeyManagementException e) {
      throw (new RuntimeException(e));
    }
  }
  return (ctx);
}
 

Example 45

From project skalli, under directory /org.eclipse.skalli.core/src/main/java/org/eclipse/skalli/core/internal/destination/.

Source file: DestinationServiceImpl.java

  19 
vote

private void initializeConnectionManager(){
  connectionManager=new ThreadSafeClientConnManager();
  connectionManager.setMaxTotal(MAX_TOTAL_CONNECTIONS);
  connectionManager.setDefaultMaxPerRoute(MAX_CONNECTIONS_PER_ROUTE);
  SSLContext sslContext=getSSLContext();
  try {
    sslContext.init(null,new TrustManager[]{new AlwaysTrustX509Manager()},null);
  }
 catch (  KeyManagementException e) {
    throw new IllegalStateException("Failed to initialize SSL context",e);
  }
  SSLSocketFactory socketFactory=new SSLSocketFactory(sslContext,new AllowAllHostnamesVerifier());
  SchemeRegistry schemeRegistry=connectionManager.getSchemeRegistry();
  schemeRegistry.register(new Scheme(HTTPS,443,socketFactory));
}
 

Example 46

From project SMSSync, under directory /smssync/src/org/addhen/smssync/net/.

Source file: MainHttpClient.java

  19 
vote

public MainHttpClient(String url){
  this.url=url;
  httpParameters=new BasicHttpParams();
  httpParameters.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS,1);
  httpParameters.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE,new ConnPerRouteBean(1));
  httpParameters.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE,false);
  HttpProtocolParams.setVersion(httpParameters,HttpVersion.HTTP_1_1);
  HttpProtocolParams.setContentCharset(httpParameters,"utf8");
  HttpConnectionParams.setConnectionTimeout(httpParameters,timeoutConnection);
  HttpConnectionParams.setSoTimeout(httpParameters,timeoutSocket);
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  try {
    schemeRegistry.register(new Scheme("https",new TrustedSocketFactory(url,false),443));
  }
 catch (  KeyManagementException e) {
    e.printStackTrace();
  }
catch (  NoSuchAlgorithmException e) {
    e.printStackTrace();
  }
  ThreadSafeClientConnManager manager=new ThreadSafeClientConnManager(httpParameters,schemeRegistry);
  httpclient=new DefaultHttpClient(manager,httpParameters);
}
 

Example 47

From project Speedometer, under directory /android/src/com/google/wireless/speed/speedometer/.

Source file: Checkin.java

  19 
vote

public MySSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
  super(truststore);
  X509TrustManager tm=new X509TrustManager(){
    public X509Certificate[] getAcceptedIssuers(){
      return null;
    }
    @Override public void checkClientTrusted(    X509Certificate[] chain,    String authType) throws CertificateException {
    }
    @Override public void checkServerTrusted(    X509Certificate[] chain,    String authType) throws CertificateException {
    }
  }
;
  sslContext.init(null,new TrustManager[]{tm},null);
}
 

Example 48

From project subsonic, under directory /subsonic-android/src/github/daneren2005/dsub/service/ssl/.

Source file: SSLSocketFactory.java

  19 
vote

private static SSLContext createSSLContext(String algorithm,final KeyStore keystore,final String keystorePassword,final KeyStore truststore,final SecureRandom random,final TrustStrategy trustStrategy) throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException, KeyManagementException {
  if (algorithm == null) {
    algorithm=TLS;
  }
  KeyManagerFactory kmfactory=KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
  kmfactory.init(keystore,keystorePassword != null ? keystorePassword.toCharArray() : null);
  KeyManager[] keymanagers=kmfactory.getKeyManagers();
  TrustManagerFactory tmfactory=TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
  tmfactory.init(keystore);
  TrustManager[] trustmanagers=tmfactory.getTrustManagers();
  if (trustmanagers != null && trustStrategy != null) {
    for (int i=0; i < trustmanagers.length; i++) {
      TrustManager tm=trustmanagers[i];
      if (tm instanceof X509TrustManager) {
        trustmanagers[i]=new TrustManagerDecorator((X509TrustManager)tm,trustStrategy);
      }
    }
  }
  SSLContext sslcontext=SSLContext.getInstance(algorithm);
  sslcontext.init(keymanagers,trustmanagers,random);
  return sslcontext;
}
 

Example 49

From project Subsonic-Android, under directory /src/net/sourceforge/subsonic/androidapp/service/ssl/.

Source file: SSLSocketFactory.java

  19 
vote

private static SSLContext createSSLContext(String algorithm,final KeyStore keystore,final String keystorePassword,final KeyStore truststore,final SecureRandom random,final TrustStrategy trustStrategy) throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException, KeyManagementException {
  if (algorithm == null) {
    algorithm=TLS;
  }
  KeyManagerFactory kmfactory=KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
  kmfactory.init(keystore,keystorePassword != null ? keystorePassword.toCharArray() : null);
  KeyManager[] keymanagers=kmfactory.getKeyManagers();
  TrustManagerFactory tmfactory=TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
  tmfactory.init(keystore);
  TrustManager[] trustmanagers=tmfactory.getTrustManagers();
  if (trustmanagers != null && trustStrategy != null) {
    for (int i=0; i < trustmanagers.length; i++) {
      TrustManager tm=trustmanagers[i];
      if (tm instanceof X509TrustManager) {
        trustmanagers[i]=new TrustManagerDecorator((X509TrustManager)tm,trustStrategy);
      }
    }
  }
  SSLContext sslcontext=SSLContext.getInstance(algorithm);
  sslcontext.init(keymanagers,trustmanagers,random);
  return sslcontext;
}
 

Example 50

From project subsonic_1, under directory /subsonic-android/src/net/sourceforge/subsonic/androidapp/service/ssl/.

Source file: SSLSocketFactory.java

  19 
vote

private static SSLContext createSSLContext(String algorithm,final KeyStore keystore,final String keystorePassword,final KeyStore truststore,final SecureRandom random,final TrustStrategy trustStrategy) throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException, KeyManagementException {
  if (algorithm == null) {
    algorithm=TLS;
  }
  KeyManagerFactory kmfactory=KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
  kmfactory.init(keystore,keystorePassword != null ? keystorePassword.toCharArray() : null);
  KeyManager[] keymanagers=kmfactory.getKeyManagers();
  TrustManagerFactory tmfactory=TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
  tmfactory.init(keystore);
  TrustManager[] trustmanagers=tmfactory.getTrustManagers();
  if (trustmanagers != null && trustStrategy != null) {
    for (int i=0; i < trustmanagers.length; i++) {
      TrustManager tm=trustmanagers[i];
      if (tm instanceof X509TrustManager) {
        trustmanagers[i]=new TrustManagerDecorator((X509TrustManager)tm,trustStrategy);
      }
    }
  }
  SSLContext sslcontext=SSLContext.getInstance(algorithm);
  sslcontext.init(keymanagers,trustmanagers,random);
  return sslcontext;
}
 

Example 51

From project subsonic_2, under directory /subsonic-android/src/net/sourceforge/subsonic/androidapp/service/ssl/.

Source file: SSLSocketFactory.java

  19 
vote

private static SSLContext createSSLContext(String algorithm,final KeyStore keystore,final String keystorePassword,final KeyStore truststore,final SecureRandom random,final TrustStrategy trustStrategy) throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException, KeyManagementException {
  if (algorithm == null) {
    algorithm=TLS;
  }
  KeyManagerFactory kmfactory=KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
  kmfactory.init(keystore,keystorePassword != null ? keystorePassword.toCharArray() : null);
  KeyManager[] keymanagers=kmfactory.getKeyManagers();
  TrustManagerFactory tmfactory=TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
  tmfactory.init(keystore);
  TrustManager[] trustmanagers=tmfactory.getTrustManagers();
  if (trustmanagers != null && trustStrategy != null) {
    for (int i=0; i < trustmanagers.length; i++) {
      TrustManager tm=trustmanagers[i];
      if (tm instanceof X509TrustManager) {
        trustmanagers[i]=new TrustManagerDecorator((X509TrustManager)tm,trustStrategy);
      }
    }
  }
  SSLContext sslcontext=SSLContext.getInstance(algorithm);
  sslcontext.init(keymanagers,trustmanagers,random);
  return sslcontext;
}
 

Example 52

From project Supersonic, under directory /subsonic-android/src/net/sourceforge/subsonic/androidapp/service/ssl/.

Source file: SSLSocketFactory.java

  19 
vote

private static SSLContext createSSLContext(String algorithm,final KeyStore keystore,final String keystorePassword,final KeyStore truststore,final SecureRandom random,final TrustStrategy trustStrategy) throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException, KeyManagementException {
  if (algorithm == null) {
    algorithm=TLS;
  }
  KeyManagerFactory kmfactory=KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
  kmfactory.init(keystore,keystorePassword != null ? keystorePassword.toCharArray() : null);
  KeyManager[] keymanagers=kmfactory.getKeyManagers();
  TrustManagerFactory tmfactory=TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
  tmfactory.init(keystore);
  TrustManager[] trustmanagers=tmfactory.getTrustManagers();
  if (trustmanagers != null && trustStrategy != null) {
    for (int i=0; i < trustmanagers.length; i++) {
      TrustManager tm=trustmanagers[i];
      if (tm instanceof X509TrustManager) {
        trustmanagers[i]=new TrustManagerDecorator((X509TrustManager)tm,trustStrategy);
      }
    }
  }
  SSLContext sslcontext=SSLContext.getInstance(algorithm);
  sslcontext.init(keymanagers,trustmanagers,random);
  return sslcontext;
}
 

Example 53

From project SVQCOM, under directory /Core/src/com/ushahidi/android/app/net/.

Source file: MainHttpClient.java

  19 
vote

public MainHttpClient(Context context){
  httpParameters=new BasicHttpParams();
  httpParameters.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS,1);
  httpParameters.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE,new ConnPerRouteBean(1));
  httpParameters.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE,false);
  HttpProtocolParams.setVersion(httpParameters,HttpVersion.HTTP_1_1);
  HttpProtocolParams.setContentCharset(httpParameters,"utf8");
  HttpConnectionParams.setConnectionTimeout(httpParameters,timeoutConnection);
  HttpConnectionParams.setSoTimeout(httpParameters,timeoutSocket);
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  try {
    schemeRegistry.register(new Scheme("https",new TrustedSocketFactory(Preferences.domain,false),443));
  }
 catch (  KeyManagementException e) {
    e.printStackTrace();
  }
catch (  NoSuchAlgorithmException e) {
    e.printStackTrace();
  }
  httpClient=new DefaultHttpClient(new ThreadSafeClientConnManager(httpParameters,schemeRegistry),httpParameters);
}
 

Example 54

From project SWADroid, under directory /SWADroid/src/es/ugr/swad/swadroid/ssl/.

Source file: SecureConnection.java

  19 
vote

/** 
 * Bypasses certificate verification in application.
 * @throws NoSuchAlgorithmException
 * @throws KeyManagementException
 */
public static void initSecureConnection() throws NoSuchAlgorithmException, KeyManagementException {
  SSLContext sc=SSLContext.getInstance("TLS");
  sc.init(null,untrustedTM,new SecureRandom());
  HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
  HttpsURLConnection.setDefaultHostnameVerifier(untrustedHN);
}
 

Example 55

From project thumbslug, under directory /src/main/java/org/candlepin/thumbslug/ssl/.

Source file: SslContextFactory.java

  19 
vote

public static SSLContext getCandlepinClientContext(){
  SSLContext clientContext=null;
  String algorithm=Security.getProperty("ssl.KeyManagerFactory.algorithm");
  if (algorithm == null) {
    algorithm="SunX509";
  }
  try {
    clientContext=SSLContext.getInstance(PROTOCOL);
    clientContext.init(null,ClientContextTrustManagerFactory.getTrustManagers(),null);
  }
 catch (  NoSuchAlgorithmException e) {
    throw new Error("Failed to initialize the thumbslug to candlepin ssl context",e);
  }
catch (  KeyManagementException e) {
    throw new Error("Failed to initialize the thumbslug to candlepin ssl context",e);
  }
  return clientContext;
}
 

Example 56

From project TiVo-Commander, under directory /src/com/arantius/tivocommander/rpc/.

Source file: MindRpc.java

  19 
vote

private static SSLSocketFactory createSocketFactory(final Activity originActivity){
  final String password=readPassword(originActivity);
  try {
    KeyStore keyStore=KeyStore.getInstance("PKCS12");
    KeyManagerFactory fac=KeyManagerFactory.getInstance("X509");
    InputStream keyInput=originActivity.getResources().openRawResource(R.raw.cdata);
    keyStore.load(keyInput,password.toCharArray());
    keyInput.close();
    fac.init(keyStore,password.toCharArray());
    SSLContext context=SSLContext.getInstance("TLS");
    TrustManager[] tm=new TrustManager[]{new AlwaysTrustManager()};
    context.init(fac.getKeyManagers(),tm,new SecureRandom());
    return context.getSocketFactory();
  }
 catch (  CertificateException e) {
    Log.e(LOG_TAG,"createSocketFactory: CertificateException!",e);
  }
catch (  IOException e) {
    Log.e(LOG_TAG,"createSocketFactory: IOException!",e);
  }
catch (  KeyManagementException e) {
    Log.e(LOG_TAG,"createSocketFactory: KeyManagementException!",e);
  }
catch (  KeyStoreException e) {
    Log.e(LOG_TAG,"createSocketFactory: KeyStoreException!",e);
  }
catch (  NoSuchAlgorithmException e) {
    Log.e(LOG_TAG,"createSocketFactory: NoSuchAlgorithmException!",e);
  }
catch (  UnrecoverableKeyException e) {
    Log.e(LOG_TAG,"createSocketFactory: UnrecoverableKeyException!",e);
  }
  return null;
}
 

Example 57

From project twitter-2-weibo, under directory /core/src/main/java/weibo4j/model/.

Source file: MySSLSocketFactory.java

  19 
vote

private SSLContext createSSLContext(){
  SSLContext sslcontext=null;
  try {
    sslcontext=SSLContext.getInstance("SSL");
    sslcontext.init(null,new TrustManager[]{new TrustAnyTrustManager()},new java.security.SecureRandom());
  }
 catch (  NoSuchAlgorithmException e) {
    e.printStackTrace();
  }
catch (  KeyManagementException e) {
    e.printStackTrace();
  }
  return sslcontext;
}
 

Example 58

From project upm-android, under directory /src/com/u17od/upm/transport/.

Source file: HTTPTransport.java

  19 
vote

private HttpURLConnection getConnection(URL url) throws TransportException {
  HttpURLConnection conn;
  try {
    conn=(HttpURLConnection)url.openConnection();
    if (conn instanceof HttpsURLConnection) {
      if (certFile.exists() && sslFactory == null) {
        buildSSLFactory();
      }
      if (sslFactory != null) {
        ((HttpsURLConnection)conn).setSSLSocketFactory(sslFactory);
        if (trustedHost != null) {
          ((HttpsURLConnection)conn).setHostnameVerifier(new HostnameVerifier(){
            @Override public boolean verify(            String hostname,            SSLSession session){
              return hostname.equals(trustedHost);
            }
          }
);
        }
      }
    }
  }
 catch (  IOException e) {
    throw new TransportException(e);
  }
catch (  KeyManagementException e) {
    throw new TransportException(e);
  }
catch (  CertificateException e) {
    throw new TransportException(e);
  }
catch (  KeyStoreException e) {
    throw new TransportException(e);
  }
catch (  NoSuchAlgorithmException e) {
    throw new TransportException(e);
  }
  return conn;
}
 

Example 59

From project Ushahidi_Android, under directory /Core/src/com/ushahidi/android/app/net/.

Source file: MainHttpClient.java

  19 
vote

public MainHttpClient(Context context){
  this.context=context;
  httpParameters=new BasicHttpParams();
  httpParameters.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS,1);
  httpParameters.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE,new ConnPerRouteBean(1));
  httpParameters.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE,false);
  HttpProtocolParams.setVersion(httpParameters,HttpVersion.HTTP_1_1);
  HttpProtocolParams.setContentCharset(httpParameters,"utf8");
  HttpConnectionParams.setConnectionTimeout(httpParameters,timeoutConnection);
  HttpConnectionParams.setSoTimeout(httpParameters,timeoutSocket);
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  try {
    schemeRegistry.register(new Scheme("https",new TrustedSocketFactory(Preferences.domain,false),443));
  }
 catch (  KeyManagementException e) {
    e.printStackTrace();
  }
catch (  NoSuchAlgorithmException e) {
    e.printStackTrace();
  }
  httpClient=new DefaultHttpClient(new ThreadSafeClientConnManager(httpParameters,schemeRegistry),httpParameters);
  httpClient.setParams(httpParameters);
}
 

Example 60

From project Vega, under directory /platform/com.subgraph.vega.http.requests/src/com/subgraph/vega/internal/http/requests/.

Source file: AbstractHttpClientFactory.java

  19 
vote

protected static SchemeRegistry createSchemeRegistry(){
  final SchemeRegistry sr=new SchemeRegistry();
  sr.register(new Scheme("http",80,PlainSocketFactory.getSocketFactory()));
  SSLContext ctx;
  try {
    ctx=SSLContext.getInstance("TLS");
    X509TrustManager tm=new X509TrustManager(){
      public void checkClientTrusted(      X509Certificate[] xcs,      String string) throws CertificateException {
      }
      public void checkServerTrusted(      X509Certificate[] xcs,      String string) throws CertificateException {
      }
      public X509Certificate[] getAcceptedIssuers(){
        return null;
      }
    }
;
    ctx.init(null,new X509TrustManager[]{tm},null);
    SSLSocketFactory ssf=new SSLSocketFactory(ctx,SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    sr.register(new Scheme("https",443,ssf));
  }
 catch (  NoSuchAlgorithmException e) {
    e.printStackTrace();
  }
catch (  KeyManagementException e) {
    e.printStackTrace();
  }
  return sr;
}
 

Example 61

From project Weave, under directory /JTDS_SqlServerDriver/src/main/net/sourceforge/jtds/ssl/.

Source file: SocketFactories.java

  19 
vote

/** 
 * Returns an SSLSocketFactory whose sockets will not authenticate the server.
 * @return an <code>SSLSocketFactory</code>
 */
private static SSLSocketFactory factory() throws NoSuchAlgorithmException, KeyManagementException {
  if (factorySingleton == null) {
    SSLContext ctx=SSLContext.getInstance("TLS");
    ctx.init(null,trustManagers(),null);
    factorySingleton=ctx.getSocketFactory();
  }
  return factorySingleton;
}
 

Example 62

From project Wordpress-Android-App, under directory /src/org/wordpress/android/util/.

Source file: TrustAllSSLSocketFactory.java

  19 
vote

public TrustAllSSLSocketFactory() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException {
  super(null);
  try {
    SSLContext sslcontext=SSLContext.getInstance("TLS");
    sslcontext.init(null,new TrustManager[]{new TrustAllManager()},null);
    factory=sslcontext.getSocketFactory();
    setHostnameVerifier(new AllowAllHostnameVerifier());
  }
 catch (  Exception ex) {
  }
}
 

Example 63

From project Xebia-vCloud, under directory /src/main/java/fr/xebia/vcloud/.

Source file: FakeSSLSocketFactory.java

  19 
vote

public static SSLSocketFactory getInstance() throws KeyManagementException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException {
  return new SSLSocketFactory(new TrustStrategy(){
    public boolean isTrusted(    final X509Certificate[] chain,    final String authType) throws CertificateException {
      return true;
    }
  }
,SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
}
 

Example 64

From project xnio_1, under directory /api/src/main/java/org/xnio/ssl/.

Source file: JsseSslUtils.java

  19 
vote

/** 
 * Create a new SSL context, configured from an option map and the given parameters.
 * @param keyManagers the key managers to use, or {@code null} to configure from the option map
 * @param trustManagers the trust managers to use, or {@code null} to configure from the option map
 * @param secureRandom the secure RNG to use, or {@code null} to choose a system default
 * @param optionMap the SSL context options
 * @return a new context
 * @throws NoSuchProviderException if there is no matching provider
 * @throws NoSuchAlgorithmException if there is no matching algorithm
 * @throws KeyManagementException if the context initialization fails
 */
public static SSLContext createSSLContext(KeyManager[] keyManagers,TrustManager[] trustManagers,SecureRandom secureRandom,OptionMap optionMap) throws NoSuchAlgorithmException, NoSuchProviderException, KeyManagementException {
  final String provider=optionMap.get(Options.SSL_PROVIDER);
  final String protocol=optionMap.get(Options.SSL_PROTOCOL);
  final SSLContext sslContext;
  if (protocol == null) {
    return SSLContext.getDefault();
  }
 else   if (provider == null) {
    sslContext=SSLContext.getInstance(protocol);
  }
 else {
    sslContext=SSLContext.getInstance(protocol,provider);
  }
  if (keyManagers == null) {
    final Sequence<Class<? extends KeyManager>> keyManagerClasses=optionMap.get(Options.SSL_JSSE_KEY_MANAGER_CLASSES);
    if (keyManagerClasses != null) {
      final int size=keyManagerClasses.size();
      keyManagers=new KeyManager[size];
      for (int i=0; i < size; i++) {
        keyManagers[i]=instantiate(keyManagerClasses.get(i));
      }
    }
  }
  if (trustManagers == null) {
    final Sequence<Class<? extends TrustManager>> trustManagerClasses=optionMap.get(Options.SSL_JSSE_TRUST_MANAGER_CLASSES);
    if (trustManagerClasses != null) {
      final int size=trustManagerClasses.size();
      trustManagers=new TrustManager[size];
      for (int i=0; i < size; i++) {
        trustManagers[i]=instantiate(trustManagerClasses.get(i));
      }
    }
  }
  sslContext.init(keyManagers,trustManagers,secureRandom);
  sslContext.getClientSessionContext().setSessionCacheSize(optionMap.get(Options.SSL_CLIENT_SESSION_CACHE_SIZE,0));
  sslContext.getClientSessionContext().setSessionTimeout(optionMap.get(Options.SSL_CLIENT_SESSION_TIMEOUT,0));
  sslContext.getServerSessionContext().setSessionCacheSize(optionMap.get(Options.SSL_SERVER_SESSION_CACHE_SIZE,0));
  sslContext.getServerSessionContext().setSessionTimeout(optionMap.get(Options.SSL_SERVER_SESSION_TIMEOUT,0));
  return sslContext;
}
 

Example 65

From project xqsync, under directory /src/java/com/marklogic/ps/.

Source file: Connection.java

  19 
vote

/** 
 * @param _uris
 * @throws XccConfigException
 * @throws NoSuchAlgorithmException
 * @throws KeyManagementException
 */
private void init(URI[] _uris) throws XccConfigException, KeyManagementException, NoSuchAlgorithmException {
  if (null == _uris || 1 > _uris.length) {
    throw new NullPointerException("must supply uris");
  }
  uri=new URI[_uris.length];
  cs=new ContentSource[_uris.length];
  for (int i=0; i < _uris.length; i++) {
    if (null == _uris[i].getHost()) {
      throw new UnimplementedFeatureException("bad URI: cannot parse host from " + _uris[i]);
    }
    uri[i]=_uris[i];
    boolean ssl=uri[i].getScheme().equals("xccs");
    cs[i]=ssl ? ContentSourceFactory.newContentSource(uri[i],getSecurityOptions()) : ContentSourceFactory.newContentSource(uri[i]);
  }
}