00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef TLSV1_COMMON_H
00016 #define TLSV1_COMMON_H
00017
00018 #include "crypto/crypto.h"
00019
00020 #define TLS_VERSION 0x0301
00021 #define TLS_RANDOM_LEN 32
00022 #define TLS_PRE_MASTER_SECRET_LEN 48
00023 #define TLS_MASTER_SECRET_LEN 48
00024 #define TLS_SESSION_ID_MAX_LEN 32
00025 #define TLS_VERIFY_DATA_LEN 12
00026
00027
00028 enum {
00029 TLS_HANDSHAKE_TYPE_HELLO_REQUEST = 0,
00030 TLS_HANDSHAKE_TYPE_CLIENT_HELLO = 1,
00031 TLS_HANDSHAKE_TYPE_SERVER_HELLO = 2,
00032 TLS_HANDSHAKE_TYPE_NEW_SESSION_TICKET = 4 ,
00033 TLS_HANDSHAKE_TYPE_CERTIFICATE = 11,
00034 TLS_HANDSHAKE_TYPE_SERVER_KEY_EXCHANGE = 12,
00035 TLS_HANDSHAKE_TYPE_CERTIFICATE_REQUEST = 13,
00036 TLS_HANDSHAKE_TYPE_SERVER_HELLO_DONE = 14,
00037 TLS_HANDSHAKE_TYPE_CERTIFICATE_VERIFY = 15,
00038 TLS_HANDSHAKE_TYPE_CLIENT_KEY_EXCHANGE = 16,
00039 TLS_HANDSHAKE_TYPE_FINISHED = 20,
00040 TLS_HANDSHAKE_TYPE_CERTIFICATE_URL = 21 ,
00041 TLS_HANDSHAKE_TYPE_CERTIFICATE_STATUS = 22
00042 };
00043
00044
00045 #define TLS_NULL_WITH_NULL_NULL 0x0000
00046 #define TLS_RSA_WITH_NULL_MD5 0x0001
00047 #define TLS_RSA_WITH_NULL_SHA 0x0002
00048 #define TLS_RSA_EXPORT_WITH_RC4_40_MD5 0x0003
00049 #define TLS_RSA_WITH_RC4_128_MD5 0x0004
00050 #define TLS_RSA_WITH_RC4_128_SHA 0x0005
00051 #define TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5 0x0006
00052 #define TLS_RSA_WITH_IDEA_CBC_SHA 0x0007
00053 #define TLS_RSA_EXPORT_WITH_DES40_CBC_SHA 0x0008
00054 #define TLS_RSA_WITH_DES_CBC_SHA 0x0009
00055 #define TLS_RSA_WITH_3DES_EDE_CBC_SHA 0x000A
00056 #define TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA 0x000B
00057 #define TLS_DH_DSS_WITH_DES_CBC_SHA 0x000C
00058 #define TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA 0x000D
00059 #define TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA 0x000E
00060 #define TLS_DH_RSA_WITH_DES_CBC_SHA 0x000F
00061 #define TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA 0x0010
00062 #define TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA 0x0011
00063 #define TLS_DHE_DSS_WITH_DES_CBC_SHA 0x0012
00064 #define TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA 0x0013
00065 #define TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA 0x0014
00066 #define TLS_DHE_RSA_WITH_DES_CBC_SHA 0x0015
00067 #define TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA 0x0016
00068 #define TLS_DH_anon_EXPORT_WITH_RC4_40_MD5 0x0017
00069 #define TLS_DH_anon_WITH_RC4_128_MD5 0x0018
00070 #define TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA 0x0019
00071 #define TLS_DH_anon_WITH_DES_CBC_SHA 0x001A
00072 #define TLS_DH_anon_WITH_3DES_EDE_CBC_SHA 0x001B
00073 #define TLS_RSA_WITH_AES_128_CBC_SHA 0x002F
00074 #define TLS_DH_DSS_WITH_AES_128_CBC_SHA 0x0030
00075 #define TLS_DH_RSA_WITH_AES_128_CBC_SHA 0x0031
00076 #define TLS_DHE_DSS_WITH_AES_128_CBC_SHA 0x0032
00077 #define TLS_DHE_RSA_WITH_AES_128_CBC_SHA 0x0033
00078 #define TLS_DH_anon_WITH_AES_128_CBC_SHA 0x0034
00079 #define TLS_RSA_WITH_AES_256_CBC_SHA 0x0035
00080 #define TLS_DH_DSS_WITH_AES_256_CBC_SHA 0x0036
00081 #define TLS_DH_RSA_WITH_AES_256_CBC_SHA 0x0037
00082 #define TLS_DHE_DSS_WITH_AES_256_CBC_SHA 0x0038
00083 #define TLS_DHE_RSA_WITH_AES_256_CBC_SHA 0x0039
00084 #define TLS_DH_anon_WITH_AES_256_CBC_SHA 0x003A
00085
00086
00087 #define TLS_COMPRESSION_NULL 0
00088
00089
00090 #define TLS_ALERT_LEVEL_WARNING 1
00091 #define TLS_ALERT_LEVEL_FATAL 2
00092
00093
00094 #define TLS_ALERT_CLOSE_NOTIFY 0
00095 #define TLS_ALERT_UNEXPECTED_MESSAGE 10
00096 #define TLS_ALERT_BAD_RECORD_MAC 20
00097 #define TLS_ALERT_DECRYPTION_FAILED 21
00098 #define TLS_ALERT_RECORD_OVERFLOW 22
00099 #define TLS_ALERT_DECOMPRESSION_FAILURE 30
00100 #define TLS_ALERT_HANDSHAKE_FAILURE 40
00101 #define TLS_ALERT_BAD_CERTIFICATE 42
00102 #define TLS_ALERT_UNSUPPORTED_CERTIFICATE 43
00103 #define TLS_ALERT_CERTIFICATE_REVOKED 44
00104 #define TLS_ALERT_CERTIFICATE_EXPIRED 45
00105 #define TLS_ALERT_CERTIFICATE_UNKNOWN 46
00106 #define TLS_ALERT_ILLEGAL_PARAMETER 47
00107 #define TLS_ALERT_UNKNOWN_CA 48
00108 #define TLS_ALERT_ACCESS_DENIED 49
00109 #define TLS_ALERT_DECODE_ERROR 50
00110 #define TLS_ALERT_DECRYPT_ERROR 51
00111 #define TLS_ALERT_EXPORT_RESTRICTION 60
00112 #define TLS_ALERT_PROTOCOL_VERSION 70
00113 #define TLS_ALERT_INSUFFICIENT_SECURITY 71
00114 #define TLS_ALERT_INTERNAL_ERROR 80
00115 #define TLS_ALERT_USER_CANCELED 90
00116 #define TLS_ALERT_NO_RENEGOTIATION 100
00117 #define TLS_ALERT_UNSUPPORTED_EXTENSION 110
00118 #define TLS_ALERT_CERTIFICATE_UNOBTAINABLE 111
00119 #define TLS_ALERT_UNRECOGNIZED_NAME 112
00120 #define TLS_ALERT_BAD_CERTIFICATE_STATUS_RESPONSE 113
00121 #define TLS_ALERT_BAD_CERTIFICATE_HASH_VALUE 114
00122
00123
00124 enum {
00125 TLS_CHANGE_CIPHER_SPEC = 1
00126 };
00127
00128
00129 #define TLS_EXT_SERVER_NAME 0
00130 #define TLS_EXT_MAX_FRAGMENT_LENGTH 1
00131 #define TLS_EXT_CLIENT_CERTIFICATE_URL 2
00132 #define TLS_EXT_TRUSTED_CA_KEYS 3
00133 #define TLS_EXT_TRUNCATED_HMAC 4
00134 #define TLS_EXT_STATUS_REQUEST 5
00135 #define TLS_EXT_SESSION_TICKET 35
00136
00137 #define TLS_EXT_PAC_OPAQUE TLS_EXT_SESSION_TICKET
00138
00139
00140 typedef enum {
00141 TLS_KEY_X_NULL,
00142 TLS_KEY_X_RSA,
00143 TLS_KEY_X_RSA_EXPORT,
00144 TLS_KEY_X_DH_DSS_EXPORT,
00145 TLS_KEY_X_DH_DSS,
00146 TLS_KEY_X_DH_RSA_EXPORT,
00147 TLS_KEY_X_DH_RSA,
00148 TLS_KEY_X_DHE_DSS_EXPORT,
00149 TLS_KEY_X_DHE_DSS,
00150 TLS_KEY_X_DHE_RSA_EXPORT,
00151 TLS_KEY_X_DHE_RSA,
00152 TLS_KEY_X_DH_anon_EXPORT,
00153 TLS_KEY_X_DH_anon
00154 } tls_key_exchange;
00155
00156 typedef enum {
00157 TLS_CIPHER_NULL,
00158 TLS_CIPHER_RC4_40,
00159 TLS_CIPHER_RC4_128,
00160 TLS_CIPHER_RC2_CBC_40,
00161 TLS_CIPHER_IDEA_CBC,
00162 TLS_CIPHER_DES40_CBC,
00163 TLS_CIPHER_DES_CBC,
00164 TLS_CIPHER_3DES_EDE_CBC,
00165 TLS_CIPHER_AES_128_CBC,
00166 TLS_CIPHER_AES_256_CBC
00167 } tls_cipher;
00168
00169 typedef enum {
00170 TLS_HASH_NULL,
00171 TLS_HASH_MD5,
00172 TLS_HASH_SHA
00173 } tls_hash;
00174
00175 struct tls_cipher_suite {
00176 u16 suite;
00177 tls_key_exchange key_exchange;
00178 tls_cipher cipher;
00179 tls_hash hash;
00180 };
00181
00182 typedef enum {
00183 TLS_CIPHER_STREAM,
00184 TLS_CIPHER_BLOCK
00185 } tls_cipher_type;
00186
00187 struct tls_cipher_data {
00188 tls_cipher cipher;
00189 tls_cipher_type type;
00190 size_t key_material;
00191 size_t expanded_key_material;
00192 size_t block_size;
00193 enum crypto_cipher_alg alg;
00194 };
00195
00196
00197 struct tls_verify_hash {
00198 struct crypto_hash *md5_client;
00199 struct crypto_hash *sha1_client;
00200 struct crypto_hash *md5_server;
00201 struct crypto_hash *sha1_server;
00202 struct crypto_hash *md5_cert;
00203 struct crypto_hash *sha1_cert;
00204 };
00205
00206
00207 const struct tls_cipher_suite * tls_get_cipher_suite(u16 suite);
00208 const struct tls_cipher_data * tls_get_cipher_data(tls_cipher cipher);
00209 int tls_server_key_exchange_allowed(tls_cipher cipher);
00210 int tls_parse_cert(const u8 *buf, size_t len, struct crypto_public_key **pk);
00211 int tls_verify_hash_init(struct tls_verify_hash *verify);
00212 void tls_verify_hash_add(struct tls_verify_hash *verify, const u8 *buf,
00213 size_t len);
00214 void tls_verify_hash_free(struct tls_verify_hash *verify);
00215
00216 #endif