diff options
author | Ade Lee <alee@redhat.com> | 2012-01-11 12:57:53 -0500 |
---|---|---|
committer | Ade Lee <alee@redhat.com> | 2012-01-11 13:49:04 -0500 |
commit | 10cfe7756e967ac91c66d33b392aeab9cf3780fb (patch) | |
tree | d5ac9b58442265d2ce5ef60e31f041ddacba1b4f /pki/base/util/src/com/netscape | |
parent | edcb24f65cc3700e75d0a1d14dc2483f210b0ee4 (diff) | |
download | pki-10cfe7756e967ac91c66d33b392aeab9cf3780fb.tar.gz pki-10cfe7756e967ac91c66d33b392aeab9cf3780fb.tar.xz pki-10cfe7756e967ac91c66d33b392aeab9cf3780fb.zip |
Formatting (no line wrap in comments or code)
Diffstat (limited to 'pki/base/util/src/com/netscape')
104 files changed, 2069 insertions, 2446 deletions
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 e659da9b9..e2d5d156a 100644 --- a/pki/base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java +++ b/pki/base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java @@ -17,7 +17,6 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.crypto; - import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.CharConversionException; @@ -109,27 +108,27 @@ public class CryptoUtil { /* * encodes cert */ - // private static BASE64Encoder mEncoder = new BASE64Encoder(); + // private static BASE64Encoder mEncoder = new BASE64Encoder(); public static String toMIME64(X509CertImpl cert) { try { - return - "-----BEGIN CERTIFICATE-----\n" - // + mEncoder.encodeBuffer(cert.getEncoded()) - + OSUtil.BtoA( cert.getEncoded() ) + return "-----BEGIN CERTIFICATE-----\n" + // + mEncoder.encodeBuffer(cert.getEncoded()) + + OSUtil.BtoA(cert.getEncoded()) + "-----END CERTIFICATE-----\n"; - } catch (Exception e) {} + } catch (Exception e) { + } return null; } - + public static boolean arraysEqual(byte[] bytes, byte[] ints) { if (bytes == null || ints == null) { return false; } - + if (bytes.length != ints.length) { return false; } - + for (int i = 0; i < bytes.length; i++) { if (bytes[i] != ints[i]) { return false; @@ -142,7 +141,7 @@ public class CryptoUtil { * Retrieves handle to a JSS token. */ public static CryptoToken getTokenByName(String token) - throws CryptoManager.NotInitializedException, + throws CryptoManager.NotInitializedException, NoSuchTokenException { CryptoManager cm = CryptoManager.getInstance(); CryptoToken t = null; @@ -159,7 +158,7 @@ public class CryptoUtil { * Generates a RSA key pair. */ public static KeyPair generateRSAKeyPair(String token, int keysize) - throws CryptoManager.NotInitializedException, + throws CryptoManager.NotInitializedException, NoSuchTokenException, NoSuchAlgorithmException, TokenException { @@ -172,21 +171,20 @@ public class CryptoUtil { return pair; } - public static boolean isECCKey(X509Key key) - { + public static boolean isECCKey(X509Key key) { String keyAlgo = key.getAlgorithm(); - if (keyAlgo.equals("EC") || + if (keyAlgo.equals("EC") || keyAlgo.equals("OID.1.2.840.10045.44")) { // ECC - return true; - } - return false; + return true; + } + return false; } /** * Generates an ecc key pair. */ public static KeyPair generateECCKeyPair(String token, int keysize) - throws CryptoManager.NotInitializedException, + throws CryptoManager.NotInitializedException, NoSuchTokenException, NoSuchAlgorithmException, TokenException { @@ -194,9 +192,9 @@ public class CryptoUtil { } public static KeyPair generateECCKeyPair(String token, int keysize, - org.mozilla.jss.crypto.KeyPairGeneratorSpi.Usage[] usage_ops, - org.mozilla.jss.crypto.KeyPairGeneratorSpi.Usage[] usage_mask) - throws CryptoManager.NotInitializedException, + org.mozilla.jss.crypto.KeyPairGeneratorSpi.Usage[] usage_ops, + org.mozilla.jss.crypto.KeyPairGeneratorSpi.Usage[] usage_mask) + throws CryptoManager.NotInitializedException, NoSuchTokenException, NoSuchAlgorithmException, TokenException { @@ -217,7 +215,7 @@ public class CryptoUtil { * Generates an ecc key pair by curve name */ public static KeyPair generateECCKeyPair(String token, String curveName) - throws CryptoManager.NotInitializedException, + throws CryptoManager.NotInitializedException, NoSuchTokenException, NoSuchAlgorithmException, TokenException { @@ -225,7 +223,7 @@ public class CryptoUtil { } public static KeyPair generateECCKeyPair(CryptoToken token, String curveName) - throws CryptoManager.NotInitializedException, + throws CryptoManager.NotInitializedException, NoSuchTokenException, NoSuchAlgorithmException, TokenException { @@ -233,9 +231,9 @@ public class CryptoUtil { } public static KeyPair generateECCKeyPair(String token, String curveName, - org.mozilla.jss.crypto.KeyPairGeneratorSpi.Usage[] usage_ops, - org.mozilla.jss.crypto.KeyPairGeneratorSpi.Usage[] usage_mask) - throws CryptoManager.NotInitializedException, + org.mozilla.jss.crypto.KeyPairGeneratorSpi.Usage[] usage_ops, + org.mozilla.jss.crypto.KeyPairGeneratorSpi.Usage[] usage_mask) + throws CryptoManager.NotInitializedException, NoSuchTokenException, NoSuchAlgorithmException, TokenException { @@ -244,9 +242,9 @@ public class CryptoUtil { } public static KeyPair generateECCKeyPair(CryptoToken token, String curveName, - org.mozilla.jss.crypto.KeyPairGeneratorSpi.Usage[] usage_ops, - org.mozilla.jss.crypto.KeyPairGeneratorSpi.Usage[] usage_mask) - throws CryptoManager.NotInitializedException, + org.mozilla.jss.crypto.KeyPairGeneratorSpi.Usage[] usage_ops, + org.mozilla.jss.crypto.KeyPairGeneratorSpi.Usage[] usage_mask) + throws CryptoManager.NotInitializedException, NoSuchTokenException, NoSuchAlgorithmException, TokenException { @@ -255,17 +253,17 @@ public class CryptoUtil { g.setKeyPairUsages(usage_ops, usage_mask); - System.out.println("CryptoUtil: generateECCKeyPair: curve = "+ curveName); + System.out.println("CryptoUtil: generateECCKeyPair: curve = " + curveName); int curveCode = 0; try { curveCode = g.getCurveCodeByName(curveName); } catch (Exception e) { - System.out.println("CryptoUtil: generateECCKeyPair: "+ e.toString()); + System.out.println("CryptoUtil: generateECCKeyPair: " + e.toString()); throw new NoSuchAlgorithmException(); } g.initialize(curveCode); - System.out.println("CryptoUtil: generateECCKeyPair: after KeyPairGenerator initialize with:"+ curveName); + System.out.println("CryptoUtil: generateECCKeyPair: after KeyPairGenerator initialize with:" + curveName); KeyPair pair = g.genKeyPair(); return pair; @@ -289,21 +287,21 @@ public class CryptoUtil { ByteArrayOutputStream output = new ByteArrayOutputStream(); Base64OutputStream b64 = new Base64OutputStream(new PrintStream(new - FilterOutputStream(output))); - + FilterOutputStream(output))); + b64.write(bytes); b64.flush(); - + // This is internationally safe because Base64 chars are // contained within 8859_1 return output.toString("8859_1"); } - + public static byte[] base64Decode(String s) throws IOException { - // BASE64Decoder base64 = new BASE64Decoder(); - // byte[] d = base64.decodeBuffer(s); - byte[] d = OSUtil.AtoB( s ); - + // BASE64Decoder base64 = new BASE64Decoder(); + // byte[] d = base64.decodeBuffer(s); + byte[] d = OSUtil.AtoB(s); + return d; } @@ -313,10 +311,10 @@ public class CryptoUtil { public static String reqFormat(String content) { int beginIndex = CERTREQ_BEGIN_HEADING.length(); int endIndex = CERTREQ_END_HEADING.length(); - + String result = CERTREQ_BEGIN_HEADING + "\n"; int index = 0; - + while (content.length() >= LINE_COUNT) { result = result + content.substring(0, LINE_COUNT) + "\n"; content = content.substring(LINE_COUNT); @@ -326,11 +324,11 @@ public class CryptoUtil { } else { result = result + CERTREQ_END_HEADING; } - + return result; } - - public static String getPKCS10FromKey(String dn, + + public static String getPKCS10FromKey(String dn, byte modulus[], byte exponent[], byte prikdata[]) throws IOException, InvalidKeyException, @@ -339,8 +337,7 @@ public class CryptoUtil { CertificateException, SignatureException, CryptoManager.NotInitializedException, - NoSuchAlgorithmException - { + NoSuchAlgorithmException { X509Key x509key = getPublicX509Key(modulus, exponent); PrivateKey prik = findPrivateKeyFromID(prikdata); PKCS10 pkcs10 = createCertificationRequest(dn, x509key, prik); @@ -350,7 +347,7 @@ public class CryptoUtil { return bs.toString(); } - public static String getPKCS10FromKey(String dn, + public static String getPKCS10FromKey(String dn, byte modulus[], byte exponent[], byte prikdata[], String alg) throws IOException, InvalidKeyException, @@ -359,8 +356,7 @@ public class CryptoUtil { CertificateException, SignatureException, CryptoManager.NotInitializedException, - NoSuchAlgorithmException - { + NoSuchAlgorithmException { X509Key x509key = getPublicX509Key(modulus, exponent); PrivateKey prik = findPrivateKeyFromID(prikdata); PKCS10 pkcs10 = createCertificationRequest(dn, x509key, prik, alg); @@ -379,10 +375,10 @@ public class CryptoUtil { } int beginIndex = CERT_BEGIN_HEADING.length(); int endIndex = CERT_END_HEADING.length(); - + String result = CERT_BEGIN_HEADING + "\n"; int index = 0; - + while (content.length() >= LINE_COUNT) { result = result + content.substring(0, LINE_COUNT) + "\n"; content = content.substring(LINE_COUNT); @@ -392,31 +388,32 @@ public class CryptoUtil { } else { result = result + CERT_END_HEADING; } - + return result; } /** * strips out the begin and end certificate brackets + * * @param s the string potentially bracketed with - * "-----BEGIN CERTIFICATE-----" and "-----END CERTIFICATE-----" + * "-----BEGIN CERTIFICATE-----" and "-----END CERTIFICATE-----" * @return string without the brackets */ public static String stripCertBrackets(String s) { if (s == null) { return s; } - + if (s.startsWith(CERT_BEGIN_HEADING) && s.endsWith(CERT_END_HEADING)) { return (s.substring(27, (s.length() - 25))); } - + // To support Thawte's header and footer if ((s.startsWith("-----BEGIN PKCS #7 SIGNED DATA-----")) && (s.endsWith("-----END PKCS #7 SIGNED DATA-----"))) { return (s.substring(35, (s.length() - 33))); } - + return s; } @@ -430,13 +427,13 @@ public class CryptoUtil { s = s.replaceAll("-----END NEW CERTIFICATE REQUEST-----", ""); s = s.replaceAll("-----BEGIN CERTIFICATE-----", ""); s = s.replaceAll("-----END CERTIFICATE-----", ""); - + StringBuffer sb = new StringBuffer(); StringTokenizer st = new StringTokenizer(s, "\r\n "); - + while (st.hasMoreTokens()) { String nextLine = st.nextToken(); - + nextLine = nextLine.trim(); if (nextLine.equals("-----BEGIN CERTIFICATE REQUEST-----")) { continue; @@ -460,10 +457,10 @@ public class CryptoUtil { } return sb.toString(); } - + public static String normalizeCertStr(String s) { String val = ""; - + for (int i = 0; i < s.length(); i++) { if (s.charAt(i) == '\n') { continue; @@ -484,61 +481,58 @@ public class CryptoUtil { CryptoManager.NotInitializedException, TokenException, CertificateEncodingException, - CertificateException - { + CertificateException { byte[] blah = base64Decode(certchain); CryptoManager manager = CryptoManager.getInstance(); PKCS7 pkcs7 = null; - try { - // try PKCS7 first - pkcs7 = new PKCS7(blah); + try { + // try PKCS7 first + pkcs7 = new PKCS7(blah); } catch (Exception e) { } X509Certificate cert = null; if (pkcs7 == null) { - cert = manager.importCACertPackage(blah); - } else { - java.security.cert.X509Certificate certsInP7[] = - pkcs7.getCertificates(); - if (certsInP7 == null) { cert = manager.importCACertPackage(blah); - } else { - for (int i = 0; i < certsInP7.length; i++) { - // import P7 one by one - cert = manager.importCACertPackage(certsInP7[i].getEncoded()); + } else { + java.security.cert.X509Certificate certsInP7[] = + pkcs7.getCertificates(); + if (certsInP7 == null) { + cert = manager.importCACertPackage(blah); + } else { + for (int i = 0; i < certsInP7.length; i++) { + // import P7 one by one + cert = manager.importCACertPackage(certsInP7[i].getEncoded()); + } } - } } - X509Certificate[] certchains = - CryptoManager.getInstance().buildCertificateChain(cert); - + X509Certificate[] certchains = + CryptoManager.getInstance().buildCertificateChain(cert); + if (certchains != null) { - cert = certchains[certchains.length - 1]; + cert = certchains[certchains.length - 1]; } InternalCertificate icert = (InternalCertificate) cert; - icert.setSSLTrust( InternalCertificate.TRUSTED_CA + icert.setSSLTrust(InternalCertificate.TRUSTED_CA | InternalCertificate.TRUSTED_CLIENT_CA | InternalCertificate.VALID_CA); } public static SEQUENCE parseCRMFMsgs(byte cert_request[]) - throws IOException, InvalidBERException - { - ByteArrayInputStream crmfBlobIn = - new ByteArrayInputStream(cert_request); + throws IOException, InvalidBERException { + ByteArrayInputStream crmfBlobIn = + new ByteArrayInputStream(cert_request); SEQUENCE crmfMsgs = (SEQUENCE) - new SEQUENCE.OF_Template(new CertReqMsg.Template()).decode( + new SEQUENCE.OF_Template(new CertReqMsg.Template()).decode( crmfBlobIn); return crmfMsgs; } - public static X509Key getX509KeyFromCRMFMsgs(SEQUENCE crmfMsgs) - throws IOException, NoSuchAlgorithmException, - InvalidKeyException, InvalidKeyFormatException - { + public static X509Key getX509KeyFromCRMFMsgs(SEQUENCE crmfMsgs) + throws IOException, NoSuchAlgorithmException, + InvalidKeyException, InvalidKeyFormatException { int nummsgs = crmfMsgs.size(); if (nummsgs <= 0) { - throw new IOException("invalid certificate requests"); + throw new IOException("invalid certificate requests"); } CertReqMsg msg = (CertReqMsg) crmfMsgs.elementAt(0); CertRequest certreq = msg.getCertReq(); @@ -549,28 +543,28 @@ public class CryptoUtil { return x509key; } - public static X509Key getPublicX509Key(byte modulus[], byte exponent[]) - throws InvalidKeyException { + public static X509Key getPublicX509Key(byte modulus[], byte exponent[]) + throws InvalidKeyException { return new netscape.security.provider.RSAPublicKey(new BigInt(modulus), new BigInt(exponent)); } public static X509Key getPublicX509ECCKey(byte encoded[]) - throws InvalidKeyException { - try { - return X509Key.parse(new DerValue(encoded)); - } catch (IOException e) { - throw new InvalidKeyException(); - } + throws InvalidKeyException { + try { + return X509Key.parse(new DerValue(encoded)); + } catch (IOException e) { + throw new InvalidKeyException(); + } } public static X509Key convertPublicKeyToX509Key(PublicKey pubk) - throws InvalidKeyException { + throws InvalidKeyException { X509Key xKey; - + if (pubk instanceof RSAPublicKey) { RSAPublicKey rsaKey = (RSAPublicKey) pubk; - + xKey = new netscape.security.provider.RSAPublicKey( new BigInt(rsaKey.getModulus()), new BigInt(rsaKey.getPublicExponent())); @@ -578,18 +572,18 @@ public class CryptoUtil { // Assert.assert(pubk instanceof DSAPublicKey); DSAPublicKey dsaKey = (DSAPublicKey) pubk; DSAParams params = dsaKey.getParams(); - + xKey = new netscape.security.provider.DSAPublicKey(dsaKey.getY(), params.getP(), params.getQ(), params.getG()); } return xKey; } - public static String getSubjectName(SEQUENCE crmfMsgs) - throws IOException { + public static String getSubjectName(SEQUENCE crmfMsgs) + throws IOException { int nummsgs = crmfMsgs.size(); if (nummsgs <= 0) { - throw new IOException("invalid certificate requests"); + throw new IOException("invalid certificate requests"); } CertReqMsg msg = (CertReqMsg) crmfMsgs.elementAt(0); CertRequest certreq = msg.getCertReq(); @@ -597,7 +591,7 @@ public class CryptoUtil { Name n = certTemplate.getSubject(); ByteArrayOutputStream subjectEncStream = new ByteArrayOutputStream(); n.encode(subjectEncStream); - + byte[] b = subjectEncStream.toByteArray(); X500Name subject = new X500Name(b); return subject.toString(); @@ -607,46 +601,46 @@ public class CryptoUtil { * Creates a Certificate template. */ public static X509CertInfo createX509CertInfo(KeyPair pair, - int serialno, String issuername, String subjname, + int serialno, String issuername, String subjname, Date notBefore, Date notAfter) - throws IOException, - CertificateException, + throws IOException, + CertificateException, InvalidKeyException { - return createX509CertInfo(convertPublicKeyToX509Key(pair.getPublic()), + return createX509CertInfo(convertPublicKeyToX509Key(pair.getPublic()), serialno, issuername, subjname, notBefore, notAfter); } public static X509CertInfo createX509CertInfo(PublicKey publickey, - int serialno, String issuername, String subjname, + int serialno, String issuername, String subjname, Date notBefore, Date notAfter) - throws IOException, - CertificateException, + throws IOException, + CertificateException, InvalidKeyException { return createX509CertInfo(convertPublicKeyToX509Key(publickey), serialno, issuername, subjname, notBefore, notAfter); } public static X509CertInfo createX509CertInfo(X509Key x509key, - int serialno, String issuername, String subjname, + int serialno, String issuername, String subjname, Date notBefore, Date notAfter) - throws IOException, - CertificateException, + throws IOException, + CertificateException, InvalidKeyException { // set default; use the other call with "alg" to set algorithm String alg = "SHA256withRSA"; try { - return createX509CertInfo (x509key, serialno, issuername, subjname, notBefore, notAfter, alg); + return createX509CertInfo(x509key, serialno, issuername, subjname, notBefore, notAfter, alg); } catch (NoSuchAlgorithmException ex) { - // for those that calls the old call without alg - throw new CertificateException("createX509CertInfo old call should not be here"); + // for those that calls the old call without alg + throw new CertificateException("createX509CertInfo old call should not be here"); } } public static X509CertInfo createX509CertInfo(X509Key x509key, - int serialno, String issuername, String subjname, + int serialno, String issuername, String subjname, Date notBefore, Date notAfter, String alg) - throws IOException, - CertificateException, + throws IOException, + CertificateException, InvalidKeyException, NoSuchAlgorithmException { X509CertInfo info = new X509CertInfo(); @@ -668,10 +662,9 @@ public class CryptoUtil { return info; } - - public static X509CertImpl signECCCert(PrivateKey privateKey, + public static X509CertImpl signECCCert(PrivateKey privateKey, X509CertInfo certInfo) - throws NoSuchTokenException, + throws NoSuchTokenException, CryptoManager.NotInitializedException, NoSuchAlgorithmException, NoSuchTokenException, @@ -679,16 +672,15 @@ public class CryptoUtil { InvalidKeyException, SignatureException, IOException, - CertificateException - { + CertificateException { // set default; use the other call with "alg" to specify algorithm String alg = "SHA256withEC"; return signECCCert(privateKey, certInfo, alg); } - public static X509CertImpl signECCCert(PrivateKey privateKey, + public static X509CertImpl signECCCert(PrivateKey privateKey, X509CertInfo certInfo, String alg) - throws NoSuchTokenException, + throws NoSuchTokenException, CryptoManager.NotInitializedException, NoSuchAlgorithmException, NoSuchTokenException, @@ -696,18 +688,17 @@ public class CryptoUtil { InvalidKeyException, SignatureException, IOException, - CertificateException - { - return signCert(privateKey, certInfo, + CertificateException { + return signCert(privateKey, certInfo, Cert.mapAlgorithmToJss(alg)); } /** * Signs certificate. */ - public static X509CertImpl signCert(PrivateKey privateKey, + public static X509CertImpl signCert(PrivateKey privateKey, X509CertInfo certInfo, String alg) - throws NoSuchTokenException, + throws NoSuchTokenException, CryptoManager.NotInitializedException, NoSuchAlgorithmException, NoSuchTokenException, @@ -716,13 +707,13 @@ public class CryptoUtil { SignatureException, IOException, CertificateException { - return signCert (privateKey, certInfo, + return signCert(privateKey, certInfo, Cert.mapAlgorithmToJss(alg)); } - public static X509CertImpl signCert(PrivateKey privateKey, + public static X509CertImpl signCert(PrivateKey privateKey, X509CertInfo certInfo, SignatureAlgorithm sigAlg) - throws NoSuchTokenException, + throws NoSuchTokenException, CryptoManager.NotInitializedException, NoSuchAlgorithmException, NoSuchTokenException, @@ -735,28 +726,28 @@ public class CryptoUtil { DerInputStream ds = new DerInputStream(ASN1Util.encode(sigAlg.toOID())); ObjectIdentifier sigAlgOID = new ObjectIdentifier(ds); AlgorithmId aid = new AlgorithmId(sigAlgOID); - certInfo.set(X509CertInfo.ALGORITHM_ID, - new CertificateAlgorithmId(aid)); - - org.mozilla.jss.crypto.PrivateKey priKey = - (org.mozilla.jss.crypto.PrivateKey) privateKey; + certInfo.set(X509CertInfo.ALGORITHM_ID, + new CertificateAlgorithmId(aid)); + + org.mozilla.jss.crypto.PrivateKey priKey = + (org.mozilla.jss.crypto.PrivateKey) privateKey; CryptoToken token = priKey.getOwningToken(); - + DerOutputStream tmp = new DerOutputStream(); DerOutputStream out = new DerOutputStream(); - + certInfo.encode(tmp); Signature signer = token.getSignatureContext(sigAlg); - + signer.initSign(priKey); signer.update(tmp.toByteArray()); byte signed[] = signer.sign(); - + aid.encode(tmp); tmp.putBitString(signed); out.write(DerValue.tag_Sequence, tmp); X509CertImpl signedCert = new X509CertImpl(out.toByteArray()); - + return signedCert; } @@ -765,20 +756,20 @@ public class CryptoUtil { */ public static PKCS10 createCertificationRequest(String subjectName, X509Key pubk, PrivateKey prik) - throws NoSuchAlgorithmException, NoSuchProviderException, + throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException, IOException, CertificateException, SignatureException { // give default String alg = "SHA256withRSA"; if (isECCKey(pubk)) { - alg = "SHA256withEC"; + alg = "SHA256withEC"; } return createCertificationRequest(subjectName, pubk, prik, alg); } public static PKCS10 createCertificationRequest(String subjectName, X509Key pubk, PrivateKey prik, String alg) - throws NoSuchAlgorithmException, NoSuchProviderException, + throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException, IOException, CertificateException, SignatureException { X509Key key = pubk; @@ -799,7 +790,7 @@ public class CryptoUtil { */ public static PKCS10 createCertificationRequest(String subjectName, KeyPair keyPair) - throws NoSuchAlgorithmException, NoSuchProviderException, + throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException, IOException, CertificateException, SignatureException { String alg; @@ -813,45 +804,45 @@ public class CryptoUtil { // Assert.assert(pubk instanceof DSAPublicKey); alg = "DSA"; } - return createCertificationRequest(subjectName,keyPair, alg); + return createCertificationRequest(subjectName, keyPair, alg); } public static PKCS10 createCertificationRequest(String subjectName, KeyPair keyPair, String alg) - throws NoSuchAlgorithmException, NoSuchProviderException, + throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException, IOException, CertificateException, SignatureException { PublicKey pubk = keyPair.getPublic(); X509Key key = convertPublicKeyToX509Key(pubk); - + java.security.Signature sig = java.security.Signature.getInstance(alg, "Mozilla-JSS"); - + sig.initSign(keyPair.getPrivate()); - + PKCS10 pkcs10 = new PKCS10(key); - + X500Name name = new X500Name(subjectName); X500Signer signer = new X500Signer(sig, name); - + pkcs10.encodeAndSign(signer); - + return pkcs10; } public static void unTrustCert(InternalCertificate cert) { // remove TRUSTED_CA int flag = cert.getSSLTrust(); - + flag ^= InternalCertificate.VALID_CA; cert.setSSLTrust(flag); } - + /** * Trusts a certificate by nickname. */ - public static void trustCertByNickname(String nickname) - throws CryptoManager.NotInitializedException, + public static void trustCertByNickname(String nickname) + throws CryptoManager.NotInitializedException, TokenException { CryptoManager cm = CryptoManager.getInstance(); X509Certificate certs[] = cm.findCertsByNickname(nickname); @@ -871,12 +862,12 @@ public class CryptoUtil { int flag = InternalCertificate.VALID_CA | InternalCertificate.TRUSTED_CA | InternalCertificate.USER | InternalCertificate.TRUSTED_CLIENT_CA; - + cert.setSSLTrust(flag); cert.setObjectSigningTrust(flag); cert.setEmailTrust(flag); } - + /** * To certificate server point of view, SSL trust is * what we referring. @@ -889,7 +880,7 @@ public class CryptoUtil { return false; } } - + public static boolean isTrust(int flag) { if (((flag & InternalCertificate.VALID_CA) > 0) && ((flag & InternalCertificate.TRUSTED_CA) > 0) @@ -906,11 +897,11 @@ public class CryptoUtil { */ public static SymmetricKey generateKey(CryptoToken token, KeyGenAlgorithm alg) - throws TokenException, NoSuchAlgorithmException, + throws TokenException, NoSuchAlgorithmException, IllegalStateException { try { KeyGenerator kg = token.getKeyGenerator(alg); - + return kg.generate(); } catch (CharConversionException e) { throw new RuntimeException( @@ -950,8 +941,8 @@ public class CryptoUtil { /** * Retrieves a private key from a unique key ID. */ - public static PrivateKey findPrivateKeyFromID(byte id[]) - throws CryptoManager.NotInitializedException, + public static PrivateKey findPrivateKeyFromID(byte id[]) + throws CryptoManager.NotInitializedException, TokenException { CryptoManager cm = CryptoManager.getInstance(); Enumeration enums = cm.getAllTokens(); @@ -960,7 +951,7 @@ public class CryptoUtil { CryptoToken token = (CryptoToken) enums.nextElement(); String tokenName = token.getName(); CryptoStore store = token.getCryptoStore(); - PrivateKey keys[] = store.getPrivateKeys(); + PrivateKey keys[] = store.getPrivateKeys(); if (keys != null) { for (int i = 0; i < keys.length; i++) { @@ -977,7 +968,7 @@ public class CryptoUtil { * Retrieves all user certificates from all tokens. */ public static X509CertImpl[] getAllUserCerts() - throws CryptoManager.NotInitializedException, + throws CryptoManager.NotInitializedException, TokenException { Vector certs = new Vector(); CryptoManager cm = CryptoManager.getInstance(); @@ -986,10 +977,10 @@ public class CryptoUtil { while (enums.hasMoreElements()) { CryptoToken token = (CryptoToken) enums.nextElement(); String tokenName = token.getName(); - + CryptoStore store = token.getCryptoStore(); org.mozilla.jss.crypto.X509Certificate list[] = store.getCertificates(); - + for (int i = 0; i < list.length; i++) { try { PrivateKey key = cm.findPrivKeyByCert(list[i]); @@ -1022,7 +1013,7 @@ public class CryptoUtil { * Deletes a private key. */ public static void deletePrivateKey(PrivateKey prikey) - throws CryptoManager.NotInitializedException, TokenException { + throws CryptoManager.NotInitializedException, TokenException { CryptoManager cm = CryptoManager.getInstance(); try { @@ -1030,21 +1021,23 @@ public class CryptoUtil { CryptoStore store = token.getCryptoStore(); store.deletePrivateKey(prikey); - } catch (NoSuchItemOnTokenException e) {} + } catch (NoSuchItemOnTokenException e) { + } } /** * Retrieves a private key by nickname. */ public static PrivateKey getPrivateKey(String nickname) - throws CryptoManager.NotInitializedException, TokenException { + throws CryptoManager.NotInitializedException, TokenException { try { CryptoManager cm = CryptoManager.getInstance(); X509Certificate cert = cm.findCertByNickname(nickname); org.mozilla.jss.crypto.PrivateKey prikey = cm.findPrivKeyByCert(cert); return prikey; - } catch (ObjectNotFoundException e) {} + } catch (ObjectNotFoundException e) { + } return null; } @@ -1052,7 +1045,7 @@ public class CryptoUtil { * Deletes all certificates by a nickname. */ public static void deleteAllCertificates(String nickname) - throws CryptoManager.NotInitializedException, TokenException { + throws CryptoManager.NotInitializedException, TokenException { CryptoManager cm = CryptoManager.getInstance(); X509Certificate certs[] = cm.findCertsByNickname(nickname); @@ -1068,18 +1061,20 @@ public class CryptoUtil { CryptoStore store = token.getCryptoStore(); store.deleteCert(cert); - } catch (NoSuchItemOnTokenException e) {} catch (ObjectNotFoundException e) {} + } catch (NoSuchItemOnTokenException e) { + } catch (ObjectNotFoundException e) { + } } } /** - * Imports a PKCS#7 certificate chain that includes the user + * Imports a PKCS#7 certificate chain that includes the user * certificate, and trusts the certificate. */ - public static X509Certificate importUserCertificateChain(String c, + public static X509Certificate importUserCertificateChain(String c, String nickname) - throws CryptoManager.NotInitializedException, - CryptoManager.NicknameConflictException, + throws CryptoManager.NotInitializedException, + CryptoManager.NicknameConflictException, CryptoManager.UserCertConflictException, NoSuchItemOnTokenException, TokenException, @@ -1095,7 +1090,7 @@ public class CryptoUtil { * Imports a user certificate, and trusts the certificate. */ public static void importUserCertificate(X509CertImpl cert, String nickname) - throws CryptoManager.NotInitializedException, + throws CryptoManager.NotInitializedException, CertificateEncodingException, NoSuchItemOnTokenException, TokenException, @@ -1108,8 +1103,8 @@ public class CryptoUtil { } public static void importUserCertificate(X509CertImpl cert, String nickname, - boolean trust) - throws CryptoManager.NotInitializedException, + boolean trust) + throws CryptoManager.NotInitializedException, CertificateEncodingException, NoSuchItemOnTokenException, TokenException, @@ -1127,7 +1122,7 @@ public class CryptoUtil { CertificateChain certchain = new CertificateChain(); certchain.decode(bis); - java.security.cert.X509Certificate[] certs = certchain.getChain(); + java.security.cert.X509Certificate[] certs = certchain.getChain(); return certs; } @@ -1136,25 +1131,22 @@ public class CryptoUtil { // START ENABLE_ECC // This following can be removed when JSS with ECC capability // is integrated. -class CryptoAlgorithm extends Algorithm -{ +class CryptoAlgorithm extends Algorithm { protected CryptoAlgorithm(int oidIndex, String name) { super(oidIndex, name); } } -class CryptoKeyPairAlgorithm extends KeyPairAlgorithm -{ - protected CryptoKeyPairAlgorithm(int oidIndex, String name, Algorithm algFamily) { super(oidIndex, name, algFamily); +class CryptoKeyPairAlgorithm extends KeyPairAlgorithm { + protected CryptoKeyPairAlgorithm(int oidIndex, String name, Algorithm algFamily) { + super(oidIndex, name, algFamily); } } -class CryptoSignatureAlgorithm extends SignatureAlgorithm -{ +class CryptoSignatureAlgorithm extends SignatureAlgorithm { protected CryptoSignatureAlgorithm(int oidIndex, String name, - SignatureAlgorithm signingAlg, DigestAlgorithm digestAlg, - OBJECT_IDENTIFIER oid) - { + SignatureAlgorithm signingAlg, DigestAlgorithm digestAlg, + OBJECT_IDENTIFIER oid) { super(oidIndex, name, signingAlg, digestAlg, oid); } } diff --git a/pki/base/util/src/com/netscape/cmsutil/crypto/Module.java b/pki/base/util/src/com/netscape/cmsutil/crypto/Module.java index e7971ea78..16f948fd7 100644 --- a/pki/base/util/src/com/netscape/cmsutil/crypto/Module.java +++ b/pki/base/util/src/com/netscape/cmsutil/crypto/Module.java @@ -31,34 +31,34 @@ public class Module { private Vector mTokens = null; private boolean mFound = false; - public Module (String name, String printName) { - mCommonName = name; - mUserFriendlyName = printName; - mTokens = new Vector(); + public Module(String name, String printName) { + mCommonName = name; + mUserFriendlyName = printName; + mTokens = new Vector(); } - public Module (String name, String printName, String image) { - mCommonName = name; - mUserFriendlyName = printName; - mImagePath = image; - mTokens = new Vector(); + public Module(String name, String printName, String image) { + mCommonName = name; + mUserFriendlyName = printName; + mImagePath = image; + mTokens = new Vector(); } public void addToken(CryptoToken t) { - Token token = new Token(t); - mTokens.addElement(token); + Token token = new Token(t); + mTokens.addElement(token); } public String getCommonName() { - return mCommonName; + return mCommonName; } public String getUserFriendlyName() { - return mUserFriendlyName; + return mUserFriendlyName; } public String getImagePath() { - return mImagePath; + return mImagePath; } public boolean isFound() { @@ -70,6 +70,6 @@ public class Module { } public Vector getTokens() { - return mTokens; + return mTokens; } } diff --git a/pki/base/util/src/com/netscape/cmsutil/crypto/Token.java b/pki/base/util/src/com/netscape/cmsutil/crypto/Token.java index f86e49bdc..c6f5a5e3c 100644 --- a/pki/base/util/src/com/netscape/cmsutil/crypto/Token.java +++ b/pki/base/util/src/com/netscape/cmsutil/crypto/Token.java @@ -22,36 +22,36 @@ import org.mozilla.jss.crypto.CryptoToken; public class Token { CryptoToken mToken; - public Token (CryptoToken token) { - mToken = token; + public Token(CryptoToken token) { + mToken = token; } public String getNickName() { - String nickName=""; + String nickName = ""; try { - nickName = mToken.getName(); + nickName = mToken.getName(); } catch (Exception e) { } - return nickName; + return nickName; } public boolean isLoggedIn() { boolean isLoggedIn = false; try { - isLoggedIn = mToken.isLoggedIn(); + isLoggedIn = mToken.isLoggedIn(); } catch (Exception e) { } - return isLoggedIn; + return isLoggedIn; } public boolean isPresent() { boolean isPresent = false; try { - isPresent = mToken.isPresent(); + isPresent = mToken.isPresent(); } catch (Exception e) { } - return isPresent; + return isPresent; } } diff --git a/pki/base/util/src/com/netscape/cmsutil/http/ConnectAsync.java b/pki/base/util/src/com/netscape/cmsutil/http/ConnectAsync.java index 8922f38dd..ca230ca21 100644 --- a/pki/base/util/src/com/netscape/cmsutil/http/ConnectAsync.java +++ b/pki/base/util/src/com/netscape/cmsutil/http/ConnectAsync.java @@ -17,12 +17,10 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.http; - import java.net.SocketException; import com.netscape.cmsutil.net.ISocketFactory; - public class ConnectAsync extends Thread { String host = null; int port = 0; @@ -33,9 +31,9 @@ public class ConnectAsync extends Thread { this.host = host; this.port = port; this.obj = sock; - setName("ConnectAsync"); + setName("ConnectAsync"); } - + public void run() { try { obj.makeSocket(host, port); @@ -46,4 +44,3 @@ public class ConnectAsync extends Thread { } } } - diff --git a/pki/base/util/src/com/netscape/cmsutil/http/Http.java b/pki/base/util/src/com/netscape/cmsutil/http/Http.java index acece15d1..2cda7fd12 100644 --- a/pki/base/util/src/com/netscape/cmsutil/http/Http.java +++ b/pki/base/util/src/com/netscape/cmsutil/http/Http.java @@ -17,7 +17,6 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.http; - public class Http { public static final String HttpVers = "HTTP/1.0"; diff --git a/pki/base/util/src/com/netscape/cmsutil/http/HttpClient.java b/pki/base/util/src/com/netscape/cmsutil/http/HttpClient.java index 130d747d6..2ad67578f 100644 --- a/pki/base/util/src/com/netscape/cmsutil/http/HttpClient.java +++ b/pki/base/util/src/com/netscape/cmsutil/http/HttpClient.java @@ -60,7 +60,7 @@ public class HttpClient { } public void connect(String host, int port) - throws IOException { + throws IOException { if (mFactory != null) { if (mCertApprovalCallback == null) { mSocket = mFactory.makeSocket(host, port); @@ -76,7 +76,7 @@ public class HttpClient { throw e; } - + mInputStream = mSocket.getInputStream(); mOutputStream = mSocket.getOutputStream(); mInputStreamReader = new InputStreamReader(mInputStream, "UTF8"); @@ -87,7 +87,7 @@ public class HttpClient { // Inserted by beomsuk public void connect(String host, int port, int timeout) - throws IOException { + throws IOException { if (mFactory != null) { mSocket = mFactory.makeSocket(host, port, timeout); } else { @@ -99,7 +99,7 @@ public class HttpClient { throw e; } - + mInputStream = mSocket.getInputStream(); mOutputStream = mSocket.getOutputStream(); mInputStreamReader = new InputStreamReader(mInputStream, "UTF8"); @@ -114,14 +114,13 @@ public class HttpClient { } /** - * Sends a request to http server. - * Returns a http response. + * Sends a request to http server. + * Returns a http response. */ - public HttpResponse send(HttpRequest request) - throws IOException { + public HttpResponse send(HttpRequest request) + throws IOException { HttpResponse resp = new HttpResponse(); - if (mOutputStream == null) throw new IOException("Output stream not initialized"); request.write(mOutputStreamWriter); @@ -137,7 +136,7 @@ public class HttpClient { } public void disconnect() - throws IOException { + throws IOException { mSocket.close(); mInputStream = null; mOutputStream = null; @@ -172,7 +171,7 @@ public class HttpClient { * unit test */ public static void main(String args[]) - throws Exception { + throws Exception { HttpClient c = new HttpClient(); HttpRequest req = new HttpRequest(); HttpResponse resp = null; @@ -182,7 +181,7 @@ public class HttpClient { req.setMethod("GET"); req.setURI(args[2]); - if (args.length >= 4) + if (args.length >= 4) req.setHeader("Connection", args[3]); resp = c.send(req); @@ -203,7 +202,8 @@ public class HttpClient { char[] msgbody; for (int i = 0; i < 2; i++) { - if (i == 1) req.setHeader("Connection", "Close"); + if (i == 1) + req.setHeader("Connection", "Close"); resp = c.send(req); System.out.println("version " + resp.getHttpVers()); System.out.println("status code " + resp.getStatusCode()); diff --git a/pki/base/util/src/com/netscape/cmsutil/http/HttpEofException.java b/pki/base/util/src/com/netscape/cmsutil/http/HttpEofException.java index e5573612e..824b9ea2a 100644 --- a/pki/base/util/src/com/netscape/cmsutil/http/HttpEofException.java +++ b/pki/base/util/src/com/netscape/cmsutil/http/HttpEofException.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.http; - import java.io.IOException; - public class HttpEofException extends IOException { /** * diff --git a/pki/base/util/src/com/netscape/cmsutil/http/HttpMessage.java b/pki/base/util/src/com/netscape/cmsutil/http/HttpMessage.java index 93eeef68c..100cbb5af 100644 --- a/pki/base/util/src/com/netscape/cmsutil/http/HttpMessage.java +++ b/pki/base/util/src/com/netscape/cmsutil/http/HttpMessage.java @@ -17,21 +17,19 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.http; - import java.io.BufferedReader; import java.io.IOException; import java.io.OutputStreamWriter; import java.util.Enumeration; import java.util.Hashtable; - /** - * Basic HTTP Message, excluding message body. + * Basic HTTP Message, excluding message body. * Not optimized for performance. * Set fields or parse from input. */ public class HttpMessage { - protected String mLine = null; // request or response line. + protected String mLine = null; // request or response line. protected Hashtable mHeaders = null; protected String mContent = null; // arbitrary content chars assumed. @@ -42,14 +40,14 @@ public class HttpMessage { mHeaders = new Hashtable(); } - /** + /** * Set a header field. <br> * Content-length is automatically set on write.<br> * If value spans multiple lines must be in proper http format for * multiple lines. */ public void setHeader(String name, String value) { - if (mHeaders == null) + if (mHeaders == null) mHeaders = new Hashtable(); mHeaders.put(name.toLowerCase(), value); } @@ -62,11 +60,11 @@ public class HttpMessage { } /** - * write http headers - * does not support values of more than one line + * write http headers + * does not support values of more than one line */ public void writeHeaders(OutputStreamWriter writer) - throws IOException { + throws IOException { if (mHeaders != null) { Enumeration keys = mHeaders.keys(); String header, value; @@ -85,7 +83,7 @@ public class HttpMessage { * does not support values of more than one line or multivalue headers. */ public void readHeaders(BufferedReader reader) - throws IOException { + throws IOException { mHeaders = new Hashtable(); int colon; @@ -93,7 +91,7 @@ public class HttpMessage { while (true) { line = reader.readLine(); - if (line == null || line.equals("")) + if (line == null || line.equals("")) break; colon = line.indexOf(':'); if (colon == -1) { @@ -107,7 +105,7 @@ public class HttpMessage { } public void write(OutputStreamWriter writer) - throws IOException { + throws IOException { writer.write(mLine + Http.CRLF); writeHeaders(writer); writer.flush(); @@ -118,12 +116,12 @@ public class HttpMessage { } public void parse(BufferedReader reader) - throws IOException { + throws IOException { String line = reader.readLine(); -// if (line == null) { - // throw new HttpEofException("End of stream reached"); - // } + // if (line == null) { + // throw new HttpEofException("End of stream reached"); + // } if (line.equals("")) { throw new HttpProtocolException("Bad Http req/resp line " + line); } @@ -143,7 +141,7 @@ public class HttpMessage { done = reader.read(cbuf, total, len - total); total += done; } - + mContent = new String(cbuf); } } diff --git a/pki/base/util/src/com/netscape/cmsutil/http/HttpProtocolException.java b/pki/base/util/src/com/netscape/cmsutil/http/HttpProtocolException.java index 6b2fc75fe..b5ceb1d7f 100644 --- a/pki/base/util/src/com/netscape/cmsutil/http/HttpProtocolException.java +++ b/pki/base/util/src/com/netscape/cmsutil/http/HttpProtocolException.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.http; - import java.io.IOException; - public class HttpProtocolException extends IOException { /** * diff --git a/pki/base/util/src/com/netscape/cmsutil/http/HttpRequest.java b/pki/base/util/src/com/netscape/cmsutil/http/HttpRequest.java index 76232a2dc..9024dabf0 100644 --- a/pki/base/util/src/com/netscape/cmsutil/http/HttpRequest.java +++ b/pki/base/util/src/com/netscape/cmsutil/http/HttpRequest.java @@ -17,16 +17,14 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.http; - import java.io.BufferedReader; import java.io.IOException; import java.io.OutputStreamWriter; - /** * Basic HTTP Request. not optimized for performance. * Set fields or parse from input. - * Handles text content. + * Handles text content. */ public class HttpRequest extends HttpMessage { public static final String GET = "GET"; @@ -48,9 +46,9 @@ public class HttpRequest extends HttpMessage { * set set request method. */ public void setMethod(String method) - throws HttpProtocolException { - if (!method.equals(GET) && !method.equals(HEAD) && - !method.equals(POST)) + throws HttpProtocolException { + if (!method.equals(GET) && !method.equals(HEAD) && + !method.equals(POST)) throw new HttpProtocolException("No such method " + method); mMethod = method; } @@ -66,7 +64,7 @@ public class HttpRequest extends HttpMessage { * write request to the http client */ public void write(OutputStreamWriter writer) - throws IOException { + throws IOException { if (mMethod == null || mURI == null) { HttpProtocolException e = new HttpProtocolException( "Http request method or uri not initialized"); @@ -83,17 +81,17 @@ public class HttpRequest extends HttpMessage { * parse a http request from a http client */ public void parse(BufferedReader reader) - throws IOException { + throws IOException { super.parse(reader); int method = mLine.indexOf(Http.SP); mMethod = mLine.substring(0, method); - if (!mMethod.equals(GET) && !mMethod.equals(POST) && - !mMethod.equals(HEAD)) { + if (!mMethod.equals(GET) && !mMethod.equals(POST) && + !mMethod.equals(HEAD)) { reset(); throw new HttpProtocolException("Bad Http request method"); - } + } int uri = mLine.lastIndexOf(Http.SP); @@ -101,8 +99,8 @@ public class HttpRequest extends HttpMessage { mHttpVers = mLine.substring(uri + 1); if (!mHttpVers.equals("")) { - if (!mHttpVers.equals(Http.Vers1_0) && - !mHttpVers.equals(Http.Vers1_1)) { + if (!mHttpVers.equals(Http.Vers1_0) && + !mHttpVers.equals(Http.Vers1_1)) { reset(); throw new HttpProtocolException("Bad Http version in request"); } diff --git a/pki/base/util/src/com/netscape/cmsutil/http/HttpResponse.java b/pki/base/util/src/com/netscape/cmsutil/http/HttpResponse.java index 09d8e562d..7ac7e2f69 100644 --- a/pki/base/util/src/com/netscape/cmsutil/http/HttpResponse.java +++ b/pki/base/util/src/com/netscape/cmsutil/http/HttpResponse.java @@ -17,12 +17,10 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.http; - import java.io.BufferedReader; import java.io.IOException; import java.io.OutputStreamWriter; - /** * Basic HTTP Response. * Set fields or parse from input. @@ -72,7 +70,7 @@ public class HttpResponse extends HttpMessage { * write the response out to the http client */ public void write(OutputStreamWriter writer) - throws IOException { + throws IOException { if (mStatusCode == null) { throw new HttpProtocolException("status code not set in response"); } @@ -88,7 +86,7 @@ public class HttpResponse extends HttpMessage { * parse a http response from a http server */ public void parse(BufferedReader reader) - throws IOException { + throws IOException { mHttpVers = null; mStatusCode = null; mReasonPhrase = null; @@ -102,8 +100,8 @@ public class HttpResponse extends HttpMessage { throw new HttpProtocolException("no Http version in response"); } mHttpVers = mLine.substring(0, httpvers); - if (!mHttpVers.equals(Http.Vers1_0) && - !mHttpVers.equals(Http.Vers1_1)) { + if (!mHttpVers.equals(Http.Vers1_0) && + !mHttpVers.equals(Http.Vers1_1)) { reset(); throw new HttpProtocolException("Bad Http version in response"); } diff --git a/pki/base/util/src/com/netscape/cmsutil/http/JssSSLSocketFactory.java b/pki/base/util/src/com/netscape/cmsutil/http/JssSSLSocketFactory.java index 501886b54..791549812 100644 --- a/pki/base/util/src/com/netscape/cmsutil/http/JssSSLSocketFactory.java +++ b/pki/base/util/src/com/netscape/cmsutil/http/JssSSLSocketFactory.java @@ -17,7 +17,6 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.http; - import java.io.IOException; import java.net.Socket; import java.net.SocketException; @@ -35,12 +34,12 @@ import com.netscape.cmsutil.net.ISocketFactory; /** * Uses NSS ssl socket. - * + * * @version $Revision$ $Date$ */ public class JssSSLSocketFactory implements ISocketFactory { private String mClientAuthCertNickname = null; - private SSLSocket s = null; + private SSLSocket s = null; public JssSSLSocketFactory() { } @@ -71,51 +70,49 @@ public class JssSSLSocketFactory implements ISocketFactory { SSLSocket.TLS_DHE_RSA_WITH_AES_256_CBC_SHA, 0 }; - + static { int i; - for (i = SSLSocket.SSL2_RC4_128_WITH_MD5; - i <= SSLSocket.SSL2_RC2_128_CBC_EXPORT40_WITH_MD5; ++i) { + for (i = SSLSocket.SSL2_RC4_128_WITH_MD5; i <= SSLSocket.SSL2_RC2_128_CBC_EXPORT40_WITH_MD5; ++i) { try { SSLSocket.setCipherPreferenceDefault(i, false); - } catch( SocketException e) { + } catch (SocketException e) { } } //skip SSL_EN_IDEA_128_EDE3_CBC_WITH_MD5 - for (i = SSLSocket.SSL2_DES_64_CBC_WITH_MD5; - i <= SSLSocket.SSL2_DES_192_EDE3_CBC_WITH_MD5; ++i) { + for (i = SSLSocket.SSL2_DES_64_CBC_WITH_MD5; i <= SSLSocket.SSL2_DES_192_EDE3_CBC_WITH_MD5; ++i) { try { SSLSocket.setCipherPreferenceDefault(i, false); - } catch( SocketException e) { + } catch (SocketException e) { } } for (i = 0; cipherSuites[i] != 0; ++i) { try { SSLSocket.setCipherPreferenceDefault(cipherSuites[i], true); - } catch( SocketException e) { + } catch (SocketException e) { } } } - public Socket makeSocket(String host, int port) - throws IOException, UnknownHostException { + public Socket makeSocket(String host, int port) + throws IOException, UnknownHostException { return makeSocket(host, port, null, null); } - public Socket makeSocket(String host, int port, - SSLCertificateApprovalCallback certApprovalCallback, - SSLClientCertificateSelectionCallback clientCertCallback) - throws IOException, UnknownHostException { + public Socket makeSocket(String host, int port, + SSLCertificateApprovalCallback certApprovalCallback, + SSLClientCertificateSelectionCallback clientCertCallback) + throws IOException, UnknownHostException { try { s = new SSLSocket(host, port, null, 0, certApprovalCallback, - clientCertCallback); + clientCertCallback); for (int i = 0; cipherSuites[i] != 0; ++i) { try { SSLSocket.setCipherPreferenceDefault(cipherSuites[i], true); - } catch( SocketException e) { + } catch (SocketException e) { } } @@ -154,8 +151,8 @@ public class JssSSLSocketFactory implements ISocketFactory { return s; } - public Socket makeSocket(String host, int port, int timeout) - throws IOException, UnknownHostException { + public Socket makeSocket(String host, int port, int timeout) + throws IOException, UnknownHostException { Thread t = new ConnectAsync(this, host, port); t.start(); @@ -163,7 +160,7 @@ public class JssSSLSocketFactory implements ISocketFactory { t.join(1000 * timeout); } catch (InterruptedException e) { } - + if (t.isAlive()) { } @@ -179,9 +176,8 @@ public class JssSSLSocketFactory implements ISocketFactory { public ClientHandshakeCB(Object sc) { this.sc = sc; } - + public void handshakeCompleted(SSLHandshakeCompletedEvent event) { } } } - diff --git a/pki/base/util/src/com/netscape/cmsutil/ldap/LDAPUtil.java b/pki/base/util/src/com/netscape/cmsutil/ldap/LDAPUtil.java index eaae00074..132e65e6c 100644 --- a/pki/base/util/src/com/netscape/cmsutil/ldap/LDAPUtil.java +++ b/pki/base/util/src/com/netscape/cmsutil/ldap/LDAPUtil.java @@ -44,18 +44,18 @@ public class LDAPUtil { LDIFContent content = record.getContent(); int type = content.getType(); if (type == LDIFContent.ATTRIBUTE_CONTENT) { - LDIFAttributeContent c = (LDIFAttributeContent)content; + LDIFAttributeContent c = (LDIFAttributeContent) content; LDAPAttribute[] attrs = c.getAttributes(); LDAPAttributeSet myAttrs = new LDAPAttributeSet(); - for (int i=0; i<attrs.length; i++) + for (int i = 0; i < attrs.length; i++) myAttrs.add(attrs[i]); LDAPEntry entry = new LDAPEntry(dn, myAttrs); try { conn.add(entry); } catch (LDAPException ee) { } - } else if (type == LDIFContent.MODIFICATION_CONTENT) { - LDIFModifyContent c = (LDIFModifyContent)content; + } else if (type == LDIFContent.MODIFICATION_CONTENT) { + LDIFModifyContent c = (LDIFModifyContent) content; LDAPModification[] mods = c.getModifications(); try { conn.modify(dn, mods); diff --git a/pki/base/util/src/com/netscape/cmsutil/net/ISocketFactory.java b/pki/base/util/src/com/netscape/cmsutil/net/ISocketFactory.java index 9227f5911..18f6cac88 100644 --- a/pki/base/util/src/com/netscape/cmsutil/net/ISocketFactory.java +++ b/pki/base/util/src/com/netscape/cmsutil/net/ISocketFactory.java @@ -24,15 +24,15 @@ import java.net.UnknownHostException; import org.mozilla.jss.ssl.SSLCertificateApprovalCallback; import org.mozilla.jss.ssl.SSLClientCertificateSelectionCallback; -public interface ISocketFactory -{ - Socket makeSocket(String host, int port) - throws IOException, UnknownHostException; - Socket makeSocket(String host, int port, int timeout) - throws IOException, UnknownHostException; - Socket makeSocket(String host, int port, - SSLCertificateApprovalCallback certApprovalCallback, - SSLClientCertificateSelectionCallback clientCertCallback) - throws IOException, UnknownHostException; -} +public interface ISocketFactory { + Socket makeSocket(String host, int port) + throws IOException, UnknownHostException; + + Socket makeSocket(String host, int port, int timeout) + throws IOException, UnknownHostException; + Socket makeSocket(String host, int port, + SSLCertificateApprovalCallback certApprovalCallback, + SSLClientCertificateSelectionCallback clientCertCallback) + throws IOException, UnknownHostException; +} diff --git a/pki/base/util/src/com/netscape/cmsutil/ocsp/BasicOCSPResponse.java b/pki/base/util/src/com/netscape/cmsutil/ocsp/BasicOCSPResponse.java index f6306b789..11ae7f152 100644 --- a/pki/base/util/src/com/netscape/cmsutil/ocsp/BasicOCSPResponse.java +++ b/pki/base/util/src/com/netscape/cmsutil/ocsp/BasicOCSPResponse.java @@ -35,7 +35,7 @@ import org.mozilla.jss.pkix.primitive.AlgorithmIdentifier; /** * RFC 2560: - * + * * <pre> * BasicOCSPResponse ::= SEQUENCE { * tbsResponseData ResponseData, @@ -43,11 +43,10 @@ import org.mozilla.jss.pkix.primitive.AlgorithmIdentifier; * signature BIT STRING, * certs [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL } * </pre> - * + * * @version $Revision$ $Date$ */ -public class BasicOCSPResponse implements Response -{ +public class BasicOCSPResponse implements Response { private byte mData[] = null; private ResponseData _rd = null; private AlgorithmIdentifier _signAlg = null; @@ -55,21 +54,18 @@ public class BasicOCSPResponse implements Response private Certificate _certs[] = null; public BasicOCSPResponse(ResponseData rd, AlgorithmIdentifier signAlg, - BIT_STRING signature, Certificate certs[]) - { + BIT_STRING signature, Certificate certs[]) { _rd = rd; _signAlg = signAlg; _signature = signature; _certs = certs; } - public BasicOCSPResponse(OCTET_STRING os) - { + public BasicOCSPResponse(OCTET_STRING os) { this(os.toByteArray()); } - public BasicOCSPResponse(byte data[]) - { + public BasicOCSPResponse(byte data[]) { mData = data; // extract _rd, _signAlg, _signature and _certs @@ -79,23 +75,21 @@ public class BasicOCSPResponse implements Response _signAlg = resp.getSignatureAlgorithm(); _signature = resp.getSignature(); _certs = resp.getCerts(); - } catch (Exception e) { + } catch (Exception e) { // exception in decoding byte data - } + } } private static final Tag TAG = SEQUENCE.TAG; - public Tag getTag() - { + public Tag getTag() { return TAG; } - public void encode(Tag t, OutputStream os) throws IOException - { - if (mData != null) { - os.write(mData); - } else { + public void encode(Tag t, OutputStream os) throws IOException { + if (mData != null) { + os.write(mData); + } else { SEQUENCE seq = new SEQUENCE(); seq.addElement(_rd); seq.addElement(_signAlg); @@ -105,50 +99,42 @@ public class BasicOCSPResponse implements Response for (Certificate c : _certs) { certsSeq.addElement(c); } - EXPLICIT certsExplicit = new EXPLICIT(new Tag(0),certsSeq); + EXPLICIT certsExplicit = new EXPLICIT(new Tag(0), certsSeq); seq.addElement(certsExplicit); } - seq.encode(t,os); - } + seq.encode(t, os); + } } - public void encode(OutputStream os) throws IOException - { + public void encode(OutputStream os) throws IOException { encode(TAG, os); } - public OCTET_STRING getBytes() - { + public OCTET_STRING getBytes() { return null; } - public ResponseData getResponseData() - { + public ResponseData getResponseData() { return _rd; } - public AlgorithmIdentifier getSignatureAlgorithm() - { + public AlgorithmIdentifier getSignatureAlgorithm() { return _signAlg; } - public BIT_STRING getSignature() - { + public BIT_STRING getSignature() { return _signature; } - public int getCertsCount() - { + public int getCertsCount() { return (_certs != null) ? _certs.length : 0; } - public Certificate[] getCerts() - { - return _certs; + public Certificate[] getCerts() { + return _certs; } - public Certificate getCertificateAt(int pos) - { + public Certificate getCertificateAt(int pos) { return (_certs != null) ? _certs[pos] : null; } @@ -161,54 +147,49 @@ public class BasicOCSPResponse implements Response /** * A Template for decoding <code>ResponseBytes</code>. */ - public static class Template implements ASN1Template - { + public static class Template implements ASN1Template { private SEQUENCE.Template seqt; - public Template() - { - seqt = new SEQUENCE.Template(); - seqt.addElement( ResponseData.getTemplate() ); - seqt.addElement( AlgorithmIdentifier.getTemplate() ); - seqt.addElement( BIT_STRING.getTemplate() ); - seqt.addOptionalElement( new EXPLICIT.Template( - new Tag(0), new SEQUENCE.OF_Template( - Certificate.getTemplate())) ); - } - - public boolean tagMatch(Tag tag) - { - return TAG.equals(tag); - } - - public ASN1Value decode(InputStream istream) - throws InvalidBERException, IOException - { - return decode(TAG, istream); - } - - public ASN1Value decode(Tag implicitTag, InputStream istream) - throws InvalidBERException, IOException - { - SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, istream); - - ResponseData rd = (ResponseData)seq.elementAt(0); - AlgorithmIdentifier alg = (AlgorithmIdentifier)seq.elementAt(1); - BIT_STRING bs = (BIT_STRING)seq.elementAt(2); - Certificate[] certs = null; - if (seq.size() == 4) { - // optional certificates are present - EXPLICIT certSeqExplicit = (EXPLICIT) seq.elementAt(3); - SEQUENCE certSeq = (SEQUENCE) certSeqExplicit.getContent(); - if (certSeq != null) { - certs = new Certificate[certSeq.size()]; - for (int x = 0; x < certSeq.size(); x++) { - certs[x] = (Certificate) certSeq.elementAt(x); - } - } - } - - return new BasicOCSPResponse(rd, alg, bs, certs); - } + public Template() { + seqt = new SEQUENCE.Template(); + seqt.addElement(ResponseData.getTemplate()); + seqt.addElement(AlgorithmIdentifier.getTemplate()); + seqt.addElement(BIT_STRING.getTemplate()); + seqt.addOptionalElement(new EXPLICIT.Template( + new Tag(0), new SEQUENCE.OF_Template( + Certificate.getTemplate()))); + } + + public boolean tagMatch(Tag tag) { + return TAG.equals(tag); + } + + public ASN1Value decode(InputStream istream) + throws InvalidBERException, IOException { + return decode(TAG, istream); + } + + public ASN1Value decode(Tag implicitTag, InputStream istream) + throws InvalidBERException, IOException { + SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, istream); + + ResponseData rd = (ResponseData) seq.elementAt(0); + AlgorithmIdentifier alg = (AlgorithmIdentifier) seq.elementAt(1); + BIT_STRING bs = (BIT_STRING) seq.elementAt(2); + Certificate[] certs = null; + if (seq.size() == 4) { + // optional certificates are present + EXPLICIT certSeqExplicit = (EXPLICIT) seq.elementAt(3); + SEQUENCE certSeq = (SEQUENCE) certSeqExplicit.getContent(); + if (certSeq != null) { + certs = new Certificate[certSeq.size()]; + for (int x = 0; x < certSeq.size(); x++) { + certs[x] = (Certificate) certSeq.elementAt(x); + } + } + } + + return new BasicOCSPResponse(rd, alg, bs, certs); + } } } diff --git a/pki/base/util/src/com/netscape/cmsutil/ocsp/CertID.java b/pki/base/util/src/com/netscape/cmsutil/ocsp/CertID.java index 3c563d939..b6979c784 100644 --- a/pki/base/util/src/com/netscape/cmsutil/ocsp/CertID.java +++ b/pki/base/util/src/com/netscape/cmsutil/ocsp/CertID.java @@ -32,7 +32,7 @@ import org.mozilla.jss.pkix.primitive.AlgorithmIdentifier; /** * RFC 2560: - * + * * <pre> * CertID ::= SEQUENCE { * hashAlgorithm AlgorithmIdentifier, @@ -40,130 +40,116 @@ import org.mozilla.jss.pkix.primitive.AlgorithmIdentifier; * issuerKeyHash OCTET STRING, -- Hash of Issuers public key * serialNumber CertificateSerialNumber } * </pre> - * + * * @version $Revision$ $Date$ */ -public class CertID implements ASN1Value -{ - /////////////////////////////////////////////////////////////////////// - // Members and member access - /////////////////////////////////////////////////////////////////////// - private AlgorithmIdentifier hashAlgorithm; - private OCTET_STRING issuerNameHash; - private OCTET_STRING issuerKeyHash; - private INTEGER serialNumber; - private SEQUENCE sequence; - - public AlgorithmIdentifier getHashAlgorithm() - { - return hashAlgorithm; - } - - public OCTET_STRING getIssuerNameHash() - { - return issuerNameHash; - } - - public OCTET_STRING getIssuerKeyHash() - { - return issuerKeyHash; - } - - public INTEGER getSerialNumber() - { - return serialNumber; - } - - /////////////////////////////////////////////////////////////////////// - // Constructors - /////////////////////////////////////////////////////////////////////// - - public CertID(AlgorithmIdentifier hashAlgorithm, - OCTET_STRING issuerNameHash, OCTET_STRING issuerKeyHash, - INTEGER serialNumber) - { - sequence = new SEQUENCE(); - - this.hashAlgorithm = hashAlgorithm; - sequence.addElement(hashAlgorithm); - - this.issuerNameHash = issuerNameHash; - sequence.addElement(issuerNameHash); - - this.issuerKeyHash = issuerKeyHash; - sequence.addElement(issuerKeyHash); - - this.serialNumber = serialNumber; - sequence.addElement(serialNumber); - } - - /////////////////////////////////////////////////////////////////////// - // encoding/decoding - /////////////////////////////////////////////////////////////////////// - - private static final Tag TAG = SEQUENCE.TAG; - - public Tag getTag() - { - return TAG; - } - - public void encode(OutputStream ostream) throws IOException - { - encode(TAG, ostream); - } - - public void encode(Tag implicitTag, OutputStream ostream) - throws IOException - { - sequence.encode(implicitTag, ostream); - } - - private static final Template templateInstance = new Template(); - - public static Template getTemplate() { - return templateInstance; - } - - /** - * A Template for decoding a <code>CertID</code>. - */ - public static class Template implements ASN1Template - { - - private SEQUENCE.Template seqt; - - public Template() - { - seqt = new SEQUENCE.Template(); - seqt.addElement( AlgorithmIdentifier.getTemplate() ); - seqt.addElement( OCTET_STRING.getTemplate() ); - seqt.addElement( OCTET_STRING.getTemplate() ); - seqt.addElement( INTEGER.getTemplate() ); - } - - public boolean tagMatch(Tag tag) - { - return TAG.equals(tag); - } - - public ASN1Value decode(InputStream istream) - throws InvalidBERException, IOException - { - return decode(TAG, istream); - } - - public ASN1Value decode(Tag implicitTag, InputStream istream) - throws InvalidBERException, IOException - { - SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, istream); - - return new CertID( - (AlgorithmIdentifier) seq.elementAt(0), - (OCTET_STRING) seq.elementAt(1), - (OCTET_STRING) seq.elementAt(2), - (INTEGER) seq.elementAt(3)); - } - } +public class CertID implements ASN1Value { + /////////////////////////////////////////////////////////////////////// + // Members and member access + /////////////////////////////////////////////////////////////////////// + private AlgorithmIdentifier hashAlgorithm; + private OCTET_STRING issuerNameHash; + private OCTET_STRING issuerKeyHash; + private INTEGER serialNumber; + private SEQUENCE sequence; + + public AlgorithmIdentifier getHashAlgorithm() { + return hashAlgorithm; + } + + public OCTET_STRING getIssuerNameHash() { + return issuerNameHash; + } + + public OCTET_STRING getIssuerKeyHash() { + return issuerKeyHash; + } + + public INTEGER getSerialNumber() { + return serialNumber; + } + + /////////////////////////////////////////////////////////////////////// + // Constructors + /////////////////////////////////////////////////////////////////////// + + public CertID(AlgorithmIdentifier hashAlgorithm, + OCTET_STRING issuerNameHash, OCTET_STRING issuerKeyHash, + INTEGER serialNumber) { + sequence = new SEQUENCE(); + + this.hashAlgorithm = hashAlgorithm; + sequence.addElement(hashAlgorithm); + + this.issuerNameHash = issuerNameHash; + sequence.addElement(issuerNameHash); + + this.issuerKeyHash = issuerKeyHash; + sequence.addElement(issuerKeyHash); + + this.serialNumber = serialNumber; + sequence.addElement(serialNumber); + } + + /////////////////////////////////////////////////////////////////////// + // encoding/decoding + /////////////////////////////////////////////////////////////////////// + + private static final Tag TAG = SEQUENCE.TAG; + + public Tag getTag() { + return TAG; + } + + public void encode(OutputStream ostream) throws IOException { + encode(TAG, ostream); + } + + public void encode(Tag implicitTag, OutputStream ostream) + throws IOException { + sequence.encode(implicitTag, ostream); + } + + private static final Template templateInstance = new Template(); + + public static Template getTemplate() { + return templateInstance; + } + + /** + * A Template for decoding a <code>CertID</code>. + */ + public static class Template implements ASN1Template { + + private SEQUENCE.Template seqt; + + public Template() { + seqt = new SEQUENCE.Template(); + seqt.addElement(AlgorithmIdentifier.getTemplate()); + seqt.addElement(OCTET_STRING.getTemplate()); + seqt.addElement(OCTET_STRING.getTemplate()); + seqt.addElement(INTEGER.getTemplate()); + } + + public boolean tagMatch(Tag tag) { + return TAG.equals(tag); + } + + public ASN1Value decode(InputStream istream) + throws InvalidBERException, IOException { + return decode(TAG, istream); + } + + public ASN1Value decode(Tag implicitTag, InputStream istream) + throws InvalidBERException, IOException { + SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, istream); + + return new CertID( + (AlgorithmIdentifier) seq.elementAt(0), + (OCTET_STRING) seq.elementAt(1), + (OCTET_STRING) seq.elementAt(2), + (INTEGER) seq.elementAt(3)); + } + } } diff --git a/pki/base/util/src/com/netscape/cmsutil/ocsp/CertStatus.java b/pki/base/util/src/com/netscape/cmsutil/ocsp/CertStatus.java index c6fe4b510..a90eb215f 100644 --- a/pki/base/util/src/com/netscape/cmsutil/ocsp/CertStatus.java +++ b/pki/base/util/src/com/netscape/cmsutil/ocsp/CertStatus.java @@ -21,16 +21,15 @@ import org.mozilla.jss.asn1.ASN1Value; /** * RFC 2560: - * + * * <pre> * CertStatus ::= CHOICE { * good [0] IMPLICIT NULL, * revoked [1] IMPLICIT RevokedInfo, * unknown [2] IMPLICIT UnknownInfo } * </pre> - * + * * @version $Revision$ $Date$ */ -public interface CertStatus extends ASN1Value -{ +public interface CertStatus extends ASN1Value { } diff --git a/pki/base/util/src/com/netscape/cmsutil/ocsp/GoodInfo.java b/pki/base/util/src/com/netscape/cmsutil/ocsp/GoodInfo.java index c0b5015d0..fa7387260 100644 --- a/pki/base/util/src/com/netscape/cmsutil/ocsp/GoodInfo.java +++ b/pki/base/util/src/com/netscape/cmsutil/ocsp/GoodInfo.java @@ -30,79 +30,69 @@ import org.mozilla.jss.asn1.Tag; /** * RFC 2560: - * + * * <pre> * CertStatus ::= CHOICE { * good [0] IMPLICIT NULL, * revoked [1] IMPLICIT RevokedInfo, * unknown [2] IMPLICIT UnknownInfo } * </pre> - * + * * @version $Revision$ $Date$ */ -public class GoodInfo implements CertStatus -{ - private static final Tag TAG = SEQUENCE.TAG; +public class GoodInfo implements CertStatus { + private static final Tag TAG = SEQUENCE.TAG; - public GoodInfo() - { - } + public GoodInfo() { + } - public Tag getTag() - { - return Tag.get(0); - } + public Tag getTag() { + return Tag.get(0); + } - public void encode(Tag t, OutputStream os) throws IOException - { - NULL.getInstance().encode(getTag(), os); - } + public void encode(Tag t, OutputStream os) throws IOException { + NULL.getInstance().encode(getTag(), os); + } - public void encode(OutputStream os) throws IOException - { - encode(getTag(), os); - } + public void encode(OutputStream os) throws IOException { + encode(getTag(), os); + } - private static final Template templateInstance = new Template(); + private static final Template templateInstance = new Template(); - public static Template getTemplate() { - return templateInstance; - } + public static Template getTemplate() { + return templateInstance; + } - /** - * A Template for decoding <code>ResponseBytes</code>. - */ - public static class Template implements ASN1Template - { + /** + * A Template for decoding <code>ResponseBytes</code>. + */ + public static class Template implements ASN1Template { - private SEQUENCE.Template seqt; + private SEQUENCE.Template seqt; - public Template() - { - seqt = new SEQUENCE.Template(); - seqt.addElement(new NULL.Template() ); + public Template() { + seqt = new SEQUENCE.Template(); + seqt.addElement(new NULL.Template()); - } + } - public boolean tagMatch(Tag tag) - { - return TAG.equals(tag); - } + public boolean tagMatch(Tag tag) { + return TAG.equals(tag); + } - public ASN1Value decode(InputStream istream) - throws InvalidBERException, IOException - { - return decode(TAG, istream); - } + public ASN1Value decode(InputStream istream) + throws InvalidBERException, IOException { + return decode(TAG, istream); + } - public ASN1Value decode(Tag implicitTag, InputStream istream) - throws InvalidBERException, IOException - { - // SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, - // istream); + public ASN1Value decode(Tag implicitTag, InputStream istream) + throws InvalidBERException, IOException { + // SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, + // istream); - return new GoodInfo(); + return new GoodInfo(); - } } + } } diff --git a/pki/base/util/src/com/netscape/cmsutil/ocsp/KeyHashID.java b/pki/base/util/src/com/netscape/cmsutil/ocsp/KeyHashID.java index 96a3e44fa..358fb0ebd 100644 --- a/pki/base/util/src/com/netscape/cmsutil/ocsp/KeyHashID.java +++ b/pki/base/util/src/com/netscape/cmsutil/ocsp/KeyHashID.java @@ -30,87 +30,76 @@ import org.mozilla.jss.asn1.Tag; /** * RFC 2560: - * + * * <pre> * ResponderID ::= CHOICE { * byName [1] EXPLICIT Name, * byKey [2] EXPLICIT KeyHash } * </pre> - * + * * @version $Revision$ $Date$ */ -public class KeyHashID implements ResponderID -{ - private OCTET_STRING _hash = null; - private static final Tag TAG = SEQUENCE.TAG; - - public KeyHashID(OCTET_STRING hash) - { - _hash = hash; - } - - public Tag getTag() - { - return Tag.get(2); - } - - public void encode(Tag tag, OutputStream os) throws IOException - { - _hash.encode(os); - } - - public void encode(OutputStream os) throws IOException - { - _hash.encode(os); - } - - public OCTET_STRING getHash() - { - return _hash; - } - - private static final Template templateInstance = new Template(); - - public static Template getTemplate() { - return templateInstance; +public class KeyHashID implements ResponderID { + private OCTET_STRING _hash = null; + private static final Tag TAG = SEQUENCE.TAG; + + public KeyHashID(OCTET_STRING hash) { + _hash = hash; + } + + public Tag getTag() { + return Tag.get(2); + } + + public void encode(Tag tag, OutputStream os) throws IOException { + _hash.encode(os); + } + + public void encode(OutputStream os) throws IOException { + _hash.encode(os); + } + + public OCTET_STRING getHash() { + return _hash; + } + + private static final Template templateInstance = new Template(); + + public static Template getTemplate() { + return templateInstance; + } + + /** + * A Template for decoding <code>ResponseBytes</code>. + */ + public static class Template implements ASN1Template { + + private SEQUENCE.Template seqt; + + public Template() { + seqt = new SEQUENCE.Template(); + // seqt.addElement(new EXPLICIT.Template( + // new Tag (2), new OCTET_STRING.Template()) ); + seqt.addElement(new OCTET_STRING.Template()); + + } + + public boolean tagMatch(Tag tag) { + return TAG.equals(tag); + } + + public ASN1Value decode(InputStream istream) + throws InvalidBERException, IOException { + return decode(TAG, istream); } - /** - * A Template for decoding <code>ResponseBytes</code>. - */ - public static class Template implements ASN1Template - { - - private SEQUENCE.Template seqt; - - public Template() - { - seqt = new SEQUENCE.Template(); -// seqt.addElement(new EXPLICIT.Template( - // new Tag (2), new OCTET_STRING.Template()) ); - seqt.addElement(new OCTET_STRING.Template() ); - - } - - public boolean tagMatch(Tag tag) - { - return TAG.equals(tag); - } - - public ASN1Value decode(InputStream istream) - throws InvalidBERException, IOException - { - return decode(TAG, istream); - } - - public ASN1Value decode(Tag implicitTag, InputStream istream) - throws InvalidBERException, IOException - { - SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, + public ASN1Value decode(Tag implicitTag, InputStream istream) + throws InvalidBERException, IOException { + SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, istream); - OCTET_STRING o = (OCTET_STRING)seq.elementAt(0); - return new KeyHashID(o); - } - } + OCTET_STRING o = (OCTET_STRING) seq.elementAt(0); + return new KeyHashID(o); + } + } } diff --git a/pki/base/util/src/com/netscape/cmsutil/ocsp/NameID.java b/pki/base/util/src/com/netscape/cmsutil/ocsp/NameID.java index aa6ef1b55..529ededbb 100644 --- a/pki/base/util/src/com/netscape/cmsutil/ocsp/NameID.java +++ b/pki/base/util/src/com/netscape/cmsutil/ocsp/NameID.java @@ -30,88 +30,77 @@ import org.mozilla.jss.pkix.primitive.Name; /** * RFC 2560: - * + * * <pre> * ResponderID ::= CHOICE { * byName [1] EXPLICIT Name, * byKey [2] EXPLICIT KeyHash } * </pre> - * + * * @version $Revision$ $Date$ */ -public class NameID implements ResponderID -{ - private Name _name = null; - private static final Tag TAG = SEQUENCE.TAG; - - public NameID(Name n) - { - _name = n; - } - - public Tag getTag() - { - return Tag.get(1); - } - - public void encode(Tag tag, OutputStream os) throws IOException - { - _name.encode(os); - } - - public void encode(OutputStream os) throws IOException - { - _name.encode(os); - } - - public Name getName() - { - return _name; - } - - private static final Template templateInstance = new Template(); - - public static Template getTemplate() { - return templateInstance; +public class NameID implements ResponderID { + private Name _name = null; + private static final Tag TAG = SEQUENCE.TAG; + + public NameID(Name n) { + _name = n; + } + + public Tag getTag() { + return Tag.get(1); + } + + public void encode(Tag tag, OutputStream os) throws IOException { + _name.encode(os); + } + + public void encode(OutputStream os) throws IOException { + _name.encode(os); + } + + public Name getName() { + return _name; + } + + private static final Template templateInstance = new Template(); + + public static Template getTemplate() { + return templateInstance; + } + + /** + * A Template for decoding <code>ResponseBytes</code>. + */ + public static class Template implements ASN1Template { + + private SEQUENCE.Template seqt; + + public Template() { + seqt = new SEQUENCE.Template(); + // seqt.addElement(new EXPLICIT.Template( + // new Tag (1), new Name.Template()) ); + seqt.addElement(new Name.Template()); + + } + + public boolean tagMatch(Tag tag) { + return TAG.equals(tag); } - /** - * A Template for decoding <code>ResponseBytes</code>. - */ - public static class Template implements ASN1Template - { - - private SEQUENCE.Template seqt; - - public Template() - { - seqt = new SEQUENCE.Template(); - // seqt.addElement(new EXPLICIT.Template( - // new Tag (1), new Name.Template()) ); - seqt.addElement(new Name.Template()); - - } - - public boolean tagMatch(Tag tag) - { - return TAG.equals(tag); - } - - public ASN1Value decode(InputStream istream) - throws InvalidBERException, IOException - { - return decode(TAG, istream); - } - - public ASN1Value decode(Tag implicitTag, InputStream istream) - throws InvalidBERException, IOException - { - SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, + public ASN1Value decode(InputStream istream) + throws InvalidBERException, IOException { + return decode(TAG, istream); + } + + public ASN1Value decode(Tag implicitTag, InputStream istream) + throws InvalidBERException, IOException { + SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, istream); - - // EXPLICIT e_name = (EXPLICIT) seq.elementAt(0); - Name name = (Name)seq.elementAt(0); - return new NameID(name); - } - } + + // EXPLICIT e_name = (EXPLICIT) seq.elementAt(0); + Name name = (Name) seq.elementAt(0); + return new NameID(name); + } + } } diff --git a/pki/base/util/src/com/netscape/cmsutil/ocsp/OCSPRequest.java b/pki/base/util/src/com/netscape/cmsutil/ocsp/OCSPRequest.java index ea2e54221..963bdc832 100644 --- a/pki/base/util/src/com/netscape/cmsutil/ocsp/OCSPRequest.java +++ b/pki/base/util/src/com/netscape/cmsutil/ocsp/OCSPRequest.java @@ -30,125 +30,111 @@ import org.mozilla.jss.asn1.Tag; /** * RFC 2560: - * + * * <pre> * OCSPRequest ::= SEQUENCE { * tbsRequest TBSRequest, * optionalSignature [0] EXPLICIT Signature OPTIONAL } * </pre> - * + * * @version $Revision$ $Date$ */ -public class OCSPRequest implements ASN1Value -{ - - /////////////////////////////////////////////////////////////////////// - // Members and member access - /////////////////////////////////////////////////////////////////////// - private TBSRequest tbsRequest; - private Signature optionalSignature; - private SEQUENCE sequence; - - /** - * Returns the <code>TBSRequest</code> field. - */ - public TBSRequest getTBSRequest() - { - return tbsRequest; - } - - /** - * Returns the <code>Signature</code> field. - */ - public Signature getSignature() - { - return optionalSignature; - } - - - /* THIS code is probably broken. It does not properly encode the explicit element */ - - public OCSPRequest(TBSRequest tbsRequest, Signature optionalSignature) - { - sequence = new SEQUENCE(); - - this.tbsRequest = tbsRequest; - sequence.addElement(tbsRequest); - - this.optionalSignature = optionalSignature; - if (optionalSignature != null) { - sequence.addElement(optionalSignature); - } - } - - /////////////////////////////////////////////////////////////////////// - // encoding/decoding - /////////////////////////////////////////////////////////////////////// - private static final Tag TAG = SEQUENCE.TAG; - - public Tag getTag() - { - return TAG; - } - - public void encode(OutputStream ostream) throws IOException - { - encode(TAG, ostream); - } - - public void encode(Tag implicitTag, OutputStream ostream) - throws IOException - { - sequence.encode(implicitTag, ostream); - } - - private static final Template templateInstance = new Template(); - - public static Template getTemplate() - { - return templateInstance; - } - - /** - * A Template for decoding OCSPRequest. - */ - public static class Template implements ASN1Template - { - - private SEQUENCE.Template seqt; - - public Template() - { - seqt = new SEQUENCE.Template(); - seqt.addElement(TBSRequest.getTemplate()); - seqt.addOptionalElement( new EXPLICIT.Template( new Tag(0), - new Signature.Template()) ); - } - - public boolean tagMatch(Tag tag) - { - return TAG.equals(tag); - } - - public ASN1Value decode(InputStream istream) - throws InvalidBERException, IOException - { - return decode(TAG, istream); - } - - public ASN1Value decode(Tag implicitTag, InputStream istream) - throws InvalidBERException, IOException - { - SEQUENCE seq = (SEQUENCE) seqt.decode(istream); - Signature signature = null; - if (seq.elementAt(1) != null) { - signature = (Signature)((EXPLICIT)seq.elementAt(1)).getContent(); - } - - return new OCSPRequest( - (TBSRequest) seq.elementAt(0), - signature); - } - } +public class OCSPRequest implements ASN1Value { + + /////////////////////////////////////////////////////////////////////// + // Members and member access + /////////////////////////////////////////////////////////////////////// + private TBSRequest tbsRequest; + private Signature optionalSignature; + private SEQUENCE sequence; + + /** + * Returns the <code>TBSRequest</code> field. + */ + public TBSRequest getTBSRequest() { + return tbsRequest; + } + + /** + * Returns the <code>Signature</code> field. + */ + public Signature getSignature() { + return optionalSignature; + } + + /* THIS code is probably broken. It does not properly encode the explicit element */ + + public OCSPRequest(TBSRequest tbsRequest, Signature optionalSignature) { + sequence = new SEQUENCE(); + + this.tbsRequest = tbsRequest; + sequence.addElement(tbsRequest); + + this.optionalSignature = optionalSignature; + if (optionalSignature != null) { + sequence.addElement(optionalSignature); + } + } + + /////////////////////////////////////////////////////////////////////// + // encoding/decoding + /////////////////////////////////////////////////////////////////////// + private static final Tag TAG = SEQUENCE.TAG; + + public Tag getTag() { + return TAG; + } + + public void encode(OutputStream ostream) throws IOException { + encode(TAG, ostream); + } + + public void encode(Tag implicitTag, OutputStream ostream) + throws IOException { + sequence.encode(implicitTag, ostream); + } + + private static final Template templateInstance = new Template(); + + public static Template getTemplate() { + return templateInstance; + } + + /** + * A Template for decoding OCSPRequest. + */ + public static class Template implements ASN1Template { + + private SEQUENCE.Template seqt; + + public Template() { + seqt = new SEQUENCE.Template(); + seqt.addElement(TBSRequest.getTemplate()); + seqt.addOptionalElement(new EXPLICIT.Template(new Tag(0), + new Signature.Template())); + } + + public boolean tagMatch(Tag tag) { + return TAG.equals(tag); + } + + public ASN1Value decode(InputStream istream) + throws InvalidBERException, IOException { + return decode(TAG, istream); + } + + public ASN1Value decode(Tag implicitTag, InputStream istream) + throws InvalidBERException, IOException { + SEQUENCE seq = (SEQUENCE) seqt.decode(istream); + Signature signature = null; + if (seq.elementAt(1) != null) { + signature = (Signature) ((EXPLICIT) seq.elementAt(1)).getContent(); + } + + return new OCSPRequest( + (TBSRequest) seq.elementAt(0), + signature); + } + } } diff --git a/pki/base/util/src/com/netscape/cmsutil/ocsp/OCSPResponse.java b/pki/base/util/src/com/netscape/cmsutil/ocsp/OCSPResponse.java index d8635fe2a..6696cd9dc 100644 --- a/pki/base/util/src/com/netscape/cmsutil/ocsp/OCSPResponse.java +++ b/pki/base/util/src/com/netscape/cmsutil/ocsp/OCSPResponse.java @@ -30,118 +30,106 @@ import org.mozilla.jss.asn1.Tag; /** * RFC 2560: - * + * * <pre> * OCSPResponse ::= SEQUENCE { * responseStatus OCSPResponseStatus, * responseBytes [0] EXPLICIT ResponseBytes OPTIONAL } * </pre> - * + * * @version $Revision$ $Date$ */ -public class OCSPResponse implements ASN1Value -{ - /////////////////////////////////////////////////////////////////////// - // Members and member access - /////////////////////////////////////////////////////////////////////// - private OCSPResponseStatus responseStatus = null; - private ResponseBytes responseBytes = null; - private SEQUENCE sequence; - - public OCSPResponseStatus getResponseStatus() - { - return responseStatus; - } - - public ResponseBytes getResponseBytes() - { - return responseBytes; - } - - public OCSPResponse(OCSPResponseStatus responseStatus, - ResponseBytes responseBytes) - { - sequence = new SEQUENCE(); - - this.responseStatus = responseStatus; - sequence.addElement(responseStatus); - - this.responseBytes = responseBytes; - sequence.addElement(new EXPLICIT(Tag.get(0), responseBytes)); - } - - /////////////////////////////////////////////////////////////////////// - // encoding/decoding - /////////////////////////////////////////////////////////////////////// - - private static final Tag TAG = SEQUENCE.TAG; - - public Tag getTag() - { - return TAG; - } - - public void encode(OutputStream ostream) throws IOException - { - encode(TAG, ostream); - } - - public void encode(Tag implicitTag, OutputStream ostream) - throws IOException - { - sequence.encode(implicitTag, ostream); - } - - private static final Template templateInstance = new Template(); - - public static Template getTemplate() { - return templateInstance; - } - - /** - * A Template for decoding an <code>OCSPResponse</code>. - */ - public static class Template implements ASN1Template - { - - private SEQUENCE.Template seqt; - - public Template() - { - seqt = new SEQUENCE.Template(); - seqt.addElement( OCSPResponseStatus.getTemplate() ); - seqt.addOptionalElement( - new EXPLICIT.Template( - new Tag (0), new ResponseBytes.Template()) ); - - } - - public boolean tagMatch(Tag tag) - { - return TAG.equals(tag); - } - - public ASN1Value decode(InputStream istream) - throws InvalidBERException, IOException - { - return decode(TAG, istream); - } - - public ASN1Value decode(Tag implicitTag, InputStream istream) - throws InvalidBERException, IOException - { - SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, istream); - - OCSPResponseStatus rs = (OCSPResponseStatus) seq.elementAt(0); - ResponseBytes rb = null; - ASN1Value val = seq.elementAt(1); - if (val instanceof EXPLICIT) { - EXPLICIT exp = (EXPLICIT)val; - rb = (ResponseBytes)exp.getContent(); - } else { - rb = (ResponseBytes)val; - } - return new OCSPResponse(rs, rb); - } - } +public class OCSPResponse implements ASN1Value { + /////////////////////////////////////////////////////////////////////// + // Members and member access + /////////////////////////////////////////////////////////////////////// + private OCSPResponseStatus responseStatus = null; + private ResponseBytes responseBytes = null; + private SEQUENCE sequence; + + public OCSPResponseStatus getResponseStatus() { + return responseStatus; + } + + public ResponseBytes getResponseBytes() { + return responseBytes; + } + + public OCSPResponse(OCSPResponseStatus responseStatus, + ResponseBytes responseBytes) { + sequence = new SEQUENCE(); + + this.responseStatus = responseStatus; + sequence.addElement(responseStatus); + + this.responseBytes = responseBytes; + sequence.addElement(new EXPLICIT(Tag.get(0), responseBytes)); + } + + /////////////////////////////////////////////////////////////////////// + // encoding/decoding + /////////////////////////////////////////////////////////////////////// + + private static final Tag TAG = SEQUENCE.TAG; + + public Tag getTag() { + return TAG; + } + + public void encode(OutputStream ostream) throws IOException { + encode(TAG, ostream); + } + + public void encode(Tag implicitTag, OutputStream ostream) + throws IOException { + sequence.encode(implicitTag, ostream); + } + + private static final Template templateInstance = new Template(); + + public static Template getTemplate() { + return templateInstance; + } + + /** + * A Template for decoding an <code>OCSPResponse</code>. + */ + public static class Template implements ASN1Template { + + private SEQUENCE.Template seqt; + + public Template() { + seqt = new SEQUENCE.Template(); + seqt.addElement(OCSPResponseStatus.getTemplate()); + seqt.addOptionalElement( + new EXPLICIT.Template( + new Tag(0), new ResponseBytes.Template())); + + } + + public boolean tagMatch(Tag tag) { + return TAG.equals(tag); + } + + public ASN1Value decode(InputStream istream) + throws InvalidBERException, IOException { + return decode(TAG, istream); + } + + public ASN1Value decode(Tag implicitTag, InputStream istream) + throws InvalidBERException, IOException { + SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, istream); + + OCSPResponseStatus rs = (OCSPResponseStatus) seq.elementAt(0); + ResponseBytes rb = null; + ASN1Value val = seq.elementAt(1); + if (val instanceof EXPLICIT) { + EXPLICIT exp = (EXPLICIT) val; + rb = (ResponseBytes) exp.getContent(); + } else { + rb = (ResponseBytes) val; + } + return new OCSPResponse(rs, rb); + } + } } diff --git a/pki/base/util/src/com/netscape/cmsutil/ocsp/OCSPResponseStatus.java b/pki/base/util/src/com/netscape/cmsutil/ocsp/OCSPResponseStatus.java index 145fbe7d0..38ca881c2 100644 --- a/pki/base/util/src/com/netscape/cmsutil/ocsp/OCSPResponseStatus.java +++ b/pki/base/util/src/com/netscape/cmsutil/ocsp/OCSPResponseStatus.java @@ -29,7 +29,7 @@ import org.mozilla.jss.asn1.Tag; /** * RFC 2560: - * + * * <pre> * OCSPResponseStatus ::= ENUMERATED { * successful (0), --Response has valid confirmations @@ -41,90 +41,80 @@ import org.mozilla.jss.asn1.Tag; * unauthorized (6) --Request unauthorized * } * </pre> - * + * * @version $Revision$ $Date$ */ -public class OCSPResponseStatus implements ASN1Value -{ - /////////////////////////////////////////////////////////////////////// - // Members and member access - /////////////////////////////////////////////////////////////////////// - public final static OCSPResponseStatus SUCCESSFUL = - new OCSPResponseStatus(0); - public final static OCSPResponseStatus MALFORMED_REQUEST = - new OCSPResponseStatus(1); - public final static OCSPResponseStatus INTERNAL_ERROR = - new OCSPResponseStatus(2); - public final static OCSPResponseStatus TRY_LATER = - new OCSPResponseStatus(3); - public final static OCSPResponseStatus SIG_REQUIRED = - new OCSPResponseStatus(5); - public final static OCSPResponseStatus UNAUTHORIZED = - new OCSPResponseStatus(6); - - private ENUMERATED responseStatus; - - public long getValue() - { - return responseStatus.getValue(); - } - - public OCSPResponseStatus(long val) - { - responseStatus = new ENUMERATED(val); - } - - /////////////////////////////////////////////////////////////////////// - // encoding/decoding - /////////////////////////////////////////////////////////////////////// - - private static final Tag TAG = ENUMERATED.TAG; - - public Tag getTag() - { - return TAG; - } - - public void encode(OutputStream ostream) throws IOException - { - encode(TAG, ostream); - } - - public void encode(Tag implicitTag, OutputStream ostream) - throws IOException - { - responseStatus.encode(implicitTag, ostream); - } - - private static final Template templateInstance = new Template(); - - public static Template getTemplate() { - return templateInstance; - } - - /** - * A Template for decoding an <code>OCSPResponseStatus</code>. - */ - public static class Template implements ASN1Template - { - public boolean tagMatch(Tag tag) - { - return TAG.equals(tag); - } - - public ASN1Value decode(InputStream istream) - throws InvalidBERException, IOException - { - return decode(TAG, istream); - } - - public ASN1Value decode(Tag implicitTag, InputStream istream) - throws InvalidBERException, IOException - { - ENUMERATED.Template enumt = new ENUMERATED.Template(); - ENUMERATED enum1 = (ENUMERATED) enumt.decode(implicitTag, istream); - - return new OCSPResponseStatus(enum1.getValue()); - } - } +public class OCSPResponseStatus implements ASN1Value { + /////////////////////////////////////////////////////////////////////// + // Members and member access + /////////////////////////////////////////////////////////////////////// + public final static OCSPResponseStatus SUCCESSFUL = + new OCSPResponseStatus(0); + public final static OCSPResponseStatus MALFORMED_REQUEST = + new OCSPResponseStatus(1); + public final static OCSPResponseStatus INTERNAL_ERROR = + new OCSPResponseStatus(2); + public final static OCSPResponseStatus TRY_LATER = + new OCSPResponseStatus(3); + public final static OCSPResponseStatus SIG_REQUIRED = + new OCSPResponseStatus(5); + public final static OCSPResponseStatus UNAUTHORIZED = + new OCSPResponseStatus(6); + + private ENUMERATED responseStatus; + + public long getValue() { + return responseStatus.getValue(); + } + + public OCSPResponseStatus(long val) { + responseStatus = new ENUMERATED(val); + } + + /////////////////////////////////////////////////////////////////////// + // encoding/decoding + /////////////////////////////////////////////////////////////////////// + + private static final Tag TAG = ENUMERATED.TAG; + + public Tag getTag() { + return TAG; + } + + public void encode(OutputStream ostream) throws IOException { + encode(TAG, ostream); + } + + public void encode(Tag implicitTag, OutputStream ostream) + throws IOException { + responseStatus.encode(implicitTag, ostream); + } + + private static final Template templateInstance = new Template(); + + public static Template getTemplate() { + return templateInstance; + } + + /** + * A Template for decoding an <code>OCSPResponseStatus</code>. + */ + public static class Template implements ASN1Template { + public boolean tagMatch(Tag tag) { + return TAG.equals(tag); + } + + public ASN1Value decode(InputStream istream) + throws InvalidBERException, IOException { + return decode(TAG, istream); + } + + public ASN1Value decode(Tag implicitTag, InputStream istream) + throws InvalidBERException, IOException { + ENUMERATED.Template enumt = new ENUMERATED.Template(); + ENUMERATED enum1 = (ENUMERATED) enumt.decode(implicitTag, istream); + + return new OCSPResponseStatus(enum1.getValue()); + } + } } diff --git a/pki/base/util/src/com/netscape/cmsutil/ocsp/Request.java b/pki/base/util/src/com/netscape/cmsutil/ocsp/Request.java index 9f277bb96..85c97de22 100644 --- a/pki/base/util/src/com/netscape/cmsutil/ocsp/Request.java +++ b/pki/base/util/src/com/netscape/cmsutil/ocsp/Request.java @@ -31,132 +31,117 @@ import org.mozilla.jss.pkix.cert.Extension; /** * RFC 2560: - * + * * <pre> * Request ::= SEQUENCE { * reqCert CertID, * singleRequestExtensions [0] EXPLICIT Extensions OPTIONAL } * </pre> - * + * * @version $Revision$ $Date$ */ -public class Request implements ASN1Value -{ - /////////////////////////////////////////////////////////////////////// - // members and member access - /////////////////////////////////////////////////////////////////////// - private CertID reqCert = null; - private SEQUENCE singleRequestExtensions = null; - private SEQUENCE sequence = null; - - public CertID getCertID() - { - return reqCert; - } - - public int getExtensionsCount() - { - if(singleRequestExtensions == null) { - return 0; - } else { - return singleRequestExtensions.size(); - } - } - - public Extension getRequestExtensionAt(int index) - { - if(singleRequestExtensions == null) { - throw new ArrayIndexOutOfBoundsException(); - } - return (Extension) singleRequestExtensions.elementAt(index); - } - - public Request(CertID reqCert, SEQUENCE singleRequestExtensions) - { - sequence = new SEQUENCE(); - - this.reqCert = reqCert; - sequence.addElement(reqCert); - - if (singleRequestExtensions != null) { - this.singleRequestExtensions = singleRequestExtensions; - sequence.addElement(singleRequestExtensions); - } - } - - /////////////////////////////////////////////////////////////////////// - // encode / decode - /////////////////////////////////////////////////////////////////////// - private static final Tag TAG = SEQUENCE.TAG; - - public Tag getTag() - { - return TAG; - } - - public void encode(OutputStream ostream) throws IOException - { - encode(TAG, ostream); - } - - public void encode(Tag implicitTag, OutputStream ostream) - throws IOException - { - sequence.encode(implicitTag, ostream); - } - - private static final Template templateInstance = new Template(); - - public static Template getTemplate() - { - return templateInstance; - } - - /** - * A Template for decoding Request. - */ - public static class Template implements ASN1Template - { - - private SEQUENCE.Template seqt; - - public Template() - { - seqt = new SEQUENCE.Template(); - seqt.addElement( CertID.getTemplate() ); - seqt.addOptionalElement(new EXPLICIT.Template(new Tag(0), - new SEQUENCE.OF_Template(new Extension.Template()) )); - } - - public boolean tagMatch(Tag tag) - { - return TAG.equals(tag); - } - - public ASN1Value decode(InputStream istream) - throws InvalidBERException, IOException - { - return decode(TAG, istream); - } - - public ASN1Value decode(Tag implicitTag, InputStream istream) - throws InvalidBERException, IOException - { - SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, istream); - - EXPLICIT tag = (EXPLICIT) seq.elementAt(1); - - if (tag == null) { - return new Request( - (CertID) seq.elementAt(0), - (SEQUENCE) null); - } - else { - return new Request( - (CertID) seq.elementAt(0), - (SEQUENCE) tag.getContent()); - } - } - } +public class Request implements ASN1Value { + /////////////////////////////////////////////////////////////////////// + // members and member access + /////////////////////////////////////////////////////////////////////// + private CertID reqCert = null; + private SEQUENCE singleRequestExtensions = null; + private SEQUENCE sequence = null; + + public CertID getCertID() { + return reqCert; + } + + public int getExtensionsCount() { + if (singleRequestExtensions == null) { + return 0; + } else { + return singleRequestExtensions.size(); + } + } + + public Extension getRequestExtensionAt(int index) { + if (singleRequestExtensions == null) { + throw new ArrayIndexOutOfBoundsException(); + } + return (Extension) singleRequestExtensions.elementAt(index); + } + + public Request(CertID reqCert, SEQUENCE singleRequestExtensions) { + sequence = new SEQUENCE(); + + this.reqCert = reqCert; + sequence.addElement(reqCert); + + if (singleRequestExtensions != null) { + this.singleRequestExtensions = singleRequestExtensions; + sequence.addElement(singleRequestExtensions); + } + } + + /////////////////////////////////////////////////////////////////////// + // encode / decode + /////////////////////////////////////////////////////////////////////// + private static final Tag TAG = SEQUENCE.TAG; + + public Tag getTag() { + return TAG; + } + + public void encode(OutputStream ostream) throws IOException { + encode(TAG, ostream); + } + + public void encode(Tag implicitTag, OutputStream ostream) + throws IOException { + sequence.encode(implicitTag, ostream); + } + + private static final Template templateInstance = new Template(); + + public static Template getTemplate() { + return templateInstance; + } + + /** + * A Template for decoding Request. + */ + public static class Template implements ASN1Template { + + private SEQUENCE.Template seqt; + + public Template() { + seqt = new SEQUENCE.Template(); + seqt.addElement(CertID.getTemplate()); + seqt.addOptionalElement(new EXPLICIT.Template(new Tag(0), + new SEQUENCE.OF_Template(new Extension.Template()))); + } + + public boolean tagMatch(Tag tag) { + return TAG.equals(tag); + } + + public ASN1Value decode(InputStream istream) + throws InvalidBERException, IOException { + return decode(TAG, istream); + } + + public ASN1Value decode(Tag implicitTag, InputStream istream) + throws InvalidBERException, IOException { + SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, istream); + + EXPLICIT tag = (EXPLICIT) seq.elementAt(1); + + if (tag == null) { + return new Request( + (CertID) seq.elementAt(0), + (SEQUENCE) null); + } else { + return new Request( + (CertID) seq.elementAt(0), + (SEQUENCE) tag.getContent()); + } + } + } } diff --git a/pki/base/util/src/com/netscape/cmsutil/ocsp/ResponderID.java b/pki/base/util/src/com/netscape/cmsutil/ocsp/ResponderID.java index d5cfa6807..02e30de05 100644 --- a/pki/base/util/src/com/netscape/cmsutil/ocsp/ResponderID.java +++ b/pki/base/util/src/com/netscape/cmsutil/ocsp/ResponderID.java @@ -19,18 +19,16 @@ package com.netscape.cmsutil.ocsp; import org.mozilla.jss.asn1.ASN1Value; - /** * RFC 2560: - * + * * <pre> * ResponderID ::= CHOICE { * byName [1] EXPLICIT Name, * byKey [2] EXPLICIT KeyHash } * </pre> - * + * * @version $Revision$ $Date$ */ -public interface ResponderID extends ASN1Value -{ +public interface ResponderID extends ASN1Value { } diff --git a/pki/base/util/src/com/netscape/cmsutil/ocsp/Response.java b/pki/base/util/src/com/netscape/cmsutil/ocsp/Response.java index eb011e1c1..0d363e811 100644 --- a/pki/base/util/src/com/netscape/cmsutil/ocsp/Response.java +++ b/pki/base/util/src/com/netscape/cmsutil/ocsp/Response.java @@ -22,14 +22,13 @@ import org.mozilla.jss.asn1.OCTET_STRING; /** * RFC 2560: - * + * * <pre> * response OCTET STRING * </pre> - * + * * @version $Revision$ $Date$ */ -public interface Response extends ASN1Value -{ - public OCTET_STRING getBytes(); +public interface Response extends ASN1Value { + public OCTET_STRING getBytes(); } diff --git a/pki/base/util/src/com/netscape/cmsutil/ocsp/ResponseBytes.java b/pki/base/util/src/com/netscape/cmsutil/ocsp/ResponseBytes.java index b5fed0d9f..c5d461148 100644 --- a/pki/base/util/src/com/netscape/cmsutil/ocsp/ResponseBytes.java +++ b/pki/base/util/src/com/netscape/cmsutil/ocsp/ResponseBytes.java @@ -31,112 +31,100 @@ import org.mozilla.jss.asn1.Tag; /** * RFC 2560: - * + * * <pre> * ResponseBytes ::= SEQUENCE { * responseType OBJECT IDENTIFIER, * response OCTET STRING } * </pre> - * + * * @version $Revision$ $Date$ */ -public class ResponseBytes implements ASN1Value -{ - /////////////////////////////////////////////////////////////////////// - // Members and member access - /////////////////////////////////////////////////////////////////////// - public final static OBJECT_IDENTIFIER OCSP = - new OBJECT_IDENTIFIER("1.3.6.1.5.5.7.48.1"); - public final static OBJECT_IDENTIFIER OCSP_BASIC = - new OBJECT_IDENTIFIER("1.3.6.1.5.5.7.48.1.1"); - - private OBJECT_IDENTIFIER responseType = null; - private OCTET_STRING response = null; - private SEQUENCE sequence; - - public OBJECT_IDENTIFIER getObjectIdentifier() - { - return responseType; - } - - public OCTET_STRING getResponse() - { - return response; - } - - public ResponseBytes(OBJECT_IDENTIFIER responseType, OCTET_STRING response) - { - sequence = new SEQUENCE(); - - this.responseType = responseType; - sequence.addElement(responseType); - - this.response = response; - sequence.addElement(response); - } - - /////////////////////////////////////////////////////////////////////// - // encoding/decoding - /////////////////////////////////////////////////////////////////////// - - private static final Tag TAG = SEQUENCE.TAG; - - public Tag getTag() - { - return TAG; - } - - public void encode(OutputStream ostream) throws IOException - { - encode(TAG, ostream); - } - - public void encode(Tag implicitTag, OutputStream ostream) - throws IOException - { - sequence.encode(implicitTag, ostream); - } - - private static final Template templateInstance = new Template(); - - public static Template getTemplate() { - return templateInstance; - } - - /** - * A Template for decoding <code>ResponseBytes</code>. - */ - public static class Template implements ASN1Template - { - - private SEQUENCE.Template seqt; - - public Template() - { - seqt = new SEQUENCE.Template(); - seqt.addElement( OBJECT_IDENTIFIER.getTemplate() ); - seqt.addElement( OCTET_STRING.getTemplate() ); - } - - public boolean tagMatch(Tag tag) - { - return TAG.equals(tag); - } - - public ASN1Value decode(InputStream istream) - throws InvalidBERException, IOException - { - return decode(TAG, istream); - } - - public ASN1Value decode(Tag implicitTag, InputStream istream) - throws InvalidBERException, IOException - { - SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, istream); - - return new ResponseBytes( - (OBJECT_IDENTIFIER) seq.elementAt(0), - (OCTET_STRING) seq.elementAt(1)); - } - } +public class ResponseBytes implements ASN1Value { + /////////////////////////////////////////////////////////////////////// + // Members and member access + /////////////////////////////////////////////////////////////////////// + public final static OBJECT_IDENTIFIER OCSP = + new OBJECT_IDENTIFIER("1.3.6.1.5.5.7.48.1"); + public final static OBJECT_IDENTIFIER OCSP_BASIC = + new OBJECT_IDENTIFIER("1.3.6.1.5.5.7.48.1.1"); + + private OBJECT_IDENTIFIER responseType = null; + private OCTET_STRING response = null; + private SEQUENCE sequence; + + public OBJECT_IDENTIFIER getObjectIdentifier() { + return responseType; + } + + public OCTET_STRING getResponse() { + return response; + } + + public ResponseBytes(OBJECT_IDENTIFIER responseType, OCTET_STRING response) { + sequence = new SEQUENCE(); + + this.responseType = responseType; + sequence.addElement(responseType); + + this.response = response; + sequence.addElement(response); + } + + /////////////////////////////////////////////////////////////////////// + // encoding/decoding + /////////////////////////////////////////////////////////////////////// + + private static final Tag TAG = SEQUENCE.TAG; + + public Tag getTag() { + return TAG; + } + + public void encode(OutputStream ostream) throws IOException { + encode(TAG, ostream); + } + + public void encode(Tag implicitTag, OutputStream ostream) + throws IOException { + sequence.encode(implicitTag, ostream); + } + + private static final Template templateInstance = new Template(); + + public static Template getTemplate() { + return templateInstance; + } + + /** + * A Template for decoding <code>ResponseBytes</code>. + */ + public static class Template implements ASN1Template { + + private SEQUENCE.Template seqt; + + public Template() { + seqt = new SEQUENCE.Template(); + seqt.addElement(OBJECT_IDENTIFIER.getTemplate()); + seqt.addElement(OCTET_STRING.getTemplate()); + } + + public boolean tagMatch(Tag tag) { + return TAG.equals(tag); + } + + public ASN1Value decode(InputStream istream) + throws InvalidBERException, IOException { + return decode(TAG, istream); + } + + public ASN1Value decode(Tag implicitTag, InputStream istream) + throws InvalidBERException, IOException { + SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, istream); + + return new ResponseBytes( + (OBJECT_IDENTIFIER) seq.elementAt(0), + (OCTET_STRING) seq.elementAt(1)); + } + } } diff --git a/pki/base/util/src/com/netscape/cmsutil/ocsp/ResponseData.java b/pki/base/util/src/com/netscape/cmsutil/ocsp/ResponseData.java index 81c5eee4c..1b28cf134 100644 --- a/pki/base/util/src/com/netscape/cmsutil/ocsp/ResponseData.java +++ b/pki/base/util/src/com/netscape/cmsutil/ocsp/ResponseData.java @@ -35,7 +35,7 @@ import org.mozilla.jss.pkix.cert.Extension; /** * RFC 2560: - * + * * <pre> * ResponseData ::= SEQUENCE { * version [0] EXPLICIT Version DEFAULT v1, @@ -44,13 +44,12 @@ import org.mozilla.jss.pkix.cert.Extension; * responses SEQUENCE OF SingleResponse, * responseExtensions [1] EXPLICIT Extensions OPTIONAL } * </pre> - * + * * @version $Revision$ $Date$ */ -public class ResponseData implements ASN1Value -{ +public class ResponseData implements ASN1Value { private static final INTEGER v1 = new INTEGER(0); - private INTEGER mVer; + private INTEGER mVer; private ResponderID mRID = null; private GeneralizedTime mProduced = null; private SingleResponse mSR[] = null; @@ -58,7 +57,7 @@ public class ResponseData implements ASN1Value private static final Tag TAG = SEQUENCE.TAG; - public ResponseData(INTEGER ver, ResponderID rid, GeneralizedTime produced, + public ResponseData(INTEGER ver, ResponderID rid, GeneralizedTime produced, SingleResponse sr[], Extension exts[]) { mVer = (ver != null) ? ver : v1; mRID = rid; @@ -67,30 +66,25 @@ public class ResponseData implements ASN1Value mExts = exts; } - public ResponseData(ResponderID rid, GeneralizedTime produced, - SingleResponse sr[]) - { + public ResponseData(ResponderID rid, GeneralizedTime produced, + SingleResponse sr[]) { this(v1, rid, produced, sr, null); } - public ResponseData(ResponderID rid, GeneralizedTime produced, - SingleResponse sr[], Extension exts[]) - { + public ResponseData(ResponderID rid, GeneralizedTime produced, + SingleResponse sr[], Extension exts[]) { this(v1, rid, produced, sr, exts); } - - public Tag getTag() - { + + public Tag getTag() { return TAG; } - public void encode(OutputStream os) throws IOException - { + public void encode(OutputStream os) throws IOException { encode(null, os); } - public void encode(Tag t, OutputStream os) throws IOException - { + public void encode(Tag t, OutputStream os) throws IOException { SEQUENCE seq = new SEQUENCE(); if (mVer != v1) { @@ -116,35 +110,29 @@ public class ResponseData implements ASN1Value } else { seq.encode(t, os); } - } + } - public ResponderID getResponderID() - { + public ResponderID getResponderID() { return mRID; } - public GeneralizedTime getProducedAt() - { + public GeneralizedTime getProducedAt() { return mProduced; } - public int getResponseCount() - { + public int getResponseCount() { return (mSR != null) ? mSR.length : 0; } - public SingleResponse getResponseAt(int pos) - { + public SingleResponse getResponseAt(int pos) { return (mSR != null) ? mSR[pos] : null; } - public int getResponseExtensionCount() - { - return (mExts != null) ? mExts.length : 0; + public int getResponseExtensionCount() { + return (mExts != null) ? mExts.length : 0; } - public Extension getResponseExtensionAt(int pos) - { + public Extension getResponseExtensionAt(int pos) { return (mExts != null) ? mExts[pos] : null; } @@ -157,67 +145,62 @@ public class ResponseData implements ASN1Value /** * A Template for decoding <code>ResponseBytes</code>. */ - public static class Template implements ASN1Template - { + public static class Template implements ASN1Template { private SEQUENCE.Template seqt; - public Template() - { - seqt = new SEQUENCE.Template(); - seqt.addOptionalElement(new EXPLICIT.Template( - new Tag (0), new INTEGER.Template()) ); - seqt.addElement(new ANY.Template() ); - seqt.addElement(new GeneralizedTime.Template() ); + public Template() { + seqt = new SEQUENCE.Template(); + seqt.addOptionalElement(new EXPLICIT.Template( + new Tag(0), new INTEGER.Template())); + seqt.addElement(new ANY.Template()); + seqt.addElement(new GeneralizedTime.Template()); seqt.addElement(new SEQUENCE.OF_Template( - SingleResponse.getTemplate())); + SingleResponse.getTemplate())); seqt.addOptionalElement(new EXPLICIT.Template( - new Tag(1), new SEQUENCE.OF_Template( - Extension.getTemplate()))); + new Tag(1), new SEQUENCE.OF_Template( + Extension.getTemplate()))); } - public boolean tagMatch(Tag tag) - { + public boolean tagMatch(Tag tag) { return TAG.equals(tag); } public ASN1Value decode(InputStream istream) - throws InvalidBERException, IOException - { + throws InvalidBERException, IOException { return decode(TAG, istream); } public ASN1Value decode(Tag implicitTag, InputStream istream) - throws InvalidBERException, IOException - { - SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, - istream); + throws InvalidBERException, IOException { + SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, + istream); INTEGER ver = v1; - EXPLICIT e_ver = (EXPLICIT)seq.elementAt(0); + EXPLICIT e_ver = (EXPLICIT) seq.elementAt(0); if (e_ver != null && e_ver.getTag().getNum() == 0) { - ver = (INTEGER)e_ver.getContent(); + ver = (INTEGER) e_ver.getContent(); } ResponderID rid = null; - ANY e_rid = (ANY)seq.elementAt(1); + ANY e_rid = (ANY) seq.elementAt(1); if (e_rid.getTag().getNum() == 1) { // name id - rid = (NameID) - NameID.getTemplate().decode(e_rid.getTag(), - new ByteArrayInputStream(e_rid.getEncoded())); + rid = (NameID) + NameID.getTemplate().decode(e_rid.getTag(), + new ByteArrayInputStream(e_rid.getEncoded())); } else if (e_rid.getTag().getNum() == 2) { // key hash id rid = (KeyHashID) - KeyHashID.getTemplate().decode(e_rid.getTag(), - new ByteArrayInputStream(e_rid.getEncoded())); + KeyHashID.getTemplate().decode(e_rid.getTag(), + new ByteArrayInputStream(e_rid.getEncoded())); } - GeneralizedTime producedAt = (GeneralizedTime) seq.elementAt(2); - SEQUENCE responses = (SEQUENCE)seq.elementAt(3); + GeneralizedTime producedAt = (GeneralizedTime) seq.elementAt(2); + SEQUENCE responses = (SEQUENCE) seq.elementAt(3); SingleResponse sr[] = null; - if ((responses != null) && (responses.size() > 0)) { + if ((responses != null) && (responses.size() > 0)) { sr = new SingleResponse[responses.size()]; for (int i = 0; i < responses.size(); i++) { - sr[i] = (SingleResponse)responses.elementAt(i); + sr[i] = (SingleResponse) responses.elementAt(i); } } @@ -226,14 +209,14 @@ public class ResponseData implements ASN1Value SEQUENCE extns_seq; Extension[] extns_array = null; if (extns_exp != null) { - extns_seq = (SEQUENCE)extns_exp.getContent(); + extns_seq = (SEQUENCE) extns_exp.getContent(); extns_array = new Extension[extns_seq.size()]; - for (int x=0;x<extns_array.length;x++) { + for (int x = 0; x < extns_array.length; x++) { extns_array[x] = (Extension) extns_seq.elementAt(x); } } return new ResponseData(ver, rid, producedAt, sr, extns_array); - } - } + } + } } diff --git a/pki/base/util/src/com/netscape/cmsutil/ocsp/RevokedInfo.java b/pki/base/util/src/com/netscape/cmsutil/ocsp/RevokedInfo.java index b1b7489f5..9b0b2d186 100644 --- a/pki/base/util/src/com/netscape/cmsutil/ocsp/RevokedInfo.java +++ b/pki/base/util/src/com/netscape/cmsutil/ocsp/RevokedInfo.java @@ -32,94 +32,82 @@ import org.mozilla.jss.asn1.Tag; /** * RFC 2560: - * + * * <pre> * RevokedInfo ::= SEQUENCE { * revocationTime GeneralizedTime, * revocationReason [0] EXPLICIT CRLReason OPTIONAL } * </pre> - * + * * @version $Revision$ $Date$ */ -public class RevokedInfo implements CertStatus -{ - private static final Tag TAG = SEQUENCE.TAG; +public class RevokedInfo implements CertStatus { + private static final Tag TAG = SEQUENCE.TAG; - private GeneralizedTime mRevokedAt; + private GeneralizedTime mRevokedAt; - public RevokedInfo(GeneralizedTime revokedAt) - { - mRevokedAt = revokedAt; - } + public RevokedInfo(GeneralizedTime revokedAt) { + mRevokedAt = revokedAt; + } - public Tag getTag() - { - return Tag.get(1); - } + public Tag getTag() { + return Tag.get(1); + } - public void encode(Tag t, OutputStream os) throws IOException - { - SEQUENCE seq = new SEQUENCE(); - seq.addElement(mRevokedAt); - seq.encode(t, os); - } + public void encode(Tag t, OutputStream os) throws IOException { + SEQUENCE seq = new SEQUENCE(); + seq.addElement(mRevokedAt); + seq.encode(t, os); + } - public void encode(OutputStream os) throws IOException - { - encode(getTag(), os); - } - - public GeneralizedTime getRevocationTime() - { - return mRevokedAt; - } + public void encode(OutputStream os) throws IOException { + encode(getTag(), os); + } + + public GeneralizedTime getRevocationTime() { + return mRevokedAt; + } + + private static final Template templateInstance = new Template(); + + public static Template getTemplate() { + return templateInstance; + } + /** + * A Template for decoding <code>ResponseBytes</code>. + */ + public static class Template implements ASN1Template { - private static final Template templateInstance = new Template(); + private SEQUENCE.Template seqt; + + public Template() { + seqt = new SEQUENCE.Template(); + seqt.addElement(new GeneralizedTime.Template()); + seqt.addOptionalElement( + new EXPLICIT.Template(new Tag(0), + new INTEGER.Template())); + + } + + public boolean tagMatch(Tag tag) { + return TAG.equals(tag); + } - public static Template getTemplate() { - return templateInstance; + public ASN1Value decode(InputStream istream) + throws InvalidBERException, IOException { + return decode(TAG, istream); } - /** - * A Template for decoding <code>ResponseBytes</code>. - */ - public static class Template implements ASN1Template - { - - private SEQUENCE.Template seqt; - - public Template() - { - seqt = new SEQUENCE.Template(); - seqt.addElement(new GeneralizedTime.Template() ); - seqt.addOptionalElement( - new EXPLICIT.Template( new Tag(0), - new INTEGER.Template()) ); - - } - - public boolean tagMatch(Tag tag) - { - return TAG.equals(tag); - } - - public ASN1Value decode(InputStream istream) - throws InvalidBERException, IOException - { - return decode(TAG, istream); - } - - public ASN1Value decode(Tag implicitTag, InputStream istream) - throws InvalidBERException, IOException - { - SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, + public ASN1Value decode(Tag implicitTag, InputStream istream) + throws InvalidBERException, IOException { + SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, istream); - GeneralizedTime revokedAt = (GeneralizedTime) - seq.elementAt(0); - return new RevokedInfo(revokedAt); + GeneralizedTime revokedAt = (GeneralizedTime) + seq.elementAt(0); + return new RevokedInfo(revokedAt); - } } + } } diff --git a/pki/base/util/src/com/netscape/cmsutil/ocsp/Signature.java b/pki/base/util/src/com/netscape/cmsutil/ocsp/Signature.java index d670dfe23..b9b192aee 100644 --- a/pki/base/util/src/com/netscape/cmsutil/ocsp/Signature.java +++ b/pki/base/util/src/com/netscape/cmsutil/ocsp/Signature.java @@ -33,142 +33,127 @@ import org.mozilla.jss.pkix.primitive.AlgorithmIdentifier; /** * RFC 2560: - * + * * <pre> * Signature ::= SEQUENCE { * signatureAlgorithm AlgorithmIdentifier, * signature BIT STRING, * certs [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL } * </pre> - * + * * @version $Revision$ $Date$ */ -public class Signature implements ASN1Value -{ - /////////////////////////////////////////////////////////////////////// - // Members and member access - /////////////////////////////////////////////////////////////////////// - private AlgorithmIdentifier signatureAlgorithm; - private BIT_STRING signature; - private SEQUENCE certs; - private SEQUENCE sequence; - - public AlgorithmIdentifier getSignatureAlgorithm() - { - return signatureAlgorithm; - } - - public BIT_STRING getSignature() - { - return signature; - } - - public int getCertificateCount() - { - if(certs == null) { - return 0; - } else { - return certs.size(); - } - } - - public Certificate getCertificateAt(int index) - { - if(certs == null) { - throw new ArrayIndexOutOfBoundsException(); - } - return (Certificate) certs.elementAt(index); - } - - public Signature(AlgorithmIdentifier signatureAlgorithm, - BIT_STRING signature, SEQUENCE certs) - { - sequence = new SEQUENCE(); - - this.signatureAlgorithm = signatureAlgorithm; - sequence.addElement(signatureAlgorithm); - - this.signature = signature; - sequence.addElement(signature); - - this.certs = certs; - sequence.addElement(certs); - } - - /////////////////////////////////////////////////////////////////////// - // encode / decode - /////////////////////////////////////////////////////////////////////// - private static final Tag TAG = SEQUENCE.TAG; - - public Tag getTag() - { - return TAG; - } - - public void encode(OutputStream ostream) throws IOException - { - encode(TAG, ostream); - } - - public void encode(Tag implicitTag, OutputStream ostream) - throws IOException - { - sequence.encode(implicitTag, ostream); - } - - private static final Template templateInstance = new Template(); - - public static Template getTemplate() - { - return templateInstance; - } - - /** - * A Template for decoding Request. - */ - public static class Template implements ASN1Template - { - - private SEQUENCE.Template seqt; - - public Template() - { - seqt = new SEQUENCE.Template(); - seqt.addElement( AlgorithmIdentifier.getTemplate() ); - seqt.addElement( BIT_STRING.getTemplate() ); - seqt.addOptionalElement( - new EXPLICIT.Template( - new Tag(0), - new SEQUENCE.OF_Template( new Certificate.Template()) - ) - ); - } - - public boolean tagMatch(Tag tag) - { - return TAG.equals(tag); - } - - public ASN1Value decode(InputStream istream) - throws InvalidBERException, IOException - { - return decode(TAG, istream); - } - - public ASN1Value decode(Tag implicitTag, InputStream istream) - throws InvalidBERException, IOException - { - SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, istream); - SEQUENCE certs=null; - if( seq.elementAt(2) != null ) { - certs = (SEQUENCE) ((EXPLICIT)seq.elementAt(2)).getContent(); - } - - return new Signature( - (AlgorithmIdentifier) seq.elementAt(0), - (BIT_STRING) seq.elementAt(1), - certs); - } - } +public class Signature implements ASN1Value { + /////////////////////////////////////////////////////////////////////// + // Members and member access + /////////////////////////////////////////////////////////////////////// + private AlgorithmIdentifier signatureAlgorithm; + private BIT_STRING signature; + private SEQUENCE certs; + private SEQUENCE sequence; + + public AlgorithmIdentifier getSignatureAlgorithm() { + return signatureAlgorithm; + } + + public BIT_STRING getSignature() { + return signature; + } + + public int getCertificateCount() { + if (certs == null) { + return 0; + } else { + return certs.size(); + } + } + + public Certificate getCertificateAt(int index) { + if (certs == null) { + throw new ArrayIndexOutOfBoundsException(); + } + return (Certificate) certs.elementAt(index); + } + + public Signature(AlgorithmIdentifier signatureAlgorithm, + BIT_STRING signature, SEQUENCE certs) { + sequence = new SEQUENCE(); + + this.signatureAlgorithm = signatureAlgorithm; + sequence.addElement(signatureAlgorithm); + + this.signature = signature; + sequence.addElement(signature); + + this.certs = certs; + sequence.addElement(certs); + } + + /////////////////////////////////////////////////////////////////////// + // encode / decode + /////////////////////////////////////////////////////////////////////// + private static final Tag TAG = SEQUENCE.TAG; + + public Tag getTag() { + return TAG; + } + + public void encode(OutputStream ostream) throws IOException { + encode(TAG, ostream); + } + + public void encode(Tag implicitTag, OutputStream ostream) + throws IOException { + sequence.encode(implicitTag, ostream); + } + + private static final Template templateInstance = new Template(); + + public static Template getTemplate() { + return templateInstance; + } + + /** + * A Template for decoding Request. + */ + public static class Template implements ASN1Template { + + private SEQUENCE.Template seqt; + + public Template() { + seqt = new SEQUENCE.Template(); + seqt.addElement(AlgorithmIdentifier.getTemplate()); + seqt.addElement(BIT_STRING.getTemplate()); + seqt.addOptionalElement( + new EXPLICIT.Template( + new Tag(0), + new SEQUENCE.OF_Template(new Certificate.Template()) + ) + ); + } + + public boolean tagMatch(Tag tag) { + return TAG.equals(tag); + } + + public ASN1Value decode(InputStream istream) + throws InvalidBERException, IOException { + return decode(TAG, istream); + } + + public ASN1Value decode(Tag implicitTag, InputStream istream) + throws InvalidBERException, IOException { + SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, istream); + SEQUENCE certs = null; + if (seq.elementAt(2) != null) { + certs = (SEQUENCE) ((EXPLICIT) seq.elementAt(2)).getContent(); + } + + return new Signature( + (AlgorithmIdentifier) seq.elementAt(0), + (BIT_STRING) seq.elementAt(1), + certs); + } + } } diff --git a/pki/base/util/src/com/netscape/cmsutil/ocsp/SingleResponse.java b/pki/base/util/src/com/netscape/cmsutil/ocsp/SingleResponse.java index 1ce727471..ab54e5019 100644 --- a/pki/base/util/src/com/netscape/cmsutil/ocsp/SingleResponse.java +++ b/pki/base/util/src/com/netscape/cmsutil/ocsp/SingleResponse.java @@ -34,7 +34,7 @@ import org.mozilla.jss.pkix.cert.Extension; /** * RFC 2560: - * + * * <pre> * SingleResponse ::= SEQUENCE { * certID CertID, @@ -43,157 +43,140 @@ import org.mozilla.jss.pkix.cert.Extension; * nextUpdate [0] EXPLICIT GeneralizedTime OPTIONAL, * singleExtensions [1] EXPLICIT Extensions OPTIONAL } * </pre> - * + * * @version $Revision$ $Date$ */ -public class SingleResponse implements ASN1Value -{ - private CertID mCID = null; - private CertStatus mStatus = null; - private GeneralizedTime mThisUpdate = null; - private GeneralizedTime mNextUpdate = null; - - private static final Tag TAG = SEQUENCE.TAG; - - public SingleResponse(CertID cid, CertStatus s, - GeneralizedTime thisUpdate, GeneralizedTime nextUpdate) - { - mCID = cid; - mStatus = s; - mThisUpdate = thisUpdate; - mNextUpdate = nextUpdate; - } - - public CertID getCertID() - { - return mCID; - } - - public Tag getTag() - { - return null; - } - - public void encode(Tag t, OutputStream os) throws IOException - { - SEQUENCE seq = new SEQUENCE(); - seq.addElement(mCID); - seq.addElement(mStatus); - seq.addElement(mThisUpdate); - if (mNextUpdate != null) - { - seq.addElement(new EXPLICIT(Tag.get(0), mNextUpdate)); - } - if (t == null) { - seq.encode(os); - } else { - seq.encode(t, os); - } - } - - public void encode(OutputStream os) throws IOException - { - encode(null, os); - } - - public CertStatus getCertStatus() - { - return mStatus; - } - - public GeneralizedTime getThisUpdate() - { - return mThisUpdate; - } - - public GeneralizedTime getNextUpdate() - { - return mNextUpdate; - } - - public int getExtensionCount() - { - return 0; - } - - public Extension getExtensionAt(int pos) - { - return null; - } - - private static final Template templateInstance = new Template(); - - public static Template getTemplate() { - return templateInstance; +public class SingleResponse implements ASN1Value { + private CertID mCID = null; + private CertStatus mStatus = null; + private GeneralizedTime mThisUpdate = null; + private GeneralizedTime mNextUpdate = null; + + private static final Tag TAG = SEQUENCE.TAG; + + public SingleResponse(CertID cid, CertStatus s, + GeneralizedTime thisUpdate, GeneralizedTime nextUpdate) { + mCID = cid; + mStatus = s; + mThisUpdate = thisUpdate; + mNextUpdate = nextUpdate; + } + + public CertID getCertID() { + return mCID; + } + + public Tag getTag() { + return null; + } + + public void encode(Tag t, OutputStream os) throws IOException { + SEQUENCE seq = new SEQUENCE(); + seq.addElement(mCID); + seq.addElement(mStatus); + seq.addElement(mThisUpdate); + if (mNextUpdate != null) { + seq.addElement(new EXPLICIT(Tag.get(0), mNextUpdate)); } + if (t == null) { + seq.encode(os); + } else { + seq.encode(t, os); + } + } + + public void encode(OutputStream os) throws IOException { + encode(null, os); + } + + public CertStatus getCertStatus() { + return mStatus; + } + + public GeneralizedTime getThisUpdate() { + return mThisUpdate; + } + + public GeneralizedTime getNextUpdate() { + return mNextUpdate; + } + + public int getExtensionCount() { + return 0; + } + + public Extension getExtensionAt(int pos) { + return null; + } + + private static final Template templateInstance = new Template(); + + public static Template getTemplate() { + return templateInstance; + } - /** - * A Template for decoding <code>ResponseBytes</code>. - */ - public static class Template implements ASN1Template - { - - private SEQUENCE.Template seqt; - - public Template() - { - seqt = new SEQUENCE.Template(); - seqt.addElement(new CertID.Template() ); - seqt.addElement(new ANY.Template() ); - seqt.addElement(new GeneralizedTime.Template() ); - seqt.addOptionalElement(new EXPLICIT.Template( + /** + * A Template for decoding <code>ResponseBytes</code>. + */ + public static class Template implements ASN1Template { + + private SEQUENCE.Template seqt; + + public Template() { + seqt = new SEQUENCE.Template(); + seqt.addElement(new CertID.Template()); + seqt.addElement(new ANY.Template()); + seqt.addElement(new GeneralizedTime.Template()); + seqt.addOptionalElement(new EXPLICIT.Template( new Tag(0), new GeneralizedTime.Template())); - seqt.addOptionalElement(new EXPLICIT.Template(new Tag(1), + seqt.addOptionalElement(new EXPLICIT.Template(new Tag(1), new SEQUENCE.OF_Template(new Extension.Template()))); - } - - public boolean tagMatch(Tag tag) - { - return TAG.equals(tag); - } - - public ASN1Value decode(InputStream istream) - throws InvalidBERException, IOException - { - return decode(TAG, istream); - } - - public ASN1Value decode(Tag implicitTag, InputStream istream) - throws InvalidBERException, IOException - { - SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, - istream); - - CertID cid = (CertID)seq.elementAt(0); - CertStatus status = null; - ANY e_status = (ANY)seq.elementAt(1); - if (e_status.getTag().getNum() == 0) { - status = (GoodInfo) + } + + public boolean tagMatch(Tag tag) { + return TAG.equals(tag); + } + + public ASN1Value decode(InputStream istream) + throws InvalidBERException, IOException { + return decode(TAG, istream); + } + + public ASN1Value decode(Tag implicitTag, InputStream istream) + throws InvalidBERException, IOException { + SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, + istream); + + CertID cid = (CertID) seq.elementAt(0); + CertStatus status = null; + ANY e_status = (ANY) seq.elementAt(1); + if (e_status.getTag().getNum() == 0) { + status = (GoodInfo) GoodInfo.getTemplate().decode( - e_status.getTag(), - new ByteArrayInputStream(e_status.getEncoded())); - // good - } else if (e_status.getTag().getNum() == 1) { - // revoked - status = (RevokedInfo) + e_status.getTag(), + new ByteArrayInputStream(e_status.getEncoded())); + // good + } else if (e_status.getTag().getNum() == 1) { + // revoked + status = (RevokedInfo) RevokedInfo.getTemplate().decode( - e_status.getTag(), - new ByteArrayInputStream(e_status.getEncoded())); - } else if (e_status.getTag().getNum() == 2) { - // unknown - status = (UnknownInfo) + e_status.getTag(), + new ByteArrayInputStream(e_status.getEncoded())); + } else if (e_status.getTag().getNum() == 2) { + // unknown + status = (UnknownInfo) UnknownInfo.getTemplate().decode( - e_status.getTag(), - new ByteArrayInputStream(e_status.getEncoded())); - } - GeneralizedTime thisUpdate = (GeneralizedTime) - seq.elementAt(2); - GeneralizedTime nextUpdate = null; + e_status.getTag(), + new ByteArrayInputStream(e_status.getEncoded())); + } + GeneralizedTime thisUpdate = (GeneralizedTime) + seq.elementAt(2); + GeneralizedTime nextUpdate = null; - return new SingleResponse(cid, status, thisUpdate, - nextUpdate); + return new SingleResponse(cid, status, thisUpdate, + nextUpdate); - } } + } } diff --git a/pki/base/util/src/com/netscape/cmsutil/ocsp/TBSRequest.java b/pki/base/util/src/com/netscape/cmsutil/ocsp/TBSRequest.java index ea23200db..b7f706edb 100644 --- a/pki/base/util/src/com/netscape/cmsutil/ocsp/TBSRequest.java +++ b/pki/base/util/src/com/netscape/cmsutil/ocsp/TBSRequest.java @@ -33,7 +33,7 @@ import org.mozilla.jss.pkix.cert.Extension; /** * RFC 2560: - * + * * <pre> * TBSRequest ::= SEQUENCE { * version [0] EXPLICIT Version DEFAULT v1, @@ -41,33 +41,29 @@ import org.mozilla.jss.pkix.cert.Extension; * requestList SEQUENCE OF Request, * requestExtensions [2] EXPLICIT Extensions OPTIONAL } * </pre> - * + * * @version $Revision$ $Date$ */ -public class TBSRequest implements ASN1Value -{ +public class TBSRequest implements ASN1Value { /////////////////////////////////////////////////////////////////////// // members and member access /////////////////////////////////////////////////////////////////////// - private static final INTEGER v1 = new INTEGER (0); + private static final INTEGER v1 = new INTEGER(0); private INTEGER version; private ANY requestorName; private SEQUENCE requestList; private SEQUENCE requestExtensions; - public INTEGER getVersion() - { + public INTEGER getVersion() { return version; } - public ANY getRequestorName() - { + public ANY getRequestorName() { return requestorName; - } + } - public int getRequestCount() - { + public int getRequestCount() { if (requestList == null) { return 0; } else { @@ -75,13 +71,11 @@ public class TBSRequest implements ASN1Value } } - public Request getRequestAt(int index) - { + public Request getRequestAt(int index) { return (Request) requestList.elementAt(index); } - public int getExtensionsCount() - { + public int getExtensionsCount() { if (requestExtensions == null) { return 0; } else { @@ -89,18 +83,16 @@ public class TBSRequest implements ASN1Value } } - public Extension getRequestExtensionAt(int index) - { + public Extension getRequestExtensionAt(int index) { return (Extension) requestExtensions.elementAt(index); } /////////////////////////////////////////////////////////////////////// // constructors /////////////////////////////////////////////////////////////////////// - + public TBSRequest(INTEGER version, ANY requestorName, - SEQUENCE requestList, SEQUENCE requestExtensions) - { + SEQUENCE requestList, SEQUENCE requestExtensions) { this.version = (version != null) ? version : v1; this.requestorName = requestorName; this.requestList = requestList; @@ -112,20 +104,17 @@ public class TBSRequest implements ASN1Value /////////////////////////////////////////////////////////////////////// public static final Tag TAG = SEQUENCE.TAG; - public Tag getTag() - { + public Tag getTag() { return TAG; } public void encode(OutputStream ostream) - throws IOException - { + throws IOException { encode(TAG, ostream); } public void encode(Tag implicitTag, OutputStream ostream) - throws IOException - { + throws IOException { SEQUENCE seq = new SEQUENCE(); if (version != v1) { @@ -150,52 +139,46 @@ public class TBSRequest implements ASN1Value private static final Template templateInstance = new Template(); - public static Template getTemplate() - { + public static Template getTemplate() { return templateInstance; } /** * A Template for decoding TBSRequest. */ - public static class Template implements ASN1Template - { + public static class Template implements ASN1Template { private SEQUENCE.Template seqt; - public Template() - { + public Template() { seqt = new SEQUENCE.Template(); seqt.addElement( - new EXPLICIT.Template( - new Tag(0), new INTEGER.Template()), - new EXPLICIT( new Tag(0), new INTEGER(0)) - ); + new EXPLICIT.Template( + new Tag(0), new INTEGER.Template()), + new EXPLICIT(new Tag(0), new INTEGER(0)) + ); seqt.addOptionalElement( - new EXPLICIT.Template( - new Tag (1), new ANY.Template()) ); - seqt.addElement( new SEQUENCE.OF_Template(new Request.Template()) ); + new EXPLICIT.Template( + new Tag(1), new ANY.Template())); + seqt.addElement(new SEQUENCE.OF_Template(new Request.Template())); seqt.addOptionalElement(new EXPLICIT.Template(new Tag(2), - new SEQUENCE.OF_Template(new Extension.Template())) ); + new SEQUENCE.OF_Template(new Extension.Template()))); } - public boolean tagMatch(Tag tag) - { + public boolean tagMatch(Tag tag) { return TAG.equals(tag); } public ASN1Value decode(InputStream istream) - throws InvalidBERException, IOException - { + throws InvalidBERException, IOException { return decode(TAG, istream); } public ASN1Value decode(Tag implicitTag, InputStream istream) - throws InvalidBERException, IOException - { + throws InvalidBERException, IOException { SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, istream); - INTEGER v = v1; //assume default version + INTEGER v = v1; //assume default version EXPLICIT e_ver = (EXPLICIT) seq.elementAt(0); if (e_ver != null) { v = (INTEGER) e_ver.getContent(); @@ -212,16 +195,16 @@ public class TBSRequest implements ASN1Value EXPLICIT exts = (EXPLICIT) seq.elementAt(3); SEQUENCE exts_seq; if (exts != null) { - exts_seq = (SEQUENCE)exts.getContent(); + exts_seq = (SEQUENCE) exts.getContent(); } else { exts_seq = null; } return new TBSRequest( - v, - requestorname, - (SEQUENCE) seq.elementAt(2), - exts_seq); + v, + requestorname, + (SEQUENCE) seq.elementAt(2), + exts_seq); } } } diff --git a/pki/base/util/src/com/netscape/cmsutil/ocsp/UnknownInfo.java b/pki/base/util/src/com/netscape/cmsutil/ocsp/UnknownInfo.java index d9891f5a5..1fe4ea743 100644 --- a/pki/base/util/src/com/netscape/cmsutil/ocsp/UnknownInfo.java +++ b/pki/base/util/src/com/netscape/cmsutil/ocsp/UnknownInfo.java @@ -30,76 +30,66 @@ import org.mozilla.jss.asn1.Tag; /** * RFC 2560: - * + * * <pre> * UnknownInfo ::= NULL -- this can be replaced with an enumeration * </pre> - * + * * @version $Revision$ $Date$ */ -public class UnknownInfo implements CertStatus -{ - private static final Tag TAG = SEQUENCE.TAG; +public class UnknownInfo implements CertStatus { + private static final Tag TAG = SEQUENCE.TAG; - public UnknownInfo() - { - } + public UnknownInfo() { + } - public Tag getTag() - { - return Tag.get(2); - } + public Tag getTag() { + return Tag.get(2); + } - public void encode(Tag t, OutputStream os) throws IOException - { - NULL.getInstance().encode(getTag(), os); - } + public void encode(Tag t, OutputStream os) throws IOException { + NULL.getInstance().encode(getTag(), os); + } - public void encode(OutputStream os) throws IOException - { - encode(getTag(), os); - } + public void encode(OutputStream os) throws IOException { + encode(getTag(), os); + } - private static final Template templateInstance = new Template(); + private static final Template templateInstance = new Template(); - public static Template getTemplate() { - return templateInstance; - } + public static Template getTemplate() { + return templateInstance; + } - /** - * A Template for decoding <code>ResponseBytes</code>. - */ - public static class Template implements ASN1Template - { + /** + * A Template for decoding <code>ResponseBytes</code>. + */ + public static class Template implements ASN1Template { - private SEQUENCE.Template seqt; + private SEQUENCE.Template seqt; - public Template() - { -// seqt = new SEQUENCE.Template(); - // seqt.addElement(new NULL.Template() ); + public Template() { + // seqt = new SEQUENCE.Template(); + // seqt.addElement(new NULL.Template() ); - } + } - public boolean tagMatch(Tag tag) - { - return TAG.equals(tag); - } + public boolean tagMatch(Tag tag) { + return TAG.equals(tag); + } - public ASN1Value decode(InputStream istream) - throws InvalidBERException, IOException - { - return decode(TAG, istream); - } + public ASN1Value decode(InputStream istream) + throws InvalidBERException, IOException { + return decode(TAG, istream); + } - public ASN1Value decode(Tag implicitTag, InputStream istream) - throws InvalidBERException, IOException - { - // SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, - // istream); + public ASN1Value decode(Tag implicitTag, InputStream istream) + throws InvalidBERException, IOException { + // SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, + // istream); - return new UnknownInfo(); + return new UnknownInfo(); - } } + } } diff --git a/pki/base/util/src/com/netscape/cmsutil/password/IPasswordReader.java b/pki/base/util/src/com/netscape/cmsutil/password/IPasswordReader.java index 1a6a026ba..357ae0a6c 100644 --- a/pki/base/util/src/com/netscape/cmsutil/password/IPasswordReader.java +++ b/pki/base/util/src/com/netscape/cmsutil/password/IPasswordReader.java @@ -16,11 +16,14 @@ // All rights reserved. // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.password; + import java.io.IOException; import java.util.Enumeration; public interface IPasswordReader { public void init(String pwdPath) throws IOException; + public String getPassword(String tag); + public Enumeration getTags(); } diff --git a/pki/base/util/src/com/netscape/cmsutil/password/IPasswordStore.java b/pki/base/util/src/com/netscape/cmsutil/password/IPasswordStore.java index 3d7a8d80c..f2e9293d3 100644 --- a/pki/base/util/src/com/netscape/cmsutil/password/IPasswordStore.java +++ b/pki/base/util/src/com/netscape/cmsutil/password/IPasswordStore.java @@ -22,9 +22,13 @@ import java.util.Enumeration; public interface IPasswordStore { public void init(String pwdPath) throws IOException; + public String getPassword(String tag); + public Enumeration getTags(); + public Object putPassword(String tag, String password); + public void commit() - throws IOException, ClassCastException, NullPointerException; + throws IOException, ClassCastException, NullPointerException; } diff --git a/pki/base/util/src/com/netscape/cmsutil/password/IPasswordWriter.java b/pki/base/util/src/com/netscape/cmsutil/password/IPasswordWriter.java index 2f42e02cb..c9f9691e7 100644 --- a/pki/base/util/src/com/netscape/cmsutil/password/IPasswordWriter.java +++ b/pki/base/util/src/com/netscape/cmsutil/password/IPasswordWriter.java @@ -16,12 +16,15 @@ // All rights reserved. // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.password; + import java.io.IOException; public interface IPasswordWriter { public void init(String pwdPath) - throws IOException;; + throws IOException;; + public Object putPassword(String tag, String password); + public void commit() - throws IOException, ClassCastException, NullPointerException; + throws IOException, ClassCastException, NullPointerException; } diff --git a/pki/base/util/src/com/netscape/cmsutil/password/PlainPasswordFile.java b/pki/base/util/src/com/netscape/cmsutil/password/PlainPasswordFile.java index c9cec1df6..c962e1c6e 100644 --- a/pki/base/util/src/com/netscape/cmsutil/password/PlainPasswordFile.java +++ b/pki/base/util/src/com/netscape/cmsutil/password/PlainPasswordFile.java @@ -23,7 +23,7 @@ import java.io.IOException; import java.util.Enumeration; import java.util.Properties; -public class PlainPasswordFile implements IPasswordStore{ +public class PlainPasswordFile implements IPasswordStore { private String mPwdPath = ""; private Properties mPwdStore; private static final String PASSWORD_WRITER_HEADER = ""; @@ -32,24 +32,23 @@ public class PlainPasswordFile implements IPasswordStore{ } public void init(String pwdPath) - throws IOException - { - mPwdStore = new Properties(); - // initialize mPwdStore - mPwdPath = pwdPath; + throws IOException { + mPwdStore = new Properties(); + // initialize mPwdStore + mPwdPath = pwdPath; - FileInputStream file = new FileInputStream(mPwdPath); - mPwdStore.load(file); - file.close(); + FileInputStream file = new FileInputStream(mPwdPath); + mPwdStore.load(file); + file.close(); } public String getPassword(String tag) { - return (String) mPwdStore.getProperty(tag); + return (String) mPwdStore.getProperty(tag); } // return an array of String-based tag public Enumeration getTags() { - return mPwdStore.propertyNames(); + return mPwdStore.propertyNames(); } public Object putPassword(String tag, String password) { @@ -57,8 +56,7 @@ public class PlainPasswordFile implements IPasswordStore{ } public void commit() - throws IOException, ClassCastException, NullPointerException - { + throws IOException, ClassCastException, NullPointerException { FileOutputStream file = new FileOutputStream(mPwdPath); mPwdStore.store(file, PASSWORD_WRITER_HEADER); file.close(); diff --git a/pki/base/util/src/com/netscape/cmsutil/password/PlainPasswordReader.java b/pki/base/util/src/com/netscape/cmsutil/password/PlainPasswordReader.java index 27a39cb6f..4065fd72c 100644 --- a/pki/base/util/src/com/netscape/cmsutil/password/PlainPasswordReader.java +++ b/pki/base/util/src/com/netscape/cmsutil/password/PlainPasswordReader.java @@ -22,7 +22,7 @@ import java.io.IOException; import java.util.Enumeration; import java.util.Properties; -public class PlainPasswordReader implements IPasswordReader{ +public class PlainPasswordReader implements IPasswordReader { private String mPwdPath = ""; private Properties mPwdStore; @@ -30,24 +30,23 @@ public class PlainPasswordReader implements IPasswordReader{ } public void init(String pwdPath) - throws IOException - { - mPwdStore = new Properties(); - // initialize mPwdStore - mPwdPath = pwdPath; - mPwdStore = new Properties(); + throws IOException { + mPwdStore = new Properties(); + // initialize mPwdStore + mPwdPath = pwdPath; + mPwdStore = new Properties(); - FileInputStream file = new FileInputStream(mPwdPath); - mPwdStore.load(file); - file.close(); + FileInputStream file = new FileInputStream(mPwdPath); + mPwdStore.load(file); + file.close(); } public String getPassword(String tag) { - return (String) mPwdStore.getProperty(tag); + return (String) mPwdStore.getProperty(tag); } // return an array of String-based tag public Enumeration getTags() { - return mPwdStore.propertyNames(); + return mPwdStore.propertyNames(); } } diff --git a/pki/base/util/src/com/netscape/cmsutil/password/PlainPasswordWriter.java b/pki/base/util/src/com/netscape/cmsutil/password/PlainPasswordWriter.java index 0cd29a181..3ceac4bd6 100644 --- a/pki/base/util/src/com/netscape/cmsutil/password/PlainPasswordWriter.java +++ b/pki/base/util/src/com/netscape/cmsutil/password/PlainPasswordWriter.java @@ -22,7 +22,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.util.Properties; -public class PlainPasswordWriter implements IPasswordWriter{ +public class PlainPasswordWriter implements IPasswordWriter { private static final String PASSWORD_WRITER_HEADER = ""; private String mPwdPath = ""; private Properties mPwdStore; @@ -31,28 +31,26 @@ public class PlainPasswordWriter implements IPasswordWriter{ } public void init(String pwdPath) - throws IOException - { - mPwdStore = new Properties(); - // initialize mPwdStore - mPwdPath = pwdPath; - mPwdStore = new Properties(); - - FileInputStream file = new FileInputStream(mPwdPath); - mPwdStore.load(file); - file.close(); + throws IOException { + mPwdStore = new Properties(); + // initialize mPwdStore + mPwdPath = pwdPath; + mPwdStore = new Properties(); + + FileInputStream file = new FileInputStream(mPwdPath); + mPwdStore.load(file); + file.close(); } public Object putPassword(String tag, String password) { - return mPwdStore.setProperty(tag, password); + return mPwdStore.setProperty(tag, password); } public void commit() - throws IOException, ClassCastException, NullPointerException - { - FileOutputStream file = new FileOutputStream(mPwdPath); - mPwdStore.store(file, PASSWORD_WRITER_HEADER); - file.close(); + throws IOException, ClassCastException, NullPointerException { + FileOutputStream file = new FileOutputStream(mPwdPath); + mPwdStore.store(file, PASSWORD_WRITER_HEADER); + file.close(); } } diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/AccessAccept.java b/pki/base/util/src/com/netscape/cmsutil/radius/AccessAccept.java index c5f9828c1..4824c885f 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/AccessAccept.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/AccessAccept.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class AccessAccept extends ServerPacket { public AccessAccept(byte data[]) throws IOException { super(data); diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/AccessChallenge.java b/pki/base/util/src/com/netscape/cmsutil/radius/AccessChallenge.java index bab34ffe9..c06f809b1 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/AccessChallenge.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/AccessChallenge.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class AccessChallenge extends ServerPacket { public AccessChallenge(byte data[]) throws IOException { super(data); diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/AccessReject.java b/pki/base/util/src/com/netscape/cmsutil/radius/AccessReject.java index 12081a6b9..5f32ef349 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/AccessReject.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/AccessReject.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class AccessReject extends ServerPacket { public AccessReject(byte data[]) throws IOException { super(data); diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/AccessRequest.java b/pki/base/util/src/com/netscape/cmsutil/radius/AccessRequest.java index 5075f9325..7856b0cc8 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/AccessRequest.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/AccessRequest.java @@ -17,9 +17,6 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - - - public class AccessRequest extends NASPacket { public AccessRequest(short id, Authenticator auth) { super(ACCESS_REQUEST, id, auth); diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/Attribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/Attribute.java index 33c1f3929..5e79816e4 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/Attribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/Attribute.java @@ -17,13 +17,11 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.ByteArrayOutputStream; import java.io.IOException; - public abstract class Attribute { - public static final int USER_NAME = 1; + public static final int USER_NAME = 1; public static final int USER_PASSWORD = 2; public static final int CHAP_PASSWORD = 3; public static final int NAS_IP_ADDRESS = 4; @@ -81,12 +79,12 @@ public abstract class Attribute { return _t; } - public abstract byte[] getValue() - throws IOException; + public abstract byte[] getValue() + throws IOException; - public byte[] getData() - throws IOException { - ByteArrayOutputStream attrOS = new ByteArrayOutputStream(); + public byte[] getData() + throws IOException { + ByteArrayOutputStream attrOS = new ByteArrayOutputStream(); attrOS.write(_t); // type byte value[] = getValue(); diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/AttributeFactory.java b/pki/base/util/src/com/netscape/cmsutil/radius/AttributeFactory.java index bf2369721..021c06720 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/AttributeFactory.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/AttributeFactory.java @@ -17,13 +17,11 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class AttributeFactory { public static Attribute createAttribute(byte data[]) - throws IOException { + throws IOException { switch (data[0] & 0xFF) { case Attribute.USER_NAME: // 1 return new UserNameAttribute(data); diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/AttributeSet.java b/pki/base/util/src/com/netscape/cmsutil/radius/AttributeSet.java index e79b96f7c..46860de19 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/AttributeSet.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/AttributeSet.java @@ -17,11 +17,9 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.util.Enumeration; import java.util.Vector; - public class AttributeSet { private Vector _attrs = new Vector(); diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/Authenticator.java b/pki/base/util/src/com/netscape/cmsutil/radius/Authenticator.java index 3236d9b65..008af489a 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/Authenticator.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/Authenticator.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public abstract class Authenticator { public abstract byte[] getData() throws IOException; } diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/CHAPChallengeAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/CHAPChallengeAttribute.java index 8b2655c2e..cd715a031 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/CHAPChallengeAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/CHAPChallengeAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class CHAPChallengeAttribute extends Attribute { private String _str = null; diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/CHAPPasswordAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/CHAPPasswordAttribute.java index 90ebea144..3f0ef1793 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/CHAPPasswordAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/CHAPPasswordAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class CHAPPasswordAttribute extends Attribute { private byte _value[] = null; private int _ident = 0; diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/CallbackIdAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/CallbackIdAttribute.java index 894ae9c89..5fd806003 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/CallbackIdAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/CallbackIdAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class CallbackIdAttribute extends Attribute { private byte _value[] = null; private String _str = null; diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/CallbackNumberAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/CallbackNumberAttribute.java index 96e4af79e..d6e45cecd 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/CallbackNumberAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/CallbackNumberAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class CallbackNumberAttribute extends Attribute { private byte _value[] = null; private String _str = null; diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/CallerStationIdAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/CallerStationIdAttribute.java index 05e4836d6..3b5eec804 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/CallerStationIdAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/CallerStationIdAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class CallerStationIdAttribute extends Attribute { private byte _value[] = null; private String _str = null; diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/CallingStationIdAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/CallingStationIdAttribute.java index b1f77b694..9a57f8089 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/CallingStationIdAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/CallingStationIdAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class CallingStationIdAttribute extends Attribute { private byte _value[] = null; private String _str = null; diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/ChallengeException.java b/pki/base/util/src/com/netscape/cmsutil/radius/ChallengeException.java index de1222a3b..b05801181 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/ChallengeException.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/ChallengeException.java @@ -17,9 +17,6 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - - - public class ChallengeException extends Exception { /** * diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/FilterIdAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/FilterIdAttribute.java index c8d9abf8e..879d7d5c7 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/FilterIdAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/FilterIdAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class FilterIdAttribute extends Attribute { private byte _value[] = null; private String _str = null; diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/FramedAppleTalkLinkAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/FramedAppleTalkLinkAttribute.java index 2176fbc02..05273780f 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/FramedAppleTalkLinkAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/FramedAppleTalkLinkAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class FramedAppleTalkLinkAttribute extends Attribute { public static int UN_NUMBERED = 0; diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/FramedAppleTalkNetworkAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/FramedAppleTalkNetworkAttribute.java index 6ea0c05ff..cea0d936a 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/FramedAppleTalkNetworkAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/FramedAppleTalkNetworkAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class FramedAppleTalkNetworkAttribute extends Attribute { private byte _value[] = null; private int _type = 0; diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/FramedAppleTalkZoneAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/FramedAppleTalkZoneAttribute.java index 3ea8c654f..54ee47c45 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/FramedAppleTalkZoneAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/FramedAppleTalkZoneAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class FramedAppleTalkZoneAttribute extends Attribute { private byte _value[] = null; private String _str = null; diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/FramedCompressionAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/FramedCompressionAttribute.java index cf21b9fda..b57c030b5 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/FramedCompressionAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/FramedCompressionAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class FramedCompressionAttribute extends Attribute { public static final int NONE = 1; public static final int VJ_TCP_IP_HEADER = 2; @@ -33,9 +31,9 @@ public class FramedCompressionAttribute extends Attribute { public FramedCompressionAttribute(byte value[]) { super(); _t = FRAMED_COMPRESSION; - _type = value[5] & 0xFF; - _type |= ((value[4] << 8) & 0xFF00); - _type |= ((value[3] << 16) & 0xFF0000); + _type = value[5] & 0xFF; + _type |= ((value[4] << 8) & 0xFF00); + _type |= ((value[3] << 16) & 0xFF0000); _type |= ((value[2] << 24) & 0xFF000000); _value = value; } diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/FramedIPAddressAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/FramedIPAddressAttribute.java index 1fac0a3f0..2f66ee8c2 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/FramedIPAddressAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/FramedIPAddressAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class FramedIPAddressAttribute extends Attribute { private byte _value[] = null; private byte _addr[] = new byte[4]; @@ -28,10 +26,10 @@ public class FramedIPAddressAttribute extends Attribute { public FramedIPAddressAttribute(byte value[]) { super(); _t = FRAMED_IP_ADDRESS; - _addr[0] = value[2]; - _addr[1] = value[3]; - _addr[2] = value[4]; - _addr[3] = value[5]; + _addr[0] = value[2]; + _addr[1] = value[3]; + _addr[2] = value[4]; + _addr[3] = value[5]; _value = value; } diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/FramedIPNetmaskAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/FramedIPNetmaskAttribute.java index 9350fac11..f8e1980c7 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/FramedIPNetmaskAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/FramedIPNetmaskAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class FramedIPNetmaskAttribute extends Attribute { private byte _value[] = null; private byte _mask[] = new byte[4]; diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/FramedIPXNetworkAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/FramedIPXNetworkAttribute.java index 900c46c00..92f47eec1 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/FramedIPXNetworkAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/FramedIPXNetworkAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class FramedIPXNetworkAttribute extends Attribute { private byte _value[] = null; private byte _net[] = new byte[4]; diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/FramedMTUAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/FramedMTUAttribute.java index b3a362337..5cd9551a2 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/FramedMTUAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/FramedMTUAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class FramedMTUAttribute extends Attribute { private byte _value[] = null; private int _type = 0; diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/FramedProtocolAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/FramedProtocolAttribute.java index 1acee4ce7..5af219b9a 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/FramedProtocolAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/FramedProtocolAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class FramedProtocolAttribute extends Attribute { public static final int PPP = 1; public static final int SLIP = 2; @@ -35,9 +33,9 @@ public class FramedProtocolAttribute extends Attribute { public FramedProtocolAttribute(byte value[]) { super(); _t = SERVICE_TYPE; - _type = value[5] & 0xFF; - _type |= ((value[4] << 8) & 0xFF00); - _type |= ((value[3] << 16) & 0xFF0000); + _type = value[5] & 0xFF; + _type |= ((value[4] << 8) & 0xFF00); + _type |= ((value[3] << 16) & 0xFF0000); _type |= ((value[2] << 24) & 0xFF000000); _value = value; } diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/FramedRouteAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/FramedRouteAttribute.java index bc49adb06..9b123fe2a 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/FramedRouteAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/FramedRouteAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class FramedRouteAttribute extends Attribute { private byte _value[] = null; private String _str = null; diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/FramedRoutingAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/FramedRoutingAttribute.java index 1ea4e334f..14d2b0cc8 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/FramedRoutingAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/FramedRoutingAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class FramedRoutingAttribute extends Attribute { public static final int NONE = 0; public static final int SEND_ROUTING_PACKETS = 1; diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/GenericAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/GenericAttribute.java index c368a2712..ac1798ae3 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/GenericAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/GenericAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class GenericAttribute extends Attribute { private byte _value[] = null; diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/IdleTimeoutAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/IdleTimeoutAttribute.java index 38b45a6c8..44b0c5087 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/IdleTimeoutAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/IdleTimeoutAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class IdleTimeoutAttribute extends Attribute { private int _timeout = 0; diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/LoginIPHostAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/LoginIPHostAttribute.java index 7bfe179ff..0d1c0565a 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/LoginIPHostAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/LoginIPHostAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class LoginIPHostAttribute extends Attribute { public static final int NAS_ALLOW_SELECT = 0xFFFFFFFF; public static final int NAS_SELECT = 0; diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/LoginLATGroupAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/LoginLATGroupAttribute.java index 93a507661..4cee6bc3a 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/LoginLATGroupAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/LoginLATGroupAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class LoginLATGroupAttribute extends Attribute { private byte _value[] = null; private String _str = null; diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/LoginLATNodeAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/LoginLATNodeAttribute.java index 38b4b315f..2c2d3411e 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/LoginLATNodeAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/LoginLATNodeAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class LoginLATNodeAttribute extends Attribute { private byte _value[] = null; private String _str = null; diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/LoginLATPortAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/LoginLATPortAttribute.java index 056b0fc43..330161ec8 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/LoginLATPortAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/LoginLATPortAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class LoginLATPortAttribute extends Attribute { private byte _value[] = null; private String _str = null; diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/LoginLATServiceAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/LoginLATServiceAttribute.java index 7409a83a4..158630d27 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/LoginLATServiceAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/LoginLATServiceAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class LoginLATServiceAttribute extends Attribute { private byte _value[] = null; private String _str = null; diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/LoginServiceAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/LoginServiceAttribute.java index 88f5623be..73f49d39f 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/LoginServiceAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/LoginServiceAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class LoginServiceAttribute extends Attribute { public static final int TELNET = 0; public static final int RLOGIN = 1; diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/LoginTCPPortAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/LoginTCPPortAttribute.java index 0c924f695..6b44f50c6 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/LoginTCPPortAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/LoginTCPPortAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class LoginTCPPortAttribute extends Attribute { private int _port = 0; @@ -43,12 +41,12 @@ public class LoginTCPPortAttribute extends Attribute { } public byte[] getValue() throws IOException { - byte[] p = new byte[4]; + byte[] p = new byte[4]; - p[0] = (byte) ((_port >>> 24) & 0xFF); - p[1] = (byte) ((_port >>> 16) & 0xFF); - p[2] = (byte) ((_port >>> 8) & 0xFF); - p[3] = (byte) (_port & 0xFF); + p[0] = (byte) ((_port >>> 24) & 0xFF); + p[1] = (byte) ((_port >>> 16) & 0xFF); + p[2] = (byte) ((_port >>> 8) & 0xFF); + p[3] = (byte) (_port & 0xFF); return p; } } diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/NASClassAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/NASClassAttribute.java index ba644f201..57b983028 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/NASClassAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/NASClassAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class NASClassAttribute extends Attribute { private byte _value[] = null; private String _str = null; diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/NASIPAddressAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/NASIPAddressAttribute.java index 42dc1a19b..d4022b3dd 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/NASIPAddressAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/NASIPAddressAttribute.java @@ -17,11 +17,9 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; import java.net.InetAddress; - public class NASIPAddressAttribute extends Attribute { private InetAddress _ip = null; private byte _value[] = null; diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/NASIdentifierAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/NASIdentifierAttribute.java index 99917cac7..0a3a62cd8 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/NASIdentifierAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/NASIdentifierAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class NASIdentifierAttribute extends Attribute { private byte _value[] = null; private String _str = null; diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/NASPacket.java b/pki/base/util/src/com/netscape/cmsutil/radius/NASPacket.java index b270eadde..70d143989 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/NASPacket.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/NASPacket.java @@ -17,11 +17,9 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.ByteArrayOutputStream; import java.io.IOException; - public abstract class NASPacket extends Packet { public NASPacket(int c, short id, Authenticator auth) { super(c, id, auth); diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/NASPortAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/NASPortAttribute.java index 949fa4759..0f7b31e75 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/NASPortAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/NASPortAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class NASPortAttribute extends Attribute { private int _port = 0; @@ -39,12 +37,12 @@ public class NASPortAttribute extends Attribute { } public byte[] getValue() throws IOException { - byte[] p = new byte[4]; + byte[] p = new byte[4]; - p[0] = (byte) ((_port >>> 24) & 0xFF); - p[1] = (byte) ((_port >>> 16) & 0xFF); - p[2] = (byte) ((_port >>> 8) & 0xFF); - p[3] = (byte) (_port & 0xFF); + p[0] = (byte) ((_port >>> 24) & 0xFF); + p[1] = (byte) ((_port >>> 16) & 0xFF); + p[2] = (byte) ((_port >>> 8) & 0xFF); + p[3] = (byte) (_port & 0xFF); return p; } } diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/NASPortTypeAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/NASPortTypeAttribute.java index ca7cf7b09..84ccc3ae1 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/NASPortTypeAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/NASPortTypeAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class NASPortTypeAttribute extends Attribute { public static final int ASYNC = 0; public static final int SYNC = 1; diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/Packet.java b/pki/base/util/src/com/netscape/cmsutil/radius/Packet.java index 4af445639..4fad0ba79 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/Packet.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/Packet.java @@ -17,17 +17,14 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - - - public abstract class Packet { - public static final int ACCESS_REQUEST = 1; - public static final int ACCESS_ACCEPT = 2; - public static final int ACCESS_REJECT = 3; + public static final int ACCESS_REQUEST = 1; + public static final int ACCESS_ACCEPT = 2; + public static final int ACCESS_REJECT = 3; // public static final int ACCOUNTING_REQUEST = 4; // public static final int ACCOUNTING_RESPONSE = 5; public static final int ACCESS_CHALLENGE = 11; - public static final int RESERVED = 255; + public static final int RESERVED = 255; protected int _c = 0; protected short _id = 0; diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/PacketFactory.java b/pki/base/util/src/com/netscape/cmsutil/radius/PacketFactory.java index c9dd1620a..8d2e20e74 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/PacketFactory.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/PacketFactory.java @@ -17,13 +17,11 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class PacketFactory { public static ServerPacket createServerPacket(byte data[]) - throws IOException { + throws IOException { switch (data[0] & 0xFF) { case Packet.ACCESS_ACCEPT: return new AccessAccept(data); diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/PortLimitAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/PortLimitAttribute.java index 602603cb6..7903bb1fd 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/PortLimitAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/PortLimitAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class PortLimitAttribute extends Attribute { private int _port = 0; diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/ProxyStateAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/ProxyStateAttribute.java index ef04ae0ca..83831b652 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/ProxyStateAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/ProxyStateAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class ProxyStateAttribute extends Attribute { private byte _value[] = null; private String _str = null; diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/RadiusConn.java b/pki/base/util/src/com/netscape/cmsutil/radius/RadiusConn.java index 1c09ea2c4..b22807a5d 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/RadiusConn.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/RadiusConn.java @@ -17,7 +17,6 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; import java.io.InterruptedIOException; import java.net.DatagramPacket; @@ -28,7 +27,6 @@ import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.util.Properties; - /** * This class implements RFC2865 - Remote Authentication Dial In * User Service (RADIUS), June 2000. @@ -52,20 +50,20 @@ public class RadiusConn { private int _maxRetries = MAX_RETRIES; private SecureRandom _rand = null; - public RadiusConn(String host1, String host2, int port, String secret, - int timeout) throws SocketException { + public RadiusConn(String host1, String host2, int port, String secret, + int timeout) throws SocketException { this(host1, port, host2, port, secret, timeout, null, null); } public RadiusConn(String host, int port, String secret, byte seed[], - Properties options) - throws SocketException { + Properties options) + throws SocketException { this(host, port, host, port, secret, DEFAULT_TIMEOUT, seed, options); } - public RadiusConn(String host1, int port1, String host2, int port2, - String secret, int timeout, byte seed[], Properties options) - throws SocketException { + public RadiusConn(String host1, int port1, String host2, int port2, + String secret, int timeout, byte seed[], Properties options) + throws SocketException { _host[0] = host1; _port[0] = port1; _host[1] = host2; @@ -73,7 +71,7 @@ public class RadiusConn { _selected = 0; _secret = secret; _options = options; - _socket = new DatagramSocket(); + _socket = new DatagramSocket(); _socket.setSoTimeout(timeout * 1000); if (seed == null) { _rand = new SecureRandom(); @@ -86,8 +84,8 @@ public class RadiusConn { _socket.disconnect(); } - public void authenticate(String name, String password) - throws IOException, NoSuchAlgorithmException, + public void authenticate(String name, String password) + throws IOException, NoSuchAlgorithmException, RejectException, ChallengeException { int retries = 0; Packet res = null; @@ -104,7 +102,7 @@ public class RadiusConn { send(req, _host[_selected], _port[_selected]); try { retries++; - res = receive(); + res = receive(); if (res instanceof AccessReject) { throw new RejectException((AccessReject) res); } else if (res instanceof AccessChallenge) { @@ -121,24 +119,23 @@ public class RadiusConn { } // throw e; } - + } - } - while (res == null); + } while (res == null); } public void replyChallenge(String password, ChallengeException ce) - throws IOException, NoSuchAlgorithmException, + throws IOException, NoSuchAlgorithmException, RejectException, ChallengeException { replyChallenge(null, password, ce); } - public void replyChallenge(String name, String password, - ChallengeException ce) - throws IOException, NoSuchAlgorithmException, + public void replyChallenge(String name, String password, + ChallengeException ce) + throws IOException, NoSuchAlgorithmException, RejectException, ChallengeException { StateAttribute state = (StateAttribute) - ce.getAttributeSet().getAttributeByType(Attribute.STATE); + ce.getAttributeSet().getAttributeByType(Attribute.STATE); if (state == null) throw new IOException("State not found in challenge"); @@ -154,7 +151,7 @@ public class RadiusConn { req.addAttribute(new NASPortAttribute(_socket.getLocalPort())); send(req, _host[_selected], _port[_selected]); - Packet res = receive(); + Packet res = receive(); if (res instanceof AccessReject) { throw new RejectException((AccessReject) res); @@ -164,7 +161,7 @@ public class RadiusConn { } public void replyChallenge(String name, String password, String state) - throws IOException, NoSuchAlgorithmException, + throws IOException, NoSuchAlgorithmException, RejectException, ChallengeException { if (state == null) throw new IOException("State not found in challenge"); @@ -178,7 +175,7 @@ public class RadiusConn { req.addAttribute(new NASPortAttribute(_socket.getLocalPort())); send(req, _host[_selected], _port[_selected]); - Packet res = receive(); + Packet res = receive(); if (res instanceof AccessReject) { throw new RejectException((AccessReject) res); @@ -192,12 +189,12 @@ public class RadiusConn { } private void send(NASPacket packet, String host, int port) - throws IOException { - DatagramPacket dp = new DatagramPacket(new byte[4096], 4096); + throws IOException { + DatagramPacket dp = new DatagramPacket(new byte[4096], 4096); - dp.setPort(port); - dp.setAddress(InetAddress.getByName(host)); - byte data[] = packet.getData(); + dp.setPort(port); + dp.setAddress(InetAddress.getByName(host)); + byte data[] = packet.getData(); dp.setLength(data.length); dp.setData(data); @@ -207,10 +204,10 @@ public class RadiusConn { } private ServerPacket receive() - throws IOException { - DatagramPacket dp = new DatagramPacket(new byte[4096], 4096); + throws IOException { + DatagramPacket dp = new DatagramPacket(new byte[4096], 4096); - _socket.receive(dp); + _socket.receive(dp); byte data[] = dp.getData(); ServerPacket p = PacketFactory.createServerPacket(data); diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/RejectException.java b/pki/base/util/src/com/netscape/cmsutil/radius/RejectException.java index d80b045e3..1c4e7bea9 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/RejectException.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/RejectException.java @@ -17,9 +17,6 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - - - public class RejectException extends Exception { /** * @@ -37,5 +34,5 @@ public class RejectException extends Exception { public String getReplyMessage() { return ((ReplyMessageAttribute) (_res.getAttributeSet().getAttributeByType(Attribute.REPLY_MESSAGE))).getString(); - } + } } diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/ReplyMessageAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/ReplyMessageAttribute.java index 094a51730..5ec4ea052 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/ReplyMessageAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/ReplyMessageAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class ReplyMessageAttribute extends Attribute { private byte _value[] = null; private String _str = null; diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/RequestAuthenticator.java b/pki/base/util/src/com/netscape/cmsutil/radius/RequestAuthenticator.java index 108b51451..5d82752dd 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/RequestAuthenticator.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/RequestAuthenticator.java @@ -17,18 +17,16 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; - public class RequestAuthenticator extends Authenticator { private byte _ra[] = null; - public RequestAuthenticator(SecureRandom rand, String secret) - throws NoSuchAlgorithmException { + public RequestAuthenticator(SecureRandom rand, String secret) + throws NoSuchAlgorithmException { byte[] authenticator = new byte[16]; rand.nextBytes(authenticator); diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/ResponseAuthenticator.java b/pki/base/util/src/com/netscape/cmsutil/radius/ResponseAuthenticator.java index 93fd46c39..3c3de33c4 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/ResponseAuthenticator.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/ResponseAuthenticator.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class ResponseAuthenticator extends Authenticator { private byte _data[] = null; diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/ServerPacket.java b/pki/base/util/src/com/netscape/cmsutil/radius/ServerPacket.java index abbe255fc..f7d7fa302 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/ServerPacket.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/ServerPacket.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public abstract class ServerPacket extends Packet { public ServerPacket(byte data[]) throws IOException { super(); @@ -41,8 +39,8 @@ public abstract class ServerPacket extends Packet { int attrLen = (data[startp + 1] & 0xFF); byte attrData[] = new byte[attrLen]; - System.arraycopy(data, startp, attrData, 0, attrData.length); - addAttribute(AttributeFactory.createAttribute(attrData)); + System.arraycopy(data, startp, attrData, 0, attrData.length); + addAttribute(AttributeFactory.createAttribute(attrData)); startp += attrData.length; } } diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/ServiceTypeAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/ServiceTypeAttribute.java index 7ab143f79..f31c74f9a 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/ServiceTypeAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/ServiceTypeAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class ServiceTypeAttribute extends Attribute { public static final int LOGIN = 1; public static final int FRAMED = 2; @@ -40,9 +38,9 @@ public class ServiceTypeAttribute extends Attribute { public ServiceTypeAttribute(byte value[]) { super(); _t = SERVICE_TYPE; - _type = value[5] & 0xFF; - _type |= ((value[4] << 8) & 0xFF00); - _type |= ((value[3] << 16) & 0xFF0000); + _type = value[5] & 0xFF; + _type |= ((value[4] << 8) & 0xFF00); + _type |= ((value[3] << 16) & 0xFF0000); _type |= ((value[2] << 24) & 0xFF000000); _value = value; } diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/SessionTimeoutAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/SessionTimeoutAttribute.java index fcbf69425..2809aee4b 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/SessionTimeoutAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/SessionTimeoutAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class SessionTimeoutAttribute extends Attribute { private int _timeout = 0; @@ -39,12 +37,12 @@ public class SessionTimeoutAttribute extends Attribute { } public byte[] getValue() throws IOException { - byte[] p = new byte[4]; + byte[] p = new byte[4]; - p[0] = (byte) ((_timeout >>> 24) & 0xFF); - p[1] = (byte) ((_timeout >>> 16) & 0xFF); - p[2] = (byte) ((_timeout >>> 8) & 0xFF); - p[3] = (byte) (_timeout & 0xFF); + p[0] = (byte) ((_timeout >>> 24) & 0xFF); + p[1] = (byte) ((_timeout >>> 16) & 0xFF); + p[2] = (byte) ((_timeout >>> 8) & 0xFF); + p[3] = (byte) (_timeout & 0xFF); return p; } } diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/StateAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/StateAttribute.java index 4408819a6..027f95620 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/StateAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/StateAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class StateAttribute extends Attribute { private byte _value[] = null; private String _str = null; diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/TerminationActionAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/TerminationActionAttribute.java index 67f214adf..b47a70d8c 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/TerminationActionAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/TerminationActionAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class TerminationActionAttribute extends Attribute { public static final int DEFAULT = 0; public static final int RADIUS_REQUEST = 1; diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/UserNameAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/UserNameAttribute.java index ccc715e54..af7ce6bbe 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/UserNameAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/UserNameAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class UserNameAttribute extends Attribute { private String _name = null; diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/UserPasswordAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/UserPasswordAttribute.java index 938652e09..31c27cdfd 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/UserPasswordAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/UserPasswordAttribute.java @@ -17,12 +17,10 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; - public class UserPasswordAttribute extends Attribute { private Authenticator _ra = null; private String _secret = null; @@ -43,7 +41,7 @@ public class UserPasswordAttribute extends Attribute { MessageDigest md5 = null; try { - md5 = MessageDigest.getInstance("MD5"); + md5 = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { throw new IOException(e.getMessage()); } @@ -57,7 +55,7 @@ public class UserPasswordAttribute extends Attribute { for (int i = 0; i < ret.length; i++) { if ((i % 16) == 0) { - md5.reset(); + md5.reset(); md5.update(_secret.getBytes()); } if (i < up.length) { diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/VendorSpecificAttribute.java b/pki/base/util/src/com/netscape/cmsutil/radius/VendorSpecificAttribute.java index e3f174160..5f3d9f170 100644 --- a/pki/base/util/src/com/netscape/cmsutil/radius/VendorSpecificAttribute.java +++ b/pki/base/util/src/com/netscape/cmsutil/radius/VendorSpecificAttribute.java @@ -17,10 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.radius; - import java.io.IOException; - public class VendorSpecificAttribute extends Attribute { private byte _value[] = null; private String _id = null; diff --git a/pki/base/util/src/com/netscape/cmsutil/scep/CRSPKIMessage.java b/pki/base/util/src/com/netscape/cmsutil/scep/CRSPKIMessage.java index 16406e2a7..cc5ee43f8 100644 --- a/pki/base/util/src/com/netscape/cmsutil/scep/CRSPKIMessage.java +++ b/pki/base/util/src/com/netscape/cmsutil/scep/CRSPKIMessage.java @@ -17,7 +17,6 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.scep; - import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.CharConversionException; @@ -49,70 +48,69 @@ import org.mozilla.jss.pkix.cert.Certificate; import org.mozilla.jss.pkix.cert.CertificateInfo; import org.mozilla.jss.pkix.primitive.AlgorithmIdentifier; - public class CRSPKIMessage { - + // OIDs for authenticated attributes - public static OBJECT_IDENTIFIER CRS_MESSAGETYPE = - new OBJECT_IDENTIFIER(new long[] {2, 16, 840, 1, 113733, 1, 9, 2} - ); - public static OBJECT_IDENTIFIER CRS_PKISTATUS = - new OBJECT_IDENTIFIER(new long[] {2, 16, 840, 1, 113733, 1, 9, 3} - ); - public static OBJECT_IDENTIFIER CRS_FAILINFO = - new OBJECT_IDENTIFIER(new long[] {2, 16, 840, 1, 113733, 1, 9, 4} - ); - public static OBJECT_IDENTIFIER CRS_SENDERNONCE = - new OBJECT_IDENTIFIER(new long[] {2, 16, 840, 1, 113733, 1, 9, 5} - ); - public static OBJECT_IDENTIFIER CRS_RECIPIENTNONCE = - new OBJECT_IDENTIFIER(new long[] {2, 16, 840, 1, 113733, 1, 9, 6} - ); - public static OBJECT_IDENTIFIER CRS_TRANSID = - new OBJECT_IDENTIFIER(new long[] {2, 16, 840, 1, 113733, 1, 9, 7} - ); + public static OBJECT_IDENTIFIER CRS_MESSAGETYPE = + new OBJECT_IDENTIFIER(new long[] { 2, 16, 840, 1, 113733, 1, 9, 2 } + ); + public static OBJECT_IDENTIFIER CRS_PKISTATUS = + new OBJECT_IDENTIFIER(new long[] { 2, 16, 840, 1, 113733, 1, 9, 3 } + ); + public static OBJECT_IDENTIFIER CRS_FAILINFO = + new OBJECT_IDENTIFIER(new long[] { 2, 16, 840, 1, 113733, 1, 9, 4 } + ); + public static OBJECT_IDENTIFIER CRS_SENDERNONCE = + new OBJECT_IDENTIFIER(new long[] { 2, 16, 840, 1, 113733, 1, 9, 5 } + ); + public static OBJECT_IDENTIFIER CRS_RECIPIENTNONCE = + new OBJECT_IDENTIFIER(new long[] { 2, 16, 840, 1, 113733, 1, 9, 6 } + ); + public static OBJECT_IDENTIFIER CRS_TRANSID = + new OBJECT_IDENTIFIER(new long[] { 2, 16, 840, 1, 113733, 1, 9, 7 } + ); public static OBJECT_IDENTIFIER CRS_EXTENSIONREQ = - new OBJECT_IDENTIFIER(new long[] {2, 16, 840, 1, 113733, 1, 9, 8} - ); - + new OBJECT_IDENTIFIER(new long[] { 2, 16, 840, 1, 113733, 1, 9, 8 } + ); + // PKCS9 defined OIDs public static OBJECT_IDENTIFIER PKCS9_CONTENT_TYPE = - new OBJECT_IDENTIFIER(new long[] {1, 2, 840, 113549, 1, 9, 3} - ); + new OBJECT_IDENTIFIER(new long[] { 1, 2, 840, 113549, 1, 9, 3 } + ); public static OBJECT_IDENTIFIER PKCS9_MESSAGE_DIGEST = - new OBJECT_IDENTIFIER(new long[] {1, 2, 840, 113549, 1, 9, 4} - ); + new OBJECT_IDENTIFIER(new long[] { 1, 2, 840, 113549, 1, 9, 4 } + ); /* PKCS 1 - rsaEncryption */ public static OBJECT_IDENTIFIER RSA_ENCRYPTION = - new OBJECT_IDENTIFIER(new long[] {1, 2, 840, 113549, 1, 1, 1} - ); - + new OBJECT_IDENTIFIER(new long[] { 1, 2, 840, 113549, 1, 1, 1 } + ); + public static OBJECT_IDENTIFIER DES_CBC_ENCRYPTION = - new OBJECT_IDENTIFIER(new long[] {1, 3, 14, 3, 2, 7} - ); + new OBJECT_IDENTIFIER(new long[] { 1, 3, 14, 3, 2, 7 } + ); public static OBJECT_IDENTIFIER DES_EDE3_CBC_ENCRYPTION = - new OBJECT_IDENTIFIER(new long[] {1, 2, 840, 113549, 3, 7} - ); + new OBJECT_IDENTIFIER(new long[] { 1, 2, 840, 113549, 3, 7 } + ); - public static OBJECT_IDENTIFIER MD5_DIGEST = - new OBJECT_IDENTIFIER(new long[] {1, 2, 840, 113549, 2, 5} - ); + public static OBJECT_IDENTIFIER MD5_DIGEST = + new OBJECT_IDENTIFIER(new long[] { 1, 2, 840, 113549, 2, 5 } + ); - public static OBJECT_IDENTIFIER SHA1_DIGEST = - new OBJECT_IDENTIFIER(new long[] {1, 3, 14, 3, 2, 26} - ); + public static OBJECT_IDENTIFIER SHA1_DIGEST = + new OBJECT_IDENTIFIER(new long[] { 1, 3, 14, 3, 2, 26 } + ); - public static OBJECT_IDENTIFIER SHA256_DIGEST = - new OBJECT_IDENTIFIER(new long[] {2, 16, 840, 1, 101, 3, 4, 2, 1} - ); + public static OBJECT_IDENTIFIER SHA256_DIGEST = + new OBJECT_IDENTIFIER(new long[] { 2, 16, 840, 1, 101, 3, 4, 2, 1 } + ); - public static OBJECT_IDENTIFIER SHA512_DIGEST = - new OBJECT_IDENTIFIER(new long[] {2, 16, 840, 1, 101, 3, 4, 2, 3} - ); + public static OBJECT_IDENTIFIER SHA512_DIGEST = + new OBJECT_IDENTIFIER(new long[] { 2, 16, 840, 1, 101, 3, 4, 2, 3 } + ); // Strings given in 'messageType' authenticated attribute public final static String mType_PKCSReq = "19"; @@ -120,12 +118,12 @@ public class CRSPKIMessage { public final static String mType_GetCertInitial = "20"; public final static String mType_GetCert = "21"; public final static String mType_GetCRL = "22"; - + // Strings given in 'PKIStatus' authenticated attribute public final static String mStatus_SUCCESS = "0"; public final static String mStatus_FAILURE = "2"; public final static String mStatus_PENDING = "3"; - + // Strings given in 'failInfo' authenticated attribute public final static String mFailInfo_badAlg = "0"; public final static String mFailInfo_badMessageCheck = "1"; @@ -140,66 +138,65 @@ public class CRSPKIMessage { public final static String mFailInfo_noKeyReuse = "10"; public final static String mFailInfo_internalCAError = "11"; public final static String mFailInfo_tryLater = "12"; - + // ************************************************************************ // These private members represent the flattened structure of the PKIMessage // ************************************************************************ - + // top level is just a ContentInfo - private ContentInfo crsci; + private ContentInfo crsci; // it's content is a signedData - private SignedData sd; + private SignedData sd; // In the signed data, we have: - private int sdv; // Version - private ContentInfo data; // The data to be digested - private EnvelopedData sded; // Enveloped data inside of signed data - private byte[] signerCertBytes; + private int sdv; // Version + private ContentInfo data; // The data to be digested + private EnvelopedData sded; // Enveloped data inside of signed data + private byte[] signerCertBytes; org.mozilla.jss.pkix.cert.Certificate signerCert; - private SET sis; // set of SignerInfos - private SignerInfo si; // First SignerInfo + private SET sis; // set of SignerInfos + private SignerInfo si; // First SignerInfo private AlgorithmIdentifier digestAlgorithmId = null; - private int siv; // Version - private SET aa; // Authenticated Attributes - private SET aa_old; // Authenticated Attributes - private IssuerAndSerialNumber sgnIASN; // Signer's Issuer Name and Serialnum - private OCTET_STRING aa_digest; // digest of the authenticated attrs - - private String messageType; // these are all authenticated attributes - private String failInfo; - private String pkiStatus; - private String transactionID; - private byte[] senderNonce; - private byte[] recipientNonce; + private int siv; // Version + private SET aa; // Authenticated Attributes + private SET aa_old; // Authenticated Attributes + private IssuerAndSerialNumber sgnIASN; // Signer's Issuer Name and Serialnum + private OCTET_STRING aa_digest; // digest of the authenticated attrs + + private String messageType; // these are all authenticated attributes + private String failInfo; + private String pkiStatus; + private String transactionID; + private byte[] senderNonce; + private byte[] recipientNonce; private OCTET_STRING msg_digest; // digest of the message // Inside the sded Enveloped data - private RecipientInfo ri; // First RecipientInfo - private int riv; // Version - private AlgorithmIdentifier riAlgid; // alg that the bulk key is wrapped with - private byte[] riKey; // bulk key, wrapped with above algorithm - private byte[] cKey; // * 'clear', unwrapped key (not in ASN.1) * + private RecipientInfo ri; // First RecipientInfo + private int riv; // Version + private AlgorithmIdentifier riAlgid; // alg that the bulk key is wrapped with + private byte[] riKey; // bulk key, wrapped with above algorithm + private byte[] cKey; // * 'clear', unwrapped key (not in ASN.1) * private IssuerAndSerialNumber rcpIASN; // Recipient's Issuer Name and Serial Number private EncryptedContentInfo eci; - private byte[] iv; // initialization vector for above key - private byte[] ec; // encrypted content (P10, in case of request) - private byte[] cc; // * 'clear' content (not in ASN.1) * - private String encryptionAlgorithm = null; + private byte[] iv; // initialization vector for above key + private byte[] ec; // encrypted content (P10, in case of request) + private byte[] cc; // * 'clear' content (not in ASN.1) * + private String encryptionAlgorithm = null; // For the CertRep, the enveloped content is another signed Data: - private SignedData crsd; - private int rsdVersion; - private byte[] rsdCert; // certificate to send in response + private SignedData crsd; + private int rsdVersion; + private byte[] rsdCert; // certificate to send in response - private Object myP10; + private Object myP10; - private Hashtable attrs; // miscellanous + private Hashtable attrs; // miscellanous // *** END *** // - public void debug() { } @@ -211,30 +208,28 @@ public class CRSPKIMessage { return attrs.get(a); } - private SignatureAlgorithm getSignatureAlgorithm (String hashAlgorithm) - { + private SignatureAlgorithm getSignatureAlgorithm(String hashAlgorithm) { SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.RSASignatureWithMD5Digest; if (hashAlgorithm != null) { if (hashAlgorithm.equals("SHA1")) { signatureAlgorithm = SignatureAlgorithm.RSASignatureWithSHA1Digest; } else if (hashAlgorithm.equals("SHA256")) { signatureAlgorithm = SignatureAlgorithm.RSASignatureWithSHA256Digest; - } else if (hashAlgorithm.equals("SHA512")) { + } else if (hashAlgorithm.equals("SHA512")) { signatureAlgorithm = SignatureAlgorithm.RSASignatureWithSHA512Digest; } } return signatureAlgorithm; } - private OBJECT_IDENTIFIER getAlgorithmOID (String hashAlgorithm) - { + private OBJECT_IDENTIFIER getAlgorithmOID(String hashAlgorithm) { OBJECT_IDENTIFIER oid = MD5_DIGEST; if (hashAlgorithm != null) { if (hashAlgorithm.equals("SHA1")) { oid = SHA1_DIGEST; } else if (hashAlgorithm.equals("SHA256")) { oid = SHA256_DIGEST; - } else if (hashAlgorithm.equals("SHA512")) { + } else if (hashAlgorithm.equals("SHA512")) { oid = SHA512_DIGEST; } } @@ -242,8 +237,7 @@ public class CRSPKIMessage { } // getHashAlgorithm is added to work around issue 636217 - private String getHashAlgorithm (OBJECT_IDENTIFIER algorithmOID) - { + private String getHashAlgorithm(OBJECT_IDENTIFIER algorithmOID) { String hashAlgorithm = null; OBJECT_IDENTIFIER oid = MD5_DIGEST; if (algorithmOID != null) { @@ -253,7 +247,7 @@ public class CRSPKIMessage { hashAlgorithm = "SHA1"; } else if (algorithmOID.equals(SHA256_DIGEST)) { hashAlgorithm = "SHA256"; - } else if (algorithmOID.equals(SHA512_DIGEST)) { + } else if (algorithmOID.equals(SHA512_DIGEST)) { hashAlgorithm = "SHA512"; } } @@ -263,33 +257,33 @@ public class CRSPKIMessage { // These functions are used to initialize the various blobs public void makeSignedData(int version, - byte[] certificate, String hashAlgorithm) { + byte[] certificate, String hashAlgorithm) { try { SET digest_algs = new SET(); digest_algs.addElement(new AlgorithmIdentifier(getAlgorithmOID(hashAlgorithm), new NULL())); - + // SET certs = new SET(); // certs.addElement(new ANY(certificate)); - + SET sis = new SET(); sis.addElement(si); - + ContentInfo data = this.data; this.sd = new SignedData( digest_algs, data, - null, // don't send the certs, he already has them - null, // crl's - sis); + null, // don't send the certs, he already has them + null, // crl's + sis); } catch (Exception e) { } } - + public byte[] getResponse() throws IOException, InvalidBERException { crsci = new ContentInfo(ContentInfo.SIGNED_DATA, @@ -318,23 +312,23 @@ public class CRSPKIMessage { */ public void makeSignerInfo(int version, - // issuer and serialnumber - org.mozilla.jss.crypto.PrivateKey pk, String hashAlgorithm) - throws java.security.NoSuchAlgorithmException, + // issuer and serialnumber + org.mozilla.jss.crypto.PrivateKey pk, String hashAlgorithm) + throws java.security.NoSuchAlgorithmException, TokenException, java.security.InvalidKeyException, - java.security.SignatureException, + java.security.SignatureException, org.mozilla.jss.CryptoManager.NotInitializedException { - si = new SignerInfo(sgnIASN, // issuer and serialnum - this.aa, // Authenticated Attributes - null, // Unauthenticated Attrs - ContentInfo.ENVELOPED_DATA, // content type - msg_digest.toByteArray(), // digest - getSignatureAlgorithm(hashAlgorithm), + si = new SignerInfo(sgnIASN, // issuer and serialnum + this.aa, // Authenticated Attributes + null, // Unauthenticated Attrs + ContentInfo.ENVELOPED_DATA, // content type + msg_digest.toByteArray(), // digest + getSignatureAlgorithm(hashAlgorithm), pk); } - + public void makeAuthenticatedAttributes() { aa = new SET(); @@ -346,28 +340,28 @@ public class CRSPKIMessage { tidset.addElement((new PrintableString(transactionID))); aa.addElement(new Attribute(CRS_TRANSID, tidset)); } - + if (pkiStatus != null) { SET pkistatusset = new SET(); pkistatusset.addElement(new PrintableString(pkiStatus)); aa.addElement(new Attribute(CRS_PKISTATUS, pkistatusset)); } - + if (messageType != null) { SET aaset = new SET(); aaset.addElement(new PrintableString(messageType)); - aa.addElement(new Attribute(CRS_MESSAGETYPE, aaset)); + aa.addElement(new Attribute(CRS_MESSAGETYPE, aaset)); } if (failInfo != null) { SET fiset = new SET(); fiset.addElement(new PrintableString(failInfo)); - aa.addElement(new Attribute(CRS_FAILINFO, fiset)); + aa.addElement(new Attribute(CRS_FAILINFO, fiset)); } - + if (senderNonce != null) { SET snset = new SET(); @@ -383,29 +377,29 @@ public class CRSPKIMessage { } // XXX sender nonce - + } catch (CharConversionException e) { } } - + public byte[] makeEnvelopedData(int version) { byte[] r; try { - + if (this.ri != null) { ContentInfo ci; SET ris = new SET(); ris.addElement(this.ri); - + this.sded = new EnvelopedData( new INTEGER(version), ris, eci); - + ci = new ContentInfo(ContentInfo.ENVELOPED_DATA, sded); ByteArrayOutputStream ba = new ByteArrayOutputStream(); @@ -432,8 +426,8 @@ public class CRSPKIMessage { this.riv = version; this.riAlgid = new AlgorithmIdentifier(RSA_ENCRYPTION, new NULL()); - this.riKey = riKey; - + this.riKey = riKey; + this.ri = new RecipientInfo( new INTEGER(this.riv), rcpIASN, @@ -469,19 +463,19 @@ public class CRSPKIMessage { try { SET certs = new SET(); ANY cert = new ANY(certificate); - + certs.addElement(cert); - + crsd = new SignedData( - new SET(), // empty set of digestAlgorithmID's - new ContentInfo( - new OBJECT_IDENTIFIER(new long[] {1, 2, 840, 113549, 1, 7, 1} + new SET(), // empty set of digestAlgorithmID's + new ContentInfo( + new OBJECT_IDENTIFIER(new long[] { 1, 2, 840, 113549, 1, 7, 1 } ), null), //empty content - certs, - null, // no CRL's - new SET() // empty SignerInfos - ); + certs, + null, // no CRL's + new SET() // empty SignerInfos + ); ContentInfo wrap = new ContentInfo(ContentInfo.SIGNED_DATA, crsd); @@ -495,7 +489,7 @@ public class CRSPKIMessage { return null; } } - + public String toString() { StringBuffer sb = new StringBuffer(); sb.append("{ messageType="); @@ -507,15 +501,15 @@ public class CRSPKIMessage { sb.append(", transactionID="); sb.append(getTransactionID()); sb.append(", senderNonce="); - sb.append( Arrays.toString( getSenderNonce() ) ); + sb.append(Arrays.toString(getSenderNonce())); sb.append(", recipientNonce="); - sb.append( Arrays.toString( getRecipientNonce() ) ); + sb.append(Arrays.toString(getRecipientNonce())); sb.append(" }"); - + String s = sb.toString(); return s; } - + public String getMessageType() { return messageType; } @@ -559,7 +553,7 @@ public class CRSPKIMessage { public String getDigestAlgorithmName() { String name = null; if (digestAlgorithmId != null) { - name = getHashAlgorithm(digestAlgorithmId.getOID()); + name = getHashAlgorithm(digestAlgorithmId.getOID()); } return name; } @@ -568,10 +562,10 @@ public class CRSPKIMessage { try { org.mozilla.jss.pkix.cert.Certificate.Template ct = new - org.mozilla.jss.pkix.cert.Certificate.Template(); - + org.mozilla.jss.pkix.cert.Certificate.Template(); + ByteArrayInputStream bais = new ByteArrayInputStream(this.signerCertBytes); - + signerCert = (org.mozilla.jss.pkix.cert.Certificate) ct.decode(bais); return signerCert.getInfo().getSubjectPublicKeyInfo().toPublicKey(); } catch (Exception e) { @@ -591,7 +585,7 @@ public class CRSPKIMessage { } - public void setAA_old( SET auth_attrs ) { + public void setAA_old(SET auth_attrs) { aa_old = auth_attrs; } @@ -611,15 +605,15 @@ public class CRSPKIMessage { public byte[] getAADigest() { return aa_digest.toByteArray(); } - + public Object getP10() { return myP10; } - + public void setP10(Object p10) { myP10 = p10; } - + public void setSgnIssuerAndSerialNumber(IssuerAndSerialNumber iasn) { this.sgnIASN = iasn; } @@ -629,7 +623,7 @@ public class CRSPKIMessage { } public IssuerAndSerialNumber getSgnIssuerAndSerialNumber() { - return this.sgnIASN; + return this.sgnIASN; } public IssuerAndSerialNumber getRcpIssuerAndSerialNumber() { @@ -662,7 +656,6 @@ public class CRSPKIMessage { // public void setCertificate(byte [] cert) { this.certificate = cert; } - public void setMsgDigest(byte[] digest) { this.msg_digest = new OCTET_STRING(digest); } @@ -673,53 +666,52 @@ public class CRSPKIMessage { public void setPending() { // setIssuerAndSerialNumber(); - + setMessageType(mType_CertRep); setPKIStatus(mStatus_PENDING); }; - + public void setFailure(String failInfo) { setMessageType(mType_CertRep); setPKIStatus(mStatus_FAILURE); setFailInfo(failInfo); } - + // Should add a Certificate to this call public void setSuccess() { setMessageType(mType_CertRep); setPKIStatus(mStatus_SUCCESS); } - + /** * Gets a byte array which is the der-encoded blob * which gets sent back to the router. */ - + public byte[] getEncoded() { //Assert.assert(messageType != null); //Assert.assert(pkiStatus != null); - - return new byte[1]; // blagh + + return new byte[1]; // blagh } - - private void decodeCRSPKIMessage (ByteArrayInputStream bais) throws InvalidBERException, Exception { + private void decodeCRSPKIMessage(ByteArrayInputStream bais) throws InvalidBERException, Exception { org.mozilla.jss.pkcs7.ContentInfo.Template crscit; crscit = new ContentInfo.Template(); crsci = (ContentInfo) crscit.decode(bais); - - if (!ContentInfo.SIGNED_DATA.equals(crsci.getContentType())) { + + if (!ContentInfo.SIGNED_DATA.equals(crsci.getContentType())) { throw new Exception("ContentType wasn't signed data, it was" + crsci.getContentType()); } - + // Now that we know that the contentInfo is a SignedData, we can decode it SignedData.Template sdt = new SignedData.Template(); - + sd = (SignedData) sdt.decode( new ByteArrayInputStream( - ((ANY) crsci.getContent()).getEncoded() + ((ANY) crsci.getContent()).getEncoded() )); this.decodeSD(); } @@ -727,34 +719,34 @@ public class CRSPKIMessage { public CRSPKIMessage() { attrs = new Hashtable(); } - - public CRSPKIMessage (ByteArrayInputStream bais) throws InvalidBERException, Exception { + + public CRSPKIMessage(ByteArrayInputStream bais) throws InvalidBERException, Exception { attrs = new Hashtable(); decodeCRSPKIMessage(bais); } private void decodeSD() throws Exception { - ContentInfo sdci; + ContentInfo sdci; sis = sd.getSignerInfos(); - + decodeSI(); sdci = sd.getContentInfo(); - + // HACK to work with CRS ANY a = (ANY) sdci.getContent(); ByteArrayInputStream s = new ByteArrayInputStream(a.getEncoded()); OCTET_STRING os = (OCTET_STRING) (new OCTET_STRING.Template()).decode(s); - + ByteArrayInputStream s2 = new ByteArrayInputStream(os.toByteArray()); ContentInfo ci = (ContentInfo) (new ContentInfo.Template()).decode(s2); ByteArrayInputStream s3 = new ByteArrayInputStream(((ANY) ci.getContent()).getEncoded()); - + EnvelopedData.Template edt = new EnvelopedData.Template(); sded = (EnvelopedData) edt.decode(s3); - + SET signerCerts = (SET) sd.getCertificates(); Certificate firstCert = (Certificate) signerCerts.elementAt(0); @@ -764,10 +756,10 @@ public class CRSPKIMessage { sgnIASN = new IssuerAndSerialNumber(firstCertInfo.getIssuer(), firstCertInfo.getSerialNumber()); - + decodeED(); } - + private void decodeSI() throws Exception { if (sis.size() == 0) { throw new Exception("SignerInfos is empty"); @@ -780,12 +772,12 @@ public class CRSPKIMessage { aa_digest = new OCTET_STRING(si.getEncryptedDigest()); } - + private void decodeED() throws Exception { SET ris; ris = (SET) sded.getRecipientInfos(); - + if (ris.size() == 0) { throw new Exception("RecipientInfos is empty"); } @@ -799,32 +791,32 @@ public class CRSPKIMessage { } else { throw new Exception("P10 encrypted alg is not supported (not DES): " + eci.getContentEncryptionAlgorithm().getOID()); } - + ec = eci.getEncryptedContent().toByteArray(); OCTET_STRING.Template ost = new OCTET_STRING.Template(); - + OCTET_STRING os = (OCTET_STRING) - ost.decode(new ByteArrayInputStream( - ((ANY) eci.getContentEncryptionAlgorithm().getParameters()).getEncoded() - ) - ); + ost.decode(new ByteArrayInputStream( + ((ANY) eci.getContentEncryptionAlgorithm().getParameters()).getEncoded() + ) + ); iv = os.toByteArray(); decodeRI(); } - + /** * The PKCS10 request is encrypt with a symmetric key. * This key in turn is encrypted with the RSA key in the * CA certificate. - * - * riAlgid is the algorithm the symm key is encrypted with. It had - * better be RSA - * riKey is the encrypted symmetric key + * + * riAlgid is the algorithm the symm key is encrypted with. It had + * better be RSA + * riKey is the encrypted symmetric key */ - + private void decodeRI() throws Exception { // really should get issuer and serial number of our RI, as this @@ -832,18 +824,18 @@ public class CRSPKIMessage { // going to assume that the key is the Signing cert for the server. riAlgid = ri.getKeyEncryptionAlgorithmID(); - + if (!riAlgid.getOID().equals(RSA_ENCRYPTION)) { throw new Exception("Request is protected by a key which we can't decrypt"); } - + riKey = ri.getEncryptedKey().toByteArray(); - + } - + private void decodeAA() throws InvalidBERException, IOException { aa = si.getAuthenticatedAttributes(); - + int count; for (count = 0; count < aa.size(); count++) { @@ -853,20 +845,20 @@ public class CRSPKIMessage { PrintableString ps; PrintableString.Template pst = new PrintableString.Template(); OCTET_STRING.Template ost = new OCTET_STRING.Template(); - + OBJECT_IDENTIFIER oid = a.getType(); if (oid.equals(CRS_MESSAGETYPE)) { ps = (PrintableString) pst.decode(new ByteArrayInputStream(f.getEncoded())); // We make a new string here messageType = ps.toString(); - + } else if (oid.equals(CRS_PKISTATUS)) { ps = (PrintableString) pst.decode(new ByteArrayInputStream(f.getEncoded())); - pkiStatus = new String (ps.toString()); + pkiStatus = new String(ps.toString()); } else if (oid.equals(CRS_FAILINFO)) { ps = (PrintableString) pst.decode(new ByteArrayInputStream(f.getEncoded())); - failInfo = new String (ps.toString()); + failInfo = new String(ps.toString()); } else if (oid.equals(CRS_SENDERNONCE)) { OCTET_STRING oss = (OCTET_STRING) ost.decode(new ByteArrayInputStream(f.getEncoded())); @@ -877,18 +869,18 @@ public class CRSPKIMessage { recipientNonce = osr.toByteArray(); } else if (oid.equals(CRS_TRANSID)) { ps = (PrintableString) pst.decode(new ByteArrayInputStream(f.getEncoded())); - transactionID = new String (ps.toString()); + transactionID = new String(ps.toString()); } - + } - - } // end of decodeAA(); - + + } // end of decodeAA(); + public String getMessageTypeString() { if (messageType == null) { return null; } - + if (messageType.equals(mType_PKCSReq)) { return "PKCSReq"; } @@ -908,5 +900,4 @@ public class CRSPKIMessage { //Assert.assert(false); return 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 d5689ac9d..b280a7600 100644 --- a/pki/base/util/src/com/netscape/cmsutil/util/Cert.java +++ b/pki/base/util/src/com/netscape/cmsutil/util/Cert.java @@ -17,7 +17,6 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.util; - import java.io.IOException; import java.security.cert.CertificateException; import java.security.cert.X509CRL; @@ -63,13 +62,13 @@ public class Cert { } if ((s.startsWith("-----BEGIN CERTIFICATE-----")) && - (s.endsWith("-----END CERTIFICATE-----"))) { + (s.endsWith("-----END CERTIFICATE-----"))) { return (s.substring(27, (s.length() - 25))); } // To support Thawte's header and footer if ((s.startsWith("-----BEGIN PKCS #7 SIGNED DATA-----")) && - (s.endsWith("-----END PKCS #7 SIGNED DATA-----"))) { + (s.endsWith("-----END PKCS #7 SIGNED DATA-----"))) { return (s.substring(35, (s.length() - 33))); } @@ -81,23 +80,23 @@ public class Cert { return s; } if ((s.startsWith("-----BEGIN CERTIFICATE REVOCATION LIST-----")) && - (s.endsWith("-----END CERTIFICATE REVOCATION LIST-----"))) { + (s.endsWith("-----END CERTIFICATE REVOCATION LIST-----"))) { return (s.substring(43, (s.length() - 41))); } return s; } public static String stripCertBrackets(String s) { - return stripBrackets(s); + return stripBrackets(s); } - // private static BASE64Decoder mDecoder = new BASE64Decoder(); + // private static BASE64Decoder mDecoder = new BASE64Decoder(); public static X509CertImpl mapCert(String mime64) - throws IOException { + throws IOException { mime64 = stripCertBrackets(mime64.trim()); String newval = normalizeCertStr(mime64); - // byte rawPub[] = mDecoder.decodeBuffer(newval); - byte rawPub[] = OSUtil.AtoB( newval ); + // byte rawPub[] = mDecoder.decodeBuffer(newval); + byte rawPub[] = OSUtil.AtoB(newval); X509CertImpl cert = null; try { @@ -108,27 +107,27 @@ public class Cert { } public static X509Certificate[] mapCertFromPKCS7(String mime64) - throws IOException { + throws IOException { mime64 = stripCertBrackets(mime64.trim()); String newval = normalizeCertStr(mime64); - // byte rawPub[] = mDecoder.decodeBuffer(newval); - byte rawPub[] = OSUtil.AtoB( newval ); + // byte rawPub[] = mDecoder.decodeBuffer(newval); + byte rawPub[] = OSUtil.AtoB(newval); PKCS7 p7 = null; try { p7 = new PKCS7(rawPub); } catch (Exception e) { - throw new IOException( "p7 is null" ); + throw new IOException("p7 is null"); } return p7.getCertificates(); } public static X509CRL mapCRL(String mime64) - throws IOException { + throws IOException { mime64 = stripCRLBrackets(mime64.trim()); String newval = normalizeCertStr(mime64); - // byte rawPub[] = mDecoder.decodeBuffer(newval); - byte rawPub[] = OSUtil.AtoB( newval ); + // byte rawPub[] = mDecoder.decodeBuffer(newval); + byte rawPub[] = OSUtil.AtoB(newval); X509CRL crl = null; try { @@ -139,7 +138,7 @@ public class Cert { } public static X509CRL mapCRL1(String mime64) - throws IOException { + throws IOException { mime64 = stripCRLBrackets(mime64.trim()); byte rawPub[] = OSUtil.AtoB(mime64); @@ -187,4 +186,3 @@ public class Cert { return val; } } - diff --git a/pki/base/util/src/com/netscape/cmsutil/util/Fmt.java b/pki/base/util/src/com/netscape/cmsutil/util/Fmt.java index 49b878c4c..a24b8d090 100644 --- a/pki/base/util/src/com/netscape/cmsutil/util/Fmt.java +++ b/pki/base/util/src/com/netscape/cmsutil/util/Fmt.java @@ -45,7 +45,6 @@ package com.netscape.cmsutil.util; // Visit the ACME Labs Java page for up-to-date versions of this and other // fine Java utilities: http://www.acme.com/java/ - /// Some simple single-arg sprintf-like routines. // <P> // It is apparently impossible to declare a Java method that accepts @@ -205,7 +204,7 @@ public class Fmt { if ((l & 0xf000000000000000L) != 0) return fmt( Long.toString(l >>> 60, 16) + - fmt(l & 0x0fffffffffffffffL, 15, HX | ZF), + fmt(l & 0x0fffffffffffffffL, 15, HX | ZF), minWidth, flags | WN); else return fmt(Long.toString(l, 16), minWidth, flags | WN); @@ -213,7 +212,7 @@ public class Fmt { if ((l & 0x8000000000000000L) != 0) return fmt( Long.toString(l >>> 63, 8) + - fmt(l & 0x7fffffffffffffffL, 21, OC | ZF), + fmt(l & 0x7fffffffffffffffL, 21, OC | ZF), minWidth, flags | WN); else return fmt(Long.toString(l, 8), minWidth, flags | WN); @@ -375,8 +374,8 @@ public class Fmt { int numFigs = number.length(); int fracFigs = fraction.length(); - if( ( numFigs == 0 || number.toString().equals( "0" ) ) && - fracFigs > 0 ) { + if ((numFigs == 0 || number.toString().equals("0")) && + fracFigs > 0) { // Don't count leading zeros in the fraction. numFigs = 0; for (int i = 0; i < fraction.length(); ++i) { @@ -394,11 +393,11 @@ public class Fmt { } else if (sigFigs < mantFigs && sigFigs >= numFigs) { // Want fewer figures in the fraction; chop. fraction.setLength( - fraction.length() - (fracFigs - (sigFigs - numFigs))); + fraction.length() - (fracFigs - (sigFigs - numFigs))); // Round? } else if (sigFigs < numFigs) { // Want fewer figures in the number; turn them to zeros. - fraction.setLength(0); // should already be zero, but make sure + fraction.setLength(0); // should already be zero, but make sure for (int i = sigFigs; i < numFigs; ++i) number.setCharAt(i, '0'); // Round? @@ -427,7 +426,7 @@ public class Fmt { if (d == Double.POSITIVE_INFINITY) return "Inf"; - // Grab the sign, and then make the number positive for simplicity. + // Grab the sign, and then make the number positive for simplicity. boolean negative = false; if (d < 0.0D) { @@ -471,19 +470,21 @@ public class Fmt { else num = Integer.parseInt(numStr); - // Build the new mantissa. + // Build the new mantissa. StringBuffer newMantBuf = new StringBuffer(numStr + "."); double p = Math.pow(10, exp); double frac = d - num * p; String digits = "0123456789"; - int nDigits = 16 - numStr.length(); // about 16 digits in a double + int nDigits = 16 - numStr.length(); // about 16 digits in a double for (int i = 0; i < nDigits; ++i) { p /= 10.0D; int dig = (int) (frac / p); - if (dig < 0) dig = 0; - if (dig > 9) dig = 9; + if (dig < 0) + dig = 0; + if (dig > 9) + dig = 9; newMantBuf.append(digits.charAt(dig)); frac -= dig * p; } @@ -519,86 +520,86 @@ public class Fmt { while (newMantBuf.charAt(len - 1) == '0') newMantBuf.setLength(--len); - // And chop a trailing dot, if any. + // And chop a trailing dot, if any. if (newMantBuf.charAt(len - 1) == '.') newMantBuf.setLength(--len); - // Done. + // Done. return (negative ? "-" : "") + - newMantBuf + - (expStr.length() != 0 ? ("e" + expStr) : ""); + newMantBuf + + (expStr.length() != 0 ? ("e" + expStr) : ""); } /****************************************************************************** - /// Test program. - public static void main( String[] args ) - { - System.out.println( "Starting tests." ); - show( Fmt.fmt( "Hello there." ) ); - show( Fmt.fmt( 123 ) ); - show( Fmt.fmt( 123, 10 ) ); - show( Fmt.fmt( 123, 10, Fmt.ZF ) ); - show( Fmt.fmt( 123, 10, Fmt.LJ ) ); - show( Fmt.fmt( -123 ) ); - show( Fmt.fmt( -123, 10 ) ); - show( Fmt.fmt( -123, 10, Fmt.ZF ) ); - show( Fmt.fmt( -123, 10, Fmt.LJ ) ); - show( Fmt.fmt( (byte) 0xbe, 22, Fmt.OC ) ); - show( Fmt.fmt( (short) 0xbabe, 22, Fmt.OC ) ); - show( Fmt.fmt( 0xcafebabe, 22, Fmt.OC ) ); - show( Fmt.fmt( 0xdeadbeefcafebabeL, 22, Fmt.OC ) ); - show( Fmt.fmt( 0x8000000000000000L, 22, Fmt.OC ) ); - show( Fmt.fmt( (byte) 0xbe, 16, Fmt.HX ) ); - show( Fmt.fmt( (short) 0xbabe, 16, Fmt.HX ) ); - show( Fmt.fmt( 0xcafebabe, 16, Fmt.HX ) ); - show( Fmt.fmt( 0xdeadbeefcafebabeL, 16, Fmt.HX ) ); - show( Fmt.fmt( 0x8000000000000000L, 16, Fmt.HX ) ); - show( Fmt.fmt( 'c' ) ); - show( Fmt.fmt( new java.util.Date() ) ); - show( Fmt.fmt( 123.456F ) ); - show( Fmt.fmt( 123456000000000000.0F ) ); - show( Fmt.fmt( 123.456F, 0, 8 ) ); - show( Fmt.fmt( 123.456F, 0, 7 ) ); - show( Fmt.fmt( 123.456F, 0, 6 ) ); - show( Fmt.fmt( 123.456F, 0, 5 ) ); - show( Fmt.fmt( 123.456F, 0, 4 ) ); - show( Fmt.fmt( 123.456F, 0, 3 ) ); - show( Fmt.fmt( 123.456F, 0, 2 ) ); - show( Fmt.fmt( 123.456F, 0, 1 ) ); - show( Fmt.fmt( 123456000000000000.0F, 0, 4 ) ); - show( Fmt.fmt( -123.456F, 0, 4 ) ); - show( Fmt.fmt( -123456000000000000.0F, 0, 4 ) ); - show( Fmt.fmt( 123.0F ) ); - show( Fmt.fmt( 123.0D ) ); - show( Fmt.fmt( 1.234567890123456789F ) ); - show( Fmt.fmt( 1.234567890123456789D ) ); - show( Fmt.fmt( 1234567890123456789F ) ); - show( Fmt.fmt( 1234567890123456789D ) ); - show( Fmt.fmt( 0.000000000000000000001234567890123456789F ) ); - show( Fmt.fmt( 0.000000000000000000001234567890123456789D ) ); - show( Fmt.fmt( 12300.0F ) ); - show( Fmt.fmt( 12300.0D ) ); - show( Fmt.fmt( 123000.0F ) ); - show( Fmt.fmt( 123000.0D ) ); - show( Fmt.fmt( 1230000.0F ) ); - show( Fmt.fmt( 1230000.0D ) ); - show( Fmt.fmt( 12300000.0F ) ); - show( Fmt.fmt( 12300000.0D ) ); - show( Fmt.fmt( Float.NaN ) ); - show( Fmt.fmt( Float.POSITIVE_INFINITY ) ); - show( Fmt.fmt( Float.NEGATIVE_INFINITY ) ); - show( Fmt.fmt( Double.NaN ) ); - show( Fmt.fmt( Double.POSITIVE_INFINITY ) ); - show( Fmt.fmt( Double.NEGATIVE_INFINITY ) ); - show( Fmt.fmt( 1.0F / 8.0F ) ); - show( Fmt.fmt( 1.0D / 8.0D ) ); - System.out.println( "Done with tests." ); - } - - private static void show( String str ) - { - System.out.println( "#" + str + "#" ); - } - ******************************************************************************/ + * /// Test program. + * public static void main( String[] args ) + * { + * System.out.println( "Starting tests." ); + * show( Fmt.fmt( "Hello there." ) ); + * show( Fmt.fmt( 123 ) ); + * show( Fmt.fmt( 123, 10 ) ); + * show( Fmt.fmt( 123, 10, Fmt.ZF ) ); + * show( Fmt.fmt( 123, 10, Fmt.LJ ) ); + * show( Fmt.fmt( -123 ) ); + * show( Fmt.fmt( -123, 10 ) ); + * show( Fmt.fmt( -123, 10, Fmt.ZF ) ); + * show( Fmt.fmt( -123, 10, Fmt.LJ ) ); + * show( Fmt.fmt( (byte) 0xbe, 22, Fmt.OC ) ); + * show( Fmt.fmt( (short) 0xbabe, 22, Fmt.OC ) ); + * show( Fmt.fmt( 0xcafebabe, 22, Fmt.OC ) ); + * show( Fmt.fmt( 0xdeadbeefcafebabeL, 22, Fmt.OC ) ); + * show( Fmt.fmt( 0x8000000000000000L, 22, Fmt.OC ) ); + * show( Fmt.fmt( (byte) 0xbe, 16, Fmt.HX ) ); + * show( Fmt.fmt( (short) 0xbabe, 16, Fmt.HX ) ); + * show( Fmt.fmt( 0xcafebabe, 16, Fmt.HX ) ); + * show( Fmt.fmt( 0xdeadbeefcafebabeL, 16, Fmt.HX ) ); + * show( Fmt.fmt( 0x8000000000000000L, 16, Fmt.HX ) ); + * show( Fmt.fmt( 'c' ) ); + * show( Fmt.fmt( new java.util.Date() ) ); + * show( Fmt.fmt( 123.456F ) ); + * show( Fmt.fmt( 123456000000000000.0F ) ); + * show( Fmt.fmt( 123.456F, 0, 8 ) ); + * show( Fmt.fmt( 123.456F, 0, 7 ) ); + * show( Fmt.fmt( 123.456F, 0, 6 ) ); + * show( Fmt.fmt( 123.456F, 0, 5 ) ); + * show( Fmt.fmt( 123.456F, 0, 4 ) ); + * show( Fmt.fmt( 123.456F, 0, 3 ) ); + * show( Fmt.fmt( 123.456F, 0, 2 ) ); + * show( Fmt.fmt( 123.456F, 0, 1 ) ); + * show( Fmt.fmt( 123456000000000000.0F, 0, 4 ) ); + * show( Fmt.fmt( -123.456F, 0, 4 ) ); + * show( Fmt.fmt( -123456000000000000.0F, 0, 4 ) ); + * show( Fmt.fmt( 123.0F ) ); + * show( Fmt.fmt( 123.0D ) ); + * show( Fmt.fmt( 1.234567890123456789F ) ); + * show( Fmt.fmt( 1.234567890123456789D ) ); + * show( Fmt.fmt( 1234567890123456789F ) ); + * show( Fmt.fmt( 1234567890123456789D ) ); + * show( Fmt.fmt( 0.000000000000000000001234567890123456789F ) ); + * show( Fmt.fmt( 0.000000000000000000001234567890123456789D ) ); + * show( Fmt.fmt( 12300.0F ) ); + * show( Fmt.fmt( 12300.0D ) ); + * show( Fmt.fmt( 123000.0F ) ); + * show( Fmt.fmt( 123000.0D ) ); + * show( Fmt.fmt( 1230000.0F ) ); + * show( Fmt.fmt( 1230000.0D ) ); + * show( Fmt.fmt( 12300000.0F ) ); + * show( Fmt.fmt( 12300000.0D ) ); + * show( Fmt.fmt( Float.NaN ) ); + * show( Fmt.fmt( Float.POSITIVE_INFINITY ) ); + * show( Fmt.fmt( Float.NEGATIVE_INFINITY ) ); + * show( Fmt.fmt( Double.NaN ) ); + * show( Fmt.fmt( Double.POSITIVE_INFINITY ) ); + * show( Fmt.fmt( Double.NEGATIVE_INFINITY ) ); + * show( Fmt.fmt( 1.0F / 8.0F ) ); + * show( Fmt.fmt( 1.0D / 8.0D ) ); + * System.out.println( "Done with tests." ); + * } + * + * private static void show( String str ) + * { + * System.out.println( "#" + str + "#" ); + * } + ******************************************************************************/ } diff --git a/pki/base/util/src/com/netscape/cmsutil/util/HMACDigest.java b/pki/base/util/src/com/netscape/cmsutil/util/HMACDigest.java index e77e37a50..09bf53bbf 100644 --- a/pki/base/util/src/com/netscape/cmsutil/util/HMACDigest.java +++ b/pki/base/util/src/com/netscape/cmsutil/util/HMACDigest.java @@ -17,14 +17,12 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.util; - import java.security.MessageDigest; - /** * This class implements the HMAC algorithm specified in RFC 2104 using * any MessageDigest. - * + * * @author mikep * @version $Revision$, $Date$ * @see java.security.MessageDigest @@ -51,9 +49,9 @@ public class HMACDigest implements Cloneable { /** * Creates an HMACDigest - * - * @param md The MessageDigest to be used for the HMAC calculation. It - * must be clonable. + * + * @param md The MessageDigest to be used for the HMAC calculation. It + * must be clonable. */ public HMACDigest(MessageDigest md) { mMD = md; @@ -62,9 +60,9 @@ public class HMACDigest implements Cloneable { /** * Creates an HMACDigest and initializes the HMAC function * with the given key. - * - * @param md The MessageDigest to be used for the HMAC calculation. It - * must be clonable. + * + * @param md The MessageDigest to be used for the HMAC calculation. It + * must be clonable. * @param key The key value to be used in the HMAC calculation */ public HMACDigest(MessageDigest md, byte[] key) { @@ -81,18 +79,18 @@ public class HMACDigest implements Cloneable { /** * Initialize the HMAC function - * + * * The HMAC transform looks like: - * - * hash(key XOR opad, hash(key XOR ipad, text)) - * + * + * hash(key XOR opad, hash(key XOR ipad, text)) + * * where key is an n byte key * ipad is the byte 0x36 repeated 64 times * opad is the byte 0x5c repeated 64 times * and text is the data being protected - * + * * This routine must be called after every reset. - * + * * @param key The password used to protect the hash value */ public void init(byte[] key) { @@ -133,7 +131,7 @@ public class HMACDigest implements Cloneable { /** * Updates the digest using the specified array of bytes. - * + * * @param input the array of bytes. */ public void update(byte[] input) { @@ -143,7 +141,7 @@ public class HMACDigest implements Cloneable { /** * Completes the HMAC computation with the outer pad * The digest is reset after this call is made. - * + * * @return the array of bytes for the resulting hash value. */ public byte[] digest() { @@ -175,16 +173,15 @@ public class HMACDigest implements Cloneable { /** * Clone the HMACDigest - * + * * @return a clone if the implementation is cloneable. - * @exception CloneNotSupportedException if this is called on a - * MessageDigest implementation that does not support - * <code>Cloneable</code>. + * @exception CloneNotSupportedException if this is called on a + * MessageDigest implementation that does not support <code>Cloneable</code>. */ public Object clone() throws CloneNotSupportedException { int i; - HMACDigest hd = (HMACDigest) super.clone(); + HMACDigest hd = (HMACDigest) super.clone(); hd.mKeyOpad = new byte[PAD_BYTES]; hd.mKeyIpad = new byte[PAD_BYTES]; 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 36933da8e..6f4ba4976 100644 --- a/pki/base/util/src/com/netscape/cmsutil/util/Utils.java +++ b/pki/base/util/src/com/netscape/cmsutil/util/Utils.java @@ -17,7 +17,6 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.util; - import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.ByteArrayOutputStream; @@ -36,64 +35,64 @@ import java.util.Date; import java.util.Vector; public class Utils { - /** - * Checks if this is NT. - */ - public static boolean isNT() { - return ((File.separator).equals("\\")); - } + /** + * Checks if this is NT. + */ + public static boolean isNT() { + return ((File.separator).equals("\\")); + } - public static boolean exec(String cmd) { - try { - String cmds[] = null; - if (isNT()) { - // NT - cmds = new String[3]; - cmds[0] = "cmd"; - cmds[1] = "/c"; - cmds[2] = cmd; - } else { - // UNIX - cmds = new String[3]; - cmds[0] = "/bin/sh"; - cmds[1] = "-c"; - cmds[2] = cmd; - } - Process process = Runtime.getRuntime().exec(cmds); - process.waitFor(); - BufferedReader pOut = null; - String l = null; + public static boolean exec(String cmd) { + try { + String cmds[] = null; + if (isNT()) { + // NT + cmds = new String[3]; + cmds[0] = "cmd"; + cmds[1] = "/c"; + cmds[2] = cmd; + } else { + // UNIX + cmds = new String[3]; + cmds[0] = "/bin/sh"; + cmds[1] = "-c"; + cmds[2] = cmd; + } + Process process = Runtime.getRuntime().exec(cmds); + process.waitFor(); + BufferedReader pOut = null; + String l = null; - if (process.exitValue() == 0) { - /** - pOut = new BufferedReader( - new InputStreamReader(process.getInputStream())); - while ((l = pOut.readLine()) != null) { - System.out.println(l); - } - **/ - return true; - } else { - /** - pOut = new BufferedReader( - new InputStreamReader(process.getErrorStream())); - l = null; - while ((l = pOut.readLine()) != null) { - System.out.println(l); - } - **/ - return false; - } - } catch (Exception e) { - return false; - } - } + if (process.exitValue() == 0) { + /** + * pOut = new BufferedReader( + * new InputStreamReader(process.getInputStream())); + * while ((l = pOut.readLine()) != null) { + * System.out.println(l); + * } + **/ + return true; + } else { + /** + * pOut = new BufferedReader( + * new InputStreamReader(process.getErrorStream())); + * l = null; + * while ((l = pOut.readLine()) != null) { + * System.out.println(l); + * } + **/ + return false; + } + } catch (Exception e) { + return false; + } + } - public static String SpecialURLDecode(String s) { + public static String SpecialURLDecode(String s) { if (s == null) return null; ByteArrayOutputStream out = new ByteArrayOutputStream(s.length()); - + for (int i = 0; i < s.length(); i++) { int c = (int) s.charAt(i); @@ -111,11 +110,11 @@ public class Utils { return out.toString(); } - public static byte[] SpecialDecode(String s) { + public static byte[] SpecialDecode(String s) { if (s == null) return null; ByteArrayOutputStream out = new ByteArrayOutputStream(s.length()); - + for (int i = 0; i < s.length(); i++) { int c = (int) s.charAt(i); @@ -133,17 +132,17 @@ public class Utils { return out.toByteArray(); } - public static String SpecialEncode(byte data[]) { + public static String SpecialEncode(byte data[]) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < data.length; i++) { - sb.append("%"); - if ((data[i] & 0xff) < 16) { - sb.append("0"); - } - sb.append(Integer.toHexString((data[i] & 0xff))); + sb.append("%"); + if ((data[i] & 0xff) < 16) { + sb.append("0"); + } + sb.append(Integer.toHexString((data[i] & 0xff))); } return sb.toString().toUpperCase(); - } + } public static void checkHost(String hostname) throws UnknownHostException { InetAddress addr = InetAddress.getByName(hostname); @@ -151,17 +150,17 @@ public class Utils { public static void copy(String orig, String dest) { try { - BufferedReader in = new BufferedReader(new FileReader(orig)); - PrintWriter out = new PrintWriter( - new BufferedWriter(new FileWriter(dest))); - String line = ""; - while (in.ready()) { - line = in.readLine(); - if (line != null) - out.println(line); - } - in.close(); - out.close(); + BufferedReader in = new BufferedReader(new FileReader(orig)); + PrintWriter out = new PrintWriter( + new BufferedWriter(new FileWriter(dest))); + String line = ""; + while (in.ready()) { + line = in.readLine(); + if (line != null) + out.println(line); + } + in.close(); + out.close(); } catch (Exception ee) { } } @@ -230,9 +229,10 @@ public class Utils { } return true; } - + /** * strips out double quotes around String parameter + * * @param s the string potentially bracketed with double quotes * @return string stripped of surrounding double quotes */ diff --git a/pki/base/util/src/com/netscape/cmsutil/xml/XMLObject.java b/pki/base/util/src/com/netscape/cmsutil/xml/XMLObject.java index a012f1a08..8890d79fe 100644 --- a/pki/base/util/src/com/netscape/cmsutil/xml/XMLObject.java +++ b/pki/base/util/src/com/netscape/cmsutil/xml/XMLObject.java @@ -16,6 +16,7 @@ // All rights reserved. // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.xml; + import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; @@ -43,8 +44,7 @@ import org.w3c.dom.NodeList; import org.w3c.dom.Text; import org.xml.sax.SAXException; -public class XMLObject -{ +public class XMLObject { private Document mDoc = null; public XMLObject() throws ParserConfigurationException { @@ -53,15 +53,15 @@ public class XMLObject mDoc = docBuilder.newDocument(); } - public XMLObject(InputStream s) - throws SAXException, IOException, ParserConfigurationException { + public XMLObject(InputStream s) + throws SAXException, IOException, ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = factory.newDocumentBuilder(); mDoc = docBuilder.parse(s); } - public XMLObject(File f) - throws SAXException, IOException, ParserConfigurationException { + public XMLObject(File f) + throws SAXException, IOException, ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = factory.newDocumentBuilder(); mDoc = docBuilder.parse(f); @@ -77,14 +77,14 @@ public class XMLObject public Node createRoot(String name) { Element root = mDoc.createElement(name); mDoc.appendChild(root); - return (Node)root; + return (Node) root; } public Node getRoot() { return mDoc.getFirstChild(); } - /** + /** * If you have duplicate containers, then this method will return the * first container in the list. */ @@ -98,7 +98,7 @@ public class XMLObject public Node createContainer(Node containerParent, String containerName) { Element node = mDoc.createElement(containerName); containerParent.appendChild(node); - return (Node)node; + return (Node) node; } public void addItemToContainer(Node container, String tagname, String value) { @@ -109,7 +109,7 @@ public class XMLObject } public String getValue(String tagname) { - Node n = getContainer(tagname); + Node n = getContainer(tagname); if (n != null) { NodeList c = n.getChildNodes(); @@ -125,7 +125,7 @@ public class XMLObject public Vector getAllValues(String tagname) { Vector v = new Vector(); NodeList nodes = mDoc.getElementsByTagName(tagname); - for (int i=0; i<nodes.getLength(); i++) { + for (int i = 0; i < nodes.getLength(); i++) { Node n = nodes.item(i); NodeList c = n.getChildNodes(); if (c.getLength() > 0) { @@ -141,7 +141,7 @@ public class XMLObject Vector v = new Vector(); NodeList c = container.getChildNodes(); int len = c.getLength(); - for (int i=0; i<len; i++) { + for (int i = 0; i < len; i++) { Node subchild = c.item(i); if (subchild.getNodeName().equals(tagname)) { NodeList grandchildren = subchild.getChildNodes(); @@ -166,8 +166,8 @@ public class XMLObject return bos.toByteArray(); } - public void output(OutputStream os) - throws TransformerConfigurationException, TransformerException { + public void output(OutputStream os) + throws TransformerConfigurationException, TransformerException { TransformerFactory tranFactory = TransformerFactory.newInstance(); Transformer aTransformer = tranFactory.newTransformer(); Source src = new DOMSource(mDoc); @@ -183,5 +183,5 @@ public class XMLObject transformer.transform(src, dest); String xmlString = dest.getWriter().toString(); return xmlString; - } + } } |