Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

27
LINES

< > BotCompany Repo | #1024323 // Serve HTTPS with SNI Spike 1 [doesn't work]

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Libraryless. Click here for Pure Java version (4871L/36K).

1  
!7
2  
3  
!include once #1024321 // SNIKeyManager
4  
5  
import javax.net.ssl.*;
6  
7  
p {
8  
  char[] passphrase = trim(loadSecretTextFileMandatory(#1013896, "keystore-pass")).toCharArray();
9  
10  
  KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
11  
  temp InputStream keystoreStream = new FileInputStream(javaxSecretDir("keystore.p12"));
12  
  keystore.load(keystoreStream, passphrase);
13  
  KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
14  
  keyManagerFactory.init(keystore, passphrase);
15  
16  
  TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
17  
  trustManagerFactory.init(keystore);
18  
  
19  
  SSLContext ctx = SSLContext.getInstance("TLS");
20  
  KeyManager[] keyManagers = keyManagerFactory.getKeyManagers();
21  
  if (l(keyManagers) > 1) print("Confused: More than one key manager");
22  
  SNIKeyManager wrappedKeyManager = new((X509ExtendedKeyManager) first(keyManagers));
23  
  wrappedKeyManager.verbose = true;
24  
  ctx.init(new KeyManager[] {wrappedKeyManager}, trustManagerFactory.getTrustManagers(), null);
25  
  
26  
  serveHttps(1443, ctx.getServerSocketFactory());
27  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1024323
Snippet name: Serve HTTPS with SNI Spike 1 [doesn't work]
Eternal ID of this version: #1024323/7
Text MD5: 66a66b982ab80571e908f51f524e8380
Transpilation MD5: 935361de47e7ed816fcf542c7b94ee7d
Author: stefan
Category: javax / https
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-08-02 14:39:36
Source code size: 1185 bytes / 27 lines
Pitched / IR pitched: No / No
Views / Downloads: 186 / 738
Version history: 6 change(s)
Referenced in: [show references]