Merge pull request #6442 from embedded-specialties/int-sequence

ASN.1 Integer sequence
This commit is contained in:
Sean Parkinson
2023-05-30 09:37:55 +10:00
committed by GitHub
4 changed files with 31 additions and 7 deletions

View File

@ -65,6 +65,9 @@ static int wolfssl_asn1_item_new(void** item, int type)
case WOLFSSL_ASN1_BIT_STRING_ASN1:
*(WOLFSSL_ASN1_BIT_STRING**)item = wolfSSL_ASN1_BIT_STRING_new();
break;
case WOLFSSL_ASN1_INTEGER_ASN1:
*(WOLFSSL_ASN1_INTEGER**)item = wolfSSL_ASN1_INTEGER_new();
break;
default:
WOLFSSL_MSG("Type not supported in wolfSSL_ASN1_item_new");
*(void**)item = NULL;
@ -128,6 +131,9 @@ static void wolfssl_asn1_item_free(void** item, int type)
case WOLFSSL_ASN1_BIT_STRING_ASN1:
wolfSSL_ASN1_BIT_STRING_free(*(WOLFSSL_ASN1_BIT_STRING**)item);
break;
case WOLFSSL_ASN1_INTEGER_ASN1:
wolfSSL_ASN1_INTEGER_free(*(WOLFSSL_ASN1_INTEGER**)item);
break;
default:
WOLFSSL_MSG("Type not supported in wolfSSL_ASN1_item_free");
}
@ -225,6 +231,17 @@ static int wolfssl_i2d_asn1_item(void** item, int type, byte* buf)
len = wolfSSL_i2d_ASN1_BIT_STRING(
*(const WOLFSSL_ASN1_BIT_STRING**)item, buf);
break;
case WOLFSSL_ASN1_INTEGER_ASN1:
{
byte *tmp_buf = buf;
len = wolfSSL_i2d_ASN1_INTEGER(
*(const WOLFSSL_ASN1_INTEGER**)item, &tmp_buf);
if ((buf == NULL) && (tmp_buf != NULL)) {
XFREE(tmp_buf, NULL, DYNAMIC_TYPE_ASN1);
tmp_buf = NULL;
}
}
break;
default:
WOLFSSL_MSG("Type not support in processMembers");
len = 0;
@ -543,7 +560,7 @@ WOLFSSL_ASN1_INTEGER* wolfSSL_ASN1_INTEGER_new(void)
void wolfSSL_ASN1_INTEGER_free(WOLFSSL_ASN1_INTEGER* in)
{
if ((in != NULL) && (in->isDynamic)) {
/* Dispose of any data allocated in BIT_STRING. */
/* Dispose of any data allocated in INTEGER. */
XFREE(in->data, NULL, DYNAMIC_TYPE_OPENSSL);
}
/* Dispose of the ASN.1 INTEGER object. */
@ -787,7 +804,7 @@ static int wolfssl_asn1_int_twos_compl(byte* data, int length, byte* neg)
* @return -1 when a is NULL or no data, out is NULL, dynamic memory allocation
* fails or encoding length fails.
*/
int wolfSSL_i2d_ASN1_INTEGER(WOLFSSL_ASN1_INTEGER* a, unsigned char** out)
int wolfSSL_i2d_ASN1_INTEGER(const WOLFSSL_ASN1_INTEGER* a, unsigned char** out)
{
int ret = 0;
byte* buf = NULL;

View File

@ -33539,7 +33539,8 @@ static int test_wolfSSL_IMPLEMENT_ASN1_FUNCTIONS(void)
const EC_GROUP *group;
const EC_POINT *point;
int nid;
TEST_ASN1 test_asn1;
TEST_ASN1 *test_asn1 = NULL;
const unsigned char badObjDer[] = { 0x06, 0x00 };
const unsigned char goodObjDer[] = {
0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01
@ -33631,12 +33632,17 @@ static int test_wolfSSL_IMPLEMENT_ASN1_FUNCTIONS(void)
XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
DPP_BOOTSTRAPPING_KEY_free(bootstrap);
/* Test integer */
AssertNotNull(test_asn1 = TEST_ASN1_new());
der = NULL;
ASN1_INTEGER_set(test_asn1->integer, 100);
AssertIntEQ(i2d_TEST_ASN1(test_asn1, &der), 5);
XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
TEST_ASN1_free(test_asn1);
/* Test error cases. */
AssertNull(TEST_ASN1_new());
AssertNull(wolfSSL_ASN1_item_new(NULL));
TEST_ASN1_free(NULL);
XMEMSET(&test_asn1, 0, sizeof(TEST_ASN1));
AssertIntEQ(i2d_TEST_ASN1(&test_asn1, &der), 0);
res = TEST_RES_CHECK(1);
#endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */

View File

@ -140,6 +140,7 @@ typedef struct {
typedef enum {
WOLFSSL_X509_ALGOR_ASN1 = 0,
WOLFSSL_ASN1_BIT_STRING_ASN1,
WOLFSSL_ASN1_INTEGER_ASN1,
} WOLFSSL_ASN1_TYPES;
#define ASN1_SEQUENCE(type) \

View File

@ -2057,7 +2057,7 @@ WOLFSSL_API WOLFSSL_ASN1_INTEGER* wolfSSL_d2i_ASN1_INTEGER(
WOLFSSL_ASN1_INTEGER** a,
const unsigned char** in,
long inSz);
WOLFSSL_API int wolfSSL_i2d_ASN1_INTEGER(WOLFSSL_ASN1_INTEGER* a,
WOLFSSL_API int wolfSSL_i2d_ASN1_INTEGER(const WOLFSSL_ASN1_INTEGER* a,
unsigned char** out);
WOLFSSL_API int wolfSSL_ASN1_TIME_print(WOLFSSL_BIO* bio, const WOLFSSL_ASN1_TIME* asnTime);