Skip to content

Commit c73fde7

Browse files
committed
Merge remote-tracking branch 'origin/pr/2531' into development
Ensure tests pass when the submodule is used by updating the list of crypto tests to include test_suite_oid in both tests/CMakeLists.txt and tests/Makefile. * origin/pr/2531: Add changeLog entry Add certificate policy of type any policy id
2 parents 3930e18 + 3b11c85 commit c73fde7

File tree

7 files changed

+72
-0
lines changed

7 files changed

+72
-0
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ mbed TLS ChangeLog (Sorted per branch, date)
22

33
= mbed TLS x.x.x branch released xxxx-xx-xx
44

5+
Features
6+
* Add the Any Policy certificate policy oid, as defined in
7+
rfc 5280 section 4.2.1.4.
8+
59
Bugfix
610
* Fix private key DER output in the key_app_writer example. File contents
711
were shifted by one byte, creating an invalid ASN.1 tag. Fixed by

include/mbedtls/oid.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@
167167
#define MBEDTLS_OID_INIHIBIT_ANYPOLICY MBEDTLS_OID_ID_CE "\x36" /**< id-ce-inhibitAnyPolicy OBJECT IDENTIFIER ::= { id-ce 54 } */
168168
#define MBEDTLS_OID_FRESHEST_CRL MBEDTLS_OID_ID_CE "\x2E" /**< id-ce-freshestCRL OBJECT IDENTIFIER ::= { id-ce 46 } */
169169

170+
/*
171+
* Certificate policies
172+
*/
173+
#define MBEDTLS_OID_ANY_POLICY MBEDTLS_OID_CERTIFICATE_POLICIES "\x00" /**< anyPolicy OBJECT IDENTIFIER ::= { id-ce-certificatePolicies 0 } */
174+
170175
/*
171176
* Netscape certificate extensions
172177
*/
@@ -576,6 +581,16 @@ int mbedtls_oid_get_md_hmac( const mbedtls_asn1_buf *oid, mbedtls_md_type_t *md_
576581
*/
577582
int mbedtls_oid_get_extended_key_usage( const mbedtls_asn1_buf *oid, const char **desc );
578583

584+
/**
585+
* \brief Translate certificate policies OID into description
586+
*
587+
* \param oid OID to use
588+
* \param desc place to store string pointer
589+
*
590+
* \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
591+
*/
592+
int mbedtls_oid_get_certificate_policies( const mbedtls_asn1_buf *oid, const char **desc );
593+
579594
/**
580595
* \brief Translate md_type into hash algorithm OID
581596
*

library/oid.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,15 @@ static const mbedtls_oid_descriptor_t oid_ext_key_usage[] =
296296
FN_OID_TYPED_FROM_ASN1(mbedtls_oid_descriptor_t, ext_key_usage, oid_ext_key_usage)
297297
FN_OID_GET_ATTR1(mbedtls_oid_get_extended_key_usage, mbedtls_oid_descriptor_t, ext_key_usage, const char *, description)
298298

299+
static const mbedtls_oid_descriptor_t oid_certificate_policies[] =
300+
{
301+
{ ADD_LEN( MBEDTLS_OID_ANY_POLICY ), "anyPolicy", "Any Policy" },
302+
{ NULL, 0, NULL, NULL },
303+
};
304+
305+
FN_OID_TYPED_FROM_ASN1(mbedtls_oid_descriptor_t, certificate_policies, oid_certificate_policies)
306+
FN_OID_GET_ATTR1(mbedtls_oid_get_certificate_policies, mbedtls_oid_descriptor_t, certificate_policies, const char *, description)
307+
299308
#if defined(MBEDTLS_MD_C)
300309
/*
301310
* For SignatureAlgorithmIdentifier

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ if(NOT USE_CRYPTO_SUBMODULE)
116116
add_test_suite(memory_buffer_alloc)
117117
add_test_suite(mpi)
118118
add_test_suite(nist_kw)
119+
add_test_suite(oid)
119120
add_test_suite(pem)
120121
add_test_suite(pkcs1_v15)
121122
add_test_suite(pkcs1_v21)

tests/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ APPS := $(filter-out \
9797
test_suite_memory_buffer_alloc \
9898
test_suite_mpi \
9999
test_suite_nist_kw \
100+
test_suite_oid \
100101
test_suite_pem \
101102
test_suite_pk \
102103
test_suite_pkcs1_v15 \

tests/suites/test_suite_oid.data

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
OID get Any Policy certificate policy
2+
oid_get_certificate_policies:"551D2000":"Any Policy"
3+
4+
OID get certificate policy invalid oid
5+
oid_get_certificate_policies:"5533445566":""
6+
7+
OID get certificate policy wrong oid - id-ce-authorityKeyIdentifier
8+
oid_get_certificate_policies:"551D23":""

tests/suites/test_suite_oid.function

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* BEGIN_HEADER */
2+
#include "mbedtls/oid.h"
3+
#include "mbedtls/asn1.h"
4+
#include "mbedtls/asn1write.h"
5+
#include "string.h"
6+
/* END_HEADER */
7+
8+
/* BEGIN_DEPENDENCIES
9+
* depends_on:MBEDTLS_OID_C
10+
* END_DEPENDENCIES
11+
*/
12+
13+
/* BEGIN_CASE depends_on:MBEDTLS_ASN1_WRITE_C*/
14+
void oid_get_certificate_policies( data_t * oid, char * result_str )
15+
{
16+
mbedtls_asn1_buf asn1_buf = { 0, 0, NULL };
17+
int ret;
18+
const char *desc;
19+
20+
asn1_buf.tag = MBEDTLS_ASN1_OID;
21+
asn1_buf.p = oid->x;
22+
asn1_buf.len = oid->len;
23+
24+
ret = mbedtls_oid_get_certificate_policies( &asn1_buf, &desc );
25+
if( strlen( result_str ) == 0 )
26+
{
27+
TEST_ASSERT( ret == MBEDTLS_ERR_OID_NOT_FOUND );
28+
}
29+
else
30+
{
31+
TEST_ASSERT( strcmp( ( char* )desc, result_str ) == 0 );
32+
}
33+
}
34+
/* END_CASE */

0 commit comments

Comments
 (0)