diff options
author | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2015-11-12 11:43:52 +0100 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2015-11-12 11:57:59 +0100 |
commit | e19a5047916e0f4403b905f8ff5370caae968cab (patch) | |
tree | bac6467702c9154498ddef22238486e360404b37 /lib/x509/x509_write.c | |
parent | c3f9880e34896741cabfca55c2df5659b84c748e (diff) | |
download | gnutls-e19a5047916e0f4403b905f8ff5370caae968cab.tar.gz |
Added gnutls_x509_crt_set_issuer_unique_id() and gnutls_x509_crt_set_subject_unique_id()
Diffstat (limited to 'lib/x509/x509_write.c')
-rw-r--r-- | lib/x509/x509_write.c | 92 |
1 files changed, 88 insertions, 4 deletions
diff --git a/lib/x509/x509_write.c b/lib/x509/x509_write.c index 9ef092a35e..d1bf9cb4b4 100644 --- a/lib/x509/x509_write.c +++ b/lib/x509/x509_write.c @@ -1005,17 +1005,101 @@ gnutls_x509_crt_set_serial(gnutls_x509_crt_t cert, const void *serial, } +/** + * gnutls_x509_crt_set_issuer_unique_id: + * @cert: a certificate of type #gnutls_x509_crt_t + * @id: The unique ID + * @id_size: Holds the size of the unique ID. + * + * This function will set the X.509 certificate's issuer unique ID field. + * + * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a + * negative error value. + **/ +int +gnutls_x509_crt_set_issuer_unique_id(gnutls_x509_crt_t cert, const void *id, + size_t id_size) +{ + int ret; + + if (cert == NULL) { + gnutls_assert(); + return GNUTLS_E_INVALID_REQUEST; + } + + ret = + asn1_write_value(cert->cert, "tbsCertificate.issuerUniqueID", + id, id_size*8); + if (ret != ASN1_SUCCESS) { + gnutls_assert(); + return _gnutls_asn2err(ret); + } + + return 0; +} + +/** + * gnutls_x509_crt_set_subject_unique_id: + * @cert: a certificate of type #gnutls_x509_crt_t + * @id: The unique ID + * @id_size: Holds the size of the unique ID. + * + * This function will set the X.509 certificate's subject unique ID field. + * + * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a + * negative error value. + **/ +int +gnutls_x509_crt_set_subject_unique_id(gnutls_x509_crt_t cert, const void *id, + size_t id_size) +{ + int ret; + + if (cert == NULL) { + gnutls_assert(); + return GNUTLS_E_INVALID_REQUEST; + } + + ret = + asn1_write_value(cert->cert, "tbsCertificate.subjectUniqueID", + id, id_size*8); + if (ret != ASN1_SUCCESS) { + gnutls_assert(); + return _gnutls_asn2err(ret); + } + + return 0; +} + /* If OPTIONAL fields have not been initialized then * disable them. */ static void disable_optional_stuff(gnutls_x509_crt_t cert) { + asn1_data_node_st n; + asn1_node node; + unsigned remove_subject_unique_id = 1; + unsigned remove_issuer_unique_id = 1; + + node = asn1_find_node(cert->cert, "tbsCertificate.issuerUniqueID"); + if (node) { + if (asn1_read_node_value(node, &n) == ASN1_SUCCESS && n.value_len != 0) + remove_issuer_unique_id = 0; + } - asn1_write_value(cert->cert, "tbsCertificate.issuerUniqueID", NULL, - 0); + node = asn1_find_node(cert->cert, "tbsCertificate.subjectUniqueID"); + if (node) { + if (asn1_read_node_value(node, &n) == ASN1_SUCCESS && n.value_len != 0) + remove_subject_unique_id = 0; + } + + if (remove_issuer_unique_id) + asn1_write_value(cert->cert, "tbsCertificate.issuerUniqueID", NULL, + 0); - asn1_write_value(cert->cert, "tbsCertificate.subjectUniqueID", - NULL, 0); + if (remove_subject_unique_id) + asn1_write_value(cert->cert, "tbsCertificate.subjectUniqueID", + NULL, 0); if (cert->use_extensions == 0) { _gnutls_debug_log("Disabling X.509 extensions.\n"); |