Various fixes...
authorDr. Stephen Henson <steve@openssl.org>
Mon, 21 Aug 2000 22:02:23 +0000 (22:02 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Mon, 21 Aug 2000 22:02:23 +0000 (22:02 +0000)
initialize ex_pathlen to -1 so it isn't checked if pathlen
is not present.

set ucert to NULL in apps/pkcs12.c otherwise it gets freed
twice.

remove extraneous '\r' in MIME encoder.

Allow a NULL to be passed to X509_gmtime_adj()

Make PKCS#7 code use definite length encoding rather then
the indefinite stuff it used previously.

CHANGES
apps/pkcs12.c
crypto/asn1/p7_lib.c
crypto/asn1/x_x509.c
crypto/pkcs7/pk7_mime.c
crypto/x509/x509_vfy.c

diff --git a/CHANGES b/CHANGES
index e545b5002e3bcdc4b4f230f492cc1ec6a5d14ac5..b01f3a07f8d708bf5b96d4d826ff38d9024ac3cb 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -4,6 +4,13 @@
 
  Changes between 0.9.5a and 0.9.6  [xx XXX 2000]
 
+  *) Modification to PKCS#7 encoding routines to output definite
+     length encoding. Since currently the whole structures are in
+     memory there's not real point in using indefinite length 
+     constructed encoding. However if OpenSSL is compiled with
+     the flag PKCS7_INDEFINITE_ENCODING the old form is used.
+     [Steve Henson]
+
   *) Added BIO_vprintf() and BIO_vsnprintf().
      [Richard Levitte]
 
index 963797155fc578fcd564506bacacdd9ad1aedd62..0f3ac4977a235806c3a7f817ad5705905f03b480 100644 (file)
@@ -502,6 +502,8 @@ int MAIN(int argc, char **argv)
        }
        sk_X509_pop_free(certs, X509_free);
        certs = NULL;
+       /* ucert is part of certs so it is already freed */
+       ucert = NULL;
 
 #ifdef CRYPTO_MDEBUG
        CRYPTO_pop_info();
index 90ead17dbc756a6bf719eb7de035fda40e8418a7..76cb675497c28f6b256d60e612f94779bb81a1a6 100644 (file)
@@ -62,6 +62,8 @@
 #include <openssl/pkcs7.h>
 #include <openssl/objects.h>
 
+#ifdef PKCS7_INDEFINITE_ENCODING
+
 int i2d_PKCS7(PKCS7 *a, unsigned char **pp)
        {
        M_ASN1_I2D_vars(a);
@@ -144,6 +146,96 @@ int i2d_PKCS7(PKCS7 *a, unsigned char **pp)
        M_ASN1_I2D_finish();
        }
 
+#else
+
+int i2d_PKCS7(PKCS7 *a, unsigned char **pp)
+       {
+       int explen = 0;
+       M_ASN1_I2D_vars(a);
+
+       if (a->asn1 != NULL)
+               {
+               if (pp == NULL)
+                       return((int)a->length);
+               memcpy(*pp,a->asn1,(int)a->length);
+               *pp+=a->length;
+               return((int)a->length);
+               }
+
+       M_ASN1_I2D_len(a->type,i2d_ASN1_OBJECT);
+       if (a->d.ptr != NULL)
+               {
+               /* Save current length */
+               r = ret;
+               switch (OBJ_obj2nid(a->type))
+                       {
+               case NID_pkcs7_data:
+                       M_ASN1_I2D_len(a->d.data,i2d_ASN1_OCTET_STRING);
+                       break;
+               case NID_pkcs7_signed:
+                       M_ASN1_I2D_len(a->d.sign,i2d_PKCS7_SIGNED);
+                       break;
+               case NID_pkcs7_enveloped:
+                       M_ASN1_I2D_len(a->d.enveloped,i2d_PKCS7_ENVELOPE);
+                       break;
+               case NID_pkcs7_signedAndEnveloped:
+                       M_ASN1_I2D_len(a->d.signed_and_enveloped,
+                               i2d_PKCS7_SIGN_ENVELOPE);
+                       break;
+               case NID_pkcs7_digest:
+                       M_ASN1_I2D_len(a->d.digest,i2d_PKCS7_DIGEST);
+                       break;
+               case NID_pkcs7_encrypted:
+                       M_ASN1_I2D_len(a->d.encrypted,i2d_PKCS7_ENCRYPT);
+                       break;
+               default:
+                       break;
+                       }
+               /* Work out explicit tag content size */
+               explen = ret - r;
+               /* Work out explicit tag size: Note: ASN1_object_size
+                * includes the content length.
+                */
+               ret =  r + ASN1_object_size(1, explen, 0);
+               }
+
+       M_ASN1_I2D_seq_total();
+
+       M_ASN1_I2D_put(a->type,i2d_ASN1_OBJECT);
+
+       if (a->d.ptr != NULL)
+               {
+               ASN1_put_object(&p, 1, explen, 0, V_ASN1_CONTEXT_SPECIFIC);
+               switch (OBJ_obj2nid(a->type))
+                       {
+               case NID_pkcs7_data:
+                       M_ASN1_I2D_put(a->d.data,i2d_ASN1_OCTET_STRING);
+                       break;
+               case NID_pkcs7_signed:
+                       M_ASN1_I2D_put(a->d.sign,i2d_PKCS7_SIGNED);
+                       break;
+               case NID_pkcs7_enveloped:
+                       M_ASN1_I2D_put(a->d.enveloped,i2d_PKCS7_ENVELOPE);
+                       break;
+               case NID_pkcs7_signedAndEnveloped:
+                       M_ASN1_I2D_put(a->d.signed_and_enveloped,
+                               i2d_PKCS7_SIGN_ENVELOPE);
+                       break;
+               case NID_pkcs7_digest:
+                       M_ASN1_I2D_put(a->d.digest,i2d_PKCS7_DIGEST);
+                       break;
+               case NID_pkcs7_encrypted:
+                       M_ASN1_I2D_put(a->d.encrypted,i2d_PKCS7_ENCRYPT);
+                       break;
+               default:
+                       break;
+                       }
+               }
+       M_ASN1_I2D_finish();
+       }
+
+#endif
+
 PKCS7 *d2i_PKCS7(PKCS7 **a, unsigned char **pp, long length)
        {
        M_ASN1_D2I_vars(a,PKCS7 *,PKCS7_new);
index ea71a29c9ab19776ed7bea9c563b3262561a499b..36f0e4743eefd098e72f18b79bc251b6de834960 100644 (file)
@@ -117,6 +117,7 @@ X509 *X509_new(void)
        ret->references=1;
        ret->valid=0;
        ret->ex_flags = 0;
+       ret->ex_pathlen = -1;
        ret->name=NULL;
        ret->aux=NULL;
        M_ASN1_New(ret->cert_info,X509_CINF_new);
index 9741aa578ecd897a30e34325424afb9c547306ce..a7b692943646a241b55aed7cb70f948bed7d4c8d 100644 (file)
@@ -170,7 +170,7 @@ int SMIME_write_PKCS7(BIO *bio, PKCS7 *p7, BIO *data, int flags)
                BIO_printf(bio, "micalg=sha1 ; boundary=\"----%s\"\n\n", bound);
                BIO_printf(bio, "This is an S/MIME signed message\n\n");
                /* Now write out the first part */
-               BIO_printf(bio, "------%s\r\n", bound);
+               BIO_printf(bio, "------%s\n", bound);
                if(flags & PKCS7_TEXT) BIO_printf(bio, "Content-Type: text/plain\n\n");
                while((i = BIO_read(data, linebuf, MAX_SMLEN)) > 0) 
                                                BIO_write(bio, linebuf, i);
index 0d5273d51a432da18fe4159689ce5d20a18f4036..ccc031377a62b5069445ac2776416e1c1024f4ae 100644 (file)
@@ -582,6 +582,7 @@ ASN1_TIME *X509_gmtime_adj(ASN1_TIME *s, long adj)
 
        time(&t);
        t+=adj;
+       if(!s) return ASN1_TIME_set(s, t);
        if(s->type == V_ASN1_UTCTIME) return(ASN1_UTCTIME_set(s,t));
        return ASN1_GENERALIZEDTIME_set(s, t);
        }