155714Skris/* ssl/ssl2.h */ 255714Skris/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 355714Skris * All rights reserved. 455714Skris * 555714Skris * This package is an SSL implementation written 655714Skris * by Eric Young (eay@cryptsoft.com). 755714Skris * The implementation was written so as to conform with Netscapes SSL. 8280297Sjkim * 955714Skris * This library is free for commercial and non-commercial use as long as 1055714Skris * the following conditions are aheared to. The following conditions 1155714Skris * apply to all code found in this distribution, be it the RC4, RSA, 1255714Skris * lhash, DES, etc., code; not just the SSL code. The SSL documentation 1355714Skris * included with this distribution is covered by the same copyright terms 1455714Skris * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15280297Sjkim * 1655714Skris * Copyright remains Eric Young's, and as such any Copyright notices in 1755714Skris * the code are not to be removed. 1855714Skris * If this package is used in a product, Eric Young should be given attribution 1955714Skris * as the author of the parts of the library used. 2055714Skris * This can be in the form of a textual message at program startup or 2155714Skris * in documentation (online or textual) provided with the package. 22280297Sjkim * 2355714Skris * Redistribution and use in source and binary forms, with or without 2455714Skris * modification, are permitted provided that the following conditions 2555714Skris * are met: 2655714Skris * 1. Redistributions of source code must retain the copyright 2755714Skris * notice, this list of conditions and the following disclaimer. 2855714Skris * 2. Redistributions in binary form must reproduce the above copyright 2955714Skris * notice, this list of conditions and the following disclaimer in the 3055714Skris * documentation and/or other materials provided with the distribution. 3155714Skris * 3. All advertising materials mentioning features or use of this software 3255714Skris * must display the following acknowledgement: 3355714Skris * "This product includes cryptographic software written by 3455714Skris * Eric Young (eay@cryptsoft.com)" 3555714Skris * The word 'cryptographic' can be left out if the rouines from the library 3655714Skris * being used are not cryptographic related :-). 37280297Sjkim * 4. If you include any Windows specific code (or a derivative thereof) from 3855714Skris * the apps directory (application code) you must include an acknowledgement: 3955714Skris * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40280297Sjkim * 4155714Skris * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 4255714Skris * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 4355714Skris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 4455714Skris * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 4555714Skris * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 4655714Skris * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 4755714Skris * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 4855714Skris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 4955714Skris * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 5055714Skris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 5155714Skris * SUCH DAMAGE. 52280297Sjkim * 5355714Skris * The licence and distribution terms for any publically available version or 5455714Skris * derivative of this code cannot be changed. i.e. this code cannot simply be 5555714Skris * copied and put under another distribution licence 5655714Skris * [including the GNU Public Licence.] 5755714Skris */ 5855714Skris 59280297Sjkim#ifndef HEADER_SSL2_H 60280297Sjkim# define HEADER_SSL2_H 6155714Skris 6255714Skris#ifdef __cplusplus 6355714Skrisextern "C" { 6455714Skris#endif 6555714Skris 6655714Skris/* Protocol Version Codes */ 67280297Sjkim# define SSL2_VERSION 0x0002 68280297Sjkim# define SSL2_VERSION_MAJOR 0x00 69280297Sjkim# define SSL2_VERSION_MINOR 0x02 70280297Sjkim/* #define SSL2_CLIENT_VERSION 0x0002 */ 71280297Sjkim/* #define SSL2_SERVER_VERSION 0x0002 */ 7255714Skris 7355714Skris/* Protocol Message Codes */ 74280297Sjkim# define SSL2_MT_ERROR 0 75280297Sjkim# define SSL2_MT_CLIENT_HELLO 1 76280297Sjkim# define SSL2_MT_CLIENT_MASTER_KEY 2 77280297Sjkim# define SSL2_MT_CLIENT_FINISHED 3 78280297Sjkim# define SSL2_MT_SERVER_HELLO 4 79280297Sjkim# define SSL2_MT_SERVER_VERIFY 5 80280297Sjkim# define SSL2_MT_SERVER_FINISHED 6 81280297Sjkim# define SSL2_MT_REQUEST_CERTIFICATE 7 82280297Sjkim# define SSL2_MT_CLIENT_CERTIFICATE 8 8355714Skris 8455714Skris/* Error Message Codes */ 85280297Sjkim# define SSL2_PE_UNDEFINED_ERROR 0x0000 86280297Sjkim# define SSL2_PE_NO_CIPHER 0x0001 87280297Sjkim# define SSL2_PE_NO_CERTIFICATE 0x0002 88280297Sjkim# define SSL2_PE_BAD_CERTIFICATE 0x0004 89280297Sjkim# define SSL2_PE_UNSUPPORTED_CERTIFICATE_TYPE 0x0006 9055714Skris 9155714Skris/* Cipher Kind Values */ 92280297Sjkim# define SSL2_CK_NULL_WITH_MD5 0x02000000/* v3 */ 93280297Sjkim# define SSL2_CK_RC4_128_WITH_MD5 0x02010080 94280297Sjkim# define SSL2_CK_RC4_128_EXPORT40_WITH_MD5 0x02020080 95280297Sjkim# define SSL2_CK_RC2_128_CBC_WITH_MD5 0x02030080 96280297Sjkim# define SSL2_CK_RC2_128_CBC_EXPORT40_WITH_MD5 0x02040080 97280297Sjkim# define SSL2_CK_IDEA_128_CBC_WITH_MD5 0x02050080 98280297Sjkim# define SSL2_CK_DES_64_CBC_WITH_MD5 0x02060040 99280297Sjkim# define SSL2_CK_DES_64_CBC_WITH_SHA 0x02060140/* v3 */ 100280297Sjkim# define SSL2_CK_DES_192_EDE3_CBC_WITH_MD5 0x020700c0 101280297Sjkim# define SSL2_CK_DES_192_EDE3_CBC_WITH_SHA 0x020701c0/* v3 */ 102280297Sjkim# define SSL2_CK_RC4_64_WITH_MD5 0x02080080/* MS hack */ 10355714Skris 104280297Sjkim# define SSL2_CK_DES_64_CFB64_WITH_MD5_1 0x02ff0800/* SSLeay */ 105280297Sjkim# define SSL2_CK_NULL 0x02ff0810/* SSLeay */ 10655714Skris 107280297Sjkim# define SSL2_TXT_DES_64_CFB64_WITH_MD5_1 "DES-CFB-M1" 108280297Sjkim# define SSL2_TXT_NULL_WITH_MD5 "NULL-MD5" 109280297Sjkim# define SSL2_TXT_RC4_128_WITH_MD5 "RC4-MD5" 110280297Sjkim# define SSL2_TXT_RC4_128_EXPORT40_WITH_MD5 "EXP-RC4-MD5" 111280297Sjkim# define SSL2_TXT_RC2_128_CBC_WITH_MD5 "RC2-CBC-MD5" 112280297Sjkim# define SSL2_TXT_RC2_128_CBC_EXPORT40_WITH_MD5 "EXP-RC2-CBC-MD5" 113280297Sjkim# define SSL2_TXT_IDEA_128_CBC_WITH_MD5 "IDEA-CBC-MD5" 114280297Sjkim# define SSL2_TXT_DES_64_CBC_WITH_MD5 "DES-CBC-MD5" 115280297Sjkim# define SSL2_TXT_DES_64_CBC_WITH_SHA "DES-CBC-SHA" 116280297Sjkim# define SSL2_TXT_DES_192_EDE3_CBC_WITH_MD5 "DES-CBC3-MD5" 117280297Sjkim# define SSL2_TXT_DES_192_EDE3_CBC_WITH_SHA "DES-CBC3-SHA" 118280297Sjkim# define SSL2_TXT_RC4_64_WITH_MD5 "RC4-64-MD5" 11955714Skris 120280297Sjkim# define SSL2_TXT_NULL "NULL" 121280297Sjkim 12255714Skris/* Flags for the SSL_CIPHER.algorithm2 field */ 123280297Sjkim# define SSL2_CF_5_BYTE_ENC 0x01 124280297Sjkim# define SSL2_CF_8_BYTE_ENC 0x02 12555714Skris 12655714Skris/* Certificate Type Codes */ 127280297Sjkim# define SSL2_CT_X509_CERTIFICATE 0x01 12855714Skris 12955714Skris/* Authentication Type Code */ 130280297Sjkim# define SSL2_AT_MD5_WITH_RSA_ENCRYPTION 0x01 13155714Skris 132280297Sjkim# define SSL2_MAX_SSL_SESSION_ID_LENGTH 32 13355714Skris 13455714Skris/* Upper/Lower Bounds */ 135280297Sjkim# define SSL2_MAX_MASTER_KEY_LENGTH_IN_BITS 256 136280297Sjkim# ifdef OPENSSL_SYS_MPE 137280297Sjkim# define SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER 29998u 138280297Sjkim# else 139280297Sjkim# define SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER 32767u 140280297Sjkim /* 2^15-1 */ 141280297Sjkim# endif 142280297Sjkim# define SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER 16383/* 2^14-1 */ 14355714Skris 144280297Sjkim# define SSL2_CHALLENGE_LENGTH 16 145280297Sjkim/* 146280297Sjkim * #define SSL2_CHALLENGE_LENGTH 32 147280297Sjkim */ 148280297Sjkim# define SSL2_MIN_CHALLENGE_LENGTH 16 149280297Sjkim# define SSL2_MAX_CHALLENGE_LENGTH 32 150280297Sjkim# define SSL2_CONNECTION_ID_LENGTH 16 151280297Sjkim# define SSL2_MAX_CONNECTION_ID_LENGTH 16 152280297Sjkim# define SSL2_SSL_SESSION_ID_LENGTH 16 153280297Sjkim# define SSL2_MAX_CERT_CHALLENGE_LENGTH 32 154280297Sjkim# define SSL2_MIN_CERT_CHALLENGE_LENGTH 16 155280297Sjkim# define SSL2_MAX_KEY_MATERIAL_LENGTH 24 15655714Skris 157280297Sjkim# ifndef HEADER_SSL_LOCL_H 158280297Sjkim# define CERT char 159280297Sjkim# endif 16055714Skris 161280297Sjkim# ifndef OPENSSL_NO_SSL_INTERN 162238405Sjkim 163280297Sjkimtypedef struct ssl2_state_st { 164280297Sjkim int three_byte_header; 165280297Sjkim int clear_text; /* clear text */ 166280297Sjkim int escape; /* not used in SSLv2 */ 167280297Sjkim int ssl2_rollback; /* used if SSLv23 rolled back to SSLv2 */ 168280297Sjkim /* 169280297Sjkim * non-blocking io info, used to make sure the same args were passwd 170280297Sjkim */ 171280297Sjkim unsigned int wnum; /* number of bytes sent so far */ 172280297Sjkim int wpend_tot; 173280297Sjkim const unsigned char *wpend_buf; 174280297Sjkim int wpend_off; /* offset to data to write */ 175280297Sjkim int wpend_len; /* number of bytes passwd to write */ 176280297Sjkim int wpend_ret; /* number of bytes to return to caller */ 177280297Sjkim /* buffer raw data */ 178280297Sjkim int rbuf_left; 179280297Sjkim int rbuf_offs; 180280297Sjkim unsigned char *rbuf; 181280297Sjkim unsigned char *wbuf; 182280297Sjkim unsigned char *write_ptr; /* used to point to the start due to 2/3 byte 183280297Sjkim * header. */ 184280297Sjkim unsigned int padding; 185280297Sjkim unsigned int rlength; /* passed to ssl2_enc */ 186280297Sjkim int ract_data_length; /* Set when things are encrypted. */ 187280297Sjkim unsigned int wlength; /* passed to ssl2_enc */ 188280297Sjkim int wact_data_length; /* Set when things are decrypted. */ 189280297Sjkim unsigned char *ract_data; 190280297Sjkim unsigned char *wact_data; 191280297Sjkim unsigned char *mac_data; 192280297Sjkim unsigned char *read_key; 193280297Sjkim unsigned char *write_key; 194280297Sjkim /* Stuff specifically to do with this SSL session */ 195280297Sjkim unsigned int challenge_length; 196280297Sjkim unsigned char challenge[SSL2_MAX_CHALLENGE_LENGTH]; 197280297Sjkim unsigned int conn_id_length; 198280297Sjkim unsigned char conn_id[SSL2_MAX_CONNECTION_ID_LENGTH]; 199280297Sjkim unsigned int key_material_length; 200280297Sjkim unsigned char key_material[SSL2_MAX_KEY_MATERIAL_LENGTH * 2]; 201280297Sjkim unsigned long read_sequence; 202280297Sjkim unsigned long write_sequence; 203280297Sjkim struct { 204280297Sjkim unsigned int conn_id_length; 205280297Sjkim unsigned int cert_type; 206280297Sjkim unsigned int cert_length; 207280297Sjkim unsigned int csl; 208280297Sjkim unsigned int clear; 209280297Sjkim unsigned int enc; 210280297Sjkim unsigned char ccl[SSL2_MAX_CERT_CHALLENGE_LENGTH]; 211280297Sjkim unsigned int cipher_spec_length; 212280297Sjkim unsigned int session_id_length; 213280297Sjkim unsigned int clen; 214280297Sjkim unsigned int rlen; 215280297Sjkim } tmp; 216280297Sjkim} SSL2_STATE; 21755714Skris 218280297Sjkim# endif 21955714Skris 22055714Skris/* SSLv2 */ 22155714Skris/* client */ 222280297Sjkim# define SSL2_ST_SEND_CLIENT_HELLO_A (0x10|SSL_ST_CONNECT) 223280297Sjkim# define SSL2_ST_SEND_CLIENT_HELLO_B (0x11|SSL_ST_CONNECT) 224280297Sjkim# define SSL2_ST_GET_SERVER_HELLO_A (0x20|SSL_ST_CONNECT) 225280297Sjkim# define SSL2_ST_GET_SERVER_HELLO_B (0x21|SSL_ST_CONNECT) 226280297Sjkim# define SSL2_ST_SEND_CLIENT_MASTER_KEY_A (0x30|SSL_ST_CONNECT) 227280297Sjkim# define SSL2_ST_SEND_CLIENT_MASTER_KEY_B (0x31|SSL_ST_CONNECT) 228280297Sjkim# define SSL2_ST_SEND_CLIENT_FINISHED_A (0x40|SSL_ST_CONNECT) 229280297Sjkim# define SSL2_ST_SEND_CLIENT_FINISHED_B (0x41|SSL_ST_CONNECT) 230280297Sjkim# define SSL2_ST_SEND_CLIENT_CERTIFICATE_A (0x50|SSL_ST_CONNECT) 231280297Sjkim# define SSL2_ST_SEND_CLIENT_CERTIFICATE_B (0x51|SSL_ST_CONNECT) 232280297Sjkim# define SSL2_ST_SEND_CLIENT_CERTIFICATE_C (0x52|SSL_ST_CONNECT) 233280297Sjkim# define SSL2_ST_SEND_CLIENT_CERTIFICATE_D (0x53|SSL_ST_CONNECT) 234280297Sjkim# define SSL2_ST_GET_SERVER_VERIFY_A (0x60|SSL_ST_CONNECT) 235280297Sjkim# define SSL2_ST_GET_SERVER_VERIFY_B (0x61|SSL_ST_CONNECT) 236280297Sjkim# define SSL2_ST_GET_SERVER_FINISHED_A (0x70|SSL_ST_CONNECT) 237280297Sjkim# define SSL2_ST_GET_SERVER_FINISHED_B (0x71|SSL_ST_CONNECT) 238280297Sjkim# define SSL2_ST_CLIENT_START_ENCRYPTION (0x80|SSL_ST_CONNECT) 239280297Sjkim# define SSL2_ST_X509_GET_CLIENT_CERTIFICATE (0x90|SSL_ST_CONNECT) 24055714Skris/* server */ 241280297Sjkim# define SSL2_ST_GET_CLIENT_HELLO_A (0x10|SSL_ST_ACCEPT) 242280297Sjkim# define SSL2_ST_GET_CLIENT_HELLO_B (0x11|SSL_ST_ACCEPT) 243280297Sjkim# define SSL2_ST_GET_CLIENT_HELLO_C (0x12|SSL_ST_ACCEPT) 244280297Sjkim# define SSL2_ST_SEND_SERVER_HELLO_A (0x20|SSL_ST_ACCEPT) 245280297Sjkim# define SSL2_ST_SEND_SERVER_HELLO_B (0x21|SSL_ST_ACCEPT) 246280297Sjkim# define SSL2_ST_GET_CLIENT_MASTER_KEY_A (0x30|SSL_ST_ACCEPT) 247280297Sjkim# define SSL2_ST_GET_CLIENT_MASTER_KEY_B (0x31|SSL_ST_ACCEPT) 248280297Sjkim# define SSL2_ST_SEND_SERVER_VERIFY_A (0x40|SSL_ST_ACCEPT) 249280297Sjkim# define SSL2_ST_SEND_SERVER_VERIFY_B (0x41|SSL_ST_ACCEPT) 250280297Sjkim# define SSL2_ST_SEND_SERVER_VERIFY_C (0x42|SSL_ST_ACCEPT) 251280297Sjkim# define SSL2_ST_GET_CLIENT_FINISHED_A (0x50|SSL_ST_ACCEPT) 252280297Sjkim# define SSL2_ST_GET_CLIENT_FINISHED_B (0x51|SSL_ST_ACCEPT) 253280297Sjkim# define SSL2_ST_SEND_SERVER_FINISHED_A (0x60|SSL_ST_ACCEPT) 254280297Sjkim# define SSL2_ST_SEND_SERVER_FINISHED_B (0x61|SSL_ST_ACCEPT) 255280297Sjkim# define SSL2_ST_SEND_REQUEST_CERTIFICATE_A (0x70|SSL_ST_ACCEPT) 256280297Sjkim# define SSL2_ST_SEND_REQUEST_CERTIFICATE_B (0x71|SSL_ST_ACCEPT) 257280297Sjkim# define SSL2_ST_SEND_REQUEST_CERTIFICATE_C (0x72|SSL_ST_ACCEPT) 258280297Sjkim# define SSL2_ST_SEND_REQUEST_CERTIFICATE_D (0x73|SSL_ST_ACCEPT) 259280297Sjkim# define SSL2_ST_SERVER_START_ENCRYPTION (0x80|SSL_ST_ACCEPT) 260280297Sjkim# define SSL2_ST_X509_GET_SERVER_CERTIFICATE (0x90|SSL_ST_ACCEPT) 26155714Skris 26255714Skris#ifdef __cplusplus 26355714Skris} 26455714Skris#endif 26555714Skris#endif 266