Libraryless. Click here for Pure Java version (3243L/19K).
1 | scope serverSocketFactory_botCompanyEtc. |
2 | |
3 | import javax.net.*; |
4 | import javax.net.ssl.*; |
5 | |
6 | static SNIKeyManager #keyManager; |
7 | |
8 | sS #passphrase = "botcompany"; |
9 | static File #trustKeyStoreFile; |
10 | |
11 | static char[] #getPassphrase() { |
12 | ret getChars(passphrase); |
13 | } |
14 | |
15 | static SNIKeyManager #makeSNIKeyManager() { |
16 | ret new SNIKeyManager(makeKeyManagerMap()); |
17 | } |
18 | |
19 | static Map<S, Pair<X509KeyManager, S>> #makeKeyManagerMap() { |
20 | L<File> dirs = sortByFileName(listDirsContainingFileNamed(javaxSecretDir(), "keystore.p12")); |
21 | char[] passphrase = getPassphrase(); |
22 | ret (Map) mapToOrderedMap(dirs, dir -> pair(fileName(dir), |
23 | pair(keyManagerFromKeyStore(newFile(dir, "keystore.p12"), passphrase), fileName(dir)))); |
24 | } |
25 | |
26 | static SSLServerSocketFactory serverSocketFactory_botCompanyEtc() ctex { |
27 | trustKeyStoreFile = anyKeyStore(); |
28 | if (trustKeyStoreFile == null) ret (SSLServerSocketFactory) SSLServerSocketFactory.getDefault(); |
29 | KeyStore trustKeyStore = keyStoreFromFile(trustKeyStoreFile, getPassphrase()); |
30 | SNIKeyManager wrappedKeyManager = makeSNIKeyManager(); |
31 | keyManager = wrappedKeyManager; |
32 | //wrappedKeyManager.verbose = true; |
33 | |
34 | TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); |
35 | trustManagerFactory.init(trustKeyStore); |
36 | |
37 | SSLContext ctx = SSLContext.getInstance("TLS"); |
38 | ctx.init(new KeyManager[] {wrappedKeyManager}, trustManagerFactory.getTrustManagers(), null); |
39 | |
40 | ret ctx.getServerSocketFactory(); |
41 | } |
42 | |
43 | svoid serverSocketFactory_botCompanyEtc_update() { |
44 | keyManager.keyManagersByDomain = makeKeyManagerMap(); |
45 | } |
46 | |
47 | end scope |
Began life as a copy of #1024328
download show line numbers debug dex old transpilations
Travelled to 8 computer(s): bhatertpkbcr, mqqgnosmbjvj, podlckwnjdmb, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1028045 |
Snippet name: | serverSocketFactory_botCompanyEtc [LIVE] |
Eternal ID of this version: | #1028045/16 |
Text MD5: | c19ff73c17acf0f8365529c47e0102b6 |
Transpilation MD5: | 368e56fc3b03308923a5f1ee6b30ef19 |
Author: | stefan |
Category: | javax / https |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-12-23 02:39:49 |
Source code size: | 1639 bytes / 47 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 310 / 468 |
Version history: | 15 change(s) |
Referenced in: | [show references] |