1656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* v3_sxnet.c */
2e45f106cb6b47af1f21efe76e933bdea2f5dd1caNagendra Modadugu/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * project 1999.
4656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project */
5656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* ====================================================================
6656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * Copyright (c) 1999 The OpenSSL Project.  All rights reserved.
7656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *
8656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * Redistribution and use in source and binary forms, with or without
9656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * modification, are permitted provided that the following conditions
10656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * are met:
11656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *
12656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 1. Redistributions of source code must retain the above copyright
13656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *    notice, this list of conditions and the following disclaimer.
14656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *
15656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 2. Redistributions in binary form must reproduce the above copyright
16656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *    notice, this list of conditions and the following disclaimer in
17656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *    the documentation and/or other materials provided with the
18656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *    distribution.
19656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *
20656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 3. All advertising materials mentioning features or use of this
21656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *    software must display the following acknowledgment:
22656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *    "This product includes software developed by the OpenSSL Project
23656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *
25656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *    endorse or promote products derived from this software without
27656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *    prior written permission. For written permission, please contact
28656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *    licensing@OpenSSL.org.
29656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *
30656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 5. Products derived from this software may not be called "OpenSSL"
31656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *    nor may "OpenSSL" appear in their names without prior written
32656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *    permission of the OpenSSL Project.
33656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *
34656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 6. Redistributions of any form whatsoever must retain the following
35656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *    acknowledgment:
36656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *    "This product includes software developed by the OpenSSL Project
37656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *
39656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
43656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * OF THE POSSIBILITY OF SUCH DAMAGE.
51656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * ====================================================================
52656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *
53656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * This product includes cryptographic software written by Eric Young
54656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * (eay@cryptsoft.com).  This product includes software written by Tim
55656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * Hudson (tjh@cryptsoft.com).
56656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *
57656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project */
58656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
59656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#include <stdio.h>
60656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#include "cryptlib.h"
61656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#include <openssl/conf.h>
62656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#include <openssl/asn1.h>
63656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#include <openssl/asn1t.h>
64656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#include <openssl/x509v3.h>
65656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
66656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* Support for Thawte strong extranet extension */
67656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
68656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#define SXNET_TEST
69656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
70656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectstatic int sxnet_i2r(X509V3_EXT_METHOD *method, SXNET *sx, BIO *out, int indent);
71656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#ifdef SXNET_TEST
72656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectstatic SXNET * sxnet_v2i(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
73656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project						STACK_OF(CONF_VALUE) *nval);
74656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#endif
75656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectconst X509V3_EXT_METHOD v3_sxnet = {
76656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source ProjectNID_sxnet, X509V3_EXT_MULTILINE, ASN1_ITEM_ref(SXNET),
77656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project0,0,0,0,
78656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project0,0,
79656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project0,
80656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#ifdef SXNET_TEST
81656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project(X509V3_EXT_V2I)sxnet_v2i,
82656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#else
83656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project0,
84656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#endif
85656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project(X509V3_EXT_I2R)sxnet_i2r,
86656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project0,
87656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source ProjectNULL
88656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project};
89656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
90656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source ProjectASN1_SEQUENCE(SXNETID) = {
91656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	ASN1_SIMPLE(SXNETID, zone, ASN1_INTEGER),
92656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	ASN1_SIMPLE(SXNETID, user, ASN1_OCTET_STRING)
93656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project} ASN1_SEQUENCE_END(SXNETID)
94656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
95656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source ProjectIMPLEMENT_ASN1_FUNCTIONS(SXNETID)
96656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
97656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source ProjectASN1_SEQUENCE(SXNET) = {
98656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	ASN1_SIMPLE(SXNET, version, ASN1_INTEGER),
99656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	ASN1_SEQUENCE_OF(SXNET, ids, SXNETID)
100656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project} ASN1_SEQUENCE_END(SXNET)
101656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
102656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source ProjectIMPLEMENT_ASN1_FUNCTIONS(SXNET)
103656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
104656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectstatic int sxnet_i2r(X509V3_EXT_METHOD *method, SXNET *sx, BIO *out,
105656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	     int indent)
106656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project{
107656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	long v;
108656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	char *tmp;
109656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	SXNETID *id;
110656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	int i;
111656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	v = ASN1_INTEGER_get(sx->version);
112656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	BIO_printf(out, "%*sVersion: %ld (0x%lX)", indent, "", v + 1, v);
113656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	for(i = 0; i < sk_SXNETID_num(sx->ids); i++) {
114656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project		id = sk_SXNETID_value(sx->ids, i);
115656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project		tmp = i2s_ASN1_INTEGER(NULL, id->zone);
116656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project		BIO_printf(out, "\n%*sZone: %s, User: ", indent, "", tmp);
117656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project		OPENSSL_free(tmp);
118656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project		M_ASN1_OCTET_STRING_print(out, id->user);
119656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	}
120656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	return 1;
121656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project}
122656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
123656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#ifdef SXNET_TEST
124656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
125656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* NBB: this is used for testing only. It should *not* be used for anything
126656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * else because it will just take static IDs from the configuration file and
127656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * they should really be separate values for each user.
128656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project */
129656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
130656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
131656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectstatic SXNET * sxnet_v2i(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
132656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	     STACK_OF(CONF_VALUE) *nval)
133656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project{
134656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	CONF_VALUE *cnf;
135656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	SXNET *sx = NULL;
136656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	int i;
137656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
138656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project		cnf = sk_CONF_VALUE_value(nval, i);
139656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project		if(!SXNET_add_id_asc(&sx, cnf->name, cnf->value, -1))
140656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project								 return NULL;
141656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	}
142656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	return sx;
143656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project}
144656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
145656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
146656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#endif
147656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
148656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* Strong Extranet utility functions */
149656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
150656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* Add an id given the zone as an ASCII number */
151656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
152656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectint SXNET_add_id_asc(SXNET **psx, char *zone, char *user,
153656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	     int userlen)
154656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project{
155656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	ASN1_INTEGER *izone = NULL;
156656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	if(!(izone = s2i_ASN1_INTEGER(NULL, zone))) {
157656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project		X509V3err(X509V3_F_SXNET_ADD_ID_ASC,X509V3_R_ERROR_CONVERTING_ZONE);
158656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project		return 0;
159656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	}
160656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	return SXNET_add_id_INTEGER(psx, izone, user, userlen);
161656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project}
162656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
163656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* Add an id given the zone as an unsigned long */
164656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
165656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectint SXNET_add_id_ulong(SXNET **psx, unsigned long lzone, char *user,
166656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	     int userlen)
167656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project{
168656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	ASN1_INTEGER *izone = NULL;
169656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	if(!(izone = M_ASN1_INTEGER_new()) || !ASN1_INTEGER_set(izone, lzone)) {
170656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project		X509V3err(X509V3_F_SXNET_ADD_ID_ULONG,ERR_R_MALLOC_FAILURE);
171656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project		M_ASN1_INTEGER_free(izone);
172656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project		return 0;
173656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	}
174656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	return SXNET_add_id_INTEGER(psx, izone, user, userlen);
175656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
176656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project}
177656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
178656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* Add an id given the zone as an ASN1_INTEGER.
179656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * Note this version uses the passed integer and doesn't make a copy so don't
180656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * free it up afterwards.
181656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project */
182656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
183656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectint SXNET_add_id_INTEGER(SXNET **psx, ASN1_INTEGER *zone, char *user,
184656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	     int userlen)
185656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project{
186656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	SXNET *sx = NULL;
187656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	SXNETID *id = NULL;
188656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	if(!psx || !zone || !user) {
189656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project		X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER,X509V3_R_INVALID_NULL_ARGUMENT);
190656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project		return 0;
191656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	}
192656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	if(userlen == -1) userlen = strlen(user);
193656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	if(userlen > 64) {
194656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project		X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER,X509V3_R_USER_TOO_LONG);
195656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project		return 0;
196656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	}
197656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	if(!*psx) {
198656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project		if(!(sx = SXNET_new())) goto err;
199656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project		if(!ASN1_INTEGER_set(sx->version, 0)) goto err;
200656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project		*psx = sx;
201656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	} else sx = *psx;
202656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	if(SXNET_get_id_INTEGER(sx, zone)) {
203656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project		X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER,X509V3_R_DUPLICATE_ZONE_ID);
204656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project		return 0;
205656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	}
206656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
207656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	if(!(id = SXNETID_new())) goto err;
208656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	if(userlen == -1) userlen = strlen(user);
209656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
210656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	if(!M_ASN1_OCTET_STRING_set(id->user, user, userlen)) goto err;
211656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	if(!sk_SXNETID_push(sx->ids, id)) goto err;
212656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	id->zone = zone;
213656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	return 1;
214656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
215656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	err:
216656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER,ERR_R_MALLOC_FAILURE);
217656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	SXNETID_free(id);
218656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	SXNET_free(sx);
219656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	*psx = NULL;
220656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	return 0;
221656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project}
222656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
223656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source ProjectASN1_OCTET_STRING *SXNET_get_id_asc(SXNET *sx, char *zone)
224656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project{
225656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	ASN1_INTEGER *izone = NULL;
226656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	ASN1_OCTET_STRING *oct;
227656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	if(!(izone = s2i_ASN1_INTEGER(NULL, zone))) {
228656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project		X509V3err(X509V3_F_SXNET_GET_ID_ASC,X509V3_R_ERROR_CONVERTING_ZONE);
229656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project		return NULL;
230656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	}
231656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	oct = SXNET_get_id_INTEGER(sx, izone);
232656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	M_ASN1_INTEGER_free(izone);
233656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	return oct;
234656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project}
235656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
236656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source ProjectASN1_OCTET_STRING *SXNET_get_id_ulong(SXNET *sx, unsigned long lzone)
237656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project{
238656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	ASN1_INTEGER *izone = NULL;
239656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	ASN1_OCTET_STRING *oct;
240656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	if(!(izone = M_ASN1_INTEGER_new()) || !ASN1_INTEGER_set(izone, lzone)) {
241656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project		X509V3err(X509V3_F_SXNET_GET_ID_ULONG,ERR_R_MALLOC_FAILURE);
242656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project		M_ASN1_INTEGER_free(izone);
243656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project		return NULL;
244656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	}
245656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	oct = SXNET_get_id_INTEGER(sx, izone);
246656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	M_ASN1_INTEGER_free(izone);
247656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	return oct;
248656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project}
249656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
250656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source ProjectASN1_OCTET_STRING *SXNET_get_id_INTEGER(SXNET *sx, ASN1_INTEGER *zone)
251656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project{
252656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	SXNETID *id;
253656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	int i;
254656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	for(i = 0; i < sk_SXNETID_num(sx->ids); i++) {
255656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project		id = sk_SXNETID_value(sx->ids, i);
256656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project		if(!M_ASN1_INTEGER_cmp(id->zone, zone)) return id->user;
257656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	}
258656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	return NULL;
259656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project}
260656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
261656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source ProjectIMPLEMENT_STACK_OF(SXNETID)
262656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source ProjectIMPLEMENT_ASN1_SET_OF(SXNETID)
263