SSLContext sc = SSLContext.getDefault();
SSLEngine se = sc.createSSLEngine();
String[] serverParts = getServerName().split(":", 2);
- SocketChannel s = SocketChannel.open(new InetSocketAddress(serverParts[0], Integer.parseInt(serverParts[1])));
-
- in = ByteBuffer.allocate(se.getSession().getApplicationBufferSize());
- inC = ByteBuffer.allocate(se.getSession().getPacketBufferSize());
- inC.limit(0);
- out = ByteBuffer.allocate(se.getSession().getApplicationBufferSize());
- outC = ByteBuffer.allocate(se.getSession().getPacketBufferSize());
- outC.limit(0);
- se.setUseClientMode(true);
- se.beginHandshake();
-
- work(se, s);
- se.beginHandshake();
- try {
+ try (SocketChannel s = SocketChannel.open(new InetSocketAddress(serverParts[0], Integer.parseInt(serverParts[1])))) {
+
+ in = ByteBuffer.allocate(se.getSession().getApplicationBufferSize());
+ inC = ByteBuffer.allocate(se.getSession().getPacketBufferSize());
+ inC.limit(0);
+ out = ByteBuffer.allocate(se.getSession().getApplicationBufferSize());
+ outC = ByteBuffer.allocate(se.getSession().getPacketBufferSize());
+ outC.limit(0);
+ se.setUseClientMode(true);
+ se.beginHandshake();
+
work(se, s);
- throw new Error("Client re-negotiation succeded (possible DoS vulnerability");
- } catch (EOFException e) {
- // Cool, server closed connection
+ se.beginHandshake();
+ try {
+ work(se, s);
+ throw new Error("Client re-negotiation succeded (possible DoS vulnerability");
+ } catch (EOFException e) {
+ // Cool, server closed connection
+ }
}
}
}
private boolean acceptSSLServer(SSLServerSocket sss) throws IOException {
- try {
- Socket s = sss.accept();
+ try (Socket s = sss.accept()) {
s.getOutputStream().write('b');
s.getOutputStream().close();
return true;
public static void run(String[] args, ImportType truncate) throws ClassNotFoundException, SQLException, IOException {
Class.forName(args[0]);
- Connection conn = DriverManager.getConnection(args[1], args[2], args[3]);
- conn.setAutoCommit(false);
- Statement stmt = conn.createStatement();
- try (InputStream structure = DatabaseConnection.class.getResourceAsStream("tableStructure.sql")) {
- SQLFileManager.addFile(stmt, structure, truncate);
- }
- File localData = new File("doc/sampleData.sql");
- if (localData.exists()) {
- try (FileInputStream f = new FileInputStream(localData)) {
- SQLFileManager.addFile(stmt, f, ImportType.PRODUCTION);
+ final Connection conn = DriverManager.getConnection(args[1], args[2], args[3]);
+ try {
+ conn.setAutoCommit(false);
+ Statement stmt = conn.createStatement();
+ try {
+ try (InputStream structure = DatabaseConnection.class.getResourceAsStream("tableStructure.sql")) {
+ SQLFileManager.addFile(stmt, structure, truncate);
+ }
+ File localData = new File("doc/sampleData.sql");
+ if (localData.exists()) {
+ try (FileInputStream f = new FileInputStream(localData)) {
+ SQLFileManager.addFile(stmt, f, ImportType.PRODUCTION);
+ }
+ }
+ stmt.executeBatch();
+ conn.commit();
+ } finally {
+ stmt.close();
}
+ } finally {
+ conn.close();
}
- stmt.executeBatch();
- conn.commit();
- stmt.close();
-
- conn.close();
}
-
}