Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

pssl.h

Go to the documentation of this file.
00001 /* 00002 * pssl.h 00003 * 00004 * Secure Sockets Layer channel interface class. 00005 * 00006 * Portable Windows Library 00007 * 00008 * Copyright (c) 1993-2002 Equivalence Pty. Ltd. 00009 * 00010 * The contents of this file are subject to the Mozilla Public License 00011 * Version 1.0 (the "License"); you may not use this file except in 00012 * compliance with the License. You may obtain a copy of the License at 00013 * http://www.mozilla.org/MPL/ 00014 * 00015 * Software distributed under the License is distributed on an "AS IS" 00016 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00017 * the License for the specific language governing rights and limitations 00018 * under the License. 00019 * 00020 * The Original Code is Portable Windows Library. 00021 * 00022 * The Initial Developer of the Original Code is Equivalence Pty. Ltd. 00023 * 00024 * Contributor(s): ______________________________________. 00025 * 00026 * $Log: pssl.h,v $ 00027 * Revision 1.19 2002/11/06 22:47:24 robertj 00028 * Fixed header comment (copyright etc) 00029 * 00030 * Revision 1.18 2002/09/16 01:08:59 robertj 00031 * Added #define so can select if #pragma interface/implementation is used on 00032 * platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan. 00033 * 00034 * Revision 1.17 2002/03/28 07:26:36 robertj 00035 * Added Diffie-Hellman parameters wrapper class. 00036 * 00037 * Revision 1.16 2001/12/13 09:15:20 robertj 00038 * Added function to get private key as ray DER binary data or as base64 string. 00039 * 00040 * Revision 1.15 2001/12/06 04:06:03 robertj 00041 * Removed "Win32 SSL xxx" build configurations in favour of system 00042 * environment variables to select optional libraries. 00043 * 00044 * Revision 1.14 2001/10/31 01:30:40 robertj 00045 * Added enhancements for saving/loading/creating certificates and keys. 00046 * 00047 * Revision 1.13 2001/09/10 02:51:22 robertj 00048 * Major change to fix problem with error codes being corrupted in a 00049 * PChannel when have simultaneous reads and writes in threads. 00050 * 00051 * Revision 1.12 2001/06/01 00:53:59 robertj 00052 * Added certificate constructor that takes a PBYTEArray 00053 * 00054 * Revision 1.11 2001/05/16 06:02:05 craigs 00055 * Changed to allow detection of non-SSL connection to SecureHTTPServiceProcess 00056 * 00057 * Revision 1.10 2000/11/14 08:33:16 robertj 00058 * Added certificate and private key classes. 00059 * 00060 * Revision 1.9 2000/08/25 08:11:02 robertj 00061 * Fixed OpenSSL support so can operate as a server channel. 00062 * 00063 * Revision 1.8 2000/08/04 12:52:18 robertj 00064 * SSL changes, added error functions, removed need to have openssl include directory in app. 00065 * 00066 * Revision 1.7 2000/01/10 02:23:18 craigs 00067 * Update for new OpenSSL 00068 * 00069 * Revision 1.6 1999/02/16 08:07:10 robertj 00070 * MSVC 6.0 compatibility changes. 00071 * 00072 * Revision 1.5 1998/12/04 13:01:51 craigs 00073 * Changed for SSLeay 0.9 00074 * 00075 * Revision 1.4 1998/09/23 06:19:50 robertj 00076 * Added open source copyright license. 00077 * 00078 * Revision 1.3 1997/05/04 02:49:52 craigs 00079 * Added support for client and server certificates 00080 * 00081 * Revision 1.1 1996/11/15 07:37:48 craigs 00082 * Initial revision 00083 * 00084 */ 00085 00086 #ifndef _PSSL_H 00087 #define _PSSL_H 00088 00089 #ifdef P_USE_PRAGMA 00090 #pragma interface 00091 #endif 00092 00093 #include <ptlib/sockets.h> 00094 00095 00096 struct ssl_st; 00097 struct ssl_ctx_st; 00098 struct x509_st; 00099 struct evp_pkey_st; 00100 struct dh_st; 00101 00102 enum PSSLFileTypes { 00103 PSSLFileTypePEM, 00104 PSSLFileTypeASN1, 00105 PSSLFileTypeDEFAULT 00106 }; 00107 00108 00113 class PSSLPrivateKey : public PObject 00114 { 00115 PCLASSINFO(PSSLPrivateKey, PObject); 00116 public: 00119 PSSLPrivateKey(); 00120 00123 PSSLPrivateKey( 00124 unsigned modulus, 00125 void (*callback)(int,int,void *) = NULL, 00126 void *cb_arg = NULL 00127 ); 00128 00134 PSSLPrivateKey( 00135 const PFilePath & keyFile, 00136 PSSLFileTypes fileType = PSSLFileTypeDEFAULT 00137 ); 00138 00141 PSSLPrivateKey( 00142 const BYTE * keyData, 00143 PINDEX keySize 00144 ); 00145 00148 PSSLPrivateKey( 00149 const PBYTEArray & keyData 00150 ); 00151 00154 PSSLPrivateKey( 00155 const PSSLPrivateKey & privKey 00156 ); 00157 00160 PSSLPrivateKey & operator=( 00161 const PSSLPrivateKey & privKay 00162 ); 00163 00166 ~PSSLPrivateKey(); 00167 00170 operator evp_pkey_st *() const { return key; } 00171 00174 BOOL Create( 00175 unsigned modulus, 00176 void (*callback)(int,int,void *) = NULL, 00177 void *cb_arg = NULL 00178 ); 00179 00182 PBYTEArray GetData() const; 00183 00186 PString AsString() const; 00187 00193 BOOL Load( 00194 const PFilePath & keyFile, 00195 PSSLFileTypes fileType = PSSLFileTypeDEFAULT 00196 ); 00197 00203 BOOL Save( 00204 const PFilePath & keyFile, 00205 BOOL append = FALSE, 00206 PSSLFileTypes fileType = PSSLFileTypeDEFAULT 00207 ); 00208 00209 00210 protected: 00211 evp_pkey_st * key; 00212 }; 00213 00214 00219 class PSSLCertificate : public PObject 00220 { 00221 PCLASSINFO(PSSLCertificate, PObject); 00222 public: 00225 PSSLCertificate(); 00226 00232 PSSLCertificate( 00233 const PFilePath & certFile, 00234 PSSLFileTypes fileType = PSSLFileTypeDEFAULT 00235 ); 00236 00239 PSSLCertificate( 00240 const BYTE * certData, 00241 PINDEX certSize 00242 ); 00243 00246 PSSLCertificate( 00247 const PBYTEArray & certData 00248 ); 00249 00252 PSSLCertificate( 00253 const PString & certString 00254 ); 00255 00258 PSSLCertificate( 00259 const PSSLCertificate & cert 00260 ); 00261 00264 PSSLCertificate & operator=( 00265 const PSSLCertificate & cert 00266 ); 00267 00270 ~PSSLCertificate(); 00271 00274 operator x509_st *() const { return certificate; } 00275 00284 BOOL CreateRoot( 00285 const PString & subject, 00286 const PSSLPrivateKey & key 00287 ); 00288 00291 PBYTEArray GetData() const; 00292 00295 PString AsString() const; 00296 00302 BOOL Load( 00303 const PFilePath & certFile, 00304 PSSLFileTypes fileType = PSSLFileTypeDEFAULT 00305 ); 00306 00312 BOOL Save( 00313 const PFilePath & keyFile, 00314 BOOL append = FALSE, 00315 PSSLFileTypes fileType = PSSLFileTypeDEFAULT 00316 ); 00317 00318 00319 protected: 00320 x509_st * certificate; 00321 }; 00322 00323 00328 class PSSLDiffieHellman : public PObject 00329 { 00330 PCLASSINFO(PSSLDiffieHellman, PObject); 00331 public: 00334 PSSLDiffieHellman(); 00335 00341 PSSLDiffieHellman( 00342 const PFilePath & dhFile, 00343 PSSLFileTypes fileType = PSSLFileTypeDEFAULT 00344 ); 00345 00348 PSSLDiffieHellman( 00349 const BYTE * pData, 00350 PINDEX pSize, 00351 const BYTE * gData, 00352 PINDEX gSize 00353 ); 00354 00357 PSSLDiffieHellman( 00358 const PSSLDiffieHellman & dh 00359 ); 00360 00363 PSSLDiffieHellman & operator=( 00364 const PSSLDiffieHellman & dh 00365 ); 00366 00369 ~PSSLDiffieHellman(); 00370 00373 operator dh_st *() const { return dh; } 00374 00380 BOOL Load( 00381 const PFilePath & dhFile, 00382 PSSLFileTypes fileType = PSSLFileTypeDEFAULT 00383 ); 00384 00385 protected: 00386 dh_st * dh; 00387 }; 00388 00389 00395 class PSSLContext { 00396 public: 00404 PSSLContext( 00405 const void * sessionId = NULL, 00406 PINDEX idSize = 0 00407 ); 00408 00411 ~PSSLContext(); 00412 00415 operator ssl_ctx_st *() const { return context; } 00416 00419 BOOL SetCAPath( 00420 const PDirectory & caPath 00421 ); 00422 00425 BOOL SetCAFile( 00426 const PFilePath & caFile 00427 ); 00428 00431 BOOL UseCertificate( 00432 const PSSLCertificate & certificate 00433 ); 00434 00437 BOOL UsePrivateKey( 00438 const PSSLPrivateKey & key 00439 ); 00440 00443 BOOL UseDiffieHellman( 00444 const PSSLDiffieHellman & dh 00445 ); 00446 00449 BOOL SetCipherList( 00450 const PString & ciphers 00451 ); 00452 00453 protected: 00454 ssl_ctx_st * context; 00455 }; 00456 00457 00460 class PSSLChannel : public PIndirectChannel 00461 { 00462 PCLASSINFO(PSSLChannel, PIndirectChannel) 00463 public: 00467 PSSLChannel( 00468 PSSLContext * context = NULL, 00469 BOOL autoDeleteContext = FALSE 00470 ); 00471 PSSLChannel( 00472 PSSLContext & context 00473 ); 00474 00477 ~PSSLChannel(); 00478 00479 // Overrides from PChannel 00480 virtual BOOL Read(void * buf, PINDEX len); 00481 virtual BOOL Write(const void * buf, PINDEX len); 00482 virtual BOOL Close(); 00483 virtual BOOL Shutdown(ShutdownValue) { return TRUE; } 00484 virtual PString GetErrorText(ErrorGroup group = NumErrorGroups) const; 00485 virtual BOOL ConvertOSError(int error, ErrorGroup group = LastGeneralError); 00486 00487 // New functions 00492 BOOL Accept(); 00493 00496 BOOL Accept( 00497 PChannel & channel 00498 ); 00499 00502 BOOL Accept( 00503 PChannel * channel, 00504 BOOL autoDelete = TRUE 00505 ); 00506 00507 00512 BOOL Connect(); 00513 00516 BOOL Connect( 00517 PChannel & channel 00518 ); 00519 00522 BOOL Connect( 00523 PChannel * channel, 00524 BOOL autoDelete = TRUE 00525 ); 00526 00529 BOOL UseCertificate( 00530 const PSSLCertificate & certificate 00531 ); 00532 00535 BOOL UsePrivateKey( 00536 const PSSLPrivateKey & key 00537 ); 00538 00539 enum VerifyMode { 00540 VerifyNone, 00541 VerifyPeer, 00542 VerifyPeerMandatory, 00543 }; 00544 00545 void SetVerifyMode( 00546 VerifyMode mode 00547 ); 00548 00549 PSSLContext * GetContext() const { return context; } 00550 00551 virtual BOOL RawSSLRead(void * buf, PINDEX & len); 00552 00553 protected: 00563 virtual BOOL OnOpen(); 00564 00565 protected: 00566 PSSLContext * context; 00567 BOOL autoDeleteContext; 00568 ssl_st * ssl; 00569 }; 00570 00571 #endif // _PSSL_H

Generated on Sat Jul 24 15:35:56 2004 for PWLib by doxygen 1.3.7