-/* 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 2006.
*/
/* ====================================================================
#include <openssl/x509.h>
#include <openssl/asn1.h>
#include <openssl/dsa.h>
+#include <openssl/bn.h>
+#ifndef OPENSSL_NO_CMS
+#include <openssl/cms.h>
+#endif
#include "asn1_locl.h"
static int dsa_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey)
return 1;
err:
- if (pubkey)
+ if (public_key)
ASN1_INTEGER_free(public_key);
if (dsa)
DSA_free(dsa);
if (*p == (V_ASN1_SEQUENCE|V_ASN1_CONSTRUCTED))
{
ASN1_TYPE *t1, *t2;
- if(!(ndsa = ASN1_seq_unpack_ASN1_TYPE(p, pklen,
- d2i_ASN1_TYPE,
- ASN1_TYPE_free)))
+ if(!(ndsa = d2i_ASN1_SEQUENCE_ANY(NULL, &p, pklen)));
goto decerr;
if (sk_ASN1_TYPE_num(ndsa) != 2)
goto decerr;
*pbuflen = i;
}
-int do_dsa_print(BIO *bp, const DSA *x, int off, int ptype)
+static int do_dsa_print(BIO *bp, const DSA *x, int off, int ptype)
{
unsigned char *m=NULL;
int ret=0;
case ASN1_PKEY_CTRL_PKCS7_SIGN:
if (arg1 == 0)
{
+ int snid, hnid;
X509_ALGOR *alg1, *alg2;
PKCS7_SIGNER_INFO_get0_algs(arg2, NULL, &alg1, &alg2);
- X509_ALGOR_set0(alg1, OBJ_nid2obj(NID_sha1),
- V_ASN1_NULL, 0);
- X509_ALGOR_set0(alg2, OBJ_nid2obj(NID_dsaWithSHA1),
- V_ASN1_UNDEF, 0);
+ if (alg1 == NULL || alg1->algorithm == NULL)
+ return -1;
+ hnid = OBJ_obj2nid(alg1->algorithm);
+ if (hnid == NID_undef)
+ return -1;
+ if (!OBJ_find_sigid_by_algs(&snid, hnid, EVP_PKEY_id(pkey)))
+ return -1;
+ X509_ALGOR_set0(alg2, OBJ_nid2obj(snid), V_ASN1_UNDEF, 0);
}
return 1;
+#ifndef OPENSSL_NO_CMS
+ case ASN1_PKEY_CTRL_CMS_SIGN:
+ if (arg1 == 0)
+ {
+ int snid, hnid;
+ X509_ALGOR *alg1, *alg2;
+ CMS_SignerInfo_get0_algs(arg2, NULL, NULL, &alg1, &alg2);
+ if (alg1 == NULL || alg1->algorithm == NULL)
+ return -1;
+ hnid = OBJ_obj2nid(alg1->algorithm);
+ if (hnid == NID_undef)
+ return -1;
+ if (!OBJ_find_sigid_by_algs(&snid, hnid, EVP_PKEY_id(pkey)))
+ return -1;
+ X509_ALGOR_set0(alg2, OBJ_nid2obj(snid), V_ASN1_UNDEF, 0);
+ }
+ return 1;
+#endif
case ASN1_PKEY_CTRL_DEFAULT_MD_NID:
*(int *)arg2 = NID_sha1;