You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@jakarta.apache.org by se...@apache.org on 2010/07/06 15:14:38 UTC

svn commit: r960893 - /jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/protocol/LocalTrustStoreSSLSocketFactory.java

Author: sebb
Date: Tue Jul  6 13:14:37 2010
New Revision: 960893

URL: http://svn.apache.org/viewvc?rev=960893&view=rev
Log:
Local truststore socket factory

Added:
    jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/protocol/LocalTrustStoreSSLSocketFactory.java   (with props)

Added: jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/protocol/LocalTrustStoreSSLSocketFactory.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/protocol/LocalTrustStoreSSLSocketFactory.java?rev=960893&view=auto
==============================================================================
--- jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/protocol/LocalTrustStoreSSLSocketFactory.java (added)
+++ jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/protocol/LocalTrustStoreSSLSocketFactory.java Tue Jul  6 13:14:37 2010
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.jmeter.protocol.smtp.sampler.protocol;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.security.KeyStore;
+import java.security.SecureRandom;
+
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.TrustManagerFactory;
+
+import org.apache.commons.io.IOUtils;
+
+/**
+ * This class implements an SSLSocketFactory which supports a local truststore.
+ */
+public class LocalTrustStoreSSLSocketFactory extends SSLSocketFactory  {
+
+    private final SSLSocketFactory factory;
+
+    public LocalTrustStoreSSLSocketFactory(File truststore){
+        SSLContext sslcontext = null;
+        try {
+            KeyStore ks = KeyStore.getInstance("JKS"); // $NON-NLS-1$
+            FileInputStream stream = null;
+            try {
+                stream = new FileInputStream(truststore);
+                ks.load(stream, null);
+            } finally {
+                IOUtils.closeQuietly(stream);
+            }
+
+            TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
+            tmf.init(ks);
+            TrustManager[] trustmanagers = tmf.getTrustManagers();
+            sslcontext = SSLContext.getInstance("TLS"); // $NON-NLS-1$
+            sslcontext.init( null, trustmanagers, new SecureRandom());
+        } catch (Exception e) {
+            throw new RuntimeException("Could not create the SSL context",e);
+        }
+        factory = sslcontext.getSocketFactory();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Socket createSocket( Socket socket, String s, int i, boolean
+            flag)
+            throws IOException {
+        return factory.createSocket( socket, s, i, flag);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Socket createSocket( InetAddress inaddr, int i,
+            InetAddress inaddr1, int j) throws IOException {
+        return factory.createSocket( inaddr, i, inaddr1, j);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Socket createSocket( InetAddress inaddr, int i) throws
+            IOException {
+        return factory.createSocket( inaddr, i);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Socket createSocket( String s, int i, InetAddress inaddr, int j)
+    throws IOException {
+        return factory.createSocket( s, i, inaddr, j);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Socket createSocket( String s, int i) throws IOException {
+        return factory.createSocket( s, i);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Socket createSocket() throws IOException {
+        return factory.createSocket();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String[] getDefaultCipherSuites() {
+        return factory.getSupportedCipherSuites();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String[] getSupportedCipherSuites() {
+        return factory.getSupportedCipherSuites();
+    }
+}
\ No newline at end of file

Propchange: jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/protocol/LocalTrustStoreSSLSocketFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/protocol/LocalTrustStoreSSLSocketFactory.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@jakarta.apache.org
For additional commands, e-mail: notifications-help@jakarta.apache.org