Added functions to retrieve CAR and CHR from certs.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos 2022-06-08 17:34:17 +02:00
parent 494df64674
commit 6d8161de73
2 changed files with 34 additions and 0 deletions

View file

@ -240,3 +240,34 @@ size_t asn1_cvc_aut(void *rsa_ecdsa, uint8_t key_type, uint8_t *buf, size_t buf_
mbedtls_mpi_free(&s);
return p-buf;
}
uint8_t *cvc_get_field(uint8_t *data, size_t len, size_t *olen, uint16_t tag) {
uint8_t *rdata = NULL;
if (data == NULL || len == 0)
return NULL;
if (asn1_find_tag(data, len, tag, olen, &rdata) == false)
return NULL;
return rdata;
}
uint8_t *cvc_get_car(uint8_t *data, size_t len, size_t *olen) {
uint8_t *bkdata = data;
if ((data = cvc_get_field(data, len, olen, 0x67)) == NULL) /* Check for CSR */
data = bkdata;
if ((data = cvc_get_field(data, len, olen, 0x7F21)) != NULL) {
if ((data = cvc_get_field(data, len, olen, 0x7F4E)) != NULL)
return cvc_get_field(data, len, olen, 0x42);
}
return NULL;
}
uint8_t *cvc_get_chr(uint8_t *data, size_t len, size_t *olen) {
uint8_t *bkdata = data;
if ((data = cvc_get_field(data, len, olen, 0x67)) == NULL) /* Check for CSR */
data = bkdata;
if ((data = cvc_get_field(data, len, olen, 0x7F21)) != NULL) {
if ((data = cvc_get_field(data, len, olen, 0x7F4E)) != NULL)
return cvc_get_field(data, len, olen, 0x5F20);
}
return NULL;
}

View file

@ -23,5 +23,8 @@
extern size_t asn1_cvc_cert(void *rsa_ecdsa, uint8_t key_type, uint8_t *buf, size_t buf_len);
extern size_t asn1_cvc_aut(void *rsa_ecdsa, uint8_t key_type, uint8_t *buf, size_t buf_len);
extern uint8_t *cvc_get_field(uint8_t *data, size_t len, size_t *olen, uint16_t tag);
extern uint8_t *cvc_get_car(uint8_t *data, size_t len, size_t *olen);
extern uint8_t *cvc_get_chr(uint8_t *data, size_t len, size_t *olen);
#endif