1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package goldengate.commandexec.ssl.server;
22
23 import goldengate.commandexec.utils.LocalExecDefaultResult;
24 import goldengate.common.crypto.ssl.GgSecureKeyStore;
25 import goldengate.common.crypto.ssl.GgSslContextFactory;
26 import goldengate.common.logging.GgSlf4JLoggerFactory;
27
28 import java.net.InetAddress;
29 import java.net.InetSocketAddress;
30 import java.util.concurrent.ExecutorService;
31 import java.util.concurrent.Executors;
32
33 import org.jboss.netty.bootstrap.ServerBootstrap;
34 import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
35 import org.jboss.netty.logging.InternalLoggerFactory;
36
37
38
39
40
41 public class LocalExecSslServer {
42
43 static ExecutorService threadPool;
44 static ExecutorService threadPool2;
45
46
47
48
49
50
51
52
53
54
55
56
57 public static void main(String[] args) throws Exception {
58 InternalLoggerFactory.setDefaultFactory(new GgSlf4JLoggerFactory(null));
59 int port = 9999;
60 InetAddress addr;
61 long delay = LocalExecDefaultResult.MAXWAITPROCESS;
62 String keyStoreFilename, keyStorePasswd, keyPassword;
63 String trustStoreFilename = null, trustStorePasswd = null;
64 byte []loop = {127,0,0,1};
65 addr = InetAddress.getByAddress(loop);
66 if (args.length >=3) {
67 keyStoreFilename = args[0];
68 keyStorePasswd = args[1];
69 keyPassword = args[2];
70 if (args.length >= 5) {
71 trustStoreFilename = args[3];
72 trustStorePasswd = args[4];
73 if (args.length >= 7) {
74 addr = InetAddress.getByName(args[5]);
75 port = Integer.parseInt(args[6]);
76 if (args.length > 7) {
77 delay = Long.parseLong(args[7]);
78 }
79 }
80 }
81 } else {
82 System.err.println("Need at least 3 arguments: Filename KeyStorePswd KeyPswd");
83 return;
84 }
85 threadPool = Executors.newCachedThreadPool();
86 threadPool2 = Executors.newCachedThreadPool();
87
88 ServerBootstrap bootstrap = new ServerBootstrap(
89 new NioServerSocketChannelFactory(threadPool, threadPool2));
90
91 GgSecureKeyStore ggSecureKeyStore =
92 new GgSecureKeyStore(keyStoreFilename, keyStorePasswd, keyPassword);
93 if (trustStoreFilename != null) {
94
95 ggSecureKeyStore.initTrustStore(trustStoreFilename, trustStorePasswd, true);
96 } else {
97 ggSecureKeyStore.initEmptyTrustStore();
98 }
99 GgSslContextFactory ggSslContextFactory =
100 new GgSslContextFactory(ggSecureKeyStore, true);
101
102 bootstrap.setPipelineFactory(
103 new LocalExecSslServerPipelineFactory(ggSslContextFactory, delay));
104
105
106 bootstrap.bind(new InetSocketAddress(addr, port));
107 }
108 }