2019-03-25 17:22:52 +01:00
|
|
|
/* BEGIN_HEADER */
|
|
|
|
#include "mbedtls/oid.h"
|
|
|
|
#include "mbedtls/asn1.h"
|
|
|
|
#include "mbedtls/asn1write.h"
|
|
|
|
#include "string.h"
|
2022-09-15 11:29:35 +02:00
|
|
|
#include "mbedtls/legacy_or_psa.h"
|
2019-03-25 17:22:52 +01:00
|
|
|
/* END_HEADER */
|
|
|
|
|
|
|
|
/* BEGIN_DEPENDENCIES
|
2020-10-09 10:19:39 +02:00
|
|
|
* depends_on:MBEDTLS_OID_C:!MBEDTLS_X509_REMOVE_INFO
|
2019-03-25 17:22:52 +01:00
|
|
|
* END_DEPENDENCIES
|
|
|
|
*/
|
|
|
|
|
2019-04-03 08:46:27 +02:00
|
|
|
/* BEGIN_CASE */
|
2023-01-11 14:50:10 +01:00
|
|
|
void oid_get_certificate_policies(data_t *oid, char *result_str)
|
2019-03-25 17:22:52 +01:00
|
|
|
{
|
|
|
|
mbedtls_asn1_buf asn1_buf = { 0, 0, NULL };
|
|
|
|
int ret;
|
|
|
|
const char *desc;
|
|
|
|
|
|
|
|
asn1_buf.tag = MBEDTLS_ASN1_OID;
|
|
|
|
asn1_buf.p = oid->x;
|
|
|
|
asn1_buf.len = oid->len;
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
ret = mbedtls_oid_get_certificate_policies(&asn1_buf, &desc);
|
|
|
|
if (strlen(result_str) == 0) {
|
|
|
|
TEST_ASSERT(ret == MBEDTLS_ERR_OID_NOT_FOUND);
|
|
|
|
} else {
|
|
|
|
TEST_ASSERT(ret == 0);
|
|
|
|
TEST_ASSERT(strcmp((char *) desc, result_str) == 0);
|
2019-03-25 17:22:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* END_CASE */
|
2019-04-01 17:12:23 +02:00
|
|
|
|
|
|
|
/* BEGIN_CASE */
|
2023-01-11 14:50:10 +01:00
|
|
|
void oid_get_extended_key_usage(data_t *oid, char *result_str)
|
2019-04-01 17:12:23 +02:00
|
|
|
{
|
|
|
|
mbedtls_asn1_buf asn1_buf = { 0, 0, NULL };
|
|
|
|
int ret;
|
|
|
|
const char *desc;
|
|
|
|
|
|
|
|
asn1_buf.tag = MBEDTLS_ASN1_OID;
|
|
|
|
asn1_buf.p = oid->x;
|
|
|
|
asn1_buf.len = oid->len;
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
ret = mbedtls_oid_get_extended_key_usage(&asn1_buf, &desc);
|
|
|
|
if (strlen(result_str) == 0) {
|
|
|
|
TEST_ASSERT(ret == MBEDTLS_ERR_OID_NOT_FOUND);
|
|
|
|
} else {
|
|
|
|
TEST_ASSERT(ret == 0);
|
|
|
|
TEST_ASSERT(strcmp((char *) desc, result_str) == 0);
|
2019-04-01 17:12:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* END_CASE */
|
2019-04-03 08:45:07 +02:00
|
|
|
|
|
|
|
/* BEGIN_CASE */
|
2023-01-11 14:50:10 +01:00
|
|
|
void oid_get_x509_extension(data_t *oid, int exp_type)
|
2019-04-03 08:45:07 +02:00
|
|
|
{
|
|
|
|
mbedtls_asn1_buf ext_oid = { 0, 0, NULL };
|
|
|
|
int ret;
|
|
|
|
int ext_type;
|
|
|
|
|
|
|
|
ext_oid.tag = MBEDTLS_ASN1_OID;
|
|
|
|
ext_oid.p = oid->x;
|
|
|
|
ext_oid.len = oid->len;
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
ret = mbedtls_oid_get_x509_ext_type(&ext_oid, &ext_type);
|
|
|
|
if (exp_type == 0) {
|
|
|
|
TEST_ASSERT(ret == MBEDTLS_ERR_OID_NOT_FOUND);
|
|
|
|
} else {
|
|
|
|
TEST_ASSERT(ret == 0);
|
|
|
|
TEST_ASSERT(ext_type == exp_type);
|
2019-04-03 08:45:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* END_CASE */
|
2019-05-06 18:15:44 +02:00
|
|
|
|
2022-08-05 11:47:48 +02:00
|
|
|
/* BEGIN_CASE */
|
2023-01-11 14:50:10 +01:00
|
|
|
void oid_get_md_alg_id(data_t *oid, int exp_md_id)
|
2019-05-06 18:15:44 +02:00
|
|
|
{
|
|
|
|
mbedtls_asn1_buf md_oid = { 0, 0, NULL };
|
|
|
|
int ret;
|
|
|
|
mbedtls_md_type_t md_id = 0;
|
|
|
|
|
|
|
|
md_oid.tag = MBEDTLS_ASN1_OID;
|
|
|
|
md_oid.p = oid->x;
|
|
|
|
md_oid.len = oid->len;
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
ret = mbedtls_oid_get_md_alg(&md_oid, &md_id);
|
2019-05-06 18:15:44 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (exp_md_id < 0) {
|
|
|
|
TEST_ASSERT(ret == MBEDTLS_ERR_OID_NOT_FOUND);
|
|
|
|
TEST_ASSERT(md_id == 0);
|
|
|
|
} else {
|
|
|
|
TEST_ASSERT(ret == 0);
|
|
|
|
TEST_ASSERT((mbedtls_md_type_t) exp_md_id == md_id);
|
2019-05-06 18:15:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* END_CASE */
|
2023-02-14 18:29:16 +01:00
|
|
|
|
|
|
|
/* BEGIN_CASE */
|
|
|
|
void oid_get_numeric_string(data_t *oid, int error_ret, char *result_str)
|
|
|
|
{
|
|
|
|
char buf[256];
|
|
|
|
mbedtls_asn1_buf input_oid = { 0, 0, NULL };
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
input_oid.tag = MBEDTLS_ASN1_OID;
|
|
|
|
input_oid.p = oid->x;
|
|
|
|
input_oid.len = oid->len;
|
|
|
|
|
|
|
|
ret = mbedtls_oid_get_numeric_string(buf, sizeof(buf), &input_oid);
|
|
|
|
|
|
|
|
if (error_ret == 0) {
|
|
|
|
TEST_ASSERT(strcmp(buf, result_str) == 0);
|
|
|
|
} else {
|
|
|
|
TEST_EQUAL(ret, error_ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* END_CASE */
|
2023-02-15 12:09:10 +01:00
|
|
|
|
|
|
|
/* BEGIN_CASE */
|
|
|
|
void oid_from_numeric_string(char *oid_str, int error_ret,
|
|
|
|
data_t *exp_oid_buf)
|
|
|
|
{
|
|
|
|
mbedtls_asn1_buf oid = { 0, 0, NULL };
|
|
|
|
mbedtls_asn1_buf exp_oid = { 0, 0, NULL };
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
exp_oid.tag = MBEDTLS_ASN1_OID;
|
|
|
|
exp_oid.p = exp_oid_buf->x;
|
|
|
|
exp_oid.len = exp_oid_buf->len;
|
|
|
|
|
|
|
|
ret = mbedtls_oid_from_numeric_string(&oid, oid_str, strlen(oid_str));
|
|
|
|
|
|
|
|
if (error_ret == 0) {
|
|
|
|
TEST_EQUAL(oid.len, exp_oid.len);
|
|
|
|
TEST_ASSERT(memcmp(oid.p, exp_oid.p, oid.len) == 0);
|
|
|
|
mbedtls_free(oid.p);
|
|
|
|
oid.p = NULL;
|
|
|
|
oid.len = 0;
|
|
|
|
} else {
|
|
|
|
TEST_EQUAL(ret, error_ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* END_CASE */
|