src/ssl_sock.c
static int
ssl_sock_get_dn_entry(X509_NAME *a, const struct chunk *entry, int pos, struct chunk *out)
{
	X509_NAME_ENTRY *ne;
	int i, j, n;
	int cur = 0;
	const char *s;
	char tmp[128];

	out->len = 0;
	for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {
		if (pos < 0)
			j = (sk_X509_NAME_ENTRY_num(a->entries)-1) - i;
		else
			j = i;

		ne = sk_X509_NAME_ENTRY_value(a->entries, j);
		n = OBJ_obj2nid(ne->object);
		if ((n == NID_undef) || ((s = OBJ_nid2sn(n)) == NULL)) {
			i2t_ASN1_OBJECT(tmp, sizeof(tmp), ne->object);
			s = tmp;
		}

		if (chunk_strcasecmp(entry, s) != 0)
			continue;

		if (pos < 0)
			cur--;
		else
			cur++;

		if (cur != pos)
			continue;

		if (ne->value->length > out->size)
			return -1;

		memcpy(out->str, ne->value->data, ne->value->length);
		out->len = ne->value->length;
		return 1;
	}

	return 0;

}
/* Extract an entry from a X509_NAME and copy its value to an output chunk.
 * Returns 1 if entry found, 0 if entry not found, or -1 if output not large enough.
 */
Extract an entry from a X509_NAME and copy its value to an output chunk.
Returns 1 if entry found, 0 if entry not found, or -1 if output not large enough.
Extract an entry from a X509_NAME and copy its value to an output chunk . Returns 1 if entry found 0 if entry not found or - 1 if output not large enough .
static int
ssl_sock_get_dn_entry(X509_NAME *a, const struct chunk *entry, int pos, struct chunk *out)
{
	X509_NAME_ENTRY *ne;
	int i, j, n;
	int cur = 0;
	const char *s;
	char tmp[128];
	out->len = 0;
	for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {
		if (pos < 0)
			j = (sk_X509_NAME_ENTRY_num(a->entries)-1) - i;
		else
			j = i;
		ne = sk_X509_NAME_ENTRY_value(a->entries, j);
		n = OBJ_obj2nid(ne->object);
		if ((n == NID_undef) || ((s = OBJ_nid2sn(n)) == NULL)) {
			i2t_ASN1_OBJECT(tmp, sizeof(tmp), ne->object);
			s = tmp;
		}
		if (chunk_strcasecmp(entry, s) != 0)
			continue;
		if (pos < 0)
			cur--;
		else
			cur++;
		if (cur != pos)
			continue;
		if (ne->value->length > out->size)
			return -1;
		memcpy(out->str, ne->value->data, ne->value->length);
		out->len = ne->value->length;
		return 1;
	}
	return 0;
}
static int ssl_sock_get_dn_entry ( X509_NAME * a , const struct chunk * entry , int pos , struct chunk * out ) { X509_NAME_ENTRY * ne ; int i , j , n ; int cur = 0 ; const char * s ; char tmp [ 128 ] ; out -> len = 0 ; for ( i = 0 ; i < sk_X509_NAME_ENTRY_num ( a -> entries ) ; i ++ ) { if ( pos < 0 ) j = ( sk_X509_NAME_ENTRY_num ( a -> entries ) - 1 ) - i ; else j = i ; ne = sk_X509_NAME_ENTRY_value ( a -> entries , j ) ; n = OBJ_obj2nid ( ne -> object ) ; if ( ( n == NID_undef ) || ( ( s = OBJ_nid2sn ( n ) ) == NULL ) ) { i2t_ASN1_OBJECT ( tmp , sizeof ( tmp ) , ne -> object ) ; s = tmp ; } if ( chunk_strcasecmp ( entry , s ) != 0 ) continue ; if ( pos < 0 ) cur -- ; else cur ++ ; if ( cur != pos ) continue ; if ( ne -> value -> length > out -> size ) return -1 ; memcpy ( out -> str , ne -> value -> data , ne -> value -> length ) ; out -> len = ne -> value -> length ; return 1 ; } return 0 ; }
Extract an entry from a X509_NAME and copy its value to an output chunk.
Extract an entry from a X509_NAME and copy its value to an output chunk .