avoid potential spurious BN_free()
[openssl.git] / crypto / x509 / x509.h
index 96d3b6988892c1cd79cb28da8f15d323ae0978fc..66990ae5a88e831dab3ea36fd9957515f7257d1f 100644 (file)
@@ -64,6 +64,7 @@
 #ifndef HEADER_X509_H
 #define HEADER_X509_H
 
+#include <openssl/e_os2.h>
 #include <openssl/symhacks.h>
 #ifndef OPENSSL_NO_BUFFER
 #include <openssl/buffer.h>
 #include <openssl/asn1.h>
 #include <openssl/safestack.h>
 
-#ifndef OPENSSL_NO_RSA
-#include <openssl/rsa.h>
-#endif
-
-#ifndef OPENSSL_NO_DSA
-#include <openssl/dsa.h>
-#endif
-
 #ifndef OPENSSL_NO_EC
 #include <openssl/ec.h>
 #endif
 #include <openssl/ecdh.h>
 #endif
 
+#ifndef OPENSSL_NO_DEPRECATED
+#ifndef OPENSSL_NO_RSA
+#include <openssl/rsa.h>
+#endif
+#ifndef OPENSSL_NO_DSA
+#include <openssl/dsa.h>
+#endif
 #ifndef OPENSSL_NO_DH
 #include <openssl/dh.h>
 #endif
+#endif
+
 #ifndef OPENSSL_NO_SHA
 #include <openssl/sha.h>
 #endif
-#include <openssl/evp.h>
-#include <openssl/e_os2.h>
 #include <openssl/ossl_typ.h>
 
 #ifdef  __cplusplus
@@ -113,8 +113,9 @@ extern "C" {
 #endif
 
 #ifdef OPENSSL_SYS_WIN32
-/* Under Win32 this is defined in wincrypt.h */
+/* Under Win32 these are defined in wincrypt.h */
 #undef X509_NAME
+#undef X509_CERT_PAIR
 #endif
 
 #define X509_FILETYPE_PEM      1
@@ -135,8 +136,8 @@ extern "C" {
 typedef struct X509_objects_st
        {
        int nid;
-       int (*a2i)();
-       int (*i2a)();
+       int (*a2i)(void);
+       int (*i2a)(void);
        } X509_OBJECTS;
 
 struct X509_algor_st
@@ -279,12 +280,14 @@ struct x509_st
        CRYPTO_EX_DATA ex_data;
        /* These contain copies of various extension values */
        long ex_pathlen;
+       long ex_pcpathlen;
        unsigned long ex_flags;
        unsigned long ex_kusage;
        unsigned long ex_xkusage;
        unsigned long ex_nscert;
        ASN1_OCTET_STRING *skid;
        struct AUTHORITY_KEYID_st *akid;
+       X509_POLICY_CACHE *policy_cache;
 #ifndef OPENSSL_NO_SHA
        unsigned char sha1_hash[SHA_DIGEST_LENGTH];
 #endif
@@ -307,6 +310,11 @@ typedef struct x509_trust_st {
 
 DECLARE_STACK_OF(X509_TRUST)
 
+typedef struct x509_cert_pair_st {
+       X509 *forward;
+       X509 *reverse;
+} X509_CERT_PAIR;
+
 /* standard trust ids */
 
 #define X509_TRUST_DEFAULT     -1      /* Only valid in purpose settings */
@@ -428,6 +436,7 @@ typedef struct X509_crl_info_st
        ASN1_TIME *nextUpdate;
        STACK_OF(X509_REVOKED) *revoked;
        STACK_OF(X509_EXTENSION) /* [0] */ *extensions;
+       ASN1_ENCODING enc;
        } X509_CRL_INFO;
 
 struct X509_crl_st
@@ -504,10 +513,12 @@ typedef struct Netscape_certificate_sequence
        STACK_OF(X509) *certs;
        } NETSCAPE_CERT_SEQUENCE;
 
+/* Unused (and iv length is wrong)
 typedef struct CBCParameter_st
        {
        unsigned char iv[8];
        } CBC_PARAM;
+*/
 
 /* Password based encryption structure */
 
@@ -849,10 +860,6 @@ X509_REQ *X509_REQ_dup(X509_REQ *req);
 X509_ALGOR *X509_ALGOR_dup(X509_ALGOR *xn);
 X509_NAME *X509_NAME_dup(X509_NAME *xn);
 X509_NAME_ENTRY *X509_NAME_ENTRY_dup(X509_NAME_ENTRY *ne);
-#ifndef OPENSSL_NO_RSA
-RSA *RSAPublicKey_dup(RSA *rsa);
-RSA *RSAPrivateKey_dup(RSA *rsa);
-#endif
 
 #endif /* !SSLEAY_MACROS */
 
@@ -881,21 +888,21 @@ EVP_PKEY *        X509_PUBKEY_get(X509_PUBKEY *key);
 int            X509_get_pubkey_parameters(EVP_PKEY *pkey,
                                           STACK_OF(X509) *chain);
 int            i2d_PUBKEY(EVP_PKEY *a,unsigned char **pp);
-EVP_PKEY *     d2i_PUBKEY(EVP_PKEY **a,unsigned char **pp,
+EVP_PKEY *     d2i_PUBKEY(EVP_PKEY **a,const unsigned char **pp,
                        long length);
 #ifndef OPENSSL_NO_RSA
 int            i2d_RSA_PUBKEY(RSA *a,unsigned char **pp);
-RSA *          d2i_RSA_PUBKEY(RSA **a,unsigned char **pp,
+RSA *          d2i_RSA_PUBKEY(RSA **a,const unsigned char **pp,
                        long length);
 #endif
 #ifndef OPENSSL_NO_DSA
 int            i2d_DSA_PUBKEY(DSA *a,unsigned char **pp);
-DSA *          d2i_DSA_PUBKEY(DSA **a,unsigned char **pp,
+DSA *          d2i_DSA_PUBKEY(DSA **a,const unsigned char **pp,
                        long length);
 #endif
 #ifndef OPENSSL_NO_EC
 int            i2d_EC_PUBKEY(EC_KEY *a, unsigned char **pp);
-EC_KEY                 *d2i_EC_PUBKEY(EC_KEY **a, unsigned char **pp,
+EC_KEY                 *d2i_EC_PUBKEY(EC_KEY **a, const unsigned char **pp,
                        long length);
 #endif
 
@@ -919,16 +926,19 @@ DECLARE_ASN1_FUNCTIONS(X509_CINF)
 DECLARE_ASN1_FUNCTIONS(X509)
 DECLARE_ASN1_FUNCTIONS(X509_CERT_AUX)
 
+DECLARE_ASN1_FUNCTIONS(X509_CERT_PAIR)
+
 int X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
             CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
 int X509_set_ex_data(X509 *r, int idx, void *arg);
 void *X509_get_ex_data(X509 *r, int idx);
 int            i2d_X509_AUX(X509 *a,unsigned char **pp);
-X509 *         d2i_X509_AUX(X509 **a,unsigned char **pp,long length);
+X509 *         d2i_X509_AUX(X509 **a,const unsigned char **pp,long length);
 
 int X509_alias_set1(X509 *x, unsigned char *name, int len);
 int X509_keyid_set1(X509 *x, unsigned char *id, int len);
 unsigned char * X509_alias_get0(X509 *x, int *len);
+unsigned char * X509_keyid_get0(X509 *x, int *len);
 int (*X509_TRUST_set_default(int (*trust)(int , X509 *, int)))(int, X509 *, int);
 int X509_TRUST_set(int *t, int trust);
 int X509_add1_trust_object(X509 *x, ASN1_OBJECT *obj);
@@ -945,7 +955,7 @@ int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev);
 X509_PKEY *    X509_PKEY_new(void );
 void           X509_PKEY_free(X509_PKEY *a);
 int            i2d_X509_PKEY(X509_PKEY *a,unsigned char **pp);
-X509_PKEY *    d2i_X509_PKEY(X509_PKEY **a,unsigned char **pp,long length);
+X509_PKEY *    d2i_X509_PKEY(X509_PKEY **a,const unsigned char **pp,long length);
 
 DECLARE_ASN1_FUNCTIONS(NETSCAPE_SPKI)
 DECLARE_ASN1_FUNCTIONS(NETSCAPE_SPKAC)
@@ -956,15 +966,15 @@ X509_INFO *       X509_INFO_new(void);
 void           X509_INFO_free(X509_INFO *a);
 char *         X509_NAME_oneline(X509_NAME *a,char *buf,int size);
 
-int ASN1_verify(int (*i2d)(), X509_ALGOR *algor1,
-       ASN1_BIT_STRING *signature,char *data,EVP_PKEY *pkey);
+int ASN1_verify(i2d_of_void *i2d, X509_ALGOR *algor1,
+               ASN1_BIT_STRING *signature,char *data,EVP_PKEY *pkey);
 
-int ASN1_digest(int (*i2d)(),const EVP_MD *type,char *data,
-       unsigned char *md,unsigned int *len);
+int ASN1_digest(i2d_of_void *i2d,const EVP_MD *type,char *data,
+               unsigned char *md,unsigned int *len);
 
-int ASN1_sign(int (*i2d)(), X509_ALGOR *algor1, X509_ALGOR *algor2,
-       ASN1_BIT_STRING *signature,
-       char *data,EVP_PKEY *pkey, const EVP_MD *type);
+int ASN1_sign(i2d_of_void *i2d, X509_ALGOR *algor1,
+             X509_ALGOR *algor2, ASN1_BIT_STRING *signature,
+             char *data,EVP_PKEY *pkey, const EVP_MD *type);
 
 int ASN1_item_digest(const ASN1_ITEM *it,const EVP_MD *type,void *data,
        unsigned char *md,unsigned int *len);
@@ -1029,6 +1039,8 @@ int X509_CRL_sort(X509_CRL *crl);
 int X509_REVOKED_set_serialNumber(X509_REVOKED *x, ASN1_INTEGER *serial);
 int X509_REVOKED_set_revocationDate(X509_REVOKED *r, ASN1_TIME *tm);
 
+int            X509_REQ_check_private_key(X509_REQ *x509,EVP_PKEY *pkey);
+
 int            X509_check_private_key(X509 *x509,EVP_PKEY *pkey);
 
 int            X509_issuer_and_serial_cmp(const X509 *a, const X509 *b);
@@ -1085,18 +1097,18 @@ int X509_NAME_add_entry_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, int type,
 int X509_NAME_add_entry_by_NID(X509_NAME *name, int nid, int type,
                        unsigned char *bytes, int len, int loc, int set);
 X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_txt(X509_NAME_ENTRY **ne,
-               char *field, int type, unsigned char *bytes, int len);
+               const char *field, int type, const unsigned char *bytes, int len);
 X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid,
                        int type,unsigned char *bytes, int len);
-int X509_NAME_add_entry_by_txt(X509_NAME *name, char *field, int type,
-                       unsigned char *bytes, int len, int loc, int set);
+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);
 X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne,
-                       ASN1_OBJECT *obj, int type,unsigned char *bytes,
+                       ASN1_OBJECT *obj, int type,const unsigned char *bytes,
                        int len);
 int            X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne,
                        ASN1_OBJECT *obj);
 int            X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type,
-                       unsigned char *bytes, int len);
+                       const unsigned char *bytes, int len);
 ASN1_OBJECT *  X509_NAME_ENTRY_get_object(X509_NAME_ENTRY *ne);
 ASN1_STRING *  X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne);
 
@@ -1189,6 +1201,24 @@ int X509_ATTRIBUTE_count(X509_ATTRIBUTE *attr);
 ASN1_OBJECT *X509_ATTRIBUTE_get0_object(X509_ATTRIBUTE *attr);
 ASN1_TYPE *X509_ATTRIBUTE_get0_type(X509_ATTRIBUTE *attr, int idx);
 
+int EVP_PKEY_get_attr_count(const EVP_PKEY *key);
+int EVP_PKEY_get_attr_by_NID(const EVP_PKEY *key, int nid,
+                         int lastpos);
+int EVP_PKEY_get_attr_by_OBJ(const EVP_PKEY *key, ASN1_OBJECT *obj,
+                         int lastpos);
+X509_ATTRIBUTE *EVP_PKEY_get_attr(const EVP_PKEY *key, int loc);
+X509_ATTRIBUTE *EVP_PKEY_delete_attr(EVP_PKEY *key, int loc);
+int EVP_PKEY_add1_attr(EVP_PKEY *key, X509_ATTRIBUTE *attr);
+int EVP_PKEY_add1_attr_by_OBJ(EVP_PKEY *key,
+                       const ASN1_OBJECT *obj, int type,
+                       const unsigned char *bytes, int len);
+int EVP_PKEY_add1_attr_by_NID(EVP_PKEY *key,
+                       int nid, int type,
+                       const unsigned char *bytes, int len);
+int EVP_PKEY_add1_attr_by_txt(EVP_PKEY *key,
+                       const char *attrname, int type,
+                       const unsigned char *bytes, int len);
+
 int            X509_verify_cert(X509_STORE_CTX *ctx);
 
 /* lookup a cert from a X509 STACK */
@@ -1235,18 +1265,20 @@ void ERR_load_X509_strings(void);
 /* Function codes. */
 #define X509_F_ADD_CERT_DIR                             100
 #define X509_F_BY_FILE_CTRL                             101
+#define X509_F_CHECK_POLICY                             145
 #define X509_F_DIR_CTRL                                         102
 #define X509_F_GET_CERT_BY_SUBJECT                      103
 #define X509_F_NETSCAPE_SPKI_B64_DECODE                         129
 #define X509_F_NETSCAPE_SPKI_B64_ENCODE                         130
+#define X509_F_X509AT_ADD1_ATTR                                 135
 #define X509_F_X509V3_ADD_EXT                           104
-#define X509_F_X509_ADD_ATTR                            135
 #define X509_F_X509_ATTRIBUTE_CREATE_BY_NID             136
 #define X509_F_X509_ATTRIBUTE_CREATE_BY_OBJ             137
 #define X509_F_X509_ATTRIBUTE_CREATE_BY_TXT             140
 #define X509_F_X509_ATTRIBUTE_GET0_DATA                         139
 #define X509_F_X509_ATTRIBUTE_SET1_DATA                         138
 #define X509_F_X509_CHECK_PRIVATE_KEY                   128
+#define X509_F_X509_CRL_PRINT_FP                        147
 #define X509_F_X509_EXTENSION_CREATE_BY_NID             108
 #define X509_F_X509_EXTENSION_CREATE_BY_OBJ             109
 #define X509_F_X509_GET_PUBKEY_PARAMETERS               110
@@ -1259,14 +1291,16 @@ void ERR_load_X509_strings(void);
 #define X509_F_X509_NAME_ENTRY_SET_OBJECT               115
 #define X509_F_X509_NAME_ONELINE                        116
 #define X509_F_X509_NAME_PRINT                          117
-#define X509_F_X509_PRINT_FP                            118
+#define X509_F_X509_PRINT_EX_FP                                 118
 #define X509_F_X509_PUBKEY_GET                          119
 #define X509_F_X509_PUBKEY_SET                          120
-#define X509_F_X509_REQ_PRINT                           121
+#define X509_F_X509_REQ_CHECK_PRIVATE_KEY               144
+#define X509_F_X509_REQ_PRINT_EX                        121
 #define X509_F_X509_REQ_PRINT_FP                        122
 #define X509_F_X509_REQ_TO_X509                                 123
 #define X509_F_X509_STORE_ADD_CERT                      124
 #define X509_F_X509_STORE_ADD_CRL                       125
+#define X509_F_X509_STORE_CTX_GET1_ISSUER               146
 #define X509_F_X509_STORE_CTX_INIT                      143
 #define X509_F_X509_STORE_CTX_NEW                       142
 #define X509_F_X509_STORE_CTX_PURPOSE_INHERIT           134