Additional, more descriptive error message for rejection of a session ID
[openssl.git] / ssl / ssl.h
index 6a3ad30969526b550f9cbe497c178562e36f9b94..8983cf97fa600ffe9bf76e5e9d91733179f62da4 100644 (file)
--- a/ssl/ssl.h
+++ b/ssl/ssl.h
@@ -148,6 +148,7 @@ extern "C" {
 #include <openssl/lhash.h>
 #include <openssl/buffer.h>
 #include <openssl/bio.h>
+#include <openssl/pem.h>
 #include <openssl/x509.h>
 
 #define SSL_FILETYPE_ASN1      X509_FILETYPE_ASN1
@@ -241,10 +242,12 @@ typedef struct ssl_session_st
        int not_resumable;
 
        /* The cert is the certificate used to establish this connection */
-       struct cert_st /* CERT */ *cert;
+       struct sess_cert_st /* SESS_CERT */ *sess_cert;
 
-       /* This is the cert for the other end.  On servers, it will be
-        * the same as cert->x509 */
+       /* This is the cert for the other end.
+        * On clients, it will be the same as sess_cert->peer_key->x509
+        * (the latter is not enough as sess_cert is not retained
+        * in the external representation of sessions, see ssl_asn1.c). */
        X509 *peer;
 
        int references;
@@ -391,15 +394,16 @@ struct ssl_ctx_st
 /**/   char *app_verify_arg;
 
        /* default values to use in SSL structures */
-/**/   struct cert_st /* CERT */ *default_cert;
+/**/   struct cert_st /* CERT */ *cert;
 /**/   int read_ahead;
 /**/   int verify_mode;
+/**/   int verify_depth;
 /**/   unsigned int sid_ctx_length;
 /**/   unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
 /**/   int (*default_verify_callback)(int ok,X509_STORE_CTX *ctx);
 
        /* Default password callback. */
-/**/   int (*default_passwd_callback)();
+/**/   pem_password_cb *default_passwd_callback;
 
        /* get client cert callback */
 /**/   int (*client_cert_cb)(/* SSL *ssl, X509 **x509, EVP_PKEY **pkey */);
@@ -510,6 +514,14 @@ struct ssl_st
        int in_handshake;
        int (*handshake_func)();
 
+       /* Imagine that here's a boolean member "init" that is
+        * switched as soon as SSL_set_{accept/connect}_state
+        * is called for the first time, so that "state" and
+        * "handshake_func" are properly initialized.  But as
+        * handshake_func is == 0 until then, we use this
+        * test instead of an "init" member.
+        */
+
        int server;     /* are we the server side? - mostly used by SSL_clear*/
 
        int new_session;/* 1 if we are to use a new session */
@@ -573,6 +585,7 @@ struct ssl_st
        /* Used in SSL2 and SSL3 */
        int verify_mode;        /* 0 don't care about verify failure.
                                 * 1 fail if verify fails */
+       int verify_depth;
        int (*verify_callback)(int ok,X509_STORE_CTX *ctx); /* fail if callback returns 0 */
        void (*info_callback)(); /* optional informational callback */
 
@@ -685,10 +698,6 @@ struct ssl_st
 #define SSL_get_timeout(a)     SSL_SESSION_get_timeout(a)
 #define SSL_set_timeout(a,b)   SSL_SESSION_set_timeout((a),(b))
 
-/* VMS linker has a 31 char name limit */
-#define SSL_CTX_set_cert_verify_callback(a,b,c) \
-               SSL_CTX_set_cert_verify_cb((a),(b),(c))
-
 #if 1 /*SSLEAY_MACROS*/
 #define d2i_SSL_SESSION_bio(bp,s_id) (SSL_SESSION *)ASN1_d2i_bio( \
        (char *(*)())SSL_SESSION_new,(char *(*)())d2i_SSL_SESSION, \
@@ -805,6 +814,21 @@ struct ssl_st
 #define SSL_CTX_add_extra_chain_cert(ctx,x509) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_EXTRA_CHAIN_CERT,0,(char *)x509)
 
+/* VMS uses only 31 characters for symbols. */
+#ifdef VMS
+#undef SSL_CTX_set_cert_verify_callback
+#define SSL_CTX_set_cert_verify_callback SSL_CTX_set_cert_verify_cb
+#undef SSL_CTX_use_certificate_chain_file
+#define SSL_CTX_use_certificate_chain_file SSL_CTX_use_cert_chain_file
+#undef SSL_CTX_set_default_verify_paths
+#define SSL_CTX_set_default_verify_paths SSL_CTX_set_def_verify_paths
+#undef SSL_get_ex_data_X509_STORE_CTX_idx
+#define SSL_get_ex_data_X509_STORE_CTX_idx SSL_get_ex_data_X509_STOR_CTX_i
+#undef SSL_add_file_cert_subjects_to_stack
+#define SSL_add_file_cert_subjects_to_stack SSL_add_file_cert_sub_to_stack
+#undef SSL_add_dir_cert_subjects_to_stack
+#define SSL_add_dir_cert_subjects_to_stack SSL_add_dir_cert_sub_to_stack
+#endif
 
 #ifdef HEADER_BIO_H
 BIO_METHOD *BIO_f_ssl(void);
@@ -851,9 +875,11 @@ BIO *      SSL_get_wbio(SSL *s);
 int    SSL_set_cipher_list(SSL *s, char *str);
 void   SSL_set_read_ahead(SSL *s, int yes);
 int    SSL_get_verify_mode(SSL *s);
+int    SSL_get_verify_depth(SSL *s);
 int    (*SSL_get_verify_callback(SSL *s))(int,X509_STORE_CTX *);
 void   SSL_set_verify(SSL *s, int mode,
                       int (*callback)(int ok,X509_STORE_CTX *ctx));
+void   SSL_set_verify_depth(SSL *s, int depth);
 #ifndef NO_RSA
 int    SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa);
 #endif
@@ -864,16 +890,17 @@ int       SSL_use_certificate(SSL *ssl, X509 *x);
 int    SSL_use_certificate_ASN1(SSL *ssl, unsigned char *d, int len);
 
 #ifndef NO_STDIO
-int    SSL_use_RSAPrivateKey_file(SSL *ssl, char *file, int type);
-int    SSL_use_PrivateKey_file(SSL *ssl, char *file, int type);
-int    SSL_use_certificate_file(SSL *ssl, char *file, int type);
-int    SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, char *file, int type);
-int    SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, char *file, int type);
-int    SSL_CTX_use_certificate_file(SSL_CTX *ctx, char *file, int type);
+int    SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type);
+int    SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type);
+int    SSL_use_certificate_file(SSL *ssl, const char *file, int type);
+int    SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file, int type);
+int    SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type);
+int    SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type);
+int    SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file); /* PEM type */
 STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file);
-int    SSL_add_file_cert_subjects_to_stack(STACK *stackCAs,
+int    SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs,
                                            const char *file);
-int    SSL_add_dir_cert_subjects_to_stack(STACK *stackCAs,
+int    SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs,
                                           const char *dir);
 #endif
 
@@ -912,10 +939,12 @@ X509 *    SSL_get_peer_certificate(SSL *s);
 STACK_OF(X509) *SSL_get_peer_cert_chain(SSL *s);
 
 int SSL_CTX_get_verify_mode(SSL_CTX *ctx);
+int SSL_CTX_get_verify_depth(SSL_CTX *ctx);
 int (*SSL_CTX_get_verify_callback(SSL_CTX *ctx))(int,X509_STORE_CTX *);
 void SSL_CTX_set_verify(SSL_CTX *ctx,int mode,
                        int (*callback)(int, X509_STORE_CTX *));
-void SSL_CTX_set_cert_verify_cb(SSL_CTX *ctx, int (*cb)(),char *arg);
+void SSL_CTX_set_verify_depth(SSL_CTX *ctx,int depth);
+void SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx, int (*cb)(),char *arg);
 #ifndef NO_RSA
 int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa);
 #endif
@@ -926,7 +955,7 @@ int SSL_CTX_use_PrivateKey_ASN1(int pk,SSL_CTX *ctx,
 int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x);
 int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, unsigned char *d);
 
-void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx,int (*cb)());
+void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *);
 
 int SSL_CTX_check_private_key(SSL_CTX *ctx);
 int SSL_check_private_key(SSL *ctx);
@@ -1011,7 +1040,8 @@ void SSL_set_shutdown(SSL *ssl,int mode);
 int SSL_get_shutdown(SSL *ssl);
 int SSL_version(SSL *ssl);
 int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx);
-int SSL_CTX_load_verify_locations(SSL_CTX *ctx,char *CAfile,char *CApath);
+int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile,
+       const char *CApath);
 SSL_SESSION *SSL_get_session(SSL *ssl);
 SSL_CTX *SSL_get_SSL_CTX(SSL *ssl);
 void SSL_set_info_callback(SSL *ssl,void (*cb)());
@@ -1150,6 +1180,8 @@ int SSL_COMP_add_compression_method(int id,char *cm);
 #define SSL_F_SSL_ADD_FILE_CERT_SUBJECTS_TO_STACK       216
 #define SSL_F_SSL_BAD_METHOD                            160
 #define SSL_F_SSL_BYTES_TO_CIPHER_LIST                  161
+#define SSL_F_SSL_CERT_DUP                              221
+#define SSL_F_SSL_CERT_INST                             222
 #define SSL_F_SSL_CERT_INSTANTIATE                      214
 #define SSL_F_SSL_CERT_NEW                              162
 #define SSL_F_SSL_CHECK_PRIVATE_KEY                     163
@@ -1162,6 +1194,7 @@ int SSL_COMP_add_compression_method(int id,char *cm);
 #define SSL_F_SSL_CTX_SET_SSL_VERSION                   170
 #define SSL_F_SSL_CTX_USE_CERTIFICATE                   171
 #define SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1              172
+#define SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE        220
 #define SSL_F_SSL_CTX_USE_CERTIFICATE_FILE              173
 #define SSL_F_SSL_CTX_USE_PRIVATEKEY                    174
 #define SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1               175
@@ -1177,10 +1210,12 @@ int SSL_COMP_add_compression_method(int id,char *cm);
 #define SSL_F_SSL_INIT_WBIO_BUFFER                      184
 #define SSL_F_SSL_LOAD_CLIENT_CA_FILE                   185
 #define SSL_F_SSL_NEW                                   186
+#define SSL_F_SSL_READ                                  223
 #define SSL_F_SSL_RSA_PRIVATE_DECRYPT                   187
 #define SSL_F_SSL_RSA_PUBLIC_ENCRYPT                    188
 #define SSL_F_SSL_SESSION_NEW                           189
 #define SSL_F_SSL_SESSION_PRINT_FP                      190
+#define SSL_F_SSL_SESS_CERT_NEW                                 225
 #define SSL_F_SSL_SET_CERT                              191
 #define SSL_F_SSL_SET_FD                                192
 #define SSL_F_SSL_SET_PKEY                              193
@@ -1188,6 +1223,7 @@ int SSL_COMP_add_compression_method(int id,char *cm);
 #define SSL_F_SSL_SET_SESSION                           195
 #define SSL_F_SSL_SET_SESSION_ID_CONTEXT                218
 #define SSL_F_SSL_SET_WFD                               196
+#define SSL_F_SSL_SHUTDOWN                              224
 #define SSL_F_SSL_UNDEFINED_FUNCTION                    197
 #define SSL_F_SSL_USE_CERTIFICATE                       198
 #define SSL_F_SSL_USE_CERTIFICATE_ASN1                  199
@@ -1269,6 +1305,7 @@ int SSL_COMP_add_compression_method(int id,char *cm);
 #define SSL_R_INVALID_CHALLENGE_LENGTH                  158
 #define SSL_R_LENGTH_MISMATCH                           159
 #define SSL_R_LENGTH_TOO_SHORT                          160
+#define SSL_R_LIBRARY_BUG                               274
 #define SSL_R_LIBRARY_HAS_NO_CIPHERS                    161
 #define SSL_R_MISSING_DH_DSA_CERT                       162
 #define SSL_R_MISSING_DH_KEY                            163
@@ -1328,6 +1365,7 @@ int SSL_COMP_add_compression_method(int id,char *cm);
 #define SSL_R_REUSE_CERT_LENGTH_NOT_ZERO                216
 #define SSL_R_REUSE_CERT_TYPE_NOT_ZERO                  217
 #define SSL_R_REUSE_CIPHER_LIST_NOT_ZERO                218
+#define SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED          277
 #define SSL_R_SHORT_READ                                219
 #define SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE     220
 #define SSL_R_SSL23_DOING_SESSION_ID_REUSE              221
@@ -1379,6 +1417,7 @@ int SSL_COMP_add_compression_method(int id,char *cm);
 #define SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES                 243
 #define SSL_R_UNEXPECTED_MESSAGE                        244
 #define SSL_R_UNEXPECTED_RECORD                                 245
+#define SSL_R_UNINITIALIZED                             276
 #define SSL_R_UNKNOWN_ALERT_TYPE                        246
 #define SSL_R_UNKNOWN_CERTIFICATE_TYPE                  247
 #define SSL_R_UNKNOWN_CIPHER_RETURNED                   248