00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 #ifndef WTLS_STATESUPPORT_H
00061 #define WTLS_STATESUPPORT_H
00062
00063 #include "gwlib/gwlib.h"
00064 #include "wtls_pdu.h"
00065 #include "wtls.h"
00066 #define KEYSIZE_MAX 2048
00067 #define NOT_EXPORTABLE 0
00068 #define EXPORTABLE 1
00069 #define BLOCK 0
00070 #define STREAM 1
00071
00072
00073
00074
00075
00076
00077
00078 enum key_exchange_suites{
00079 NULL_keyxchg,
00080 SHARED_SECRET,
00081 DH_anon,
00082 DH_anon_512,
00083 RSA_anon,
00084 RSA_anon_512,
00085 RSA_anon_768,
00086 RSA_NOLIMIT,
00087 RSA_512,
00088 RSA_768,
00089 ECDH_anon,
00090 ECDH_anon_113,
00091 ECDH_anon_131,
00092 ECDH_ECDSA_NOLIMIT
00093 };
00094
00095
00096 enum bulk_algorithms {
00097 NULL_bulk,
00098 RC5_CBC_40,
00099 RC5_CBC_56,
00100 RC5_CBC,
00101 DES_CBC_40,
00102 DES_CBC,
00103 TRIPLE_DES_CBC_EDE,
00104 IDEA_CBC_40,
00105 IDEA_CBC_56,
00106 IDEA_CBC
00107 };
00108
00109
00110 enum keyed_macs{
00111 SHA_0,
00112 SHA_40,
00113 SHA_80,
00114 SHA_NOLIMIT,
00115 SHA_XOR_40,
00116 MD5_40,
00117 MD5_80,
00118 MD5_NOLIMIT
00119 };
00120
00121
00122 typedef struct
00123 {
00124 const char* title;
00125 int key_size_limit;
00126 } keyxchg_table_t;
00127
00128 static keyxchg_table_t keyxchg_table[] = {
00129 {"NULL",0},
00130 {"Shared Secret", KEYSIZE_MAX},
00131 {"DH-anon",KEYSIZE_MAX},
00132 {"DH-anon-512",512},
00133 {"DH-anon-768",768},
00134 {"RSA-anon", KEYSIZE_MAX},
00135 {"RSA-anon-512",512},
00136 {"RSA-anon-768",768},
00137 {"RSA",KEYSIZE_MAX},
00138 {"RSA-512", 512},
00139 {"RSA-768",768},
00140 {"ECDH-anon",KEYSIZE_MAX},
00141 {"ECDH-anon-113",113},
00142 {"ECDH-anon-131",131},
00143 {"ECDH-ECDSA",KEYSIZE_MAX}
00144 };
00145
00146
00147 typedef struct
00148 {
00149 const char* title;
00150 int is_exportable;
00151 int block_or_stream;
00152 int key_material;
00153 int expanded_key_material;
00154 int effective_key_bits;
00155 int iv_size;
00156 int block_size;
00157 } bulk_table_t;
00158
00159 static bulk_table_t bulk_table[] = {
00160 {"NULL Encryption",EXPORTABLE,STREAM,0,0,0,0,0},
00161 {"RC5-CBC-40",EXPORTABLE,BLOCK,5,16,40,8,8},
00162 {"RC5-CBC-56",EXPORTABLE,BLOCK,7,16,56,8,8},
00163 {"RC5-CBC",NOT_EXPORTABLE,BLOCK,16,16,128,8,8},
00164 {"DES-CBC-40",EXPORTABLE,BLOCK,5,8,40,8,8},
00165 {"DES-CBC",NOT_EXPORTABLE,BLOCK,8,8,56,8,8},
00166 {"3DES-CBC-EDE",NOT_EXPORTABLE,BLOCK,24,24,168,8,8},
00167 {"IDEA-CBC-40",EXPORTABLE,BLOCK,5,16,40,8,8},
00168 {"IDEA-CBC-56",EXPORTABLE,BLOCK,7,16,56,8,8},
00169 {"IDEA-CBC",NOT_EXPORTABLE,BLOCK,16,16,128,8,8}
00170 };
00171
00172
00173 typedef struct
00174 {
00175 const char* title;
00176 int key_size;
00177 int mac_size;
00178 } hash_table_t;
00179
00180 static hash_table_t hash_table[] = {
00181 {"SHA-0",0,0},
00182 {"SHA1-40",20,5},
00183 {"SHA1-80",20,10},
00184 {"SHA1",20,20},
00185 {"SHA-XOR-40",0,5},
00186 {"MD5-40",16,5},
00187 {"MD5-80",16,10},
00188 {"MD5",16,16}
00189 };
00190
00191
00192 Octstr* wtls_calculate_prf(Octstr* secret, Octstr* label,
00193 Octstr* seed, int byteLength, WTLSMachine* wtls_machine);
00194 RSAPublicKey* wtls_get_rsapublickey(void);
00195 Random* wtls_get_random(void);
00196 Octstr* wtls_decrypt(Octstr* buffer, WTLSMachine* wtls_machine);
00197 Octstr* wtls_encrypt(Octstr* buffer, WTLSMachine* wtls_machine, int recordType);
00198 Octstr* wtls_decrypt_rsa(Octstr* encryptedData);
00199
00200
00201
00202 CipherSuite* wtls_choose_ciphersuite(List* ciphersuites);
00203 int wtls_choose_clientkeyid(List* clientKeyIDs);
00204 int wtls_choose_snmode(int snmode);
00205 int wtls_choose_krefresh(int krefresh);
00206
00207
00208
00209
00210
00211
00212 int clienthellos_are_identical (List* pdu_list, List* last_received_packet);
00213 int certifcateverifys_are_identical (List* pdu_list, List* last_received_packet);
00214 int certificates_are_identical (List* pdu_list, List* last_received_packet);
00215 int clientkeyexchanges_are_identical (List* pdu_list, List* last_received_packet);
00216 int changecipherspecs_are_identical (List* pdu_list, List* last_received_packet);
00217 int finisheds_are_indentical (List* pdu_list, List* last_received_packet);
00218
00219
00220
00221
00222 int packet_contains_changecipherspec (List* pdu_list);
00223 int packet_contains_finished (List* pdu_list);
00224 int packet_contains_optional_stuff (List* pdu_list);
00225 int packet_contains_userdata (List* pdu_list);
00226 int packet_contains_clienthello (List* pdu_list);
00227
00228
00229
00230
00231 int is_critical_alert (List* pdu_list);
00232 int is_warning_alert (List* pdu_list);
00233
00234 void calculate_client_key_block(WTLSMachine *wtls_machine);
00235 void calculate_server_key_block(WTLSMachine *wtls_machine);
00236
00237 #endif
See file LICENSE for details about the license agreement for using,
modifying, copying or deriving work from this software.