Diff
Modified: trunk/jopenssl/src/java/org/jruby/ext/openssl/PKCS7.java (1099 => 1100)
--- trunk/jopenssl/src/java/org/jruby/ext/openssl/PKCS7.java 2008-08-08 10:54:44 UTC (rev 1099)
+++ trunk/jopenssl/src/java/org/jruby/ext/openssl/PKCS7.java 2008-08-11 12:36:54 UTC (rev 1100)
@@ -41,22 +41,14 @@
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
+import java.util.Set;
import javax.security.auth.x500.X500Principal;
import org.bouncycastle.asn1.ASN1InputStream;
import org.bouncycastle.asn1.ASN1Object;
-import org.bouncycastle.asn1.cms.ContentInfo;
import org.bouncycastle.asn1.x509.TBSCertificateStructure;
-import org.bouncycastle.cms.CMSEnvelopedData;
-import org.bouncycastle.cms.CMSEnvelopedDataGenerator;
-import org.bouncycastle.cms.CMSException;
-import org.bouncycastle.cms.CMSProcessableByteArray;
-import org.bouncycastle.cms.CMSSignedData;
-import org.bouncycastle.cms.CMSSignedDataGenerator;
-import org.bouncycastle.cms.RecipientInformation;
-import org.bouncycastle.cms.SignerInformation;
-import org.bouncycastle.cms.SignerInformationStore;
import org.jruby.Ruby;
import org.jruby.RubyArray;
+import org.jruby.RubyBignum;
import org.jruby.RubyClass;
import org.jruby.RubyFile;
import org.jruby.RubyModule;
@@ -68,7 +60,9 @@
import org.jruby.ext.openssl.impl.BIO;
import org.jruby.ext.openssl.impl.MemBIO;
import org.jruby.ext.openssl.impl.Mime;
+import org.jruby.ext.openssl.impl.RecipInfo;
import org.jruby.ext.openssl.impl.SMIME;
+import org.jruby.ext.openssl.impl.SignerInfoWithPkey;
import org.jruby.ext.openssl.x509store.PEMInputOutput;
import org.jruby.ext.openssl.x509store.StoreContext;
import org.jruby.ext.openssl.x509store.X509AuxCertificate;
@@ -323,8 +317,24 @@
@JRubyMethod
public IRubyObject recipients() {
- System.err.println("WARNING: un.implemented method called PKCS7#recipients");
- return getRuntime().getNil();
+ List<RecipInfo> sk = null;
+
+ if(p7.isEnveloped()) {
+ sk = p7.getEnveloped().getRecipientInfo();
+ } else if(p7.isSignedAndEnveloped()) {
+ sk = p7.getSignedAndEnveloped().getRecipientInfo();
+ } else {
+ sk = null;
+ }
+ if(sk == null) {
+ return getRuntime().newArray();
+ }
+
+ RubyArray ary = getRuntime().newArray(sk.size());
+ for(RecipInfo ri : sk) {
+ ary.append(RecipientInfo.create(getRuntime(), ri));
+ }
+ return ary;
}
@JRubyMethod
@@ -406,7 +416,7 @@
cPKCS7Signer.defineAnnotatedMethods(SignerInfo.class);
}
- public static SignerInfo create(Ruby runtime, SignerInformation info) {
+ public static SignerInfo create(Ruby runtime, SignerInfoWithPkey info) {
SignerInfo sinfo = new SignerInfo(runtime, (RubyClass)(((RubyModule)(runtime.getModule("OpenSSL").getConstant("PKCS7"))).getConstant("SignerInfo")));
sinfo.initWithSignerInformation(info);
return sinfo;
@@ -416,7 +426,7 @@
super(runtime,type);
}
- private void initWithSignerInformation(SignerInformation info) {
+ private void initWithSignerInformation(SignerInfoWithPkey info) {
}
@@ -463,15 +473,15 @@
}
- public static RecipientInfo create(Ruby runtime, RecipientInformation info) {
+ public static RecipientInfo create(Ruby runtime, RecipInfo info) {
RecipientInfo rinfo = new RecipientInfo(runtime, (RubyClass)(((RubyModule)(runtime.getModule("OpenSSL").getConstant("PKCS7"))).getConstant("RecipientInfo")));
rinfo.initWithRecipientInformation(info);
return rinfo;
}
- private RecipientInformation info;
+ private RecipInfo info;
- private void initWithRecipientInformation(RecipientInformation info) {
+ private void initWithRecipientInformation(RecipInfo info) {
this.info = info;
}
@@ -483,14 +493,12 @@
@JRubyMethod
public IRubyObject issuer() {
- System.err.println("WARNING: un-implemented method called RecipientInfo#issuer");
- return getRuntime().getNil();
+ return X509Name.create(getRuntime(), info.getIssuerAndSerial().getName());
}
@JRubyMethod
public IRubyObject serial() {
- System.err.println("WARNING: un-implemented method called RecipientInfo#serial");
- return getRuntime().getNil();
+ return RubyBignum.bignorm(getRuntime(), info.getIssuerAndSerial().getCertificateSerialNumber().getValue());
}
@JRubyMethod
Modified: trunk/jopenssl/src/java/org/jruby/ext/openssl/X509Name.java (1099 => 1100)
--- trunk/jopenssl/src/java/org/jruby/ext/openssl/X509Name.java 2008-08-08 10:54:44 UTC (rev 1099)
+++ trunk/jopenssl/src/java/org/jruby/ext/openssl/X509Name.java 2008-08-11 12:36:54 UTC (rev 1100)
@@ -117,7 +117,30 @@
values.add(value);
types.add(type);
}
+
+ public static X509Name create(Ruby runtime, org.bouncycastle.asn1.x509.X509Name realName) {
+ X509Name name = new X509Name(runtime, ((RubyModule)(runtime.getModule("OpenSSL").getConstant("X509"))).getClass("Name"));
+ name.fromASN1Sequence((ASN1Sequence)realName.getDERObject());
+ return name;
+ }
+ void fromASN1Sequence(ASN1Sequence seq) {
+ oids = new ArrayList<Object>();
+ values = new ArrayList<Object>();
+ types = new ArrayList<Object>();
+ for(Enumeration enm = seq.getObjects();enm.hasMoreElements();) {
+ ASN1Sequence value = (ASN1Sequence)(((ASN1Set)enm.nextElement()).getObjectAt(0));
+ oids.add(value.getObjectAt(0));
+ if(value.getObjectAt(1) instanceof DERString) {
+ values.add(((DERString)value.getObjectAt(1)).getString());
+ } else {
+ values.add(null);
+ }
+ types.add(getRuntime().newFixnum(ASN1.idForClass(value.getObjectAt(1).getClass())));
+ }
+ }
+
+
@JRubyMethod(rest=true, frame=true)
public IRubyObject initialize(IRubyObject[] args, Block unusedBlock) {
if(org.jruby.runtime.Arity.checkArgumentCount(getRuntime(),args,0,2) == 0) {
@@ -152,20 +175,7 @@
}
} else {
try {
- ASN1Sequence seq = (ASN1Sequence)new ASN1InputStream(OpenSSLImpl.to_der_if_possible(arg).convertToString().getBytes()).readObject();
- oids = new ArrayList<Object>();
- values = new ArrayList<Object>();
- types = new ArrayList<Object>();
- for(Enumeration enm = seq.getObjects();enm.hasMoreElements();) {
- ASN1Sequence value = (ASN1Sequence)(((ASN1Set)enm.nextElement()).getObjectAt(0));
- oids.add(value.getObjectAt(0));
- if(value.getObjectAt(1) instanceof DERString) {
- values.add(((DERString)value.getObjectAt(1)).getString());
- } else {
- values.add(null);
- }
- types.add(getRuntime().newFixnum(ASN1.idForClass(value.getObjectAt(1).getClass())));
- }
+ fromASN1Sequence((ASN1Sequence)new ASN1InputStream(OpenSSLImpl.to_der_if_possible(arg).convertToString().getBytes()).readObject());
} catch(Exception e) {
System.err.println("exception in init for X509Name: " + e);
}
Modified: trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/Envelope.java (1099 => 1100)
--- trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/Envelope.java 2008-08-08 10:54:44 UTC (rev 1099)
+++ trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/Envelope.java 2008-08-11 12:36:54 UTC (rev 1100)
@@ -56,7 +56,7 @@
/**
* Describe recipientInfo here.
*/
- private Set<RecipInfo> recipientInfo = new HashSet<RecipInfo>();
+ private List<RecipInfo> recipientInfo = new ArrayList<RecipInfo>();
/**
* Get the <code>Version</code> value.
@@ -99,7 +99,7 @@
*
* @return a <code>Set<RecipInfo></code> value
*/
- public final Set<RecipInfo> getRecipientInfo() {
+ public final List<RecipInfo> getRecipientInfo() {
return recipientInfo;
}
@@ -108,7 +108,7 @@
*
* @param newRecipientInfo The new RecipientInfo value.
*/
- public final void setRecipientInfo(final Set<RecipInfo> newRecipientInfo) {
+ public final void setRecipientInfo(final List<RecipInfo> newRecipientInfo) {
this.recipientInfo = newRecipientInfo;
}
@@ -158,9 +158,9 @@
return new DERSet(vector);
}
- private static Set<RecipInfo> recipientInfosFromASN1Set(DEREncodable content) {
+ private static List<RecipInfo> recipientInfosFromASN1Set(DEREncodable content) {
ASN1Set set = (ASN1Set)content;
- Set<RecipInfo> result = new HashSet<RecipInfo>();
+ List<RecipInfo> result = new ArrayList<RecipInfo>();
for(Enumeration<?> e = set.getObjects(); e.hasMoreElements();) {
result.add(RecipInfo.fromASN1((DEREncodable)e.nextElement()));
}
Modified: trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/PKCS7.java (1099 => 1100)
--- trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/PKCS7.java 2008-08-08 10:54:44 UTC (rev 1099)
+++ trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/PKCS7.java 2008-08-11 12:36:54 UTC (rev 1100)
@@ -330,7 +330,7 @@
ASN1OctetString os = null;
int i = this.data.getType();
state = S_HEADER;
- Set<RecipInfo> rsk = null;
+ List<RecipInfo> rsk = null;
AlgorithmIdentifier xalg = null;
AlgorithmIdentifier xa = null;
Cipher evpCipher = null;
Modified: trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/SignEnvelope.java (1099 => 1100)
--- trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/SignEnvelope.java 2008-08-08 10:54:44 UTC (rev 1099)
+++ trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/SignEnvelope.java 2008-08-11 12:36:54 UTC (rev 1100)
@@ -71,7 +71,7 @@
/**
* Describe recipientInfo here.
*/
- private Set<RecipInfo> recipientInfo = new HashSet<RecipInfo>();
+ private List<RecipInfo> recipientInfo = new ArrayList<RecipInfo>();
/**
* Get the <code>Version</code> value.
@@ -114,7 +114,7 @@
*
* @return a <code>Set<RecipInfo></code> value
*/
- public final Set<RecipInfo> getRecipientInfo() {
+ public final List<RecipInfo> getRecipientInfo() {
return recipientInfo;
}
@@ -123,7 +123,7 @@
*
* @param newRecipientInfo The new RecipientInfo value.
*/
- public final void setRecipientInfo(final Set<RecipInfo> newRecipientInfo) {
+ public final void setRecipientInfo(final List<RecipInfo> newRecipientInfo) {
this.recipientInfo = newRecipientInfo;
}