OpenMoHAA 0.82.0
Loading...
Searching...
No Matches
gsSSL.h
1
3#ifndef __GSSSL_H__
4#define __GSSSL_H__
5
6#include "../darray.h"
7#include "../md5.h"
8#include "gsCrypt.h"
9#include "gsSHA1.h"
10#include "gsRC4.h"
11
12#if defined(__cplusplus)
13extern "C"
14{
15#endif
16
17 // SSL common types and defines. Used by HTTP SSL encryption engine
18
21// SSL v3.0
22#define GS_SSL_VERSION_MAJOR (0x03)
23#define GS_SSL_VERSION_MINOR (0x00)
24
25
28 // SSL content types
29#define GS_SSL_CONTENT_CHANGECIPHERSPEC (0x14) // 20
30#define GS_SSL_CONTENT_ALERT (0x15) // 21 Not sure if this is the correct value
31#define GS_SSL_CONTENT_HANDSHAKE (0x16) // 22
32#define GS_SSL_CONTENT_APPLICATIONDATA (0x17) // 23
33
34 // SSL handshake message types
35//#define GS_SSL_HANDSHAKE_HELLOREQUEST (0)
36#define GS_SSL_HANDSHAKE_CLIENTHELLO (1)
37#define GS_SSL_HANDSHAKE_SERVERHELLO (2)
38#define GS_SSL_HANDSHAKE_CERTIFICATE (11)
39//#define GS_SSL_HANDSHAKE_SERVERKEYEXCHANGE (12)
40//#define GS_SSL_HANDSHAKE_CERTIFICATEREQUEST (13)
41#define GS_SSL_HANDSHAKE_SERVERHELLODONE (14)
42//#define GS_SSL_HANDSHAKE_CERTIFICATEVERIFY (15)
43#define GS_SSL_HANDSHAKE_CLIENTKEYEXCHANGE (16)
44#define GS_SSL_HANDSHAKE_FINISHED (20)
45
46// the largest payload for a single SSL packet, RFC const
47// ----> RFC includes MAC and any padding, actual user data must be less
48#define GS_SSL_MAX_CONTENTLENGTH ((0x4000) - (0xFF))
49
50#ifndef HAVE_CIPHER_SUITES
51 /* these are the ones used by IE */
52 #define TLS_RSA_WITH_RC4_128_MD5 0x04
53 #define TLS_RSA_WITH_RCA_128_SHA 0x05
54 #define TLS_RSA_WITH_3DES_EDE_CBC_SHA 0x0a
55 #define TLS_RSA_WITH_DES_CBC_SHA 0x09
56 #define TLS_RSA_EXPORT1024_WITH_RC4_56_SHA 0x64
57 #define TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA 0x62
58 #define TLS_RSA_EXPORT_WITH_RC4_40_MD5 0x03
59 #define TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5 0x06
60 #define TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA 0x13
61 #define TLS_DHE_DSS_WITH_DES_CBC_SHA 0x12
62 #define TLS_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA 0x63
63#endif
64
65 // These depend on the SSL cipher suite ranges
66#define GS_SSL_MAX_MAC_SECRET_SIZE (20)
67#define GS_SSL_MAX_SYMMETRIC_KEY_SIZE (16)
68#define GS_SSL_MAX_IV_SIZE (16)
69#define GS_SSL_NUM_CIPHER_SUITES (1) // cipher suite list defined in gsSSL.c
70#define GS_SSL_MASTERSECRET_LEN (48)
71#define GS_SSL_PAD_ONE "666666666666666666666666666666666666666666666666" // 48 bytes
72#define GS_SSL_PAD_TWO "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\" // 48 bytes
73#define GS_SSL_MD5_PAD_LEN (48)
74#define GS_SSL_SHA1_PAD_LEN (40) // use only 40 of the 48 bytes
75#define GS_SSL_CLIENT_FINISH_VALUE "CLNT"
76#define GS_SSL_SERVER_FINISH_VALUE "SRVR"
77
78
81// SSL instance/session info
82typedef struct gsSSL
83{
84 int sessionLen;
85 unsigned char sessionData[255]; // up to 256 bytes
86 unsigned short cipherSuite;
87
88 //DArray certificateArray;
89 gsCryptRSAKey serverpub;
90 unsigned char sendSeqNBO[8]; // incrementing sequence number (for messages sent)
91 unsigned char receiveSeqNBO[8]; // ditto (for messages received)
92
93 // Key buffers
94 // Actual data may be smaller than array size
95 unsigned char clientWriteMACSecret[GS_CRYPT_SHA1_HASHSIZE];
96 unsigned char clientReadMACSecret [GS_CRYPT_SHA1_HASHSIZE];
97 unsigned char clientWriteKey [GS_SSL_MAX_SYMMETRIC_KEY_SIZE];
98 unsigned char clientReadKey [GS_SSL_MAX_SYMMETRIC_KEY_SIZE];
99 unsigned char clientWriteIV [GS_SSL_MAX_IV_SIZE];
100 unsigned char clientReadIV [GS_SSL_MAX_IV_SIZE];
101
102 // Actual lengths of the above data blocks
103 int clientWriteMACLen;
104 int clientReadMACLen;
105 int clientWriteKeyLen;
106 int clientReadKeyLen;
107 int clientWriteIVLen;
108 int clientReadIVLen;
109
110 RC4Context sendRC4; // initialized ONCE per key exchange
111 RC4Context recvRC4; // initialized ONCE per key exchange
112
113 // these are unused once the handshake is complete
114 // todo: dynamically allocate or remove to free space
115 MD5_CTX finishHashMD5;
116 SHA1Context finishHashSHA1;
117 unsigned char serverRandom[32]; // server random for key generation, sent plain text
118 unsigned char clientRandom[32]; // client random for key generation, sent plain text
119 unsigned char premastersecret[GS_SSL_MASTERSECRET_LEN]; // client random for key generation, sent encrypted with serverpub
120 unsigned char mastersecret[GS_SSL_MASTERSECRET_LEN];
121
122} gsSSL;
123
124
125// SSL messages (like the ClientHello) are wrapped in a "record" struct
127{
128 unsigned char contentType; // = GS_SSL_CONTENT_HANDSHAKE;
129 unsigned char versionMajor; // = GS_SSL_VERSION_MAJOR;
130 unsigned char versionMinor; // = GS_SSL_VERSION_MINOR;
131 unsigned char lengthNBO[2]; // length of msg, limited to 2^14
132
133 // WARNING: lengthNBO can NOT be an unsigned short
134 // This would create alignment issues from the previous 3 parameters
135
137
139{
140 gsSSLRecordHeaderMsg header; // include the header for easier packing
141 unsigned char handshakeType; // 0x01
142 unsigned char lengthNBO[3]; // 3 byte length, NBO integer! 61 = 0x00 00 3d
143 unsigned char versionMajor; // = GS_SSL_VERSION_MAJOR;
144 unsigned char versionMinor; // = GS_SSL_VERSION_MINOR;
145 unsigned char time[4]; // 4 byte random (spec says set to current unix-time)
146 unsigned char random[28]; // 28 byte random, total of 32 random bytes
147 unsigned char sessionIdLen; // how many of the bytes that follow are session info? (def:0)
148
149 // ALIGNMENT: 44 bytes prior to this, alignment should be OK
150 unsigned short cipherSuitesLength; // 2* number of cipher suites
151 unsigned short cipherSuites[GS_SSL_NUM_CIPHER_SUITES];
152 unsigned char compressionMethodLen; // no standard methods, set to 1
153 unsigned char compressionMethodList; // set to 0
155
157{
158 gsSSLRecordHeaderMsg header; // included here for easier packing
159 unsigned char handshakeType; // 0x10
160 unsigned char lengthNBO[3];
161 // The next lengthNBO bytes are the client contribution to the key
163
164
167// Information about each cipher suite
169{
170 int mSuiteID;
171 int mKeyLen;
172 int mMACLen;
173 int mIVLen;
175
176extern const gsSSLCipherSuiteDesc gsSSLCipherSuites[GS_SSL_NUM_CIPHER_SUITES];
177extern const unsigned char gsSslRsaOid[9];
178
179
182#if defined(__cplusplus)
183} // extern "C"
184#endif
185
186#endif // __GSSSL_H__
Definition md5.h:66
Definition gsRC4.h:18
Definition gsSHA1.h:56
Definition gsCrypt.h:48
Definition gsSSL.h:169
Definition gsSSL.h:139
Definition gsSSL.h:157
Definition gsSSL.h:127
Definition gsSSL.h:83