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
00061 #ifndef PDU_H
00062 #define PDU_H
00063
00064 #include "gwlib/list.h"
00065 #include "gwlib/octstr.h"
00066 #include "wtls.h"
00067
00068 typedef enum wtls_pdu_modes {
00069 ChangeCipher_PDU = 1,
00070 Alert_PDU,
00071 Handshake_PDU,
00072 Application_PDU
00073 } wtls_pdu_modes;
00074
00075 typedef enum handshake_type{
00076 hello_request = 0,
00077 client_hello = 1,
00078 server_hello = 2,
00079 certificate = 11,
00080 server_key_exchange = 12,
00081 certificate_request = 13,
00082 server_hello_done = 14,
00083 certificate_verify = 15,
00084 client_key_exchange = 16,
00085 finished = 20
00086 } HandshakeType;
00087
00088 typedef enum compmethod {
00089 null_comp = 0
00090 } CompressionMethod;
00091
00092 typedef enum certificateformat {
00093 WTLSCert = 1,
00094 X509Cert,
00095 X968Cert
00096 } CertificateFormat;
00097
00098 typedef enum sig_algo {
00099 anonymous,
00100 ecdsa_sha,
00101 rsa_sha,
00102 } SignatureAlgorithm;
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 typedef enum keyex_suite {
00113 null_k,
00114 shared_secret,
00115 dh_anon,
00116 dh_anon_512,
00117 dh_anon_768,
00118 rsa_anon,
00119 rsa_anon_512,
00120 rsa_anon_768,
00121 rsa,
00122 rsa_512,
00123 rsa_768,
00124 ecdh_anon,
00125 ecdh_anon_113,
00126 ecdh_anon_131,
00127 ecdh_ecdsa,
00128 } KeyExchangeSuite;
00129
00130 typedef enum pubkey_algo {
00131 rsa_pubkey,
00132 diffie_hellman_pubkey,
00133 elliptic_curve_pubkey,
00134 } PublicKeyAlgorithm;
00135
00136 typedef enum identifier_type {
00137 null = 0,
00138 text,
00139 binary,
00140 key_hash_sha = 254,
00141 x509_name = 255
00142 } IdentifierType;
00143
00144 typedef enum public_key_type {
00145 rsa_key = 2,
00146 ecdh_key = 3,
00147 ecdsa_key = 4
00148 } PublicKeyType;
00149
00150 typedef enum ecbasistype {
00151 ec_basis_onb = 1,
00152 ec_basis_trinomial,
00153 ec_basis_pentanomial,
00154 ec_basis_polynomial
00155 } ECBasisType;
00156
00157 typedef enum ecfield {
00158 ec_prime_p,
00159 ec_characteristic_two
00160 } ECField;
00161
00162 typedef struct random {
00163 long gmt_unix_time;
00164 Octstr *random_bytes;
00165 } Random;
00166
00167 typedef struct ecpoint {
00168 Octstr *point;
00169 } ECPoint;
00170
00171 typedef ECPoint ECPublicKey;
00172
00173 typedef struct dhpublickey {
00174 Octstr *dh_Y;
00175 } DHPublicKey;
00176
00177 typedef struct rsa_public_key {
00178 Octstr *rsa_exponent;
00179 Octstr *rsa_modulus;
00180 } RSAPublicKey;
00181
00182 typedef struct public_key {
00183
00184 ECPublicKey *ecdh_pubkey;
00185
00186 ECPublicKey *ecdsa_pubkey;
00187
00188 RSAPublicKey *rsa_pubkey;
00189 } PublicKey;
00190
00191 typedef struct identifier {
00192 IdentifierType id_type;
00193
00194 int charset;
00195 Octstr *name;
00196
00197 Octstr *identifier;
00198
00199 Octstr *key_hash;
00200
00201 Octstr *distinguished_name;
00202 } Identifier;
00203
00204 typedef struct eccurve {
00205 Octstr *a;
00206 Octstr *b;
00207 Octstr *seed;
00208 } ECCurve;
00209
00210 typedef struct dh_parameters{
00211 int dh_e;
00212 Octstr *dh_p;
00213 Octstr *dh_g;
00214 } DHParameters;
00215
00216 typedef struct ec_parameters{
00217 ECField field;
00218
00219 Octstr *prime_p;
00220
00221 int m;
00222 ECBasisType basis;
00223
00224
00225 int k;
00226
00227 int k1;
00228 int k2;
00229 int k3;
00230
00231 Octstr *irreducible;
00232 ECCurve *curve;
00233 ECPoint *base;
00234 Octstr *order;
00235 Octstr *cofactor;
00236 } ECParameters;
00237
00238 typedef struct parameter_set {
00239 long length;
00240
00241
00242 DHParameters *dhparams;
00243
00244 ECParameters *ecparams;
00245 } ParameterSet;
00246
00247 typedef struct parameter_specifier {
00248 int param_index;
00249 ParameterSet *param_set;
00250 } ParameterSpecifier;
00251
00252 typedef struct key_exchange_id {
00253 int key_exchange_suite;
00254 ParameterSpecifier *param_specif;
00255 Identifier *identifier;
00256 } KeyExchangeId;
00257
00258 typedef struct signature {
00259
00260
00261
00262 List *sha_hash;
00263 } Signature;
00264
00265 typedef struct to_be_signed_cert {
00266 int certificate_version;
00267 SignatureAlgorithm signature_algo;
00268 Identifier *issuer;
00269 long valid_not_before;
00270 long valid_not_after;
00271 Identifier *subject;
00272 PublicKeyType pubkey_type;
00273 ParameterSpecifier *param_spec;
00274 PublicKey *pubkey;
00275 } ToBeSignedCertificate;
00276
00277 typedef struct wtls_cert {
00278 ToBeSignedCertificate *tobesigned_cert;
00279 Signature *signature;
00280 } WTLSCertificate;
00281
00282 typedef struct rsa_secret{
00283 int client_version;
00284 List *random;
00285 } RSASecret;
00286
00287 typedef struct rsa_encrypted_secret {
00288 Octstr *encrypted_secret;
00289 } RSAEncryptedSecret;
00290
00291 typedef struct cipher_suite {
00292 int bulk_cipher_algo;
00293 int mac_algo;
00294 } CipherSuite;
00295
00296 typedef struct cert_request {
00297 List *trusted_authorities;
00298 } CertificateRequest;
00299
00300 typedef struct cert_verify {
00301 Signature *signature;
00302 } CertificateVerify;
00303
00304 typedef struct hello_request
00305 {
00306 int dummy;
00307 } HelloRequest;
00308
00309 typedef struct client_hello
00310 {
00311 int clientversion;
00312 Random *random;
00313 Octstr *session_id;
00314 List *client_key_ids;
00315 List *trusted_key_ids;
00316 List *ciphersuites;
00317 List *comp_methods;
00318 int snmode;
00319 int krefresh;
00320 } ClientHello;
00321
00322
00323 typedef struct server_hello
00324 {
00325 int serverversion;
00326 Random *random;
00327 Octstr *session_id;
00328 int client_key_id;
00329 CipherSuite *ciphersuite;
00330 CompressionMethod comp_method;
00331 int snmode;
00332 int krefresh;
00333 } ServerHello;
00334
00335 typedef struct certificate {
00336 CertificateFormat certificateformat;
00337
00338 WTLSCertificate *wtls_certificate;
00339
00340 Octstr *x509_certificate;
00341
00342 Octstr *x968_certificate;
00343 } Certificate;
00344
00345 typedef struct server_key_exchange
00346 {
00347 ParameterSpecifier *param_spec;
00348
00349 RSAPublicKey *rsa_params;
00350
00351 DHPublicKey *dh_params;
00352
00353 ECPublicKey *ecdh_params;
00354 } ServerKeyExchange;
00355
00356 typedef struct client_key_exchange
00357 {
00358
00359 RSAEncryptedSecret *rsa_params;
00360
00361 DHPublicKey *dh_anon_params;
00362
00363 ECPublicKey *ecdh_params;
00364 } ClientKeyExchange;
00365
00366 typedef struct finished {
00367 Octstr *verify_data;
00368 } Finished;
00369
00370 typedef struct server_hello_done
00371 {
00372 int dummy;
00373 } ServerHelloDone;
00374
00375 typedef struct cc
00376 {
00377 int change;
00378 } ChangeCipher;
00379
00380 typedef struct alert
00381 {
00382 int level;
00383 int desc;
00384 Octstr *chksum;
00385 } Alert;
00386
00387 typedef struct handshake
00388 {
00389 HandshakeType msg_type;
00390 int length;
00391
00392
00393
00394 ClientHello *client_hello;
00395
00396 ServerHello *server_hello;
00397
00398 Certificate *certificate;
00399
00400 ServerKeyExchange *server_key_exchange;
00401
00402 CertificateRequest *certificate_request;
00403
00404 ServerHelloDone *server_hello_done;
00405
00406 CertificateVerify *cert_verify;
00407
00408 ClientKeyExchange *client_key_exchange;
00409
00410 Finished *finished;
00411 } Handshake;
00412
00413 typedef struct application
00414 {
00415 Octstr *data;
00416 } Application;
00417
00418 typedef struct wtls_pdu {
00419 int type;
00420 int reserved;
00421 int cipher;
00422 int seqnum;
00423 int rlen;
00424
00425 union {
00426 ChangeCipher cc;
00427 Alert alert;
00428 Handshake handshake;
00429 Application application;
00430 } u;
00431 } wtls_PDU;
00432
00433 typedef struct wtls_payload {
00434 int type;
00435 int reserved;
00436 int cipher;
00437 int seqnum;
00438 int rlen;
00439
00440 Octstr *data;
00441 } wtls_Payload;
00442
00443
00444 wtls_PDU *wtls_pdu_create(int type);
00445 void wtls_pdu_destroy(wtls_PDU *msg);
00446 void wtls_pdu_dump(wtls_PDU *msg, int level);
00447 wtls_PDU *wtls_pdu_unpack(wtls_Payload *payload, WTLSMachine* wtls_machine);
00448 wtls_Payload *wtls_pdu_pack(wtls_PDU *pdu, WTLSMachine* wtls_machine);
00449
00450 wtls_Payload *wtls_payload_unpack(Octstr *data);
00451 Octstr *wtls_payload_pack(wtls_Payload *payload);
00452 void wtls_payload_destroy(wtls_Payload *payload);
00453
00454 List* wtls_unpack_payloadlist (Octstr *data);
00455 Octstr* wtls_pack_payloadlist (List* payloadlist);
00456
00457
00458 #endif
See file LICENSE for details about the license agreement for using,
modifying, copying or deriving work from this software.