Modified: trunk/jopenssl/src/java/org/jruby/ext/openssl/OpenSSLImpl.java (1040 => 1041)
--- trunk/jopenssl/src/java/org/jruby/ext/openssl/OpenSSLImpl.java 2008-07-06 15:06:27 UTC (rev 1040)
+++ trunk/jopenssl/src/java/org/jruby/ext/openssl/OpenSSLImpl.java 2008-07-06 15:06:31 UTC (rev 1041)
@@ -78,12 +78,12 @@
ASN1.addObject(runtime, 18, "OU", "organizationalUnitName","2.5.4.11");
ASN1.addObject(runtime, 19, "RSA", "rsa","2.5.8.1.1");
ASN1.addObject(runtime, 20, null, "pkcs7","1.2.840.113549.1.7");
-ASN1.addObject(runtime, 21, null, "pkcs7-data","1.2.840.113549.1.7.1");
-ASN1.addObject(runtime, 22, null, "pkcs7-signedData","1.2.840.113549.1.7.2");
-ASN1.addObject(runtime, 23, null, "pkcs7-envelopedData","1.2.840.113549.1.7.3");
-ASN1.addObject(runtime, 24, null, "pkcs7-signedAndEnvelopedData","1.2.840.113549.1.7.4");
-ASN1.addObject(runtime, 25, null, "pkcs7-digestData","1.2.840.113549.1.7.5");
-ASN1.addObject(runtime, 26, null, "pkcs7-encryptedData","1.2.840.113549.1.7.6");
+ASN1.addObject(runtime, org.jruby.ext.openssl.impl.PKCS7.NID_pkcs7_data, null, "pkcs7-data","1.2.840.113549.1.7.1");
+ASN1.addObject(runtime, org.jruby.ext.openssl.impl.PKCS7.NID_pkcs7_signed, null, "pkcs7-signedData","1.2.840.113549.1.7.2");
+ASN1.addObject(runtime, org.jruby.ext.openssl.impl.PKCS7.NID_pkcs7_enveloped, null, "pkcs7-envelopedData","1.2.840.113549.1.7.3");
+ASN1.addObject(runtime, org.jruby.ext.openssl.impl.PKCS7.NID_pkcs7_signedAndEnveloped, null, "pkcs7-signedAndEnvelopedData","1.2.840.113549.1.7.4");
+ASN1.addObject(runtime, org.jruby.ext.openssl.impl.PKCS7.NID_pkcs7_digest, null, "pkcs7-digestData","1.2.840.113549.1.7.5");
+ASN1.addObject(runtime, org.jruby.ext.openssl.impl.PKCS7.NID_pkcs7_encrypted, null, "pkcs7-encryptedData","1.2.840.113549.1.7.6");
ASN1.addObject(runtime, 27, null, "pkcs3","1.2.840.113549.1.3");
ASN1.addObject(runtime, 28, null, "dhKeyAgreement","1.2.840.113549.1.3.1");
ASN1.addObject(runtime, 29, "DES-ECB", "des-ecb","1.3.14.3.2.6");
Modified: trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/PKCS7.java (1040 => 1041)
--- trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/PKCS7.java 2008-07-06 15:06:27 UTC (rev 1040)
+++ trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/PKCS7.java 2008-07-06 15:06:31 UTC (rev 1041)
@@ -34,13 +34,18 @@
*
* @author <a href="" PROTECTED]">Ola Bini</a>
*/
-public class PKCS7 {
+public class PKCS7 extends TypeDiscriminating {
+ public static final int NID_pkcs7_signed = 22;
+ public static final int NID_pkcs7_encrypted = 26;
+ public static final int NID_pkcs7_enveloped = 23;
+ public static final int NID_pkcs7_signedAndEnveloped = 24;
+ public static final int NID_pkcs7_data = 21;
+ public static final int NID_pkcs7_digest = 25;
+
private String asn1;
private int state; //used during processing
private int detached;
- private ASN1Encodable type;
-
/* content as defined by the type */
/* all encryption/message digests are applied to the 'contents',
* leaving out the 'type' field. */
@@ -68,7 +73,52 @@
/* Anything else */
private ASN1Encodable other;
+ public Object ctrl(int cmd, Object v, Object ignored) {
+ int ret = 0;
+ switch(cmd) {
+ case OP_SET_DETACHED_SIGNATURE:
+ if(isSigned()) {
+ ret = detached = ((Integer)v).intValue();
+ if(ret != 0 && sign.contents.isData()) {
+ sign.contents.data = ""
+ }
+ } else {
+ // TODO: ERR
+ ret = 0;
+ }
+ break;
+ case OP_GET_DETACHED_SIGNATURE:
+ if(isSigned()) {
+ if(sign == null || sign.contents.ptr == null) {
+ ret = 1;
+ } else {
+ ret = 0;
+ }
+ } else {
+ // TODO: ERR
+ ret = 0;
+ }
+ break;
+ default:
+ // TODO: ERR
+ ret = 0;
+ }
+ return Integer.valueOf(ret);
+ }
+
+ public void setDetached(int v) {
+ ctrl(OP_SET_DETACHED_SIGNATURE, Integer.valueOf(v), null);
+ }
+
+ public int getDetached() {
+ return ((Integer)ctrl(OP_GET_DETACHED_SIGNATURE, null, null)).intValue();
+ }
+
+ public boolean isDetached() {
+ return isSigned() && getDetached() != 0;
+ }
+
public static final int S_HEADER = 0;
public static final int S_BODY = 1;
public static final int S_TAIL = 2;
@@ -180,5 +230,17 @@
public static final int R_UNSUPPORTED_CONTENT_TYPE = 112;
public static final int R_WRONG_CONTENT_TYPE = 113;
public static final int R_WRONG_PKCS7_TYPE = 114;
+
+ public void setSign(Signed sign) {
+ this.sign = sign;
+ }
+
+ public void setData(ASN1OctetString data) {
+ this.data = ""
+ }
+
+ public ASN1OctetString getData() {
+ return this.data;
+ }
}// PKCS7
Copied: trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/TypeDiscriminating.java (from rev 1040, trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/Digest.java) (0 => 1041)
--- trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/TypeDiscriminating.java (rev 0)
+++ trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/TypeDiscriminating.java 2008-07-06 15:06:31 UTC (rev 1041)
@@ -0,0 +1,65 @@
+/***** BEGIN LICENSE BLOCK *****
+ * Version: CPL 1.0/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Common Public
+ * License Version 1.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Software distributed under the License is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * rights and limitations under the License.
+ *
+ * Copyright (C) 2008 Ola Bini <[EMAIL PROTECTED]>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either of the GNU General Public License Version 2 or later (the "GPL"),
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the CPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the CPL, the GPL or the LGPL.
+ ***** END LICENSE BLOCK *****/
+package org.jruby.ext.openssl.impl;
+
+/**
+ * @author <a href="" PROTECTED]">Ola Bini</a>
+ */
+public abstract class TypeDiscriminating {
+ protected int type;
+
+ public boolean isSigned() {
+ return this.type == PKCS7.NID_pkcs7_signed;
+ }
+
+ public boolean isEncrypted() {
+ return this.type == PKCS7.NID_pkcs7_encrypted;
+ }
+
+ public boolean isEnveloped() {
+ return this.type == PKCS7.NID_pkcs7_enveloped;
+ }
+
+ public boolean isSignedAndEnveloped() {
+ return this.type == PKCS7.NID_pkcs7_signedAndEnveloped;
+ }
+
+ public boolean isData() {
+ return this.type == PKCS7.NID_pkcs7_data;
+ }
+
+ public boolean isDigest() {
+ return this.type == PKCS7.NID_pkcs7_digest;
+ }
+
+ // helpers for testing
+
+ public void setType(int type) {
+ this.type = type;
+ }
+}// TypeDiscriminating
Modified: trunk/jopenssl/test/test_java_pkcs7.rb (1040 => 1041)
--- trunk/jopenssl/test/test_java_pkcs7.rb 2008-07-06 15:06:27 UTC (rev 1040)
+++ trunk/jopenssl/test/test_java_pkcs7.rb 2008-07-06 15:06:31 UTC (rev 1041)
@@ -3,8 +3,13 @@
if defined?(JRUBY_VERSION)
require "java"
$CLASSPATH << 'pkg/classes'
+ $CLASSPATH << 'lib/bcprov-jdk14-139.jar'
class TestJavaPKCS7 < Test::Unit::TestCase
+ module ASN1
+ OctetString = org.bouncycastle.asn1.DEROctetString
+ end
+
PKCS7 = org.jruby.ext.openssl.impl.PKCS7 unless defined?(PKCS7)
Digest = org.jruby.ext.openssl.impl.Digest unless defined?(Digest)
EncContent = org.jruby.ext.openssl.impl.EncContent unless defined?(EncContent)
@@ -16,8 +21,101 @@
Signed = org.jruby.ext.openssl.impl.Signed unless defined?(Signed)
SignerInfo = org.jruby.ext.openssl.impl.SignerInfo unless defined?(SignerInfo)
- def test_truth
- assert true
+ def test_is_signed
+ p7 = PKCS7.new
+ p7.type = PKCS7::NID_pkcs7_signed
+ assert p7.signed?
+ assert !p7.encrypted?
+ assert !p7.enveloped?
+ assert !p7.signed_and_enveloped?
+ assert !p7.data?
+ assert !p7.digest?
end
+
+ def test_is_encrypted
+ p7 = PKCS7.new
+ p7.type = PKCS7::NID_pkcs7_encrypted
+ assert !p7.signed?
+ assert p7.encrypted?
+ assert !p7.enveloped?
+ assert !p7.signed_and_enveloped?
+ assert !p7.data?
+ assert !p7.digest?
+ end
+
+ def test_is_enveloped
+ p7 = PKCS7.new
+ p7.type = PKCS7::NID_pkcs7_enveloped
+ assert !p7.signed?
+ assert !p7.encrypted?
+ assert p7.enveloped?
+ assert !p7.signed_and_enveloped?
+ assert !p7.data?
+ assert !p7.digest?
+ end
+
+ def test_is_signed_and_enveloped
+ p7 = PKCS7.new
+ p7.type = PKCS7::NID_pkcs7_signedAndEnveloped
+ assert !p7.signed?
+ assert !p7.encrypted?
+ assert !p7.enveloped?
+ assert p7.signed_and_enveloped?
+ assert !p7.data?
+ assert !p7.digest?
+ end
+
+ def test_is_data
+ p7 = PKCS7.new
+ p7.type = PKCS7::NID_pkcs7_data
+ assert !p7.signed?
+ assert !p7.encrypted?
+ assert !p7.enveloped?
+ assert !p7.signed_and_enveloped?
+ assert p7.data?
+ assert !p7.digest?
+ end
+
+ def test_is_digest
+ p7 = PKCS7.new
+ p7.type = PKCS7::NID_pkcs7_digest
+ assert !p7.signed?
+ assert !p7.encrypted?
+ assert !p7.enveloped?
+ assert !p7.signed_and_enveloped?
+ assert !p7.data?
+ assert p7.digest?
+ end
+
+ def test_set_detached
+ p7 = PKCS7.new
+ p7.type = PKCS7::NID_pkcs7_signed
+
+ sign = Signed.new
+ p7.sign = sign
+
+ test_p7 = PKCS7.new
+ test_p7.type = PKCS7::NID_pkcs7_data
+ test_p7.data = ""
+ sign.contents = test_p7
+
+ p7.detached = 2
+ assert_equal 1, p7.get_detached
+ assert_equal nil, test_p7.data
+ end
+
+ # TODO implement these tests too
+ def __test
+ p7.detached = 0
+ assert_equal 0, p7.get_detached
+
+ p7.type = PKCS7::NID_pkcs7_signed
+ p7.detached = 1
+ assert p7.detached?
+
+ p7.type = PKCS7::NID_pkcs7_data
+ p7.detached = 1
+ assert !p7.detached?
+ end
end
end