Import OpenSSL 1.1.0h
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
#include <openssl/objects.h>
|
||||
#include <openssl/safestack.h>
|
||||
#include <openssl/e_os2.h>
|
||||
#include <internal/thread_once.h>
|
||||
#include "obj_lcl.h"
|
||||
|
||||
/*
|
||||
@@ -44,6 +45,7 @@ static int obj_strcmp(const char *a, const char *b)
|
||||
*/
|
||||
static LHASH_OF(OBJ_NAME) *names_lh = NULL;
|
||||
static int names_type_num = OBJ_NAME_TYPE_NUM;
|
||||
static CRYPTO_RWLOCK *lock = NULL;
|
||||
|
||||
struct name_funcs_st {
|
||||
unsigned long (*hash_func) (const char *name);
|
||||
@@ -62,23 +64,33 @@ static STACK_OF(NAME_FUNCS) *name_funcs_stack;
|
||||
static unsigned long obj_name_hash(const OBJ_NAME *a);
|
||||
static int obj_name_cmp(const OBJ_NAME *a, const OBJ_NAME *b);
|
||||
|
||||
int OBJ_NAME_init(void)
|
||||
static CRYPTO_ONCE init = CRYPTO_ONCE_STATIC_INIT;
|
||||
DEFINE_RUN_ONCE_STATIC(o_names_init)
|
||||
{
|
||||
if (names_lh != NULL)
|
||||
return (1);
|
||||
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);
|
||||
names_lh = lh_OBJ_NAME_new(obj_name_hash, obj_name_cmp);
|
||||
lock = CRYPTO_THREAD_lock_new();
|
||||
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);
|
||||
return (names_lh != NULL);
|
||||
return names_lh != NULL && lock != NULL;
|
||||
}
|
||||
|
||||
int OBJ_NAME_init(void)
|
||||
{
|
||||
return RUN_ONCE(&init, o_names_init);
|
||||
}
|
||||
|
||||
int OBJ_NAME_new_index(unsigned long (*hash_func) (const char *),
|
||||
int (*cmp_func) (const char *, const char *),
|
||||
void (*free_func) (const char *, int, const char *))
|
||||
{
|
||||
int ret, i, push;
|
||||
int ret = 0, i, push;
|
||||
NAME_FUNCS *name_funcs;
|
||||
|
||||
if (!OBJ_NAME_init())
|
||||
return 0;
|
||||
|
||||
CRYPTO_THREAD_write_lock(lock);
|
||||
|
||||
if (name_funcs_stack == NULL) {
|
||||
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);
|
||||
name_funcs_stack = sk_NAME_FUNCS_new_null();
|
||||
@@ -86,7 +98,7 @@ int OBJ_NAME_new_index(unsigned long (*hash_func) (const char *),
|
||||
}
|
||||
if (name_funcs_stack == NULL) {
|
||||
/* ERROR */
|
||||
return (0);
|
||||
goto out;
|
||||
}
|
||||
ret = names_type_num;
|
||||
names_type_num++;
|
||||
@@ -96,7 +108,8 @@ int OBJ_NAME_new_index(unsigned long (*hash_func) (const char *),
|
||||
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);
|
||||
if (name_funcs == NULL) {
|
||||
OBJerr(OBJ_F_OBJ_NAME_NEW_INDEX, ERR_R_MALLOC_FAILURE);
|
||||
return (0);
|
||||
ret = 0;
|
||||
goto out;
|
||||
}
|
||||
name_funcs->hash_func = OPENSSL_LH_strhash;
|
||||
name_funcs->cmp_func = obj_strcmp;
|
||||
@@ -108,7 +121,8 @@ int OBJ_NAME_new_index(unsigned long (*hash_func) (const char *),
|
||||
if (!push) {
|
||||
OBJerr(OBJ_F_OBJ_NAME_NEW_INDEX, ERR_R_MALLOC_FAILURE);
|
||||
OPENSSL_free(name_funcs);
|
||||
return 0;
|
||||
ret = 0;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
name_funcs = sk_NAME_FUNCS_value(name_funcs_stack, ret);
|
||||
@@ -118,7 +132,10 @@ int OBJ_NAME_new_index(unsigned long (*hash_func) (const char *),
|
||||
name_funcs->cmp_func = cmp_func;
|
||||
if (free_func != NULL)
|
||||
name_funcs->free_func = free_func;
|
||||
return (ret);
|
||||
|
||||
out:
|
||||
CRYPTO_THREAD_unlock(lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int obj_name_cmp(const OBJ_NAME *a, const OBJ_NAME *b)
|
||||
@@ -134,7 +151,7 @@ static int obj_name_cmp(const OBJ_NAME *a, const OBJ_NAME *b)
|
||||
} else
|
||||
ret = strcmp(a->name, b->name);
|
||||
}
|
||||
return (ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static unsigned long obj_name_hash(const OBJ_NAME *a)
|
||||
@@ -150,18 +167,20 @@ static unsigned long obj_name_hash(const OBJ_NAME *a)
|
||||
ret = OPENSSL_LH_strhash(a->name);
|
||||
}
|
||||
ret ^= a->type;
|
||||
return (ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
const char *OBJ_NAME_get(const char *name, int type)
|
||||
{
|
||||
OBJ_NAME on, *ret;
|
||||
int num = 0, alias;
|
||||
const char *value = NULL;
|
||||
|
||||
if (name == NULL)
|
||||
return (NULL);
|
||||
if ((names_lh == NULL) && !OBJ_NAME_init())
|
||||
return (NULL);
|
||||
return NULL;
|
||||
if (!OBJ_NAME_init())
|
||||
return NULL;
|
||||
CRYPTO_THREAD_read_lock(lock);
|
||||
|
||||
alias = type & OBJ_NAME_ALIAS;
|
||||
type &= ~OBJ_NAME_ALIAS;
|
||||
@@ -172,24 +191,30 @@ const char *OBJ_NAME_get(const char *name, int type)
|
||||
for (;;) {
|
||||
ret = lh_OBJ_NAME_retrieve(names_lh, &on);
|
||||
if (ret == NULL)
|
||||
return (NULL);
|
||||
break;
|
||||
if ((ret->alias) && !alias) {
|
||||
if (++num > 10)
|
||||
return (NULL);
|
||||
break;
|
||||
on.name = ret->data;
|
||||
} else {
|
||||
return (ret->data);
|
||||
value = ret->data;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
CRYPTO_THREAD_unlock(lock);
|
||||
return value;
|
||||
}
|
||||
|
||||
int OBJ_NAME_add(const char *name, int type, const char *data)
|
||||
{
|
||||
OBJ_NAME *onp, *ret;
|
||||
int alias;
|
||||
int alias, ok = 0;
|
||||
|
||||
if ((names_lh == NULL) && !OBJ_NAME_init())
|
||||
return (0);
|
||||
if (!OBJ_NAME_init())
|
||||
return 0;
|
||||
|
||||
CRYPTO_THREAD_write_lock(lock);
|
||||
|
||||
alias = type & OBJ_NAME_ALIAS;
|
||||
type &= ~OBJ_NAME_ALIAS;
|
||||
@@ -197,7 +222,7 @@ int OBJ_NAME_add(const char *name, int type, const char *data)
|
||||
onp = OPENSSL_malloc(sizeof(*onp));
|
||||
if (onp == NULL) {
|
||||
/* ERROR */
|
||||
return 0;
|
||||
goto unlock;
|
||||
}
|
||||
|
||||
onp->name = name;
|
||||
@@ -223,18 +248,26 @@ int OBJ_NAME_add(const char *name, int type, const char *data)
|
||||
if (lh_OBJ_NAME_error(names_lh)) {
|
||||
/* ERROR */
|
||||
OPENSSL_free(onp);
|
||||
return 0;
|
||||
goto unlock;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
|
||||
ok = 1;
|
||||
|
||||
unlock:
|
||||
CRYPTO_THREAD_unlock(lock);
|
||||
return ok;
|
||||
}
|
||||
|
||||
int OBJ_NAME_remove(const char *name, int type)
|
||||
{
|
||||
OBJ_NAME on, *ret;
|
||||
int ok = 0;
|
||||
|
||||
if (names_lh == NULL)
|
||||
return (0);
|
||||
if (!OBJ_NAME_init())
|
||||
return 0;
|
||||
|
||||
CRYPTO_THREAD_write_lock(lock);
|
||||
|
||||
type &= ~OBJ_NAME_ALIAS;
|
||||
on.name = name;
|
||||
@@ -253,9 +286,11 @@ int OBJ_NAME_remove(const char *name, int type)
|
||||
ret->data);
|
||||
}
|
||||
OPENSSL_free(ret);
|
||||
return (1);
|
||||
} else
|
||||
return (0);
|
||||
ok = 1;
|
||||
}
|
||||
|
||||
CRYPTO_THREAD_unlock(lock);
|
||||
return ok;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
@@ -363,8 +398,10 @@ void OBJ_NAME_cleanup(int type)
|
||||
if (type < 0) {
|
||||
lh_OBJ_NAME_free(names_lh);
|
||||
sk_NAME_FUNCS_pop_free(name_funcs_stack, name_funcs_free);
|
||||
CRYPTO_THREAD_lock_free(lock);
|
||||
names_lh = NULL;
|
||||
name_funcs_stack = NULL;
|
||||
lock = NULL;
|
||||
} else
|
||||
lh_OBJ_NAME_set_down_load(names_lh, down_load);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -213,8 +213,8 @@ int OBJ_add_object(const ASN1_OBJECT *obj)
|
||||
err:
|
||||
for (i = ADDED_DATA; i <= ADDED_NID; i++)
|
||||
OPENSSL_free(ao[i]);
|
||||
OPENSSL_free(o);
|
||||
return (NID_undef);
|
||||
ASN1_OBJECT_free(o);
|
||||
return NID_undef;
|
||||
}
|
||||
|
||||
ASN1_OBJECT *OBJ_nid2obj(int n)
|
||||
@@ -500,7 +500,7 @@ int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name)
|
||||
n += i;
|
||||
OPENSSL_free(bndec);
|
||||
} else {
|
||||
BIO_snprintf(tbuf, sizeof tbuf, ".%lu", l);
|
||||
BIO_snprintf(tbuf, sizeof(tbuf), ".%lu", l);
|
||||
i = strlen(tbuf);
|
||||
if (buf && (buf_len > 0)) {
|
||||
OPENSSL_strlcpy(buf, tbuf, buf_len);
|
||||
@@ -632,6 +632,10 @@ const void *OBJ_bsearch_ex_(const void *key, const void *base_, int num,
|
||||
return (p);
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse a BIO sink to create some extra oid's objects.
|
||||
* Line format:<OID:isdigit or '.']><isspace><SN><isspace><LN>
|
||||
*/
|
||||
int OBJ_create_objects(BIO *in)
|
||||
{
|
||||
char buf[512];
|
||||
@@ -653,9 +657,9 @@ int OBJ_create_objects(BIO *in)
|
||||
*(s++) = '\0';
|
||||
while (isspace((unsigned char)*s))
|
||||
s++;
|
||||
if (*s == '\0')
|
||||
if (*s == '\0') {
|
||||
s = NULL;
|
||||
else {
|
||||
} else {
|
||||
l = s;
|
||||
while ((*l != '\0') && !isspace((unsigned char)*l))
|
||||
l++;
|
||||
@@ -663,15 +667,18 @@ int OBJ_create_objects(BIO *in)
|
||||
*(l++) = '\0';
|
||||
while (isspace((unsigned char)*l))
|
||||
l++;
|
||||
if (*l == '\0')
|
||||
if (*l == '\0') {
|
||||
l = NULL;
|
||||
} else
|
||||
}
|
||||
} else {
|
||||
l = NULL;
|
||||
}
|
||||
}
|
||||
} else
|
||||
} else {
|
||||
s = NULL;
|
||||
if ((o == NULL) || (*o == '\0'))
|
||||
return (num);
|
||||
}
|
||||
if (*o == '\0')
|
||||
return num;
|
||||
if (!OBJ_create(o, s, l))
|
||||
return (num);
|
||||
num++;
|
||||
@@ -685,7 +692,8 @@ int OBJ_create(const char *oid, const char *sn, const char *ln)
|
||||
int ok = 0;
|
||||
|
||||
/* Check to see if short or long name already present */
|
||||
if (OBJ_sn2nid(sn) != NID_undef || OBJ_ln2nid(ln) != NID_undef) {
|
||||
if ((sn != NULL && OBJ_sn2nid(sn) != NID_undef)
|
||||
|| (ln != NULL && OBJ_ln2nid(ln) != NID_undef)) {
|
||||
OBJerr(OBJ_F_OBJ_CREATE, OBJ_R_OID_EXISTS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user