1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.kuali.mobility.push.factory;
16
17 import java.security.KeyStore;
18
19 import javax.net.ssl.KeyManagerFactory;
20 import javax.net.ssl.SSLContext;
21 import javax.net.ssl.SSLSocket;
22 import javax.net.ssl.SSLSocketFactory;
23 import javax.net.ssl.TrustManagerFactory;
24
25 import org.apache.commons.pool.PoolableObjectFactory;
26 import org.springframework.beans.factory.annotation.Value;
27 import org.springframework.core.io.Resource;
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 public class iOSFeedbackConnectionFactory implements PoolableObjectFactory<SSLSocket>{
48
49
50 @Value("${push.apple.feedback.host}")
51 private String host = null;
52
53
54 @Value("${push.apple.feedback.port}")
55 private int port;
56
57
58 @Value("${push.apple.key.file}")
59 private Resource certPath;
60
61
62 @Value("${push.apple.key.passphrase}")
63 private String certPassword;
64
65
66
67
68
69
70
71 @Override
72 public SSLSocket makeObject() throws Exception {
73 SSLSocket socket = null;
74 KeyStore keyStore = KeyStore.getInstance("PKCS12");
75 keyStore.load(certPath.getInputStream(), certPassword.toCharArray());
76 KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("sunx509");
77 keyManagerFactory.init(keyStore, certPassword.toCharArray());
78 TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("sunx509");
79 trustManagerFactory.init(keyStore);
80 SSLContext sslCtx = SSLContext.getInstance("TLS");
81 sslCtx.init(keyManagerFactory.getKeyManagers(), null, null);
82 SSLSocketFactory sslSocketFactory = sslCtx.getSocketFactory();
83 socket = (SSLSocket)sslSocketFactory.createSocket(host, port);
84 socket.startHandshake();
85 return socket;
86 }
87
88
89
90
91
92 @Override
93 public void destroyObject(SSLSocket obj) throws Exception {
94 if (obj == null){
95
96
97 return;
98 }
99 try{
100 obj.close();
101 }
102 catch (Exception e) {
103
104 }
105 }
106
107
108
109
110
111 @Override
112 public boolean validateObject(SSLSocket obj) {
113 if (obj == null){
114 return false;
115 }
116 return obj.isConnected() && !obj.isClosed();
117 }
118
119
120
121
122
123 @Override
124 public void activateObject(SSLSocket obj) throws Exception {
125
126 }
127
128
129
130
131
132 @Override
133 public void passivateObject(SSLSocket obj) throws Exception {
134
135 }
136 }