[PATCH] Add gnutls_x509_dn_export.
Joe Orton
jorton at redhat.com
Thu Feb 21 14:20:12 CET 2008
On Thu, Feb 21, 2008 at 11:39:17AM +0000, Joe Orton wrote:
> This adds another DN function, to export a DN object back to DER. (I
> only really need a DER export; the value of exporting a DN to PEM format
> is certainly questionable, but this is allowed for consistency with the
> other _foo_export functions)
Hmmm, that didn't actually work, and I don't really understand why. Can
anyone help? This is rather beyond my understanding of ASN.1/libtasn1!
The asn1_der_coding(asn1_data, "") call was failing with the error
ASN1_ELEMENT_NOT_FOUND in _gnutls_x509_export_int. Is that call not
supposed to provide the DER coding for the entire node?
If I change it as below, to pass "rdnSequence" rather than "", it does
work; there's a test case in here too.
diff --git a/doc/manpages/Makefile.am b/doc/manpages/Makefile.am
index 16bff3e..c185259 100644
--- a/doc/manpages/Makefile.am
+++ b/doc/manpages/Makefile.am
@@ -26,7 +26,7 @@ if ENABLE_SRP
dist_man_MANS += srptool.1
endif
-APIMANS = gnutls_oprfi_enable_client.3 gnutls_oprfi_enable_server.3 gnutls_server_name_get.3 gnutls_server_name_set.3 gnutls_alert_get_name.3 gnutls_alert_send.3 gnutls_error_to_alert.3 gnutls_alert_send_appropriate.3 gnutls_alert_get.3 gnutls_mac_get_name.3 gnutls_mac_get_id.3 gnutls_mac_get_key_size.3 gnutls_mac_list.3 gnutls_compression_get_name.3 gnutls_compression_get_id.3 gnutls_compression_list.3 gnutls_cipher_get_key_size.3 gnutls_cipher_get_name.3 gnutls_cipher_get_id.3 gnutls_cipher_list.3 gnutls_kx_get_name.3 gnutls_kx_get_id.3 gnutls_kx_list.3 gnutls_protocol_get_name.3 gnutls_protocol_get_id.3 gnutls_protocol_list.3 gnutls_cipher_suite_get_name.3 gnutls_cipher_suite_info.3 gnutls_certificate_type_get_name.3 gnutls_certificate_type_get_id.3 gnutls_certificate_type_list.3 gnutls_sign_algorithm_get_name.3 gnutls_pk_algorithm_get_name.3 gnutls_anon_free_server_credentials.3 gnutls_anon_allocate_server_credentials.3 gnutls_anon_free_client_credentials.3 gnutls_anon_allocate_client_credentials.3 gnutls_anon_set_server_dh_params.3 gnutls_anon_set_server_params_function.3 gnutls_credentials_clear.3 gnutls_credentials_set.3 gnutls_auth_get_type.3 gnutls_auth_server_get_type.3 gnutls_auth_client_get_type.3 gnutls_transport_set_errno.3 gnutls_transport_set_global_errno.3 gnutls_record_check_pending.3 gnutls_certificate_free_keys.3 gnutls_certificate_free_cas.3 gnutls_certificate_free_ca_names.3 gnutls_certificate_free_credentials.3 gnutls_certificate_allocate_credentials.3 gnutls_certificate_server_set_request.3 gnutls_certificate_client_set_retrieve_function.3 gnutls_certificate_server_set_retrieve_function.3 gnutls_certificate_verify_peers2.3 gnutls_certificate_verify_peers.3 gnutls_certificate_expiration_time_peers.3 gnutls_certificate_activation_time_peers.3 gnutls_sign_callback_set.3 gnutls_sign_callback_get.3 gnutls_db_set_retrieve_function.3 gnutls_db_set_remove_function.3 gnutls_db_set_store_function.3 gnutls_db_set_ptr.3 gnutls_db_get_ptr.3 gnutls_db_set_cache_expiration.3 gnutls_db_check_entry.3 gnutls_db_remove_session.3 gnutls_dh_params_import_raw.3 gnutls_dh_params_init.3 gnutls_dh_params_deinit.3 gnutls_dh_params_cpy.3 gnutls_dh_params_generate2.3 gnutls_dh_params_import_pkcs3.3 gnutls_dh_params_export_pkcs3.3 gnutls_dh_params_export_raw.3 gnutls_error_is_fatal.3 gnutls_perror.3 gnutls_strerror.3 gnutls_global_set_log_function.3 gnutls_global_set_log_level.3 gnutls_global_set_mem_functions.3 gnutls_global_init.3 gnutls_global_deinit.3 gnutls_transport_set_pull_function.3 gnutls_transport_set_push_function.3 gnutls_check_version.3 gnutls_rehandshake.3 gnutls_handshake.3 gnutls_handshake_set_max_packet_length.3 gnutls_handshake_get_last_in.3 gnutls_handshake_get_last_out.3 gnutls_malloc.3 gnutls_free.3 gnutls_certificate_set_openpgp_key.3 gnutls_certificate_set_openpgp_key_mem.3 gnutls_certificate_set_openpgp_key_file.3 gnutls_certificate_set_openpgp_keyring_file.3 gnutls_certificate_set_openpgp_keyring_mem.3 gnutls_openpgp_set_recv_key_function.3 gnutls_openpgp_privkey_sign_hash.3 gnutls_cipher_set_priority.3 gnutls_kx_set_priority.3 gnutls_mac_set_priority.3 gnutls_compression_set_priority.3 gnutls_protocol_set_priority.3 gnutls_certificate_type_set_priority.3 gnutls_priority_set.3 gnutls_priority_init.3 gnutls_priority_deinit.3 gnutls_priority_set_direct.3 gnutls_set_default_priority.3 gnutls_set_default_export_priority.3 gnutls_psk_free_client_credentials.3 gnutls_psk_allocate_client_credentials.3 gnutls_psk_set_client_credentials.3 gnutls_psk_free_server_credentials.3 gnutls_psk_allocate_server_credentials.3 gnutls_psk_set_server_credentials_file.3 gnutls_psk_set_server_credentials_function.3 gnutls_psk_set_client_credentials_function.3 gnutls_psk_server_get_username.3 gnutls_hex_decode.3 gnutls_hex_encode.3 gnutls_psk_set_server_dh_params.3 gnutls_psk_set_server_params_function.3 gnutls_protocol_get_version.3 gnutls_transport_set_lowat.3 gnutls_record_disable_padding.3 gnutls_transport_set_ptr.3 gnutls_transport_set_ptr2.3 gnutls_transport_get_ptr.3 gnutls_transport_get_ptr2.3 gnutls_bye.3 gnutls_record_send.3 gnutls_record_recv.3 gnutls_record_get_max_size.3 gnutls_record_set_max_size.3 gnutls_rsa_params_import_raw.3 gnutls_rsa_params_init.3 gnutls_rsa_params_deinit.3 gnutls_rsa_params_cpy.3 gnutls_rsa_params_generate2.3 gnutls_rsa_params_import_pkcs1.3 gnutls_rsa_params_export_pkcs1.3 gnutls_rsa_params_export_raw.3 gnutls_session_get_data.3 gnutls_session_get_data2.3 gnutls_session_get_id.3 gnutls_session_set_data.3 gnutls_cipher_get.3 gnutls_certificate_type_get.3 gnutls_kx_get.3 gnutls_mac_get.3 gnutls_compression_get.3 gnutls_init.3 gnutls_deinit.3 gnutls_openpgp_send_cert.3 gnutls_certificate_send_x509_rdn_sequence.3 gnutls_handshake_set_private_extensions.3 gnutls_prf_raw.3 gnutls_prf.3 gnutls_session_get_client_random.3 gnutls_session_get_server_random.3 gnutls_session_get_master_secret.3 gnutls_session_is_resumed.3 gnutls_session_get_ptr.3 gnutls_session_set_ptr.3 gnutls_record_get_direction.3 gnutls_handshake_set_post_client_hello_function.3 gnutls_session_enable_compatibility_mode.3 gnutls_dh_set_prime_bits.3 gnutls_dh_get_group.3 gnutls_dh_get_pubkey.3 gnutls_rsa_export_get_pubkey.3 gnutls_dh_get_secret_bits.3 gnutls_dh_get_prime_bits.3 gnutls_rsa_export_get_modulus_bits.3 gnutls_dh_get_peers_public_bits.3 gnutls_certificate_get_ours.3 gnutls_certificate_get_peers.3 gnutls_certificate_client_get_request_status.3 gnutls_fingerprint.3 gnutls_certificate_set_dh_params.3 gnutls_certificate_set_params_function.3 gnutls_certificate_set_verify_flags.3 gnutls_certificate_set_verify_limits.3 gnutls_certificate_set_rsa_export_params.3 gnutls_psk_set_params_function.3 gnutls_anon_set_params_function.3 gnutls_certificate_set_x509_key_mem.3 gnutls_certificate_set_x509_key.3 gnutls_certificate_set_x509_key_file.3 gnutls_certificate_set_x509_trust_mem.3 gnutls_certificate_set_x509_trust.3 gnutls_certificate_set_x509_trust_file.3 gnutls_certificate_set_x509_crl_mem.3 gnutls_certificate_set_x509_crl.3 gnutls_certificate_set_x509_crl_file.3 gnutls_certificate_set_x509_simple_pkcs12_file.3 gnutls_certificate_free_crls.3 gnutls_pem_base64_encode.3 gnutls_pem_base64_encode_alloc.3 gnutls_pem_base64_decode.3 gnutls_pem_base64_decode_alloc.3 gnutls_global_init_extra.3 gnutls_extra_check_version.3 gnutls_ia_permute_inner_secret.3 gnutls_ia_generate_challenge.3 gnutls_ia_extract_inner_secret.3 gnutls_ia_endphase_send.3 gnutls_ia_verify_endphase.3 gnutls_ia_send.3 gnutls_ia_recv.3 gnutls_ia_handshake_p.3 gnutls_ia_handshake.3 gnutls_ia_allocate_client_credentials.3 gnutls_ia_free_client_credentials.3 gnutls_ia_set_client_avp_function.3 gnutls_ia_set_client_avp_ptr.3 gnutls_ia_get_client_avp_ptr.3 gnutls_ia_allocate_server_credentials.3 gnutls_ia_free_server_credentials.3 gnutls_ia_set_server_avp_function.3 gnutls_ia_set_server_avp_ptr.3 gnutls_ia_get_server_avp_ptr.3 gnutls_ia_enable.3 gnutls_x509_dn_oid_known.3 gnutls_x509_crl_init.3 gnutls_x509_crl_deinit.3 gnutls_x509_crl_import.3 gnutls_x509_crl_get_issuer_dn.3 gnutls_x509_crl_get_issuer_dn_by_oid.3 gnutls_x509_crl_get_dn_oid.3 gnutls_x509_crl_get_signature_algorithm.3 gnutls_x509_crl_get_signature.3 gnutls_x509_crl_get_version.3 gnutls_x509_crl_get_this_update.3 gnutls_x509_crl_get_next_update.3 gnutls_x509_crl_get_crt_count.3 gnutls_x509_crl_get_crt_serial.3 gnutls_x509_crl_export.3 gnutls_x509_crl_set_version.3 gnutls_x509_crl_sign2.3 gnutls_x509_crl_sign.3 gnutls_x509_crl_set_this_update.3 gnutls_x509_crl_set_next_update.3 gnutls_x509_crl_set_crt_serial.3 gnutls_x509_crl_set_crt.3 gnutls_x509_crq_init.3 gnutls_x509_crq_deinit.3 gnutls_x509_crq_import.3 gnutls_x509_crq_get_dn.3 gnutls_x509_crq_get_dn_by_oid.3 gnutls_x509_crq_get_dn_oid.3 gnutls_x509_crq_get_challenge_password.3 gnutls_x509_crq_set_attribute_by_oid.3 gnutls_x509_crq_get_attribute_by_oid.3 gnutls_x509_crq_set_dn_by_oid.3 gnutls_x509_crq_set_version.3 gnutls_x509_crq_get_version.3 gnutls_x509_crq_set_key.3 gnutls_x509_crq_set_challenge_password.3 gnutls_x509_crq_sign2.3 gnutls_x509_crq_sign.3 gnutls_x509_crq_export.3 gnutls_x509_crq_get_pk_algorithm.3 gnutls_x509_rdn_get.3 gnutls_x509_rdn_get_by_oid.3 gnutls_x509_rdn_get_oid.3 gnutls_x509_crt_print.3 gnutls_x509_crl_print.3 gnutls_pkcs12_bag_init.3 gnutls_pkcs12_bag_deinit.3 gnutls_pkcs12_bag_get_type.3 gnutls_pkcs12_bag_get_count.3 gnutls_pkcs12_bag_get_data.3 gnutls_pkcs12_bag_set_data.3 gnutls_pkcs12_bag_set_crt.3 gnutls_pkcs12_bag_set_crl.3 gnutls_pkcs12_bag_set_key_id.3 gnutls_pkcs12_bag_get_key_id.3 gnutls_pkcs12_bag_get_friendly_name.3 gnutls_pkcs12_bag_set_friendly_name.3 gnutls_pkcs12_bag_decrypt.3 gnutls_pkcs12_bag_encrypt.3 gnutls_pkcs12_init.3 gnutls_pkcs12_deinit.3 gnutls_pkcs12_import.3 gnutls_pkcs12_export.3 gnutls_pkcs12_get_bag.3 gnutls_pkcs12_set_bag.3 gnutls_pkcs12_generate_mac.3 gnutls_pkcs12_verify_mac.3 gnutls_pkcs7_init.3 gnutls_pkcs7_deinit.3 gnutls_pkcs7_import.3 gnutls_pkcs7_get_crt_raw.3 gnutls_pkcs7_get_crt_count.3 gnutls_pkcs7_export.3 gnutls_pkcs7_set_crt_raw.3 gnutls_pkcs7_set_crt.3 gnutls_pkcs7_delete_crt.3 gnutls_pkcs7_get_crl_raw.3 gnutls_pkcs7_get_crl_count.3 gnutls_pkcs7_set_crl_raw.3 gnutls_pkcs7_set_crl.3 gnutls_pkcs7_delete_crl.3 gnutls_x509_privkey_init.3 gnutls_x509_privkey_deinit.3 gnutls_x509_privkey_cpy.3 gnutls_x509_privkey_import.3 gnutls_x509_privkey_import_rsa_raw.3 gnutls_x509_privkey_import_dsa_raw.3 gnutls_x509_privkey_get_pk_algorithm.3 gnutls_x509_privkey_export.3 gnutls_x509_privkey_export_rsa_raw.3 gnutls_x509_privkey_export_dsa_raw.3 gnutls_x509_privkey_generate.3 gnutls_x509_privkey_get_key_id.3 gnutls_x509_privkey_sign_data.3 gnutls_x509_privkey_sign_hash.3 gnutls_x509_privkey_verify_data.3 gnutls_x509_privkey_fix.3 gnutls_x509_privkey_export_pkcs8.3 gnutls_x509_privkey_import_pkcs8.3 gnutls_x509_crt_check_hostname.3 gnutls_x509_crt_check_issuer.3 gnutls_x509_crt_list_verify.3 gnutls_x509_crt_verify.3 gnutls_x509_crl_check_issuer.3 gnutls_x509_crl_verify.3 gnutls_x509_crt_init.3 gnutls_x509_crt_deinit.3 gnutls_x509_crt_import.3 gnutls_x509_crt_get_issuer_dn.3 gnutls_x509_crt_get_issuer_dn_by_oid.3 gnutls_x509_crt_get_issuer_dn_oid.3 gnutls_x509_crt_get_dn.3 gnutls_x509_crt_get_dn_by_oid.3 gnutls_x509_crt_get_dn_oid.3 gnutls_x509_crt_get_signature_algorithm.3 gnutls_x509_crt_get_signature.3 gnutls_x509_crt_get_version.3 gnutls_x509_crt_get_activation_time.3 gnutls_x509_crt_get_expiration_time.3 gnutls_x509_crt_get_serial.3 gnutls_x509_crt_get_subject_key_id.3 gnutls_x509_crt_get_authority_key_id.3 gnutls_x509_crt_get_pk_algorithm.3 gnutls_x509_crt_get_subject_alt_name.3 gnutls_x509_crt_get_subject_alt_name2.3 gnutls_x509_crt_get_subject_alt_othername_oid.3 gnutls_x509_crt_get_basic_constraints.3 gnutls_x509_crt_get_ca_status.3 gnutls_x509_crt_get_key_usage.3 gnutls_x509_crt_get_proxy.3 gnutls_x509_crt_get_extension_by_oid.3 gnutls_x509_crt_get_extension_oid.3 gnutls_x509_crt_get_extension_info.3 gnutls_x509_crt_get_extension_data.3 gnutls_x509_crt_get_raw_issuer_dn.3 gnutls_x509_crt_get_raw_dn.3 gnutls_x509_crt_get_subject.3 gnutls_x509_crt_get_issuer.3 gnutls_x509_dn_get_rdn_ava.3 gnutls_x509_crt_get_fingerprint.3 gnutls_x509_crt_export.3 gnutls_x509_crt_get_key_id.3 gnutls_x509_crt_check_revocation.3 gnutls_x509_crt_verify_data.3 gnutls_x509_crt_get_crl_dist_points.3 gnutls_x509_crt_get_key_purpose_oid.3 gnutls_x509_crt_get_pk_rsa_raw.3 gnutls_x509_crt_get_pk_dsa_raw.3 gnutls_x509_crt_list_import.3 gnutls_x509_crt_set_dn_by_oid.3 gnutls_x509_crt_set_issuer_dn_by_oid.3 gnutls_x509_crt_set_proxy_dn.3 gnutls_x509_crt_set_version.3 gnutls_x509_crt_set_key.3 gnutls_x509_crt_set_crq.3 gnutls_x509_crt_set_extension_by_oid.3 gnutls_x509_crt_set_basic_constraints.3 gnutls_x509_crt_set_ca_status.3 gnutls_x509_crt_set_key_usage.3 gnutls_x509_crt_set_subject_alternative_name.3 gnutls_x509_crt_set_proxy.3 gnutls_x509_crt_sign2.3 gnutls_x509_crt_sign.3 gnutls_x509_crt_set_activation_time.3 gnutls_x509_crt_set_expiration_time.3 gnutls_x509_crt_set_serial.3 gnutls_x509_crt_set_crl_dist_points.3 gnutls_x509_crt_cpy_crl_dist_points.3 gnutls_x509_crt_set_subject_key_id.3 gnutls_x509_crt_set_authority_key_id.3 gnutls_x509_crt_set_key_purpose_oid.3 gnutls_openpgp_keyring_init.3 gnutls_openpgp_keyring_deinit.3 gnutls_openpgp_keyring_check_id.3 gnutls_openpgp_keyring_import.3 gnutls_openpgp_crt_print.3 gnutls_openpgp_crt_init.3 gnutls_openpgp_crt_deinit.3 gnutls_openpgp_crt_import.3 gnutls_openpgp_crt_export.3 gnutls_openpgp_crt_get_fingerprint.3 gnutls_openpgp_crt_get_name.3 gnutls_openpgp_crt_get_pk_algorithm.3 gnutls_openpgp_crt_get_version.3 gnutls_openpgp_crt_get_creation_time.3 gnutls_openpgp_crt_get_expiration_time.3 gnutls_openpgp_crt_get_key_id.3 gnutls_openpgp_crt_get_revoked_status.3 gnutls_openpgp_crt_check_hostname.3 gnutls_openpgp_crt_get_key_usage.3 gnutls_openpgp_crt_get_subkey_count.3 gnutls_openpgp_crt_get_subkey_revoked_status.3 gnutls_openpgp_crt_get_subkey_pk_algorithm.3 gnutls_openpgp_crt_get_subkey_creation_time.3 gnutls_openpgp_crt_get_subkey_expiration_time.3 gnutls_openpgp_crt_get_subkey_id.3 gnutls_openpgp_crt_get_subkey_idx.3 gnutls_openpgp_crt_get_subkey_usage.3 gnutls_openpgp_crt_get_pk_rsa_raw.3 gnutls_openpgp_crt_get_pk_dsa_raw.3 gnutls_openpgp_crt_get_subkey_pk_rsa_raw.3 gnutls_openpgp_crt_get_subkey_pk_dsa_raw.3 gnutls_openpgp_crt_verify_ring.3 gnutls_openpgp_crt_verify_self.3 gnutls_openpgp_privkey_init.3 gnutls_openpgp_privkey_deinit.3 gnutls_openpgp_privkey_import.3 gnutls_openpgp_privkey_export.3 gnutls_openpgp_privkey_get_pk_algorithm.3 gnutls_openpgp_privkey_get_revoked_status.3 gnutls_openpgp_privkey_get_fingerprint.3 gnutls_openpgp_privkey_get_key_id.3 gnutls_openpgp_privkey_get_subkey_count.3 gnutls_openpgp_privkey_get_subkey_revoked_status.3 gnutls_openpgp_privkey_get_subkey_pk_algorithm.3 gnutls_openpgp_privkey_get_subkey_idx.3 gnutls_openpgp_privkey_get_subkey_creation_time.3 gnutls_openpgp_privkey_get_subkey_expiration_time.3 gnutls_openpgp_privkey_get_subkey_id.3 gnutls_openpgp_privkey_export_rsa_raw.3 gnutls_openpgp_privkey_export_dsa_raw.3 gnutls_openpgp_privkey_export_subkey_rsa_raw.3 gnutls_openpgp_privkey_export_subkey_dsa_raw.3
+APIMANS = gnutls_oprfi_enable_client.3 gnutls_oprfi_enable_server.3 gnutls_server_name_get.3 gnutls_server_name_set.3 gnutls_alert_get_name.3 gnutls_alert_send.3 gnutls_error_to_alert.3 gnutls_alert_send_appropriate.3 gnutls_alert_get.3 gnutls_mac_get_name.3 gnutls_mac_get_id.3 gnutls_mac_get_key_size.3 gnutls_mac_list.3 gnutls_compression_get_name.3 gnutls_compression_get_id.3 gnutls_compression_list.3 gnutls_cipher_get_key_size.3 gnutls_cipher_get_name.3 gnutls_cipher_get_id.3 gnutls_cipher_list.3 gnutls_kx_get_name.3 gnutls_kx_get_id.3 gnutls_kx_list.3 gnutls_protocol_get_name.3 gnutls_protocol_get_id.3 gnutls_protocol_list.3 gnutls_cipher_suite_get_name.3 gnutls_cipher_suite_info.3 gnutls_certificate_type_get_name.3 gnutls_certificate_type_get_id.3 gnutls_certificate_type_list.3 gnutls_sign_algorithm_get_name.3 gnutls_pk_algorithm_get_name.3 gnutls_anon_free_server_credentials.3 gnutls_anon_allocate_server_credentials.3 gnutls_anon_free_client_credentials.3 gnutls_anon_allocate_client_credentials.3 gnutls_anon_set_server_dh_params.3 gnutls_anon_set_server_params_function.3 gnutls_credentials_clear.3 gnutls_credentials_set.3 gnutls_auth_get_type.3 gnutls_auth_server_get_type.3 gnutls_auth_client_get_type.3 gnutls_transport_set_errno.3 gnutls_transport_set_global_errno.3 gnutls_record_check_pending.3 gnutls_certificate_free_keys.3 gnutls_certificate_free_cas.3 gnutls_certificate_export_x509_cas.3 gnutls_certificate_export_x509_crls.3 gnutls_certificate_export_openpgp_keyring.3 gnutls_certificate_free_ca_names.3 gnutls_certificate_free_credentials.3 gnutls_certificate_allocate_credentials.3 gnutls_certificate_server_set_request.3 gnutls_certificate_client_set_retrieve_function.3 gnutls_certificate_server_set_retrieve_function.3 gnutls_certificate_verify_peers2.3 gnutls_certificate_verify_peers.3 gnutls_certificate_expiration_time_peers.3 gnutls_certificate_activation_time_peers.3 gnutls_sign_callback_set.3 gnutls_sign_callback_get.3 gnutls_db_set_retrieve_function.3 gnutls_db_set_remove_function.3 gnutls_db_set_store_function.3 gnutls_db_set_ptr.3 gnutls_db_get_ptr.3 gnutls_db_set_cache_expiration.3 gnutls_db_check_entry.3 gnutls_db_remove_session.3 gnutls_dh_params_import_raw.3 gnutls_dh_params_init.3 gnutls_dh_params_deinit.3 gnutls_dh_params_cpy.3 gnutls_dh_params_generate2.3 gnutls_dh_params_import_pkcs3.3 gnutls_dh_params_export_pkcs3.3 gnutls_dh_params_export_raw.3 gnutls_error_is_fatal.3 gnutls_perror.3 gnutls_strerror.3 gnutls_global_set_log_function.3 gnutls_global_set_log_level.3 gnutls_global_set_mem_functions.3 gnutls_global_init.3 gnutls_global_deinit.3 gnutls_transport_set_pull_function.3 gnutls_transport_set_push_function.3 gnutls_check_version.3 gnutls_rehandshake.3 gnutls_handshake.3 gnutls_handshake_set_max_packet_length.3 gnutls_handshake_get_last_in.3 gnutls_handshake_get_last_out.3 gnutls_malloc.3 gnutls_free.3 gnutls_certificate_set_openpgp_key.3 gnutls_certificate_set_openpgp_key_mem.3 gnutls_certificate_set_openpgp_key_file.3 gnutls_certificate_set_openpgp_key_mem2.3 gnutls_certificate_set_openpgp_key_file2.3 gnutls_certificate_set_openpgp_keyring_file.3 gnutls_certificate_set_openpgp_keyring_mem.3 gnutls_openpgp_set_recv_key_function.3 gnutls_openpgp_privkey_sign_hash.3 gnutls_cipher_set_priority.3 gnutls_kx_set_priority.3 gnutls_mac_set_priority.3 gnutls_compression_set_priority.3 gnutls_protocol_set_priority.3 gnutls_certificate_type_set_priority.3 gnutls_priority_set.3 gnutls_priority_init.3 gnutls_priority_deinit.3 gnutls_priority_set_direct.3 gnutls_set_default_priority.3 gnutls_set_default_export_priority.3 gnutls_psk_free_client_credentials.3 gnutls_psk_allocate_client_credentials.3 gnutls_psk_set_client_credentials.3 gnutls_psk_free_server_credentials.3 gnutls_psk_allocate_server_credentials.3 gnutls_psk_set_server_credentials_file.3 gnutls_psk_set_server_credentials_function.3 gnutls_psk_set_client_credentials_function.3 gnutls_psk_server_get_username.3 gnutls_hex_decode.3 gnutls_hex_encode.3 gnutls_psk_set_server_dh_params.3 gnutls_psk_set_server_params_function.3 gnutls_protocol_get_version.3 gnutls_transport_set_lowat.3 gnutls_record_disable_padding.3 gnutls_transport_set_ptr.3 gnutls_transport_set_ptr2.3 gnutls_transport_get_ptr.3 gnutls_transport_get_ptr2.3 gnutls_bye.3 gnutls_record_send.3 gnutls_record_recv.3 gnutls_record_get_max_size.3 gnutls_record_set_max_size.3 gnutls_rsa_params_import_raw.3 gnutls_rsa_params_init.3 gnutls_rsa_params_deinit.3 gnutls_rsa_params_cpy.3 gnutls_rsa_params_generate2.3 gnutls_rsa_params_import_pkcs1.3 gnutls_rsa_params_export_pkcs1.3 gnutls_rsa_params_export_raw.3 gnutls_session_get_data.3 gnutls_session_get_data2.3 gnutls_session_get_id.3 gnutls_session_set_data.3 gnutls_cipher_get.3 gnutls_certificate_type_get.3 gnutls_kx_get.3 gnutls_mac_get.3 gnutls_compression_get.3 gnutls_init.3 gnutls_deinit.3 gnutls_openpgp_send_cert.3 gnutls_certificate_send_x509_rdn_sequence.3 gnutls_handshake_set_private_extensions.3 gnutls_prf_raw.3 gnutls_prf.3 gnutls_session_get_client_random.3 gnutls_session_get_server_random.3 gnutls_session_get_master_secret.3 gnutls_session_is_resumed.3 gnutls_session_get_ptr.3 gnutls_session_set_ptr.3 gnutls_record_get_direction.3 gnutls_handshake_set_post_client_hello_function.3 gnutls_session_enable_compatibility_mode.3 gnutls_dh_set_prime_bits.3 gnutls_dh_get_group.3 gnutls_dh_get_pubkey.3 gnutls_rsa_export_get_pubkey.3 gnutls_dh_get_secret_bits.3 gnutls_dh_get_prime_bits.3 gnutls_rsa_export_get_modulus_bits.3 gnutls_dh_get_peers_public_bits.3 gnutls_certificate_get_ours.3 gnutls_certificate_get_peers.3 gnutls_certificate_client_get_request_status.3 gnutls_fingerprint.3 gnutls_certificate_set_dh_params.3 gnutls_certificate_set_params_function.3 gnutls_certificate_set_verify_flags.3 gnutls_certificate_set_verify_limits.3 gnutls_certificate_set_rsa_export_params.3 gnutls_psk_set_params_function.3 gnutls_anon_set_params_function.3 gnutls_certificate_set_x509_key_mem.3 gnutls_certificate_set_x509_key.3 gnutls_certificate_set_x509_key_file.3 gnutls_certificate_set_x509_trust_mem.3 gnutls_certificate_set_x509_trust.3 gnutls_certificate_set_x509_trust_file.3 gnutls_certificate_set_x509_crl_mem.3 gnutls_certificate_set_x509_crl.3 gnutls_certificate_set_x509_crl_file.3 gnutls_certificate_set_x509_simple_pkcs12_file.3 gnutls_certificate_free_crls.3 gnutls_pem_base64_encode.3 gnutls_pem_base64_encode_alloc.3 gnutls_pem_base64_decode.3 gnutls_pem_base64_decode_alloc.3 gnutls_global_init_extra.3 gnutls_extra_check_version.3 gnutls_ia_permute_inner_secret.3 gnutls_ia_generate_challenge.3 gnutls_ia_extract_inner_secret.3 gnutls_ia_endphase_send.3 gnutls_ia_verify_endphase.3 gnutls_ia_send.3 gnutls_ia_recv.3 gnutls_ia_handshake_p.3 gnutls_ia_handshake.3 gnutls_ia_allocate_client_credentials.3 gnutls_ia_free_client_credentials.3 gnutls_ia_set_client_avp_function.3 gnutls_ia_set_client_avp_ptr.3 gnutls_ia_get_client_avp_ptr.3 gnutls_ia_allocate_server_credentials.3 gnutls_ia_free_server_credentials.3 gnutls_ia_set_server_avp_function.3 gnutls_ia_set_server_avp_ptr.3 gnutls_ia_get_server_avp_ptr.3 gnutls_ia_enable.3 gnutls_x509_dn_oid_known.3 gnutls_x509_crl_init.3 gnutls_x509_crl_deinit.3 gnutls_x509_crl_import.3 gnutls_x509_crl_get_issuer_dn.3 gnutls_x509_crl_get_issuer_dn_by_oid.3 gnutls_x509_crl_get_dn_oid.3 gnutls_x509_crl_get_signature_algorithm.3 gnutls_x509_crl_get_signature.3 gnutls_x509_crl_get_version.3 gnutls_x509_crl_get_this_update.3 gnutls_x509_crl_get_next_update.3 gnutls_x509_crl_get_crt_count.3 gnutls_x509_crl_get_crt_serial.3 gnutls_x509_crl_export.3 gnutls_x509_crl_set_version.3 gnutls_x509_crl_sign2.3 gnutls_x509_crl_sign.3 gnutls_x509_crl_set_this_update.3 gnutls_x509_crl_set_next_update.3 gnutls_x509_crl_set_crt_serial.3 gnutls_x509_crl_set_crt.3 gnutls_x509_crq_init.3 gnutls_x509_crq_deinit.3 gnutls_x509_crq_import.3 gnutls_x509_crq_get_dn.3 gnutls_x509_crq_get_dn_by_oid.3 gnutls_x509_crq_get_dn_oid.3 gnutls_x509_crq_get_challenge_password.3 gnutls_x509_crq_set_attribute_by_oid.3 gnutls_x509_crq_get_attribute_by_oid.3 gnutls_x509_crq_set_dn_by_oid.3 gnutls_x509_crq_set_version.3 gnutls_x509_crq_get_version.3 gnutls_x509_crq_set_key.3 gnutls_x509_crq_set_challenge_password.3 gnutls_x509_crq_sign2.3 gnutls_x509_crq_sign.3 gnutls_x509_crq_export.3 gnutls_x509_crq_get_pk_algorithm.3 gnutls_x509_dn_init.3 gnutls_x509_dn_import.3 gnutls_x509_dn_deinit.3 gnutls_x509_rdn_get.3 gnutls_x509_rdn_get_by_oid.3 gnutls_x509_rdn_get_oid.3 gnutls_x509_crt_print.3 gnutls_x509_crl_print.3 gnutls_pkcs12_init.3 gnutls_pkcs12_deinit.3 gnutls_pkcs12_import.3 gnutls_pkcs12_export.3 gnutls_pkcs12_get_bag.3 gnutls_pkcs12_set_bag.3 gnutls_pkcs12_generate_mac.3 gnutls_pkcs12_verify_mac.3 gnutls_pkcs12_bag_init.3 gnutls_pkcs12_bag_deinit.3 gnutls_pkcs12_bag_get_type.3 gnutls_pkcs12_bag_get_count.3 gnutls_pkcs12_bag_get_data.3 gnutls_pkcs12_bag_set_data.3 gnutls_pkcs12_bag_set_crt.3 gnutls_pkcs12_bag_set_crl.3 gnutls_pkcs12_bag_set_key_id.3 gnutls_pkcs12_bag_get_key_id.3 gnutls_pkcs12_bag_get_friendly_name.3 gnutls_pkcs12_bag_set_friendly_name.3 gnutls_pkcs12_bag_decrypt.3 gnutls_pkcs12_bag_encrypt.3 gnutls_pkcs7_init.3 gnutls_pkcs7_deinit.3 gnutls_pkcs7_import.3 gnutls_pkcs7_get_crt_raw.3 gnutls_pkcs7_get_crt_count.3 gnutls_pkcs7_export.3 gnutls_pkcs7_set_crt_raw.3 gnutls_pkcs7_set_crt.3 gnutls_pkcs7_delete_crt.3 gnutls_pkcs7_get_crl_raw.3 gnutls_pkcs7_get_crl_count.3 gnutls_pkcs7_set_crl_raw.3 gnutls_pkcs7_set_crl.3 gnutls_pkcs7_delete_crl.3 gnutls_x509_privkey_init.3 gnutls_x509_privkey_deinit.3 gnutls_x509_privkey_cpy.3 gnutls_x509_privkey_import.3 gnutls_x509_privkey_import_rsa_raw.3 gnutls_x509_privkey_import_dsa_raw.3 gnutls_x509_privkey_get_pk_algorithm.3 gnutls_x509_privkey_export.3 gnutls_x509_privkey_export_rsa_raw.3 gnutls_x509_privkey_export_dsa_raw.3 gnutls_x509_privkey_generate.3 gnutls_x509_privkey_get_key_id.3 gnutls_x509_privkey_sign_data.3 gnutls_x509_privkey_sign_hash.3 gnutls_x509_privkey_verify_data.3 gnutls_x509_privkey_fix.3 gnutls_x509_privkey_export_pkcs8.3 gnutls_x509_privkey_import_pkcs8.3 gnutls_x509_crt_check_hostname.3 gnutls_x509_crt_check_issuer.3 gnutls_x509_crt_list_verify.3 gnutls_x509_crt_verify.3 gnutls_x509_crl_check_issuer.3 gnutls_x509_crl_verify.3 gnutls_x509_crt_init.3 gnutls_x509_crt_deinit.3 gnutls_x509_crt_import.3 gnutls_x509_crt_get_issuer_dn.3 gnutls_x509_crt_get_issuer_dn_by_oid.3 gnutls_x509_crt_get_issuer_dn_oid.3 gnutls_x509_crt_get_dn.3 gnutls_x509_crt_get_dn_by_oid.3 gnutls_x509_crt_get_dn_oid.3 gnutls_x509_crt_get_signature_algorithm.3 gnutls_x509_crt_get_signature.3 gnutls_x509_crt_get_version.3 gnutls_x509_crt_get_activation_time.3 gnutls_x509_crt_get_expiration_time.3 gnutls_x509_crt_get_serial.3 gnutls_x509_crt_get_subject_key_id.3 gnutls_x509_crt_get_authority_key_id.3 gnutls_x509_crt_get_pk_algorithm.3 gnutls_x509_crt_get_subject_alt_name.3 gnutls_x509_crt_get_subject_alt_name2.3 gnutls_x509_crt_get_subject_alt_othername_oid.3 gnutls_x509_crt_get_basic_constraints.3 gnutls_x509_crt_get_ca_status.3 gnutls_x509_crt_get_key_usage.3 gnutls_x509_crt_get_proxy.3 gnutls_x509_crt_get_extension_by_oid.3 gnutls_x509_crt_get_extension_oid.3 gnutls_x509_crt_get_extension_info.3 gnutls_x509_crt_get_extension_data.3 gnutls_x509_crt_get_raw_issuer_dn.3 gnutls_x509_crt_get_raw_dn.3 gnutls_x509_crt_get_subject.3 gnutls_x509_crt_get_issuer.3 gnutls_x509_dn_get_rdn_ava.3 gnutls_x509_crt_get_fingerprint.3 gnutls_x509_crt_export.3 gnutls_x509_crt_get_key_id.3 gnutls_x509_crt_check_revocation.3 gnutls_x509_crt_verify_data.3 gnutls_x509_crt_get_crl_dist_points.3 gnutls_x509_crt_get_key_purpose_oid.3 gnutls_x509_crt_get_pk_rsa_raw.3 gnutls_x509_crt_get_pk_dsa_raw.3 gnutls_x509_crt_list_import.3 gnutls_x509_crt_set_dn_by_oid.3 gnutls_x509_crt_set_issuer_dn_by_oid.3 gnutls_x509_crt_set_proxy_dn.3 gnutls_x509_crt_set_version.3 gnutls_x509_crt_set_key.3 gnutls_x509_crt_set_crq.3 gnutls_x509_crt_set_extension_by_oid.3 gnutls_x509_crt_set_basic_constraints.3 gnutls_x509_crt_set_ca_status.3 gnutls_x509_crt_set_key_usage.3 gnutls_x509_crt_set_subject_alternative_name.3 gnutls_x509_crt_set_proxy.3 gnutls_x509_crt_sign2.3 gnutls_x509_crt_sign.3 gnutls_x509_crt_set_activation_time.3 gnutls_x509_crt_set_expiration_time.3 gnutls_x509_crt_set_serial.3 gnutls_x509_crt_set_crl_dist_points.3 gnutls_x509_crt_cpy_crl_dist_points.3 gnutls_x509_crt_set_subject_key_id.3 gnutls_x509_crt_set_authority_key_id.3 gnutls_x509_crt_set_key_purpose_oid.3 gnutls_openpgp_keyring_init.3 gnutls_openpgp_keyring_deinit.3 gnutls_openpgp_keyring_check_id.3 gnutls_openpgp_keyring_import.3 gnutls_openpgp_keyring_get_crt_count.3 gnutls_openpgp_keyring_get_crt.3 gnutls_openpgp_crt_print.3 gnutls_openpgp_crt_init.3 gnutls_openpgp_crt_deinit.3 gnutls_openpgp_crt_import.3 gnutls_openpgp_crt_export.3 gnutls_openpgp_crt_get_fingerprint.3 gnutls_openpgp_crt_get_name.3 gnutls_openpgp_crt_get_pk_algorithm.3 gnutls_openpgp_crt_get_version.3 gnutls_openpgp_crt_get_creation_time.3 gnutls_openpgp_crt_get_expiration_time.3 gnutls_openpgp_crt_get_key_id.3 gnutls_openpgp_crt_get_revoked_status.3 gnutls_openpgp_crt_check_hostname.3 gnutls_openpgp_crt_get_key_usage.3 gnutls_openpgp_crt_get_subkey_count.3 gnutls_openpgp_crt_get_subkey_revoked_status.3 gnutls_openpgp_crt_get_subkey_pk_algorithm.3 gnutls_openpgp_crt_get_subkey_creation_time.3 gnutls_openpgp_crt_get_subkey_expiration_time.3 gnutls_openpgp_crt_get_subkey_id.3 gnutls_openpgp_crt_get_subkey_idx.3 gnutls_openpgp_crt_get_subkey_usage.3 gnutls_openpgp_crt_get_pk_rsa_raw.3 gnutls_openpgp_crt_get_pk_dsa_raw.3 gnutls_openpgp_crt_get_subkey_pk_rsa_raw.3 gnutls_openpgp_crt_get_subkey_pk_dsa_raw.3 gnutls_openpgp_crt_get_preferred_key_id.3 gnutls_openpgp_crt_set_preferred_key_id.3 gnutls_openpgp_crt_get_auth_subkey.3 gnutls_openpgp_crt_verify_ring.3 gnutls_openpgp_crt_verify_self.3 gnutls_openpgp_privkey_init.3 gnutls_openpgp_privkey_deinit.3 gnutls_openpgp_privkey_import.3 gnutls_openpgp_privkey_export.3 gnutls_openpgp_privkey_get_pk_algorithm.3 gnutls_openpgp_privkey_get_revoked_status.3 gnutls_openpgp_privkey_get_fingerprint.3 gnutls_openpgp_privkey_get_key_id.3 gnutls_openpgp_privkey_get_subkey_count.3 gnutls_openpgp_privkey_get_subkey_revoked_status.3 gnutls_openpgp_privkey_get_subkey_pk_algorithm.3 gnutls_openpgp_privkey_get_subkey_idx.3 gnutls_openpgp_privkey_get_subkey_creation_time.3 gnutls_openpgp_privkey_get_subkey_expiration_time.3 gnutls_openpgp_privkey_get_subkey_id.3 gnutls_openpgp_privkey_export_rsa_raw.3 gnutls_openpgp_privkey_export_dsa_raw.3 gnutls_openpgp_privkey_export_subkey_rsa_raw.3 gnutls_openpgp_privkey_export_subkey_dsa_raw.3 gnutls_openpgp_privkey_get_preferred_key_id.3 gnutls_openpgp_privkey_set_preferred_key_id.3
SRPMANS = gnutls_srp_base64_encode.3 gnutls_srp_base64_encode_alloc.3 gnutls_srp_base64_decode.3 gnutls_srp_base64_decode_alloc.3 gnutls_srp_free_client_credentials.3 gnutls_srp_allocate_client_credentials.3 gnutls_srp_set_client_credentials.3 gnutls_srp_free_server_credentials.3 gnutls_srp_allocate_server_credentials.3 gnutls_srp_set_server_credentials_file.3 gnutls_srp_set_server_credentials_function.3 gnutls_srp_set_client_credentials_function.3 gnutls_srp_server_get_username.3 gnutls_srp_verifier.3
diff --git a/includes/gnutls/x509.h b/includes/gnutls/x509.h
index 4b700f4..98d54c7 100644
--- a/includes/gnutls/x509.h
+++ b/includes/gnutls/x509.h
@@ -333,6 +333,10 @@ extern "C"
int gnutls_x509_dn_import (gnutls_x509_dn_t odn,
const gnutls_datum_t * data);
+ int gnutls_x509_dn_export (gnutls_x509_dn_t dn,
+ gnutls_x509_crt_fmt_t format, void *output_data,
+ size_t * output_data_size);
+
void gnutls_x509_dn_deinit (gnutls_x509_dn_t idn);
diff --git a/lib/x509/common.c b/lib/x509/common.c
index 44fda11..0eeb034 100644
--- a/lib/x509/common.c
+++ b/lib/x509/common.c
@@ -710,9 +710,9 @@ _gnutls_x509_san_find_type (char *str_type)
* to PEM or DER raw data.
*/
int
-_gnutls_x509_export_int (ASN1_TYPE asn1_data,
- gnutls_x509_crt_fmt_t format, char *pem_header,
- unsigned char *output_data, size_t * output_data_size)
+_gnutls_x509_export_int_named (ASN1_TYPE asn1_data, const char *name,
+ gnutls_x509_crt_fmt_t format, char *pem_header,
+ unsigned char *output_data, size_t * output_data_size)
{
int result, len;
@@ -725,7 +725,7 @@ _gnutls_x509_export_int (ASN1_TYPE asn1_data,
len = *output_data_size;
if ((result =
- asn1_der_coding (asn1_data, "", output_data, &len,
+ asn1_der_coding (asn1_data, name, output_data, &len,
NULL)) != ASN1_SUCCESS)
{
*output_data_size = len;
@@ -745,7 +745,7 @@ _gnutls_x509_export_int (ASN1_TYPE asn1_data,
opaque *out;
gnutls_datum tmp;
- result = _gnutls_x509_der_encode( asn1_data, "", &tmp, 0);
+ result = _gnutls_x509_der_encode( asn1_data, name, &tmp, 0);
if (result < 0)
{
gnutls_assert();
@@ -793,6 +793,16 @@ _gnutls_x509_export_int (ASN1_TYPE asn1_data,
return 0;
}
+int
+_gnutls_x509_export_int (ASN1_TYPE asn1_data,
+ gnutls_x509_crt_fmt_t format, char *pem_header,
+ unsigned char *output_data, size_t * output_data_size)
+{
+ return _gnutls_x509_export_int_named (asn1_data, "",
+ format, pem_header, output_data,
+ output_data_size);
+}
+
/* Decodes an octet string. Leave string_type null for a normal
* octet string. Otherwise put something like BMPString, PrintableString
* etc.
diff --git a/lib/x509/common.h b/lib/x509/common.h
index c619fc0..ffc3545 100644
--- a/lib/x509/common.h
+++ b/lib/x509/common.h
@@ -90,6 +90,11 @@ int _gnutls_x509_export_int (ASN1_TYPE asn1_data,
unsigned char *output_data,
size_t * output_data_size);
+int _gnutls_x509_export_int_named (ASN1_TYPE asn1_data, const char *name,
+ gnutls_x509_crt_fmt_t format, char *pem_header,
+ unsigned char *output_data,
+ size_t * output_data_size);
+
int _gnutls_x509_read_value (ASN1_TYPE c, const char *root,
gnutls_datum_t * ret, int str);
int _gnutls_x509_write_value (ASN1_TYPE c, const char *root,
diff --git a/lib/x509/dn.c b/lib/x509/dn.c
index 8b84de2..9c94cd5 100644
--- a/lib/x509/dn.c
+++ b/lib/x509/dn.c
@@ -1211,3 +1211,42 @@ _gnutls_x509_compare_raw_dn (const gnutls_datum_t * dn1,
}
return 1; /* they match */
}
+
+/**
+ * gnutls_x509_dn_export - This function will export the DN
+ * @dn: Holds the opaque DN object
+ * @format: the format of output params. One of PEM or DER.
+ * @output_data: will contain a DN PEM or DER encoded
+ * @output_data_size: holds the size of output_data (and will be
+ * replaced by the actual size of parameters)
+ *
+ * This function will export the DN to DER or PEM format.
+ *
+ * If the buffer provided is not long enough to hold the output, then
+ * *output_data_size is updated and GNUTLS_E_SHORT_MEMORY_BUFFER will
+ * be returned.
+ *
+ * If the structure is PEM encoded, it will have a header
+ * of "BEGIN NAME".
+ *
+ * Return value: In case of failure a negative value will be
+ * returned, and 0 on success.
+ **/
+int
+gnutls_x509_dn_export (gnutls_x509_dn_t dn,
+ gnutls_x509_crt_fmt_t format, void *output_data,
+ size_t * output_data_size)
+{
+ ASN1_TYPE asn1 = dn;
+
+ if (asn1 == NULL)
+ {
+ gnutls_assert ();
+ return GNUTLS_E_INVALID_REQUEST;
+ }
+
+ return _gnutls_x509_export_int_named (asn1, "rdnSequence",
+ format, "NAME",
+ output_data,
+ output_data_size);
+}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index dc03c1b..7fb1fff 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -37,7 +37,7 @@ noinst_LTLIBRARIES = libutils.la
libutils_la_SOURCES = utils.h utils.c
ctests = simple openssl gc set_pkcs12_cred certder \
- certificate_set_x509_crl dn parse_ca
+ certificate_set_x509_crl dn parse_ca moredn
openssl_LDADD = $(LDADD) ../libextra/libgnutls-openssl.la
if HAVE_FORK
ctests += openpgpself x509self x509signself x509dn anonself pskself dhepskself tlsia resume
diff --git a/tests/moredn.c b/tests/moredn.c
new file mode 100644
index 0000000..25fc068
--- /dev/null
+++ b/tests/moredn.c
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2008 Free Software Foundation
+ *
+ * Author: Joe Orton
+ *
+ * This file is part of GNUTLS.
+ *
+ * GNUTLS is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GNUTLS is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNUTLS; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/* Parts copied from GnuTLS example programs. */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <gnutls/gnutls.h>
+#include <gnutls/x509.h>
+
+#include "utils.h"
+
+static const char cert_pem[] =
+ "-----BEGIN CERTIFICATE-----\n"
+ "MIICHjCCAYmgAwIBAgIERiYdNzALBgkqhkiG9w0BAQUwGTEXMBUGA1UEAxMOR251\n"
+ "VExTIHRlc3QgQ0EwHhcNMDcwNDE4MTMyOTI3WhcNMDgwNDE3MTMyOTI3WjAdMRsw\n"
+ "GQYDVQQDExJHbnVUTFMgdGVzdCBjbGllbnQwgZwwCwYJKoZIhvcNAQEBA4GMADCB\n"
+ "iAKBgLtmQ/Xyxde2jMzF3/WIO7HJS2oOoa0gUEAIgKFPXKPQ+GzP5jz37AR2ExeL\n"
+ "ZIkiW8DdU3w77XwEu4C5KL6Om8aOoKUSy/VXHqLnu7czSZ/ju0quak1o/8kR4jKN\n"
+ "zj2AC41179gAgY8oBAOgIo1hBAf6tjd9IQdJ0glhaZiQo1ipAgMBAAGjdjB0MAwG\n"
+ "A1UdEwEB/wQCMAAwEwYDVR0lBAwwCgYIKwYBBQUHAwIwDwYDVR0PAQH/BAUDAweg\n"
+ "ADAdBgNVHQ4EFgQUTLkKm/odNON+3svSBxX+odrLaJEwHwYDVR0jBBgwFoAU6Twc\n"
+ "+62SbuYGpFYsouHAUyfI8pUwCwYJKoZIhvcNAQEFA4GBALujmBJVZnvaTXr9cFRJ\n"
+ "jpfc/3X7sLUsMvumcDE01ls/cG5mIatmiyEU9qI3jbgUf82z23ON/acwJf875D3/\n"
+ "U7jyOsBJ44SEQITbin2yUeJMIm1tievvdNXBDfW95AM507ShzP12sfiJkJfjjdhy\n"
+ "dc8Siq5JojruiMizAf0pA7in\n"
+ "-----END CERTIFICATE-----\n";
+static const gnutls_datum_t cert_datum = { (char *)cert_pem, sizeof (cert_pem) };
+
+void
+doit (void)
+{
+
+ gnutls_global_init ();
+ gnutls_x509_crt_t cert;
+ gnutls_x509_dn_t sdn, dn2;
+ unsigned char buf[8192], buf2[8192];
+ size_t buflen, buf2len;
+ gnutls_datum_t datum;
+ int rv;
+
+ if (gnutls_x509_crt_init(&cert) == 0)
+ success ("success: cert init\n");
+ else
+ fail ("cert init failure\n");
+
+ if (gnutls_x509_crt_import (cert, &cert_datum, GNUTLS_X509_FMT_PEM) == 0)
+ success ("success: imported PEM cert\n");
+ else
+ fail ("FAIL: could not import PEM cert\n");
+
+ if (gnutls_x509_crt_get_subject (cert, &sdn) == 0)
+ success ("success: got subject DN.\n");
+ else
+ fail ("FAIL: could not get subject DN.\n");
+
+ buflen = sizeof buf;
+ rv = gnutls_x509_dn_export (sdn, GNUTLS_X509_FMT_DER, buf, &buflen);
+ if (rv == 0)
+ success ("success: exported subject DN.\n");
+ else
+ fail ("FAIL: could not export subject DN: %s\n",
+ gnutls_strerror (rv));
+
+ if (gnutls_x509_dn_init (&dn2) == 0)
+ success ("success: init DN.\n");
+ else
+ fail ("FAIL: DN init.\n");
+
+ datum.data = buf;
+ datum.size = buflen;
+
+ if (gnutls_x509_dn_import (dn2, &datum) == 0)
+ success ("success: re-import subject DN.\n");
+ else
+ fail ("FAIL: re-import subject DN.\n");
+
+ buf2len = sizeof buf2;
+ rv = gnutls_x509_dn_export (dn2, GNUTLS_X509_FMT_DER, buf2, &buf2len);
+ if (rv == 0)
+ success ("success: exported subject DN.\n");
+ else
+ fail ("FAIL: could not export subject DN: %s\n",
+ gnutls_strerror (rv));
+
+ if (buflen == buf2len && memcmp (buf, buf2, buflen) == 0)
+ success ("success: export/import/export match.\n");
+ else
+ fail ("FAIL: export/import/export differ.\n");
+
+ gnutls_x509_dn_deinit (dn2);
+
+ gnutls_x509_crt_deinit (cert);
+
+}
More information about the Gnutls-devel
mailing list