5360 |
11 Jun 10 |
nicklas |
1 |
/* |
5360 |
11 Jun 10 |
nicklas |
$Id: TestBioSource.java 5340 2010-05-10 06:15:00Z nicklas $ |
5360 |
11 Jun 10 |
nicklas |
3 |
|
5360 |
11 Jun 10 |
nicklas |
Copyright (C) 2005 Nicklas Nordborg |
5360 |
11 Jun 10 |
nicklas |
Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg |
5360 |
11 Jun 10 |
nicklas |
6 |
|
5360 |
11 Jun 10 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
5360 |
11 Jun 10 |
nicklas |
Available at http://base.thep.lu.se/ |
5360 |
11 Jun 10 |
nicklas |
9 |
|
5360 |
11 Jun 10 |
nicklas |
BASE is free software; you can redistribute it and/or |
5360 |
11 Jun 10 |
nicklas |
modify it under the terms of the GNU General Public License |
5360 |
11 Jun 10 |
nicklas |
as published by the Free Software Foundation; either version 3 |
5360 |
11 Jun 10 |
nicklas |
of the License, or (at your option) any later version. |
5360 |
11 Jun 10 |
nicklas |
14 |
|
5360 |
11 Jun 10 |
nicklas |
BASE is distributed in the hope that it will be useful, |
5360 |
11 Jun 10 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
5360 |
11 Jun 10 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5360 |
11 Jun 10 |
nicklas |
GNU General Public License for more details. |
5360 |
11 Jun 10 |
nicklas |
19 |
|
5360 |
11 Jun 10 |
nicklas |
You should have received a copy of the GNU General Public License |
5360 |
11 Jun 10 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
5360 |
11 Jun 10 |
nicklas |
22 |
*/ |
5360 |
11 Jun 10 |
nicklas |
23 |
import net.sf.basedb.core.*; |
5362 |
16 Jun 10 |
nicklas |
24 |
import net.sf.basedb.util.FileUtil; |
5360 |
11 Jun 10 |
nicklas |
25 |
|
5362 |
16 Jun 10 |
nicklas |
26 |
import java.io.ByteArrayOutputStream; |
5362 |
16 Jun 10 |
nicklas |
27 |
import java.io.FileInputStream; |
7352 |
28 Apr 17 |
nicklas |
28 |
import java.io.FileWriter; |
7352 |
28 Apr 17 |
nicklas |
29 |
import java.security.SecureRandom; |
7352 |
28 Apr 17 |
nicklas |
30 |
import java.security.cert.Certificate; |
5362 |
16 Jun 10 |
nicklas |
31 |
import java.security.cert.X509Certificate; |
7352 |
28 Apr 17 |
nicklas |
32 |
import java.util.Base64; |
5360 |
11 Jun 10 |
nicklas |
33 |
import java.util.Set; |
5360 |
11 Jun 10 |
nicklas |
34 |
|
7352 |
28 Apr 17 |
nicklas |
35 |
import javax.net.ssl.SSLContext; |
7352 |
28 Apr 17 |
nicklas |
36 |
import javax.net.ssl.SSLSocket; |
7352 |
28 Apr 17 |
nicklas |
37 |
import javax.net.ssl.SSLSocketFactory; |
7352 |
28 Apr 17 |
nicklas |
38 |
import javax.net.ssl.TrustManager; |
7352 |
28 Apr 17 |
nicklas |
39 |
import javax.net.ssl.X509TrustManager; |
7352 |
28 Apr 17 |
nicklas |
40 |
|
5360 |
11 Jun 10 |
nicklas |
41 |
public class TestFileServer |
5360 |
11 Jun 10 |
nicklas |
42 |
{ |
5360 |
11 Jun 10 |
nicklas |
43 |
|
5360 |
11 Jun 10 |
nicklas |
44 |
static boolean ok = true; |
5360 |
11 Jun 10 |
nicklas |
45 |
public static void main(String[] args) |
5360 |
11 Jun 10 |
nicklas |
46 |
{ |
5360 |
11 Jun 10 |
nicklas |
47 |
TestUtil.checkArgs(args); |
5360 |
11 Jun 10 |
nicklas |
48 |
TestUtil.begin(); |
5360 |
11 Jun 10 |
nicklas |
49 |
ok = test_all(); |
5360 |
11 Jun 10 |
nicklas |
50 |
TestUtil.stop(); |
5360 |
11 Jun 10 |
nicklas |
51 |
} |
5360 |
11 Jun 10 |
nicklas |
52 |
|
5360 |
11 Jun 10 |
nicklas |
53 |
static boolean test_all() |
5360 |
11 Jun 10 |
nicklas |
54 |
{ |
5360 |
11 Jun 10 |
nicklas |
55 |
write("++Testing file servers"); |
5360 |
11 Jun 10 |
nicklas |
56 |
write_header(); |
5360 |
11 Jun 10 |
nicklas |
// Standard tests: create, load, list |
7982 |
14 Jun 21 |
nicklas |
58 |
int id = test_create("base.thep.lu.se", "BASE trac site", "base", "base", "data/base.thep.lu.se.crt", null, null); |
5360 |
11 Jun 10 |
nicklas |
59 |
test_load(id); |
5360 |
11 Jun 10 |
nicklas |
60 |
test_list(-1); |
5360 |
11 Jun 10 |
nicklas |
61 |
|
5360 |
11 Jun 10 |
nicklas |
62 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
5360 |
11 Jun 10 |
nicklas |
// Standard test: Delete |
5360 |
11 Jun 10 |
nicklas |
64 |
test_delete(id); |
5360 |
11 Jun 10 |
nicklas |
65 |
write("++Testing file servers "+(ok ? "OK" : "Failed")+"\n"); |
5360 |
11 Jun 10 |
nicklas |
66 |
return ok; |
5360 |
11 Jun 10 |
nicklas |
67 |
} |
5360 |
11 Jun 10 |
nicklas |
68 |
|
5362 |
16 Jun 10 |
nicklas |
69 |
static int test_create(String name, String description, String username, String password, |
5362 |
16 Jun 10 |
nicklas |
70 |
String serverCertificateFile, String clientCertificateFile, String clientCertificatePassword) |
5360 |
11 Jun 10 |
nicklas |
71 |
{ |
5360 |
11 Jun 10 |
nicklas |
72 |
if (!TestUtil.hasPermission(Permission.CREATE, Item.FILESERVER)) return 0; |
5360 |
11 Jun 10 |
nicklas |
73 |
int id = 0; |
5360 |
11 Jun 10 |
nicklas |
74 |
DbControl dc = null; |
5360 |
11 Jun 10 |
nicklas |
75 |
try |
5360 |
11 Jun 10 |
nicklas |
76 |
{ |
5360 |
11 Jun 10 |
nicklas |
77 |
dc = TestUtil.getDbControl(); |
5360 |
11 Jun 10 |
nicklas |
78 |
FileServer fs = FileServer.getNew(dc); |
5360 |
11 Jun 10 |
nicklas |
79 |
fs.setName(name); |
5360 |
11 Jun 10 |
nicklas |
80 |
fs.setDescription(description); |
5360 |
11 Jun 10 |
nicklas |
81 |
fs.setUsername(username); |
5360 |
11 Jun 10 |
nicklas |
82 |
fs.setPassword(password); |
5362 |
16 Jun 10 |
nicklas |
83 |
if (serverCertificateFile != null) |
5362 |
16 Jun 10 |
nicklas |
84 |
{ |
7352 |
28 Apr 17 |
nicklas |
85 |
java.io.File certFile = new java.io.File(serverCertificateFile); |
7428 |
23 Nov 17 |
nicklas |
86 |
if (!certFile.exists() || (System.currentTimeMillis() - certFile.lastModified()) > 86400000) // replace if older than 1 day |
7352 |
28 Apr 17 |
nicklas |
87 |
{ |
7352 |
28 Apr 17 |
nicklas |
88 |
downloadCertificate(name, certFile); |
7352 |
28 Apr 17 |
nicklas |
89 |
} |
7352 |
28 Apr 17 |
nicklas |
90 |
|
5362 |
16 Jun 10 |
nicklas |
91 |
ByteArrayOutputStream out = new ByteArrayOutputStream(); |
7352 |
28 Apr 17 |
nicklas |
92 |
FileUtil.copy(new FileInputStream(certFile), out); |
5362 |
16 Jun 10 |
nicklas |
93 |
out.close(); |
5362 |
16 Jun 10 |
nicklas |
94 |
fs.setServerCertificate(out.toByteArray()); |
7290 |
31 Jan 17 |
nicklas |
95 |
fs.getServerX509Certificate().checkValidity(); |
5362 |
16 Jun 10 |
nicklas |
96 |
} |
5362 |
16 Jun 10 |
nicklas |
97 |
if (clientCertificateFile != null) |
5362 |
16 Jun 10 |
nicklas |
98 |
{ |
5362 |
16 Jun 10 |
nicklas |
99 |
ByteArrayOutputStream out = new ByteArrayOutputStream(); |
5362 |
16 Jun 10 |
nicklas |
100 |
FileUtil.copy(new FileInputStream(clientCertificateFile), out); |
5362 |
16 Jun 10 |
nicklas |
101 |
out.close(); |
5362 |
16 Jun 10 |
nicklas |
102 |
fs.setClientCertificate(out.toByteArray()); |
5362 |
16 Jun 10 |
nicklas |
103 |
fs.setClientCertificatePassword(clientCertificatePassword); |
7290 |
31 Jan 17 |
nicklas |
104 |
fs.getClientX509Certificate().checkValidity(); |
5362 |
16 Jun 10 |
nicklas |
105 |
} |
5360 |
11 Jun 10 |
nicklas |
106 |
dc.saveItem(fs); |
5360 |
11 Jun 10 |
nicklas |
107 |
dc.commit(); |
5360 |
11 Jun 10 |
nicklas |
108 |
id = fs.getId(); |
5360 |
11 Jun 10 |
nicklas |
109 |
write_item(0, fs); |
5360 |
11 Jun 10 |
nicklas |
110 |
write("--Create file server OK"); |
5360 |
11 Jun 10 |
nicklas |
111 |
} |
5360 |
11 Jun 10 |
nicklas |
112 |
catch (Throwable ex) |
5360 |
11 Jun 10 |
nicklas |
113 |
{ |
5360 |
11 Jun 10 |
nicklas |
114 |
write("--Create file server FAILED"); |
5360 |
11 Jun 10 |
nicklas |
115 |
ex.printStackTrace(); |
5360 |
11 Jun 10 |
nicklas |
116 |
ok = false; |
5360 |
11 Jun 10 |
nicklas |
117 |
} |
5360 |
11 Jun 10 |
nicklas |
118 |
finally |
5360 |
11 Jun 10 |
nicklas |
119 |
{ |
5360 |
11 Jun 10 |
nicklas |
120 |
if (dc != null) dc.close(); |
5360 |
11 Jun 10 |
nicklas |
121 |
} |
5360 |
11 Jun 10 |
nicklas |
122 |
return id; |
5360 |
11 Jun 10 |
nicklas |
123 |
} |
5360 |
11 Jun 10 |
nicklas |
124 |
|
5360 |
11 Jun 10 |
nicklas |
125 |
static void test_load(int id) |
5360 |
11 Jun 10 |
nicklas |
126 |
{ |
5360 |
11 Jun 10 |
nicklas |
127 |
if (id == 0) return; |
5360 |
11 Jun 10 |
nicklas |
128 |
DbControl dc = null; |
5360 |
11 Jun 10 |
nicklas |
129 |
try |
5360 |
11 Jun 10 |
nicklas |
130 |
{ |
5360 |
11 Jun 10 |
nicklas |
131 |
dc = TestUtil.getDbControl(); |
5360 |
11 Jun 10 |
nicklas |
132 |
FileServer fs = FileServer.getById(dc, id); |
5360 |
11 Jun 10 |
nicklas |
133 |
write_item(0, fs); |
5360 |
11 Jun 10 |
nicklas |
134 |
write("--Load file server OK"); |
5360 |
11 Jun 10 |
nicklas |
135 |
} |
5360 |
11 Jun 10 |
nicklas |
136 |
catch (Throwable ex) |
5360 |
11 Jun 10 |
nicklas |
137 |
{ |
5360 |
11 Jun 10 |
nicklas |
138 |
write("--Load file server FAILED"); |
5360 |
11 Jun 10 |
nicklas |
139 |
ex.printStackTrace(); |
5360 |
11 Jun 10 |
nicklas |
140 |
ok = false; |
5360 |
11 Jun 10 |
nicklas |
141 |
} |
5360 |
11 Jun 10 |
nicklas |
142 |
finally |
5360 |
11 Jun 10 |
nicklas |
143 |
{ |
5360 |
11 Jun 10 |
nicklas |
144 |
if (dc != null) dc.close(); |
5360 |
11 Jun 10 |
nicklas |
145 |
} |
5360 |
11 Jun 10 |
nicklas |
146 |
} |
5360 |
11 Jun 10 |
nicklas |
147 |
|
5360 |
11 Jun 10 |
nicklas |
148 |
static void test_list(int expectedResults) |
5360 |
11 Jun 10 |
nicklas |
149 |
{ |
5360 |
11 Jun 10 |
nicklas |
150 |
DbControl dc = null; |
5360 |
11 Jun 10 |
nicklas |
151 |
try |
5360 |
11 Jun 10 |
nicklas |
152 |
{ |
5360 |
11 Jun 10 |
nicklas |
153 |
dc = TestUtil.getDbControl(); |
5360 |
11 Jun 10 |
nicklas |
154 |
ItemResultList<FileServer> l = FileServer.getQuery().list(dc); |
5360 |
11 Jun 10 |
nicklas |
155 |
for (int i = 0; i<l.size(); i++) |
5360 |
11 Jun 10 |
nicklas |
156 |
{ |
5360 |
11 Jun 10 |
nicklas |
157 |
write_item(i, l.get(i)); |
5360 |
11 Jun 10 |
nicklas |
158 |
} |
5360 |
11 Jun 10 |
nicklas |
159 |
if (expectedResults >= 0 && expectedResults != l.size()) |
5360 |
11 Jun 10 |
nicklas |
160 |
{ |
5360 |
11 Jun 10 |
nicklas |
161 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
5360 |
11 Jun 10 |
nicklas |
162 |
} |
5360 |
11 Jun 10 |
nicklas |
163 |
write("--List file server OK ("+l.size()+")"); |
5360 |
11 Jun 10 |
nicklas |
164 |
} |
5360 |
11 Jun 10 |
nicklas |
165 |
catch (Throwable ex) |
5360 |
11 Jun 10 |
nicklas |
166 |
{ |
5360 |
11 Jun 10 |
nicklas |
167 |
write("--List file server FAILED"); |
5360 |
11 Jun 10 |
nicklas |
168 |
ex.printStackTrace(); |
5360 |
11 Jun 10 |
nicklas |
169 |
ok = false; |
5360 |
11 Jun 10 |
nicklas |
170 |
} |
5360 |
11 Jun 10 |
nicklas |
171 |
finally |
5360 |
11 Jun 10 |
nicklas |
172 |
{ |
5360 |
11 Jun 10 |
nicklas |
173 |
if (dc != null) dc.close(); |
5360 |
11 Jun 10 |
nicklas |
174 |
} |
5360 |
11 Jun 10 |
nicklas |
175 |
} |
5360 |
11 Jun 10 |
nicklas |
176 |
|
5360 |
11 Jun 10 |
nicklas |
177 |
static void test_delete(int id) |
5360 |
11 Jun 10 |
nicklas |
178 |
{ |
5360 |
11 Jun 10 |
nicklas |
179 |
if (id == 0) return; |
5360 |
11 Jun 10 |
nicklas |
180 |
DbControl dc = null; |
5360 |
11 Jun 10 |
nicklas |
181 |
try |
5360 |
11 Jun 10 |
nicklas |
182 |
{ |
5360 |
11 Jun 10 |
nicklas |
183 |
dc = TestUtil.getDbControl(); |
5360 |
11 Jun 10 |
nicklas |
184 |
FileServer fs = FileServer.getById(dc, id); |
5360 |
11 Jun 10 |
nicklas |
185 |
dc.deleteItem(fs); |
5360 |
11 Jun 10 |
nicklas |
186 |
Set<ItemProxy> using = fs.getUsingItems(); |
5360 |
11 Jun 10 |
nicklas |
187 |
if (using.size() > 0) |
5360 |
11 Jun 10 |
nicklas |
188 |
{ |
5360 |
11 Jun 10 |
nicklas |
189 |
throw new BaseException(fs + " is used by " + using); |
5360 |
11 Jun 10 |
nicklas |
190 |
} |
5360 |
11 Jun 10 |
nicklas |
191 |
dc.commit(); |
5360 |
11 Jun 10 |
nicklas |
192 |
write("--Delete file server OK"); |
5360 |
11 Jun 10 |
nicklas |
193 |
} |
5360 |
11 Jun 10 |
nicklas |
194 |
catch (Throwable ex) |
5360 |
11 Jun 10 |
nicklas |
195 |
{ |
5360 |
11 Jun 10 |
nicklas |
196 |
write("--Delete file server FAILED"); |
5360 |
11 Jun 10 |
nicklas |
197 |
ex.printStackTrace(); |
5360 |
11 Jun 10 |
nicklas |
198 |
ok = false; |
5360 |
11 Jun 10 |
nicklas |
199 |
} |
5360 |
11 Jun 10 |
nicklas |
200 |
finally |
5360 |
11 Jun 10 |
nicklas |
201 |
{ |
5360 |
11 Jun 10 |
nicklas |
202 |
if (dc != null) dc.close(); |
5360 |
11 Jun 10 |
nicklas |
203 |
} |
5360 |
11 Jun 10 |
nicklas |
204 |
} |
5360 |
11 Jun 10 |
nicklas |
205 |
|
5360 |
11 Jun 10 |
nicklas |
206 |
|
5360 |
11 Jun 10 |
nicklas |
207 |
static void write_header() |
5360 |
11 Jun 10 |
nicklas |
208 |
{ |
5360 |
11 Jun 10 |
nicklas |
209 |
if (!TestUtil.getSilent()) |
5360 |
11 Jun 10 |
nicklas |
210 |
{ |
5362 |
16 Jun 10 |
nicklas |
211 |
write(" \tID \tName \tDescription\tUsername\tServer certificate"); |
5362 |
16 Jun 10 |
nicklas |
212 |
write("-- \t-- \t--------- \t-----------\t--------\t------------------"); |
5360 |
11 Jun 10 |
nicklas |
213 |
} |
5360 |
11 Jun 10 |
nicklas |
214 |
} |
5360 |
11 Jun 10 |
nicklas |
215 |
static void write_item(int i, FileServer fs) |
5360 |
11 Jun 10 |
nicklas |
216 |
throws BaseException |
5360 |
11 Jun 10 |
nicklas |
217 |
{ |
5362 |
16 Jun 10 |
nicklas |
218 |
|
5362 |
16 Jun 10 |
nicklas |
219 |
if (!TestUtil.getSilent()) |
5362 |
16 Jun 10 |
nicklas |
220 |
{ |
5362 |
16 Jun 10 |
nicklas |
221 |
String cert = null; |
5362 |
16 Jun 10 |
nicklas |
222 |
try |
5362 |
16 Jun 10 |
nicklas |
223 |
{ |
5362 |
16 Jun 10 |
nicklas |
224 |
X509Certificate tmp = fs.getServerX509Certificate(); |
7982 |
14 Jun 21 |
nicklas |
225 |
if (tmp != null) |
7982 |
14 Jun 21 |
nicklas |
226 |
{ |
7982 |
14 Jun 21 |
nicklas |
227 |
cert = tmp.getSubjectX500Principal().toString(); |
7982 |
14 Jun 21 |
nicklas |
228 |
cert += "; Valid until "+DateUtil.formatDate(tmp.getNotAfter()); |
7982 |
14 Jun 21 |
nicklas |
229 |
} |
5362 |
16 Jun 10 |
nicklas |
230 |
} |
5362 |
16 Jun 10 |
nicklas |
231 |
catch (Exception ex) |
5362 |
16 Jun 10 |
nicklas |
232 |
{ |
5362 |
16 Jun 10 |
nicklas |
233 |
cert = ex.getMessage(); |
5362 |
16 Jun 10 |
nicklas |
234 |
} |
5362 |
16 Jun 10 |
nicklas |
235 |
System.out.println(i+":\t"+fs.getId()+"\t"+fs.getName()+"\t"+fs.getDescription()+ |
5362 |
16 Jun 10 |
nicklas |
236 |
"\t"+fs.getUsername() + "\t" + cert); |
5362 |
16 Jun 10 |
nicklas |
237 |
} |
5360 |
11 Jun 10 |
nicklas |
238 |
} |
5360 |
11 Jun 10 |
nicklas |
239 |
static void write(String message) |
5360 |
11 Jun 10 |
nicklas |
240 |
{ |
5360 |
11 Jun 10 |
nicklas |
241 |
System.out.println(message); |
5360 |
11 Jun 10 |
nicklas |
242 |
} |
7352 |
28 Apr 17 |
nicklas |
243 |
|
7352 |
28 Apr 17 |
nicklas |
244 |
private static void downloadCertificate(String host, java.io.File certFile) |
7352 |
28 Apr 17 |
nicklas |
245 |
throws Exception |
7352 |
28 Apr 17 |
nicklas |
246 |
{ |
7352 |
28 Apr 17 |
nicklas |
// TrustManager implemenation that trusts all certificates |
7352 |
28 Apr 17 |
nicklas |
248 |
|
7352 |
28 Apr 17 |
nicklas |
249 |
TrustManager trustAll = new X509TrustManager() |
7352 |
28 Apr 17 |
nicklas |
250 |
{ |
7352 |
28 Apr 17 |
nicklas |
251 |
@Override |
7352 |
28 Apr 17 |
nicklas |
252 |
public X509Certificate[] getAcceptedIssuers() |
7352 |
28 Apr 17 |
nicklas |
253 |
{ |
7352 |
28 Apr 17 |
nicklas |
254 |
return null; |
7352 |
28 Apr 17 |
nicklas |
255 |
} |
7352 |
28 Apr 17 |
nicklas |
256 |
@Override |
7352 |
28 Apr 17 |
nicklas |
257 |
public void checkClientTrusted(X509Certificate[] certs, String authType) |
7352 |
28 Apr 17 |
nicklas |
258 |
{} |
7352 |
28 Apr 17 |
nicklas |
259 |
@Override |
7352 |
28 Apr 17 |
nicklas |
260 |
public void checkServerTrusted(X509Certificate[] certs, String authType) |
7352 |
28 Apr 17 |
nicklas |
261 |
{} |
7352 |
28 Apr 17 |
nicklas |
262 |
}; |
7352 |
28 Apr 17 |
nicklas |
263 |
|
7352 |
28 Apr 17 |
nicklas |
264 |
SSLSocket socket = null; |
7352 |
28 Apr 17 |
nicklas |
265 |
FileWriter out = null; |
7352 |
28 Apr 17 |
nicklas |
266 |
try |
7352 |
28 Apr 17 |
nicklas |
267 |
{ |
7352 |
28 Apr 17 |
nicklas |
268 |
|
7352 |
28 Apr 17 |
nicklas |
// Creates a new SSL context and factory with our trust-all trust manager |
7352 |
28 Apr 17 |
nicklas |
270 |
SSLContext sc = SSLContext.getInstance("SSL"); |
7352 |
28 Apr 17 |
nicklas |
271 |
sc.init(null, new TrustManager[] { trustAll }, new SecureRandom()); |
7352 |
28 Apr 17 |
nicklas |
272 |
SSLSocketFactory factory = sc.getSocketFactory(); |
7352 |
28 Apr 17 |
nicklas |
273 |
|
7352 |
28 Apr 17 |
nicklas |
// Connect to the host |
7352 |
28 Apr 17 |
nicklas |
275 |
socket = (SSLSocket) factory.createSocket(host, 443); |
7352 |
28 Apr 17 |
nicklas |
276 |
socket.startHandshake(); |
7352 |
28 Apr 17 |
nicklas |
277 |
|
7352 |
28 Apr 17 |
nicklas |
// And get the certificate |
7352 |
28 Apr 17 |
nicklas |
279 |
Certificate[] certs = socket.getSession().getPeerCertificates(); |
7352 |
28 Apr 17 |
nicklas |
280 |
Certificate cert = certs[0]; |
7352 |
28 Apr 17 |
nicklas |
281 |
|
7352 |
28 Apr 17 |
nicklas |
// Save it to the file |
7352 |
28 Apr 17 |
nicklas |
283 |
out = new FileWriter(certFile); |
7352 |
28 Apr 17 |
nicklas |
284 |
out.write("-----BEGIN CERTIFICATE-----\n"); |
7352 |
28 Apr 17 |
nicklas |
285 |
out.write(Base64.getEncoder().encodeToString(cert.getEncoded())); |
7352 |
28 Apr 17 |
nicklas |
286 |
out.write("\n-----END CERTIFICATE-----\n"); |
7352 |
28 Apr 17 |
nicklas |
287 |
out.close(); |
7352 |
28 Apr 17 |
nicklas |
288 |
} |
7352 |
28 Apr 17 |
nicklas |
289 |
finally |
7352 |
28 Apr 17 |
nicklas |
290 |
{ |
7352 |
28 Apr 17 |
nicklas |
291 |
if (socket != null) socket.close(); |
7352 |
28 Apr 17 |
nicklas |
292 |
if (out != null) out.close(); |
7352 |
28 Apr 17 |
nicklas |
293 |
} |
7352 |
28 Apr 17 |
nicklas |
294 |
} |
5360 |
11 Jun 10 |
nicklas |
295 |
} |