pk7_doit.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/* crypto/pkcs7/pk7_doit.c */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
*
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* 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 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 the
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS 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 AUTHOR OR 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.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
#include <stdio.h>
#include "cryptlib.h"
void *value);
{
int isOther=1;
switch( nid )
{
case NID_pkcs7_data:
case NID_pkcs7_signed:
case NID_pkcs7_enveloped:
case NID_pkcs7_digest:
case NID_pkcs7_encrypted:
isOther=0;
break;
default:
isOther=1;
}
return isOther;
}
{
if ( PKCS7_type_is_data(p7))
return NULL;
}
{
int i;
X509_ALGOR *xa;
switch (i)
{
case NID_pkcs7_signed:
break;
if (evp_cipher == NULL)
{
goto err;
}
break;
case NID_pkcs7_enveloped:
if (evp_cipher == NULL)
{
goto err;
}
break;
default:
goto err;
}
{
for (i=0; i<sk_X509_ALGOR_num(md_sk); i++)
{
{
goto err;
}
{
goto err;
}
else
}
}
if (evp_cipher != NULL)
{
unsigned char key[EVP_MAX_KEY_LENGTH];
unsigned char iv[EVP_MAX_IV_LENGTH];
unsigned char *tmp;
{
goto err;
}
goto err;
if (ivlen > 0) {
goto err;
}
/* Lets do the pub key stuff :-) */
max=0;
for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++)
{
{
goto err;
}
}
{
goto err;
}
for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++)
{
if (jj <= 0)
{
goto err;
}
}
else
}
{
if (PKCS7_is_detached(p7))
else
{
{
}
}
}
if (0)
{
err:
}
return(out);
}
/* int */
{
int i,j;
X509_ALGOR *xa;
switch (i)
{
case NID_pkcs7_signed:
break;
if (evp_cipher == NULL)
{
goto err;
}
break;
case NID_pkcs7_enveloped:
if (evp_cipher == NULL)
{
goto err;
}
break;
default:
goto err;
}
/* We will be checking the signature */
{
for (i=0; i<sk_X509_ALGOR_num(md_sk); i++)
{
{
goto err;
}
{
goto err;
}
else
}
}
if (evp_cipher != NULL)
{
#if 0
unsigned char key[EVP_MAX_KEY_LENGTH];
unsigned char iv[EVP_MAX_IV_LENGTH];
unsigned char *p;
int max;
#endif
int jj;
{
goto err;
}
/* It was encrypted, we need to decrypt the secret key
* with the private key */
/* Find the recipientInfo which matches the passed certificate
* (if any)
*/
for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++) {
}
goto err;
}
{
goto err;
}
if (jj <= 0)
{
goto err;
}
goto err;
* and effective key length. The key length is
* determined by the size of the decrypted RSA key.
*/
{
goto err;
}
}
else
}
#if 1
{
}
else
{
#if 0
/* We need to set this so that when we have read all
* the data, the encrypt BIO, if present, will read
* EOF and encode the last few bytes */
#else
else {
}
#endif
}
#endif
if (0)
{
err:
}
return(out);
}
{
int ret=0;
int i,j;
switch (i)
{
/* XXXXXXXXXXXXXXXX */
break;
case NID_pkcs7_enveloped:
/* XXXXXXXXXXXXXXXX */
break;
case NID_pkcs7_signed:
/* If detached data then the content is excluded */
}
break;
}
{
{
goto err;
}
for (i=0; i<sk_PKCS7_SIGNER_INFO_num(si_sk); i++)
{
for (;;)
{
== NULL)
{
goto err;
}
{
goto err;
}
if (EVP_MD_CTX_type(mdc) == j)
break;
else
}
/* We now have the EVP_MD_CTX, lets do the
* signing. */
{
goto err;
}
/* If there are attributes, we add the digest
* attribute and only sign the attributes */
{
/* Add signing time if not already present */
if (!PKCS7_get_signed_attribute(si,
{
}
/* Add digest */
/* Now sign the attributes */
}
#ifndef OPENSSL_NO_DSA
#endif
{
goto err;
}
{
goto err;
}
}
}
if (!PKCS7_is_detached(p7))
{
{
goto err;
}
/* Mark the BIO read only then we can use its copy of the data
* instead of making an extra copy.
*/
#if 0
#endif
}
ret=1;
err:
return(ret);
}
{
int ret=0,i;
if (PKCS7_type_is_signed(p7))
{
}
else if (PKCS7_type_is_signedAndEnveloped(p7))
{
}
else
{
goto err;
}
/* XXXXXXXXXXXXXXXXXXXXXXX */
/* were we able to find the cert in passed to us */
{
goto err;
}
/* Lets verify */
{
goto err;
}
i=X509_verify_cert(ctx);
if (i <= 0)
{
goto err;
}
err:
return ret;
}
{
int ret=0,i;
int md_type;
if (!PKCS7_type_is_signed(p7) &&
goto err;
}
for (;;)
{
{
goto err;
}
{
goto err;
}
break;
/* Workaround for some broken clients that put the signature
* OID instead of the digest OID in digest_alg->algorithm
*/
break;
}
/* mdc is the digest ctx that we want, unless there are attributes,
* in which case the digest is the signed attributes */
{
if (!message_digest)
{
goto err;
}
{
#if 0
{
int ii;
}
#endif
ret= -1;
goto err;
}
}
if (!pkey)
{
ret = -1;
goto err;
}
#ifndef OPENSSL_NO_DSA
#endif
if (i <= 0)
{
ret= -1;
goto err;
}
else
ret=1;
err:
return(ret);
}
{
int i;
if (i != NID_pkcs7_signedAndEnveloped) return(NULL);
return(ri->issuer_and_serial);
}
{
}
{
}
{
int i;
ASN1_OBJECT *o;
o=OBJ_nid2obj(nid);
for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++)
{
{
else
return(NULL);
}
}
return(NULL);
}
{
}
{
int i;
for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++)
{
== NULL)
return(0);
}
return(1);
}
{
int i;
for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++)
{
== NULL)
return(0);
}
return(1);
}
void *value)
{
}
void *value)
{
}
void *value)
{
{
*sk = sk_X509_ATTRIBUTE_new_null();
}
else
{
int i;
for (i=0; i<sk_X509_ATTRIBUTE_num(*sk); i++)
{
{
goto end;
}
}
goto new_attrib;
}
end:
return(1);
}