summaryrefslogtreecommitdiffstats
path: root/bcpkix/src/main/java/org/bouncycastle/cms/CMSUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'bcpkix/src/main/java/org/bouncycastle/cms/CMSUtils.java')
-rw-r--r--bcpkix/src/main/java/org/bouncycastle/cms/CMSUtils.java117
1 files changed, 100 insertions, 17 deletions
diff --git a/bcpkix/src/main/java/org/bouncycastle/cms/CMSUtils.java b/bcpkix/src/main/java/org/bouncycastle/cms/CMSUtils.java
index d6126b6..e5f7e9b 100644
--- a/bcpkix/src/main/java/org/bouncycastle/cms/CMSUtils.java
+++ b/bcpkix/src/main/java/org/bouncycastle/cms/CMSUtils.java
@@ -13,6 +13,7 @@ import org.bouncycastle.asn1.ASN1EncodableVector;
import org.bouncycastle.asn1.ASN1InputStream;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.ASN1Set;
+import org.bouncycastle.asn1.ASN1TaggedObject;
import org.bouncycastle.asn1.BEROctetStringGenerator;
import org.bouncycastle.asn1.BERSet;
import org.bouncycastle.asn1.DERSet;
@@ -29,6 +30,7 @@ import org.bouncycastle.cert.X509CRLHolder;
import org.bouncycastle.cert.X509CertificateHolder;
import org.bouncycastle.operator.DigestCalculator;
import org.bouncycastle.util.Store;
+import org.bouncycastle.util.Strings;
import org.bouncycastle.util.io.Streams;
import org.bouncycastle.util.io.TeeInputStream;
import org.bouncycastle.util.io.TeeOutputStream;
@@ -99,18 +101,37 @@ class CMSUtils
static List getCRLsFromStore(Store crlStore)
throws CMSException
{
- List certs = new ArrayList();
+ List crls = new ArrayList();
try
{
for (Iterator it = crlStore.getMatches(null).iterator(); it.hasNext();)
{
- X509CRLHolder c = (X509CRLHolder)it.next();
-
- certs.add(c.toASN1Structure());
+ Object rev = it.next();
+
+ if (rev instanceof X509CRLHolder)
+ {
+ X509CRLHolder c = (X509CRLHolder)rev;
+
+ crls.add(c.toASN1Structure());
+ }
+ // BEGIN android-removed
+ // else if (rev instanceof OtherRevocationInfoFormat)
+ // {
+ // OtherRevocationInfoFormat infoFormat = OtherRevocationInfoFormat.getInstance(rev);
+ //
+ // validateInfoFormat(infoFormat);
+ //
+ // crls.add(new DERTaggedObject(false, 1, infoFormat));
+ // }
+ // END android-removed
+ else if (rev instanceof ASN1TaggedObject)
+ {
+ crls.add(rev);
+ }
}
- return certs;
+ return crls;
}
catch (ClassCastException e)
{
@@ -119,6 +140,19 @@ class CMSUtils
}
// BEGIN android-removed
+ // private static void validateInfoFormat(OtherRevocationInfoFormat infoFormat)
+ // {
+ // if (CMSObjectIdentifiers.id_ri_ocsp_response.equals(infoFormat.getInfoFormat()))
+ // {
+ // OCSPResponse resp = OCSPResponse.getInstance(infoFormat.getInfo());
+ //
+ // if (resp.getResponseStatus().getValue().intValue() != OCSPResponseStatus.SUCCESSFUL)
+ // {
+ // throw new IllegalArgumentException("cannot add unsuccessful OCSP response to CMS SignedData");
+ // }
+ // }
+ // }
+ //
// static Collection getOthersFromStore(ASN1ObjectIdentifier otherRevocationInfoFormat, Store otherRevocationInfos)
// {
// List others = new ArrayList();
@@ -126,18 +160,10 @@ class CMSUtils
// for (Iterator it = otherRevocationInfos.getMatches(null).iterator(); it.hasNext();)
// {
// ASN1Encodable info = (ASN1Encodable)it.next();
+ // OtherRevocationInfoFormat infoFormat = new OtherRevocationInfoFormat(otherRevocationInfoFormat, info);
+ // validateInfoFormat(infoFormat);
//
- // if (CMSObjectIdentifiers.id_ri_ocsp_response.equals(otherRevocationInfoFormat))
- // {
- // OCSPResponse resp = OCSPResponse.getInstance(info);
- //
- // if (resp.getResponseStatus().getValue().intValue() != OCSPResponseStatus.SUCCESSFUL)
- // {
- // throw new IllegalArgumentException("cannot add unsuccessful OCSP response to CMS SignedData");
- // }
- // }
- //
- // others.add(new DERTaggedObject(false, 1, new OtherRevocationInfoFormat(otherRevocationInfoFormat, info)));
+ // others.add(new DERTaggedObject(false, 1, infoFormat));
// }
//
// return others;
@@ -202,7 +228,64 @@ class CMSUtils
throw new CMSException("Malformed content.", e);
}
}
-
+
+ static byte[] getPasswordBytes(int scheme, char[] password)
+ {
+ if (scheme == PasswordRecipient.PKCS5_SCHEME2)
+ {
+ return PKCS5PasswordToBytes(password);
+ }
+
+ return PKCS5PasswordToUTF8Bytes(password);
+ }
+
+ /**
+ * converts a password to a byte array according to the scheme in
+ * PKCS5 (ascii, no padding)
+ *
+ * @param password a character array representing the password.
+ * @return a byte array representing the password.
+ */
+ private static byte[] PKCS5PasswordToBytes(
+ char[] password)
+ {
+ if (password != null)
+ {
+ byte[] bytes = new byte[password.length];
+
+ for (int i = 0; i != bytes.length; i++)
+ {
+ bytes[i] = (byte)password[i];
+ }
+
+ return bytes;
+ }
+ else
+ {
+ return new byte[0];
+ }
+ }
+
+ /**
+ * converts a password to a byte array according to the scheme in
+ * PKCS5 (UTF-8, no padding)
+ *
+ * @param password a character array representing the password.
+ * @return a byte array representing the password.
+ */
+ private static byte[] PKCS5PasswordToUTF8Bytes(
+ char[] password)
+ {
+ if (password != null)
+ {
+ return Strings.toUTF8ByteArray(password);
+ }
+ else
+ {
+ return new byte[0];
+ }
+ }
+
public static byte[] streamToByteArray(
InputStream in)
throws IOException