pk7_smime.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/* pk7_smime.c */
/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
* project 1999.
*/
/* ====================================================================
* Copyright (c) 1999-2003 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
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* 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).
*
*/
/* Simple PKCS#7 processing functions */
#include <stdio.h>
#include "cryptlib.h"
{
int i;
return NULL;
}
return NULL;
}
return NULL;
}
if(!(flags & PKCS7_NOCERTS)) {
}
return NULL;
}
if(!(flags & PKCS7_NOATTR)) {
/* Add SMIMECapabilities */
if(!(flags & PKCS7_NOSMIMECAP))
{
if(!(smcap = sk_X509_ALGOR_new_null())) {
return NULL;
}
#ifndef OPENSSL_NO_DES
#endif
#ifndef OPENSSL_NO_RC2
#endif
#ifndef OPENSSL_NO_DES
#endif
#ifndef OPENSSL_NO_RC2
#endif
}
}
return NULL;
}
return p7;
}
{
char buf[4096];
int i, j=0, k, ret = 0;
if(!p7) {
return 0;
}
if(!PKCS7_type_is_signed(p7)) {
return 0;
}
/* Check for no data and no content: no data to verify signature */
return 0;
}
#if 0
/* NB: this test commented out because some versions of Netscape
* illegally include zero length content when signing data.
*/
/* Check for data and content: two sets of data */
return 0;
}
#endif
return 0;
}
if(!signers) return 0;
/* Now verify the certificates */
if (!(flags & PKCS7_NOCHAIN)) {
{
return 0;
}
return 0;
}
i = X509_verify_cert(&cert_ctx);
if (i <= 0) j = X509_STORE_CTX_get_error(&cert_ctx);
if (i <= 0) {
return 0;
}
/* Check for revocation status here */
}
if(flags & PKCS7_TEXT) {
goto err;
}
/* We now have to 'read' from p7bio to calculate digests etc. */
for (;;)
{
if (i <= 0) break;
}
if(flags & PKCS7_TEXT) {
goto err;
}
}
/* Now Verify All Signatures */
if (!(flags & PKCS7_NOSIGS))
for (i=0; i<sk_PKCS7_SIGNER_INFO_num(sinfos); i++)
{
if (j <= 0) {
goto err;
}
}
ret = 1;
err:
return ret;
}
{
int i;
if(!p7) {
return NULL;
}
if(!PKCS7_type_is_signed(p7)) {
return NULL;
}
if(!(signers = sk_X509_new_null())) {
return NULL;
}
/* Collect all the signers together */
if(sk_PKCS7_SIGNER_INFO_num(sinfos) <= 0) {
return 0;
}
for (i = 0; i < sk_PKCS7_SIGNER_INFO_num(sinfos); i++)
{
/* If any certificates passed they take priority */
if (!signer) {
return 0;
}
}
return signers;
}
/* Build a complete PKCS#7 enveloped data */
int flags)
{
int i;
return NULL;
}
goto err;
}
for(i = 0; i < sk_X509_num(certs); i++) {
goto err;
}
}
goto err;
}
goto err;
}
return p7;
err:
PKCS7_free(p7);
return NULL;
}
{
int ret, i;
char buf[4096];
if(!p7) {
return 0;
}
if(!PKCS7_type_is_enveloped(p7)) {
return 0;
}
return 0;
}
return 0;
}
if (flags & PKCS7_TEXT) {
/* Encrypt BIOs can't do BIO_gets() so add a buffer BIO */
return 0;
}
return 0;
}
return ret;
} else {
for(;;) {
if(i <= 0) break;
}
return 1;
}
}