Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ static SSLSocketFactory createBlindSocketFactory() throws GeneralSecurityExcepti
return ctx.getSocketFactory();
}

static SSLServerSocketFactory createServerSocketFactory(Context context, @NonNull final String keyStoreResourceUri) throws GeneralSecurityException, IOException {
char[] password = "".toCharArray();
static SSLServerSocketFactory createServerSocketFactory(Context context, @NonNull final String keyStoreResourceUri, final String passphrase) throws GeneralSecurityException, IOException {
char[] password = (passphrase != null) ? passphrase.toCharArray() : "".toCharArray();

InputStream keyStoreInput = getRawResourceStream(context, keyStoreResourceUri);
KeyStore keyStore = KeyStore.getInstance("PKCS12");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ public TcpSocketServer(final Context context, final ConcurrentHashMap<Integer, T
if (tlsOptions != null) {
String keystoreResourceUri = tlsOptions.getString("keystore");
assert keystoreResourceUri != null;
String passphrase = tlsOptions.hasKey("passphrase") ? tlsOptions.getString("passphrase") : null;

SSLServerSocketFactory ssf = SSLCertificateHelper.createServerSocketFactory(context, keystoreResourceUri);
SSLServerSocketFactory ssf = SSLCertificateHelper.createServerSocketFactory(context, keystoreResourceUri, passphrase);
serverSocket = ssf.createServerSocket(port, 50, localInetAddress);
isTLS = true;
// ((SSLServerSocket) serverSocket).setNeedClientAuth(true);
Expand Down
4 changes: 2 additions & 2 deletions ios/TcpSocketClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@ - (BOOL)setSecureContext:(NSDictionary *)tlsOptions {
NSURL *keystoreUrl = [[NSURL alloc] initWithString:keystoreResourcePath];
NSData *pkcs12data = [[NSData alloc] initWithContentsOfURL:keystoreUrl];
CFDataRef inPCKS12Data = (CFDataRef)CFBridgingRetain(pkcs12data);
CFStringRef password = CFSTR("");
NSString *passphrase = tlsOptions[@"passphrase"] ?: @"";
CFStringRef password = (__bridge CFStringRef)passphrase;
const void *keys[] = {kSecImportExportPassphrase};
const void *values[] = {password};
CFDictionaryRef options = CFDictionaryCreate(NULL, keys, values, 1, NULL, NULL);
Expand All @@ -357,7 +358,6 @@ - (BOOL)setSecureContext:(NSDictionary *)tlsOptions {

OSStatus securityError = SecPKCS12Import(inPCKS12Data, options, &items);
CFRelease(options);
CFRelease(password);

if (securityError != errSecSuccess) {
return false;
Expand Down
1 change: 1 addition & 0 deletions lib/types/TLSServer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default class TLSServer extends Server {
}
export type TLSServerOptions = {
keystore: any;
passphrase?: string;
};
import Server from "./Server";
import TLSSocket from "./TLSSocket";
1 change: 1 addition & 0 deletions src/TLSServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import TLSSocket from './TLSSocket';
/**
* @typedef {object} TLSServerOptions
* @property {any} keystore
* @property {string} [passphrase] - Optional passphrase for keystore
*
* @extends {Server}
*/
Expand Down