[Assorted-commits] SF.net SVN: assorted:[1462] sandbox/trunk/src/java/nettytest
Brought to you by:
yangzhang
From: <yan...@us...> - 2009-07-22 02:17:04
|
Revision: 1462 http://assorted.svn.sourceforge.net/assorted/?rev=1462&view=rev Author: yangzhang Date: 2009-07-22 02:16:59 +0000 (Wed, 22 Jul 2009) Log Message: ----------- load passphrase and certs from files; added dummy cert resources for unit tests Modified Paths: -------------- sandbox/trunk/src/java/nettytest/pom.xml sandbox/trunk/src/java/nettytest/src/main/java/Server.java Added Paths: ----------- sandbox/trunk/src/java/nettytest/src/test/resources/server.p12 sandbox/trunk/src/java/nettytest/src/test/resources/server.pass Modified: sandbox/trunk/src/java/nettytest/pom.xml =================================================================== --- sandbox/trunk/src/java/nettytest/pom.xml 2009-07-22 01:44:24 UTC (rev 1461) +++ sandbox/trunk/src/java/nettytest/pom.xml 2009-07-22 02:16:59 UTC (rev 1462) @@ -4,17 +4,28 @@ <artifactId>nettytest</artifactId> <version>0.0.1-SNAPSHOT</version> <repositories> - <repository> - <id>JBOSS</id> - <name>JBoss Repository</name> - <url>http://repository.jboss.org/maven2/</url> - </repository> + <repository> + <id>JBOSS</id> + <name>JBoss Repository</name> + <url>http://repository.jboss.org/maven2/</url> + </repository> </repositories> <dependencies> - <dependency> - <groupId>org.jboss.netty</groupId> - <artifactId>netty</artifactId> - <version>3.1.0.BETA3</version> - </dependency> + <dependency> + <groupId>org.jboss.netty</groupId> + <artifactId>netty</artifactId> + <version>3.1.0.BETA3</version> + </dependency> </dependencies> -</project> \ No newline at end of file + <build> + <plugins> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>6</source> + <target>6</target> + </configuration> + </plugin> + </plugins> + </build> +</project> Modified: sandbox/trunk/src/java/nettytest/src/main/java/Server.java =================================================================== --- sandbox/trunk/src/java/nettytest/src/main/java/Server.java 2009-07-22 01:44:24 UTC (rev 1461) +++ sandbox/trunk/src/java/nettytest/src/main/java/Server.java 2009-07-22 02:16:59 UTC (rev 1462) @@ -1,4 +1,5 @@ import java.io.FileInputStream; +import java.io.InputStreamReader; import java.net.InetSocketAddress; import java.security.KeyStore; import java.util.concurrent.Executors; @@ -21,17 +22,41 @@ public class Server extends Common { - String pass = "eUySvp2phM2Wk"; - String certPath = "C:/temp/server.p12"; + String passPath; + String certPath; + public Server(String passPath, String certPath) { + this.passPath = passPath; + this.certPath = certPath; + } + public SSLEngine getSslEngine() throws Exception { + // Read the password. + InputStreamReader passf = new InputStreamReader(new FileInputStream(passPath)); + char[] pass; + try { + StringBuffer sb = new StringBuffer(); + char[] chunk = new char[4096]; + while (true) { + int nread = passf.read(chunk, 0, chunk.length); + if (nread < 0) break; + sb.append(chunk, 0, nread); + } + String s = sb.toString(); + if (s.charAt(s.length() - 1) == '\n') + s = s.substring(0, s.length() - 1); + pass = s.toCharArray(); + } finally { + passf.close(); + } + // Load our Java key store. KeyStore ks = KeyStore.getInstance("pkcs12"); - ks.load(new FileInputStream(certPath), pass.toCharArray()); + ks.load(new FileInputStream(certPath), pass); // Like ssh-agent. KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509"); - kmf.init(ks, pass.toCharArray()); + kmf.init(ks, pass); // Create the SSL context. SSLContext ctx = SSLContext.getInstance("TLS"); @@ -43,7 +68,7 @@ } public static void main(String[] args) throws Exception { - Server server = new Server(); + Server server = new Server(args[0], args[1]); server.call(); } @@ -84,3 +109,5 @@ } } + +// vim: et sw=4 ts=4 Added: sandbox/trunk/src/java/nettytest/src/test/resources/server.p12 =================================================================== (Binary files differ) Property changes on: sandbox/trunk/src/java/nettytest/src/test/resources/server.p12 ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: sandbox/trunk/src/java/nettytest/src/test/resources/server.pass =================================================================== --- sandbox/trunk/src/java/nettytest/src/test/resources/server.pass (rev 0) +++ sandbox/trunk/src/java/nettytest/src/test/resources/server.pass 2009-07-22 02:16:59 UTC (rev 1462) @@ -0,0 +1 @@ +IQgmo1UTNAJnk This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |