>From 02713ae6bc13d7945021faf34fe86c68365051bc Mon Sep 17 00:00:00 2001
From: Abhishek Koneru <akoneru@redhat.com>
Date: Mon, 25 Jun 2012 13:55:39 -0400
Subject: [PATCH] Fixes for comments for Patch 15-2

---
 .../src/com/netscape/cmstools/HttpClient.java      |   95 +++++++++-----------
 .../src/com/netscape/cmstools/PasswordCache.java   |   10 ++-
 2 files changed, 48 insertions(+), 57 deletions(-)

diff --git a/base/java-tools/src/com/netscape/cmstools/HttpClient.java b/base/java-tools/src/com/netscape/cmstools/HttpClient.java
index d56b7df70423fae17e6ef4538b58f75edecd84b2..a3e27c70ed194f01f0dc788f4c20cf32d9f25b87 100644
--- a/base/java-tools/src/com/netscape/cmstools/HttpClient.java
+++ b/base/java-tools/src/com/netscape/cmstools/HttpClient.java
@@ -118,66 +118,55 @@ public class HttpClient {
 
             System.out.println("Total number of bytes read = " + b.length);
             if (_secure) {
-                try {
-                    CryptoManager.InitializationValues vals =
-                            new CryptoManager.InitializationValues(dbdir, "", "", "secmod.db");
-                    CryptoManager.initialize(vals);
-                    sslSocket = new SSLSocket(_host, _port);
-                    int i;
+                CryptoManager.InitializationValues vals =
+                        new CryptoManager.InitializationValues(dbdir, "", "", "secmod.db");
+                CryptoManager.initialize(vals);
+                sslSocket = new SSLSocket(_host, _port);
+                int i;
 
-                    for (i = SSLSocket.SSL2_RC4_128_WITH_MD5; i <= SSLSocket.SSL2_RC2_128_CBC_EXPORT40_WITH_MD5; ++i) {
-                        try {
-                            sslSocket.setCipherPreference(i, true);
-                        } catch (SocketException e) {
-                        }
+                for (i = SSLSocket.SSL2_RC4_128_WITH_MD5; i <= SSLSocket.SSL2_RC2_128_CBC_EXPORT40_WITH_MD5; ++i) {
+                    try {
+                        sslSocket.setCipherPreference(i, true);
+                    } catch (SocketException e) {
                     }
-                    //skip SSL_EN_IDEA_128_EDE3_CBC_WITH_MD5
-                    for (i = SSLSocket.SSL2_DES_64_CBC_WITH_MD5; i <= SSLSocket.SSL2_DES_192_EDE3_CBC_WITH_MD5; ++i) {
-                        try {
-                            sslSocket.setCipherPreference(i, true);
-                        } catch (SocketException e) {
-                        }
-                    }
-                    for (i = 0; cipherSuites[i] != 0; ++i) {
-                        try {
-                            sslSocket.setCipherPreference(cipherSuites[i], true);
-                        } catch (SocketException e) {
-                        }
+                }
+                //skip SSL_EN_IDEA_128_EDE3_CBC_WITH_MD5
+                for (i = SSLSocket.SSL2_DES_64_CBC_WITH_MD5; i <= SSLSocket.SSL2_DES_192_EDE3_CBC_WITH_MD5; ++i) {
+                    try {
+                        sslSocket.setCipherPreference(i, true);
+                    } catch (SocketException e) {
                     }
-                    SSLHandshakeCompletedListener listener = new ClientHandshakeCB(this);
-                    sslSocket.addHandshakeCompletedListener(listener);
-
-                    if (clientmode != null && clientmode.equals("true")) {
-                        CryptoManager cm = CryptoManager.getInstance();
-                        CryptoToken token = cm.getInternalKeyStorageToken();
-                        Password pass = new Password(password.toCharArray());
-                        token.login(pass);
-                        X509Certificate cert = cm.findCertByNickname(nickname);
-                        if (cert == null)
-                            System.out.println("client cert is null");
-                        else
-                            System.out.println("client cert is not null");
-                        sslSocket.setUseClientMode(true);
-                        sslSocket.setClientCertNickname(nickname);
+                }
+                for (i = 0; cipherSuites[i] != 0; ++i) {
+                    try {
+                        sslSocket.setCipherPreference(cipherSuites[i], true);
+                    } catch (SocketException e) {
                     }
+                }
+                SSLHandshakeCompletedListener listener = new ClientHandshakeCB(this);
+                sslSocket.addHandshakeCompletedListener(listener);
 
-                    sslSocket.forceHandshake();
-                    dos = new DataOutputStream(sslSocket.getOutputStream());
-                    is = sslSocket.getInputStream();
-                } catch (Exception e) {
-                    System.out.println("Exception: " + e.toString());
-                    return;
+                if (clientmode != null && clientmode.equals("true")) {
+                    CryptoManager cm = CryptoManager.getInstance();
+                    CryptoToken token = cm.getInternalKeyStorageToken();
+                    Password pass = new Password(password.toCharArray());
+                    token.login(pass);
+                    X509Certificate cert = cm.findCertByNickname(nickname);
+                    if (cert == null)
+                        System.out.println("client cert is null");
+                    else
+                        System.out.println("client cert is not null");
+                    sslSocket.setUseClientMode(true);
+                    sslSocket.setClientCertNickname(nickname);
                 }
+
+                sslSocket.forceHandshake();
+                dos = new DataOutputStream(sslSocket.getOutputStream());
+                is = sslSocket.getInputStream();
             } else {
-
-                try {
-                    socket = new Socket(_host, _port);
-                    dos = new DataOutputStream(socket.getOutputStream());
-                    is = socket.getInputStream();
-                } catch (IOException e) {
-                    e.printStackTrace();
-                    return;
-                }
+                socket = new Socket(_host, _port);
+                dos = new DataOutputStream(socket.getOutputStream());
+                is = socket.getInputStream();
             }
 
             // send request
diff --git a/base/java-tools/src/com/netscape/cmstools/PasswordCache.java b/base/java-tools/src/com/netscape/cmstools/PasswordCache.java
index a08e0c9ad8377c407680927fdce01ce259c4f937..dbc52a02ab3317270fc0f1b2c440a265063faf35 100644
--- a/base/java-tools/src/com/netscape/cmstools/PasswordCache.java
+++ b/base/java-tools/src/com/netscape/cmstools/PasswordCache.java
@@ -200,10 +200,12 @@ public class PasswordCache {
                     System.out.println("Error: " + e.toString());
                     System.exit(1);
                 } finally {
-                    try {
-                        r.close();
-                    } catch (IOException e) {
-                        e.printStackTrace();
+                    if (r != null) {
+                        try {
+                            r.close();
+                        } catch (IOException e) {
+                            e.printStackTrace();
+                        }
                     }
                 }
 
-- 
1.7.10.2

