mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-08-08 23:13:38 +08:00
first step of v2 final release
This commit is contained in:
@@ -14,8 +14,12 @@
|
||||
#include <openssl/objects.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/x509v3.h>
|
||||
#include <openssl/rsa.h>
|
||||
#include <openssl/dsa.h>
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
# include <openssl/rsa.h>
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
# include <openssl/dsa.h>
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_STDIO
|
||||
int X509_REQ_print_fp(FILE *fp, X509_REQ *x)
|
||||
|
||||
@@ -217,6 +217,7 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags,
|
||||
|
||||
int X509_ocspid_print(BIO *bp, X509 *x)
|
||||
{
|
||||
#ifndef OPENSSL_NO_SHA
|
||||
unsigned char *der = NULL;
|
||||
unsigned char *dertmp;
|
||||
int derlen;
|
||||
@@ -270,6 +271,10 @@ int X509_ocspid_print(BIO *bp, X509 *x)
|
||||
err:
|
||||
OPENSSL_free(der);
|
||||
return (0);
|
||||
#else
|
||||
BIO_printf(bp, "(SHA1 disabled)\n");
|
||||
return (1);
|
||||
#endif
|
||||
}
|
||||
|
||||
int X509_signature_dump(BIO *bp, const ASN1_STRING *sig, int indent)
|
||||
|
||||
@@ -29,18 +29,17 @@ int X509_issuer_and_serial_cmp(const X509 *a, const X509 *b)
|
||||
return (X509_NAME_cmp(ai->issuer, bi->issuer));
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_MD5
|
||||
unsigned long X509_issuer_and_serial_hash(X509 *a)
|
||||
{
|
||||
unsigned long ret = 0;
|
||||
EVP_MD_CTX *ctx = EVP_MD_CTX_new();
|
||||
unsigned char md[16];
|
||||
unsigned char md[EVP_MAX_MD_SIZE];
|
||||
char *f;
|
||||
|
||||
if (ctx == NULL)
|
||||
goto err;
|
||||
f = X509_NAME_oneline(a->cert_info.issuer, NULL, 0);
|
||||
if (!EVP_DigestInit_ex(ctx, EVP_md5(), NULL))
|
||||
if (!EVP_DigestInit_ex(ctx, EVP_get_default_digest(), NULL))
|
||||
goto err;
|
||||
if (!EVP_DigestUpdate(ctx, (unsigned char *)f, strlen(f)))
|
||||
goto err;
|
||||
@@ -58,7 +57,6 @@ unsigned long X509_issuer_and_serial_hash(X509 *a)
|
||||
EVP_MD_CTX_free(ctx);
|
||||
return (ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
int X509_issuer_name_cmp(const X509 *a, const X509 *b)
|
||||
{
|
||||
@@ -77,7 +75,7 @@ int X509_CRL_cmp(const X509_CRL *a, const X509_CRL *b)
|
||||
|
||||
int X509_CRL_match(const X509_CRL *a, const X509_CRL *b)
|
||||
{
|
||||
return memcmp(a->sha1_hash, b->sha1_hash, 20);
|
||||
return memcmp(a->sha1_hash, b->sha1_hash, sizeof(a->sha1_hash));
|
||||
}
|
||||
|
||||
X509_NAME *X509_get_issuer_name(const X509 *a)
|
||||
@@ -90,12 +88,10 @@ unsigned long X509_issuer_name_hash(X509 *x)
|
||||
return (X509_NAME_hash(x->cert_info.issuer));
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_MD5
|
||||
unsigned long X509_issuer_name_hash_old(X509 *x)
|
||||
{
|
||||
return (X509_NAME_hash_old(x->cert_info.issuer));
|
||||
}
|
||||
#endif
|
||||
|
||||
X509_NAME *X509_get_subject_name(const X509 *a)
|
||||
{
|
||||
@@ -117,12 +113,10 @@ unsigned long X509_subject_name_hash(X509 *x)
|
||||
return (X509_NAME_hash(x->cert_info.subject));
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_MD5
|
||||
unsigned long X509_subject_name_hash_old(X509 *x)
|
||||
{
|
||||
return (X509_NAME_hash_old(x->cert_info.subject));
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Compare two certificates: they must be identical for this to work. NB:
|
||||
@@ -139,7 +133,7 @@ int X509_cmp(const X509 *a, const X509 *b)
|
||||
X509_check_purpose((X509 *)a, -1, 0);
|
||||
X509_check_purpose((X509 *)b, -1, 0);
|
||||
|
||||
rv = memcmp(a->sha1_hash, b->sha1_hash, SHA_DIGEST_LENGTH);
|
||||
rv = memcmp(a->sha1_hash, b->sha1_hash, sizeof(a->sha1_hash));
|
||||
if (rv)
|
||||
return rv;
|
||||
/* Check for match against stored encoding too */
|
||||
@@ -184,21 +178,21 @@ int X509_NAME_cmp(const X509_NAME *a, const X509_NAME *b)
|
||||
unsigned long X509_NAME_hash(X509_NAME *x)
|
||||
{
|
||||
unsigned long ret = 0;
|
||||
unsigned char md[SHA_DIGEST_LENGTH];
|
||||
unsigned char md[EVP_MAX_MD_SIZE];
|
||||
|
||||
/* Make sure X509_NAME structure contains valid cached encoding */
|
||||
i2d_X509_NAME(x, NULL);
|
||||
if (!EVP_Digest(x->canon_enc, x->canon_enclen, md, NULL, EVP_sha1(),
|
||||
NULL))
|
||||
if (!EVP_Digest(x->canon_enc, x->canon_enclen, md, NULL,
|
||||
EVP_get_default_digest(), NULL))
|
||||
return 0;
|
||||
|
||||
ret = (((unsigned long)md[0]) | ((unsigned long)md[1] << 8L) |
|
||||
((unsigned long)md[2] << 16L) | ((unsigned long)md[3] << 24L)
|
||||
) & 0xffffffffL;
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_MD5
|
||||
/*
|
||||
* I now DER encode the name and hash it. Since I cache the DER encoding,
|
||||
* this is reasonably efficient.
|
||||
@@ -208,7 +202,7 @@ unsigned long X509_NAME_hash_old(X509_NAME *x)
|
||||
{
|
||||
EVP_MD_CTX *md_ctx = EVP_MD_CTX_new();
|
||||
unsigned long ret = 0;
|
||||
unsigned char md[16];
|
||||
unsigned char md[EVP_MAX_MD_SIZE];
|
||||
|
||||
if (md_ctx == NULL)
|
||||
return ret;
|
||||
@@ -216,7 +210,7 @@ unsigned long X509_NAME_hash_old(X509_NAME *x)
|
||||
/* Make sure X509_NAME structure contains valid cached encoding */
|
||||
i2d_X509_NAME(x, NULL);
|
||||
EVP_MD_CTX_set_flags(md_ctx, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
|
||||
if (EVP_DigestInit_ex(md_ctx, EVP_md5(), NULL)
|
||||
if (EVP_DigestInit_ex(md_ctx, EVP_get_default_digest(), NULL)
|
||||
&& EVP_DigestUpdate(md_ctx, x->bytes->data, x->bytes->length)
|
||||
&& EVP_DigestFinal_ex(md_ctx, md, NULL))
|
||||
ret = (((unsigned long)md[0]) | ((unsigned long)md[1] << 8L) |
|
||||
@@ -226,7 +220,6 @@ unsigned long X509_NAME_hash_old(X509_NAME *x)
|
||||
|
||||
return (ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Search a stack of X509 for a match */
|
||||
X509 *X509_find_by_issuer_and_serial(STACK_OF(X509) *sk, X509_NAME *name,
|
||||
|
||||
@@ -57,7 +57,7 @@ X509 *X509_REQ_to_X509(X509_REQ *r, int days, EVP_PKEY *pkey)
|
||||
if (pubkey == NULL || !X509_set_pubkey(ret, pubkey))
|
||||
goto err;
|
||||
|
||||
if (!X509_sign(ret, pkey, EVP_md5()))
|
||||
if (!X509_sign(ret, pkey, EVP_get_default_digest()))
|
||||
goto err;
|
||||
return ret;
|
||||
|
||||
|
||||
@@ -16,8 +16,12 @@
|
||||
#include <openssl/x509.h>
|
||||
#include "internal/x509_int.h"
|
||||
#include <openssl/ocsp.h>
|
||||
#include <openssl/rsa.h>
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
# include <openssl/rsa.h>
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
#include <openssl/dsa.h>
|
||||
#endif
|
||||
#include <openssl/x509v3.h>
|
||||
|
||||
int X509_verify(X509 *a, EVP_PKEY *r)
|
||||
@@ -363,6 +367,7 @@ int X509_pubkey_digest(const X509 *data, const EVP_MD *type,
|
||||
int X509_digest(const X509 *data, const EVP_MD *type, unsigned char *md,
|
||||
unsigned int *len)
|
||||
{
|
||||
#ifndef OPENSSL_NO_SHA
|
||||
if (type == EVP_sha1() && (data->ex_flags & EXFLAG_SET) != 0) {
|
||||
/* Asking for SHA1 and we already computed it. */
|
||||
if (len != NULL)
|
||||
@@ -370,6 +375,7 @@ int X509_digest(const X509 *data, const EVP_MD *type, unsigned char *md,
|
||||
memcpy(md, data->sha1_hash, sizeof(data->sha1_hash));
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
return (ASN1_item_digest
|
||||
(ASN1_ITEM_rptr(X509), type, (char *)data, md, len));
|
||||
}
|
||||
@@ -377,6 +383,7 @@ int X509_digest(const X509 *data, const EVP_MD *type, unsigned char *md,
|
||||
int X509_CRL_digest(const X509_CRL *data, const EVP_MD *type,
|
||||
unsigned char *md, unsigned int *len)
|
||||
{
|
||||
#ifndef OPENSSL_NO_SHA
|
||||
if (type == EVP_sha1()) {
|
||||
/* Asking for SHA1; always computed in CRL d2i. */
|
||||
if (len != NULL)
|
||||
@@ -384,6 +391,7 @@ int X509_CRL_digest(const X509_CRL *data, const EVP_MD *type,
|
||||
memcpy(md, data->sha1_hash, sizeof(data->sha1_hash));
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
return (ASN1_item_digest
|
||||
(ASN1_ITEM_rptr(X509_CRL), type, (char *)data, md, len));
|
||||
}
|
||||
|
||||
@@ -156,6 +156,14 @@ static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
|
||||
STACK_OF(X509_EXTENSION) *exts;
|
||||
X509_EXTENSION *ext;
|
||||
int idx;
|
||||
const EVP_MD *md;
|
||||
#ifndef OPENSSL_NO_SHA
|
||||
md = EVP_sha1();
|
||||
#elif !defined(OPENSSL_NO_SM3)
|
||||
md = EVP_sm3();
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
switch (operation) {
|
||||
case ASN1_OP_NEW_POST:
|
||||
@@ -172,7 +180,7 @@ static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
|
||||
break;
|
||||
|
||||
case ASN1_OP_D2I_POST:
|
||||
X509_CRL_digest(crl, EVP_sha1(), crl->sha1_hash, NULL);
|
||||
X509_CRL_digest(crl, md, crl->sha1_hash, NULL);
|
||||
crl->idp = X509_CRL_get_ext_d2i(crl,
|
||||
NID_issuing_distribution_point, NULL,
|
||||
NULL);
|
||||
|
||||
@@ -14,9 +14,15 @@
|
||||
#include "internal/asn1_int.h"
|
||||
#include "internal/evp_int.h"
|
||||
#include "internal/x509_int.h"
|
||||
#include <openssl/rsa.h>
|
||||
#include <openssl/dsa.h>
|
||||
#include <openssl/paillier.h>
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
# include <openssl/rsa.h>
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
# include <openssl/dsa.h>
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_PAILLIER
|
||||
# include <openssl/paillier.h>
|
||||
#endif
|
||||
|
||||
struct X509_pubkey_st {
|
||||
X509_ALGOR *algor;
|
||||
|
||||
Reference in New Issue
Block a user