/* a_x509a.c */
-/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
- * project 1999.
+/*
+ * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
+ * 1999.
*/
/* ====================================================================
* Copyright (c) 1999 The OpenSSL Project. All rights reserved.
* are met:
*
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
#include <stdio.h>
#include "cryptlib.h"
#include <openssl/evp.h>
-#include <openssl/asn1_mac.h>
+#include <openssl/asn1t.h>
#include <openssl/x509.h>
-/* X509_CERT_AUX routines. These are used to encode additional
- * user modifiable data about a certificate. This data is
- * appended to the X509 encoding when the *_X509_AUX routines
- * are used. This means that the "traditional" X509 routines
- * will simply ignore the extra data.
+/*
+ * X509_CERT_AUX routines. These are used to encode additional user
+ * modifiable data about a certificate. This data is appended to the X509
+ * encoding when the *_X509_AUX routines are used. This means that the
+ * "traditional" X509 routines will simply ignore the extra data.
*/
static X509_CERT_AUX *aux_get(X509 *x);
-X509_CERT_AUX *d2i_X509_CERT_AUX(X509_CERT_AUX **a, unsigned char **pp, long length)
-{
- M_ASN1_D2I_vars(a, X509_CERT_AUX *, X509_CERT_AUX_new);
-
- M_ASN1_D2I_Init();
- M_ASN1_D2I_start_sequence();
-
- M_ASN1_D2I_get_opt(ret->trust, d2i_ASN1_BIT_STRING,
- V_ASN1_BIT_STRING);
- M_ASN1_D2I_get_IMP_opt(ret->notrust, d2i_ASN1_BIT_STRING,0,
- V_ASN1_BIT_STRING);
+ASN1_SEQUENCE(X509_CERT_AUX) = {
+ ASN1_SEQUENCE_OF_OPT(X509_CERT_AUX, trust, ASN1_OBJECT),
+ ASN1_IMP_SEQUENCE_OF_OPT(X509_CERT_AUX, reject, ASN1_OBJECT, 0),
+ ASN1_OPT(X509_CERT_AUX, alias, ASN1_UTF8STRING),
+ ASN1_OPT(X509_CERT_AUX, keyid, ASN1_OCTET_STRING),
+ ASN1_IMP_SEQUENCE_OF_OPT(X509_CERT_AUX, other, X509_ALGOR, 1)
+} ASN1_SEQUENCE_END(X509_CERT_AUX)
- M_ASN1_D2I_get_seq_opt_type(ASN1_OBJECT, ret->othertrust,
- d2i_ASN1_OBJECT, ASN1_OBJECT_free);
- M_ASN1_D2I_get_IMP_set_opt_type(ASN1_OBJECT, ret->othernotrust,
- d2i_ASN1_OBJECT, ASN1_OBJECT_free, 1);
- M_ASN1_D2I_get_opt(ret->alias, d2i_ASN1_UTF8STRING, V_ASN1_UTF8STRING);
- M_ASN1_D2I_get_opt(ret->other, d2i_ASN1_TYPE, V_ASN1_SEQUENCE);
+IMPLEMENT_ASN1_FUNCTIONS(X509_CERT_AUX)
- M_ASN1_D2I_Finish(a, X509_CERT_AUX_free, ASN1_F_D2I_X509_CERT_AUX);
-}
-
-X509_CERT_AUX *X509_CERT_AUX_new()
-{
- X509_CERT_AUX *ret = NULL;
- ASN1_CTX c;
- M_ASN1_New_Malloc(ret, X509_CERT_AUX);
- ret->trust = NULL;
- ret->notrust = NULL;
- ret->othertrust = NULL;
- ret->othernotrust = NULL;
- ret->alias = NULL;
- ret->other = NULL;
- return(ret);
- M_ASN1_New_Error(ASN1_F_X509_CERT_AUX_NEW);
-}
-
-void X509_CERT_AUX_free(X509_CERT_AUX *a)
+static X509_CERT_AUX *aux_get(X509 *x)
{
- if(a == NULL) return;
- ASN1_BIT_STRING_free(a->trust);
- ASN1_BIT_STRING_free(a->notrust);
- sk_ASN1_OBJECT_pop_free(a->othertrust, ASN1_OBJECT_free);
- sk_ASN1_OBJECT_pop_free(a->othernotrust, ASN1_OBJECT_free);
- ASN1_UTF8STRING_free(a->alias);
- ASN1_TYPE_free(a->other);
+ if (!x)
+ return NULL;
+ if (!x->aux && !(x->aux = X509_CERT_AUX_new()))
+ return NULL;
+ return x->aux;
}
-int i2d_X509_CERT_AUX(X509_CERT_AUX *a, unsigned char **pp)
+int X509_alias_set1(X509 *x, unsigned char *name, int len)
{
- M_ASN1_I2D_vars(a);
-
- M_ASN1_I2D_len(a->trust, i2d_ASN1_BIT_STRING);
- M_ASN1_I2D_len_IMP_opt(a->notrust, i2d_ASN1_BIT_STRING);
-
- M_ASN1_I2D_len_SEQUENCE_opt_type(ASN1_OBJECT, a->othertrust, i2d_ASN1_OBJECT);
- M_ASN1_I2D_len_IMP_SEQUENCE_opt_type(ASN1_OBJECT, a->othernotrust, i2d_ASN1_OBJECT, 1);
-
- M_ASN1_I2D_len(a->alias, i2d_ASN1_UTF8STRING);
- M_ASN1_I2D_len(a->other, i2d_ASN1_TYPE);
-
- M_ASN1_I2D_seq_total();
-
- M_ASN1_I2D_put(a->trust, i2d_ASN1_BIT_STRING);
- M_ASN1_I2D_put_IMP_opt(a->notrust, i2d_ASN1_BIT_STRING, 0);
-
- M_ASN1_I2D_put_SEQUENCE_opt_type(ASN1_OBJECT, a->othertrust, i2d_ASN1_OBJECT);
- M_ASN1_I2D_put_IMP_SEQUENCE_opt_type(ASN1_OBJECT, a->othernotrust, i2d_ASN1_OBJECT, 1);
-
- M_ASN1_I2D_put(a->alias, i2d_ASN1_UTF8STRING);
- M_ASN1_I2D_put(a->other, i2d_ASN1_TYPE);
-
- M_ASN1_I2D_finish();
+ X509_CERT_AUX *aux;
+ if (!name) {
+ if (!x || !x->aux || !x->aux->alias)
+ return 1;
+ ASN1_UTF8STRING_free(x->aux->alias);
+ x->aux->alias = NULL;
+ return 1;
+ }
+ if (!(aux = aux_get(x)))
+ return 0;
+ if (!aux->alias && !(aux->alias = ASN1_UTF8STRING_new()))
+ return 0;
+ return ASN1_STRING_set(aux->alias, name, len);
}
-static X509_CERT_AUX *aux_get(X509 *x)
+int X509_keyid_set1(X509 *x, unsigned char *id, int len)
{
- if(!x) return NULL;
- if(!x->aux && !(x->aux = X509_CERT_AUX_new())) return NULL;
- return x->aux;
+ X509_CERT_AUX *aux;
+ if (!id) {
+ if (!x || !x->aux || !x->aux->keyid)
+ return 1;
+ ASN1_OCTET_STRING_free(x->aux->keyid);
+ x->aux->keyid = NULL;
+ return 1;
+ }
+ if (!(aux = aux_get(x)))
+ return 0;
+ if (!aux->keyid && !(aux->keyid = ASN1_OCTET_STRING_new()))
+ return 0;
+ return ASN1_STRING_set(aux->keyid, id, len);
}
-int X509_alias_set(X509 *x, unsigned char *name, int len)
+unsigned char *X509_alias_get0(X509 *x, int *len)
{
- X509_CERT_AUX *aux;
- if(!(aux = aux_get(x))) return 0;
- if(!aux->alias && !(aux->alias = ASN1_UTF8STRING_new())) return 0;
- return ASN1_STRING_set(aux->alias, name, len);
+ if (!x->aux || !x->aux->alias)
+ return NULL;
+ if (len)
+ *len = x->aux->alias->length;
+ return x->aux->alias->data;
}
-unsigned char *X509_alias_get(X509 *x, int *len)
+unsigned char *X509_keyid_get0(X509 *x, int *len)
{
- if(!x->aux || !x->aux->alias) return NULL;
- if(len) *len = x->aux->alias->length;
- return x->aux->alias->data;
+ if (!x->aux || !x->aux->keyid)
+ return NULL;
+ if (len)
+ *len = x->aux->keyid->length;
+ return x->aux->keyid->data;
}
-int X509_trust_set_bit(X509 *x, int bit, int value)
+int X509_add1_trust_object(X509 *x, ASN1_OBJECT *obj)
{
- X509_CERT_AUX *aux;
- if(bit == -1) {
- if(x->aux && x->aux->trust) {
- ASN1_BIT_STRING_free(x->aux->trust);
- x->aux->trust = NULL;
- }
- return 1;
- }
- if(!(aux = aux_get(x))) return 0;
- if(!aux->trust && !(aux->trust = ASN1_BIT_STRING_new())) return 0;
- return ASN1_BIT_STRING_set_bit(aux->trust, bit, value);
+ X509_CERT_AUX *aux;
+ ASN1_OBJECT *objtmp = NULL;
+ if (obj) {
+ objtmp = OBJ_dup(obj);
+ if (!objtmp)
+ return 0;
+ }
+ if (!(aux = aux_get(x)))
+ goto err;
+ if (!aux->trust && !(aux->trust = sk_ASN1_OBJECT_new_null()))
+ goto err;
+ if (!objtmp || sk_ASN1_OBJECT_push(aux->trust, objtmp))
+ return 1;
+ err:
+ ASN1_OBJECT_free(objtmp);
+ return 0;
}
-int X509_notrust_set_bit(X509 *x, int bit, int value)
+int X509_add1_reject_object(X509 *x, ASN1_OBJECT *obj)
{
- X509_CERT_AUX *aux;
- if(bit == -1) {
- if(x->aux && x->aux->notrust) {
- ASN1_BIT_STRING_free(x->aux->notrust);
- x->aux->notrust = NULL;
- }
- return 1;
- }
- if(!(aux = aux_get(x))) return 0;
- if(!aux->notrust && !(aux->notrust = ASN1_BIT_STRING_new())) return 0;
- return ASN1_BIT_STRING_set_bit(aux->notrust, bit, value);
+ X509_CERT_AUX *aux;
+ ASN1_OBJECT *objtmp;
+ if (!(objtmp = OBJ_dup(obj)))
+ return 0;
+ if (!(aux = aux_get(x)))
+ return 0;
+ if (!aux->reject && !(aux->reject = sk_ASN1_OBJECT_new_null()))
+ return 0;
+ return sk_ASN1_OBJECT_push(aux->reject, objtmp);
}
-int X509_add_trust_object(X509 *x, ASN1_OBJECT *obj)
+void X509_trust_clear(X509 *x)
{
- X509_CERT_AUX *aux;
- if(!(aux = aux_get(x))) return 0;
- if(!aux->othertrust
- && !(aux->othertrust = sk_ASN1_OBJECT_new_null())) return 0;
- return sk_ASN1_OBJECT_push(aux->othertrust, obj);
+ if (x->aux && x->aux->trust) {
+ sk_ASN1_OBJECT_pop_free(x->aux->trust, ASN1_OBJECT_free);
+ x->aux->trust = NULL;
+ }
}
-int X509_add_notrust_object(X509 *x, ASN1_OBJECT *obj)
+void X509_reject_clear(X509 *x)
{
- X509_CERT_AUX *aux;
- if(!(aux = aux_get(x))) return 0;
- if(!aux->othernotrust
- && !(aux->othernotrust = sk_ASN1_OBJECT_new_null())) return 0;
- return sk_ASN1_OBJECT_push(aux->othernotrust, obj);
+ if (x->aux && x->aux->reject) {
+ sk_ASN1_OBJECT_pop_free(x->aux->reject, ASN1_OBJECT_free);
+ x->aux->reject = NULL;
+ }
}
-