summaryrefslogtreecommitdiffstats
path: root/crypto/pkcs7/bio_pk7.c
diff options
context:
space:
mode:
authorDr. Stephen Henson <steve@openssl.org>2008-03-12 21:14:28 +0000
committerDr. Stephen Henson <steve@openssl.org>2008-03-12 21:14:28 +0000
commit8931b30d8478b0bd24af251fac64e7b0bf121369 (patch)
tree04d17028c745633b40b997699bc580c7b4cc600d /crypto/pkcs7/bio_pk7.c
parent27dc105f51361fc71f556e927f621218883b0c26 (diff)
And so it begins...
Initial support for CMS. Add zlib compression BIO. Add AES key wrap implementation. Generalize S/MIME MIME code to support CMS and/or PKCS7.
Diffstat (limited to 'crypto/pkcs7/bio_pk7.c')
-rw-r--r--crypto/pkcs7/bio_pk7.c168
1 files changed, 4 insertions, 164 deletions
diff --git a/crypto/pkcs7/bio_pk7.c b/crypto/pkcs7/bio_pk7.c
index d4a68c039c..c8d06d6cdc 100644
--- a/crypto/pkcs7/bio_pk7.c
+++ b/crypto/pkcs7/bio_pk7.c
@@ -1,9 +1,9 @@
/* bio_pk7.c */
-/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project.
*/
/* ====================================================================
- * Copyright (c) 2006 The OpenSSL Project. All rights reserved.
+ * Copyright (c) 2008 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -50,10 +50,6 @@
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
- * This product includes cryptographic software written by Eric Young
- * (eay@cryptsoft.com). This product includes software written by Tim
- * Hudson (tjh@cryptsoft.com).
- *
*/
#include <openssl/asn1.h>
@@ -65,165 +61,9 @@
#endif
#include <stdio.h>
-/* Highly experiemental PKCS#7 BIO support routines */
-
-/* The usage is quite simple, initialize a PKCS7 structure,
- * get a BIO from it then any data written through the BIO
- * will end up translated to PKCS#7 format on the fly.
- * The data is streamed out and does *not* need to be
- * all held in memory at once.
- *
- * When the BIO is flushed the output is finalized and any
- * signatures etc written out.
- *
- * The BIO is a 'proper' BIO and can handle non blocking I/O
- * correctly.
- *
- * The usage is simple. The implementation is *not*...
- */
-
-/* BIO support data stored in the ASN1 BIO ex_arg */
-
-typedef struct pkcs7_aux_st
- {
- /* PKCS7 structure this BIO refers to */
- PKCS7 *p7;
- /* Top of the BIO chain */
- BIO *p7bio;
- /* Output BIO */
- BIO *out;
- /* Boundary where content is inserted */
- unsigned char **boundary;
- /* DER buffer start */
- unsigned char *derbuf;
- } PKCS7_SUPPORT;
-
-static int pkcs7_prefix(BIO *b, unsigned char **pbuf, int *plen, void *parg);
-static int pkcs7_prefix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg);
-static int pkcs7_suffix(BIO *b, unsigned char **pbuf, int *plen, void *parg);
-static int pkcs7_suffix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg);
+/* Streaming encode support for PKCS#7 */
BIO *BIO_new_PKCS7(BIO *out, PKCS7 *p7)
{
- PKCS7_SUPPORT *p7aux = NULL;
- BIO *p7bio = NULL;
- BIO *asn_bio = NULL;
- unsigned char **boundary;
- p7aux = OPENSSL_malloc(sizeof(PKCS7_SUPPORT));
- asn_bio = BIO_new(BIO_f_asn1());
-
- /* ASN1 bio needs to be next to output BIO */
-
- out = BIO_push(asn_bio, out);
-
- if (!p7aux || !asn_bio || !out)
- goto err;
-
- BIO_asn1_set_prefix(asn_bio, pkcs7_prefix, pkcs7_prefix_free);
- BIO_asn1_set_suffix(asn_bio, pkcs7_suffix, pkcs7_suffix_free);
-
- /* Now initialize BIO for PKCS#7 output */
-
- p7bio = PKCS7_dataInit(p7, out);
- if (!p7bio || !PKCS7_stream(&boundary, p7))
- goto err;
-
- p7aux->p7 = p7;
- p7aux->p7bio = p7bio;
- p7aux->boundary = boundary;
- p7aux->out = out;
-
- BIO_ctrl(asn_bio, BIO_C_SET_EX_ARG, 0, p7aux);
-
- return p7bio;
-
- err:
- if (p7bio)
- BIO_free(p7bio);
- if (asn_bio)
- BIO_free(asn_bio);
- if (p7aux)
- OPENSSL_free(p7aux);
- return NULL;
- }
-
-static int pkcs7_prefix(BIO *b, unsigned char **pbuf, int *plen, void *parg)
- {
- PKCS7_SUPPORT *p7aux;
- unsigned char *p;
- int derlen;
-
- if (!parg)
- return 0;
-
- p7aux = *(PKCS7_SUPPORT **)parg;
-
- derlen = i2d_PKCS7_NDEF(p7aux->p7, NULL);
- p = OPENSSL_malloc(derlen);
- p7aux->derbuf = p;
- *pbuf = p;
- i2d_PKCS7_NDEF(p7aux->p7, &p);
-
- if (!*p7aux->boundary)
- return 0;
-
- *plen = *p7aux->boundary - *pbuf;
-
- return 1;
- }
-
-static int pkcs7_prefix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg)
- {
- PKCS7_SUPPORT *p7aux;
-
- if (!parg)
- return 0;
-
- p7aux = *(PKCS7_SUPPORT **)parg;
-
- if (p7aux->derbuf)
- OPENSSL_free(p7aux->derbuf);
-
- p7aux->derbuf = NULL;
- *pbuf = NULL;
- *plen = 0;
- return 1;
- }
-
-static int pkcs7_suffix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg)
- {
- PKCS7_SUPPORT **pp7aux = (PKCS7_SUPPORT **)parg;
- if (!pkcs7_prefix_free(b, pbuf, plen, parg))
- return 0;
- OPENSSL_free(*pp7aux);
- *pp7aux = NULL;
- return 1;
- }
-
-static int pkcs7_suffix(BIO *b, unsigned char **pbuf, int *plen, void *parg)
- {
- PKCS7_SUPPORT *p7aux;
- unsigned char *p;
- int derlen;
-
- if (!parg)
- return 0;
-
- p7aux = *(PKCS7_SUPPORT **)parg;
-
- /* Finalize structures */
- PKCS7_dataFinal(p7aux->p7, p7aux->p7bio);
-
- derlen = i2d_PKCS7_NDEF(p7aux->p7, NULL);
- p = OPENSSL_malloc(derlen);
- p7aux->derbuf = p;
- i2d_PKCS7_NDEF(p7aux->p7, &p);
- if (!*p7aux->boundary)
- return 0;
- *pbuf = *p7aux->boundary;
- *plen = derlen - (*p7aux->boundary - p7aux->derbuf);
-
- return 1;
+ return BIO_new_NDEF(out, (ASN1_VALUE *)p7, ASN1_ITEM_rptr(PKCS7));
}
-
-