early-access version 2698

This commit is contained in:
pineappleEA
2022-04-24 22:29:35 +02:00
parent c96f949832
commit caa0c2911b
486 changed files with 37806 additions and 14362 deletions

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: obj_dat.c,v 1.42 2019/07/03 03:24:04 deraadt Exp $ */
/* $OpenBSD: obj_dat.c,v 1.49 2022/03/19 17:49:32 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -69,6 +69,8 @@
#include <openssl/lhash.h>
#include <openssl/objects.h>
#include "asn1_locl.h"
/* obj_dat.h is generated from objects.h by obj_dat.pl */
#include "obj_dat.h"
@@ -456,9 +458,9 @@ OBJ_obj2nid(const ASN1_OBJECT *a)
const unsigned int *op;
ADDED_OBJ ad, *adp;
if (a == NULL)
if (a == NULL || a->length == 0)
return (NID_undef);
if (a->nid != 0)
if (a->nid != NID_undef)
return (a->nid);
if (added != NULL) {
@@ -483,12 +485,7 @@ OBJ_obj2nid(const ASN1_OBJECT *a)
ASN1_OBJECT *
OBJ_txt2obj(const char *s, int no_name)
{
int nid = NID_undef;
ASN1_OBJECT *op = NULL;
unsigned char *buf;
unsigned char *p;
const unsigned char *cp;
int i, j;
int nid;
if (!no_name) {
if (((nid = OBJ_sn2nid(s)) != NID_undef) ||
@@ -496,149 +493,16 @@ OBJ_txt2obj(const char *s, int no_name)
return OBJ_nid2obj(nid);
}
/* Work out size of content octets */
i = a2d_ASN1_OBJECT(NULL, 0, s, -1);
if (i <= 0) {
/* Don't clear the error */
/*ERR_clear_error();*/
return NULL;
}
/* Work out total size */
j = ASN1_object_size(0, i, V_ASN1_OBJECT);
if ((buf = malloc(j)) == NULL)
return NULL;
p = buf;
/* Write out tag+length */
ASN1_put_object(&p, 0, i, V_ASN1_OBJECT, V_ASN1_UNIVERSAL);
/* Write out contents */
a2d_ASN1_OBJECT(p, i, s, -1);
cp = buf;
op = d2i_ASN1_OBJECT(NULL, &cp, j);
free(buf);
return op;
return t2i_ASN1_OBJECT_internal(s);
}
int
OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name)
OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *aobj, int no_name)
{
int i, ret = 0, len, nid, first = 1, use_bn;
BIGNUM *bl = NULL;
unsigned long l;
const unsigned char *p;
if (aobj == NULL || aobj->data == NULL)
return 0;
/* Ensure that, at every state, |buf| is NUL-terminated. */
if (buf_len > 0)
buf[0] = '\0';
if ((a == NULL) || (a->data == NULL))
goto err;
if (!no_name && (nid = OBJ_obj2nid(a)) != NID_undef) {
const char *s;
s = OBJ_nid2ln(nid);
if (s == NULL)
s = OBJ_nid2sn(nid);
if (s) {
ret = strlcpy(buf, s, buf_len);
goto out;
}
}
len = a->length;
p = a->data;
while (len > 0) {
l = 0;
use_bn = 0;
for (;;) {
unsigned char c = *p++;
len--;
if ((len == 0) && (c & 0x80))
goto err;
if (use_bn) {
if (!BN_add_word(bl, c & 0x7f))
goto err;
} else
l |= c & 0x7f;
if (!(c & 0x80))
break;
if (!use_bn && (l > (ULONG_MAX >> 7L))) {
if (!bl && !(bl = BN_new()))
goto err;
if (!BN_set_word(bl, l))
goto err;
use_bn = 1;
}
if (use_bn) {
if (!BN_lshift(bl, bl, 7))
goto err;
} else
l <<= 7L;
}
if (first) {
first = 0;
if (l >= 80) {
i = 2;
if (use_bn) {
if (!BN_sub_word(bl, 80))
goto err;
} else
l -= 80;
} else {
i = (int)(l / 40);
l -= (long)(i * 40);
}
if (buf_len > 1) {
*buf++ = i + '0';
*buf = '\0';
buf_len--;
}
ret++;
}
if (use_bn) {
char *bndec;
bndec = BN_bn2dec(bl);
if (!bndec)
goto err;
i = snprintf(buf, buf_len, ".%s", bndec);
free(bndec);
if (i < 0)
goto err;
if (i >= buf_len) {
buf_len = 0;
} else {
buf += i;
buf_len -= i;
}
ret += i;
} else {
i = snprintf(buf, buf_len, ".%lu", l);
if (i < 0)
goto err;
if (i >= buf_len) {
buf_len = 0;
} else {
buf += i;
buf_len -= i;
}
ret += i;
l = 0;
}
}
out:
BN_free(bl);
return ret;
err:
ret = 0;
goto out;
return i2t_ASN1_OBJECT_internal(aobj, buf, buf_len, no_name);
}
int
@@ -815,3 +679,24 @@ OBJ_create(const char *oid, const char *sn, const char *ln)
free(buf);
return (ok);
}
size_t
OBJ_length(const ASN1_OBJECT *obj)
{
if (obj == NULL)
return 0;
if (obj->length < 0)
return 0;
return obj->length;
}
const unsigned char *
OBJ_get0_data(const ASN1_OBJECT *obj)
{
if (obj == NULL)
return NULL;
return obj->data;
}