X509_NAME_add_entry_by_txt(3) OpenSSL X509_NAME_add_entry_by_txt(3) NNAAMMEE X509_NAME_add_entry_by_txt, X509_NAME_add_entry_by_OBJ, X509_NAME_add_entry_by_NID, X509_NAME_add_entry, X509_NAME_delete_entry - X509_NAME modification functions SSYYNNOOPPSSIISS #include int X509_NAME_add_entry_by_txt(X509_NAME *name, const char *field, int type, const unsigned char *bytes, int len, int loc, int set); int X509_NAME_add_entry_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, int type, unsigned char *bytes, int len, int loc, int set); int X509_NAME_add_entry_by_NID(X509_NAME *name, int nid, int type, unsigned char *bytes, int len, int loc, int set); int X509_NAME_add_entry(X509_NAME *name,X509_NAME_ENTRY *ne, int loc, int set); X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc); DDEESSCCRRIIPPTTIIOONN _X_5_0_9___N_A_M_E___a_d_d___e_n_t_r_y___b_y___t_x_t_(_), _X_5_0_9___N_A_M_E___a_d_d___e_n_t_r_y___b_y___O_B_J_(_) and _X_5_0_9___N_A_M_E___a_d_d___e_n_t_r_y___b_y___N_I_D_(_) add a field whose name is defined by a string ffiieelldd, an object oobbjj or a NID nniidd respectively. The field value to be added is in bbyytteess of length lleenn. If lleenn is -1 then the field length is calculated internally using strlen(bytes). The type of field is determined by ttyyppee which can either be a defini- tion of the type of bbyytteess (such as MMBBSSTTRRIINNGG__AASSCC) or a standard ASN1 type (such as VV__AASSNN11__IIAA55SSTTRRIINNGG). The new entry is added to a position determined by lloocc and sseett. _X_5_0_9___N_A_M_E___a_d_d___e_n_t_r_y_(_) adds a copy of XX550099__NNAAMMEE__EENNTTRRYY structure nnee to nnaammee. The new entry is added to a position determined by lloocc and sseett. Since a copy of nnee is added nnee must be freed up after the call. _X_5_0_9___N_A_M_E___d_e_l_e_t_e___e_n_t_r_y_(_) deletes an entry from nnaammee at position lloocc. The deleted entry is returned and must be freed up. NNOOTTEESS The use of string types such as MMBBSSTTRRIINNGG__AASSCC or MMBBSSTTRRIINNGG__UUTTFF88 is strongly recommened for the ttyyppee parameter. This allows the internal code to correctly determine the type of the field and to apply length checks according to the relevant standards. This is done using _A_S_N_1___S_T_R_I_N_G___s_e_t___b_y___N_I_D_(_). If instead an ASN1 type is used no checks are performed and the sup- plied data in bbyytteess is used directly. In _X_5_0_9___N_A_M_E___a_d_d___e_n_t_r_y___b_y___t_x_t_(_) the ffiieelldd string represents the field name using OBJ_txt2obj(field, 0). The lloocc and sseett parameters determine where a new entry should be added. For almost all applications lloocc can be set to -1 and sseett to 0. This adds a new entry to the end of nnaammee as a single valued RelativeDistin- guishedName (RDN). lloocc actually determines the index where the new entry is inserted: if it is -1 it is appended. sseett determines how the new type is added. If it is zero a new RDN is created. If sseett is -1 or 1 it is added to the previous or next RDN structure respectively. This will then be a multivalued RDN: since multivalues RDNs are very seldom used sseett is almost always set to zero. EEXXAAMMPPLLEESS Create an XX550099__NNAAMMEE structure: "C=UK, O=Disorganized Organization, CN=Joe Bloggs" X509_NAME *nm; nm = X509_NAME_new(); if (nm == NULL) /* Some error */ if (!X509_NAME_add_entry_by_txt(nm, "C", MBSTRING_ASC, "UK", -1, -1, 0)) /* Error */ if (!X509_NAME_add_entry_by_txt(nm, "O", MBSTRING_ASC, "Disorganized Organization", -1, -1, 0)) /* Error */ if (!X509_NAME_add_entry_by_txt(nm, "CN", MBSTRING_ASC, "Joe Bloggs", -1, -1, 0)) /* Error */ RREETTUURRNN VVAALLUUEESS _X_5_0_9___N_A_M_E___a_d_d___e_n_t_r_y___b_y___t_x_t_(_), _X_5_0_9___N_A_M_E___a_d_d___e_n_t_r_y___b_y___O_B_J_(_), _X_5_0_9___N_A_M_E___a_d_d___e_n_t_r_y___b_y___N_I_D_(_) and _X_5_0_9___N_A_M_E___a_d_d___e_n_t_r_y_(_) return 1 for success of 0 if an error occurred. _X_5_0_9___N_A_M_E___d_e_l_e_t_e___e_n_t_r_y_(_) returns either the deleted XX550099__NNAAMMEE__EENNTTRRYY structure of NNUULLLL if an error occurred. BBUUGGSS ttyyppee can still be set to VV__AASSNN11__AAPPPP__CCHHOOOOSSEE to use a different algorithm to determine field types. Since this form does not understand multi- character types, performs no length checks and can result in invalid field types its use is strongly discouraged. SSEEEE AALLSSOO _E_R_R___g_e_t___e_r_r_o_r(3), _d_2_i___X_5_0_9___N_A_M_E(3) HHIISSTTOORRYY 1.0.1u 2016-09-22 X509_NAME_add_entry_by_txt(3)