From fc358013a7656d4bd86857a23f288f364a065cf5 Mon Sep 17 00:00:00 2001
From: Endi Sukma Dewata <edewata@redhat.com>
Date: Fri, 15 Jun 2012 09:58:40 -0500
Subject: [PATCH] Fixed null pointer exception in pkisilent on connection
 error.

Previously HTTPClient.sslConnect() would return a null if there is
a connection issue. Some code in pkisilent did not check the return
value properly so it would throw an exception. The sslConnect() has
been modified to throw an exception instead.

Ticket #180
---
 .../src/com/netscape/pkisilent/ConfigureDRM.java   |   35 ++++----
 .../src/com/netscape/pkisilent/ConfigureOCSP.java  |   37 ++++----
 .../src/com/netscape/pkisilent/ConfigureRA.java    |   31 ++++----
 .../src/com/netscape/pkisilent/ConfigureSubCA.java |   33 ++++----
 .../src/com/netscape/pkisilent/ConfigureTKS.java   |   37 ++++----
 .../src/com/netscape/pkisilent/ConfigureTPS.java   |   33 ++++----
 .../com/netscape/pkisilent/http/HTTPClient.java    |   87 +++++++++-----------
 7 files changed, 138 insertions(+), 155 deletions(-)

diff --git a/base/silent/src/com/netscape/pkisilent/ConfigureDRM.java b/base/silent/src/com/netscape/pkisilent/ConfigureDRM.java
index 6d2516399b9ab5cb8fb7cf0a104d3194f15a3079..ca35818690af1c744ae548760e247d77b4169e2f 100644
--- a/base/silent/src/com/netscape/pkisilent/ConfigureDRM.java
+++ b/base/silent/src/com/netscape/pkisilent/ConfigureDRM.java
@@ -24,7 +24,6 @@ import java.io.ByteArrayInputStream;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.InputStreamReader;
-import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
 import java.util.ArrayList;
 
@@ -32,13 +31,13 @@ import org.mozilla.jss.asn1.SEQUENCE;
 import org.mozilla.jss.pkcs12.AuthenticatedSafes;
 import org.mozilla.jss.pkcs12.PFX;
 
+import com.netscape.cmsutil.util.Utils;
 import com.netscape.pkisilent.argparser.ArgParser;
 import com.netscape.pkisilent.argparser.StringHolder;
 import com.netscape.pkisilent.common.ComCrypto;
 import com.netscape.pkisilent.common.ParseXML;
 import com.netscape.pkisilent.http.HTTPClient;
 import com.netscape.pkisilent.http.HTTPResponse;
-import com.netscape.cmsutil.util.Utils;
 
 public class ConfigureDRM {
 
@@ -194,7 +193,7 @@ public class ConfigureDRM {
 
     }
 
-    public boolean LoginPanel() {
+    public boolean LoginPanel() throws Exception {
         boolean st = false;
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
@@ -227,7 +226,7 @@ public class ConfigureDRM {
         return st;
     }
 
-    public boolean TokenChoicePanel() throws UnsupportedEncodingException {
+    public boolean TokenChoicePanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -274,7 +273,7 @@ public class ConfigureDRM {
         return true;
     }
 
-    public boolean DomainPanel() throws UnsupportedEncodingException {
+    public boolean DomainPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -299,7 +298,7 @@ public class ConfigureDRM {
 
     }
 
-    public boolean DisplayChainPanel() {
+    public boolean DisplayChainPanel() throws Exception {
         String query_string = "p=4" + "&op=next" + "&xml=true";
         hc.sslConnect(cs_hostname, cs_port, wizard_uri, query_string);
 
@@ -365,7 +364,7 @@ public class ConfigureDRM {
         }
     }
 
-    public boolean SubsystemPanel() throws UnsupportedEncodingException {
+    public boolean SubsystemPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -414,7 +413,7 @@ public class ConfigureDRM {
         }
     }
 
-    public boolean LdapConnectionPanel() throws UnsupportedEncodingException {
+    public boolean LdapConnectionPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -443,7 +442,7 @@ public class ConfigureDRM {
         return true;
     }
 
-    public boolean KeyPanel() {
+    public boolean KeyPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -530,7 +529,7 @@ public class ConfigureDRM {
         return true;
     }
 
-    public boolean CertSubjectPanel() throws UnsupportedEncodingException {
+    public boolean CertSubjectPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -600,7 +599,7 @@ public class ConfigureDRM {
         return true;
     }
 
-    public boolean CertificatePanel() throws UnsupportedEncodingException {
+    public boolean CertificatePanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -632,7 +631,7 @@ public class ConfigureDRM {
         return true;
     }
 
-    public boolean BackupPanel() throws UnsupportedEncodingException {
+    public boolean BackupPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -652,7 +651,7 @@ public class ConfigureDRM {
         return true;
     }
 
-    public boolean SavePKCS12Panel() {
+    public boolean SavePKCS12Panel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -711,7 +710,7 @@ public class ConfigureDRM {
         return true;
     }
 
-    public boolean AdminCertReqPanel() throws UnsupportedEncodingException {
+    public boolean AdminCertReqPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -767,7 +766,7 @@ public class ConfigureDRM {
         return true;
     }
 
-    public boolean AdminCertImportPanel() {
+    public boolean AdminCertImportPanel() throws Exception {
         boolean st = false;
         HTTPResponse hr = null;
 
@@ -805,7 +804,7 @@ public class ConfigureDRM {
         return true;
     }
 
-    public boolean UpdateDomainPanel() throws UnsupportedEncodingException {
+    public boolean UpdateDomainPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -824,7 +823,7 @@ public class ConfigureDRM {
         return true;
     }
 
-    public boolean ConfigureDRMInstance() throws UnsupportedEncodingException {
+    public boolean ConfigureDRMInstance() throws Exception {
         // 0. login to cert db
         ComCrypto cCrypt = new ComCrypto(client_certdb_dir,
                                         client_certdb_pwd,
@@ -985,7 +984,7 @@ public class ConfigureDRM {
         }
     }
 
-    public static void main(String args[]) throws UnsupportedEncodingException {
+    public static void main(String args[]) throws Exception {
         ConfigureDRM ca = new ConfigureDRM();
 
         // set variables
diff --git a/base/silent/src/com/netscape/pkisilent/ConfigureOCSP.java b/base/silent/src/com/netscape/pkisilent/ConfigureOCSP.java
index d6caddbcb9d626bc2ab3d849e8fc8a2fabb9a5de..0ca0a082a811ed1cfd7ea19d1ee6d8196efb8436 100644
--- a/base/silent/src/com/netscape/pkisilent/ConfigureOCSP.java
+++ b/base/silent/src/com/netscape/pkisilent/ConfigureOCSP.java
@@ -24,7 +24,6 @@ import java.io.ByteArrayInputStream;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.InputStreamReader;
-import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
 import java.util.ArrayList;
 
@@ -32,13 +31,13 @@ import org.mozilla.jss.asn1.SEQUENCE;
 import org.mozilla.jss.pkcs12.AuthenticatedSafes;
 import org.mozilla.jss.pkcs12.PFX;
 
+import com.netscape.cmsutil.util.Utils;
 import com.netscape.pkisilent.argparser.ArgParser;
 import com.netscape.pkisilent.argparser.StringHolder;
 import com.netscape.pkisilent.common.ComCrypto;
 import com.netscape.pkisilent.common.ParseXML;
 import com.netscape.pkisilent.http.HTTPClient;
 import com.netscape.pkisilent.http.HTTPResponse;
-import com.netscape.cmsutil.util.Utils;
 
 public class ConfigureOCSP {
     public static final String DEFAULT_KEY_TYPE = "RSA";
@@ -170,7 +169,7 @@ public class ConfigureOCSP {
 
     }
 
-    public boolean LoginPanel() {
+    public boolean LoginPanel() throws Exception {
         boolean st = false;
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
@@ -206,7 +205,7 @@ public class ConfigureOCSP {
         return st;
     }
 
-    public boolean TokenChoicePanel() throws UnsupportedEncodingException {
+    public boolean TokenChoicePanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -251,7 +250,7 @@ public class ConfigureOCSP {
         return true;
     }
 
-    public boolean DomainPanel() throws UnsupportedEncodingException {
+    public boolean DomainPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -276,7 +275,7 @@ public class ConfigureOCSP {
 
     }
 
-    public boolean DisplayChainPanel() {
+    public boolean DisplayChainPanel() throws Exception {
         String query_string = null;
 
         query_string = "p=4" + "&op=next" + "&xml=true";
@@ -290,7 +289,7 @@ public class ConfigureOCSP {
 
     }
 
-    public boolean SecurityDomainLoginPanel() throws UnsupportedEncodingException {
+    public boolean SecurityDomainLoginPanel() throws Exception {
         HTTPResponse hr = null;
 
         String ocsp_url = "https://" + cs_hostname + ":" + cs_port +
@@ -330,7 +329,7 @@ public class ConfigureOCSP {
 
     }
 
-    public boolean SubsystemPanel() throws UnsupportedEncodingException {
+    public boolean SubsystemPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -349,7 +348,7 @@ public class ConfigureOCSP {
         return true;
     }
 
-    public boolean LdapConnectionPanel() throws UnsupportedEncodingException {
+    public boolean LdapConnectionPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -375,7 +374,7 @@ public class ConfigureOCSP {
         return true;
     }
 
-    public boolean KeyPanel() {
+    public boolean KeyPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -437,7 +436,7 @@ public class ConfigureOCSP {
         return true;
     }
 
-    public boolean CertSubjectPanel() throws UnsupportedEncodingException {
+    public boolean CertSubjectPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -494,7 +493,7 @@ public class ConfigureOCSP {
         return true;
     }
 
-    public boolean CertificatePanel() throws UnsupportedEncodingException {
+    public boolean CertificatePanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -526,7 +525,7 @@ public class ConfigureOCSP {
         return true;
     }
 
-    public boolean BackupPanel() throws UnsupportedEncodingException {
+    public boolean BackupPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -546,7 +545,7 @@ public class ConfigureOCSP {
         return true;
     }
 
-    public boolean SavePKCS12Panel() {
+    public boolean SavePKCS12Panel() throws Exception {
         HTTPResponse hr = null;
 
         String query_string = "";
@@ -594,7 +593,7 @@ public class ConfigureOCSP {
         return true;
     }
 
-    public boolean AdminCertReqPanel() throws UnsupportedEncodingException {
+    public boolean AdminCertReqPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -650,7 +649,7 @@ public class ConfigureOCSP {
         return true;
     }
 
-    public boolean AdminCertImportPanel() {
+    public boolean AdminCertImportPanel() throws Exception {
         boolean st = false;
         HTTPResponse hr = null;
 
@@ -689,7 +688,7 @@ public class ConfigureOCSP {
         return true;
     }
 
-    public boolean UpdateDomainPanel() throws UnsupportedEncodingException {
+    public boolean UpdateDomainPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -708,7 +707,7 @@ public class ConfigureOCSP {
         return true;
     }
 
-    public boolean ConfigureOCSPInstance() throws UnsupportedEncodingException {
+    public boolean ConfigureOCSPInstance() throws Exception {
         // 0. login to cert db
         ComCrypto cCrypt = new ComCrypto(client_certdb_dir,
                                         client_certdb_pwd,
@@ -854,7 +853,7 @@ public class ConfigureOCSP {
         }
     }
 
-    public static void main(String args[]) throws UnsupportedEncodingException {
+    public static void main(String args[]) throws Exception {
         ConfigureOCSP ca = new ConfigureOCSP();
 
         // set variables
diff --git a/base/silent/src/com/netscape/pkisilent/ConfigureRA.java b/base/silent/src/com/netscape/pkisilent/ConfigureRA.java
index 0188a126a8944e44991c817dc2561b69f16a7961..ed93a16f7d666a3a2489b477870c7afbd461a77e 100644
--- a/base/silent/src/com/netscape/pkisilent/ConfigureRA.java
+++ b/base/silent/src/com/netscape/pkisilent/ConfigureRA.java
@@ -19,16 +19,15 @@ package com.netscape.pkisilent;
 // --- END COPYRIGHT BLOCK ---
 
 import java.io.ByteArrayInputStream;
-import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
 
+import com.netscape.cmsutil.util.Utils;
 import com.netscape.pkisilent.argparser.ArgParser;
 import com.netscape.pkisilent.argparser.StringHolder;
 import com.netscape.pkisilent.common.ComCrypto;
 import com.netscape.pkisilent.common.ParseXML;
 import com.netscape.pkisilent.http.HTTPClient;
 import com.netscape.pkisilent.http.HTTPResponse;
-import com.netscape.cmsutil.util.Utils;
 
 public class ConfigureRA {
 
@@ -121,7 +120,7 @@ public class ConfigureRA {
 
     }
 
-    public boolean LoginPanel() {
+    public boolean LoginPanel() throws Exception {
         boolean st = false;
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
@@ -159,7 +158,7 @@ public class ConfigureRA {
         return st;
     }
 
-    public boolean DomainPanel() throws UnsupportedEncodingException {
+    public boolean DomainPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -184,7 +183,7 @@ public class ConfigureRA {
 
     }
 
-    public boolean DisplayChainPanel() {
+    public boolean DisplayChainPanel() throws Exception {
         String query_string = "p=2" + "&op=next" + "&xml=true";
         hc.sslConnect(cs_hostname, cs_port, wizard_uri, query_string);
 
@@ -192,7 +191,7 @@ public class ConfigureRA {
 
     }
 
-    public boolean SecurityDomainLoginPanel() throws UnsupportedEncodingException {
+    public boolean SecurityDomainLoginPanel() throws Exception {
         HTTPResponse hr = null;
 
         String ra_url = "https://" + cs_hostname + ":" + cs_port +
@@ -236,7 +235,7 @@ public class ConfigureRA {
 
     }
 
-    public boolean SubsystemPanel() throws UnsupportedEncodingException {
+    public boolean SubsystemPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -272,7 +271,7 @@ public class ConfigureRA {
         return true;
     }
 
-    public boolean DBPanel() {
+    public boolean DBPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -291,7 +290,7 @@ public class ConfigureRA {
         return true;
     }
 
-    public boolean TokenChoicePanel() throws UnsupportedEncodingException {
+    public boolean TokenChoicePanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -348,7 +347,7 @@ public class ConfigureRA {
         return true;
     }
 
-    public boolean KeyPanel() {
+    public boolean KeyPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -376,7 +375,7 @@ public class ConfigureRA {
         return true;
     }
 
-    public boolean CertSubjectPanel() throws UnsupportedEncodingException {
+    public boolean CertSubjectPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -404,7 +403,7 @@ public class ConfigureRA {
         return true;
     }
 
-    public boolean CertificatePanel() {
+    public boolean CertificatePanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -427,7 +426,7 @@ public class ConfigureRA {
         return true;
     }
 
-    public boolean AdminCertReqPanel() throws UnsupportedEncodingException {
+    public boolean AdminCertReqPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -495,7 +494,7 @@ public class ConfigureRA {
         return true;
     }
 
-    public boolean AdminCertImportPanel() throws UnsupportedEncodingException {
+    public boolean AdminCertImportPanel() throws Exception {
         boolean st = false;
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
@@ -563,7 +562,7 @@ public class ConfigureRA {
         return true;
     }
 
-    public boolean ConfigureRAInstance() throws UnsupportedEncodingException {
+    public boolean ConfigureRAInstance() throws Exception {
         // 0. login to cert db
         ComCrypto cCrypt = new ComCrypto(client_certdb_dir,
                                         client_certdb_pwd,
@@ -677,7 +676,7 @@ public class ConfigureRA {
         return true;
     }
 
-    public static void main(String args[]) throws UnsupportedEncodingException {
+    public static void main(String args[]) throws Exception {
         ConfigureRA ca = new ConfigureRA();
 
         // set variables
diff --git a/base/silent/src/com/netscape/pkisilent/ConfigureSubCA.java b/base/silent/src/com/netscape/pkisilent/ConfigureSubCA.java
index 32fe687a86b2173ee1a16e7e7c0967721d7ecca7..6147d256ae5dbbc908aeb1cc8deabf43a477bbb9 100644
--- a/base/silent/src/com/netscape/pkisilent/ConfigureSubCA.java
+++ b/base/silent/src/com/netscape/pkisilent/ConfigureSubCA.java
@@ -19,7 +19,6 @@ package com.netscape.pkisilent;
 // --- END COPYRIGHT BLOCK ---
 
 import java.io.ByteArrayInputStream;
-import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
 import java.util.ArrayList;
 
@@ -174,7 +173,7 @@ public class ConfigureSubCA {
 
     }
 
-    public boolean LoginPanel() {
+    public boolean LoginPanel() throws Exception {
         boolean st = false;
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
@@ -210,7 +209,7 @@ public class ConfigureSubCA {
         return st;
     }
 
-    public boolean TokenChoicePanel() throws UnsupportedEncodingException {
+    public boolean TokenChoicePanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -261,7 +260,7 @@ public class ConfigureSubCA {
         return true;
     }
 
-    public boolean DomainPanel() throws UnsupportedEncodingException {
+    public boolean DomainPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -294,7 +293,7 @@ public class ConfigureSubCA {
 
     }
 
-    public boolean SecurityDomainLoginPanel() throws UnsupportedEncodingException {
+    public boolean SecurityDomainLoginPanel() throws Exception {
         String subca_url = "https://" + cs_hostname + ":" + cs_port +
                             "/ca/admin/console/config/wizard" +
                             "?p=5&subsystem=CA";
@@ -332,7 +331,7 @@ public class ConfigureSubCA {
 
     }
 
-    public boolean DisplayChainPanel() throws UnsupportedEncodingException {
+    public boolean DisplayChainPanel() throws Exception {
         String query_string = "p=5" + "&op=next" + "&xml=true" +
                         "&choice=newsubsystem" +
                         "&subsystemName=" +
@@ -349,7 +348,7 @@ public class ConfigureSubCA {
         return true;
     }
 
-    public boolean HierarchyPanel() {
+    public boolean HierarchyPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -368,7 +367,7 @@ public class ConfigureSubCA {
 
     }
 
-    public boolean LdapConnectionPanel() throws UnsupportedEncodingException {
+    public boolean LdapConnectionPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -394,7 +393,7 @@ public class ConfigureSubCA {
         return true;
     }
 
-    public boolean KeyPanel() {
+    public boolean KeyPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -467,7 +466,7 @@ public class ConfigureSubCA {
         return true;
     }
 
-    public boolean CertSubjectPanel() throws UnsupportedEncodingException {
+    public boolean CertSubjectPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -553,7 +552,7 @@ public class ConfigureSubCA {
         return true;
     }
 
-    public boolean CertificatePanel() throws UnsupportedEncodingException {
+    public boolean CertificatePanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -586,7 +585,7 @@ public class ConfigureSubCA {
         return true;
     }
 
-    public boolean BackupPanel() throws UnsupportedEncodingException {
+    public boolean BackupPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -627,7 +626,7 @@ public class ConfigureSubCA {
         }
     }
 
-    public boolean AdminCertReqPanel() throws UnsupportedEncodingException {
+    public boolean AdminCertReqPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -685,7 +684,7 @@ public class ConfigureSubCA {
         return true;
     }
 
-    public boolean AdminCertImportPanel() {
+    public boolean AdminCertImportPanel() throws Exception {
         boolean st = false;
 
         String query_string = "serialNumber=" + admin_serial_number +
@@ -724,7 +723,7 @@ public class ConfigureSubCA {
         return true;
     }
 
-    public boolean UpdateDomainPanel() throws UnsupportedEncodingException {
+    public boolean UpdateDomainPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -755,7 +754,7 @@ public class ConfigureSubCA {
         return true;
     }
 
-    public boolean ConfigureSubCAInstance() throws UnsupportedEncodingException {
+    public boolean ConfigureSubCAInstance() throws Exception {
         // 0. login to cert db
         ComCrypto cCrypt = new ComCrypto(client_certdb_dir,
                                         client_certdb_pwd,
@@ -900,7 +899,7 @@ public class ConfigureSubCA {
         }
     }
 
-    public static void main(String args[]) throws UnsupportedEncodingException {
+    public static void main(String args[]) throws Exception {
         ConfigureSubCA ca = new ConfigureSubCA();
 
         // set variables
diff --git a/base/silent/src/com/netscape/pkisilent/ConfigureTKS.java b/base/silent/src/com/netscape/pkisilent/ConfigureTKS.java
index 77f8ae0bcd52afdb67713e3b948aac87c630da6b..aa8dccee843f1a43052a7bf27356c5a83b154c64 100644
--- a/base/silent/src/com/netscape/pkisilent/ConfigureTKS.java
+++ b/base/silent/src/com/netscape/pkisilent/ConfigureTKS.java
@@ -24,7 +24,6 @@ import java.io.ByteArrayInputStream;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.InputStreamReader;
-import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
 import java.util.ArrayList;
 
@@ -32,13 +31,13 @@ import org.mozilla.jss.asn1.SEQUENCE;
 import org.mozilla.jss.pkcs12.AuthenticatedSafes;
 import org.mozilla.jss.pkcs12.PFX;
 
+import com.netscape.cmsutil.util.Utils;
 import com.netscape.pkisilent.argparser.ArgParser;
 import com.netscape.pkisilent.argparser.StringHolder;
 import com.netscape.pkisilent.common.ComCrypto;
 import com.netscape.pkisilent.common.ParseXML;
 import com.netscape.pkisilent.http.HTTPClient;
 import com.netscape.pkisilent.http.HTTPResponse;
-import com.netscape.cmsutil.util.Utils;
 
 public class ConfigureTKS {
 
@@ -155,7 +154,7 @@ public class ConfigureTKS {
         }
     }
 
-    public boolean LoginPanel() {
+    public boolean LoginPanel() throws Exception {
         boolean st = false;
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
@@ -191,7 +190,7 @@ public class ConfigureTKS {
         return st;
     }
 
-    public boolean TokenChoicePanel() throws UnsupportedEncodingException {
+    public boolean TokenChoicePanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -240,7 +239,7 @@ public class ConfigureTKS {
         return true;
     }
 
-    public boolean DomainPanel() throws UnsupportedEncodingException {
+    public boolean DomainPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -265,7 +264,7 @@ public class ConfigureTKS {
 
     }
 
-    public boolean DisplayChainPanel() {
+    public boolean DisplayChainPanel() throws Exception {
         String query_string = "p=4" + "&op=next" + "&xml=true";
         hc.sslConnect(cs_hostname, cs_port, wizard_uri, query_string);
         // parse xml
@@ -277,7 +276,7 @@ public class ConfigureTKS {
 
     }
 
-    public boolean SecurityDomainLoginPanel() throws UnsupportedEncodingException {
+    public boolean SecurityDomainLoginPanel() throws Exception {
         String tks_url = "https://" + cs_hostname + ":" + cs_port +
                             "/tks/admin/console/config/wizard" +
                             "?p=5&subsystem=TKS";
@@ -320,7 +319,7 @@ public class ConfigureTKS {
 
     }
 
-    public boolean SubsystemPanel() throws UnsupportedEncodingException {
+    public boolean SubsystemPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -339,7 +338,7 @@ public class ConfigureTKS {
         return true;
     }
 
-    public boolean LdapConnectionPanel() throws UnsupportedEncodingException {
+    public boolean LdapConnectionPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -365,7 +364,7 @@ public class ConfigureTKS {
         return true;
     }
 
-    public boolean KeyPanel() {
+    public boolean KeyPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -419,7 +418,7 @@ public class ConfigureTKS {
         return true;
     }
 
-    public boolean CertSubjectPanel() throws UnsupportedEncodingException {
+    public boolean CertSubjectPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -471,7 +470,7 @@ public class ConfigureTKS {
         return true;
     }
 
-    public boolean CertificatePanel() throws UnsupportedEncodingException {
+    public boolean CertificatePanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -499,7 +498,7 @@ public class ConfigureTKS {
         return true;
     }
 
-    public boolean BackupPanel() throws UnsupportedEncodingException {
+    public boolean BackupPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -519,7 +518,7 @@ public class ConfigureTKS {
         return true;
     }
 
-    public boolean SavePKCS12Panel() {
+    public boolean SavePKCS12Panel() throws Exception {
         String query_string = "";
 
         HTTPResponse hr = hc.sslConnect(cs_hostname, cs_port, pkcs12_uri, query_string);
@@ -565,7 +564,7 @@ public class ConfigureTKS {
         return true;
     }
 
-    public boolean AdminCertReqPanel() throws UnsupportedEncodingException {
+    public boolean AdminCertReqPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -622,7 +621,7 @@ public class ConfigureTKS {
         return true;
     }
 
-    public boolean AdminCertImportPanel() {
+    public boolean AdminCertImportPanel() throws Exception {
         boolean st = false;
 
         String query_string = "serialNumber=" + admin_serial_number +
@@ -660,7 +659,7 @@ public class ConfigureTKS {
         return true;
     }
 
-    public boolean UpdateDomainPanel() throws UnsupportedEncodingException {
+    public boolean UpdateDomainPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -680,7 +679,7 @@ public class ConfigureTKS {
         return true;
     }
 
-    public boolean ConfigureTKSInstance() throws UnsupportedEncodingException {
+    public boolean ConfigureTKSInstance() throws Exception {
         // 0. login to cert db
         ComCrypto cCrypt = new ComCrypto(client_certdb_dir,
                                         client_certdb_pwd,
@@ -827,7 +826,7 @@ public class ConfigureTKS {
         }
     }
 
-    public static void main(String args[]) throws UnsupportedEncodingException {
+    public static void main(String args[]) throws Exception {
         ConfigureTKS ca = new ConfigureTKS();
 
         // set variables
diff --git a/base/silent/src/com/netscape/pkisilent/ConfigureTPS.java b/base/silent/src/com/netscape/pkisilent/ConfigureTPS.java
index f3522d75df5365a6bb42c005fe799371c09175c3..f23b605fa9c4f4b25833e508031dd534205d2122 100644
--- a/base/silent/src/com/netscape/pkisilent/ConfigureTPS.java
+++ b/base/silent/src/com/netscape/pkisilent/ConfigureTPS.java
@@ -19,16 +19,15 @@ package com.netscape.pkisilent;
 // --- END COPYRIGHT BLOCK ---
 
 import java.io.ByteArrayInputStream;
-import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
 
+import com.netscape.cmsutil.util.Utils;
 import com.netscape.pkisilent.argparser.ArgParser;
 import com.netscape.pkisilent.argparser.StringHolder;
 import com.netscape.pkisilent.common.ComCrypto;
 import com.netscape.pkisilent.common.ParseXML;
 import com.netscape.pkisilent.http.HTTPClient;
 import com.netscape.pkisilent.http.HTTPResponse;
-import com.netscape.cmsutil.util.Utils;
 
 public class ConfigureTPS {
     // define global variables
@@ -156,7 +155,7 @@ public class ConfigureTPS {
 
     }
 
-    public boolean LoginPanel() {
+    public boolean LoginPanel() throws Exception {
         boolean st = false;
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
@@ -194,7 +193,7 @@ public class ConfigureTPS {
         return st;
     }
 
-    public boolean DomainPanel() throws UnsupportedEncodingException {
+    public boolean DomainPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -219,7 +218,7 @@ public class ConfigureTPS {
 
     }
 
-    public boolean DisplayChainPanel() {
+    public boolean DisplayChainPanel() throws Exception {
         String query_string = "p=4" + "&op=next" + "&xml=true";
         hc.sslConnect(cs_hostname, cs_port, wizard_uri, query_string);
 
@@ -227,7 +226,7 @@ public class ConfigureTPS {
 
     }
 
-    public boolean SecurityDomainLoginPanel() throws UnsupportedEncodingException {
+    public boolean SecurityDomainLoginPanel() throws Exception {
         String tps_url = "https://" + cs_hostname + ":" + cs_port +
                             "/tps/admin/console/config/wizard" +
                             "?p=3&subsystem=TPS";
@@ -269,7 +268,7 @@ public class ConfigureTPS {
 
     }
 
-    public boolean SubsystemPanel() throws UnsupportedEncodingException {
+    public boolean SubsystemPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -336,7 +335,7 @@ public class ConfigureTPS {
         return true;
     }
 
-    public boolean LdapAuthConnectionPanel() throws UnsupportedEncodingException {
+    public boolean LdapAuthConnectionPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -361,7 +360,7 @@ public class ConfigureTPS {
         return true;
     }
 
-    public boolean LdapConnectionPanel() throws UnsupportedEncodingException {
+    public boolean LdapConnectionPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -393,7 +392,7 @@ public class ConfigureTPS {
         return true;
     }
 
-    public boolean TokenChoicePanel() throws UnsupportedEncodingException {
+    public boolean TokenChoicePanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -450,7 +449,7 @@ public class ConfigureTPS {
         return true;
     }
 
-    public boolean KeyPanel() {
+    public boolean KeyPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -481,7 +480,7 @@ public class ConfigureTPS {
         return true;
     }
 
-    public boolean CertSubjectPanel() throws UnsupportedEncodingException {
+    public boolean CertSubjectPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -515,7 +514,7 @@ public class ConfigureTPS {
         return true;
     }
 
-    public boolean CertificatePanel() {
+    public boolean CertificatePanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -540,7 +539,7 @@ public class ConfigureTPS {
         return true;
     }
 
-    public boolean AdminCertReqPanel() throws UnsupportedEncodingException {
+    public boolean AdminCertReqPanel() throws Exception {
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
         ParseXML px = new ParseXML();
@@ -608,7 +607,7 @@ public class ConfigureTPS {
         return true;
     }
 
-    public boolean AdminCertImportPanel() throws UnsupportedEncodingException {
+    public boolean AdminCertImportPanel() throws Exception {
         boolean st = false;
         HTTPResponse hr = null;
         ByteArrayInputStream bais = null;
@@ -676,7 +675,7 @@ public class ConfigureTPS {
         return true;
     }
 
-    public boolean ConfigureTPSInstance() throws UnsupportedEncodingException {
+    public boolean ConfigureTPSInstance() throws Exception {
         // 0. login to cert db
         ComCrypto cCrypt = new ComCrypto(client_certdb_dir,
                                         client_certdb_pwd,
@@ -798,7 +797,7 @@ public class ConfigureTPS {
         return true;
     }
 
-    public static void main(String args[]) throws UnsupportedEncodingException {
+    public static void main(String args[]) throws Exception {
         ConfigureTPS ca = new ConfigureTPS();
 
         // set variables
diff --git a/base/silent/src/com/netscape/pkisilent/http/HTTPClient.java b/base/silent/src/com/netscape/pkisilent/http/HTTPClient.java
index 80335c61f9629f9d239ce1ac1a4e6c9beab7cc8e..63156548b0b6bd5ea29b0a53c7d5f8e2137d335f 100644
--- a/base/silent/src/com/netscape/pkisilent/http/HTTPClient.java
+++ b/base/silent/src/com/netscape/pkisilent/http/HTTPClient.java
@@ -275,10 +275,12 @@ public class HTTPClient implements SSLCertificateApprovalCallback {
     // posts the given query data
     // returns HTTPResponse
     public HTTPResponse sslConnect(String hostname, String portnumber,
-                                String url, String query) {
+                                String url, String query) throws Exception {
 
-        boolean st = true;
-        HTTPResponse hr = null;
+        SSLSocket socket = null;
+        OutputStream rawos = null;
+        BufferedOutputStream os = null;
+        PrintStream ps = null;
 
         try {
 
@@ -295,7 +297,7 @@ public class HTTPClient implements SSLCertificateApprovalCallback {
                                 new TestClientCertificateSelectionCallback();
 
             Socket js = new Socket(InetAddress.getByName(hostname), port);
-            SSLSocket socket = new SSLSocket(js, hostname, approvalCallback,
+            socket = new SSLSocket(js, hostname, approvalCallback,
                         certSelectionCallback);
             setCipherPref(socket);
             disableSSL2(socket);
@@ -309,9 +311,9 @@ public class HTTPClient implements SSLCertificateApprovalCallback {
                                 "/" + url +
                                 "?" + query);
 
-            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 " + url + " HTTP/1.0");
 
@@ -335,37 +337,21 @@ public class HTTPClient implements SSLCertificateApprovalCallback {
             ps.flush();
             os.flush();
 
-            try {
-                hr = readResponse(socket.getInputStream());
-                hr.parseContent();
+            HTTPResponse hr = readResponse(socket.getInputStream());
+            hr.parseContent();
 
-            } catch (Exception e) {
-                System.out.println("Exception");
-                e.printStackTrace();
-                st = false;
-            }
-
-            socket.close();
-            os.close();
-            rawos.close();
-            ps.close();
-
-            os = null;
-            rawos = null;
-            ps = null;
-
-        }
-
-        catch (Exception e) {
-            System.err.println("Exception: Unable to Send Request:" + e);
-            e.printStackTrace();
-            st = false;
-        }
-
-        if (!st)
-            return null;
-        else
             return hr;
+
+        } catch (Exception e) {
+            System.err.println("Exception: Unable to Send Request:" + e);
+            throw e;
+
+        } finally {
+            if (ps != null) try { ps.close(); } catch (Exception e) { e.printStackTrace(); }
+            if (os != null) try { os.close(); } catch (Exception e) { e.printStackTrace(); }
+            if (rawos != null) try { rawos.close(); } catch (Exception e) { e.printStackTrace(); }
+            if (socket != null) try { socket.close(); } catch (Exception e) { e.printStackTrace(); }
+        }
     }
 
     // performs non ssl connect to given host/port
@@ -374,8 +360,11 @@ public class HTTPClient implements SSLCertificateApprovalCallback {
     public HTTPResponse nonsslConnect(String hostname, String portnumber,
                                 String url, String query) throws Exception {
 
-        HTTPResponse hr = null;
+        Socket socket = null;
+        OutputStream rawos = null;
+        BufferedOutputStream os = null;
         PrintStream ps = null;
+
         try {
 
             System.out.println("#############################################");
@@ -385,7 +374,7 @@ public class HTTPClient implements SSLCertificateApprovalCallback {
             Integer x = new Integer(portnumber);
             int port = x.intValue();
 
-            Socket socket = new Socket(hostname, port);
+            socket = new Socket(hostname, port);
 
             System.out.println("Posting Query = " +
                                 "http://" + hostname +
@@ -393,8 +382,8 @@ public class HTTPClient implements SSLCertificateApprovalCallback {
                                 "/" + url +
                                 "?" + query);
 
-            OutputStream rawos = socket.getOutputStream();
-            BufferedOutputStream os = new BufferedOutputStream(rawos);
+            rawos = socket.getOutputStream();
+            os = new BufferedOutputStream(rawos);
             ps = new PrintStream(os);
 
             System.out.println("Connected.");
@@ -421,21 +410,21 @@ public class HTTPClient implements SSLCertificateApprovalCallback {
             ps.flush();
             os.flush();
 
-                hr = readResponse(socket.getInputStream());
-                hr.parseContent();
+            HTTPResponse hr = readResponse(socket.getInputStream());
+            hr.parseContent();
+
+            return hr;
 
         } catch (Exception e) {
             System.err.println("Exception: Unable to Send Request:" + e);
-            e.printStackTrace();
             throw e;
+
         } finally {
-            if (ps != null) {
-                ps.close();
-                ps = null;
-            }
+            if (ps != null) try { ps.close(); } catch (Exception e) { e.printStackTrace(); }
+            if (os != null) try { os.close(); } catch (Exception e) { e.printStackTrace(); }
+            if (rawos != null) try { rawos.close(); } catch (Exception e) { e.printStackTrace(); }
+            if (socket != null) try { socket.close(); } catch (Exception e) { e.printStackTrace(); }
         }
-
-        return hr;
     }
 
     public HTTPResponse readResponse(InputStream inputStream)
-- 
1.7.7.6

