diff options
author | Endi Sukma Dewata <edewata@redhat.com> | 2012-02-15 15:01:42 -0600 |
---|---|---|
committer | Endi Sukma Dewata <edewata@redhat.com> | 2012-02-23 21:14:28 -0600 |
commit | 970e3667eede41e72bb5a4cadf1d056ff526d944 (patch) | |
tree | 4bd18490efeb4245ff739a9c1558520b25a8f992 | |
parent | 34496a33fbbee462f67410e2ee54a7986b3aedae (diff) | |
download | pki-970e3667eede41e72bb5a4cadf1d056ff526d944.tar.gz pki-970e3667eede41e72bb5a4cadf1d056ff526d944.tar.xz pki-970e3667eede41e72bb5a4cadf1d056ff526d944.zip |
Consolidated BtoA/AtoB invocations.
The OSUtil's BtoA() and AtoB() have been replaced with wrapper
methods in com.netscape.cmsutil.util.Utils to simplify transition
into Base64 codec from Apache Commons library.
Ticket #90
79 files changed, 252 insertions, 165 deletions
diff --git a/pki/base/ca/src/com/netscape/ca/CAService.java b/pki/base/ca/src/com/netscape/ca/CAService.java index d8faa8b34..88c9dfb8d 100644 --- a/pki/base/ca/src/com/netscape/ca/CAService.java +++ b/pki/base/ca/src/com/netscape/ca/CAService.java @@ -91,6 +91,7 @@ import com.netscape.cmscore.dbs.CertRecord; import com.netscape.cmscore.dbs.CertificateRepository; import com.netscape.cmscore.dbs.RevocationInfo; import com.netscape.cmscore.util.Debug; +import com.netscape.cmsutil.util.Utils; /** * Request Service for CertificateAuthority. @@ -1675,7 +1676,7 @@ class serviceCheckChallenge implements IServant { private String hashPassword(String pwd) { String salt = "lala123"; byte[] pwdDigest = mSHADigest.digest((salt + pwd).getBytes()); - String b64E = com.netscape.osutil.OSUtil.BtoA(pwdDigest); + String b64E = Utils.base64encode(pwdDigest); return "{SHA}" + b64E; } diff --git a/pki/base/common/src/com/netscape/certsrv/base/KeyGenInfo.java b/pki/base/common/src/com/netscape/certsrv/base/KeyGenInfo.java index 23cb1957a..8c13fca56 100644 --- a/pki/base/common/src/com/netscape/certsrv/base/KeyGenInfo.java +++ b/pki/base/common/src/com/netscape/certsrv/base/KeyGenInfo.java @@ -19,6 +19,8 @@ package com.netscape.certsrv.base; import java.io.IOException; +import com.netscape.cmsutil.util.Utils; + import netscape.security.util.DerInputStream; import netscape.security.util.DerValue; import netscape.security.x509.AlgorithmId; @@ -197,7 +199,7 @@ public class KeyGenInfo { private byte[] base64Decode(String spkac) throws IOException { - return com.netscape.osutil.OSUtil.AtoB(spkac); + return Utils.base64decode(spkac); } private void derDecode(byte spkac[]) diff --git a/pki/base/common/src/com/netscape/cms/authentication/HashAuthentication.java b/pki/base/common/src/com/netscape/cms/authentication/HashAuthentication.java index 57b86157e..2537efa10 100644 --- a/pki/base/common/src/com/netscape/cms/authentication/HashAuthentication.java +++ b/pki/base/common/src/com/netscape/cms/authentication/HashAuthentication.java @@ -200,7 +200,7 @@ public class HashAuthentication implements IAuthManager, IExtendedPluginInfo { public String hashFingerprint(String host, String pageID, String uid) { byte[] hash = mSHADigest.digest((SALT + pageID + getSecret(host) + uid).getBytes()); - String b64E = com.netscape.osutil.OSUtil.BtoA(hash); + String b64E = Utils.base64encode(hash); return "{SHA}" + b64E; } diff --git a/pki/base/common/src/com/netscape/cms/crl/CMSIssuerAlternativeNameExtension.java b/pki/base/common/src/com/netscape/cms/crl/CMSIssuerAlternativeNameExtension.java index 88e859798..ee656a199 100644 --- a/pki/base/common/src/com/netscape/cms/crl/CMSIssuerAlternativeNameExtension.java +++ b/pki/base/common/src/com/netscape/cms/crl/CMSIssuerAlternativeNameExtension.java @@ -44,6 +44,7 @@ import com.netscape.certsrv.base.IExtendedPluginInfo; import com.netscape.certsrv.ca.ICMSCRLExtension; import com.netscape.certsrv.common.NameValuePairs; import com.netscape.certsrv.logging.ILogger; +import com.netscape.cmsutil.util.Utils; /** * This represents a issuer alternative name extension. @@ -158,7 +159,7 @@ public class CMSIssuerAlternativeNameExtension } else if (nameType.equalsIgnoreCase(PROP_OTHER_NAME)) { try { - byte[] val = com.netscape.osutil.OSUtil.AtoB(name); + byte[] val = Utils.base64decode(name); DerValue derVal = new DerValue(new ByteArrayInputStream(val)); GeneralName generalName = new GeneralName(derVal); diff --git a/pki/base/common/src/com/netscape/cms/policy/constraints/RenewalValidityConstraints.java b/pki/base/common/src/com/netscape/cms/policy/constraints/RenewalValidityConstraints.java index b2f654b77..023605db4 100644 --- a/pki/base/common/src/com/netscape/cms/policy/constraints/RenewalValidityConstraints.java +++ b/pki/base/common/src/com/netscape/cms/policy/constraints/RenewalValidityConstraints.java @@ -34,6 +34,7 @@ import com.netscape.certsrv.policy.IRenewalPolicy; import com.netscape.certsrv.request.IRequest; import com.netscape.certsrv.request.PolicyResult; import com.netscape.cms.policy.APolicyRule; +import com.netscape.cmsutil.util.Utils; /** * RenewalValidityConstraints is a default rule for Certificate @@ -338,7 +339,7 @@ public class RenewalValidityConstraints extends APolicyRule sb.append("\n"); try { byte[] ba = cert.getEncoded(); - String encodedCert = com.netscape.osutil.OSUtil.BtoA(ba); + String encodedCert = Utils.base64encode(ba); sb.append(CERT_HEADER + encodedCert + CERT_TRAILER); } catch (Exception e) { diff --git a/pki/base/common/src/com/netscape/cms/publish/publishers/FileBasedPublisher.java b/pki/base/common/src/com/netscape/cms/publish/publishers/FileBasedPublisher.java index d8cec78d8..5e8ad1282 100644 --- a/pki/base/common/src/com/netscape/cms/publish/publishers/FileBasedPublisher.java +++ b/pki/base/common/src/com/netscape/cms/publish/publishers/FileBasedPublisher.java @@ -45,6 +45,7 @@ import com.netscape.certsrv.base.IExtendedPluginInfo; import com.netscape.certsrv.ldap.ELdapException; import com.netscape.certsrv.logging.ILogger; import com.netscape.certsrv.publish.ILdapPublisher; +import com.netscape.cmsutil.util.Utils; /** * This publisher writes certificate and CRL into @@ -368,7 +369,7 @@ public class FileBasedPublisher implements ILdapPublisher, IExtendedPluginInfo { ByteArrayOutputStream os = new ByteArrayOutputStream(); fos = new FileOutputStream(tempFile); - fos.write(com.netscape.osutil.OSUtil.BtoA(encodedArray).getBytes()); + fos.write(Utils.base64encode(encodedArray).getBytes()); fos.close(); destName = baseName + ".b64"; destFile = new File(destName); diff --git a/pki/base/common/src/com/netscape/cms/servlet/admin/AdminServlet.java b/pki/base/common/src/com/netscape/cms/servlet/admin/AdminServlet.java index 8f1024723..0e3d2c228 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/admin/AdminServlet.java +++ b/pki/base/common/src/com/netscape/cms/servlet/admin/AdminServlet.java @@ -54,6 +54,7 @@ import com.netscape.certsrv.usrgrp.IGroup; import com.netscape.certsrv.usrgrp.IUGSubsystem; import com.netscape.certsrv.usrgrp.IUser; import com.netscape.cms.servlet.base.UserInfo; +import com.netscape.cmsutil.util.Utils; /** * A class represents an administration servlet that @@ -368,7 +369,7 @@ public class AdminServlet extends HttpServlet { String authToken = req.getHeader(HDR_AUTHORIZATION); String b64s = authToken.substring( authToken.lastIndexOf(' ') + 1); - String authCode = new String(com.netscape.osutil.OSUtil.AtoB(b64s)); + String authCode = new String(Utils.base64decode(b64s)); String userid = authCode.substring(0, authCode.indexOf(':')); String password = authCode.substring( diff --git a/pki/base/common/src/com/netscape/cms/servlet/admin/CMSAdminServlet.java b/pki/base/common/src/com/netscape/cms/servlet/admin/CMSAdminServlet.java index 6161a20d6..58fb1d03f 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/admin/CMSAdminServlet.java +++ b/pki/base/common/src/com/netscape/cms/servlet/admin/CMSAdminServlet.java @@ -77,6 +77,7 @@ import com.netscape.certsrv.selftests.ISelfTest; import com.netscape.certsrv.selftests.ISelfTestSubsystem; import com.netscape.certsrv.tks.ITKSAuthority; import com.netscape.cmsutil.util.Cert; +import com.netscape.cmsutil.util.Utils; import com.netscape.symkey.SessionKey; /** @@ -2379,7 +2380,7 @@ public final class CMSAdminServlet extends AdminServlet { byte[] bCert = null; try { - bCert = (byte[]) (com.netscape.osutil.OSUtil.AtoB(b64Cert)); + bCert = Utils.base64decode(b64Cert); } catch (Exception e) { CMS.debug("CMSAdminServlet: exception: " + e.toString()); } @@ -3422,7 +3423,7 @@ public final class CMSAdminServlet extends AdminServlet { if (rawData != null) { String base64Data = null; - base64Data = com.netscape.osutil.OSUtil.BtoA(rawData).trim(); + base64Data = Utils.base64encode(rawData).trim(); // extract all line separators from the "base64Data" for (int i = 0; i < base64Data.length(); i++) { diff --git a/pki/base/common/src/com/netscape/cms/servlet/admin/UsrGrpAdminServlet.java b/pki/base/common/src/com/netscape/cms/servlet/admin/UsrGrpAdminServlet.java index 6eaf004f9..3783ead6f 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/admin/UsrGrpAdminServlet.java +++ b/pki/base/common/src/com/netscape/cms/servlet/admin/UsrGrpAdminServlet.java @@ -56,6 +56,7 @@ import com.netscape.certsrv.usrgrp.IGroup; import com.netscape.certsrv.usrgrp.IUGSubsystem; import com.netscape.certsrv.usrgrp.IUser; import com.netscape.cmsutil.util.Cert; +import com.netscape.cmsutil.util.Utils; /** * A class representing an administration servlet for @@ -1045,7 +1046,7 @@ public class UsrGrpAdminServlet extends AdminServlet { // Base64 decode cert try { - byte bCert[] = (byte[]) (com.netscape.osutil.OSUtil.AtoB(certsString)); + byte bCert[] = Utils.base64decode(certsString); X509Certificate cert = new X509CertImpl(bCert); certs = new X509Certificate[1]; @@ -1056,7 +1057,7 @@ public class UsrGrpAdminServlet extends AdminServlet { // could it be a pkcs7 blob? CMS.debug("UsrGrpAdminServlet: " + CMS.getLogMessage("ADMIN_SRVLT_IS_PK_BLOB")); - byte p7Cert[] = (byte[]) (com.netscape.osutil.OSUtil.AtoB(certsString)); + byte p7Cert[] = Utils.base64decode(certsString); try { CryptoManager manager = CryptoManager.getInstance(); diff --git a/pki/base/common/src/com/netscape/cms/servlet/base/CMSServlet.java b/pki/base/common/src/com/netscape/cms/servlet/base/CMSServlet.java index a32116b43..c0931ee2f 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/base/CMSServlet.java +++ b/pki/base/common/src/com/netscape/cms/servlet/base/CMSServlet.java @@ -96,6 +96,7 @@ import com.netscape.cms.servlet.common.GenSvcPendingTemplateFiller; import com.netscape.cms.servlet.common.GenUnexpectedErrorTemplateFiller; import com.netscape.cms.servlet.common.ICMSTemplateFiller; import com.netscape.cms.servlet.common.ServletUtils; +import com.netscape.cmsutil.util.Utils; import com.netscape.cmsutil.xml.XMLObject; /** @@ -1563,7 +1564,7 @@ public abstract class CMSServlet extends HttpServlet { protected String hashPassword(String pwd) { String salt = generateSalt(); byte[] pwdDigest = mSHADigest.digest((salt + pwd).getBytes()); - String b64E = com.netscape.osutil.OSUtil.BtoA(pwdDigest); + String b64E = Utils.base64encode(pwdDigest); return "{SHA}" + salt + ";" + b64E; } diff --git a/pki/base/common/src/com/netscape/cms/servlet/cert/CMCRevReqServlet.java b/pki/base/common/src/com/netscape/cms/servlet/cert/CMCRevReqServlet.java index 95f5ae7b8..0dfe4a26c 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/cert/CMCRevReqServlet.java +++ b/pki/base/common/src/com/netscape/cms/servlet/cert/CMCRevReqServlet.java @@ -65,6 +65,7 @@ import com.netscape.cms.servlet.common.CMSRequest; import com.netscape.cms.servlet.common.CMSTemplate; import com.netscape.cms.servlet.common.CMSTemplateParams; import com.netscape.cms.servlet.common.ECMSGWException; +import com.netscape.cmsutil.util.Utils; /** * Revoke a certificate with a CMC-formatted revocation request @@ -497,7 +498,7 @@ public class CMCRevReqServlet extends CMSServlet { String b64eCert = req.getParameter("b64eCertificate"); if (b64eCert != null) { - byte[] certBytes = com.netscape.osutil.OSUtil.AtoB(b64eCert); + byte[] certBytes = Utils.base64decode(b64eCert); X509CertImpl cert = new X509CertImpl(certBytes); IArgBlock rarg = CMS.createArgBlock(); diff --git a/pki/base/common/src/com/netscape/cms/servlet/cert/ChallengeRevocationServlet1.java b/pki/base/common/src/com/netscape/cms/servlet/cert/ChallengeRevocationServlet1.java index e0978dd21..f056047cc 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/cert/ChallengeRevocationServlet1.java +++ b/pki/base/common/src/com/netscape/cms/servlet/cert/ChallengeRevocationServlet1.java @@ -64,6 +64,7 @@ import com.netscape.cms.servlet.common.CMSRequest; import com.netscape.cms.servlet.common.CMSTemplate; import com.netscape.cms.servlet.common.CMSTemplateParams; import com.netscape.cms.servlet.common.ECMSGWException; +import com.netscape.cmsutil.util.Utils; /** * Takes the certificate info (serial number) and optional challenge phrase, creates a @@ -424,7 +425,7 @@ public class ChallengeRevocationServlet1 extends CMSServlet { String b64eCert = req.getParameter("b64eCertificate"); if (b64eCert != null) { - byte[] certBytes = com.netscape.osutil.OSUtil.AtoB(b64eCert); + byte[] certBytes = Utils.base64decode(b64eCert); X509CertImpl cert = new X509CertImpl(certBytes); IArgBlock rarg = CMS.createArgBlock(); diff --git a/pki/base/common/src/com/netscape/cms/servlet/cert/DisplayBySerial.java b/pki/base/common/src/com/netscape/cms/servlet/cert/DisplayBySerial.java index 36746106a..4c0b56f0b 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/cert/DisplayBySerial.java +++ b/pki/base/common/src/com/netscape/cms/servlet/cert/DisplayBySerial.java @@ -65,6 +65,7 @@ import com.netscape.cms.servlet.common.CMSRequest; import com.netscape.cms.servlet.common.CMSTemplate; import com.netscape.cms.servlet.common.CMSTemplateParams; import com.netscape.cms.servlet.common.ECMSGWException; +import com.netscape.cmsutil.util.Utils; /** * Display detailed information about a certificate @@ -378,7 +379,7 @@ public class DisplayBySerial extends CMSServlet { byte[] ba = cert.getEncoded(); // Do base 64 encoding - header.addStringValue("certChainBase64", com.netscape.osutil.OSUtil.BtoA(ba)); + header.addStringValue("certChainBase64", Utils.base64encode(ba)); header.addStringValue("serialNumber", seq.toString(16)); /* @@ -424,7 +425,7 @@ public class DisplayBySerial extends CMSServlet { p7.encodeSignedData(bos, false); byte[] p7Bytes = bos.toByteArray(); - p7Str = com.netscape.osutil.OSUtil.BtoA(p7Bytes); + p7Str = Utils.base64encode(p7Bytes); header.addStringValue("pkcs7ChainBase64", p7Str); } catch (Exception e) { //p7Str = "PKCS#7 B64 Encoding error - " + e.toString() diff --git a/pki/base/common/src/com/netscape/cms/servlet/cert/DisplayCRL.java b/pki/base/common/src/com/netscape/cms/servlet/cert/DisplayCRL.java index f5422c2fc..ad503272a 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/cert/DisplayCRL.java +++ b/pki/base/common/src/com/netscape/cms/servlet/cert/DisplayCRL.java @@ -48,6 +48,7 @@ import com.netscape.cms.servlet.common.CMSRequest; import com.netscape.cms.servlet.common.CMSTemplate; import com.netscape.cms.servlet.common.CMSTemplateParams; import com.netscape.cms.servlet.common.ECMSGWException; +import com.netscape.cmsutil.util.Utils; /** * Decode the CRL and display it to the requester. @@ -341,7 +342,7 @@ public class DisplayCRL extends CMSServlet { } else if (crlDisplayType.equals("base64Encoded")) { try { byte[] ba = crl.getEncoded(); - String crlBase64Encoded = com.netscape.osutil.OSUtil.BtoA(ba); + String crlBase64Encoded = Utils.base64encode(ba); int length = crlBase64Encoded.length(); int i = 0; int j = 0; @@ -414,7 +415,7 @@ public class DisplayCRL extends CMSServlet { try { byte[] ba = deltaCRL.getEncoded(); - String crlBase64Encoded = com.netscape.osutil.OSUtil.BtoA(ba); + String crlBase64Encoded = Utils.base64encode(ba); int length = crlBase64Encoded.length(); int i = 0; int j = 0; diff --git a/pki/base/common/src/com/netscape/cms/servlet/cert/EnrollServlet.java b/pki/base/common/src/com/netscape/cms/servlet/cert/EnrollServlet.java index b32ce5e11..b580d7f79 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/cert/EnrollServlet.java +++ b/pki/base/common/src/com/netscape/cms/servlet/cert/EnrollServlet.java @@ -73,6 +73,7 @@ import com.netscape.cms.servlet.processors.CRMFProcessor; import com.netscape.cms.servlet.processors.KeyGenProcessor; import com.netscape.cms.servlet.processors.PKCS10Processor; import com.netscape.cms.servlet.processors.PKIProcessor; +import com.netscape.cmsutil.util.Utils; /** * Submit a Certificate Enrollment request @@ -1746,7 +1747,7 @@ public class EnrollServlet extends CMSServlet { if (rawData != null) { String base64Data = null; - base64Data = com.netscape.osutil.OSUtil.BtoA(rawData).trim(); + base64Data = Utils.base64encode(rawData).trim(); StringBuffer sb = new StringBuffer(); // extract all line separators from the "base64Data" diff --git a/pki/base/common/src/com/netscape/cms/servlet/cert/GetCRL.java b/pki/base/common/src/com/netscape/cms/servlet/cert/GetCRL.java index 21a0c1d20..4c8661359 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/cert/GetCRL.java +++ b/pki/base/common/src/com/netscape/cms/servlet/cert/GetCRL.java @@ -46,6 +46,7 @@ import com.netscape.cms.servlet.common.CMSRequest; import com.netscape.cms.servlet.common.CMSTemplate; import com.netscape.cms.servlet.common.CMSTemplateParams; import com.netscape.cms.servlet.common.ECMSGWException; +import com.netscape.cmsutil.util.Utils; /** * Retrieve CRL for a Certificate Authority @@ -334,7 +335,7 @@ public class GetCRL extends CMSServlet { } else if (crlDisplayType.equals("base64Encoded")) { try { byte[] ba = crl.getEncoded(); - String crlBase64Encoded = com.netscape.osutil.OSUtil.BtoA(ba); + String crlBase64Encoded = Utils.base64encode(ba); int length = crlBase64Encoded.length(); int i = 0; int j = 0; @@ -374,7 +375,7 @@ public class GetCRL extends CMSServlet { try { byte[] ba = crl.getEncoded(); - String crlBase64Encoded = com.netscape.osutil.OSUtil.BtoA(ba); + String crlBase64Encoded = Utils.base64encode(ba); int length = crlBase64Encoded.length(); int i = 0; int j = 0; diff --git a/pki/base/common/src/com/netscape/cms/servlet/cert/ImportCertsTemplateFiller.java b/pki/base/common/src/com/netscape/cms/servlet/cert/ImportCertsTemplateFiller.java index 5e4f7a427..2f551d3f5 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/cert/ImportCertsTemplateFiller.java +++ b/pki/base/common/src/com/netscape/cms/servlet/cert/ImportCertsTemplateFiller.java @@ -56,6 +56,7 @@ import com.netscape.cms.servlet.common.CMSRequest; import com.netscape.cms.servlet.common.CMSTemplateParams; import com.netscape.cms.servlet.common.ECMSGWException; import com.netscape.cms.servlet.common.ICMSTemplateFiller; +import com.netscape.cmsutil.util.Utils; /** * Set up HTTP response to import certificate into browsers @@ -352,7 +353,7 @@ public class ImportCertsTemplateFiller implements ICMSTemplateFiller { certRepContent.encode(certRepOut); byte[] certRepBytes = certRepOut.toByteArray(); - String certRepB64 = com.netscape.osutil.OSUtil.BtoA(certRepBytes); + String certRepB64 = Utils.base64encode(certRepBytes); // add CR to each return as required by cartman BufferedReader certRepB64lines = new BufferedReader(new StringReader(certRepB64)); diff --git a/pki/base/common/src/com/netscape/cms/servlet/cert/RevocationServlet.java b/pki/base/common/src/com/netscape/cms/servlet/cert/RevocationServlet.java index a4d434bd4..663eaae1a 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/cert/RevocationServlet.java +++ b/pki/base/common/src/com/netscape/cms/servlet/cert/RevocationServlet.java @@ -55,6 +55,7 @@ import com.netscape.cms.servlet.common.CMSRequest; import com.netscape.cms.servlet.common.CMSTemplate; import com.netscape.cms.servlet.common.CMSTemplateParams; import com.netscape.cms.servlet.common.ECMSGWException; +import com.netscape.cmsutil.util.Utils; /** * Perform the first step in revoking a certificate @@ -280,7 +281,7 @@ public class RevocationServlet extends CMSServlet { byte[] ba = old_cert.getEncoded(); // Do base 64 encoding - header.addStringValue("b64eCertificate", com.netscape.osutil.OSUtil.BtoA(ba)); + header.addStringValue("b64eCertificate", Utils.base64encode(ba)); } catch (CertificateEncodingException e) { } } diff --git a/pki/base/common/src/com/netscape/cms/servlet/cert/scep/CRSEnrollment.java b/pki/base/common/src/com/netscape/cms/servlet/cert/scep/CRSEnrollment.java index 99febb4cf..525775d62 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/cert/scep/CRSEnrollment.java +++ b/pki/base/common/src/com/netscape/cms/servlet/cert/scep/CRSEnrollment.java @@ -120,6 +120,7 @@ import com.netscape.certsrv.request.RequestId; import com.netscape.certsrv.request.RequestStatus; import com.netscape.cms.servlet.profile.SSLClientCertProvider; import com.netscape.cmsutil.scep.CRSPKIMessage; +import com.netscape.cmsutil.util.Utils; /** * This servlet deals with PKCS#10-based certificate requests from @@ -576,7 +577,7 @@ public class CRSEnrollment extends HttpServlet { byte[] response = null; String responseData = ""; - decodedPKIMessage = com.netscape.osutil.OSUtil.AtoB(msg); + decodedPKIMessage = Utils.base64decode(msg); try { ByteArrayInputStream is = new ByteArrayInputStream(decodedPKIMessage); @@ -817,7 +818,7 @@ public class CRSEnrollment extends HttpServlet { byte[] response = null; X509CertImpl cert = null; - decodedPKIMessage = com.netscape.osutil.OSUtil.AtoB(msg); + decodedPKIMessage = Utils.base64decode(msg); try { ByteArrayInputStream is = new ByteArrayInputStream(decodedPKIMessage); @@ -1787,7 +1788,7 @@ public class CRSEnrollment extends HttpServlet { protected String hashPassword(String pwd) { String salt = "lala123"; byte[] pwdDigest = mSHADigest.digest((salt + pwd).getBytes()); - String b64E = com.netscape.osutil.OSUtil.BtoA(pwdDigest); + String b64E = Utils.base64encode(pwdDigest); return "{SHA}" + b64E; } diff --git a/pki/base/common/src/com/netscape/cms/servlet/connector/ConnectorServlet.java b/pki/base/common/src/com/netscape/cms/servlet/connector/ConnectorServlet.java index b2c43b3f7..4f708f789 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/connector/ConnectorServlet.java +++ b/pki/base/common/src/com/netscape/cms/servlet/connector/ConnectorServlet.java @@ -71,6 +71,7 @@ import com.netscape.certsrv.request.RequestId; import com.netscape.certsrv.request.RequestStatus; import com.netscape.cms.servlet.base.CMSServlet; import com.netscape.cms.servlet.common.CMSRequest; +import com.netscape.cmsutil.util.Utils; /** * Connector servlet @@ -1094,7 +1095,7 @@ public class ConnectorServlet extends CMSServlet { if (rawData != null) { String base64Data = null; - base64Data = com.netscape.osutil.OSUtil.BtoA(rawData).trim(); + base64Data = Utils.base64encode(rawData).trim(); StringBuffer sb = new StringBuffer(); // extract all line separators from the "base64Data" diff --git a/pki/base/common/src/com/netscape/cms/servlet/csadmin/RegisterUser.java b/pki/base/common/src/com/netscape/cms/servlet/csadmin/RegisterUser.java index 1a621d53d..0042cdb5a 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/csadmin/RegisterUser.java +++ b/pki/base/common/src/com/netscape/cms/servlet/csadmin/RegisterUser.java @@ -45,6 +45,7 @@ import com.netscape.cms.servlet.base.CMSServlet; import com.netscape.cms.servlet.base.UserInfo; import com.netscape.cms.servlet.common.CMSRequest; import com.netscape.cms.servlet.common.ICMSTemplateFiller; +import com.netscape.cmsutil.util.Utils; import com.netscape.cmsutil.xml.XMLObject; /** @@ -161,7 +162,7 @@ public class RegisterUser extends CMSServlet { byte bCert[] = null; X509CertImpl cert = null; - bCert = (byte[]) (com.netscape.osutil.OSUtil.AtoB(certsString)); + bCert = Utils.base64decode(certsString); cert = new X509CertImpl(bCert); certs[0] = (X509Certificate) cert; diff --git a/pki/base/common/src/com/netscape/cms/servlet/ocsp/OCSPServlet.java b/pki/base/common/src/com/netscape/cms/servlet/ocsp/OCSPServlet.java index 24c163847..3d5e93a56 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/ocsp/OCSPServlet.java +++ b/pki/base/common/src/com/netscape/cms/servlet/ocsp/OCSPServlet.java @@ -45,6 +45,7 @@ import com.netscape.cmsutil.ocsp.ResponseBytes; import com.netscape.cmsutil.ocsp.ResponseData; import com.netscape.cmsutil.ocsp.SingleResponse; import com.netscape.cmsutil.ocsp.TBSRequest; +import com.netscape.cmsutil.util.Utils; /** * Process OCSP messages, According to RFC 2560 @@ -174,7 +175,7 @@ public class OCSPServlet extends CMSServlet { throw new Exception("OCSPServlet: OCSP request not provided in GET method"); } is = new ByteArrayInputStream( - com.netscape.osutil.OSUtil.AtoB(pathInfo.substring(1))); + Utils.base64decode(pathInfo.substring(1))); } // (1) retrieve OCSP request diff --git a/pki/base/common/src/com/netscape/cms/servlet/profile/ProfileProcessServlet.java b/pki/base/common/src/com/netscape/cms/servlet/profile/ProfileProcessServlet.java index 3c75be021..e482b67da 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/profile/ProfileProcessServlet.java +++ b/pki/base/common/src/com/netscape/cms/servlet/profile/ProfileProcessServlet.java @@ -62,6 +62,7 @@ import com.netscape.certsrv.template.ArgSet; import com.netscape.certsrv.util.IStatsSubsystem; import com.netscape.cms.profile.common.ProfilePolicy; import com.netscape.cms.servlet.common.CMSRequest; +import com.netscape.cmsutil.util.Utils; /** * This servlet approves profile-based request. @@ -932,7 +933,7 @@ public class ProfileProcessServlet extends ProfileServlet { if (rawData != null) { String base64Data = null; - base64Data = com.netscape.osutil.OSUtil.BtoA(rawData).trim(); + base64Data = Utils.base64encode(rawData).trim(); // extract all line separators from the "base64Data" StringBuffer sb = new StringBuffer(); diff --git a/pki/base/common/src/com/netscape/cms/servlet/profile/ProfileSubmitCMCServlet.java b/pki/base/common/src/com/netscape/cms/servlet/profile/ProfileSubmitCMCServlet.java index 2849e14f3..16451f6dd 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/profile/ProfileSubmitCMCServlet.java +++ b/pki/base/common/src/com/netscape/cms/servlet/profile/ProfileSubmitCMCServlet.java @@ -62,6 +62,7 @@ import com.netscape.certsrv.request.RequestStatus; import com.netscape.cms.servlet.common.AuthCredentials; import com.netscape.cms.servlet.common.CMCOutputTemplate; import com.netscape.cms.servlet.common.CMSRequest; +import com.netscape.cmsutil.util.Utils; /** * This servlet submits end-user request into the profile framework. @@ -256,7 +257,7 @@ public class ProfileSubmitCMCServlet extends ProfileServlet { } } - requestB64 = com.netscape.osutil.OSUtil.BtoA(reqbuf); + requestB64 = Utils.base64encode(reqbuf); if (CMS.debugOn()) { CMS.debug("Start of ProfileSubmitCMCServlet Input Parameters"); @@ -876,7 +877,7 @@ public class ProfileSubmitCMCServlet extends ProfileServlet { if (rawData != null) { String base64Data = null; - base64Data = com.netscape.osutil.OSUtil.BtoA(rawData).trim(); + base64Data = Utils.base64encode(rawData).trim(); // extract all line separators from the "base64Data" StringBuffer sb = new StringBuffer(); diff --git a/pki/base/common/src/com/netscape/cms/servlet/profile/ProfileSubmitServlet.java b/pki/base/common/src/com/netscape/cms/servlet/profile/ProfileSubmitServlet.java index 1d4cab76b..0bb038677 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/profile/ProfileSubmitServlet.java +++ b/pki/base/common/src/com/netscape/cms/servlet/profile/ProfileSubmitServlet.java @@ -68,6 +68,7 @@ import com.netscape.certsrv.util.IStatsSubsystem; import com.netscape.cms.servlet.common.AuthCredentials; import com.netscape.cms.servlet.common.CMSRequest; import com.netscape.cmsutil.util.Cert; +import com.netscape.cmsutil.util.Utils; import com.netscape.cmsutil.xml.XMLObject; /** @@ -1603,7 +1604,7 @@ public class ProfileSubmitServlet extends ProfileServlet { if (rawData != null) { String base64Data = null; - base64Data = com.netscape.osutil.OSUtil.BtoA(rawData).trim(); + base64Data = Utils.base64encode(rawData).trim(); // extract all line separators from the "base64Data" StringBuffer sb = new StringBuffer(); diff --git a/pki/base/common/src/com/netscape/cms/servlet/request/ProcessCertReq.java b/pki/base/common/src/com/netscape/cms/servlet/request/ProcessCertReq.java index cbe73c79f..68328a73c 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/request/ProcessCertReq.java +++ b/pki/base/common/src/com/netscape/cms/servlet/request/ProcessCertReq.java @@ -78,6 +78,7 @@ import com.netscape.cms.servlet.common.CMSTemplate; import com.netscape.cms.servlet.common.CMSTemplateParams; import com.netscape.cms.servlet.common.ECMSGWException; import com.netscape.cms.servlet.common.ICMSTemplateFiller; +import com.netscape.cmsutil.util.Utils; /** * Agent operations on Certificate requests. This servlet is used @@ -617,7 +618,7 @@ public class ProcessCertReq extends CMSServlet { if (addExts != null && !addExts.trim().equals("")) { Vector<Extension> extsToBeAdded = new Vector<Extension>(); - byte[] b = (byte[]) (com.netscape.osutil.OSUtil.AtoB(addExts)); + byte[] b = Utils.base64decode(addExts); // this b can be "Extension" Or "SEQUENCE OF Extension" try { @@ -1851,7 +1852,7 @@ public class ProcessCertReq extends CMSServlet { if (rawData != null) { String base64Data = null; - base64Data = com.netscape.osutil.OSUtil.BtoA(rawData).trim(); + base64Data = Utils.base64encode(rawData).trim(); // extract all line separators from the "base64Data" StringBuffer sb = new StringBuffer(); diff --git a/pki/base/common/src/com/netscape/cmscore/apps/CMSEngine.java b/pki/base/common/src/com/netscape/cmscore/apps/CMSEngine.java index 5071a1c80..ba8462727 100644 --- a/pki/base/common/src/com/netscape/cmscore/apps/CMSEngine.java +++ b/pki/base/common/src/com/netscape/cmscore/apps/CMSEngine.java @@ -170,7 +170,7 @@ import com.netscape.cmscore.util.Debug; import com.netscape.cmscore.util.OsSubsystem; import com.netscape.cmsutil.net.ISocketFactory; import com.netscape.cmsutil.password.IPasswordStore; -import com.netscape.osutil.OSUtil; +import com.netscape.cmsutil.util.Utils; public class CMSEngine implements ICMSEngine { private static final String ID = "MAIN"; @@ -1382,11 +1382,11 @@ public class CMSEngine implements ICMSEngine { } public String BtoA(byte data[]) { - return OSUtil.BtoA(data); + return Utils.base64encode(data); } public byte[] AtoB(String data) { - return OSUtil.AtoB(data); + return Utils.base64decode(data); } public String getEncodedCert(X509Certificate cert) { diff --git a/pki/base/common/src/com/netscape/cmscore/authentication/ChallengePhraseAuthentication.java b/pki/base/common/src/com/netscape/cmscore/authentication/ChallengePhraseAuthentication.java index 48f743ee3..1c4d9fbcf 100644 --- a/pki/base/common/src/com/netscape/cmscore/authentication/ChallengePhraseAuthentication.java +++ b/pki/base/common/src/com/netscape/cmscore/authentication/ChallengePhraseAuthentication.java @@ -46,6 +46,7 @@ import com.netscape.cmscore.base.SubsystemRegistry; import com.netscape.cmscore.dbs.CertRecord; import com.netscape.cmscore.dbs.CertificateRepository; import com.netscape.cmscore.util.Debug; +import com.netscape.cmsutil.util.Utils; /** * Challenge phrase based authentication. @@ -405,7 +406,7 @@ public class ChallengePhraseAuthentication implements IAuthManager { private String hashPassword(String pwd) { String salt = "lala123"; byte[] pwdDigest = mSHADigest.digest((salt + pwd).getBytes()); - String b64E = com.netscape.osutil.OSUtil.BtoA(pwdDigest); + String b64E = Utils.base64encode(pwdDigest); return "{SHA}" + b64E; } 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 905f7c8db..62b5971a4 100644 --- a/pki/base/common/src/com/netscape/cmscore/base/ArgBlock.java +++ b/pki/base/common/src/com/netscape/cmscore/base/ArgBlock.java @@ -32,6 +32,7 @@ import com.netscape.certsrv.apps.CMS; import com.netscape.certsrv.base.EBaseException; import com.netscape.certsrv.base.IArgBlock; import com.netscape.certsrv.base.KeyGenInfo; +import com.netscape.cmsutil.util.Utils; /** * This class represents a set of indexed arguments. @@ -697,7 +698,7 @@ public class ArgBlock implements IArgBlock { PKCS10 pkcs10 = null; try { - byte[] decodedBytes = com.netscape.osutil.OSUtil.AtoB(base64Request); + byte[] decodedBytes = Utils.base64decode(base64Request); pkcs10 = new PKCS10(decodedBytes); } catch (NoSuchProviderException e) { diff --git a/pki/base/common/src/com/netscape/cmscore/base/PropConfigStore.java b/pki/base/common/src/com/netscape/cmscore/base/PropConfigStore.java index 482bcc7b9..1e46d3ef3 100644 --- a/pki/base/common/src/com/netscape/cmscore/base/PropConfigStore.java +++ b/pki/base/common/src/com/netscape/cmscore/base/PropConfigStore.java @@ -36,6 +36,7 @@ import com.netscape.certsrv.base.EPropertyNotDefined; import com.netscape.certsrv.base.EPropertyNotFound; import com.netscape.certsrv.base.IConfigStore; import com.netscape.certsrv.base.ISourceConfigStore; +import com.netscape.cmsutil.util.Utils; /** * A class represents a in-memory configuration store. @@ -342,7 +343,7 @@ public class PropConfigStore implements IConfigStore, Cloneable { } else { CMS.traceHashKey(mDebugType, getFullName(name), "<bytearray>", "<bytearray>"); - return com.netscape.osutil.OSUtil.AtoB(str); + return Utils.base64decode(str); } } diff --git a/pki/base/common/src/com/netscape/cmscore/cert/CertUtils.java b/pki/base/common/src/com/netscape/cmscore/cert/CertUtils.java index a5c6fec90..9710d63f5 100644 --- a/pki/base/common/src/com/netscape/cmscore/cert/CertUtils.java +++ b/pki/base/common/src/com/netscape/cmscore/cert/CertUtils.java @@ -60,7 +60,7 @@ import com.netscape.certsrv.apps.CMS; import com.netscape.certsrv.base.EBaseException; import com.netscape.certsrv.base.IConfigStore; import com.netscape.certsrv.logging.ILogger; -import com.netscape.osutil.OSUtil; +import com.netscape.cmsutil.util.Utils; /** * Utility class with assorted methods to check for @@ -157,7 +157,7 @@ public class CertUtils { PKCS10 pkcs10 = null; try { - byte[] decodedBytes = com.netscape.osutil.OSUtil.AtoB(normalized); + byte[] decodedBytes = Utils.base64decode(normalized); pkcs10 = new PKCS10(decodedBytes); } catch (Exception e) { @@ -548,7 +548,7 @@ public class CertUtils { public static String toMIME64(X509CertImpl cert) { try { return "-----BEGIN CERTIFICATE-----\n" + - com.netscape.osutil.OSUtil.BtoA(cert.getEncoded()) + + Utils.base64encode(cert.getEncoded()) + "-----END CERTIFICATE-----\n"; } catch (CertificateException e) { } @@ -559,7 +559,7 @@ public class CertUtils { throws IOException { mime64 = stripCertBrackets(mime64.trim()); String newval = normalizeCertStr(mime64); - byte rawPub[] = com.netscape.osutil.OSUtil.AtoB(newval); + byte rawPub[] = Utils.base64decode(newval); X509Certificate cert = null; try { @@ -573,7 +573,7 @@ public class CertUtils { throws IOException { mime64 = stripCertBrackets(mime64.trim()); String newval = normalizeCertStr(mime64); - byte rawPub[] = com.netscape.osutil.OSUtil.AtoB(newval); + byte rawPub[] = Utils.base64decode(newval); PKCS7 p7 = null; try { @@ -588,7 +588,7 @@ public class CertUtils { throws IOException { mime64 = stripCRLBrackets(mime64.trim()); String newval = normalizeCertStr(mime64); - byte rawPub[] = com.netscape.osutil.OSUtil.AtoB(newval); + byte rawPub[] = Utils.base64decode(newval); X509CRL crl = null; try { @@ -601,7 +601,7 @@ public class CertUtils { public static X509CRL mapCRL1(String mime64) throws IOException { mime64 = stripCRLBrackets(mime64.trim()); - byte rawPub[] = OSUtil.AtoB(mime64); + byte rawPub[] = Utils.base64decode(mime64); X509CRL crl = null; try { diff --git a/pki/base/common/src/com/netscape/cmscore/connector/HttpRequestEncoder.java b/pki/base/common/src/com/netscape/cmscore/connector/HttpRequestEncoder.java index b76670946..76d39b3ed 100644 --- a/pki/base/common/src/com/netscape/cmscore/connector/HttpRequestEncoder.java +++ b/pki/base/common/src/com/netscape/cmscore/connector/HttpRequestEncoder.java @@ -26,6 +26,7 @@ import java.io.OptionalDataException; import com.netscape.certsrv.connector.IRequestEncoder; import com.netscape.cmscore.util.Debug; +import com.netscape.cmsutil.util.Utils; /** * encodes a request by serializing it. @@ -40,7 +41,7 @@ public class HttpRequestEncoder implements IRequestEncoder { os.writeObject(r); serial = ba.toByteArray(); - s = com.netscape.osutil.OSUtil.BtoA(serial); + s = Utils.base64encode(serial); return s; } @@ -51,7 +52,7 @@ public class HttpRequestEncoder implements IRequestEncoder { try { - serial = com.netscape.osutil.OSUtil.AtoB(s); + serial = Utils.base64decode(s); ByteArrayInputStream ba = new ByteArrayInputStream(serial); ObjectInputStream is = new ObjectInputStream(ba); diff --git a/pki/base/common/src/com/netscape/cmscore/policy/GeneralNameUtil.java b/pki/base/common/src/com/netscape/cmscore/policy/GeneralNameUtil.java index 14062e9d4..6afaea997 100644 --- a/pki/base/common/src/com/netscape/cmscore/policy/GeneralNameUtil.java +++ b/pki/base/common/src/com/netscape/cmscore/policy/GeneralNameUtil.java @@ -48,6 +48,7 @@ import com.netscape.certsrv.policy.IGeneralNamesAsConstraintsConfig; import com.netscape.certsrv.policy.IGeneralNamesConfig; import com.netscape.certsrv.policy.ISubjAltNameConfig; import com.netscape.cmscore.util.Debug; +import com.netscape.cmsutil.util.Utils; /** * Class that can be used to form general names from configuration file. @@ -101,7 +102,7 @@ public class GeneralNameUtil implements IGeneralNameUtil { try { if (generalNameChoice.equalsIgnoreCase(GENNAME_CHOICE_OTHERNAME)) { - byte[] val = com.netscape.osutil.OSUtil.AtoB(value); + byte[] val = Utils.base64decode(value); derVal = new DerValue(new ByteArrayInputStream(val)); Debug.trace("otherName formed"); diff --git a/pki/base/common/src/com/netscape/cmscore/security/JssSubsystem.java b/pki/base/common/src/com/netscape/cmscore/security/JssSubsystem.java index 8bcc74de5..ac44672d2 100644 --- a/pki/base/common/src/com/netscape/cmscore/security/JssSubsystem.java +++ b/pki/base/common/src/com/netscape/cmscore/security/JssSubsystem.java @@ -99,6 +99,7 @@ import com.netscape.cmscore.cert.CertPrettyPrint; import com.netscape.cmscore.cert.CertUtils; import com.netscape.cmscore.util.Debug; import com.netscape.cmsutil.crypto.CryptoUtil; +import com.netscape.cmsutil.util.Utils; /** * Subsystem for initializing JSS> @@ -1660,7 +1661,7 @@ public final class JssSubsystem implements ICryptoSubsystem { DN dn = new DN(principal.getName()); BigInteger serialno = cert.getSerialNumber(); String suffix = "." + System.currentTimeMillis(); - String b64E = com.netscape.osutil.OSUtil.BtoA(cert.getEncoded()); + String b64E = Utils.base64encode(cert.getEncoded()); PrintStream stream = new PrintStream(new FileOutputStream(pathname + suffix)); stream.println("-----BEGIN CERTIFICATE-----"); @@ -2017,7 +2018,7 @@ public final class JssSubsystem implements ICryptoSubsystem { String content = ""; String noHeader = CertUtils.stripCertBrackets(b64E); String normalized = CertUtils.normalizeCertStr(noHeader); - byte data[] = com.netscape.osutil.OSUtil.AtoB(normalized); + byte data[] = Utils.base64decode(normalized); ContentInfo ci = (ContentInfo) ASN1Util.decode(ContentInfo.getTemplate(), data); diff --git a/pki/base/common/src/com/netscape/cmscore/security/KeyCertUtil.java b/pki/base/common/src/com/netscape/cmscore/security/KeyCertUtil.java index 3eef57718..20cdae832 100644 --- a/pki/base/common/src/com/netscape/cmscore/security/KeyCertUtil.java +++ b/pki/base/common/src/com/netscape/cmscore/security/KeyCertUtil.java @@ -114,6 +114,7 @@ import com.netscape.cmscore.dbs.BigIntegerMapper; import com.netscape.cmscore.dbs.DateMapper; import com.netscape.cmscore.dbs.X509CertImplMapper; import com.netscape.cmsutil.crypto.CryptoUtil; +import com.netscape.cmsutil.util.Utils; /** * This class provides all the base methods to generate the key for different @@ -136,7 +137,7 @@ public class KeyCertUtil { if (ext != null) { try { - b = (byte[]) (com.netscape.osutil.OSUtil.AtoB(ext)); + b = Utils.base64decode(ext); // this b can be "Extension" Or "SEQUENCE OF Extension" DerValue b_der = new DerValue(b); @@ -761,7 +762,7 @@ public class KeyCertUtil { public static byte[] convertB64EToByteArray(String b64E) throws CertificateException, IOException { String str = CertUtils.stripCertBrackets(b64E); - byte bCert[] = (byte[]) (com.netscape.osutil.OSUtil.AtoB(str)); + byte bCert[] = Utils.base64decode(str); /* java.security.cert.X509Certificate cert = @@ -804,7 +805,7 @@ public class KeyCertUtil { String b64E = properties.getDerExtension(); if (b64E != null) { - byte[] b = (byte[]) (com.netscape.osutil.OSUtil.AtoB(b64E)); + byte[] b = Utils.base64decode(b64E); // this b can be "Extension" Or "SEQUENCE OF Extension" try { diff --git a/pki/base/common/src/com/netscape/cmscore/security/PWsdrCache.java b/pki/base/common/src/com/netscape/cmscore/security/PWsdrCache.java index 4142f6abe..6c834d0e0 100644 --- a/pki/base/common/src/com/netscape/cmscore/security/PWsdrCache.java +++ b/pki/base/common/src/com/netscape/cmscore/security/PWsdrCache.java @@ -184,7 +184,7 @@ public class PWsdrCache { } public byte[] base64Decode(String s) throws IOException { - byte[] d = com.netscape.osutil.OSUtil.AtoB(s); + byte[] d = Utils.base64decode(s); return d; } diff --git a/pki/base/java-tools/src/com/netscape/cmstools/AtoB.java b/pki/base/java-tools/src/com/netscape/cmstools/AtoB.java index 691bc9b19..48301e492 100644 --- a/pki/base/java-tools/src/com/netscape/cmstools/AtoB.java +++ b/pki/base/java-tools/src/com/netscape/cmstools/AtoB.java @@ -25,6 +25,8 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; +import com.netscape.cmsutil.util.Utils; + /** * The AtoB class is a utility program designed to "translate" an ASCII * BASE 64 encoded blob into a BINARY BASE 64 encoded blob. It assumes @@ -113,7 +115,7 @@ public class AtoB { // (5) Decode the ASCII BASE 64 blob enclosed in the // String() object into a BINARY BASE 64 byte[] object - binaryBASE64Blob = com.netscape.osutil.OSUtil.AtoB(asciiBASE64Blob); + binaryBASE64Blob = Utils.base64decode(asciiBASE64Blob); // (6) Finally, print the actual AtoB blob to the // specified output file diff --git a/pki/base/java-tools/src/com/netscape/cmstools/AuditVerify.java b/pki/base/java-tools/src/com/netscape/cmstools/AuditVerify.java index 8a8854f8f..fb23e89fd 100644 --- a/pki/base/java-tools/src/com/netscape/cmstools/AuditVerify.java +++ b/pki/base/java-tools/src/com/netscape/cmstools/AuditVerify.java @@ -36,6 +36,8 @@ import org.mozilla.jss.CryptoManager; import org.mozilla.jss.crypto.ObjectNotFoundException; import org.mozilla.jss.crypto.X509Certificate; +import com.netscape.cmsutil.util.Utils; + /** * Tool for verifying signed audit logs * @@ -52,7 +54,7 @@ public class AuditVerify { public static final String CRYPTO_PROVIDER = "Mozilla-JSS"; public static byte[] base64decode(String input) throws Exception { - return com.netscape.osutil.OSUtil.AtoB(input); + return Utils.base64decode(input); } // We always sign 0x0a as the line separator, regardless of what diff --git a/pki/base/java-tools/src/com/netscape/cmstools/BtoA.java b/pki/base/java-tools/src/com/netscape/cmstools/BtoA.java index 3d281d0cc..4c2e5c22a 100644 --- a/pki/base/java-tools/src/com/netscape/cmstools/BtoA.java +++ b/pki/base/java-tools/src/com/netscape/cmstools/BtoA.java @@ -22,6 +22,8 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; +import com.netscape.cmsutil.util.Utils; + /** * The BtoA class is a utility program designed to "translate" a BINARY * BASE 64 encoded blob into an ASCII BASE 64 encoded blob. It assumes @@ -88,7 +90,7 @@ public class BtoA { try { byte data[] = new byte[inputBlob.available()]; inputBlob.read(data); - String out = com.netscape.osutil.OSUtil.BtoA(data); + String out = Utils.base64encode(data); outputBlob.write(out.getBytes()); } catch (IOException e) { System.out.println("BtoA(): Unexpected BASE64 " + diff --git a/pki/base/java-tools/src/com/netscape/cmstools/CMCEnroll.java b/pki/base/java-tools/src/com/netscape/cmstools/CMCEnroll.java index d739fbcff..e2e51a29d 100644 --- a/pki/base/java-tools/src/com/netscape/cmstools/CMCEnroll.java +++ b/pki/base/java-tools/src/com/netscape/cmstools/CMCEnroll.java @@ -65,6 +65,8 @@ import org.mozilla.jss.pkix.primitive.AlgorithmIdentifier; import org.mozilla.jss.pkix.primitive.Name; import org.mozilla.jss.util.Password; +import com.netscape.cmsutil.util.Utils; + /** * Tool for signing PKCS #10 , return CMC enrollment request * @@ -142,7 +144,7 @@ public class CMCEnroll { ContentInfo fullEnrollmentReq = null; try { - byte[] decodedBytes = com.netscape.osutil.OSUtil.AtoB(asciiBASE64Blob); + byte[] decodedBytes = Utils.base64decode(asciiBASE64Blob); pkcs = new PKCS10(decodedBytes); } catch (IOException e) { @@ -199,7 +201,7 @@ public class CMCEnroll { dig = salt.getBytes(); } - String sn = com.netscape.osutil.OSUtil.BtoA(dig); + String sn = Utils.base64encode(dig); TaggedAttribute senderNonce = new TaggedAttribute(new INTEGER(bpid++), @@ -287,7 +289,7 @@ public class CMCEnroll { ByteArrayOutputStream os = new ByteArrayOutputStream(); fullEnrollmentReq.encode(os); - ps.print(com.netscape.osutil.OSUtil.BtoA(os.toByteArray())); + ps.print(Utils.base64encode(os.toByteArray())); //fullEnrollmentReq.print(ps); // no header/trailer asciiBASE64Blob = bs.toString(); } catch (Exception e) { @@ -423,7 +425,7 @@ public class CMCEnroll { @SuppressWarnings("unused") byte binaryBASE64Blob[] = - com.netscape.osutil.OSUtil.AtoB(asciiBASE64Blob); // check for errors + Utils.base64decode(asciiBASE64Blob); // check for errors // (6) Finally, print the actual CMCEnroll blob to the // specified output file diff --git a/pki/base/java-tools/src/com/netscape/cmstools/CMCRequest.java b/pki/base/java-tools/src/com/netscape/cmstools/CMCRequest.java index a4368736c..591361149 100644 --- a/pki/base/java-tools/src/com/netscape/cmstools/CMCRequest.java +++ b/pki/base/java-tools/src/com/netscape/cmstools/CMCRequest.java @@ -82,6 +82,7 @@ import org.mozilla.jss.pkix.primitive.SubjectPublicKeyInfo; import org.mozilla.jss.util.Password; import com.netscape.cmsutil.util.HMACDigest; +import com.netscape.cmsutil.util.Utils; /** * Tool for creating CMC full request @@ -184,7 +185,7 @@ public class CMCRequest { try { for (int k = 0; k < rValue.length; k++) { String asciiBASE64Blob = rValue[k]; - byte[] decodedBytes = com.netscape.osutil.OSUtil.AtoB(asciiBASE64Blob); + byte[] decodedBytes = Utils.base64decode(asciiBASE64Blob); if (format.equals("crmf")) { ByteArrayInputStream reqBlob = @@ -291,7 +292,7 @@ public class CMCRequest { ByteArrayOutputStream os = new ByteArrayOutputStream(); fullEnrollmentReq.encode(os); - ps.print(com.netscape.osutil.OSUtil.BtoA(os.toByteArray())); + ps.print(Utils.base64encode(os.toByteArray())); } String asciiBASE64Blob = bs.toString(); @@ -754,7 +755,7 @@ public class CMCRequest { dig = salt.getBytes(); } - sn = com.netscape.osutil.OSUtil.BtoA(dig); + sn = Utils.base64encode(dig); } byte bb[] = sn.getBytes(); System.out.println("SenderNonce control: "); diff --git a/pki/base/java-tools/src/com/netscape/cmstools/CMCRevoke.java b/pki/base/java-tools/src/com/netscape/cmstools/CMCRevoke.java index 57be364d7..f29984713 100644 --- a/pki/base/java-tools/src/com/netscape/cmstools/CMCRevoke.java +++ b/pki/base/java-tools/src/com/netscape/cmstools/CMCRevoke.java @@ -59,6 +59,8 @@ import org.mozilla.jss.pkix.primitive.AlgorithmIdentifier; import org.mozilla.jss.pkix.primitive.Name; import org.mozilla.jss.util.Password; +import com.netscape.cmsutil.util.Utils; + /** * Tool for signing a CMC revocation request with an agent's certificate. * @@ -322,7 +324,7 @@ public class CMCRevoke { } catch (NoSuchAlgorithmException ex) { dig = salt.getBytes(); } - String sn = com.netscape.osutil.OSUtil.BtoA(dig); + String sn = Utils.base64encode(dig); TaggedAttribute senderNonce = new TaggedAttribute(new INTEGER(bpid++), OBJECT_IDENTIFIER.id_cmc_senderNonce, @@ -410,7 +412,7 @@ public class CMCRevoke { if (fullEnrollmentReq != null) { // format is PR_REQUEST_CMC fullEnrollmentReq.encode(os); - ps.print(com.netscape.osutil.OSUtil.BtoA(os.toByteArray())); + ps.print(Utils.base64encode(os.toByteArray())); ////fullEnrollmentReq.print(ps); // no header/trailer } diff --git a/pki/base/java-tools/src/com/netscape/cmstools/CRMFPopClient.java b/pki/base/java-tools/src/com/netscape/cmstools/CRMFPopClient.java index c45148f79..22ebd6715 100644 --- a/pki/base/java-tools/src/com/netscape/cmstools/CRMFPopClient.java +++ b/pki/base/java-tools/src/com/netscape/cmstools/CRMFPopClient.java @@ -68,6 +68,7 @@ import org.mozilla.jss.pkix.primitive.SubjectPublicKeyInfo; import org.mozilla.jss.util.Password; import com.netscape.cmsutil.util.HMACDigest; +import com.netscape.cmsutil.util.Utils; /** * A command-line utility used to generate a Certificate Request Message @@ -309,7 +310,7 @@ public class CRMFPopClient { System.out.println("."); //key pair generated"); // wrap private key - byte transport[] = com.netscape.osutil.OSUtil.AtoB(transportCert); + byte transport[] = Utils.base64decode(transportCert); X509Certificate tcert = manager.importCACertPackage(transport); @@ -473,7 +474,7 @@ public class CRMFPopClient { s1.addElement(crmfMsg); byte encoded[] = ASN1Util.encode(s1); - String Req1 = com.netscape.osutil.OSUtil.BtoA(encoded); + String Req1 = Utils.base64encode(encoded); if (OUTPUT_CERT_REQ != null) { System.out.println("Generated Cert Request: ...... "); diff --git a/pki/base/java-tools/src/com/netscape/cmstools/DRMTool.java b/pki/base/java-tools/src/com/netscape/cmstools/DRMTool.java index c3a91dcd7..e2fd2c538 100644 --- a/pki/base/java-tools/src/com/netscape/cmstools/DRMTool.java +++ b/pki/base/java-tools/src/com/netscape/cmstools/DRMTool.java @@ -65,6 +65,8 @@ import org.mozilla.jss.crypto.X509Certificate; import org.mozilla.jss.pkcs11.PK11PubKey; import org.mozilla.jss.util.Password; +import com.netscape.cmsutil.util.Utils; + /** * The DRMTool class is a utility program designed to operate on an LDIF file * to perform one or more of the following tasks: @@ -1512,7 +1514,7 @@ public class DRMTool { // Decode the ASCII BASE 64 certificate enclosed in the // String() object into a BINARY BASE 64 byte[] object - decodedBASE64Cert = com.netscape.osutil.OSUtil.AtoB( + decodedBASE64Cert = Utils.base64decode( encodedBASE64Cert); // Create an X509CertImpl() object from @@ -1842,13 +1844,13 @@ public class DRMTool { 0); if (mDebug) { log("DEBUG: sk = '" - + com.netscape.osutil.OSUtil.BtoA(sk.getEncoded()) + + Utils.base64encode(sk.getEncoded()) + "' length = '" + sk.getEncoded().length + "'" + NEWLINE, false); log("DEBUG: pri = '" - + com.netscape.osutil.OSUtil.BtoA(pri) + + Utils.base64encode(pri) + "' length = '" + pri.length + "'" @@ -3703,7 +3705,7 @@ public class DRMTool { // enclosed in the String() object // into a BINARY BASE 64 byte[] object source_wrappedKeyData = - com.netscape.osutil.OSUtil.AtoB(data); + Utils.base64decode(data); // rewrap the source wrapped private key data target_wrappedKeyData = rewrap_wrapped_key_data( @@ -3712,7 +3714,7 @@ public class DRMTool { // Encode the BINARY BASE 64 byte[] object // into an ASCII BASE 64 certificate // enclosed in a String() object - revised_data = com.netscape.osutil.OSUtil.BtoA( + revised_data = Utils.base64encode( target_wrappedKeyData); // Unformat the ASCII BASE 64 certificate @@ -3777,7 +3779,7 @@ public class DRMTool { // enclosed in the String() object // into a BINARY BASE 64 byte[] object source_wrappedKeyData = - com.netscape.osutil.OSUtil.AtoB(data); + Utils.base64decode(data); // rewrap the source wrapped private key data target_wrappedKeyData = rewrap_wrapped_key_data( @@ -3786,7 +3788,7 @@ public class DRMTool { // Encode the BINARY BASE 64 byte[] object // into an ASCII BASE 64 certificate // enclosed in a String() object - revised_data = com.netscape.osutil.OSUtil.BtoA( + revised_data = Utils.base64encode( target_wrappedKeyData); // Unformat the ASCII BASE 64 certificate diff --git a/pki/base/java-tools/src/com/netscape/cmstools/ExtJoiner.java b/pki/base/java-tools/src/com/netscape/cmstools/ExtJoiner.java index 4362839ea..48f180add 100644 --- a/pki/base/java-tools/src/com/netscape/cmstools/ExtJoiner.java +++ b/pki/base/java-tools/src/com/netscape/cmstools/ExtJoiner.java @@ -20,6 +20,8 @@ package com.netscape.cmstools; import java.io.FileInputStream; import java.io.IOException; +import com.netscape.cmsutil.util.Utils; + import netscape.security.util.DerOutputStream; import netscape.security.util.DerValue; @@ -81,7 +83,7 @@ public class ExtJoiner { DerOutputStream out = new DerOutputStream(); out.putSequence(exts); - System.out.println(com.netscape.osutil.OSUtil.BtoA(out.toByteArray())); + System.out.println(Utils.base64encode(out.toByteArray())); } catch (IOException e) { System.out.println(e.toString()); } @@ -97,6 +99,6 @@ public class ExtJoiner { } finally { fis.close(); } - return com.netscape.osutil.OSUtil.AtoB(new String(data)); + return Utils.base64decode(new String(data)); } } diff --git a/pki/base/java-tools/src/com/netscape/cmstools/GenExtKeyUsage.java b/pki/base/java-tools/src/com/netscape/cmstools/GenExtKeyUsage.java index fc3511f27..35072aae3 100644 --- a/pki/base/java-tools/src/com/netscape/cmstools/GenExtKeyUsage.java +++ b/pki/base/java-tools/src/com/netscape/cmstools/GenExtKeyUsage.java @@ -19,6 +19,8 @@ package com.netscape.cmstools; import java.util.Vector; +import com.netscape.cmsutil.util.Utils; + import netscape.security.util.DerOutputStream; import netscape.security.util.DerValue; import netscape.security.util.ObjectIdentifier; @@ -89,7 +91,7 @@ public class GenExtKeyUsage { // BASE64 encode the whole thing and write it to stdout - System.out.println(com.netscape.osutil.OSUtil.BtoA(extdos.toByteArray())); + System.out.println(Utils.base64encode(extdos.toByteArray())); } catch (Exception e) { e.printStackTrace(); diff --git a/pki/base/java-tools/src/com/netscape/cmstools/GenIssuerAltNameExt.java b/pki/base/java-tools/src/com/netscape/cmstools/GenIssuerAltNameExt.java index 0c91d220e..5c905278f 100644 --- a/pki/base/java-tools/src/com/netscape/cmstools/GenIssuerAltNameExt.java +++ b/pki/base/java-tools/src/com/netscape/cmstools/GenIssuerAltNameExt.java @@ -20,6 +20,8 @@ package com.netscape.cmstools; import java.io.ByteArrayOutputStream; import java.net.InetAddress; +import com.netscape.cmsutil.util.Utils; + import netscape.security.util.ObjectIdentifier; import netscape.security.x509.DNSName; import netscape.security.x509.GeneralNameInterface; @@ -90,7 +92,7 @@ public class GenIssuerAltNameExt { ext.encode(os); System.out.println( - com.netscape.osutil.OSUtil.BtoA(os.toByteArray()) + Utils.base64encode(os.toByteArray()) ); } diff --git a/pki/base/java-tools/src/com/netscape/cmstools/GenSubjectAltNameExt.java b/pki/base/java-tools/src/com/netscape/cmstools/GenSubjectAltNameExt.java index c6814a4f7..35e07f772 100644 --- a/pki/base/java-tools/src/com/netscape/cmstools/GenSubjectAltNameExt.java +++ b/pki/base/java-tools/src/com/netscape/cmstools/GenSubjectAltNameExt.java @@ -20,6 +20,8 @@ package com.netscape.cmstools; import java.io.ByteArrayOutputStream; import java.net.InetAddress; +import com.netscape.cmsutil.util.Utils; + import netscape.security.util.ObjectIdentifier; import netscape.security.x509.DNSName; import netscape.security.x509.GeneralNameInterface; @@ -90,7 +92,7 @@ public class GenSubjectAltNameExt { ext.encode(os); System.out.println( - com.netscape.osutil.OSUtil.BtoA(os.toByteArray()) + Utils.base64encode(os.toByteArray()) ); } diff --git a/pki/base/java-tools/src/com/netscape/cmstools/HttpClient.java b/pki/base/java-tools/src/com/netscape/cmstools/HttpClient.java index 68e5fb5a1..e98847611 100644 --- a/pki/base/java-tools/src/com/netscape/cmstools/HttpClient.java +++ b/pki/base/java-tools/src/com/netscape/cmstools/HttpClient.java @@ -42,6 +42,8 @@ import org.mozilla.jss.ssl.SSLHandshakeCompletedListener; import org.mozilla.jss.ssl.SSLSocket; import org.mozilla.jss.util.Password; +import com.netscape.cmsutil.util.Utils; + /** * This class implements a CMC Enroll client for testing. * @@ -213,7 +215,7 @@ public class HttpClient { ByteArrayOutputStream bs = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(bs); - ps.print(com.netscape.osutil.OSUtil.BtoA(bout)); + ps.print(Utils.base64encode(bout)); System.out.println(bs.toString()); System.out.println(""); diff --git a/pki/base/java-tools/src/com/netscape/cmstools/OCSPClient.java b/pki/base/java-tools/src/com/netscape/cmstools/OCSPClient.java index 860893a38..d127fd99a 100644 --- a/pki/base/java-tools/src/com/netscape/cmstools/OCSPClient.java +++ b/pki/base/java-tools/src/com/netscape/cmstools/OCSPClient.java @@ -55,6 +55,7 @@ import com.netscape.cmsutil.ocsp.RevokedInfo; import com.netscape.cmsutil.ocsp.SingleResponse; import com.netscape.cmsutil.ocsp.TBSRequest; import com.netscape.cmsutil.ocsp.UnknownInfo; +import com.netscape.cmsutil.util.Utils; /** * This class implements a OCSP client for testing. @@ -129,7 +130,7 @@ public class OCSPClient { dos.flush(); System.out.println("Data Length: " + request_data.length); - System.out.println("Data: " + com.netscape.osutil.OSUtil.BtoA(request_data)); + System.out.println("Data: " + Utils.base64encode(request_data)); InputStream iiss = socket.getInputStream(); FileOutputStream fof = new FileOutputStream(output); diff --git a/pki/base/java-tools/src/com/netscape/cmstools/PKCS10Client.java b/pki/base/java-tools/src/com/netscape/cmstools/PKCS10Client.java index 5c7722c5a..7cd50a37a 100644 --- a/pki/base/java-tools/src/com/netscape/cmstools/PKCS10Client.java +++ b/pki/base/java-tools/src/com/netscape/cmstools/PKCS10Client.java @@ -45,6 +45,7 @@ import org.mozilla.jss.pkix.primitive.SubjectPublicKeyInfo; import org.mozilla.jss.util.Password; import com.netscape.cmsutil.util.HMACDigest; +import com.netscape.cmsutil.util.Utils; /** * Generates a 1024-bit RSA key pair in the security database, constructs a @@ -152,7 +153,7 @@ public class PKCS10Client { certRequest.encode(bos); byte[] bb = bos.toByteArray(); - String b64E = com.netscape.osutil.OSUtil.BtoA(bb); + String b64E = Utils.base64encode(bb); System.out.println(""); System.out.println(b64E); diff --git a/pki/base/java-tools/src/com/netscape/cmstools/PasswordCache.java b/pki/base/java-tools/src/com/netscape/cmstools/PasswordCache.java index abb09db62..ba7fb72a4 100644 --- a/pki/base/java-tools/src/com/netscape/cmstools/PasswordCache.java +++ b/pki/base/java-tools/src/com/netscape/cmstools/PasswordCache.java @@ -41,6 +41,8 @@ import org.mozilla.jss.crypto.TokenException; import org.mozilla.jss.util.Base64OutputStream; import org.mozilla.jss.util.Password; +import com.netscape.cmsutil.util.Utils; + /** * Tool for interacting with the PWcache * @@ -120,7 +122,7 @@ public class PasswordCache { } public static byte[] base64Decode(String s) throws IOException { - byte[] d = com.netscape.osutil.OSUtil.AtoB(s); + byte[] d = Utils.base64decode(s); return d; } diff --git a/pki/base/java-tools/src/com/netscape/cmstools/PrettyPrintCert.java b/pki/base/java-tools/src/com/netscape/cmstools/PrettyPrintCert.java index ddbd95c8d..382c4e312 100644 --- a/pki/base/java-tools/src/com/netscape/cmstools/PrettyPrintCert.java +++ b/pki/base/java-tools/src/com/netscape/cmstools/PrettyPrintCert.java @@ -27,6 +27,8 @@ import java.io.InputStreamReader; import java.security.cert.CertificateException; import java.util.Locale; +import com.netscape.cmsutil.util.Utils; + import netscape.security.util.CertPrettyPrint; import netscape.security.x509.CertificateSubjectName; import netscape.security.x509.RDN; @@ -171,7 +173,7 @@ public class PrettyPrintCert { // (5) Decode the ASCII BASE 64 certificate enclosed in the // String() object into a BINARY BASE 64 byte[] object - decodedBASE64Cert = com.netscape.osutil.OSUtil.AtoB(encodedBASE64Cert); + decodedBASE64Cert = Utils.base64decode(encodedBASE64Cert); // (6) Create an X509CertImpl() object from the BINARY BASE 64 // byte[] object diff --git a/pki/base/java-tools/src/com/netscape/cmstools/PrettyPrintCrl.java b/pki/base/java-tools/src/com/netscape/cmstools/PrettyPrintCrl.java index e191de027..8801b2423 100644 --- a/pki/base/java-tools/src/com/netscape/cmstools/PrettyPrintCrl.java +++ b/pki/base/java-tools/src/com/netscape/cmstools/PrettyPrintCrl.java @@ -28,6 +28,8 @@ import java.security.cert.CRLException; import java.security.cert.CertificateException; import java.util.Locale; +import com.netscape.cmsutil.util.Utils; + import netscape.security.util.CrlPrettyPrint; import netscape.security.x509.DeltaCRLIndicatorExtension; import netscape.security.x509.HoldInstructionExtension; @@ -154,7 +156,7 @@ public class PrettyPrintCrl { // (5) Decode the ASCII BASE 64 CRL enclosed in the // String() object into a BINARY BASE 64 byte[] object - decodedBASE64Crl = com.netscape.osutil.OSUtil.AtoB(encodedBASE64Crl); + decodedBASE64Crl = Utils.base64decode(encodedBASE64Crl); // (6) Create an X509CRLImpl() object from the BINARY BASE 64 // byte[] object diff --git a/pki/base/kra/functional/src/com/netscape/cms/servlet/test/DRMRestClient.java b/pki/base/kra/functional/src/com/netscape/cms/servlet/test/DRMRestClient.java index 4f7de8f84..eaf6b98dd 100644 --- a/pki/base/kra/functional/src/com/netscape/cms/servlet/test/DRMRestClient.java +++ b/pki/base/kra/functional/src/com/netscape/cms/servlet/test/DRMRestClient.java @@ -18,6 +18,7 @@ import com.netscape.cms.servlet.request.model.ArchivalRequestData; import com.netscape.cms.servlet.request.model.KeyRequestInfo; import com.netscape.cms.servlet.request.model.KeyRequestInfos; import com.netscape.cms.servlet.request.model.RecoveryRequestData; +import com.netscape.cmsutil.util.Utils; public class DRMRestClient { @@ -52,7 +53,7 @@ public class DRMRestClient { public KeyRequestInfo archiveSecurityData(byte[] encoded, String clientId, String dataType) { // create archival request ArchivalRequestData data = new ArchivalRequestData(); - String req1 = com.netscape.osutil.OSUtil.BtoA(encoded); + String req1 = Utils.base64encode(encoded); data.setWrappedPrivateData(req1); data.setClientId(clientId); data.setDataType(dataType); @@ -81,14 +82,14 @@ public class DRMRestClient { RecoveryRequestData data = new RecoveryRequestData(); data.setKeyId(keyId); if (rpwd != null) { - data.setSessionWrappedPassphrase(com.netscape.osutil.OSUtil.BtoA(rpwd)); + data.setSessionWrappedPassphrase(Utils.base64encode(rpwd)); } if (rkey != null) { - data.setTransWrappedSessionKey(com.netscape.osutil.OSUtil.BtoA(rkey)); + data.setTransWrappedSessionKey(Utils.base64encode(rkey)); } if (nonceData != null) { - data.setNonceData(com.netscape.osutil.OSUtil.BtoA(nonceData)); + data.setNonceData(Utils.base64encode(nonceData)); } KeyRequestInfo info = keyRequestClient.recoverKey(data); @@ -105,14 +106,14 @@ public class DRMRestClient { data.setKeyId(keyId); data.setRequestId(requestId); if (rkey != null) { - data.setTransWrappedSessionKey(com.netscape.osutil.OSUtil.BtoA(rkey)); + data.setTransWrappedSessionKey(Utils.base64encode(rkey)); } if (rpwd != null) { - data.setSessionWrappedPassphrase(com.netscape.osutil.OSUtil.BtoA(rpwd)); + data.setSessionWrappedPassphrase(Utils.base64encode(rpwd)); } if (nonceData != null) { - data.setNonceData(com.netscape.osutil.OSUtil.BtoA(nonceData)); + data.setNonceData(Utils.base64encode(nonceData)); } KeyData key = keyClient.retrieveKey(data); diff --git a/pki/base/kra/functional/src/com/netscape/cms/servlet/test/DRMTest.java b/pki/base/kra/functional/src/com/netscape/cms/servlet/test/DRMTest.java index fb2ef7799..368cb7282 100644 --- a/pki/base/kra/functional/src/com/netscape/cms/servlet/test/DRMTest.java +++ b/pki/base/kra/functional/src/com/netscape/cms/servlet/test/DRMTest.java @@ -44,6 +44,7 @@ import com.netscape.cms.servlet.key.model.KeyDataInfo; import com.netscape.cms.servlet.request.KeyRequestResource; import com.netscape.cms.servlet.request.model.KeyRequestInfo; import com.netscape.cmsutil.crypto.CryptoUtil; +import com.netscape.cmsutil.util.Utils; public class DRMTest { @@ -261,17 +262,17 @@ public class DRMTest { keyData = client.retrieveKey(keyId, recoveryRequestId, null, wrappedRecoveryKey, ivps.getIV()); wrappedRecoveredKey = keyData.getWrappedPrivateData(); - ivps_server = new IVParameterSpec(com.netscape.osutil.OSUtil.AtoB(keyData.getNonceData())); + ivps_server = new IVParameterSpec(Utils.base64decode(keyData.getNonceData())); try { recoveredKey = CryptoUtil.unwrapUsingSymmetricKey(token, ivps_server, - com.netscape.osutil.OSUtil.AtoB(wrappedRecoveredKey), + Utils.base64decode(wrappedRecoveredKey), recoveryKey, EncryptionAlgorithm.DES3_CBC_PAD); } catch (Exception e) { log("Exception in unwrapping key: " + e.toString()); e.printStackTrace(); } - if (!recoveredKey.equals(com.netscape.osutil.OSUtil.BtoA(vek.getEncoded()))) { + if (!recoveredKey.equals(Utils.base64encode(vek.getEncoded()))) { log("Error: recovered and archived keys do not match!"); } else { log("Success: recoverd and archived keys match!"); @@ -310,7 +311,7 @@ public class DRMTest { e.printStackTrace(); } - if (recoveredKey == null || !recoveredKey.equals(com.netscape.osutil.OSUtil.BtoA(vek.getEncoded()))) { + if (recoveredKey == null || !recoveredKey.equals(Utils.base64encode(vek.getEncoded()))) { log("Error: recovered and archived keys do not match!"); } else { log("Success: recovered and archived keys do match!"); @@ -373,12 +374,12 @@ public class DRMTest { keyData = client.retrieveKey(keyId, recoveryRequestId, null, wrappedRecoveryKey, ivps.getIV()); wrappedRecoveredKey = keyData.getWrappedPrivateData(); - ivps_server = new IVParameterSpec( com.netscape.osutil.OSUtil.AtoB(keyData.getNonceData())); + ivps_server = new IVParameterSpec( Utils.base64decode(keyData.getNonceData())); try { recoveredKey = CryptoUtil.unwrapUsingSymmetricKey(token, ivps_server, - com.netscape.osutil.OSUtil.AtoB(wrappedRecoveredKey), + Utils.base64decode(wrappedRecoveredKey), recoveryKey, EncryptionAlgorithm.DES3_CBC_PAD); - recoveredKey = new String(com.netscape.osutil.OSUtil.AtoB(recoveredKey), "UTF-8"); + recoveredKey = new String(Utils.base64decode(recoveredKey), "UTF-8"); } catch (Exception e) { log("Exception in unwrapping key: " + e.toString()); e.printStackTrace(); @@ -405,7 +406,7 @@ public class DRMTest { wrappedRecoveredKey = keyData.getWrappedPrivateData(); try { recoveredKey = CryptoUtil.unwrapUsingPassphrase(wrappedRecoveredKey, recoveryPassphrase); - recoveredKey = new String(com.netscape.osutil.OSUtil.AtoB(recoveredKey), "UTF-8"); + recoveredKey = new String(Utils.base64decode(recoveredKey), "UTF-8"); } catch (Exception e) { log("Error: cannot unwrap key using passphrase"); e.printStackTrace(); @@ -434,7 +435,7 @@ public class DRMTest { wrappedRecoveredKey = keyData.getWrappedPrivateData(); try { recoveredKey = CryptoUtil.unwrapUsingPassphrase(wrappedRecoveredKey, recoveryPassphrase); - recoveredKey = new String(com.netscape.osutil.OSUtil.AtoB(recoveredKey), "UTF-8"); + recoveredKey = new String(Utils.base64decode(recoveredKey), "UTF-8"); } catch (Exception e) { log("Error: Can't unwrap recovered key using passphrase"); e.printStackTrace(); diff --git a/pki/base/kra/functional/src/com/netscape/cms/servlet/test/GeneratePKIArchiveOptions.java b/pki/base/kra/functional/src/com/netscape/cms/servlet/test/GeneratePKIArchiveOptions.java index 0bf0134e0..604430b57 100644 --- a/pki/base/kra/functional/src/com/netscape/cms/servlet/test/GeneratePKIArchiveOptions.java +++ b/pki/base/kra/functional/src/com/netscape/cms/servlet/test/GeneratePKIArchiveOptions.java @@ -36,7 +36,7 @@ import org.mozilla.jss.crypto.TokenException; import org.mozilla.jss.util.Password; import com.netscape.cmsutil.crypto.CryptoUtil; -import com.netscape.osutil.OSUtil; +import com.netscape.cmsutil.util.Utils; @SuppressWarnings("deprecation") public class GeneratePKIArchiveOptions { @@ -168,7 +168,7 @@ public class GeneratePKIArchiveOptions { // used for wrapping to send data to DRM byte[] tcert = read(transport_file); - String transportCert = com.netscape.osutil.OSUtil.BtoA(tcert); + String transportCert = Utils.base64encode(tcert); // Initialize token try { @@ -202,7 +202,7 @@ public class GeneratePKIArchiveOptions { if (!passphraseMode) { vek = CryptoUtil.generateKey(token, KeyGenAlgorithm.DES3); // store vek in file - write_file(OSUtil.BtoA(vek.getKeyData()), key_file); + write_file(Utils.base64encode(vek.getKeyData()), key_file); } byte[] encoded = null; @@ -216,7 +216,7 @@ public class GeneratePKIArchiveOptions { } // write encoded to file - write_file(OSUtil.BtoA(encoded), out_file); + write_file(Utils.base64encode(encoded), out_file); } } diff --git a/pki/base/kra/src/com/netscape/kra/EnrollmentService.java b/pki/base/kra/src/com/netscape/kra/EnrollmentService.java index badeaed23..37d1aea53 100644 --- a/pki/base/kra/src/com/netscape/kra/EnrollmentService.java +++ b/pki/base/kra/src/com/netscape/kra/EnrollmentService.java @@ -65,6 +65,7 @@ import com.netscape.cmscore.crmf.CRMFParser; import com.netscape.cmscore.crmf.PKIArchiveOptionsContainer; import com.netscape.kra.ArchiveOptions; import com.netscape.cmscore.dbs.KeyRecord; +import com.netscape.cmsutil.util.Utils; /** * A class represents archival request processor. It @@ -552,7 +553,7 @@ public class EnrollmentService implements IService { CMS.debug("EnrollmentService::getPKIArchiveOptions> crmfBlob=" + crmfBlob); byte[] crmfBerBlob = null; - crmfBerBlob = com.netscape.osutil.OSUtil.AtoB(crmfBlob); + crmfBerBlob = Utils.base64decode(crmfBlob); ByteArrayInputStream crmfBerBlobIn = new ByteArrayInputStream(crmfBerBlob); SEQUENCE crmfmsgs = null; diff --git a/pki/base/kra/src/com/netscape/kra/SecurityDataRecoveryService.java b/pki/base/kra/src/com/netscape/kra/SecurityDataRecoveryService.java index 6673488e1..f96ece890 100644 --- a/pki/base/kra/src/com/netscape/kra/SecurityDataRecoveryService.java +++ b/pki/base/kra/src/com/netscape/kra/SecurityDataRecoveryService.java @@ -62,6 +62,7 @@ import com.netscape.certsrv.dbs.keydb.IKeyRecord; import com.netscape.certsrv.dbs.keydb.IKeyRepository; import com.netscape.cms.servlet.request.KeyRequestResource; import com.netscape.cmscore.dbs.KeyRecord; +import com.netscape.cmsutil.util.Utils; /** * This implementation services SecurityData Recovery requests. @@ -128,17 +129,17 @@ public class SecurityDataRecoveryService implements IService { String transWrappedSessKeyStr = (String) params.get(IRequest.SECURITY_DATA_TRANS_SESS_KEY); if (transWrappedSessKeyStr != null) { - wrappedSessKey = com.netscape.osutil.OSUtil.AtoB(transWrappedSessKeyStr); + wrappedSessKey = Utils.base64decode(transWrappedSessKeyStr); } String sessWrappedPassPhraseStr = (String) params.get(IRequest.SECURITY_DATA_SESS_PASS_PHRASE); if (sessWrappedPassPhraseStr != null) { - wrappedPassPhrase = com.netscape.osutil.OSUtil.AtoB(sessWrappedPassPhraseStr); + wrappedPassPhrase = Utils.base64decode(sessWrappedPassPhraseStr); } String ivInStr = (String) params.get(IRequest.SECURITY_DATA_IV_STRING_IN); if (ivInStr != null) { - iv_in = com.netscape.osutil.OSUtil.AtoB(ivInStr); + iv_in = Utils.base64decode(ivInStr); } if (transWrappedSessKeyStr == null && sessWrappedPassPhraseStr == null) { @@ -156,7 +157,7 @@ public class SecurityDataRecoveryService implements IService { iv = iv_default; } - String ivStr = com.netscape.osutil.OSUtil.BtoA(iv); + String ivStr = Utils.base64encode(iv); KeyRecord keyRecord = (KeyRecord) mStorage.readKeyRecord(serialno); @@ -239,7 +240,7 @@ public class SecurityDataRecoveryService implements IService { } } - String wrappedKeyData = com.netscape.osutil.OSUtil.BtoA(key_data); + String wrappedKeyData = Utils.base64encode(key_data); params.put(IRequest.SECURITY_DATA_SESS_WRAPPED_DATA, wrappedKeyData); params.put(IRequest.SECURITY_DATA_IV_STRING_OUT, ivStr); @@ -375,7 +376,7 @@ public class SecurityDataRecoveryService implements IService { ByteArrayOutputStream oStream = new ByteArrayOutputStream(); cInfo.encode(oStream); encoded = oStream.toByteArray(); - retData = com.netscape.osutil.OSUtil.BtoA(encoded); + retData = Utils.base64encode(encoded); } catch (Exception e) { throw new EBaseException("Can't create a PBE wrapped EncryptedContentInfo! " + e.toString()); diff --git a/pki/base/kra/src/com/netscape/kra/SecurityDataService.java b/pki/base/kra/src/com/netscape/kra/SecurityDataService.java index 7f9902eda..fa009dac9 100644 --- a/pki/base/kra/src/com/netscape/kra/SecurityDataService.java +++ b/pki/base/kra/src/com/netscape/kra/SecurityDataService.java @@ -32,6 +32,7 @@ import com.netscape.certsrv.dbs.keydb.IKeyRepository; import com.netscape.certsrv.apps.CMS; import com.netscape.cms.servlet.request.KeyRequestResource; import com.netscape.cmscore.dbs.KeyRecord; +import com.netscape.cmsutil.util.Utils; /** * This implementation implements SecurityData archival operations. @@ -87,7 +88,7 @@ public class SecurityDataService implements IService { } //We need some info from the PKIArchiveOptions wrapped security data - byte[] encoded = com.netscape.osutil.OSUtil.AtoB(wrappedSecurityData); + byte[] encoded = Utils.base64decode(wrappedSecurityData); ArchiveOptions options = ArchiveOptions.toArchiveOptions(encoded); diff --git a/pki/base/kra/src/com/netscape/kra/StorageKeyUnit.java b/pki/base/kra/src/com/netscape/kra/StorageKeyUnit.java index 3c61c293b..c956bf8d8 100644 --- a/pki/base/kra/src/com/netscape/kra/StorageKeyUnit.java +++ b/pki/base/kra/src/com/netscape/kra/StorageKeyUnit.java @@ -60,6 +60,7 @@ import com.netscape.certsrv.kra.IShare; import com.netscape.certsrv.logging.ILogger; import com.netscape.certsrv.security.Credential; import com.netscape.certsrv.security.IStorageKeyUnit; +import com.netscape.cmsutil.util.Utils; /** * A class represents a storage key unit. Currently, this @@ -736,9 +737,7 @@ public class StorageKeyUnit extends EncryptionUnit implements byte prev[] = preVerify(share); byte enc[] = cipher.doFinal(prev); - // #615387 - cannot use CMS.BtoA because CMS is not present during - // configuration - return com.netscape.osutil.OSUtil.BtoA(enc).trim(); + return Utils.base64encode(enc).trim(); } catch (NoSuchAlgorithmException e) { throw new EBaseException(CMS.getUserMessage("CMS_BASE_INVALID_KEY_1", e.toString())); diff --git a/pki/base/silent/src/com/netscape/pkisilent/ConfigureCA.java b/pki/base/silent/src/com/netscape/pkisilent/ConfigureCA.java index ee41e5a19..4dc77b894 100644 --- a/pki/base/silent/src/com/netscape/pkisilent/ConfigureCA.java +++ b/pki/base/silent/src/com/netscape/pkisilent/ConfigureCA.java @@ -33,13 +33,13 @@ import org.mozilla.jss.asn1.SEQUENCE; import org.mozilla.jss.pkcs12.AuthenticatedSafes; import org.mozilla.jss.pkcs12.PFX; -import com.netscape.osutil.OSUtil; 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 ConfigureCA { @@ -1035,7 +1035,7 @@ public class ConfigureCA { // Convert a byte array to base64 string // cert_to_import = new sun.misc.BASE64Encoder().encode( // hr.getResponseData()); - cert_to_import = OSUtil.BtoA(hr.getResponseData()); + cert_to_import = Utils.base64encode(hr.getResponseData()); // Convert base64 string to a byte array // buf = new sun.misc.BASE64Decoder().decodeBuffer(s); diff --git a/pki/base/silent/src/com/netscape/pkisilent/ConfigureDRM.java b/pki/base/silent/src/com/netscape/pkisilent/ConfigureDRM.java index caf393ad9..7d15861d1 100644 --- a/pki/base/silent/src/com/netscape/pkisilent/ConfigureDRM.java +++ b/pki/base/silent/src/com/netscape/pkisilent/ConfigureDRM.java @@ -31,13 +31,13 @@ import org.mozilla.jss.asn1.SEQUENCE; import org.mozilla.jss.pkcs12.AuthenticatedSafes; import org.mozilla.jss.pkcs12.PFX; -import com.netscape.osutil.OSUtil; 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 { @@ -775,7 +775,7 @@ public class ConfigureDRM { // String cert_to_import = // new sun.misc.BASE64Encoder().encode(hr.getResponseData()); String cert_to_import = - OSUtil.BtoA(hr.getResponseData()); + Utils.base64encode(hr.getResponseData()); System.out.println("Imported Cert=" + cert_to_import); ComCrypto cCrypt = new ComCrypto(client_certdb_dir, diff --git a/pki/base/silent/src/com/netscape/pkisilent/ConfigureOCSP.java b/pki/base/silent/src/com/netscape/pkisilent/ConfigureOCSP.java index 254d9bcec..149c79dff 100644 --- a/pki/base/silent/src/com/netscape/pkisilent/ConfigureOCSP.java +++ b/pki/base/silent/src/com/netscape/pkisilent/ConfigureOCSP.java @@ -31,13 +31,13 @@ import org.mozilla.jss.asn1.SEQUENCE; import org.mozilla.jss.pkcs12.AuthenticatedSafes; import org.mozilla.jss.pkcs12.PFX; -import com.netscape.osutil.OSUtil; 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"; @@ -676,7 +676,7 @@ public class ConfigureOCSP { // String cert_to_import = // new sun.misc.BASE64Encoder().encode(hr.getResponseData()); String cert_to_import = - OSUtil.BtoA(hr.getResponseData()); + Utils.base64encode(hr.getResponseData()); System.out.println("Imported Cert=" + cert_to_import); ComCrypto cCrypt = new ComCrypto(client_certdb_dir, diff --git a/pki/base/silent/src/com/netscape/pkisilent/ConfigureRA.java b/pki/base/silent/src/com/netscape/pkisilent/ConfigureRA.java index cade95fa8..2d109595a 100644 --- a/pki/base/silent/src/com/netscape/pkisilent/ConfigureRA.java +++ b/pki/base/silent/src/com/netscape/pkisilent/ConfigureRA.java @@ -21,13 +21,13 @@ package com.netscape.pkisilent; import java.io.ByteArrayInputStream; import java.net.URLEncoder; -import com.netscape.osutil.OSUtil; 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 { @@ -516,7 +516,7 @@ public class ConfigureRA { // cert_to_import = // new sun.misc.BASE64Encoder().encode(hr.getResponseData()); cert_to_import = - OSUtil.BtoA(hr.getResponseData()); + Utils.base64encode(hr.getResponseData()); } catch (Exception e) { System.out.println("ERROR: failed to retrieve cert"); diff --git a/pki/base/silent/src/com/netscape/pkisilent/ConfigureSubCA.java b/pki/base/silent/src/com/netscape/pkisilent/ConfigureSubCA.java index 62947e4a2..6dacc9e08 100644 --- a/pki/base/silent/src/com/netscape/pkisilent/ConfigureSubCA.java +++ b/pki/base/silent/src/com/netscape/pkisilent/ConfigureSubCA.java @@ -22,13 +22,13 @@ import java.io.ByteArrayInputStream; import java.net.URLEncoder; import java.util.ArrayList; -import com.netscape.osutil.OSUtil; 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 ConfigureSubCA { @@ -706,7 +706,7 @@ public class ConfigureSubCA { // String cert_to_import = // new sun.misc.BASE64Encoder().encode(hr.getResponseData()); String cert_to_import = - OSUtil.BtoA(hr.getResponseData()); + Utils.base64encode(hr.getResponseData()); System.out.println("Imported Cert=" + cert_to_import); ComCrypto cCrypt = new ComCrypto(client_certdb_dir, diff --git a/pki/base/silent/src/com/netscape/pkisilent/ConfigureTKS.java b/pki/base/silent/src/com/netscape/pkisilent/ConfigureTKS.java index 5fad4790e..092658b50 100644 --- a/pki/base/silent/src/com/netscape/pkisilent/ConfigureTKS.java +++ b/pki/base/silent/src/com/netscape/pkisilent/ConfigureTKS.java @@ -31,13 +31,13 @@ import org.mozilla.jss.asn1.SEQUENCE; import org.mozilla.jss.pkcs12.AuthenticatedSafes; import org.mozilla.jss.pkcs12.PFX; -import com.netscape.osutil.OSUtil; 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 { @@ -643,7 +643,7 @@ public class ConfigureTKS { // String cert_to_import = // new sun.misc.BASE64Encoder().encode(hr.getResponseData()); String cert_to_import = - OSUtil.BtoA(hr.getResponseData()); + Utils.base64encode(hr.getResponseData()); System.out.println("Imported Cert=" + cert_to_import); ComCrypto cCrypt = new ComCrypto(client_certdb_dir, diff --git a/pki/base/silent/src/com/netscape/pkisilent/ConfigureTPS.java b/pki/base/silent/src/com/netscape/pkisilent/ConfigureTPS.java index 4982a2f2d..d4df34a39 100644 --- a/pki/base/silent/src/com/netscape/pkisilent/ConfigureTPS.java +++ b/pki/base/silent/src/com/netscape/pkisilent/ConfigureTPS.java @@ -21,13 +21,13 @@ package com.netscape.pkisilent; import java.io.ByteArrayInputStream; import java.net.URLEncoder; -import com.netscape.osutil.OSUtil; 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 @@ -639,7 +639,7 @@ public class ConfigureTPS { // cert_to_import = // new sun.misc.BASE64Encoder().encode(hr.getResponseData()); cert_to_import = - OSUtil.BtoA(hr.getResponseData()); + Utils.base64encode(hr.getResponseData()); } catch (Exception e) { System.out.println("ERROR: failed to retrieve cert"); diff --git a/pki/base/silent/src/com/netscape/pkisilent/common/ComCrypto.java b/pki/base/silent/src/com/netscape/pkisilent/common/ComCrypto.java index 1c10db8fb..d629030f2 100644 --- a/pki/base/silent/src/com/netscape/pkisilent/common/ComCrypto.java +++ b/pki/base/silent/src/com/netscape/pkisilent/common/ComCrypto.java @@ -58,8 +58,7 @@ import org.mozilla.jss.pkix.primitive.AlgorithmIdentifier; import org.mozilla.jss.pkix.primitive.Name; import org.mozilla.jss.pkix.primitive.SubjectPublicKeyInfo; import org.mozilla.jss.util.Password; - -import com.netscape.osutil.OSUtil; +import com.netscape.cmsutil.util.Utils; /** * CMS Test framework . @@ -586,7 +585,7 @@ public class ComCrypto { // BASE64Encoder encoder = new BASE64Encoder(); // String Req1 = encoder.encodeBuffer(encoded); - String Req1 = OSUtil.BtoA(encoded); + String Req1 = Utils.base64encode(encoded); // Set CRMF_REQUEST variable CRMF_REQUEST = Req1; @@ -661,7 +660,7 @@ public class ComCrypto { // wrap private key // BASE64Decoder decoder = new BASE64Decoder(); // byte transport[] = decoder.decodeBuffer(transportcert); - byte transport[] = OSUtil.AtoB(transportcert); + byte transport[] = Utils.base64decode(transportcert); X509Certificate tcert = manager.importCACertPackage(transport); @@ -749,7 +748,7 @@ public class ComCrypto { // BASE64Encoder encoder = new BASE64Encoder(); // CRMF_REQUEST = encoder.encodeBuffer(encoded); - CRMF_REQUEST = OSUtil.BtoA(encoded); + CRMF_REQUEST = Utils.base64encode(encoded); System.out.println("Generated crmf request: ...... "); System.out.println(""); diff --git a/pki/base/silent/src/com/netscape/pkisilent/common/PostQuery.java b/pki/base/silent/src/com/netscape/pkisilent/common/PostQuery.java index bf5db5043..b6ab3fe8c 100644 --- a/pki/base/silent/src/com/netscape/pkisilent/common/PostQuery.java +++ b/pki/base/silent/src/com/netscape/pkisilent/common/PostQuery.java @@ -27,7 +27,7 @@ import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; -import com.netscape.osutil.OSUtil; +import com.netscape.cmsutil.util.Utils; /** * CMS Test framework . @@ -91,7 +91,7 @@ public class PostQuery { System.out.println("adminpwd=" + adminPWD); // String encoding = new sun.misc.BASE64Encoder().encode( // userPassword.getBytes()); - String encoding = OSUtil.BtoA( + String encoding = Utils.base64encode( userPassword.getBytes()); HttpURLConnection URLCon = (HttpURLConnection) myUrl.openConnection(); diff --git a/pki/base/silent/src/com/netscape/pkisilent/common/Utilities.java b/pki/base/silent/src/com/netscape/pkisilent/common/Utilities.java index 9aaf6c4d9..3e5d6fb4c 100644 --- a/pki/base/silent/src/com/netscape/pkisilent/common/Utilities.java +++ b/pki/base/silent/src/com/netscape/pkisilent/common/Utilities.java @@ -29,7 +29,7 @@ import netscape.security.x509.X500Name; import netscape.security.x509.X509CertImpl; import netscape.security.x509.X509CertInfo; -import com.netscape.osutil.OSUtil; +import com.netscape.cmsutil.util.Utils; public class Utilities { @@ -305,7 +305,7 @@ public class Utilities { try { // BASE64Decoder base64 = new BASE64Decoder(); // byte decodedBASE64Cert[] = base64.decodeBuffer(temp); - byte decodedBASE64Cert[] = OSUtil.AtoB(temp); + byte decodedBASE64Cert[] = Utils.base64decode(temp); X509CertImpl x509_cert = new X509CertImpl(decodedBASE64Cert); X509CertInfo certinfo = (X509CertInfo) x509_cert.get("x509.INFO"); diff --git a/pki/base/silent/src/com/netscape/pkisilent/http/HTTPClient.java b/pki/base/silent/src/com/netscape/pkisilent/http/HTTPClient.java index e2d6b0644..c9584463d 100644 --- a/pki/base/silent/src/com/netscape/pkisilent/http/HTTPClient.java +++ b/pki/base/silent/src/com/netscape/pkisilent/http/HTTPClient.java @@ -38,10 +38,10 @@ import org.mozilla.jss.ssl.SSLSocket; import org.mozilla.jss.ssl.TestCertApprovalCallback; import org.mozilla.jss.ssl.TestClientCertificateSelectionCallback; -import com.netscape.osutil.OSUtil; import com.netscape.pkisilent.argparser.ArgParser; import com.netscape.pkisilent.argparser.StringHolder; import com.netscape.pkisilent.common.ComCrypto; +import com.netscape.cmsutil.util.Utils; public class HTTPClient implements SSLCertificateApprovalCallback { @@ -1168,8 +1168,8 @@ public class HTTPClient implements SSLCertificateApprovalCallback { // String temp = encoder.encodeBuffer((user_id + // ":" + user_password).getBytes()); - String temp = OSUtil.BtoA((user_id + - ":" + user_password).getBytes()); + String temp = Utils.base64encode((user_id + + ":" + user_password).getBytes()); // note: temp already contains \r and \n. // remove \r and \n from the base64 encoded string. diff --git a/pki/base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java b/pki/base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java index 98b8a0bd1..92d0f7e55 100644 --- a/pki/base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java +++ b/pki/base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java @@ -114,7 +114,7 @@ import org.mozilla.jss.util.Base64OutputStream; import org.mozilla.jss.util.Password; import com.netscape.cmsutil.util.Cert; -import com.netscape.osutil.OSUtil; +import com.netscape.cmsutil.util.Utils; public class CryptoUtil { @@ -132,7 +132,7 @@ public class CryptoUtil { try { return "-----BEGIN CERTIFICATE-----\n" // + mEncoder.encodeBuffer(cert.getEncoded()) - + OSUtil.BtoA(cert.getEncoded()) + + Utils.base64encode(cert.getEncoded()) + "-----END CERTIFICATE-----\n"; } catch (Exception e) { } @@ -319,7 +319,7 @@ public class CryptoUtil { public static byte[] base64Decode(String s) throws IOException { // BASE64Decoder base64 = new BASE64Decoder(); // byte[] d = base64.decodeBuffer(s); - byte[] d = OSUtil.AtoB(s); + byte[] d = Utils.base64decode(s); return d; } @@ -1155,7 +1155,7 @@ public class CryptoUtil { PasswordConverter passConverter = new PasswordConverter(); - byte[] encoded = com.netscape.osutil.OSUtil.AtoB(wrappedRecoveredKey); + byte[] encoded = Utils.base64decode(wrappedRecoveredKey); ByteArrayInputStream inStream = new ByteArrayInputStream(encoded); cInfo = (EncryptedContentInfo) @@ -1163,7 +1163,7 @@ public class CryptoUtil { byte[] decodedData = cInfo.decrypt(pass, passConverter); - unwrappedData = com.netscape.osutil.OSUtil.BtoA(decodedData); + unwrappedData = Utils.base64encode(decodedData); return unwrappedData; } @@ -1177,7 +1177,7 @@ public class CryptoUtil { Cipher decryptor = token.getCipherContext(alg); decryptor.initDecrypt(recoveryKey, IV); byte[] unwrappedData = decryptor.doFinal(wrappedRecoveredKey); - String unwrappedS = com.netscape.osutil.OSUtil.BtoA(unwrappedData); + String unwrappedS = Utils.base64encode(unwrappedData); return unwrappedS; } @@ -1206,7 +1206,7 @@ public class CryptoUtil { public static byte[] wrapSymmetricKey(CryptoManager manager, CryptoToken token, String transportCert, SymmetricKey sk) throws CertificateEncodingException, TokenException, NoSuchAlgorithmException, InvalidKeyException, InvalidAlgorithmParameterException { - byte transport[] = com.netscape.osutil.OSUtil.AtoB(transportCert); + byte transport[] = Utils.base64decode(transportCert); X509Certificate tcert = manager.importCACertPackage(transport); KeyWrapper rsaWrap = token.getKeyWrapper(KeyWrapAlgorithm.RSA); rsaWrap.initWrap(tcert.getPublicKey(), null); diff --git a/pki/base/util/src/com/netscape/cmsutil/util/Cert.java b/pki/base/util/src/com/netscape/cmsutil/util/Cert.java index b280a7600..3563f70c7 100644 --- a/pki/base/util/src/com/netscape/cmsutil/util/Cert.java +++ b/pki/base/util/src/com/netscape/cmsutil/util/Cert.java @@ -28,8 +28,6 @@ import netscape.security.x509.X509CertImpl; import org.mozilla.jss.crypto.SignatureAlgorithm; -import com.netscape.osutil.OSUtil; - public class Cert { public static SignatureAlgorithm mapAlgorithmToJss(String algname) { @@ -96,7 +94,7 @@ public class Cert { mime64 = stripCertBrackets(mime64.trim()); String newval = normalizeCertStr(mime64); // byte rawPub[] = mDecoder.decodeBuffer(newval); - byte rawPub[] = OSUtil.AtoB(newval); + byte rawPub[] = Utils.base64decode(newval); X509CertImpl cert = null; try { @@ -111,7 +109,7 @@ public class Cert { mime64 = stripCertBrackets(mime64.trim()); String newval = normalizeCertStr(mime64); // byte rawPub[] = mDecoder.decodeBuffer(newval); - byte rawPub[] = OSUtil.AtoB(newval); + byte rawPub[] = Utils.base64decode(newval); PKCS7 p7 = null; try { @@ -127,7 +125,7 @@ public class Cert { mime64 = stripCRLBrackets(mime64.trim()); String newval = normalizeCertStr(mime64); // byte rawPub[] = mDecoder.decodeBuffer(newval); - byte rawPub[] = OSUtil.AtoB(newval); + byte rawPub[] = Utils.base64decode(newval); X509CRL crl = null; try { @@ -141,7 +139,7 @@ public class Cert { throws IOException { mime64 = stripCRLBrackets(mime64.trim()); - byte rawPub[] = OSUtil.AtoB(mime64); + byte rawPub[] = Utils.base64decode(mime64); X509CRL crl = null; try { diff --git a/pki/base/util/src/com/netscape/cmsutil/util/Utils.java b/pki/base/util/src/com/netscape/cmsutil/util/Utils.java index 06892fd84..a1801785c 100644 --- a/pki/base/util/src/com/netscape/cmsutil/util/Utils.java +++ b/pki/base/util/src/com/netscape/cmsutil/util/Utils.java @@ -39,7 +39,11 @@ public class Utils { * Checks if this is NT. */ public static boolean isNT() { - return ((File.separator).equals("\\")); + return File.separator.equals("\\"); + } + + public static boolean isUnix() { + return File.separator.equals("/"); } public static boolean exec(String cmd) { @@ -251,11 +255,20 @@ public class Utils { * there'll be trouble if the Vector contains something other * than just Strings */ - public static String[] getStringArrayFromVector(Vector v) { + public static String[] getStringArrayFromVector(Vector<String> v) { String s[] = new String[v.size()]; v.copyInto(s); return s; } + public static String base64encode(byte[] bytes) { + String string = com.netscape.osutil.OSUtil.BtoA(bytes); + return string; + } + + public static byte[] base64decode(String string) { + byte[] bytes = com.netscape.osutil.OSUtil.AtoB(string); + return bytes; + } } diff --git a/pki/base/util/src/netscape/security/extensions/AuthInfoAccessExtension.java b/pki/base/util/src/netscape/security/extensions/AuthInfoAccessExtension.java index 0bafcedd0..b8e2933dd 100644 --- a/pki/base/util/src/netscape/security/extensions/AuthInfoAccessExtension.java +++ b/pki/base/util/src/netscape/security/extensions/AuthInfoAccessExtension.java @@ -28,6 +28,8 @@ import java.security.cert.CertificateException; import java.util.Enumeration; import java.util.Vector; +import com.netscape.cmsutil.util.Utils; + import netscape.security.util.DerOutputStream; import netscape.security.util.DerValue; import netscape.security.util.ObjectIdentifier; @@ -244,7 +246,7 @@ public class AuthInfoAccessExtension extends Extension implements CertAttrSet { try { aia.encode(os); - System.out.println(com.netscape.osutil.OSUtil.BtoA(os.toByteArray())); + System.out.println(Utils.base64encode(os.toByteArray())); } catch (IOException e) { System.out.println(e.toString()); } diff --git a/pki/base/util/src/netscape/security/extensions/SubjectInfoAccessExtension.java b/pki/base/util/src/netscape/security/extensions/SubjectInfoAccessExtension.java index d78ad0344..5c373289f 100644 --- a/pki/base/util/src/netscape/security/extensions/SubjectInfoAccessExtension.java +++ b/pki/base/util/src/netscape/security/extensions/SubjectInfoAccessExtension.java @@ -28,6 +28,8 @@ import java.security.cert.CertificateException; import java.util.Enumeration; import java.util.Vector; +import com.netscape.cmsutil.util.Utils; + import netscape.security.util.DerOutputStream; import netscape.security.util.DerValue; import netscape.security.util.ObjectIdentifier; @@ -226,7 +228,7 @@ public class SubjectInfoAccessExtension extends Extension implements CertAttrSet try { aia.encode(os); - System.out.println(com.netscape.osutil.OSUtil.BtoA(os.toByteArray())); + System.out.println(Utils.base64encode(os.toByteArray())); } catch (IOException e) { System.out.println(e.toString()); } diff --git a/pki/base/util/src/netscape/security/pkcs/PKCS10.java b/pki/base/util/src/netscape/security/pkcs/PKCS10.java index cb0e6edf4..a6ddd203f 100644 --- a/pki/base/util/src/netscape/security/pkcs/PKCS10.java +++ b/pki/base/util/src/netscape/security/pkcs/PKCS10.java @@ -26,6 +26,8 @@ import java.security.Signature; import java.security.SignatureException; import java.security.cert.CertificateException; +import com.netscape.cmsutil.util.Utils; + import netscape.security.util.BigInt; import netscape.security.util.DerInputStream; import netscape.security.util.DerOutputStream; @@ -310,7 +312,7 @@ public class PKCS10 { throw new SignatureException("Cert request was not signed"); out.println("-----BEGIN NEW CERTIFICATE REQUEST-----"); - out.println(com.netscape.osutil.OSUtil.BtoA(certificateRequest)); + out.println(Utils.base64encode(certificateRequest)); out.println("-----END NEW CERTIFICATE REQUEST-----"); } diff --git a/pki/base/util/src/netscape/security/x509/CertificatePoliciesExtension.java b/pki/base/util/src/netscape/security/x509/CertificatePoliciesExtension.java index 1c72e7fa3..fedc15917 100644 --- a/pki/base/util/src/netscape/security/x509/CertificatePoliciesExtension.java +++ b/pki/base/util/src/netscape/security/x509/CertificatePoliciesExtension.java @@ -30,6 +30,8 @@ import netscape.security.util.DerOutputStream; import netscape.security.util.DerValue; import netscape.security.util.ObjectIdentifier; +import com.netscape.cmsutil.util.Utils; + /** * This class defines the Certificate Policies Extension. * @@ -327,7 +329,7 @@ public class CertificatePoliciesExtension extends Extension new CertificatePoliciesExtension(infos); // BASE64 encode the whole thing and write it to stdout - System.out.println(com.netscape.osutil.OSUtil.BtoA(ext.getExtensionValue())); + System.out.println(Utils.base64encode(ext.getExtensionValue())); } catch (IOException e) { System.out.println(e.toString()); } |