use of org.mozilla.jss.ssl.SSLServerSocket in project jss by dogtagpki.
the class JSS_FileUploadServer method doIt.
public void doIt(String[] args) throws Exception {
if (args.length < 1 || args[0].toLowerCase().indexOf("-h") != -1) {
System.out.println(usage);
System.exit(1);
}
int socketCntr = 0;
try {
if (args[0].length() > 0 && !args[0].equals("."))
fCertDbPath = args[0];
if (args[1].length() > 0 && !args[1].equals("passwords"))
fPasswordFile = args[1];
if (args[2].length() > 0 && !args[2].equals("localhost"))
fServerHost = args[2];
if (args[3].length() > 0)
fServerCertNick = args[3];
} catch (Exception e) {
}
CryptoManager cm = CryptoManager.getInstance();
CryptoToken tok = cm.getInternalKeyStorageToken();
PasswordCallback cb = new FilePasswordCallback(fPasswordFile);
tok.login(cb);
if (args[4].equalsIgnoreCase("true") == true) {
TestInetAddress = true;
}
// We have to configure the server session ID cache before
// creating any server sockets.
SSLServerSocket.configServerSessionIDCache(10, 100, 100, null);
// Disable SSL2
SSLSocket.enableSSL2Default(false);
// Note we will use the NSS default enabled ciphers suites
// open the server socket and bind to the port
logger.debug("Server about .... to create socket");
if (TestInetAddress) {
logger.debug("the HostName " + fServerHost + " the Inet Address " + InetAddress.getByName(fServerHost));
serverSock = new SSLServerSocket(port, 5, InetAddress.getByName(fServerHost), null, true);
} else {
logger.debug("Inet set to Null");
serverSock = new SSLServerSocket(port, 5, null, null, true);
}
logger.debug("Server created socket");
// serverSock.setSoTimeout(120 * 1000);
serverSock.requireClientAuth(SSLSocket.SSL_REQUIRE_NO_ERROR);
serverSock.setServerCertNickname(fServerCertNick);
logger.debug("Server specified cert by nickname");
System.out.println("Server ready to accept connections");
while (true) {
// accept the connection
sock = (SSLSocket) serverSock.accept();
// sock.setKeepAlive(true);
sock.addHandshakeCompletedListener(new HandshakeListener("server", this));
socketCntr++;
readWriteThread rwThread = new readWriteThread(sock, socketCntr);
rwThread.start();
}
}
use of org.mozilla.jss.ssl.SSLServerSocket in project jss by dogtagpki.
the class JSS_SelfServServer method doIt.
public void doIt(String[] args) throws Exception {
if (args.length < 5 || args[0].toLowerCase().equals("-h")) {
System.out.println(usage);
System.exit(1);
}
try {
if (!args[0].equals("."))
fCertDbPath = args[0];
if (!args[1].equals("passwords"))
fPasswordFile = args[1];
if (!args[2].equals("localhost"))
fServerHost = args[2];
if (args[3].equalsIgnoreCase("true") == true)
TestInetAddress = true;
if (args.length >= 5)
port = Integer.parseInt(args[4]);
if (args.length >= 6 && args[5].equalsIgnoreCase("verbose")) {
bVerbose = true;
}
if (args.length >= 7 && !args[6].equalsIgnoreCase("default")) {
fServerCertNick = args[6];
}
} catch (NumberFormatException e) {
System.out.println("Error parsing command line " + e.getMessage());
System.out.println(usage);
System.exit(1);
}
if (bVerbose)
System.out.println("initializing JSS");
CryptoManager cm = CryptoManager.getInstance();
CryptoToken tok = cm.getInternalKeyStorageToken();
PasswordCallback cb = new FilePasswordCallback(fPasswordFile);
tok.login(cb);
// We have to configure the server session ID cache before
// creating any server sockets.
SSLServerSocket.configServerSessionIDCache(10, 100, 100, null);
if (cm.FIPSEnabled()) {
/* turn on only FIPS ciphersuites */
/* Disable SSL2 and SSL3 ciphers */
SSLSocket.enableSSL2Default(false);
SSLSocket.enableSSL3Default(false);
// Enable only FIPS ciphersuites.
int[] ciphers = org.mozilla.jss.ssl.SSLSocket.getImplementedCipherSuites();
for (int i = 0; i < ciphers.length; ++i) {
if (SSLSocket.isFipsCipherSuite(ciphers[i])) {
/* enable the FIPS ciphersuite */
SSLSocket.setCipherPreferenceDefault(ciphers[i], true);
} else if (SSLSocket.getCipherPreferenceDefault(ciphers[i])) {
/* disable the non fips ciphersuite */
SSLSocket.setCipherPreferenceDefault(ciphers[i], false);
}
}
} else {
/* turn on all implemented ciphersuites the server certificate
* will determine if the ciphersuites can be used.
*/
int[] ciphers = org.mozilla.jss.ssl.SSLSocket.getImplementedCipherSuites();
for (int i = 0; i < ciphers.length; ++i) {
try {
SSLSocket.setCipherPreferenceDefault(ciphers[i], true);
if (bVerbose) {
System.out.println(Constants.cipher.cipherToString(ciphers[i]) + " " + Integer.toHexString(ciphers[i]));
}
} catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
}
}
// disable SSL2 ciphersuites
SSLSocket.enableSSL2Default(false);
}
// open the server socket and bind to the port
if (bVerbose)
System.out.println("JSS_SelfServServ about .... to create socket");
if (TestInetAddress) {
if (bVerbose)
System.out.println("JSS_SelfServServ HostName " + fServerHost + " the Inet Address " + InetAddress.getByName(fServerHost));
serverSock = new SSLServerSocket(port, 5, InetAddress.getByName(fServerHost), null, true);
} else {
if (bVerbose)
System.out.println("Inet set to Null");
serverSock = new SSLServerSocket(port, 5, null, null, true);
}
if (bVerbose)
System.out.println("JSS_SelfServServ created socket");
// Set timeout for 10 minutes
serverSock.setSoTimeout(600 * 1000);
serverSock.requireClientAuth(SSLSocket.SSL_REQUIRE_NO_ERROR);
serverSock.setServerCertNickname("Server_ECDSA");
serverSock.setServerCertNickname("Server_RSA");
serverSock.setServerCertNickname("Server_DSS");
if (bVerbose)
System.out.println("JSS_SelfServServ specified cert by nickname");
System.out.println("JSS_SelfServServ " + fServerHost + " ready to accept connections on " + port);
int socketCntr = 0;
try {
while (true) {
// accept the connection
sock = (SSLSocket) serverSock.accept();
sock.addHandshakeCompletedListener(new HandshakeListener("server", this));
socketCntr++;
sock.setSoTimeout(300 * 1000);
if (bVerbose) {
System.out.println("Timeout value for SSL sockets: " + sock.getSoTimeout() + " milliseconds");
}
readWriteThread rwThread = new readWriteThread(sock, socketCntr);
rwThread.start();
}
} catch (SocketTimeoutException ex) {
if (socketCntr == 0) {
System.out.println("JSS_SelfServServ No Client attempted to " + "connect! If " + "test ran from all.pl check the client execution " + "for errors.");
} else {
System.out.println("JSS_SelfServServ there has been " + socketCntr + " client " + " connections but the server Accept has timed out!");
}
System.out.println("JSS_SelfServServ Timeout value: " + serverSock.getSoTimeout() + " milliseconds");
ex.printStackTrace();
System.out.println("JSS_SelfServServ exiting due to timeout.");
System.exit(1);
} catch (Exception ex) {
System.out.println("JSS_SelfServServ Exception:");
ex.printStackTrace();
System.out.println("JSS_SelfServServ exiting.");
System.exit(1);
}
}
use of org.mozilla.jss.ssl.SSLServerSocket in project jss by dogtagpki.
the class SSLClientAuth method run.
/**
* Server run method.
*/
@Override
public void run() {
try {
// We have to configure the server session ID cache before
// creating any server sockets.
SSLServerSocket.configServerSessionIDCache(10, 100, 100, null);
// open the server socket and bind to the port
System.out.println("Server about to create socket");
SSLServerSocket serverSock = new SSLServerSocket(port, 5, null, null, true);
System.out.println("Server created socket");
serverSock.requireClientAuth(SSLSocket.SSL_REQUIRE_NO_ERROR);
if (useNickname) {
serverSock.setServerCertNickname(serverCertNick);
System.out.println("Server specified cert by nickname");
} else {
serverSock.setServerCert(nssServerCert);
System.out.println("Server specified cert directly");
}
// tell the client we're ready
synchronized (this) {
serverReady = true;
this.notify();
}
// accept the connection
System.out.println("Server about to accept");
SSLSocket sock = (SSLSocket) serverSock.accept();
System.out.println("Server accepted");
sock.addHandshakeCompletedListener(new HandshakeListener("server", this));
// try to read some bytes, to allow the handshake to go through
InputStream is = sock.getInputStream();
try {
System.out.println("Server about to read");
is.read();
System.out.println("Server read successful");
} catch (EOFException e) {
System.out.println("Server got EOF");
}
sock.close();
serverSock.close();
} catch (Exception e) {
synchronized (this) {
serverReady = true;
setFailure();
this.notify();
}
e.printStackTrace();
}
System.out.println("Server exiting");
}
Aggregations