OpenMoHAA 0.82.0
Loading...
Searching...
No Matches
ghttpEncryption.h
1
3#ifndef __GHTTPENCRYPTION_H__
4#define __GHTTPENCRYPTION_H__
5
6
9//#include "ghttpCommon.h"
10
11
14// Encryption method
15typedef enum
16{
17 GHIEncryptionMethod_None,
18 GHIEncryptionMethod_Encrypt, // encrypt raw data written to buffer
19 GHIEncryptionMethod_Decrypt // decrypt raw data written to buffer
20} GHIEncryptionMethod;
21
22// Encryption results
23typedef enum
24{
25 GHIEncryptionResult_None,
26 GHIEncryptionResult_Success, // successfully encrypted/decrypted
27 GHIEncryptionResult_BufferTooSmall, // buffer was too small to hold converted data
28 GHIEncryptionResult_Error // some other kind of error
29} GHIEncryptionResult;
30
31
34struct GHIEncryptor; // forward declare for callbacks
35struct GHIConnection;
36
37// Called to init the encryption engine
38typedef GHIEncryptionResult (*GHTTPEncryptorInitFunc) (struct GHIConnection * theConnection,
39 struct GHIEncryptor * theEncryptor);
40
41// Called to connect the socket (some engines do this internally)
42typedef GHIEncryptionResult (*GHTTPEncryptorConnectFunc)(struct GHIConnection * theConnection,
43 struct GHIEncryptor * theEncryptor);
44
45// Called to start the handshake process engine
46typedef GHIEncryptionResult (*GHTTPEncryptorStartFunc)(struct GHIConnection * theConnection,
47 struct GHIEncryptor * theEncryptor);
48
49// Called to destroy the encryption engine
50typedef GHIEncryptionResult (*GHTTPEncryptorCleanupFunc)(struct GHIConnection * theConnection,
51 struct GHIEncryptor * theEncryptor);
52
53// Called when data needs to be encrypted
54// - entire plain text buffer will be encrypted
55typedef GHIEncryptionResult (*GHTTPEncryptorEncryptFunc)(struct GHIConnection * theConnection,
56 struct GHIEncryptor * theEncryptor,
57 const char * thePlainTextBuffer,
58 int thePlainTextLength, // [in]
59 char * theEncryptedBuffer,
60 int * theEncryptedLength); // [in/out]
61
62// Called when data needs to be decrypted
63// - encrypted data may be left in the buffer
64// - decrypted buffer is appended to, not overwritten
65typedef GHIEncryptionResult (*GHTTPEncryptorDecryptFunc)(struct GHIConnection * theConnection,
66 struct GHIEncryptor* theEncryptor,
67 const char * theEncryptedBuffer,
68 int * theEncryptedLength, // [in/out]
69 char * theDecryptedBuffer,
70 int * theDecryptedLength);// [in/out]
71
72
75typedef struct GHIEncryptor
76{
77 void* mInterface; // only SSL is currently supported
78 GHTTPEncryptionEngine mEngine;
79 GHTTPBool mInitialized;
80 GHTTPBool mSessionStarted; // handshake started?
81 GHTTPBool mSessionEstablished; // handshake completed?
82
83 // (As coded, these two are exclusive!)
84 // pattern 1 = manually encrypt the buffer, then send using normal socket functions
85 // pattern 2 = send plain text through the encryption engine, it will send
86 GHTTPBool mEncryptOnBuffer; // engine encrypts when writing to a buffer? (pattern 1)
87 GHTTPBool mEncryptOnSend; // engine encrypts when sending over socket? (pattern 2)
88
89 // If GHTTPTrue, the SSL library handles sending/receiving handshake messages
90 GHTTPBool mLibSendsHandshakeMessages;
91
92 // Functions for engine use
93 GHTTPEncryptorInitFunc mInitFunc;
94 GHTTPEncryptorCleanupFunc mCleanupFunc;
95 GHTTPEncryptorStartFunc mStartFunc; // start the handshake process
96 GHTTPEncryptorEncryptFunc mEncryptFunc;
97 GHTTPEncryptorDecryptFunc mDecryptFunc;
99
100
103// ssl encryption
104GHIEncryptionResult ghiEncryptorSslInitFunc(struct GHIConnection * connection,
105 struct GHIEncryptor * theEncryptor);
106GHIEncryptionResult ghiEncryptorSslCleanupFunc(struct GHIConnection * connection,
107 struct GHIEncryptor * theEncryptor);
108
109GHIEncryptionResult ghiEncryptorSslStartFunc(struct GHIConnection * connection,
110 struct GHIEncryptor * theEncryptor);
111
112GHIEncryptionResult ghiEncryptorSslEncryptFunc(struct GHIConnection * connection,
113 struct GHIEncryptor * theEncryptor,
114 const char * thePlainTextBuffer,
115 int thePlainTextLength,
116 char * theEncryptedBuffer,
117 int * theEncryptedLength);
118GHIEncryptionResult ghiEncryptorSslDecryptFunc(struct GHIConnection * connection,
119 struct GHIEncryptor * theEncryptor,
120 const char * theEncryptedBuffer,
121 int * theEncryptedLength,
122 char * theDecryptedBuffer,
123 int * theDecryptedLength);
124GHIEncryptionResult ghiEncryptorSslEncryptSend(struct GHIConnection * connection,
125 struct GHIEncryptor * theEncryptor,
126 const char * thePlainTextBuffer,
127 int thePlainTextLength,
128 int * theBytesSent);
129GHIEncryptionResult ghiEncryptorSslDecryptRecv(struct GHIConnection * connection,
130 struct GHIEncryptor * theEncryptor,
131 char * theDecryptedBuffer,
132 int * theDecryptedLength);
133
134
137#endif // __GHTTPENCRYPTION_H__
Definition ghttpConnection.h:84
Definition ghttpEncryption.h:76