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