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