Title: [1073] trunk/jopenssl: Add test messages, better tests and more implementations of mime and smime functionality.

Diff

Modified: trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/BIO.java (1072 => 1073)


--- trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/BIO.java	2008-07-27 16:10:27 UTC (rev 1072)
+++ trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/BIO.java	2008-07-27 16:10:30 UTC (rev 1073)
@@ -33,8 +33,21 @@
  */
 public class BIO {
     public static BIO fromString(String input) {
-        return new StringBIO(input);
+        MemBIO bio = new MemBIO();
+        byte[] buf = null;
+        try {
+            buf = input.getBytes("ISO8859-1");
+        } catch(Exception e) {}
+        bio.write(buf, buf.length);
+        return bio;
     }
+
+    /** c: BIO_new(BIO_s_mem())
+     *
+     */
+    public static BIO mem() {
+        return new MemBIO();
+    }
     
     /** c: BIO_flush
      *
@@ -57,4 +70,19 @@
         // TODO: implement
         return -1;
     }
+
+    /** c: BIO_write
+     *
+     */
+    public int write(byte[] out, int len) {
+        // TODO: implement
+        return -1;
+    }
+
+    /** c: BIO_set_mem_eof_return
+     *
+     */
+    public void setMemEofReturn(int value) {
+        // TODO: implement
+    }
 }// BIO

Copied: trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/MemBIO.java (from rev 1072, trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/BIO.java) (0 => 1073)


--- trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/MemBIO.java	                        (rev 0)
+++ trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/MemBIO.java	2008-07-27 16:10:30 UTC (rev 1073)
@@ -0,0 +1,84 @@
+/***** 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 class MemBIO extends BIO {
+    private byte[] buffer = new byte[1024];
+    private int wpointer = 0;
+    private int rpointer = 0;
+    private int slen = 0;
+    
+    private void realloc() {
+        byte[] newBuffer = new byte[buffer.length*2];
+        System.arraycopy(buffer, 0, newBuffer, 0, wpointer);
+        buffer = newBuffer;
+    }
+
+    public int gets(byte[] in, int len) {
+        if(rpointer == slen) {
+            return 0;
+        }
+
+        int i=0;
+        for(;i<len && rpointer<slen; i++, rpointer++) {
+            in[i] = buffer[rpointer];
+
+            if(in[i] == '\n') {
+                i++; rpointer++;
+                break;
+            }
+        }
+
+        return i;
+    }
+
+    public int write(byte[] out, int len) {
+        while(wpointer + len > buffer.length) {
+            realloc();
+        }
+
+        System.arraycopy(out, 0, buffer, wpointer, len);
+        wpointer += len;
+        slen += len;
+
+        return len;
+    }
+
+    @Override
+    public String toString() {
+        try {
+            return "<MemBIO w:" + wpointer + " r:" + rpointer + " buf:\"" + new String(buffer,rpointer,slen-rpointer) + "\">";
+        } catch(Exception e) {}
+
+        return null;
+    }
+}// MemBIO

Modified: trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/Mime.java (1072 => 1073)


--- trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/Mime.java	2008-07-27 16:10:27 UTC (rev 1072)
+++ trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/Mime.java	2008-07-27 16:10:30 UTC (rev 1073)
@@ -109,6 +109,7 @@
             }
 
             public List<MimeHeader> parseHeaders(BIO bio) {
+                mimeDebug("\n!!!!!!!!!!!!!!!!!\n" + bio + "\n^^^^^^^^^^^^^^^^^^^^^^^^\n"); 
                 int state = 0;
                 byte[] linebuf = new byte[MAX_SMLEN];
                 int len = 0;
@@ -196,7 +197,7 @@
                         mimeDebug("creating new: " + q + ":" + p);
                         mhdr.getParams().add(new MimeParam(ntmp, stripEnds(linebuf, q, p)));
                     }
-                    if(p == len) {
+                    if(p == 0) {
                         break;
                     }
                 }

Modified: trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/SMIME.java (1072 => 1073)


--- trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/SMIME.java	2008-07-27 16:10:27 UTC (rev 1072)
+++ trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/SMIME.java	2008-07-27 16:10:30 UTC (rev 1073)
@@ -27,6 +27,7 @@
  ***** END LICENSE BLOCK *****/
 package org.jruby.ext.openssl.impl;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
@@ -35,6 +36,9 @@
  * @author <a href="" PROTECTED]">Ola Bini</a>
  */
 public class SMIME {
+    private final static int MAX_SMLEN = 1024;
+    private final static byte[] NEWLINE = new byte[]{'\r','\n'};
+
     private Mime mime;
 
     public SMIME() {
@@ -45,6 +49,75 @@
         this.mime = mime;
     }
 
+    private static boolean equals(byte[] first, int firstIndex, byte[] second, int secondIndex, int length) {
+        int len = length;
+        for(int i=firstIndex, 
+                j=secondIndex, 
+                flen=first.length, 
+                slen=second.length;
+            i<flen && 
+                j<slen && 
+                len>0;
+            i++, j++, len--) {
+
+            if(first[i] != second[j]) {
+                return false;
+            }
+        }
+        return len == 0;
+    }
+
+    /* c: static strip_eol
+     *
+     */
+    private boolean stripEol(byte[] linebuf, int[] plen) {
+        int len = plen[0];
+        boolean isEol = false;
+        
+        for(int p = len - 1; len > 0; len--, p--) {
+            byte c = linebuf[p];
+            if(c == '\n') {
+                isEol = true; 
+            } else if(c != '\r') {
+                break;
+            }
+            
+        }
+        plen[0] = len;
+        return isEol;
+    }
+
+    /* c: static mime_bound_check
+     *
+     */
+    private int boundCheck(byte[] line, int linelen, byte[] bound, int blen) {
+        if(linelen == -1) {
+            linelen = line.length;
+        }
+
+        if(blen == -1) {
+            blen = bound.length;
+        }
+
+        // Quickly eliminate if line length too short
+        if(blen + 2 > linelen) {
+            return 0;
+        }
+
+        if(line[0] == '-' && 
+           line[1] == '-' &&
+           equals(line, 2, bound, 0, blen)) {
+            if(line.length>=(blen+4) &&
+               line[2 + blen] == '-' &&
+               line[2 + blen + 1] == '-') {
+                return 2;
+            } else {
+                return 1;
+            }
+        }
+        return 0;
+    }
+
     /* c: B64_read_PKCS7
      *
      */
@@ -55,8 +128,49 @@
     /* c: static multi_split
      *
      */
-    public List<BIO> multiSplit(BIO bio, String boundary) {
-        return Arrays.<BIO>asList(null, null);
+    public List<BIO> multiSplit(BIO bio, byte[] bound) {
+        List<BIO> parts = new ArrayList<BIO>();
+        byte[] linebuf = new byte[MAX_SMLEN];
+        int blen = bound.length;
+        boolean eol = false;
+        int len = 0;
+        int part = 0;
+        int state = 0;
+        boolean first = true;
+        BIO bpart = null;
+
+        while((len = bio.gets(linebuf, MAX_SMLEN)) > 0) {
+            state = boundCheck(linebuf, len, bound, blen);
+            if(state == 1) {
+                first = true;
+                part++;
+            } else if(state == 2) {
+                parts.add(bpart);
+                return parts;
+            } else if(part != 0) {
+                // strip CR+LF from linebuf
+                int[] tmp = new int[] {len};
+                boolean nextEol = stripEol(linebuf, tmp);
+                len = tmp[0];
+
+                if(first) {
+                    first = false;
+                    if(bpart != null) {
+                        parts.add(bpart);
+                    }
+                    bpart = BIO.mem();
+                    bpart.setMemEofReturn(0);
+                } else if(eol) {
+                    bpart.write(NEWLINE, 2);
+                }
+                eol = nextEol;
+                if(len != 0) {
+                    bpart.write(linebuf, len);
+                }
+            }
+        }
+
+        return parts;
     }
 
     /* c: SMIME_read_PKCS7
@@ -83,13 +197,43 @@
                 throw new PKCS7Exception(PKCS7.F_SMIME_READ_PKCS7, PKCS7.R_NO_MULTIPART_BOUNDARY);
             }
 
-            List<BIO> parts = multiSplit(bio, prm.getParamValue());
+            byte[] boundary = null;
+            try {
+                boundary = prm.getParamValue().getBytes("ISO8859-1");
+            } catch(Exception e) {
+                throw new PKCS7Exception(PKCS7.F_SMIME_READ_PKCS7, PKCS7.R_NO_MULTIPART_BOUNDARY);
+            }
+
+            List<BIO> parts = multiSplit(bio, boundary);
             if(parts == null || parts.size() != 2) {
                 throw new PKCS7Exception(PKCS7.F_SMIME_READ_PKCS7, PKCS7.R_NO_MULTIPART_BODY_FAILURE);
             }
 
+            BIO p7in = parts.get(1);
 
-            return null;
+            headers = mime.parseHeaders(p7in);
+
+            if(headers == null) {
+                throw new PKCS7Exception(PKCS7.F_SMIME_READ_PKCS7, PKCS7.R_MIME_SIG_PARSE_ERROR);
+            }
+
+            hdr = mime.findHeader(headers, "content-type");
+            if(hdr == null || hdr.getValue() == null) {
+                throw new PKCS7Exception(PKCS7.F_SMIME_READ_PKCS7, PKCS7.R_NO_SIG_CONTENT_TYPE);
+            }
+
+            if(!"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());
+            }
+
+            PKCS7 p7 = readPKCS7Base64(bio);
+
+            if(bcont != null && bcont.length>0) {
+                bcont[0] = parts.get(0);
+            }
+
+            return p7;
         }
         
         if(!"application/x-pkcs7-mime".equals(hdr.getValue()) &&
@@ -98,50 +242,5 @@
         }
 
         return readPKCS7Base64(bio);
-
-// 	/* Handle multipart/signed */
-
-
-// 		/* Parse the signature piece */
-// 		p7in = sk_BIO_value(parts, 1);
-
-// 		if (!(headers = mime_parse_hdr(p7in))) {
-// 			PKCS7err(PKCS7_F_SMIME_READ_PKCS7,PKCS7_R_MIME_SIG_PARSE_ERROR);
-// 			sk_BIO_pop_free(parts, BIO_vfree);
-// 			return NULL;
-// 		}
-
-// 		/* Get content type */
-
-// 		if(!(hdr = mime_hdr_find(headers, "content-type")) ||
-// 								 !hdr->value) {
-// 			sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
-// 			PKCS7err(PKCS7_F_SMIME_READ_PKCS7, PKCS7_R_NO_SIG_CONTENT_TYPE);
-// 			return NULL;
-// 		}
-
-// 		if(strcmp(hdr->value, "application/x-pkcs7-signature") &&
-// 			strcmp(hdr->value, "application/pkcs7-signature")) {
-// 			sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
-// 			PKCS7err(PKCS7_F_SMIME_READ_PKCS7,PKCS7_R_SIG_INVALID_MIME_TYPE);
-// 			ERR_add_error_data(2, "type: ", hdr->value);
-// 			sk_BIO_pop_free(parts, BIO_vfree);
-// 			return NULL;
-// 		}
-// 		sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
-// 		/* Read in PKCS#7 */
-// 		if(!(p7 = B64_read_PKCS7(p7in))) {
-// 			PKCS7err(PKCS7_F_SMIME_READ_PKCS7,PKCS7_R_PKCS7_SIG_PARSE_ERROR);
-// 			sk_BIO_pop_free(parts, BIO_vfree);
-// 			return NULL;
-// 		}
-
-// 		if(bcont) {
-// 			*bcont = sk_BIO_value(parts, 0);
-// 			BIO_free(p7in);
-// 			sk_BIO_free(parts);
-// 		} else sk_BIO_pop_free(parts, BIO_vfree);
-// 		return p7;
-// 	}
     }
 }

Added: trunk/jopenssl/test/pkcs7_mime_encrypted.message (0 => 1073)


--- trunk/jopenssl/test/pkcs7_mime_encrypted.message	                        (rev 0)
+++ trunk/jopenssl/test/pkcs7_mime_encrypted.message	2008-07-27 16:10:30 UTC (rev 1073)
@@ -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=

Added: trunk/jopenssl/test/pkcs7_mime_signed.message (0 => 1073)


--- trunk/jopenssl/test/pkcs7_mime_signed.message	                        (rev 0)
+++ trunk/jopenssl/test/pkcs7_mime_signed.message	2008-07-27 16:10:30 UTC (rev 1073)
@@ -0,0 +1,30 @@
+MIME-Version: 1.0
+To: [EMAIL PROTECTED]
+From: [EMAIL PROTECTED]
+Subject: Example 4.9
+Message-Id: <[EMAIL PROTECTED]>
+Date: Thu, 31 Oct 2002 16:45:14 -0300
+Content-Type: application/pkcs7-mime; smime-type=signed-data;
+  name=smime.p7m
+Content-Transfer-Encoding: base64
+Content-Disposition: attachment; filename=smime.p7m
+
+
+MIIDmQYJKoZIhvcNAQcCoIIDijCCA4YCAQExCTAHBgUrDgMCGjAtBgkqhkiG9w0BBwGgIAQ
+eDQpUaGlzIGlzIHNvbWUgc2FtcGxlIGNvbnRlbnQuoIIC4DCCAtwwggKboAMCAQICAgDIMA
+kGByqGSM44BAMwEjEQMA4GA1UEAxMHQ2FybERTUzAeFw05OTA4MTcwMTEwNDlaFw0zOTEyM
+zEyMzU5NTlaMBMxETAPBgNVBAMTCEFsaWNlRFNTMIIBtjCCASsGByqGSM44BAEwggEeAoGB
+AIGNze2D6gqeOT7CSCij5EeT3Q7XqA7sU8WrhAhP/5Thc0h+DNbzREjR/p+vpKGJL+HZMMg
+23j+bv7dM3F9piuR10DcMkQiVm96nXvn89J8v3UOoi1TxP7AHCEdNXYjDw7Wz41UIddU5dh
+DEeL3/nbCElzfy5FEbteQJllzzflvbAhUA4kemGkVmuBPG2o+4NyErYov3k80CgYAmONAUi
+TKqOfs+bdlLWWpMdiM5BAI1XPLLGjDDHlBd3ZtZ4s2qBT1YwHuiNrhuB699ikIlp/R1z0oI
+Xks+kPht6pzJIYo7dhTpzi5dowfNI4W4LzABfG1JiRGJNkS9+MiVSlNWteL5c+waYTYfEX/
+Cve3RUP+YdMLRgUpgObo2OQOBhAACgYBc47ladRSWC6l63eM/qeysXty9txMRNKYWiSgRI9
+k0hmd1dRMSPUNbb+VRv/qJ8qIbPiR9PQeNW2PIu0WloErjhdbOBoA/6CN+GvIkq1MauCcNH
+u8Iv2YUgFxirGX6FYvxuzTU0pY39mFHssQyhPB+QUD9RqdjTjPypeL08oPluKOBgTB/MAwG
+A1UdEwEB/wQCMAAwDgYDVR0PAQH/BAQDAgbAMB8GA1UdIwQYMBaAFHBEPoIub4feStN14z0
+gvEMrk/EfMB0GA1UdDgQWBBS+bKGz48H37UNwpM4TAeL945f+zTAfBgNVHREEGDAWgRRBbG
+ljZURTU0BleGFtcGxlLmNvbTAJBgcqhkjOOAQDAzAAMC0CFFUMpBkfQiuJcSIzjYNqtT1na
+79FAhUAn2FTUlQLXLLd2ud2HeIQUltDXr0xYzBhAgEBMBgwEjEQMA4GA1UEAxMHQ2FybERT
+UwICAMgwBwYFKw4DAhowCQYHKoZIzjgEAwQuMCwCFD1cSW6LIUFzeXle3YI5SKSBer/sAhQ
+mCq7s/CTFHOEjgASeUjbMpx5g6A==

Added: trunk/jopenssl/test/pkcs7_multipart_signed.message (0 => 1073)


--- trunk/jopenssl/test/pkcs7_multipart_signed.message	                        (rev 0)
+++ trunk/jopenssl/test/pkcs7_multipart_signed.message	2008-07-27 16:10:30 UTC (rev 1073)
@@ -0,0 +1,45 @@
+MIME-Version: 1.0
+To: [EMAIL PROTECTED]
+From: [EMAIL PROTECTED]
+Subject: Example 4.8
+Message-Id: <[EMAIL PROTECTED]>
+Date: Fri, 06 Sep 2002 00:25:21 -0300
+Content-Type: multipart/signed;
+  micalg=SHA1;
+  boundary="----=_NextBoundry____Fri,_06_Sep_2002_00:25:21";
+  protocol="application/pkcs7-signature"
+
+		
+This is a multi-part message in MIME format.
+
+		
+------=_NextBoundry____Fri,_06_Sep_2002_00:25:21
+
+This is some sample content.
+		
+------=_NextBoundry____Fri,_06_Sep_2002_00:25:21
+Content-Type: application/pkcs7-mime; name=smime.p7s
+Content-Transfer-Encoding: base64
+Content-Disposition: attachment; filename=smime.p7s
+
+
+MIIDdwYJKoZIhvcNAQcCoIIDaDCCA2QCAQExCTAHBgUrDgMCGjALBgkqhkiG9w0BBwGgggL
+gMIIC3DCCApugAwIBAgICAMgwCQYHKoZIzjgEAzASMRAwDgYDVQQDEwdDYXJsRFNTMB4XDT
+k5MDgxNzAxMTA0OVoXDTM5MTIzMTIzNTk1OVowEzERMA8GA1UEAxMIQWxpY2VEU1MwggG2M
+IIBKwYHKoZIzjgEATCCAR4CgYEAgY3N7YPqCp45PsJIKKPkR5PdDteoDuxTxauECE//lOFz
+SH4M1vNESNH+n6+koYkv4dkwyDbeP5u/t0zcX2mK5HXQNwyRCJWb3qde+fz0ny/dQ6iLVPE
+/sAcIR01diMPDtbPjVQh11Tl2EMR4vf+dsISXN/LkURu15AmWXPN+W9sCFQDiR6YaRWa4E8
+baj7g3IStii/eTzQKBgCY40BSJMqo5+z5t2UtZakx2IzkEAjVc8ssaMMMeUF3dm1nizaoFP
+VjAe6I2uG4Hr32KQiWn9HXPSgheSz6Q+G3qnMkhijt2FOnOLl2jB80jhbgvMAF8bUmJEYk2
+RL34yJVKU1a14vlz7BphNh8Rf8K97dFQ/5h0wtGBSmA5ujY5A4GEAAKBgFzjuVp1FJYLqXr
+d4z+p7Kxe3L23ExE0phaJKBEj2TSGZ3V1ExI9Q1tv5VG/+onyohs+JH09B41bY8i7RaWgSu
+OF1s4GgD/oI34a8iSrUxq4Jw0e7wi/ZhSAXGKsZfoVi/G7NNTSljf2YUeyxDKE8H5BQP1Gp
+2NOM/Kl4vTyg+W4o4GBMH8wDAYDVR0TAQH/BAIwADAOBgNVHQ8BAf8EBAMCBsAwHwYDVR0j
+BBgwFoAUcEQ+gi5vh95K03XjPSC8QyuT8R8wHQYDVR0OBBYEFL5sobPjwfftQ3CkzhMB4v3
+jl/7NMB8GA1UdEQQYMBaBFEFsaWNlRFNTQGV4YW1wbGUuY29tMAkGByqGSM44BAMDMAAwLQ
+IUVQykGR9CK4lxIjONg2q1PWdrv0UCFQCfYVNSVAtcst3a53Yd4hBSW0NevTFjMGECAQEwG
+DASMRAwDgYDVQQDEwdDYXJsRFNTAgIAyDAHBgUrDgMCGjAJBgcqhkjOOAQDBC4wLAIUM/mG
+f6gkgp9Z0XtRdGimJeB/BxUCFGFFJqwYRt1WYcIOQoGiaowqGzVI
+
+		
+------=_NextBoundry____Fri,_06_Sep_2002_00:25:21--

Modified: trunk/jopenssl/test/test_java.rb (1072 => 1073)


--- trunk/jopenssl/test/test_java.rb	2008-07-27 16:10:27 UTC (rev 1072)
+++ trunk/jopenssl/test/test_java.rb	2008-07-27 16:10:30 UTC (rev 1073)
@@ -35,6 +35,10 @@
     CertificateFactory = java.security.cert.CertificateFactory unless defined?(CertificateFactory)
     BCP = org.bouncycastle.jce.provider.BouncyCastleProvider unless defined?(BCP)
     ByteArrayInputStream = java.io.ByteArrayInputStream unless defined?(ByteArrayInputStream)
+
+    MimeEncryptedString = File::read(File.join(File.dirname(__FILE__), 'pkcs7_mime_encrypted.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'))
     
     X509CertString = <<CERT
 -----BEGIN CERTIFICATE-----

Modified: trunk/jopenssl/test/test_java_mime.rb (1072 => 1073)


--- trunk/jopenssl/test/test_java_mime.rb	2008-07-27 16:10:27 UTC (rev 1072)
+++ trunk/jopenssl/test/test_java_mime.rb	2008-07-27 16:10:30 UTC (rev 1073)
@@ -131,5 +131,43 @@
       assert_equal [MimeParam.new("boundary","MIME_boundary"), 
                     MimeParam.new("type","text/xml")], header.params.to_a
     end
+
+    def test_advanced_mime_message
+      bio = BIO::from_string(MultipartSignedString)
+      result = Mime::DEFAULT.parse_headers(bio)
+      
+      assert_equal "mime-version", result[0].name
+      assert_equal "1.0", result[0].value
+      
+      assert_equal "to", result[1].name
+      assert_equal "[EMAIL PROTECTED]", result[1].value
+
+      assert_equal "from", result[2].name
+      assert_equal "[EMAIL PROTECTED]", result[2].value
+
+      assert_equal "subject", result[3].name
+      assert_equal "example 4.8", result[3].value
+
+      assert_equal "message-id", result[4].name
+      assert_equal "<[EMAIL PROTECTED]>", result[4].value
+
+      assert_equal "date", result[5].name
+      assert_equal "fri, 06 sep 2002 00:25:21 -0300", result[5].value
+      
+      assert_equal "content-type", result[6].name
+      assert_equal "multipart/signed", result[6].value
+      
+      assert_equal "micalg", result[6].params[0].param_name
+      assert_equal "SHA1", result[6].params[0].param_value
+
+      assert_equal "boundary", result[6].params[1].param_name
+      assert_equal "----=_NextBoundry____Fri,_06_Sep_2002_00:25:21", result[6].params[1].param_value
+
+      assert_equal "protocol", result[6].params[2].param_name
+      assert_equal "application/pkcs7-signature", result[6].params[2].param_value
+      
+      assert_equal 3, result[6].params.length
+      assert_equal 7, result.length
+    end
   end
 end

Modified: trunk/jopenssl/test/test_java_smime.rb (1072 => 1073)


--- trunk/jopenssl/test/test_java_smime.rb	2008-07-27 16:10:27 UTC (rev 1072)
+++ trunk/jopenssl/test/test_java_smime.rb	2008-07-27 16:10:30 UTC (rev 1073)
@@ -150,5 +150,12 @@
 
       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
   end
 end
_______________________________________________
Jruby-extras-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/jruby-extras-devel

Reply via email to