ssl2.h

Go to the documentation of this file.
00001 /* ssl/ssl2.h */
00002 /* Copyright (C) 1995-1998 Eric Young ([email protected])
00003  * All rights reserved.
00004  *
00005  * This package is an SSL implementation written
00006  * by Eric Young ([email protected]).
00007  * The implementation was written so as to conform with Netscapes SSL.
00008  * 
00009  * This library is free for commercial and non-commercial use as long as
00010  * the following conditions are aheared to.  The following conditions
00011  * apply to all code found in this distribution, be it the RC4, RSA,
00012  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
00013  * included with this distribution is covered by the same copyright terms
00014  * except that the holder is Tim Hudson ([email protected]).
00015  * 
00016  * Copyright remains Eric Young's, and as such any Copyright notices in
00017  * the code are not to be removed.
00018  * If this package is used in a product, Eric Young should be given attribution
00019  * as the author of the parts of the library used.
00020  * This can be in the form of a textual message at program startup or
00021  * in documentation (online or textual) provided with the package.
00022  * 
00023  * Redistribution and use in source and binary forms, with or without
00024  * modification, are permitted provided that the following conditions
00025  * are met:
00026  * 1. Redistributions of source code must retain the copyright
00027  *    notice, this list of conditions and the following disclaimer.
00028  * 2. Redistributions in binary form must reproduce the above copyright
00029  *    notice, this list of conditions and the following disclaimer in the
00030  *    documentation and/or other materials provided with the distribution.
00031  * 3. All advertising materials mentioning features or use of this software
00032  *    must display the following acknowledgement:
00033  *    "This product includes cryptographic software written by
00034  *     Eric Young ([email protected])"
00035  *    The word 'cryptographic' can be left out if the rouines from the library
00036  *    being used are not cryptographic related :-).
00037  * 4. If you include any Windows specific code (or a derivative thereof) from 
00038  *    the apps directory (application code) you must include an acknowledgement:
00039  *    "This product includes software written by Tim Hudson ([email protected])"
00040  * 
00041  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
00042  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00043  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00044  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
00045  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00046  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00047  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00048  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00049  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00050  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00051  * SUCH DAMAGE.
00052  * 
00053  * The licence and distribution terms for any publically available version or
00054  * derivative of this code cannot be changed.  i.e. this code cannot simply be
00055  * copied and put under another distribution licence
00056  * [including the GNU Public Licence.]
00057  */
00058 
00059 #ifndef HEADER_SSL2_H 
00060 #define HEADER_SSL2_H 
00061 
00062 #if (defined(__SYMBIAN32__) && !defined(SYMBIAN))
00063 #define SYMBIAN
00064 #endif
00065 
00066 #ifdef  __cplusplus
00067 extern "C" {
00068 #endif
00069 
00070 /* Protocol Version Codes */
00071 #define SSL2_VERSION            0x0002
00072 #define SSL2_VERSION_MAJOR      0x00
00073 #define SSL2_VERSION_MINOR      0x02
00074 /* #define SSL2_CLIENT_VERSION  0x0002 */
00075 /* #define SSL2_SERVER_VERSION  0x0002 */
00076 
00077 /* Protocol Message Codes */
00078 #define SSL2_MT_ERROR                   0
00079 #define SSL2_MT_CLIENT_HELLO            1
00080 #define SSL2_MT_CLIENT_MASTER_KEY       2
00081 #define SSL2_MT_CLIENT_FINISHED         3
00082 #define SSL2_MT_SERVER_HELLO            4
00083 #define SSL2_MT_SERVER_VERIFY           5
00084 #define SSL2_MT_SERVER_FINISHED         6
00085 #define SSL2_MT_REQUEST_CERTIFICATE     7
00086 #define SSL2_MT_CLIENT_CERTIFICATE      8
00087 
00088 /* Error Message Codes */
00089 #define SSL2_PE_UNDEFINED_ERROR         0x0000
00090 #define SSL2_PE_NO_CIPHER               0x0001
00091 #define SSL2_PE_NO_CERTIFICATE          0x0002
00092 #define SSL2_PE_BAD_CERTIFICATE         0x0004
00093 #define SSL2_PE_UNSUPPORTED_CERTIFICATE_TYPE 0x0006
00094 
00095 /* Cipher Kind Values */
00096 #define SSL2_CK_NULL_WITH_MD5                   0x02000000 /* v3 */
00097 #define SSL2_CK_RC4_128_WITH_MD5                0x02010080
00098 #define SSL2_CK_RC4_128_EXPORT40_WITH_MD5       0x02020080
00099 #define SSL2_CK_RC2_128_CBC_WITH_MD5            0x02030080
00100 #define SSL2_CK_RC2_128_CBC_EXPORT40_WITH_MD5   0x02040080
00101 #define SSL2_CK_IDEA_128_CBC_WITH_MD5           0x02050080
00102 #define SSL2_CK_DES_64_CBC_WITH_MD5             0x02060040
00103 #define SSL2_CK_DES_64_CBC_WITH_SHA             0x02060140 /* v3 */
00104 #define SSL2_CK_DES_192_EDE3_CBC_WITH_MD5       0x020700c0
00105 #define SSL2_CK_DES_192_EDE3_CBC_WITH_SHA       0x020701c0 /* v3 */
00106 #define SSL2_CK_RC4_64_WITH_MD5                 0x02080080 /* MS hack */
00107  
00108 #define SSL2_CK_DES_64_CFB64_WITH_MD5_1         0x02ff0800 /* SSLeay */
00109 #define SSL2_CK_NULL                            0x02ff0810 /* SSLeay */
00110 
00111 #define SSL2_TXT_DES_64_CFB64_WITH_MD5_1        "DES-CFB-M1"
00112 #define SSL2_TXT_NULL_WITH_MD5                  "NULL-MD5"
00113 #define SSL2_TXT_RC4_128_WITH_MD5               "RC4-MD5"
00114 #define SSL2_TXT_RC4_128_EXPORT40_WITH_MD5      "EXP-RC4-MD5"
00115 #define SSL2_TXT_RC2_128_CBC_WITH_MD5           "RC2-CBC-MD5"
00116 #define SSL2_TXT_RC2_128_CBC_EXPORT40_WITH_MD5  "EXP-RC2-CBC-MD5"
00117 #define SSL2_TXT_IDEA_128_CBC_WITH_MD5          "IDEA-CBC-MD5"
00118 #define SSL2_TXT_DES_64_CBC_WITH_MD5            "DES-CBC-MD5"
00119 #define SSL2_TXT_DES_64_CBC_WITH_SHA            "DES-CBC-SHA"
00120 #define SSL2_TXT_DES_192_EDE3_CBC_WITH_MD5      "DES-CBC3-MD5"
00121 #define SSL2_TXT_DES_192_EDE3_CBC_WITH_SHA      "DES-CBC3-SHA"
00122 #define SSL2_TXT_RC4_64_WITH_MD5                "RC4-64-MD5"
00123 
00124 #define SSL2_TXT_NULL                           "NULL"
00125 
00126 /* Flags for the SSL_CIPHER.algorithm2 field */
00127 #define SSL2_CF_5_BYTE_ENC                      0x01
00128 #define SSL2_CF_8_BYTE_ENC                      0x02
00129 
00130 /* Certificate Type Codes */
00131 #define SSL2_CT_X509_CERTIFICATE                0x01
00132 
00133 /* Authentication Type Code */
00134 #define SSL2_AT_MD5_WITH_RSA_ENCRYPTION         0x01
00135 
00136 #define SSL2_MAX_SSL_SESSION_ID_LENGTH          32
00137 
00138 /* Upper/Lower Bounds */
00139 #define SSL2_MAX_MASTER_KEY_LENGTH_IN_BITS      256
00140 #ifdef OPENSSL_SYS_MPE
00141 #define SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER    29998u
00142 #else
00143 #define SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER    32767u  /* 2^15-1 */
00144 #endif
00145 #define SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER    16383 /* 2^14-1 */
00146 
00147 #define SSL2_CHALLENGE_LENGTH   16
00148 /*#define SSL2_CHALLENGE_LENGTH 32 */
00149 #define SSL2_MIN_CHALLENGE_LENGTH       16
00150 #define SSL2_MAX_CHALLENGE_LENGTH       32
00151 #define SSL2_CONNECTION_ID_LENGTH       16
00152 #define SSL2_MAX_CONNECTION_ID_LENGTH   16
00153 #define SSL2_SSL_SESSION_ID_LENGTH      16
00154 #define SSL2_MAX_CERT_CHALLENGE_LENGTH  32
00155 #define SSL2_MIN_CERT_CHALLENGE_LENGTH  16
00156 #define SSL2_MAX_KEY_MATERIAL_LENGTH    24
00157 
00158 #ifndef HEADER_SSL_LOCL_H
00159 #define  CERT           char
00160 #endif
00161 
00162 typedef struct ssl2_state_st
00163         {
00164         int three_byte_header;
00165         int clear_text;         /* clear text */
00166         int escape;             /* not used in SSLv2 */
00167         int ssl2_rollback;      /* used if SSLv23 rolled back to SSLv2 */
00168 
00169         /* non-blocking io info, used to make sure the same
00170          * args were passwd */
00171         unsigned int wnum;      /* number of bytes sent so far */
00172         int wpend_tot;
00173         const unsigned char *wpend_buf;
00174 
00175         int wpend_off;  /* offset to data to write */
00176         int wpend_len;  /* number of bytes passwd to write */
00177         int wpend_ret;  /* number of bytes to return to caller */
00178 
00179         /* buffer raw data */
00180         int rbuf_left;
00181         int rbuf_offs;
00182         unsigned char *rbuf;
00183         unsigned char *wbuf;
00184 
00185         unsigned char *write_ptr;/* used to point to the start due to
00186                                   * 2/3 byte header. */
00187 
00188         unsigned int padding;
00189         unsigned int rlength; /* passed to ssl2_enc */
00190         int ract_data_length; /* Set when things are encrypted. */
00191         unsigned int wlength; /* passed to ssl2_enc */
00192         int wact_data_length; /* Set when things are decrypted. */
00193         unsigned char *ract_data;
00194         unsigned char *wact_data;
00195         unsigned char *mac_data;
00196 
00197         unsigned char *read_key;
00198         unsigned char *write_key;
00199 
00200                 /* Stuff specifically to do with this SSL session */
00201         unsigned int challenge_length;
00202         unsigned char challenge[SSL2_MAX_CHALLENGE_LENGTH];
00203         unsigned int conn_id_length;
00204         unsigned char conn_id[SSL2_MAX_CONNECTION_ID_LENGTH];
00205         unsigned int key_material_length;
00206         unsigned char key_material[SSL2_MAX_KEY_MATERIAL_LENGTH*2];
00207 
00208         unsigned long read_sequence;
00209         unsigned long write_sequence;
00210 
00211         struct  {
00212                 unsigned int conn_id_length;
00213                 unsigned int cert_type; 
00214                 unsigned int cert_length;
00215                 unsigned int csl; 
00216                 unsigned int clear;
00217                 unsigned int enc; 
00218                 unsigned char ccl[SSL2_MAX_CERT_CHALLENGE_LENGTH];
00219                 unsigned int cipher_spec_length;
00220                 unsigned int session_id_length;
00221                 unsigned int clen;
00222                 unsigned int rlen;
00223                 } tmp;
00224         } SSL2_STATE;
00225 
00226 /* SSLv2 */
00227 /* client */
00228 #define SSL2_ST_SEND_CLIENT_HELLO_A             (0x10|SSL_ST_CONNECT)
00229 #define SSL2_ST_SEND_CLIENT_HELLO_B             (0x11|SSL_ST_CONNECT)
00230 #define SSL2_ST_GET_SERVER_HELLO_A              (0x20|SSL_ST_CONNECT)
00231 #define SSL2_ST_GET_SERVER_HELLO_B              (0x21|SSL_ST_CONNECT)
00232 #define SSL2_ST_SEND_CLIENT_MASTER_KEY_A        (0x30|SSL_ST_CONNECT)
00233 #define SSL2_ST_SEND_CLIENT_MASTER_KEY_B        (0x31|SSL_ST_CONNECT)
00234 #define SSL2_ST_SEND_CLIENT_FINISHED_A          (0x40|SSL_ST_CONNECT)
00235 #define SSL2_ST_SEND_CLIENT_FINISHED_B          (0x41|SSL_ST_CONNECT)
00236 #define SSL2_ST_SEND_CLIENT_CERTIFICATE_A       (0x50|SSL_ST_CONNECT)
00237 #define SSL2_ST_SEND_CLIENT_CERTIFICATE_B       (0x51|SSL_ST_CONNECT)
00238 #define SSL2_ST_SEND_CLIENT_CERTIFICATE_C       (0x52|SSL_ST_CONNECT)
00239 #define SSL2_ST_SEND_CLIENT_CERTIFICATE_D       (0x53|SSL_ST_CONNECT)
00240 #define SSL2_ST_GET_SERVER_VERIFY_A             (0x60|SSL_ST_CONNECT)
00241 #define SSL2_ST_GET_SERVER_VERIFY_B             (0x61|SSL_ST_CONNECT)
00242 #define SSL2_ST_GET_SERVER_FINISHED_A           (0x70|SSL_ST_CONNECT)
00243 #define SSL2_ST_GET_SERVER_FINISHED_B           (0x71|SSL_ST_CONNECT)
00244 #define SSL2_ST_CLIENT_START_ENCRYPTION         (0x80|SSL_ST_CONNECT)
00245 #define SSL2_ST_X509_GET_CLIENT_CERTIFICATE     (0x90|SSL_ST_CONNECT)
00246 /* server */
00247 #define SSL2_ST_GET_CLIENT_HELLO_A              (0x10|SSL_ST_ACCEPT)
00248 #define SSL2_ST_GET_CLIENT_HELLO_B              (0x11|SSL_ST_ACCEPT)
00249 #define SSL2_ST_GET_CLIENT_HELLO_C              (0x12|SSL_ST_ACCEPT)
00250 #define SSL2_ST_SEND_SERVER_HELLO_A             (0x20|SSL_ST_ACCEPT)
00251 #define SSL2_ST_SEND_SERVER_HELLO_B             (0x21|SSL_ST_ACCEPT)
00252 #define SSL2_ST_GET_CLIENT_MASTER_KEY_A         (0x30|SSL_ST_ACCEPT)
00253 #define SSL2_ST_GET_CLIENT_MASTER_KEY_B         (0x31|SSL_ST_ACCEPT)
00254 #define SSL2_ST_SEND_SERVER_VERIFY_A            (0x40|SSL_ST_ACCEPT)
00255 #define SSL2_ST_SEND_SERVER_VERIFY_B            (0x41|SSL_ST_ACCEPT)
00256 #define SSL2_ST_SEND_SERVER_VERIFY_C            (0x42|SSL_ST_ACCEPT)
00257 #define SSL2_ST_GET_CLIENT_FINISHED_A           (0x50|SSL_ST_ACCEPT)
00258 #define SSL2_ST_GET_CLIENT_FINISHED_B           (0x51|SSL_ST_ACCEPT)
00259 #define SSL2_ST_SEND_SERVER_FINISHED_A          (0x60|SSL_ST_ACCEPT)
00260 #define SSL2_ST_SEND_SERVER_FINISHED_B          (0x61|SSL_ST_ACCEPT)
00261 #define SSL2_ST_SEND_REQUEST_CERTIFICATE_A      (0x70|SSL_ST_ACCEPT)
00262 #define SSL2_ST_SEND_REQUEST_CERTIFICATE_B      (0x71|SSL_ST_ACCEPT)
00263 #define SSL2_ST_SEND_REQUEST_CERTIFICATE_C      (0x72|SSL_ST_ACCEPT)
00264 #define SSL2_ST_SEND_REQUEST_CERTIFICATE_D      (0x73|SSL_ST_ACCEPT)
00265 #define SSL2_ST_SERVER_START_ENCRYPTION         (0x80|SSL_ST_ACCEPT)
00266 #define SSL2_ST_X509_GET_SERVER_CERTIFICATE     (0x90|SSL_ST_ACCEPT)
00267 
00268 #ifdef  __cplusplus
00269 }
00270 #endif
00271 #endif
00272 

Copyright © Nokia Corporation 2001-2008
Back to top