Diff
Modified: trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/EncContent.java (1079 => 1080)
--- trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/EncContent.java 2008-07-27 16:10:46 UTC (rev 1079)
+++ trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/EncContent.java 2008-07-27 16:10:49 UTC (rev 1080)
@@ -28,13 +28,18 @@
package org.jruby.ext.openssl.impl;
import javax.crypto.Cipher;
+import org.bouncycastle.asn1.ASN1OctetString;
+import org.bouncycastle.asn1.ASN1Sequence;
+import org.bouncycastle.asn1.DEREncodable;
+import org.bouncycastle.asn1.DERObjectIdentifier;
+import org.bouncycastle.asn1.DERTaggedObject;
+import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
/** PKCS7_ENC_CONTENT
*
* @author <a href="" PROTECTED]">Ola Bini</a>
*/
public class EncContent {
-
/**
* Describe contentType here.
*/
@@ -46,6 +51,16 @@
private Cipher cipher;
/**
+ * Describe algorithm here.
+ */
+ private AlgorithmIdentifier algorithm;
+
+ /**
+ * Describe encData here.
+ */
+ private ASN1OctetString encData;
+
+ /**
* Get the <code>ContentType</code> value.
*
* @return an <code>int</code> value
@@ -80,4 +95,71 @@
public final void setCipher(final Cipher newCipher) {
this.cipher = newCipher;
}
+
+ /**
+ * Get the <code>Algorithm</code> value.
+ *
+ * @return an <code>AlgorithmIdentifier</code> value
+ */
+ public final AlgorithmIdentifier getAlgorithm() {
+ return algorithm;
+ }
+
+ /**
+ * Set the <code>Algorithm</code> value.
+ *
+ * @param newAlgorithm The new Algorithm value.
+ */
+ public final void setAlgorithm(final AlgorithmIdentifier newAlgorithm) {
+ this.algorithm = newAlgorithm;
+ }
+
+ /**
+ * Get the <code>EncData</code> value.
+ *
+ * @return an <code>ASN1OctetString</code> value
+ */
+ public final ASN1OctetString getEncData() {
+ return encData;
+ }
+
+ /**
+ * Set the <code>EncData</code> value.
+ *
+ * @param newEncData The new EncData value.
+ */
+ public final void setEncData(final ASN1OctetString newEncData) {
+ this.encData = newEncData;
+ }
+
+ @Override
+ public String toString() {
+ return "#<EncContent contentType="+contentType+" algorithm="+ASN1Registry.o2a(algorithm.getObjectId())+" content="+encData+">";
+ }
+
+ /**
+ * EncryptedContentInfo ::= SEQUENCE {
+ * contentType ContentType,
+ * contentEncryptionAlgorithm ContentEncryptionAlgorithmIdentifier,
+ * encryptedContent [0] IMPLICIT EncryptedContent OPTIONAL }
+ *
+ * EncryptedContent ::= OCTET STRING
+ */
+ public static EncContent fromASN1(DEREncodable content) {
+ ASN1Sequence sequence = (ASN1Sequence)content;
+ DERObjectIdentifier contentType = (DERObjectIdentifier)(sequence.getObjectAt(0));
+ int nid = ASN1Registry.obj2nid(contentType);
+
+ EncContent ec = new EncContent();
+ ec.setContentType(nid);
+ ec.setAlgorithm(AlgorithmIdentifier.getInstance(sequence.getObjectAt(1)));
+ if(sequence.size() > 2 && sequence.getObjectAt(2) instanceof DERTaggedObject && ((DERTaggedObject)(sequence.getObjectAt(2))).getTagNo() == 0) {
+ DEREncodable ee = ((DERTaggedObject)(sequence.getObjectAt(2))).getObject();
+ if(ee instanceof ASN1Sequence) {
+ } else {
+ ec.setEncData((ASN1OctetString)ee);
+ }
+ }
+ return ec;
+ }
}// EncContent
Modified: trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/Envelope.java (1079 => 1080)
--- trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/Envelope.java 2008-07-27 16:10:46 UTC (rev 1079)
+++ trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/Envelope.java 2008-07-27 16:10:49 UTC (rev 1080)
@@ -27,10 +27,15 @@
***** END LICENSE BLOCK *****/
package org.jruby.ext.openssl.impl;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashSet;
import java.util.List;
-import java.util.ArrayList;
import java.util.Set;
-import java.util.HashSet;
+import org.bouncycastle.asn1.ASN1Sequence;
+import org.bouncycastle.asn1.ASN1Set;
+import org.bouncycastle.asn1.DEREncodable;
+import org.bouncycastle.asn1.DERInteger;
/** PKCS7_ENVELOPE
*
@@ -47,7 +52,7 @@
/**
* Describe recipientInfo here.
*/
- private List<RecipInfo> recipientInfo = new ArrayList<RecipInfo>();
+ private Set<RecipInfo> recipientInfo = new HashSet<RecipInfo>();
/**
* Get the <code>Version</code> value.
@@ -88,9 +93,9 @@
/**
* Get the <code>RecipientInfo</code> value.
*
- * @return a <code>List<RecipInfo></code> value
+ * @return a <code>Set<RecipInfo></code> value
*/
- public final List<RecipInfo> getRecipientInfo() {
+ public final Set<RecipInfo> getRecipientInfo() {
return recipientInfo;
}
@@ -99,7 +104,47 @@
*
* @param newRecipientInfo The new RecipientInfo value.
*/
- public final void setRecipientInfo(final List<RecipInfo> newRecipientInfo) {
+ public final void setRecipientInfo(final Set<RecipInfo> newRecipientInfo) {
this.recipientInfo = newRecipientInfo;
}
+
+ @Override
+ public String toString() {
+ return "#<Envelope version=" + version + " encData="+encData+" recipientInfo="+recipientInfo+">";
+ }
+
+ /**
+ * EnvelopedData ::= SEQUENCE {
+ * version Version,
+ * recipientInfos RecipientInfos,
+ * encryptedContentInfo EncryptedContentInfo }
+ *
+ * Version ::= INTEGER
+ *
+ * RecipientInfos ::= SET OF RecipientInfo
+ *
+ */
+ public static Envelope fromASN1(DEREncodable content) {
+ ASN1Sequence sequence = (ASN1Sequence)content;
+ DERInteger version = (DERInteger)sequence.getObjectAt(0);
+ ASN1Set recipients = (ASN1Set)sequence.getObjectAt(1);
+ DEREncodable encContent = sequence.getObjectAt(2);
+
+ Envelope envelope = new Envelope();
+ envelope.setVersion(version.getValue().intValue());
+ envelope.setRecipientInfo(recipientInfosFromASN1Set(recipients));
+ envelope.setEncData(EncContent.fromASN1(encContent));
+
+ return envelope;
+ }
+
+
+ private static Set<RecipInfo> recipientInfosFromASN1Set(DEREncodable content) {
+ ASN1Set set = (ASN1Set)content;
+ Set<RecipInfo> result = new HashSet<RecipInfo>();
+ for(Enumeration<?> e = set.getObjects(); e.hasMoreElements();) {
+ result.add(RecipInfo.fromASN1((DEREncodable)e.nextElement()));
+ }
+ return result;
+ }
}// Envelope
Modified: trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/PKCS7DataEnveloped.java (1079 => 1080)
--- trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/PKCS7DataEnveloped.java 2008-07-27 16:10:46 UTC (rev 1079)
+++ trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/PKCS7DataEnveloped.java 2008-07-27 16:10:49 UTC (rev 1080)
@@ -45,6 +45,10 @@
this.enveloped.getEncData().setContentType(PKCS7.NID_pkcs7_data);
}
+ public PKCS7DataEnveloped(Envelope enveloped) {
+ this.enveloped = enveloped;
+ }
+
public int getType() {
return PKCS7.NID_pkcs7_enveloped;
}
@@ -65,7 +69,12 @@
this.enveloped.getRecipientInfo().add(ri);
}
+ @Override
+ public String toString() {
+ return this.enveloped.toString();
+ }
+
public static PKCS7DataEnveloped fromASN1(DEREncodable content) {
- throw new UnsupportedOperationException("TODO: can't create DataEnveloped from ASN1 yet");
+ return new PKCS7DataEnveloped(Envelope.fromASN1(content));
}
}// PKCS7DataEnveloped
Modified: trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/RecipInfo.java (1079 => 1080)
--- trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/RecipInfo.java 2008-07-27 16:10:46 UTC (rev 1079)
+++ trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/RecipInfo.java 2008-07-27 16:10:49 UTC (rev 1080)
@@ -27,8 +27,13 @@
***** END LICENSE BLOCK *****/
package org.jruby.ext.openssl.impl;
+import java.security.cert.X509Certificate;
import org.bouncycastle.asn1.ASN1OctetString;
-import java.security.cert.X509Certificate;
+import org.bouncycastle.asn1.DEREncodable;
+import org.bouncycastle.asn1.DERInteger;
+import org.bouncycastle.asn1.DERSequence;
+import org.bouncycastle.asn1.pkcs.IssuerAndSerialNumber;
+import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
/** PKCS7_RECIP_INFO
*
@@ -36,10 +41,9 @@
*/
public class RecipInfo {
private int version;
- private IssuerAndSerial issuerAndSerial;
- private String keyEncAlgor;
+ private IssuerAndSerialNumber issuerAndSerial;
+ private AlgorithmIdentifier keyEncAlgor;
private ASN1OctetString encKey;
- private X509Certificate cert;
/** c: PKCS7_RECIP_INFO_set
*
@@ -47,4 +51,123 @@
public void set(X509Certificate cert) {
// TODO: implement
}
+
+ @Override
+ public boolean equals(Object other) {
+ boolean ret = this == other;
+ if(!ret && (other instanceof RecipInfo)) {
+ RecipInfo o = (RecipInfo)other;
+ ret =
+ this.version == o.version &&
+ (this.issuerAndSerial == null ? o.issuerAndSerial == null : (this.issuerAndSerial.equals(o.issuerAndSerial))) &&
+ (this.keyEncAlgor == null ? o.keyEncAlgor == null : (this.keyEncAlgor.equals(o.keyEncAlgor))) &&
+ (this.encKey == null ? o.encKey == null : (this.encKey.equals(o.encKey)));
+ }
+ return ret;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = 31;
+ result = result + 13 * version;
+ result = result + ((issuerAndSerial == null) ? 0 : 13 * issuerAndSerial.hashCode());
+ result = result + ((keyEncAlgor == null) ? 0 : 13 * keyEncAlgor.hashCode());
+ result = result + ((encKey == null) ? 0 : 13 * encKey.hashCode());
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return "#<Recipient version="+version+" issuerAndSerial="+issuerAndSerial+" keyEncAlgor="+keyEncAlgor+" encKey="+encKey+">";
+ }
+
+ /**
+ * Get the <code>Version</code> value.
+ *
+ * @return an <code>int</code> value
+ */
+ public final int getVersion() {
+ return version;
+ }
+
+ /**
+ * Set the <code>Version</code> value.
+ *
+ * @param newVersion The new Version value.
+ */
+ public final void setVersion(final int newVersion) {
+ this.version = newVersion;
+ }
+
+ /**
+ * Get the <code>IssuerAndSerial</code> value.
+ *
+ * @return an <code>IssuerAndSerialNumber</code> value
+ */
+ public final IssuerAndSerialNumber getIssuerAndSerial() {
+ return issuerAndSerial;
+ }
+
+ /**
+ * Set the <code>IssuerAndSerial</code> value.
+ *
+ * @param newIssuerAndSerial The new IssuerAndSerial value.
+ */
+ public final void setIssuerAndSerial(final IssuerAndSerialNumber newIssuerAndSerial) {
+ this.issuerAndSerial = newIssuerAndSerial;
+ }
+
+ /**
+ * Get the <code>KeyEncAlgor</code> value.
+ *
+ * @return an <code>AlgorithmIdentifier</code> value
+ */
+ public final AlgorithmIdentifier getKeyEncAlgor() {
+ return keyEncAlgor;
+ }
+
+ /**
+ * Set the <code>KeyEncAlgor</code> value.
+ *
+ * @param newKeyEncAlgor The new KeyEncAlgor value.
+ */
+ public final void setKeyEncAlgor(final AlgorithmIdentifier newKeyEncAlgor) {
+ this.keyEncAlgor = newKeyEncAlgor;
+ }
+
+ /**
+ * Get the <code>EncKey</code> value.
+ *
+ * @return an <code>ASN1OctetString</code> value
+ */
+ public final ASN1OctetString getEncKey() {
+ return encKey;
+ }
+
+ /**
+ * Set the <code>EncKey</code> value.
+ *
+ * @param newEncKey The new EncKey value.
+ */
+ public final void setEncKey(final ASN1OctetString newEncKey) {
+ this.encKey = newEncKey;
+ }
+ /**
+ * RecipientInfo ::= SEQUENCE {
+ * version Version,
+ * issuerAndSerialNumber IssuerAndSerialNumber,
+ * keyEncryptionAlgorithm KeyEncryptionAlgorithmIdentifier,
+ * encryptedKey EncryptedKey }
+ *
+ * EncryptedKey ::= OCTET STRING
+ */
+ public static RecipInfo fromASN1(DEREncodable content) {
+ DERSequence sequence = (DERSequence)content;
+ RecipInfo ri = new RecipInfo();
+ ri.setVersion(((DERInteger)sequence.getObjectAt(0)).getValue().intValue());
+ ri.setIssuerAndSerial(IssuerAndSerialNumber.getInstance(sequence.getObjectAt(1)));
+ ri.setKeyEncAlgor(AlgorithmIdentifier.getInstance(sequence.getObjectAt(2)));
+ ri.setEncKey((ASN1OctetString)sequence.getObjectAt(3));
+ return ri;
+ }
}// RecipInfo
Modified: trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/SMIME.java (1079 => 1080)
--- trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/SMIME.java 2008-07-27 16:10:46 UTC (rev 1079)
+++ trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/SMIME.java 2008-07-27 16:10:49 UTC (rev 1080)
@@ -224,7 +224,9 @@
throw new PKCS7Exception(PKCS7.F_SMIME_READ_PKCS7, PKCS7.R_NO_SIG_CONTENT_TYPE);
}
- if(!"application/x-pkcs7-mime".equals(hdr.getValue()) &&
+ if(!"application/x-pkcs7-signature".equals(hdr.getValue()) &&
+ !"application/pkcs7-signature".equals(hdr.getValue()) &&
+ !"application/x-pkcs7-mime".equals(hdr.getValue()) &&
!"application/pkcs7-mime".equals(hdr.getValue())) {
throw new PKCS7Exception(PKCS7.F_SMIME_READ_PKCS7, PKCS7.R_SIG_INVALID_MIME_TYPE, "type: " + hdr.getValue());
}
Deleted: trunk/jopenssl/test/pkcs7_mime_encrypted.message (1079 => 1080)
--- trunk/jopenssl/test/pkcs7_mime_encrypted.message 2008-07-27 16:10:46 UTC (rev 1079)
+++ trunk/jopenssl/test/pkcs7_mime_encrypted.message 2008-07-27 16:10:49 UTC (rev 1080)
@@ -1,19 +0,0 @@
-MIME-Version: 1.0
-Message-Id: <[EMAIL PROTECTED]>
-Date: Tue, 31 Oct 2000 12:00:52 -0600 (Central Standard Time)
-From: User1
-To: User2
-Subject: Example 5.3
-Content-Type: application/pkcs7-mime;
- name=smime.p7m;
- smime-type=enveloped-data
-Content-Transfer-Encoding: base64
-Content-Disposition: attachment; filename=smime.p7m
-
-
-MIIBHgYJKoZIhvcNAQcDoIIBDzCCAQsCAQAxgcAwgb0CAQAwJjASMRAwDgYDVQQDEwdDYXJ
-sUlNBAhBGNGvHgABWvBHTbi7NXXHQMA0GCSqGSIb3DQEBAQUABIGAC3EN5nGIiJi2lsGPcP
-2iJ97a4e8kbKQz36zg6Z2i0yx6zYC4mZ7mX7FBs3IWg+f6KgCLx3M1eCbWx8+MDFbbpXadC
-DgO8/nUkUNYeNxJtuzubGgzoyEd8Ch4H/dd9gdzTd+taTEgS0ipdSJuNnkVY4/M652jKKHR
-LFf02hosdR8wQwYJKoZIhvcNAQcBMBQGCCqGSIb3DQMHBAgtaMXpRwZRNYAgDsiSf8Z9P43
-LrY4OxUk660cu1lXeCSFOSOpOJ7FuVyU=
Copied: trunk/jopenssl/test/pkcs7_mime_enveloped.message (from rev 1079, trunk/jopenssl/test/pkcs7_mime_encrypted.message) (0 => 1080)
--- trunk/jopenssl/test/pkcs7_mime_enveloped.message (rev 0)
+++ trunk/jopenssl/test/pkcs7_mime_enveloped.message 2008-07-27 16:10:49 UTC (rev 1080)
@@ -0,0 +1,19 @@
+MIME-Version: 1.0
+Message-Id: <[EMAIL PROTECTED]>
+Date: Tue, 31 Oct 2000 12:00:52 -0600 (Central Standard Time)
+From: User1
+To: User2
+Subject: Example 5.3
+Content-Type: application/pkcs7-mime;
+ name=smime.p7m;
+ smime-type=enveloped-data
+Content-Transfer-Encoding: base64
+Content-Disposition: attachment; filename=smime.p7m
+
+
+MIIBHgYJKoZIhvcNAQcDoIIBDzCCAQsCAQAxgcAwgb0CAQAwJjASMRAwDgYDVQQDEwdDYXJ
+sUlNBAhBGNGvHgABWvBHTbi7NXXHQMA0GCSqGSIb3DQEBAQUABIGAC3EN5nGIiJi2lsGPcP
+2iJ97a4e8kbKQz36zg6Z2i0yx6zYC4mZ7mX7FBs3IWg+f6KgCLx3M1eCbWx8+MDFbbpXadC
+DgO8/nUkUNYeNxJtuzubGgzoyEd8Ch4H/dd9gdzTd+taTEgS0ipdSJuNnkVY4/M652jKKHR
+LFf02hosdR8wQwYJKoZIhvcNAQcBMBQGCCqGSIb3DQMHBAgtaMXpRwZRNYAgDsiSf8Z9P43
+LrY4OxUk660cu1lXeCSFOSOpOJ7FuVyU=
Modified: trunk/jopenssl/test/test_java.rb (1079 => 1080)
--- trunk/jopenssl/test/test_java.rb 2008-07-27 16:10:46 UTC (rev 1079)
+++ trunk/jopenssl/test/test_java.rb 2008-07-27 16:10:49 UTC (rev 1080)
@@ -46,7 +46,7 @@
X509Name = org.bouncycastle.asn1.x509.X509Name
- MimeEncryptedString = File::read(File.join(File.dirname(__FILE__), 'pkcs7_mime_encrypted.message'))
+ MimeEnvelopedString = File::read(File.join(File.dirname(__FILE__), 'pkcs7_mime_enveloped.message'))
MimeSignedString = File::read(File.join(File.dirname(__FILE__), 'pkcs7_mime_signed.message'))
MultipartSignedString = File::read(File.join(File.dirname(__FILE__), 'pkcs7_multipart_signed.message'))
Modified: trunk/jopenssl/test/test_java_pkcs7.rb (1079 => 1080)
--- trunk/jopenssl/test/test_java_pkcs7.rb 2008-07-27 16:10:46 UTC (rev 1079)
+++ trunk/jopenssl/test/test_java_pkcs7.rb 2008-07-27 16:10:49 UTC (rev 1080)
@@ -319,7 +319,7 @@
ri = p7.add_recipient(X509Cert)
assert_equal 1, p7.get_enveloped.recipient_info.size
- assert_equal ri, p7.get_enveloped.recipient_info.get(0)
+ assert_equal ri, p7.get_enveloped.recipient_info.iterator.next
end
@@ -330,7 +330,7 @@
ri = p7.add_recipient(X509Cert)
assert_equal 1, p7.get_signed_and_enveloped.recipient_info.size
- assert_equal ri, p7.get_signed_and_enveloped.recipient_info.get(0)
+ assert_equal ri, p7.get_signed_and_enveloped.recipient_info.iterator.next
end
def test_add_signer_to_something_that_cant_have_signers
Modified: trunk/jopenssl/test/test_java_smime.rb (1079 => 1080)
--- trunk/jopenssl/test/test_java_smime.rb 2008-07-27 16:10:46 UTC (rev 1079)
+++ trunk/jopenssl/test/test_java_smime.rb 2008-07-27 16:10:49 UTC (rev 1080)
@@ -156,11 +156,22 @@
SMIME.new(mime).readPKCS7(bio, nil)
end
-
def test_read_pkcs7_happy_path_multipart
bio = BIO::from_string(MultipartSignedString)
mime = Mime::DEFAULT
p7 = SMIME.new(mime).readPKCS7(bio, nil)
end
+
+ def test_read_pkcs7_happy_path_without_multipart_enveloped
+ bio = BIO::from_string(MimeEnvelopedString)
+ mime = Mime::DEFAULT
+ p7 = SMIME.new(mime).readPKCS7(bio, nil)
+ end
+
+ def test_read_pkcs7_happy_path_without_multipart_signed
+ bio = BIO::from_string(MimeSignedString)
+ mime = Mime::DEFAULT
+ p7 = SMIME.new(mime).readPKCS7(bio, nil)
+ end
end
end