diff options
Diffstat (limited to 'pki/base/common/src/com/netscape/cmscore/base/ArgBlock.java')
-rw-r--r-- | pki/base/common/src/com/netscape/cmscore/base/ArgBlock.java | 292 |
1 files changed, 148 insertions, 144 deletions
diff --git a/pki/base/common/src/com/netscape/cmscore/base/ArgBlock.java b/pki/base/common/src/com/netscape/cmscore/base/ArgBlock.java index 10cc7a05f..b231a72f2 100644 --- a/pki/base/common/src/com/netscape/cmscore/base/ArgBlock.java +++ b/pki/base/common/src/com/netscape/cmscore/base/ArgBlock.java @@ -17,7 +17,6 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.base; - import java.io.IOException; import java.math.BigInteger; import java.security.NoSuchAlgorithmException; @@ -34,12 +33,10 @@ import com.netscape.certsrv.base.EBaseException; import com.netscape.certsrv.base.IArgBlock; import com.netscape.certsrv.base.KeyGenInfo; - /** - * This class represents a set of indexed arguments. - * Each argument is indexed by a key, which can be - * used during the argument retrieval. - * + * This class represents a set of indexed arguments. Each argument is indexed by + * a key, which can be used during the argument retrieval. + * * @version $Revision$, $Date$ */ public class ArgBlock implements IArgBlock { @@ -48,48 +45,45 @@ public class ArgBlock implements IArgBlock { * */ private static final long serialVersionUID = -6054531129316353282L; - /*========================================================== - * variables - *==========================================================*/ - public static final String - CERT_NEW_REQUEST_HEADER = "-----BEGIN NEW CERTIFICATE REQUEST-----"; - public static final String - CERT_NEW_REQUEST_TRAILER = "-----END NEW CERTIFICATE REQUEST-----"; - public static final String - CERT_REQUEST_HEADER = "-----BEGIN CERTIFICATE REQUEST-----"; - public static final String - CERT_REQUEST_TRAILER = "-----END CERTIFICATE REQUEST-----"; - public static final String - CERT_RENEWAL_HEADER = "-----BEGIN RENEWAL CERTIFICATE REQUEST-----"; - public static final String - CERT_RENEWAL_TRAILER = "-----END RENEWAL CERTIFICATE REQUEST-----"; + /* + * ========================================================== variables + * ========================================================== + */ + public static final String CERT_NEW_REQUEST_HEADER = "-----BEGIN NEW CERTIFICATE REQUEST-----"; + public static final String CERT_NEW_REQUEST_TRAILER = "-----END NEW CERTIFICATE REQUEST-----"; + public static final String CERT_REQUEST_HEADER = "-----BEGIN CERTIFICATE REQUEST-----"; + public static final String CERT_REQUEST_TRAILER = "-----END CERTIFICATE REQUEST-----"; + public static final String CERT_RENEWAL_HEADER = "-----BEGIN RENEWAL CERTIFICATE REQUEST-----"; + public static final String CERT_RENEWAL_TRAILER = "-----END RENEWAL CERTIFICATE REQUEST-----"; private Hashtable mArgs = new Hashtable(); - private String mType = "unspecified-argblock"; + private String mType = "unspecified-argblock"; - /*========================================================== - * constructors - *==========================================================*/ + /* + * ========================================================== constructors + * ========================================================== + */ /** * Constructs an argument block with the given hashtable values. + * * @param realm the type of argblock - used for debugging the values */ public ArgBlock(String realm, Hashtable httpReq) { - mType = realm; - populate(httpReq); - } - + mType = realm; + populate(httpReq); + } + /** * Constructs an argument block with the given hashtable values. - * + * * @param httpReq hashtable keys and values */ public ArgBlock(Hashtable httpReq) { - populate(httpReq); - } + populate(httpReq); + } - private void populate(Hashtable httpReq) { + private void populate(Hashtable httpReq) { // Add all parameters from the request Enumeration e = httpReq.keys(); @@ -109,18 +103,19 @@ public class ArgBlock implements IArgBlock { public ArgBlock() { } - /*========================================================== - * public methods - *==========================================================*/ + /* + * ========================================================== public methods + * ========================================================== + */ /** * Checks if this argument block contains the given key. - * + * * @param n key * @return true if key is present */ public boolean isValuePresent(String n) { - CMS.traceHashKey(mType, n); + CMS.traceHashKey(mType, n); if (mArgs.get(n) != null) { return true; } else { @@ -130,7 +125,7 @@ public class ArgBlock implements IArgBlock { /** * Adds string-based value into this argument block. - * + * * @param n key * @param v value * @return value @@ -145,32 +140,33 @@ public class ArgBlock implements IArgBlock { /** * Retrieves argument value as string. - * + * * @param n key * @return argument value as string * @exception EBaseException failed to retrieve value */ public String getValueAsString(String n) throws EBaseException { - String t= (String)mArgs.get(n); - CMS.traceHashKey(mType, n, t); + String t = (String) mArgs.get(n); + CMS.traceHashKey(mType, n, t); if (t != null) { return t; } else { - throw new EBaseException(CMS.getUserMessage("CMS_BASE_ATTRIBUTE_NOT_FOUND", n)); + throw new EBaseException(CMS.getUserMessage( + "CMS_BASE_ATTRIBUTE_NOT_FOUND", n)); } } /** * Retrieves argument value as string. - * + * * @param n key * @param def default value to be returned if key is not present * @return argument value as string */ public String getValueAsString(String n, String def) { String val = (String) mArgs.get(n); - CMS.traceHashKey(mType, n, val, def); + CMS.traceHashKey(mType, n, val, def); if (val != null) { return val; @@ -181,35 +177,36 @@ public class ArgBlock implements IArgBlock { /** * Retrieves argument value as integer. - * + * * @param n key * @return argument value as int * @exception EBaseException failed to retrieve value */ public int getValueAsInt(String n) throws EBaseException { if (mArgs.get(n) != null) { - CMS.traceHashKey(mType, n, (String)mArgs.get(n)); + CMS.traceHashKey(mType, n, (String) mArgs.get(n)); try { return new Integer((String) mArgs.get(n)).intValue(); } catch (NumberFormatException e) { - throw new EBaseException( - CMS.getUserMessage("CMS_BASE_INVALID_ATTR_TYPE", n, e.toString())); + throw new EBaseException(CMS.getUserMessage( + "CMS_BASE_INVALID_ATTR_TYPE", n, e.toString())); } } else { - CMS.traceHashKey(mType, n, "<notpresent>"); - throw new EBaseException(CMS.getUserMessage("CMS_BASE_ATTRIBUTE_NOT_FOUND", n)); + CMS.traceHashKey(mType, n, "<notpresent>"); + throw new EBaseException(CMS.getUserMessage( + "CMS_BASE_ATTRIBUTE_NOT_FOUND", n)); } } /** * Retrieves argument value as integer. - * + * * @param n key * @param def default value to be returned if key is not present * @return argument value as int */ public int getValueAsInt(String n, int def) { - CMS.traceHashKey(mType, n, (String)mArgs.get(n), ""+def); + CMS.traceHashKey(mType, n, (String) mArgs.get(n), "" + def); if (mArgs.get(n) != null) { try { return new Integer((String) mArgs.get(n)).intValue(); @@ -223,13 +220,12 @@ public class ArgBlock implements IArgBlock { /** * Retrieves argument value as big integer. - * + * * @param n key * @return argument value as big integer * @exception EBaseException failed to retrieve value */ - public BigInteger getValueAsBigInteger(String n) - throws EBaseException { + public BigInteger getValueAsBigInteger(String n) throws EBaseException { String v = (String) mArgs.get(n); if (v != null) { @@ -239,18 +235,19 @@ public class ArgBlock implements IArgBlock { try { return new BigInteger(v, 16); } catch (NumberFormatException ex) { - throw new EBaseException( - CMS.getUserMessage("CMS_BASE_INVALID_ATTR_TYPE", n, ex.toString())); + throw new EBaseException(CMS.getUserMessage( + "CMS_BASE_INVALID_ATTR_TYPE", n, ex.toString())); } } } else { - throw new EBaseException(CMS.getUserMessage("CMS_BASE_ATTRIBUTE_NOT_FOUND", n)); + throw new EBaseException(CMS.getUserMessage( + "CMS_BASE_ATTRIBUTE_NOT_FOUND", n)); } } /** * Retrieves argument value as big integer. - * + * * @param n key * @param def default value to be returned if key is not present * @return argument value as big integer @@ -265,7 +262,7 @@ public class ArgBlock implements IArgBlock { /** * Retrieves argument value as object - * + * * @param n key * @return argument value as object * @exception EBaseException failed to retrieve value @@ -274,13 +271,14 @@ public class ArgBlock implements IArgBlock { if (mArgs.get(n) != null) { return mArgs.get(n); } else { - throw new EBaseException(CMS.getUserMessage("CMS_BASE_ATTRIBUTE_NOT_FOUND", (String) n)); + throw new EBaseException(CMS.getUserMessage( + "CMS_BASE_ATTRIBUTE_NOT_FOUND", (String) n)); } } /** * Retrieves argument value as object - * + * * @param n key * @param def default value to be returned if key is not present * @return argument value as object @@ -295,56 +293,56 @@ public class ArgBlock implements IArgBlock { /** * Gets boolean value. They should be "true" or "false". - * + * * @param name name of the input type * @return boolean type: <code>true</code> or <code>false</code> * @exception EBaseException failed to retrieve value */ - public boolean getValueAsBoolean(String name) throws EBaseException { + public boolean getValueAsBoolean(String name) throws EBaseException { String val = (String) mArgs.get(name); - CMS.traceHashKey(mType, name, val); + CMS.traceHashKey(mType, name, val); if (val != null) { - if (val.equalsIgnoreCase("true") || - val.equalsIgnoreCase("on")) + if (val.equalsIgnoreCase("true") || val.equalsIgnoreCase("on")) return true; else return false; } else { - throw new EBaseException(CMS.getUserMessage("CMS_BASE_ATTRIBUTE_NOT_FOUND", name)); + throw new EBaseException(CMS.getUserMessage( + "CMS_BASE_ATTRIBUTE_NOT_FOUND", name)); } } /** * Gets boolean value. They should be "true" or "false". - * + * * @param name name of the input type * @return boolean type: <code>true</code> or <code>false</code> */ public boolean getValueAsBoolean(String name, boolean def) { boolean val; - try { - val = getValueAsBoolean(name); + try { + val = getValueAsBoolean(name); return val; - } catch (EBaseException e) { - return def; + } catch (EBaseException e) { + return def; } } /** * Gets KeyGenInfo - * + * * @param name name of the input type * @param verify true if signature validation is required * @exception EBaseException * @return KeyGenInfo object */ public KeyGenInfo getValueAsKeyGenInfo(String name, KeyGenInfo def) - throws EBaseException { + throws EBaseException { KeyGenInfo keyGenInfo; - CMS.traceHashKey(mType, name); + CMS.traceHashKey(mType, name); if (mArgs.get(name) != null) { try { keyGenInfo = new KeyGenInfo((String) mArgs.get(name)); @@ -359,9 +357,9 @@ public class ArgBlock implements IArgBlock { } /** - * Gets PKCS10 request. This pkcs10 attribute does not - * contain header information. - * + * Gets PKCS10 request. This pkcs10 attribute does not contain header + * information. + * * @param name name of the input type * @return pkcs10 request * @exception EBaseException failed to retrieve value @@ -370,42 +368,43 @@ public class ArgBlock implements IArgBlock { PKCS10 request; if (mArgs.get(name) != null) { - CMS.traceHashKey(mType, name, (String)mArgs.get(name)); + CMS.traceHashKey(mType, name, (String) mArgs.get(name)); String tempStr = unwrap((String) mArgs.get(name), false); if (tempStr == null) { - throw new EBaseException( - CMS.getUserMessage("CMS_BASE_INVALID_ATTR_VALUE", name, "Empty Content")); + throw new EBaseException(CMS.getUserMessage( + "CMS_BASE_INVALID_ATTR_VALUE", name, "Empty Content")); } try { request = decodePKCS10(tempStr); } catch (Exception e) { - throw new EBaseException( - CMS.getUserMessage("CMS_BASE_INVALID_ATTR_VALUE", name, e.toString())); + throw new EBaseException(CMS.getUserMessage( + "CMS_BASE_INVALID_ATTR_VALUE", name, e.toString())); } } else { - CMS.traceHashKey(mType, name, "<notpresent>"); - throw new EBaseException(CMS.getUserMessage("CMS_BASE_ATTRIBUTE_NOT_FOUND", name)); + CMS.traceHashKey(mType, name, "<notpresent>"); + throw new EBaseException(CMS.getUserMessage( + "CMS_BASE_ATTRIBUTE_NOT_FOUND", name)); } return request; } /** - * Gets PKCS10 request. This pkcs10 attribute does not - * contain header information. - * + * Gets PKCS10 request. This pkcs10 attribute does not contain header + * information. + * * @param name name of the input type * @param def default PKCS10 * @return pkcs10 request * @exception EBaseException failed to retrieve value */ public PKCS10 getValueAsRawPKCS10(String name, PKCS10 def) - throws EBaseException { + throws EBaseException { PKCS10 request; - CMS.traceHashKey(mType, name); + CMS.traceHashKey(mType, name); if (mArgs.get(name) != null) { String tempStr = unwrap((String) mArgs.get(name), false); @@ -426,33 +425,34 @@ public class ArgBlock implements IArgBlock { /** * Retrieves PKCS10 - * - * @param name name of the input type + * + * @param name name of the input type * @param checkheader true if header must be present * @return PKCS10 object * @exception EBaseException failed to retrieve value */ - public PKCS10 getValueAsPKCS10(String name, boolean checkheader) - throws EBaseException { + public PKCS10 getValueAsPKCS10(String name, boolean checkheader) + throws EBaseException { PKCS10 request; - CMS.traceHashKey(mType, name); + CMS.traceHashKey(mType, name); if (mArgs.get(name) != null) { String tempStr = unwrap((String) mArgs.get(name), checkheader); if (tempStr == null) { - throw new EBaseException( - CMS.getUserMessage("CMS_BASE_INVALID_ATTR_VALUE", name, "Empty Content")); + throw new EBaseException(CMS.getUserMessage( + "CMS_BASE_INVALID_ATTR_VALUE", name, "Empty Content")); } try { request = decodePKCS10(tempStr); } catch (Exception e) { - throw new EBaseException( - CMS.getUserMessage("CMS_BASE_INVALID_ATTR_VALUE", name, e.toString())); + throw new EBaseException(CMS.getUserMessage( + "CMS_BASE_INVALID_ATTR_VALUE", name, e.toString())); } } else { - throw new EBaseException(CMS.getUserMessage("CMS_BASE_ATTRIBUTE_NOT_FOUND", name)); + throw new EBaseException(CMS.getUserMessage( + "CMS_BASE_ATTRIBUTE_NOT_FOUND", name)); } return request; @@ -460,19 +460,18 @@ public class ArgBlock implements IArgBlock { /** * Retrieves PKCS10 - * - * @param name name of the input type + * + * @param name name of the input type * @param checkheader true if header must be present * @param def default PKCS10 - * @return PKCS10 object + * @return PKCS10 object * @exception EBaseException */ - public PKCS10 getValueAsPKCS10( - String name, boolean checkheader, PKCS10 def) - throws EBaseException { + public PKCS10 getValueAsPKCS10(String name, boolean checkheader, PKCS10 def) + throws EBaseException { PKCS10 request; - CMS.traceHashKey(mType, name); + CMS.traceHashKey(mType, name); if (mArgs.get(name) != null) { @@ -495,17 +494,16 @@ public class ArgBlock implements IArgBlock { /** * Retrieves PKCS10 - * - * @param name name of the input type + * + * @param name name of the input type * @param def default PKCS10 - * @return PKCS10 object + * @return PKCS10 object * @exception EBaseException */ - public PKCS10 getValuePKCS10(String name, PKCS10 def) - throws EBaseException { + public PKCS10 getValuePKCS10(String name, PKCS10 def) throws EBaseException { PKCS10 request; String p10b64 = (String) mArgs.get(name); - CMS.traceHashKey(mType, name); + CMS.traceHashKey(mType, name); if (p10b64 != null) { @@ -522,7 +520,7 @@ public class ArgBlock implements IArgBlock { /** * Sets argument into this block. - * + * * @param name key * @param ob value */ @@ -532,18 +530,18 @@ public class ArgBlock implements IArgBlock { /** * Retrieves argument. - * + * * @param name key * @return object value */ public Object get(String name) { - CMS.traceHashKey(mType, name); + CMS.traceHashKey(mType, name); return mArgs.get(name); } /** * Deletes argument by the given key. - * + * * @param name key */ public void delete(String name) { @@ -552,7 +550,7 @@ public class ArgBlock implements IArgBlock { /** * Retrieves a list of argument keys. - * + * * @return a list of string-based keys */ public Enumeration getElements() { @@ -561,7 +559,7 @@ public class ArgBlock implements IArgBlock { /** * Retrieves a list of argument keys. - * + * * @return a list of string-based keys */ public Enumeration elements() { @@ -570,7 +568,7 @@ public class ArgBlock implements IArgBlock { /** * Adds long-type arguments to this block. - * + * * @param n key * @param v value * @return value @@ -581,7 +579,7 @@ public class ArgBlock implements IArgBlock { /** * Adds integer-type arguments to this block. - * + * * @param n key * @param v value * @return value @@ -592,7 +590,7 @@ public class ArgBlock implements IArgBlock { /** * Adds boolean-type arguments to this block. - * + * * @param n key * @param v value * @return value @@ -607,7 +605,7 @@ public class ArgBlock implements IArgBlock { /** * Adds integer-type arguments to this block. - * + * * @param n key * @param v value * @param radix radix @@ -617,20 +615,20 @@ public class ArgBlock implements IArgBlock { return mArgs.put(n, v.toString(radix)); } - /*========================================================== - * private methods - *==========================================================*/ - + /* + * ========================================================== private + * methods========================================================== + */ /** * Unwrap PKCS10 Package - * + * * @param request string formated PKCS10 request * @exception EBaseException * @return Base64Encoded PKCS10 request */ private String unwrap(String request, boolean checkHeader) - throws EBaseException { + throws EBaseException { String unwrapped; String header = null; int head = -1; @@ -655,7 +653,7 @@ public class ArgBlock implements IArgBlock { // header. if (!(head == -1 && trail == -1)) { header = CERT_REQUEST_HEADER; - + } } @@ -670,10 +668,12 @@ public class ArgBlock implements IArgBlock { // Now validate if any headers or trailers are in place if (head == -1 && checkHeader) { - throw new EBaseException(CMS.getUserMessage("CMS_BASE_MISSING_PKCS10_HEADER")); + throw new EBaseException( + CMS.getUserMessage("CMS_BASE_MISSING_PKCS10_HEADER")); } if (trail == -1 && checkHeader) { - throw new EBaseException(CMS.getUserMessage("CMS_BASE_MISSING_PKCS10_TRAILER")); + throw new EBaseException( + CMS.getUserMessage("CMS_BASE_MISSING_PKCS10_TRAILER")); } if (header != null) { @@ -695,27 +695,31 @@ public class ArgBlock implements IArgBlock { /** * Decode Der encoded PKCS10 certifictae Request - * + * * @param base64Request Base64 Encoded Certificate Request * @exception Exception * @return PKCS10 */ - private PKCS10 decodePKCS10(String base64Request) - throws EBaseException { + private PKCS10 decodePKCS10(String base64Request) throws EBaseException { PKCS10 pkcs10 = null; try { - byte[] decodedBytes = com.netscape.osutil.OSUtil.AtoB(base64Request); + byte[] decodedBytes = com.netscape.osutil.OSUtil + .AtoB(base64Request); pkcs10 = new PKCS10(decodedBytes); - } catch (NoSuchProviderException e) { - throw new EBaseException(CMS.getUserMessage("CMS_BASE_INTERNAL_ERROR", e.toString())); - } catch (IOException e) { - throw new EBaseException(CMS.getUserMessage("CMS_BASE_INTERNAL_ERROR", e.toString())); + } catch (NoSuchProviderException e) { + throw new EBaseException(CMS.getUserMessage( + "CMS_BASE_INTERNAL_ERROR", e.toString())); + } catch (IOException e) { + throw new EBaseException(CMS.getUserMessage( + "CMS_BASE_INTERNAL_ERROR", e.toString())); } catch (SignatureException e) { - throw new EBaseException(CMS.getUserMessage("CMS_BASE_INTERNAL_ERROR", e.toString())); + throw new EBaseException(CMS.getUserMessage( + "CMS_BASE_INTERNAL_ERROR", e.toString())); } catch (NoSuchAlgorithmException e) { - throw new EBaseException(CMS.getUserMessage("CMS_BASE_INTERNAL_ERROR", e.toString())); + throw new EBaseException(CMS.getUserMessage( + "CMS_BASE_INTERNAL_ERROR", e.toString())); } return pkcs10; |