networksecurity/tls/inc/SSLCONST.H
changeset 0 af10295192d8
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // SSL DLL entry code 
       
    15 // 
       
    16 //
       
    17 
       
    18 #if !defined(__SSLCONST_H__)
       
    19 #define __SSLCONST_H__
       
    20 
       
    21 #define __USE_TLSV1__
       
    22 #include <e32std.h>
       
    23 #include <e32base.h>
       
    24 
       
    25 const TInt KSSLActiveHighPriority=10;
       
    26 const TInt KSSLActiveMedPriority=0;
       
    27 const TInt KSSLActiveLowPriority=-10;
       
    28 
       
    29 // this constants are arbitrary and define high limits for the length of some tmp descriptors
       
    30 const TUint KHSMessMax=0x100000; //TODO isnt it too big or too small?
       
    31 const TInt KMaxBlkSize=32; 
       
    32 const TInt KMaxMac=32; //
       
    33 const TInt KMaxPad=8; //
       
    34 const TInt KOutRecBufLen=1024;
       
    35 const TUint KCiphTextLengLimit=0x8000; //TODO ssl defines 
       
    36 // this value as 2^14+2048 but it seems that some servers exeed this limit 
       
    37 // so I put greater value. Need to check this. (Artem)
       
    38 
       
    39 // $$VR 21/09/2001
       
    40 const TUint	KHSversionOffset=4;
       
    41 const TUint	KHSrandomOffset=6;
       
    42 const TUint KHSrandomLength=32;
       
    43 const TUint KHSsessionLenOffset=38;
       
    44 const TUint KHSciperOffset=39;
       
    45 
       
    46 // CT 18/10/00 
       
    47 // Maximum size of buffers used to hold keys during exchange. 512 will allow a 4096bit key.
       
    48 const TInt KMaxKeyBufferSize=512;
       
    49 
       
    50 //error const
       
    51 const TInt KErrRecProt=1;
       
    52 //const KErr
       
    53 
       
    54 /** States for the record protocol parser. 
       
    55 * @since v6.0 */
       
    56 enum TRecordProtocol
       
    57 	{
       
    58 	/** Changing ciphers. */
       
    59 	EChangeCipherSpec=20,
       
    60 	/** Alerting. */
       
    61 	EAlert=21,
       
    62 	/** Handshake. */
       
    63   	EHandshake=22,
       
    64 	/** Application data. */
       
    65   	EApplicationData=23
       
    66   	};
       
    67 
       
    68 const TUint8 KCHCiphSpecByte=1;
       
    69 
       
    70 /** Hanshake protocol state.
       
    71 * @since v6.0 */
       
    72 enum THandshakeProtocol
       
    73 	{
       
    74 	/** Hello request. */
       
    75 	EHelloRequest,
       
    76 	/** Client hello. */
       
    77 	EClientHello,
       
    78 	/** Server hello. */
       
    79 	EServerHello,
       
    80 	/** Certificate. */
       
    81 	ECert,
       
    82 	/** Certificate request. */
       
    83 	ECertRequest,
       
    84 	/** Certificate verify. */
       
    85 	ECertVerify,
       
    86 	/** Server hello done. */
       
    87 	EServerHelloDone,
       
    88 	/** Server key exchange. */
       
    89 	EServKeyExchange,
       
    90 	/** Client key exchange. */
       
    91 	ECliKeyExchange,
       
    92 	/** Finished. */
       
    93 	EFinished
       
    94 	};
       
    95 
       
    96 class THandshakeProtocolTag
       
    97 /** @since v6.0 */
       
    98 	{
       
    99 public:
       
   100 	THandshakeProtocol iHSMess;
       
   101 	TUint8 iValue;
       
   102 	};
       
   103 
       
   104 /** @since v6.0 */
       
   105 const THandshakeProtocolTag THSMessTypes[10] =
       
   106 	{
       
   107 		{EHelloRequest,0},
       
   108 		{EClientHello,1},
       
   109 		{EServerHello,2},
       
   110 		{ECert,11},
       
   111 		{EServKeyExchange,12},
       
   112 		{ECertRequest,13},
       
   113 		{EServerHelloDone,14},
       
   114 		{ECertVerify,15},
       
   115 		{ECliKeyExchange,16},
       
   116 		{EFinished,20}
       
   117 	};
       
   118 
       
   119 /** Handshake message item. */
       
   120 enum THSMessItemType 
       
   121 	{
       
   122 	/** Version. */
       
   123 	EVersion,
       
   124 	/** Random. */
       
   125 	ERandom,
       
   126 	/** Session ID. */
       
   127 	ESessionID,
       
   128 	/** Cipher suite. */
       
   129 	ECipherSuite,
       
   130 	/** Compression method. */
       
   131 	ECompressionMethod,
       
   132 	/** Parameter. */
       
   133 	EParameter,
       
   134 	/** Signature. */
       
   135 	ESignature,
       
   136 	/** Raw data. */
       
   137 	ERawData,
       
   138 	/** ASN1 certificate. */
       
   139 	EASN1Cert,
       
   140 	/** Select. */
       
   141 	ESelect,
       
   142 	/** End. */
       
   143 	EEnd
       
   144 	};
       
   145 
       
   146 /** Handshake message item quantity. */
       
   147 enum THSMessItemQuantity 
       
   148 	{
       
   149 	/** Single item. */
       
   150 	ESingle, 
       
   151 	/** Item list. */
       
   152 	EList
       
   153 	};
       
   154 	
       
   155 /** Handshake vector length. */
       
   156 enum THSVectorLengthType 
       
   157 	{
       
   158 	/** Length fixed. */
       
   159 	EFixed,
       
   160 	/** Length variable. */
       
   161 	EVariable
       
   162 	};
       
   163 	
       
   164 class THSMessItem
       
   165 	{
       
   166 public:
       
   167 	THSMessItemType iItemType;
       
   168 	TInt iValue;
       
   169 	THSVectorLengthType iLenType;
       
   170 	THSMessItemQuantity iQuantity;
       
   171 	};
       
   172 
       
   173 /** Protocol alerts. */
       
   174 enum TAlertProtocol
       
   175 	{
       
   176 	/** Close notification. */
       
   177 	ECloseNotify,
       
   178 	/** Unexpected message. */
       
   179 	EUnexpectedMes,
       
   180 	/** Bad MAC received. */
       
   181 	EBadRecordMac,
       
   182 	/** Decompression failure. */
       
   183 	EDecompressionFailure,
       
   184 	/** Handshake failure. */
       
   185 	EHandshakeFailure,
       
   186 	/** No certificate. */
       
   187 	ENoCertificate,
       
   188 	/** Bad certificate. */
       
   189 	EBadCertificate,
       
   190 	/** Unsupported certificate. */
       
   191 	EUnsupportedCertificate,
       
   192 	/** Certificate is revoked. */
       
   193 	ETLSCertificateRevoked,
       
   194 	/** Certificate is expired. */
       
   195 	ECertificateExpired,
       
   196 	/** Certificate unknown. */
       
   197 	ECertificateUnknown,
       
   198 	/** Illegal parameter. */
       
   199 	EIllegalParameter
       
   200 	};
       
   201 
       
   202 /** SSL Alert levels */
       
   203 enum TAlertLevel
       
   204 	{
       
   205 	/** Warning. */
       
   206 	EWarning=1,
       
   207 	/** Fatal. */
       
   208 	EFatal=2
       
   209 	};
       
   210 
       
   211 
       
   212 class TAlertLevelTag
       
   213 /** @since v6.0 */
       
   214 {
       
   215 public:
       
   216 	TAlertProtocol iAlert;
       
   217 	TUint8 iValue;
       
   218 	TAlertLevel iLevel;
       
   219 };
       
   220 
       
   221 /** @since v6.0 */
       
   222 const TAlertLevelTag Alerts[12]=
       
   223 {
       
   224 	{ECloseNotify,0,EWarning},
       
   225 	{EUnexpectedMes,10,EFatal},
       
   226 	{EBadRecordMac,20,EFatal},
       
   227 	{EDecompressionFailure,30,EFatal},
       
   228 	{EHandshakeFailure,40,EFatal},
       
   229 	{ENoCertificate,41,EWarning},
       
   230 	{EBadCertificate,42,EWarning},
       
   231 	{EUnsupportedCertificate,43,EWarning},
       
   232 	{ETLSCertificateRevoked,44,EWarning},
       
   233 	{ECertificateExpired,45,EWarning},
       
   234 	{ECertificateUnknown,46,EWarning},
       
   235 	{EIllegalParameter,47,EFatal}
       
   236 };
       
   237 
       
   238 class TTLSVersion
       
   239 /** @since v6.0 */
       
   240 	{
       
   241 public:
       
   242 	TUint8 iMajor;
       
   243 	TUint8 iMinor;
       
   244 	};
       
   245 
       
   246 const TTLSVersion SSLv3Version= {3,0};
       
   247 const TTLSVersion TLSv1Version= {3,1};
       
   248 //const TTLSVersion DefaultVersion= TLSv1Version;
       
   249 
       
   250 //#define RSA_PKCS1_PADDING	11
       
   251 //#define RSA_SSLV23_PADDING	12
       
   252 
       
   253 // Client/Server Hello frame constants,
       
   254 const TUint KServerHelloMajorOffset = 0;
       
   255 const TUint KServerHelloMinorOffset = 1;
       
   256 const TUint KHelloRandomLength = 32;
       
   257 //const TUint KServerHelloRandomOffset = 2;
       
   258 //const TUint KServerHelloSessionIDLengthOffset = 34;
       
   259 //const TUint KServerHelloSessionIDOffset = 35;
       
   260 //const TUint KServerHelloCipherSuiteLengthOffset = 35;
       
   261 
       
   262 // Server cert frame constants
       
   263 const TInt KServerCertOffset= 0x00;  
       
   264 
       
   265 //Look RFC 2104 for explanation of ipad & opad
       
   266 const TUint8 KIpad=0x36;
       
   267 const TUint8 KOpad=0x5C;
       
   268 //pg Note
       
   269 //These following definitions used to be part of the previous crypto lib 
       
   270 /** Symmetric cipher types 
       
   271 *
       
   272 * @since v6.0 */
       
   273 enum TSymmetricCipherType
       
   274 	{
       
   275 	/** default cipher. */
       
   276 	EDefaultCipher,
       
   277 	/** null cipher. */
       
   278 	ENullCipher,
       
   279 	/** DES in ecb mode, iv=0, block=8, key= 8. */
       
   280 	EDes_ecb,
       
   281 	/** DES in ecb ede mode, iv=0, block=8, key=16. */
       
   282 	EDes_ede,
       
   283 	/** DES in ecb ede mode, iv=0, block=8, key=24. */
       
   284 	EDes_ede3,
       
   285 	/** DES in cfb mode, iv=8, block=1, key= 8. */
       
   286 	EDes_cfb,
       
   287 	/** DES in ede cfb mode, iv=8, block=1, key=16. */
       
   288 	EDes_ede_cfb,
       
   289 	/** DES in ede cfb mode, iv=8, block=1, key=24. */
       
   290 	EDes_ede3_cfb,
       
   291 	/** DES in ofb mode, iv=8, block=1, key= 8. */
       
   292 	EDes_ofb,
       
   293 	/** DES in ede ofb mode, iv=8, block=1, key=16. */
       
   294 	EDes_ede_ofb,
       
   295 	/** DES in ede ofb mode, iv=8, block=1, key=24. */
       
   296 	EDes_ede3_ofb,
       
   297 	/** DES in cbc mode, iv=8, block=8, key= 8. */
       
   298 	EDes_cbc,
       
   299 	/** DES in cbc ede mode, iv=8, block=8, key=16. */
       
   300 	EDes_ede_cbc,
       
   301 	/** DES in cbc ede mode, iv=8, block=8, key=24. */
       
   302 	EDes_ede3_cbc,
       
   303 	/** DES in desx cbc mode,iv=8, block=8, key=24 */
       
   304 	EDesx_cbc,
       
   305 	/** ARC4, iv=0, block=1, key=16. */
       
   306 	ERc4,
       
   307 	/** RC5 in ecb mode. */
       
   308 	ERc5_ecb,          // RC5, 
       
   309 	/** RC5 in cbc mode. */
       
   310 	ERc5_cbc,
       
   311 	/** RC5 in cfb mode. */
       
   312 	ERc5_cfb,
       
   313 	/** RC5 in ofb mode. */
       
   314 	ERc5_ofb,
       
   315 	/** IDEA in ecb mode, iv=0, block=8, key=16. */
       
   316 	EIdea_ecb,
       
   317 	/** IDEA in cfb mode, iv=8, block=1, key=16. */
       
   318 	EIdea_cfb,
       
   319 	/** IDEA in ofb mode, iv=8, block=1, key=16. */
       
   320 	EIdea_ofb,
       
   321 	/** IDEA in cbc mode, iv=8, block=8, key=16. */
       
   322 	EIdea_cbc,
       
   323 	/** RC2 in ecb mode. */
       
   324 	ERc2_ecb,
       
   325 	/** RC2 in cbc mode. */
       
   326 	ERc2_cbc
       
   327 //	ERc2_cfb,
       
   328 //	ERc2_ofb
       
   329 	};
       
   330 
       
   331 /** Message digest types. */
       
   332 enum TMessageDigestType
       
   333 	{
       
   334 	/** Default. */
       
   335 	EDefaultDigest,
       
   336 	/** None. */
       
   337 	EMdNull,
       
   338 	/** RSA sign/verify. */
       
   339 	EMd5,
       
   340 	/** RSA sign/verify. */
       
   341 	ESha,
       
   342 	/** RSA sign/verify. */
       
   343 	ESha1,
       
   344 	/** DSA sign/verify. */
       
   345 	EDss,
       
   346 	/** DSA sign/verify. */
       
   347 	EDss1,
       
   348 	/** MAC sign/verify. */
       
   349 	EHMac
       
   350 	};
       
   351 
       
   352 /** Public key algorithm. */
       
   353 enum TPublicKeyAlg 
       
   354 	{
       
   355 	/** RSA encryption. */
       
   356 	ERsa,
       
   357 	/** DH encryption. */
       
   358 	EDh,
       
   359 	/** DSA encryption. */
       
   360 	EDsa
       
   361 	};
       
   362 
       
   363 class TAlgorithmInfo
       
   364 	{
       
   365 public:
       
   366 	TInt iType;//TODO enum
       
   367 	TInt iSize;
       
   368 	};
       
   369 
       
   370 
       
   371 #endif
       
   372