PTLib  Version 2.10.10
 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 
51 };
52 
53 
58 class PSSLPrivateKey : public PObject
59 {
60  PCLASSINFO(PSSLPrivateKey, PObject);
61  public:
65 
69  unsigned modulus,
70  void (*callback)(int,int,void *) = NULL,
71  void *cb_arg = NULL
72  );
73 
80  const PFilePath & keyFile,
82  );
83 
87  const BYTE * keyData,
88  PINDEX keySize
89  );
90 
94  const PBYTEArray & keyData
95  );
96 
100  const PSSLPrivateKey & privKey
101  );
102 
106  const PSSLPrivateKey & privKay
107  );
108 
111  ~PSSLPrivateKey();
112 
115  operator evp_pkey_st *() const { return key; }
116 
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,
141  );
142 
148  PBoolean Save(
149  const PFilePath & keyFile,
150  PBoolean append = false,
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 
178  const PFilePath & certFile,
180  );
181 
185  const BYTE * certData,
186  PINDEX certSize
187  );
188 
192  const PBYTEArray & certData
193  );
194 
198  const PString & certString
199  );
200 
204  const PSSLCertificate & cert
205  );
206 
210  const PSSLCertificate & cert
211  );
212 
216 
219  operator x509_st *() const { return certificate; }
220 
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,
250  );
251 
257  PBoolean Save(
258  const PFilePath & keyFile,
259  PBoolean append = false,
261  );
262 
263 
264  protected:
265  x509_st * certificate;
266 };
267 
268 
274 {
275  PCLASSINFO(PSSLDiffieHellman, PObject);
276  public:
280 
287  const PFilePath & dhFile,
289  );
290 
294  const BYTE * pData,
295  PINDEX pSize,
296  const BYTE * gData,
297  PINDEX gSize
298  );
299 
303  const PSSLDiffieHellman & dh
304  );
305 
309  const PSSLDiffieHellman & dh
310  );
311 
315 
318  operator dh_st *() const { return dh; }
319 
325  PBoolean Load(
326  const PFilePath & dhFile,
328  );
329 
330  protected:
331  dh_st * dh;
332 };
333 
334 
340 class PSSLContext {
341  public:
342  enum Method {
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 
377  const PDirectory & caPath
378  );
379 
383  const PFilePath & caFile
384  );
385 
389  const PSSLCertificate & certificate
390  );
391 
395  const PSSLPrivateKey & key
396  );
397 
401  const PSSLDiffieHellman & dh
402  );
403 
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 
419 {
421  public:
425  PSSLChannel(
426  PSSLContext * context = NULL,
427  PBoolean autoDeleteContext = false
428  );
429  PSSLChannel(
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 
455  PChannel & channel
456  );
457 
461  PChannel * channel,
462  PBoolean autoDelete = true
463  );
464 
465 
470  PBoolean Connect();
471 
475  PChannel & channel
476  );
477 
481  PChannel * channel,
482  PBoolean autoDelete = true
483  );
484 
488  const PSSLCertificate & certificate
489  );
490 
494  const PSSLPrivateKey & key
495  );
496 
497  enum VerifyMode {
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:
526  ssl_st * ssl;
527 };
528 
529 #endif // PTLIB_PSSL_H
530 
531 
532 // End Of File ///////////////////////////////////////////////////////////////