-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTLSSession.java
More file actions
186 lines (147 loc) · 4.46 KB
/
Copy pathTLSSession.java
File metadata and controls
186 lines (147 loc) · 4.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import java.security.Principal;
import java.security.cert.Certificate;
import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSessionContext;
import javax.security.cert.X509Certificate;
import org.bouncycastle.crypto.tls.CipherSuite;
public class TLSSession implements SSLSession {
private Certificate[] peerCertArray;
protected TLSClient tlsClient;
private long created;
public TLSSession(TLSClient tlsClient) {
super();
created = System.currentTimeMillis();
this.tlsClient = tlsClient;
}
public TLSClient getTlsClient() {
return tlsClient;
}
public void setTlsClient(TLSClient tlsClient) {
this.tlsClient = tlsClient;
}
/**
* peerCertArray を取得します
*
* @return peerCertArray
*/
public Certificate[] getPeerCertArray() {
return peerCertArray;
}
/**
* peerCertArray を設定します
*
* @param peerCertArray
*/
public void setPeerCertArray(Certificate[] peerCertArray) {
this.peerCertArray = peerCertArray;
}
@Override
public int getApplicationBufferSize() {
return 0;
}
@Override
public String getCipherSuite() {
switch (this.tlsClient.getSelectedCipherSuite()) {
case CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256:
return "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256";
case CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256:
return "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256";
case CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA:
return "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA";
case CipherSuite.TLS_RSA_WITH_AES_128_GCM_SHA256:
return "TLS_RSA_WITH_AES_128_GCM_SHA256";
case CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA256:
return "TLS_RSA_WITH_AES_128_CBC_SHA256";
case CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA:
return "TLS_RSA_WITH_AES_128_CBC_SHA";
default:
throw new UnsupportedOperationException();
}
}
@Override
public long getCreationTime() {
return created;
}
@Override
public byte[] getId() {
return this.tlsClient.getSession().getSessionID();
}
@Override
public long getLastAccessedTime() {
return System.currentTimeMillis();
}
@Override
public Certificate[] getLocalCertificates() {
throw new UnsupportedOperationException();
}
@Override
public Principal getLocalPrincipal() {
throw new UnsupportedOperationException();
}
@Override
public int getPacketBufferSize() {
return 0;
}
@Override
public X509Certificate[] getPeerCertificateChain() throws SSLPeerUnverifiedException {
return null;
}
@Override
public Certificate[] getPeerCertificates() throws SSLPeerUnverifiedException {
return peerCertArray;
}
@Override
public String getPeerHost() {
return this.tlsClient.getHost();
}
@Override
public int getPeerPort() {
return this.tlsClient.getPort();
}
@Override
public Principal getPeerPrincipal() throws SSLPeerUnverifiedException {
return null;
}
@Override
public String getProtocol() {
switch (this.tlsClient.getProtocol().getFullVersion()) {
case 0x0301:
return "TLSv1";
case 0x0302:
return "TLSv1.1";
case 0x0303:
return "TLSv1.2";
default:
throw new IllegalStateException();
}
}
@Override
public SSLSessionContext getSessionContext() {
throw new UnsupportedOperationException();
}
@Override
public Object getValue(String paramString) {
throw new UnsupportedOperationException();
}
@Override
public String[] getValueNames() {
throw new UnsupportedOperationException();
}
@Override
public void invalidate() {
throw new UnsupportedOperationException();
}
@Override
public boolean isValid() {
throw new UnsupportedOperationException();
}
@Override
public void putValue(String paramString, Object paramObject) {
throw new UnsupportedOperationException();
}
@Override
public void removeValue(String paramString) {
throw new UnsupportedOperationException();
}
}