summaryrefslogtreecommitdiffstats
path: root/base/silent/src/com/netscape/pkisilent/common
diff options
context:
space:
mode:
Diffstat (limited to 'base/silent/src/com/netscape/pkisilent/common')
-rw-r--r--base/silent/src/com/netscape/pkisilent/common/Con2Agent.java122
-rw-r--r--base/silent/src/com/netscape/pkisilent/common/DirEnroll.java60
-rw-r--r--base/silent/src/com/netscape/pkisilent/common/ServerInfo.java16
-rw-r--r--base/silent/src/com/netscape/pkisilent/common/TestClient.java23
-rw-r--r--base/silent/src/com/netscape/pkisilent/common/UserEnroll.java59
-rw-r--r--base/silent/src/com/netscape/pkisilent/common/Utilities.java105
6 files changed, 288 insertions, 97 deletions
diff --git a/base/silent/src/com/netscape/pkisilent/common/Con2Agent.java b/base/silent/src/com/netscape/pkisilent/common/Con2Agent.java
index 6d02fcd33..16fc7c77a 100644
--- a/base/silent/src/com/netscape/pkisilent/common/Con2Agent.java
+++ b/base/silent/src/com/netscape/pkisilent/common/Con2Agent.java
@@ -20,6 +20,7 @@ package com.netscape.pkisilent.common;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
+import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
@@ -157,13 +158,18 @@ public class Con2Agent implements SSLClientCertificateSelectionCallback,
// Submit requests
public boolean Send() {
+ SSLSocket socket = null;
+ OutputStream rawos = null;
+ BufferedOutputStream os = null;
+ PrintStream ps = null;
+ BufferedReader stdin1 = null;
try {
if (!loginCertDB()) {
return false;
}
- SSLSocket socket = new SSLSocket(host, port, null, 0, this, null);
+ socket = new SSLSocket(host, port, null, 0, this, null);
System.out.println("Con2Agent.java: host = " + host);
System.out.println("Con2Agent.java: port = " + port);
@@ -172,9 +178,9 @@ public class Con2Agent implements SSLClientCertificateSelectionCallback,
socket.setClientCertNickname(certnickname);
System.out.println("Connected to the socket");
- OutputStream rawos = socket.getOutputStream();
- BufferedOutputStream os = new BufferedOutputStream(rawos);
- PrintStream ps = new PrintStream(os);
+ rawos = socket.getOutputStream();
+ os = new BufferedOutputStream(rawos);
+ ps = new PrintStream(os);
System.out.println(ACTIONURL);
System.out.println("Query :" + query);
@@ -187,7 +193,7 @@ public class Con2Agent implements SSLClientCertificateSelectionCallback,
ps.println("\r");
ps.flush();
os.flush();
- BufferedReader stdin1 = new BufferedReader(
+ stdin1 = new BufferedReader(
new InputStreamReader(socket.getInputStream()));
String line;
@@ -195,32 +201,50 @@ public class Con2Agent implements SSLClientCertificateSelectionCallback,
stdout.append(line + "\n");
System.out.println(line);
}
-
+ ps.println("Connection: close");
+ } catch (Exception e) {
+ System.out.println("some exception: in Send routine" + e);
+ return false;
+ } finally {
// Send Connection: close to let the server close the connection.
// Else the socket on the server side continues to remain in TIME_WAIT state
-
- ps.println("Connection: close");
- ps.flush();
- os.flush();
- os.close();
- rawos.close();
- ps.close();
- stdin1.close();
- socket.close();
-
+ if (ps != null)
+ ps.close();
+ if (stdin1 != null) {
+ try {
+ stdin1.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ if (socket != null) {
+ try {
+ socket.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ if (os != null) {
+ try {
+ os.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ if (rawos != null) {
+ try {
+ rawos.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
if (socket.isClosed()) {
System.out.println("Con2Agent.java : Socket is Closed");
} else {
System.out.println("Con2Agent.java : Socket not Closed");
}
-
- } catch (Exception e) {
- System.out.println("some exception: in Send routine" + e);
- return false;
}
-
return true;
-
}
private boolean loginCertDB() {
@@ -271,6 +295,11 @@ public class Con2Agent implements SSLClientCertificateSelectionCallback,
}
public boolean Send_withGET() {
+ SSLSocket socket = null;
+ OutputStream rawos = null;
+ BufferedOutputStream os = null;
+ PrintStream ps = null;
+ BufferedReader stdin2 = null;
try {
@@ -278,14 +307,14 @@ public class Con2Agent implements SSLClientCertificateSelectionCallback,
return false;
}
- SSLSocket socket = new SSLSocket(host, port, null, 0, this, null);
+ socket = new SSLSocket(host, port, null, 0, this, null);
socket.setClientCertNickname(certnickname);
System.out.println("Connected to the socket");
- OutputStream rawos = socket.getOutputStream();
- BufferedOutputStream os = new BufferedOutputStream(rawos);
- PrintStream ps = new PrintStream(os);
+ rawos = socket.getOutputStream();
+ os = new BufferedOutputStream(rawos);
+ ps = new PrintStream(os);
System.out.println("Query in con2agent :" + query);
System.out.println("ACTIONURL in con2agent : " + ACTIONURL);
@@ -295,24 +324,51 @@ public class Con2Agent implements SSLClientCertificateSelectionCallback,
ps.println("\r");
ps.flush();
os.flush();
- BufferedReader stdin2 = new BufferedReader(
+ stdin2 = new BufferedReader(
new InputStreamReader(socket.getInputStream()));
String line;
while ((line = stdin2.readLine()) != null) {
stdout.append(line + "\n");
}
- stdin2.close();
-
- socket.close();
-
} catch (Exception e) {
System.err.println("some exception: in Send routine" + e);
return false;
- }
+ } finally {
+
+ if (ps != null)
+ ps.close();
+ if (stdin2 != null) {
+ try {
+ stdin2.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ if (socket != null) {
+ try {
+ socket.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ if (os != null) {
+ try {
+ os.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ if (rawos != null) {
+ try {
+ rawos.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
return true;
-
}
} // end of class
diff --git a/base/silent/src/com/netscape/pkisilent/common/DirEnroll.java b/base/silent/src/com/netscape/pkisilent/common/DirEnroll.java
index 809a65c5b..6ab1fb190 100644
--- a/base/silent/src/com/netscape/pkisilent/common/DirEnroll.java
+++ b/base/silent/src/com/netscape/pkisilent/common/DirEnroll.java
@@ -20,6 +20,7 @@ package com.netscape.pkisilent.common;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
+import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
@@ -260,7 +261,11 @@ public class DirEnroll extends TestClient {
private boolean Send() {
boolean st = false;
-
+ SSLSocket socket = null;
+ OutputStream rawos = null;
+ BufferedOutputStream os = null;
+ PrintStream ps = null;
+ BufferedReader stdin = null;
try {
if (debug) {
System.out.println("Step 3 : Socket initialize");
@@ -273,13 +278,13 @@ public class DirEnroll extends TestClient {
GregorianCalendar begin = new GregorianCalendar();
// SSLSocket socket = new SSLSocket(host,port);
- SSLSocket socket = new SSLSocket(host, port, null, 0, this, null);
+ socket = new SSLSocket(host, port, null, 0, this, null);
socket.setUseClientMode(true);
- OutputStream rawos = socket.getOutputStream();
- BufferedOutputStream os = new BufferedOutputStream(rawos);
- PrintStream ps = new PrintStream(os);
+ rawos = socket.getOutputStream();
+ os = new BufferedOutputStream(rawos);
+ ps = new PrintStream(os);
ps.println("POST /enrollment HTTP/1.0");
ps.println("Connection: Keep-Alive");
@@ -290,7 +295,7 @@ public class DirEnroll extends TestClient {
ps.println("\r");
ps.flush();
os.flush();
- BufferedReader stdin = new BufferedReader(
+ stdin = new BufferedReader(
new InputStreamReader(socket.getInputStream()));
if (debug) {
@@ -327,16 +332,6 @@ public class DirEnroll extends TestClient {
}
}
- stdin.close();
- socket.close();
- os.close();
- rawos.close();
- ps.close();
- os = null;
- rawos = null;
- stdin = null;
- ps = null;
- line = null;
GregorianCalendar end = new GregorianCalendar();
long diff = calculateElapsedTime(begin, end);
@@ -346,10 +341,39 @@ public class DirEnroll extends TestClient {
} catch (Exception e) {
System.err.println("some exception: in Send routine" + e);
return false;
+ } finally {
+ if (ps != null)
+ ps.close();
+ if (stdin != null) {
+ try {
+ stdin.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ if (socket != null) {
+ try {
+ socket.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ if (os != null) {
+ try {
+ os.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ if (rawos != null) {
+ try {
+ rawos.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
}
-
return st;
-
}
private void buildquery() throws UnsupportedEncodingException {
diff --git a/base/silent/src/com/netscape/pkisilent/common/ServerInfo.java b/base/silent/src/com/netscape/pkisilent/common/ServerInfo.java
index 637f0c1ee..ff99a47f4 100644
--- a/base/silent/src/com/netscape/pkisilent/common/ServerInfo.java
+++ b/base/silent/src/com/netscape/pkisilent/common/ServerInfo.java
@@ -21,6 +21,7 @@ package com.netscape.pkisilent.common;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileReader;
+import java.io.IOException;
import java.net.InetAddress;
import java.util.StringTokenizer;
@@ -260,9 +261,9 @@ public class ServerInfo {
String ldapHostStr = "ldapHost:";
String ldapPortStr = "ldapPort:";
String adminPortStr = "port:";
-
+ FileInputStream fis = null;
try {
- FileInputStream fis = new FileInputStream(AdminConfigFile);
+ fis = new FileInputStream(AdminConfigFile);
int size = fis.available();
byte b[] = new byte[size];
@@ -294,12 +295,17 @@ public class ServerInfo {
}
}
-
- fis.close();
} catch (Exception e) {
System.out.println("exception " + e.getMessage());
+ } finally {
+ if (fis != null) {
+ try {
+ fis.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
}
-
}
private void readCMSConfig() {
diff --git a/base/silent/src/com/netscape/pkisilent/common/TestClient.java b/base/silent/src/com/netscape/pkisilent/common/TestClient.java
index 22275ede5..6fb5bd120 100644
--- a/base/silent/src/com/netscape/pkisilent/common/TestClient.java
+++ b/base/silent/src/com/netscape/pkisilent/common/TestClient.java
@@ -20,6 +20,7 @@ package com.netscape.pkisilent.common;
import java.io.BufferedReader;
import java.io.FileInputStream;
+import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.util.Properties;
@@ -357,15 +358,15 @@ public class TestClient implements SSLCertificateApprovalCallback {
*/
public void getProperties(String fileName) throws Exception {
+ FileInputStream fis = null;
try {
- FileInputStream fis = new FileInputStream(fileName);
-
+ fis = new FileInputStream(fileName);
props = new Properties();
props.load(fis);
- } catch (Exception e) {
- System.out.println("exception " + e.getMessage());
+ } finally {
+ if (fis != null)
+ fis.close();
}
-
}
public String ReadEnv(String str) {
@@ -488,8 +489,9 @@ public class TestClient implements SSLCertificateApprovalCallback {
**/
public String readRequest(String filename) {
+ FileInputStream f1 = null;
try {
- FileInputStream f1 = new FileInputStream(filename);
+ f1 = new FileInputStream(filename);
int size = f1.available();
byte b[] = new byte[size];
@@ -497,13 +499,20 @@ public class TestClient implements SSLCertificateApprovalCallback {
return null;
}
- f1.close();
String s = new String(b);
return s;
} catch (Exception e) {
System.out.println("exception " + e.getMessage());
return null;
+ } finally {
+ if (f1 != null) {
+ try {
+ f1.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
}
}
diff --git a/base/silent/src/com/netscape/pkisilent/common/UserEnroll.java b/base/silent/src/com/netscape/pkisilent/common/UserEnroll.java
index 0e31eeb57..2f6a03924 100644
--- a/base/silent/src/com/netscape/pkisilent/common/UserEnroll.java
+++ b/base/silent/src/com/netscape/pkisilent/common/UserEnroll.java
@@ -20,6 +20,7 @@ package com.netscape.pkisilent.common;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
+import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
@@ -218,7 +219,11 @@ public class UserEnroll extends TestClient {
private boolean Send() {
boolean st = false;
-
+ SSLSocket socket = null;
+ OutputStream rawos = null;
+ BufferedOutputStream os = null;
+ PrintStream ps = null;
+ BufferedReader stdin = null;
try {
if (debug) {
@@ -232,12 +237,12 @@ public class UserEnroll extends TestClient {
GregorianCalendar begin = new GregorianCalendar();
// SSLSocket socket = new SSLSocket(host,port);
- SSLSocket socket = new SSLSocket(host, port, null, 0, this, null);
+ socket = new SSLSocket(host, port, null, 0, this, null);
socket.setUseClientMode(true);
- OutputStream rawos = socket.getOutputStream();
- BufferedOutputStream os = new BufferedOutputStream(rawos);
- PrintStream ps = new PrintStream(os);
+ rawos = socket.getOutputStream();
+ os = new BufferedOutputStream(rawos);
+ ps = new PrintStream(os);
ps.println("POST /enrollment HTTP/1.0");
ps.println("Connection: Keep-Alive");
@@ -248,7 +253,7 @@ public class UserEnroll extends TestClient {
ps.println("\r");
ps.flush();
os.flush();
- BufferedReader stdin = new BufferedReader(
+ stdin = new BufferedReader(
new InputStreamReader(socket.getInputStream()));
if (debug) {
@@ -274,16 +279,6 @@ public class UserEnroll extends TestClient {
}
}
- stdin.close();
- socket.close();
- os.close();
- rawos.close();
- ps.close();
- os = null;
- rawos = null;
- stdin = null;
- ps = null;
- line = null;
GregorianCalendar end = new GregorianCalendar();
long diff = calculateElapsedTime(begin, end);
@@ -292,6 +287,38 @@ public class UserEnroll extends TestClient {
} catch (Exception e) {
System.err.println("some exception: in Send routine" + e);
return false;
+ } finally {
+ if (ps != null) {
+ ps.close();
+ }
+ if (stdin != null) {
+ try {
+ stdin.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ if (socket != null) {
+ try {
+ socket.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ if (os != null) {
+ try {
+ os.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ if (rawos != null) {
+ try {
+ rawos.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
}
return st;
diff --git a/base/silent/src/com/netscape/pkisilent/common/Utilities.java b/base/silent/src/com/netscape/pkisilent/common/Utilities.java
index 23fd2c54e..79712eb11 100644
--- a/base/silent/src/com/netscape/pkisilent/common/Utilities.java
+++ b/base/silent/src/com/netscape/pkisilent/common/Utilities.java
@@ -20,6 +20,7 @@ package com.netscape.pkisilent.common;
import java.io.BufferedReader;
import java.io.FileInputStream;
+import java.io.IOException;
import java.io.InputStreamReader;
import netscape.security.x509.CertificateSerialNumber;
@@ -162,10 +163,11 @@ public class Utilities {
*/
public String getcertfromfile(String filename) {
StringBuffer tempBuffer = new StringBuffer();
-
+ BufferedReader in = null;
+ FileInputStream fis = null;
try {
- FileInputStream fis = new FileInputStream(filename);
- BufferedReader in = new BufferedReader(new InputStreamReader(fis));
+ fis = new FileInputStream(filename);
+ in = new BufferedReader(new InputStreamReader(fis));
String temp;
while ((temp = in.readLine()) != null) {
@@ -180,17 +182,33 @@ public class Utilities {
return tempBuffer.toString();
} catch (Exception e) {
System.out.println("ERROR: getcertfromfile" + e.toString());
- return null;
+ e.printStackTrace();
+ } finally {
+ if (in != null) {
+ try {
+ in.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ if (fis != null) {
+ try {
+ fis.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
}
-
+ return null;
}
public String getcertfromfile_withheaders(String filename) {
StringBuffer tempBuffer = new StringBuffer();
-
+ BufferedReader in = null;
+ FileInputStream fis = null;
try {
- FileInputStream fis = new FileInputStream(filename);
- BufferedReader in = new BufferedReader(new InputStreamReader(fis));
+ fis = new FileInputStream(filename);
+ in = new BufferedReader(new InputStreamReader(fis));
String temp;
while ((temp = in.readLine()) != null) {
@@ -200,8 +218,24 @@ public class Utilities {
} catch (Exception e) {
System.out.println(
"ERROR: getcertfromfile_withheaders" + e.toString());
- return null;
+ e.printStackTrace();
+ } finally {
+ if (in != null) {
+ try {
+ in.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ if (fis != null) {
+ try {
+ fis.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
}
+ return null;
}
/*
@@ -212,10 +246,11 @@ public class Utilities {
*/
public String getcrlfromfile(String filename) {
StringBuffer tempBuffer = new StringBuffer();
-
+ BufferedReader in = null;
+ FileInputStream fis = null;
try {
- FileInputStream fis = new FileInputStream(filename);
- BufferedReader in = new BufferedReader(new InputStreamReader(fis));
+ fis = new FileInputStream(filename);
+ in = new BufferedReader(new InputStreamReader(fis));
String temp;
while ((temp = in.readLine()) != null) {
@@ -225,9 +260,26 @@ public class Utilities {
return tempBuffer.toString();
} catch (Exception e) {
System.out.println("ERROR: getcrlfromfile" + e.toString());
- return null;
+ e.printStackTrace();
+ } finally {
+ if (in != null) {
+ try {
+ in.close();
+ } catch (IOException e) {
+ System.out.println("ERROR: Unable to close the input reader");
+ e.printStackTrace();
+ }
+ }
+ if (fis != null) {
+ try {
+ fis.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
}
+ return null;
}
/*
@@ -238,10 +290,11 @@ public class Utilities {
*/
public String getcafromfile(String filename) {
StringBuffer tempBuffer = new StringBuffer();
-
+ BufferedReader in = null;
+ FileInputStream fis = null;
try {
- FileInputStream fis = new FileInputStream(filename);
- BufferedReader in = new BufferedReader(new InputStreamReader(fis));
+ fis = new FileInputStream(filename);
+ in = new BufferedReader(new InputStreamReader(fis));
String temp;
while ((temp = in.readLine()) != null) {
@@ -251,9 +304,25 @@ public class Utilities {
return tempBuffer.toString();
} catch (Exception e) {
System.out.println("ERROR: getcafromfile" + e.toString());
- return null;
+ e.printStackTrace();
+ } finally {
+ if (in != null) {
+ try {
+ in.close();
+ } catch (IOException e) {
+ System.out.println("ERROR: Unable to close the input reader");
+ e.printStackTrace();
+ }
+ }
+ if (fis != null) {
+ try {
+ fis.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
}
-
+ return null;
}
/*