Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

wtls_pdu.h

Go to the documentation of this file.
00001 /* ==================================================================== 
00002  * The Kannel Software License, Version 1.0 
00003  * 
00004  * Copyright (c) 2001-2008 Kannel Group  
00005  * Copyright (c) 1998-2001 WapIT Ltd.   
00006  * All rights reserved. 
00007  * 
00008  * Redistribution and use in source and binary forms, with or without 
00009  * modification, are permitted provided that the following conditions 
00010  * are met: 
00011  * 
00012  * 1. Redistributions of source code must retain the above copyright 
00013  *    notice, this list of conditions and the following disclaimer. 
00014  * 
00015  * 2. Redistributions in binary form must reproduce the above copyright 
00016  *    notice, this list of conditions and the following disclaimer in 
00017  *    the documentation and/or other materials provided with the 
00018  *    distribution. 
00019  * 
00020  * 3. The end-user documentation included with the redistribution, 
00021  *    if any, must include the following acknowledgment: 
00022  *       "This product includes software developed by the 
00023  *        Kannel Group (http://www.kannel.org/)." 
00024  *    Alternately, this acknowledgment may appear in the software itself, 
00025  *    if and wherever such third-party acknowledgments normally appear. 
00026  * 
00027  * 4. The names "Kannel" and "Kannel Group" must not be used to 
00028  *    endorse or promote products derived from this software without 
00029  *    prior written permission. For written permission, please  
00030  *    contact org@kannel.org. 
00031  * 
00032  * 5. Products derived from this software may not be called "Kannel", 
00033  *    nor may "Kannel" appear in their name, without prior written 
00034  *    permission of the Kannel Group. 
00035  * 
00036  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 
00037  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
00038  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
00039  * DISCLAIMED.  IN NO EVENT SHALL THE KANNEL GROUP OR ITS CONTRIBUTORS 
00040  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,  
00041  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT  
00042  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR  
00043  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,  
00044  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE  
00045  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,  
00046  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
00047  * ==================================================================== 
00048  * 
00049  * This software consists of voluntary contributions made by many 
00050  * individuals on behalf of the Kannel Group.  For more information on  
00051  * the Kannel Group, please see <http://www.kannel.org/>. 
00052  * 
00053  * Portions of this software are based upon software originally written at  
00054  * WapIT Ltd., Helsinki, Finland for the Kannel project.  
00055  */ 
00056 
00057 /* wtls_pdu.h - definitions for unpacked WTLS protocol data units
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 /*typedef enum keyex_algo {
00105     rsa,
00106     rsa_anon,
00107     dh_anon,
00108     ecdh_anon,
00109     ecdh_ecdsa,
00110 } KeyExchangeAlgorithm;*/
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     /* ecdh */
00184     ECPublicKey *ecdh_pubkey;
00185     /* ecdsa */
00186     ECPublicKey *ecdsa_pubkey;
00187     /* rsa */
00188     RSAPublicKey *rsa_pubkey;
00189 } PublicKey;
00190 
00191 typedef struct identifier {
00192     IdentifierType id_type;
00193     /* text */
00194     int charset;
00195     Octstr *name;
00196     /* binary */
00197     Octstr *identifier;
00198     /* key_hash_sha */
00199     Octstr *key_hash;
00200     /* x509 */
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     /* case ec_prime_p */
00219     Octstr *prime_p;
00220     /* case ec_characteristic_two */
00221     int m;
00222     ECBasisType basis;
00223         /* case ec_basis_onb : nothing*/
00224         /* case ec_trinomial */
00225         int k;
00226         /* case ec_pentanomial */
00227         int k1;
00228         int k2;
00229         int k3;
00230         /* case ec_basis_polynomial */
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     /* rsa: empty */
00241     /* diffie-hellman */
00242     DHParameters *dhparams;
00243     /* eliptic curve */
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     /* case anonymous */
00260     /* nothing */
00261     /* case ecdsa_sha and rsa_sha */
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; // List of KeyExchangeIds
00298 } CertificateRequest;
00299 
00300 typedef struct cert_verify {
00301     Signature *signature;
00302 } CertificateVerify;
00303 
00304 typedef struct hello_request
00305 {
00306     int dummy; /* nothing here */
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; // list of 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     /* case WTLS */
00338     WTLSCertificate *wtls_certificate;
00339     /* case X509 */
00340     Octstr *x509_certificate;
00341     /* X968 */
00342     Octstr *x968_certificate;
00343 } Certificate;
00344 
00345 typedef struct server_key_exchange
00346 {
00347     ParameterSpecifier *param_spec;
00348     /* case rsa_anon */
00349     RSAPublicKey *rsa_params;
00350     /* case dh_anon */
00351     DHPublicKey *dh_params;
00352     /* case ecdh_anon */
00353     ECPublicKey *ecdh_params;
00354 } ServerKeyExchange;
00355 
00356 typedef struct client_key_exchange
00357 {
00358     /* case rsa and rsa_anon*/
00359     RSAEncryptedSecret *rsa_params;
00360     /* case dh_anon */
00361     DHPublicKey *dh_anon_params;
00362     /* case ecdh_anon and ecdh_ecdsa*/
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; /* nothing here */
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     /* case hello_request */
00392 
00393     /* case client_hello */
00394     ClientHello *client_hello;
00395     /* case server_hello */
00396     ServerHello *server_hello;
00397     /* case certificate */
00398     Certificate *certificate;
00399     /* case server_key_exchange */
00400     ServerKeyExchange *server_key_exchange;
00401     /* case certificate_request */
00402     CertificateRequest *certificate_request;
00403     /* case server_hello_done */
00404     ServerHelloDone *server_hello_done;
00405     /* case certificate_verify */
00406     CertificateVerify *cert_verify;
00407     /* case client_key_exchange */
00408     ClientKeyExchange *client_key_exchange;
00409     /* case finished */
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 /* Prototypes */
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.