sipxportlib  Version 3.3
OsEncryption.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2004-2006 SIPfoundry Inc.
3 // Licensed by SIPfoundry under the LGPL license.
4 //
5 // Copyright (C) 2004-2006 Pingtel Corp. All rights reserved.
6 // Licensed to SIPfoundry under a Contributor Agreement.
7 //
8 // $$
10 
11 
12 #ifndef _OsEncryption_h_
13 #define _OsEncryption_h_
14 
15 // SYSTEM INCLUDES
16 #ifdef HAVE_SSL
17 #define OSENCRYPTION
18 #endif
19 
20 #if defined (OSENCRYPTION)
21 #include <openssl/evp.h>
22 #include <openssl/x509.h>
23 #endif
24 
25 // APPLICATION INCLUDES
26 #include "os/OsDefs.h"
27 #include "os/OsStatus.h"
28 #include "os/OsTime.h"
29 
30 // DEFINES
31 // MACROS
32 // EXTERNAL FUNCTIONS
33 // EXTERNAL VARIABLES
34 // CONSTANTS
35 #define OE_MAX_KEY_LEN 64
36 
37 #define OE_MAX_RESULTS_HEADER_LEN 32
38 
39 // STRUCTS
40 // TYPEDEFS
41 // FORWARD DECLARATIONS
42 
44 
57 {
58  public:
60  OsEncryption(void);
61 
62  virtual ~OsEncryption(void);
63 
65  void setDataPointer(unsigned char *pIn, int inLen);
66 
68  int getDataLen(void);
69 
71  unsigned char *getDataPointer(void);
72 
74  void setResultsHeader(const unsigned char *header, int headerLen);
75 
77  unsigned char *getResults(void);
78 
80  int getResultsLen(void);
81 
83  void setKey(const unsigned char *key, int keyLen);
84 
86  OsStatus decrypt(void);
87 
89  OsStatus encrypt(void);
90 
92  OsStatus release(void);
93 
96 
97  protected:
98 
100  enum Direction
101  {
102  DECRYPT = 0,
104  };
105 
107  OsStatus init(Direction direction);
108 
110  UtlBoolean openSslError(void);
111 
113  OsStatus crypto(Direction direction);
114 
115  private:
116 
117 
118 #if defined (OSENCRYPTION)
119  X509_ALGOR *mAlgorithm;
120 
121  EVP_CIPHER_CTX mContext;
122 #endif
123 
124  unsigned char *mSalt; // defeats brute force decryption via appling dictionary
125 
126  int mSaltLen;
127 
128  unsigned char mKey[OE_MAX_KEY_LEN]; // storage of password
129 
130  int mKeyLen;
131 
132  unsigned char *mData; // pointer to storage of data
133 
134  int mDataLen;
135 
136  unsigned char *mResults; // allocated storage of results
137 
138  int mResultsLen;
139 
140  unsigned char mHeader[OE_MAX_RESULTS_HEADER_LEN]; // set/expect extra data in results buffer
141 
142  int mHeaderLen;
143 
144  // TEST: See unittests/EncryptionTest
145 
146 };
147 
148 #endif // _OsEncryption_h_
149 
void setResultsHeader(const unsigned char *header, int headerLen)
If you want to prepend this to the results header for file identification purposes.
Definition: OsEncryption.cpp:110
void setKey(const unsigned char *key, int keyLen)
set secret password
Definition: OsEncryption.cpp:101
int getDataLen(void)
How large is the untouched data buffer.
Definition: OsEncryption.cpp:123
int getResultsLen(void)
After [en/de]crypting get your results here.
Definition: OsEncryption.cpp:139
Wrapper and helper around system encryption routines.
Definition: OsEncryption.h:56
#define OE_MAX_RESULTS_HEADER_LEN
Definition: OsEncryption.h:37
unsigned char * getResults(void)
After [en/de]crypting, here&#39;s your results.
Definition: OsEncryption.cpp:134
OsEncryption(void)
Create one for each encryption/decryption operation.
Definition: OsEncryption.cpp:76
virtual ~OsEncryption(void)
Definition: OsEncryption.cpp:95
Definition: OsEncryption.h:102
#define OE_MAX_KEY_LEN
Definition: OsEncryption.h:35
OsStatus
Definition: OsStatus.h:27
OsStatus release(void)
free all, called in descructor
Definition: OsEncryption.cpp:155
Definition: OsEncryption.h:103
OsStatus decrypt(void)
operate after setting approp. input. . NOTE: This will return OS_FAILED on vxworks. */
Definition: OsEncryption.cpp:144
unsigned char * getDataPointer(void)
Pointer to untouched data buffer.
Definition: OsEncryption.cpp:128
UtlBoolean openSslError(void)
common handling of OpenSSL&#39;s errors
Definition: OsEncryption.cpp:299
OsStatus init(Direction direction)
allocate OpenSSL stuff
Definition: OsEncryption.cpp:181
Direction
OpenSSL state differentation direction for API calls.
Definition: OsEncryption.h:100
int UtlBoolean
Definition: UtlDefs.h:41
void setDataPointer(unsigned char *pIn, int inLen)
Data to feed to encryption, not touched and NOT copied, so keep it around.
Definition: OsEncryption.cpp:117
OsStatus crypto(Direction direction)
common [en/de]crypt method
Definition: OsEncryption.cpp:235
static UtlBoolean sIgnoreEncryption
DEBUG turn on/off.
Definition: OsEncryption.h:95
OsStatus encrypt(void)
operate after setting approp. input. NOTE: This will return OS_FAILED on vxworks. */ ...
Definition: OsEncryption.cpp:149