int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s) { int i; unsigned char *p; if (s->type != V_ASN1_UNIVERSALSTRING) return(0); if ((s->length%4) != 0) return(0); p=s->data; for (i=0; i<s->length; i+=4) { if ((p[0] != '\0') || (p[1] != '\0') || (p[2] != '\0')) break; else p+=4; } if (i < s->length) return(0); p=s->data; for (i=3; i<s->length; i+=4) { *(p++)=s->data[i]; } *(p)='\0'; s->length/=4; s->type=ASN1_PRINTABLE_type(s->data,s->length); return(1); }
int X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type, const uint8_t *bytes, int len) { int i; if ((ne == NULL) || ((bytes == NULL) && (len != 0))) return (0); if ((type > 0) && (type & MBSTRING_FLAG)) return ASN1_STRING_set_by_NID(&ne->value, bytes, len, type, OBJ_obj2nid(ne->object)) ? 1 : 0; if (len < 0) len = strlen((const char *)bytes); i = ASN1_STRING_set(ne->value, bytes, len); if (!i) return (0); if (type != V_ASN1_UNDEF) { if (type == V_ASN1_APP_CHOOSE) ne->value->type = ASN1_PRINTABLE_type(bytes, len); else ne->value->type = type; } return (1); }
int32_t Httpsadd_DN_object( HX509Name_t *n, char *text, char *def, char *value, int32_t nid, int32_t min, int32_t max ) { int32_t i, j, ret = 0; HX509NameEntry_t *ne = NULL; char buf[HTTPS_PARAMS_SUB_NAME_LEN]; if(!value) { Trace(HTTPS_ID, TRACE_SEVERE, "value is NULL\r\n"); return OF_FAILURE; } of_memset(buf, 0, HTTPS_PARAMS_SUB_NAME_LEN); if ((value != NULL) && (strlen(value))) { strcpy(buf, value); strcat(buf, "\n"); } if (strlen(value) == 0) { return (1); } if (buf[0] == '\0') { return(0); } else if (buf[0] == '\n') { if ((def == NULL) || (def[0] == '\0')) { return(1); } strcpy(buf, def); strcat(buf, "\n"); } else if ((buf[0] == '.') && (buf[1] == '\n')) { return(1); } i = strlen(buf); if (buf[i-1] != '\n') { Trace(HTTPS_ID, TRACE_SEVERE, "Weird input\n"); return(0); } buf[--i] = '\0'; j = ASN1_PRINTABLE_type((unsigned char *) buf, -1); if (Httpsreq_fix_data(nid, &j, i, min, max) == 0) { goto err; } if ((ne = X509_NAME_ENTRY_create_by_NID(NULL, nid, j, (unsigned char *) buf, strlen(buf))) == NULL) { goto err; } if (!X509_NAME_add_entry(n, ne, X509_NAME_entry_count(n), 0)) { goto err; } ret = 1; err: if (ne != NULL) { X509_NAME_ENTRY_free(ne); } return(ret); } /* Httpsadd_DN_object() */