PTLib
Version 2.10.4
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
pssl.h
Go to the documentation of this file.
1
/*
2
* pssl.h
3
*
4
* Secure Sockets Layer channel interface class.
5
*
6
* Portable Windows Library
7
*
8
* Copyright (c) 1993-2002 Equivalence Pty. Ltd.
9
*
10
* The contents of this file are subject to the Mozilla Public License
11
* Version 1.0 (the "License"); you may not use this file except in
12
* compliance with the License. You may obtain a copy of the License at
13
* http://www.mozilla.org/MPL/
14
*
15
* Software distributed under the License is distributed on an "AS IS"
16
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17
* the License for the specific language governing rights and limitations
18
* under the License.
19
*
20
* The Original Code is Portable Windows Library.
21
*
22
* The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23
*
24
* Contributor(s): ______________________________________.
25
*
26
* $Revision: 25519 $
27
* $Author: rjongbloed $
28
* $Date: 2011-04-06 03:26:18 -0500 (Wed, 06 Apr 2011) $
29
*/
30
31
#ifndef PTLIB_PSSL_H
32
#define PTLIB_PSSL_H
33
34
#ifdef P_USE_PRAGMA
35
#pragma interface
36
#endif
37
38
#include <
ptlib/sockets.h
>
39
40
41
struct
ssl_st;
42
struct
ssl_ctx_st;
43
struct
x509_st;
44
struct
evp_pkey_st;
45
struct
dh_st;
46
47
enum
PSSLFileTypes
{
48
PSSLFileTypePEM
,
49
PSSLFileTypeASN1
,
50
PSSLFileTypeDEFAULT
51
};
52
53
58
class
PSSLPrivateKey
:
public
PObject
59
{
60
PCLASSINFO(
PSSLPrivateKey
,
PObject
);
61
public
:
64
PSSLPrivateKey
();
65
68
PSSLPrivateKey
(
69
unsigned
modulus,
70
void
(*callback)(
int
,
int
,
void
*) = NULL,
71
void
*cb_arg = NULL
72
);
73
79
PSSLPrivateKey
(
80
const
PFilePath
& keyFile,
81
PSSLFileTypes
fileType =
PSSLFileTypeDEFAULT
82
);
83
86
PSSLPrivateKey
(
87
const
BYTE * keyData,
88
PINDEX keySize
89
);
90
93
PSSLPrivateKey
(
94
const
PBYTEArray
& keyData
95
);
96
99
PSSLPrivateKey
(
100
const
PSSLPrivateKey
& privKey
101
);
102
105
PSSLPrivateKey
&
operator=
(
106
const
PSSLPrivateKey
& privKay
107
);
108
111
~PSSLPrivateKey
();
112
115
operator
evp_pkey_st *()
const
{
return
key
; }
116
119
PBoolean
Create
(
120
unsigned
modulus,
121
void
(*callback)(
int
,
int
,
void
*) = NULL,
122
void
*cb_arg = NULL
123
);
124
127
PBYTEArray
GetData
()
const
;
128
131
PString
AsString
()
const
;
132
138
PBoolean
Load
(
139
const
PFilePath
& keyFile,
140
PSSLFileTypes
fileType =
PSSLFileTypeDEFAULT
141
);
142
148
PBoolean
Save
(
149
const
PFilePath
& keyFile,
150
PBoolean
append =
false
,
151
PSSLFileTypes
fileType =
PSSLFileTypeDEFAULT
152
);
153
154
155
protected
:
156
evp_pkey_st *
key
;
157
};
158
159
164
class
PSSLCertificate
:
public
PObject
165
{
166
PCLASSINFO(
PSSLCertificate
,
PObject
);
167
public
:
170
PSSLCertificate
();
171
177
PSSLCertificate
(
178
const
PFilePath
& certFile,
179
PSSLFileTypes
fileType =
PSSLFileTypeDEFAULT
180
);
181
184
PSSLCertificate
(
185
const
BYTE * certData,
186
PINDEX certSize
187
);
188
191
PSSLCertificate
(
192
const
PBYTEArray
& certData
193
);
194
197
PSSLCertificate
(
198
const
PString
& certString
199
);
200
203
PSSLCertificate
(
204
const
PSSLCertificate
& cert
205
);
206
209
PSSLCertificate
&
operator=
(
210
const
PSSLCertificate
& cert
211
);
212
215
~PSSLCertificate
();
216
219
operator
x509_st *()
const
{
return
certificate
; }
220
229
PBoolean
CreateRoot
(
230
const
PString
& subject,
231
const
PSSLPrivateKey
& key
232
);
233
236
PBYTEArray
GetData
()
const
;
237
240
PString
AsString
()
const
;
241
247
PBoolean
Load
(
248
const
PFilePath
& certFile,
249
PSSLFileTypes
fileType =
PSSLFileTypeDEFAULT
250
);
251
257
PBoolean
Save
(
258
const
PFilePath
& keyFile,
259
PBoolean
append =
false
,
260
PSSLFileTypes
fileType =
PSSLFileTypeDEFAULT
261
);
262
263
264
protected
:
265
x509_st *
certificate
;
266
};
267
268
273
class
PSSLDiffieHellman
:
public
PObject
274
{
275
PCLASSINFO(
PSSLDiffieHellman
,
PObject
);
276
public
:
279
PSSLDiffieHellman
();
280
286
PSSLDiffieHellman
(
287
const
PFilePath
& dhFile,
288
PSSLFileTypes
fileType =
PSSLFileTypeDEFAULT
289
);
290
293
PSSLDiffieHellman
(
294
const
BYTE * pData,
295
PINDEX pSize,
296
const
BYTE * gData,
297
PINDEX gSize
298
);
299
302
PSSLDiffieHellman
(
303
const
PSSLDiffieHellman
&
dh
304
);
305
308
PSSLDiffieHellman
&
operator=
(
309
const
PSSLDiffieHellman
& dh
310
);
311
314
~PSSLDiffieHellman
();
315
318
operator
dh_st *()
const
{
return
dh
; }
319
325
PBoolean
Load
(
326
const
PFilePath
& dhFile,
327
PSSLFileTypes
fileType =
PSSLFileTypeDEFAULT
328
);
329
330
protected
:
331
dh_st *
dh
;
332
};
333
334
340
class
PSSLContext
{
341
public
:
342
enum
Method
{
343
SSLv23
,
344
SSLv3
,
345
TLSv1
346
};
347
356
PSSLContext
(
357
const
void
* sessionId = NULL,
358
PINDEX idSize = 0
359
);
360
PSSLContext
(
361
Method
method,
362
const
void
* sessionId = NULL,
363
PINDEX idSize = 0
364
);
365
368
~PSSLContext
();
369
372
operator
ssl_ctx_st *()
const
{
return
context
; }
373
376
PBoolean
SetCAPath
(
377
const
PDirectory
& caPath
378
);
379
382
PBoolean
SetCAFile
(
383
const
PFilePath
& caFile
384
);
385
388
PBoolean
UseCertificate
(
389
const
PSSLCertificate
& certificate
390
);
391
394
PBoolean
UsePrivateKey
(
395
const
PSSLPrivateKey
& key
396
);
397
400
PBoolean
UseDiffieHellman
(
401
const
PSSLDiffieHellman
& dh
402
);
403
406
PBoolean
SetCipherList
(
407
const
PString
& ciphers
408
);
409
410
protected
:
411
void
Construct
(
Method
method,
const
void
* sessionId, PINDEX idSize);
412
ssl_ctx_st *
context
;
413
};
414
415
418
class
PSSLChannel
:
public
PIndirectChannel
419
{
420
PCLASSINFO
(
PSSLChannel
,
PIndirectChannel
)
421
public
:
425
PSSLChannel
(
426
PSSLContext
*
context
= NULL,
427
PBoolean
autoDeleteContext
=
false
428
);
429
PSSLChannel
(
430
PSSLContext
&
context
431
);
432
435
~PSSLChannel
();
436
437
// Overrides from PChannel
438
virtual
PBoolean
Read
(
void
* buf, PINDEX len);
439
virtual
PBoolean
Write
(
const
void
* buf, PINDEX len);
440
virtual
PBoolean
Close
();
441
virtual
PBoolean
Shutdown
(
ShutdownValue
) {
return
true
; }
442
virtual
PString
GetErrorText
(
ErrorGroup
group =
NumErrorGroups
)
const
;
443
virtual
PBoolean
ConvertOSError
(
int
error,
ErrorGroup
group =
LastGeneralError
);
444
445
// New functions
450
PBoolean
Accept
();
451
454
PBoolean
Accept
(
455
PChannel
& channel
456
);
457
460
PBoolean
Accept
(
461
PChannel
* channel,
462
PBoolean
autoDelete =
true
463
);
464
465
470
PBoolean
Connect
();
471
474
PBoolean
Connect
(
475
PChannel
& channel
476
);
477
480
PBoolean
Connect
(
481
PChannel
* channel,
482
PBoolean
autoDelete =
true
483
);
484
487
PBoolean
UseCertificate
(
488
const
PSSLCertificate
& certificate
489
);
490
493
PBoolean
UsePrivateKey
(
494
const
PSSLPrivateKey
& key
495
);
496
497
enum
VerifyMode
{
498
VerifyNone
,
499
VerifyPeer
,
500
VerifyPeerMandatory
,
501
};
502
503
void
SetVerifyMode
(
504
VerifyMode
mode
505
);
506
507
PSSLContext
*
GetContext
()
const
{
return
context
; }
508
509
virtual
PBoolean
RawSSLRead
(
void
* buf, PINDEX & len);
510
511
protected
:
521
virtual
PBoolean
OnOpen
();
522
523
protected
:
524
PSSLContext
*
context
;
525
PBoolean
autoDeleteContext
;
526
ssl_st *
ssl
;
527
};
528
529
#endif // PTLIB_PSSL_H
530
531
532
// End Of File ///////////////////////////////////////////////////////////////
include
ptclib
pssl.h
Generated on Tue Mar 11 2014 15:09:29 for PTLib by
1.8.1.2