#include <openssl/rand.h>
#include <openssl/objects.h>
#include <openssl/x509.h>
+#include <openssl/x509v3.h>
static int add_attribute(STACK_OF(X509_ATTRIBUTE) **sk, int nid, int atrtype,
void *value);
os=p7->d.sign->contents->d.data;
if (os->length > 0) bio =
BIO_new_mem_buf(os->data, os->length);
- } else {
+ }
+ if(bio == NULL) {
bio=BIO_new(BIO_s_mem());
BIO_set_mem_eof_return(bio,0);
}
{
int i,j;
BIO *out=NULL,*btmp=NULL,*etmp=NULL,*bio=NULL;
- char *tmp=NULL;
+ unsigned char *tmp=NULL;
X509_ALGOR *xa;
ASN1_OCTET_STRING *data_body=NULL;
const EVP_MD *evp_md;
STACK_OF(PKCS7_RECIP_INFO) *rsk=NULL;
X509_ALGOR *xalg=NULL;
PKCS7_RECIP_INFO *ri=NULL;
+#ifndef NO_RC2
+ char is_rc2 = 0;
+#endif
/* EVP_PKEY *pkey; */
#if 0
X509_STORE_CTX s_ctx;
goto err;
}
+ if(EVP_CIPHER_nid(evp_cipher) == NID_rc2_cbc)
+ {
+#ifndef NO_RC2
+ is_rc2 = 1;
+#else
+ PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNSUPPORTED_CIPHER_TYPE);
+ goto err;
+#endif
+ }
+
/* We will be checking the signature */
if (md_sk != NULL)
{
}
jj=EVP_PKEY_size(pkey);
- tmp=Malloc(jj+10);
+ tmp=(unsigned char *)Malloc(jj+10);
if (tmp == NULL)
{
PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_MALLOC_FAILURE);
goto err;
}
- jj=EVP_PKEY_decrypt((unsigned char *)tmp,
- M_ASN1_STRING_data(ri->enc_key),
- M_ASN1_STRING_length(ri->enc_key),
- pkey);
+ jj=EVP_PKEY_decrypt(tmp, M_ASN1_STRING_data(ri->enc_key),
+ M_ASN1_STRING_length(ri->enc_key), pkey);
if (jj <= 0)
{
PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_EVP_LIB);
if (EVP_CIPHER_asn1_to_param(evp_ctx,enc_alg->parameter) < 0)
return(NULL);
- if (jj != EVP_CIPHER_CTX_key_length(evp_ctx))
- {
- PKCS7err(PKCS7_F_PKCS7_DATADECODE,
+ if (jj != EVP_CIPHER_CTX_key_length(evp_ctx)) {
+ /* HACK: some S/MIME clients don't use the same key
+ * and effective key length. The key length is
+ * determined by the size of the decrypted RSA key.
+ * So we hack things to manually set the RC2 key
+ * because we currently can't do this with the EVP
+ * interface.
+ */
+#ifndef NO_RC2
+ if(is_rc2) RC2_set_key(&(evp_ctx->c.rc2_ks),jj, tmp,
+ EVP_CIPHER_CTX_key_length(evp_ctx)*8);
+ else
+#endif
+ {
+ PKCS7err(PKCS7_F_PKCS7_DATADECODE,
PKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH);
- goto err;
- }
- EVP_CipherInit(evp_ctx,NULL,(unsigned char *)tmp,NULL,0);
+ goto err;
+ }
+ } else EVP_CipherInit(evp_ctx,NULL,tmp,NULL,0);
memset(tmp,0,jj);
/* Lets verify */
X509_STORE_CTX_init(ctx,cert_store,x509,cert);
+ X509_STORE_CTX_set_purpose(ctx, X509_PURPOSE_SMIME_SIGN);
i=X509_verify_cert(ctx);
if (i <= 0)
{