pssl.h
Go to the documentation of this file.
/*
* pssl.h
*
* Secure Sockets Layer channel interface class.
*
* Portable Windows Library
*
* Copyright (c) 1993-2002 Equivalence Pty. Ltd.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Portable Windows Library.
*
* The Initial Developer of the Original Code is Equivalence Pty. Ltd.
*
* Contributor(s): ______________________________________.
*
* $Revision: 25519 $
* $Author: rjongbloed $
* $Date: 2011-04-06 03:26:18 -0500 (Wed, 06 Apr 2011) $
*/
#ifndef PTLIB_PSSL_H
#define PTLIB_PSSL_H
#ifdef P_USE_PRAGMA
#pragma interface
#endif
#include <ptlib/sockets.h>
struct ssl_st;
struct ssl_ctx_st;
struct x509_st;
struct evp_pkey_st;
struct dh_st;
enum PSSLFileTypes {
PSSLFileTypePEM,
PSSLFileTypeASN1,
PSSLFileTypeDEFAULT
};
class PSSLPrivateKey : public PObject
{
PCLASSINFO(PSSLPrivateKey, PObject);
public:
PSSLPrivateKey();
PSSLPrivateKey(
unsigned modulus,
void (*callback)(int,int,void *) = NULL,
void *cb_arg = NULL
);
PSSLPrivateKey(
const PFilePath & keyFile,
PSSLFileTypes fileType = PSSLFileTypeDEFAULT
);
PSSLPrivateKey(
const BYTE * keyData,
PINDEX keySize
);
PSSLPrivateKey(
const PBYTEArray & keyData
);
PSSLPrivateKey(
const PSSLPrivateKey & privKey
);
PSSLPrivateKey & operator=(
const PSSLPrivateKey & privKay
);
~PSSLPrivateKey();
operator evp_pkey_st *() const { return key; }
PBoolean Create(
unsigned modulus,
void (*callback)(int,int,void *) = NULL,
void *cb_arg = NULL
);
PBYTEArray GetData() const;
PString AsString() const;
PBoolean Load(
const PFilePath & keyFile,
PSSLFileTypes fileType = PSSLFileTypeDEFAULT
);
PBoolean Save(
const PFilePath & keyFile,
PBoolean append = false,
PSSLFileTypes fileType = PSSLFileTypeDEFAULT
);
protected:
evp_pkey_st * key;
};
class PSSLCertificate : public PObject
{
PCLASSINFO(PSSLCertificate, PObject);
public:
PSSLCertificate();
PSSLCertificate(
const PFilePath & certFile,
PSSLFileTypes fileType = PSSLFileTypeDEFAULT
);
PSSLCertificate(
const BYTE * certData,
PINDEX certSize
);
PSSLCertificate(
const PBYTEArray & certData
);
PSSLCertificate(
const PString & certString
);
PSSLCertificate(
const PSSLCertificate & cert
);
PSSLCertificate & operator=(
const PSSLCertificate & cert
);
~PSSLCertificate();
operator x509_st *() const { return certificate; }
PBoolean CreateRoot(
const PString & subject,
const PSSLPrivateKey & key
);
PBYTEArray GetData() const;
PString AsString() const;
PBoolean Load(
const PFilePath & certFile,
PSSLFileTypes fileType = PSSLFileTypeDEFAULT
);
PBoolean Save(
const PFilePath & keyFile,
PBoolean append = false,
PSSLFileTypes fileType = PSSLFileTypeDEFAULT
);
protected:
x509_st * certificate;
};
class PSSLDiffieHellman : public PObject
{
PCLASSINFO(PSSLDiffieHellman, PObject);
public:
PSSLDiffieHellman();
PSSLDiffieHellman(
const PFilePath & dhFile,
PSSLFileTypes fileType = PSSLFileTypeDEFAULT
);
PSSLDiffieHellman(
const BYTE * pData,
PINDEX pSize,
const BYTE * gData,
PINDEX gSize
);
PSSLDiffieHellman(
const PSSLDiffieHellman & dh
);
PSSLDiffieHellman & operator=(
const PSSLDiffieHellman & dh
);
~PSSLDiffieHellman();
operator dh_st *() const { return dh; }
PBoolean Load(
const PFilePath & dhFile,
PSSLFileTypes fileType = PSSLFileTypeDEFAULT
);
protected:
dh_st * dh;
};
class PSSLContext {
public:
enum Method {
SSLv23,
SSLv3,
TLSv1
};
PSSLContext(
const void * sessionId = NULL,
PINDEX idSize = 0
);
PSSLContext(
Method method,
const void * sessionId = NULL,
PINDEX idSize = 0
);
~PSSLContext();
operator ssl_ctx_st *() const { return context; }
PBoolean SetCAPath(
const PDirectory & caPath
);
PBoolean SetCAFile(
const PFilePath & caFile
);
PBoolean UseCertificate(
const PSSLCertificate & certificate
);
PBoolean UsePrivateKey(
const PSSLPrivateKey & key
);
PBoolean UseDiffieHellman(
const PSSLDiffieHellman & dh
);
PBoolean SetCipherList(
const PString & ciphers
);
protected:
void Construct(Method method, const void * sessionId, PINDEX idSize);
ssl_ctx_st * context;
};
class PSSLChannel : public PIndirectChannel
{
PCLASSINFO(PSSLChannel, PIndirectChannel)
public:
PSSLChannel(
PSSLContext * context = NULL,
PBoolean autoDeleteContext = false
);
PSSLChannel(
PSSLContext & context
);
~PSSLChannel();
// Overrides from PChannel
virtual PBoolean Read(void * buf, PINDEX len);
virtual PBoolean Write(const void * buf, PINDEX len);
virtual PBoolean Close();
virtual PBoolean Shutdown(ShutdownValue) { return true; }
virtual PString GetErrorText(ErrorGroup group = NumErrorGroups) const;
virtual PBoolean ConvertOSError(int error, ErrorGroup group = LastGeneralError);
// New functions
PBoolean Accept();
PBoolean Accept(
PChannel & channel
);
PBoolean Accept(
PChannel * channel,
PBoolean autoDelete = true
);
PBoolean Connect();
PBoolean Connect(
PChannel & channel
);
PBoolean Connect(
PChannel * channel,
PBoolean autoDelete = true
);
PBoolean UseCertificate(
const PSSLCertificate & certificate
);
PBoolean UsePrivateKey(
const PSSLPrivateKey & key
);
enum VerifyMode {
VerifyNone,
VerifyPeer,
VerifyPeerMandatory,
};
void SetVerifyMode(
VerifyMode mode
);
PSSLContext * GetContext() const { return context; }
virtual PBoolean RawSSLRead(void * buf, PINDEX & len);
protected:
virtual PBoolean OnOpen();
protected:
PSSLContext * context;
PBoolean autoDeleteContext;
ssl_st * ssl;
};
#endif // PTLIB_PSSL_H
// End Of File ///////////////////////////////////////////////////////////////
PSSLPrivateKey::operator=
PSSLPrivateKey & operator=(const PSSLPrivateKey &privKay)
Create a copy of the private key.
PSSLFileTypePEM
Definition: pssl.h:48
PSSLChannel::VerifyMode
VerifyMode
Definition: pssl.h:497
PChannel::NumErrorGroups
Definition: channel.h:569
PSSLCertificate::certificate
x509_st * certificate
Definition: pssl.h:265
PSSLContext::SetCipherList
PBoolean SetCipherList(const PString &ciphers)
Set the available ciphers to those listed.
PSSLFileTypeASN1
Definition: pssl.h:49
PSSLChannel::GetErrorText
virtual PString GetErrorText(ErrorGroup group=NumErrorGroups) const
Get error message description.
PSSLContext::Construct
void Construct(Method method, const void *sessionId, PINDEX idSize)
PCLASSINFO
#define PCLASSINFO(cls, par)
Declare all the standard PTLib class information.
Definition: object.h:1049
PSSLContext::Method
Method
Definition: pssl.h:342
PSSLCertificate::~PSSLCertificate
~PSSLCertificate()
Destroy and release storage for certificate.
PSSLChannel::UseCertificate
PBoolean UseCertificate(const PSSLCertificate &certificate)
Use the certificate specified.
PSSLPrivateKey::Create
PBoolean Create(unsigned modulus, void(*callback)(int, int, void *)=NULL, void *cb_arg=NULL)
Create a new private key.
PSSLContext::SetCAPath
PBoolean SetCAPath(const PDirectory &caPath)
Set the path to locate CA certificates.
PChannel::LastGeneralError
Error during other operation, eg Open()
Definition: channel.h:568
PSSLContext::PSSLContext
PSSLContext(const void *sessionId=NULL, PINDEX idSize=0)
Create a new context for SSL channels.
PSSLChannel::UsePrivateKey
PBoolean UsePrivateKey(const PSSLPrivateKey &key)
Use the private key file specified.
PSSLCertificate
Certificate for SSL.
Definition: pssl.h:164
PSSLChannel::autoDeleteContext
PBoolean autoDeleteContext
Definition: pssl.h:525
PSSLChannel::ConvertOSError
virtual PBoolean ConvertOSError(int error, ErrorGroup group=LastGeneralError)
Convert an operating system error into platform independent error.
PFilePath
This class describes a full description for a file on the particular platform.
Definition: filepath.h:65
PSSLContext::UsePrivateKey
PBoolean UsePrivateKey(const PSSLPrivateKey &key)
Use the private key specified.
PSSLCertificate::AsString
PString AsString() const
Get the certificate as ASN1 DER base64 encoded data.
PSSLChannel::VerifyNone
Definition: pssl.h:498
PSSLPrivateKey::~PSSLPrivateKey
~PSSLPrivateKey()
Destroy and release storage for private key.
PSSLCertificate::Load
PBoolean Load(const PFilePath &certFile, PSSLFileTypes fileType=PSSLFileTypeDEFAULT)
Load certificate from file.
PIndirectChannel
This is a channel that operates indirectly through another channel(s).
Definition: indchan.h:49
PSSLChannel::ssl
ssl_st * ssl
Definition: pssl.h:526
PSSLContext::UseCertificate
PBoolean UseCertificate(const PSSLCertificate &certificate)
Use the certificate specified.
PSSLPrivateKey::GetData
PBYTEArray GetData() const
Get the certificate as binary ASN1 DER encoded data.
PSSLFileTypeDEFAULT
Definition: pssl.h:50
PChannel::ShutdownValue
ShutdownValue
Definition: channel.h:433
PSSLPrivateKey
Private key for SSL.
Definition: pssl.h:58
PSSLChannel::VerifyPeerMandatory
Definition: pssl.h:500
PSSLPrivateKey::Save
PBoolean Save(const PFilePath &keyFile, PBoolean append=false, PSSLFileTypes fileType=PSSLFileTypeDEFAULT)
Save private key to file.
PSSLCertificate::GetData
PBYTEArray GetData() const
Get the certificate as binary ASN1 DER encoded data.
PSSLContext::TLSv1
Definition: pssl.h:345
PBoolean
BOOL PBoolean
Definition: object.h:102
PDirectory
Class to represent a directory in the operating system file system.
Definition: pdirect.h:182
PSSLDiffieHellman::dh
dh_st * dh
Definition: pssl.h:331
PSSLCertificate::CreateRoot
PBoolean CreateRoot(const PString &subject, const PSSLPrivateKey &key)
Create a new root certificate.
PSSLChannel::VerifyPeer
Definition: pssl.h:499
PSSLChannel::PSSLChannel
PSSLChannel(PSSLContext *context=NULL, PBoolean autoDeleteContext=false)
Create a new channel given the context.
PSSLChannel::RawSSLRead
virtual PBoolean RawSSLRead(void *buf, PINDEX &len)
PSSLContext::SSLv3
Definition: pssl.h:344
PBYTEArray
Array of unsigned characters.
Definition: array.h:670
PSSLContext::UseDiffieHellman
PBoolean UseDiffieHellman(const PSSLDiffieHellman &dh)
Use the Diffie-Hellman parameters specified.
PSSLContext::SSLv23
Definition: pssl.h:343
PSSLPrivateKey::Load
PBoolean Load(const PFilePath &keyFile, PSSLFileTypes fileType=PSSLFileTypeDEFAULT)
Load private key from file.
PChannel
Abstract class defining I/O channel semantics.
Definition: channel.h:107
PSSLChannel::Connect
PBoolean Connect()
Connect to remote server.
PSSLChannel::~PSSLChannel
~PSSLChannel()
Close and clear the SSL channel.
PString
The character string class.
Definition: pstring.h:108
PSSLDiffieHellman::~PSSLDiffieHellman
~PSSLDiffieHellman()
Destroy and release storage for Diffie-Hellman parameters.
PSSLContext
Context for SSL channels.
Definition: pssl.h:340
PSSLDiffieHellman::operator=
PSSLDiffieHellman & operator=(const PSSLDiffieHellman &dh)
Create a copy of the Diffie-Hellman parameters.
PSSLPrivateKey::key
evp_pkey_st * key
Definition: pssl.h:156
PSSLChannel
This class will start a secure SSL based channel.
Definition: pssl.h:418
PSSLChannel::OnOpen
virtual PBoolean OnOpen()
This callback is executed when the Open() function is called with open channels.
PSSLPrivateKey::AsString
PString AsString() const
Get the certificate as ASN1 DER base64 encoded data.
PChannel::ErrorGroup
ErrorGroup
Error groups.
Definition: channel.h:565
PSSLChannel::SetVerifyMode
void SetVerifyMode(VerifyMode mode)
PSSLDiffieHellman::Load
PBoolean Load(const PFilePath &dhFile, PSSLFileTypes fileType=PSSLFileTypeDEFAULT)
Load Diffie-Hellman parameters from file.
PSSLCertificate::PSSLCertificate
PSSLCertificate()
Create an empty certificate.
PSSLChannel::Shutdown
virtual PBoolean Shutdown(ShutdownValue)
Close one or both of the data streams associated with a channel.
Definition: pssl.h:441
PSSLChannel::Write
virtual PBoolean Write(const void *buf, PINDEX len)
Low level write to the channel.
PSSLChannel::Accept
PBoolean Accept()
Accept a new inbound connection (server).
PSSLChannel::Read
virtual PBoolean Read(void *buf, PINDEX len)
Low level read from the channel.
PSSLChannel::Close
virtual PBoolean Close()
Close the channel.
PSSLCertificate::operator=
PSSLCertificate & operator=(const PSSLCertificate &cert)
Create a copy of the certificate.
PSSLCertificate::Save
PBoolean Save(const PFilePath &keyFile, PBoolean append=false, PSSLFileTypes fileType=PSSLFileTypeDEFAULT)
Save certificate to file.
PSSLPrivateKey::PSSLPrivateKey
PSSLPrivateKey()
Create an empty private key.
sockets.h
PSSLDiffieHellman
Diffie-Hellman parameters for SSL.
Definition: pssl.h:273
PSSLChannel::context
PSSLContext * context
Definition: pssl.h:524
PSSLContext::SetCAFile
PBoolean SetCAFile(const PFilePath &caFile)
Set the CA certificate file.
PSSLChannel::GetContext
PSSLContext * GetContext() const
Definition: pssl.h:507
PObject
Ultimate parent class for all objects in the class library.
Definition: object.h:1118
PSSLContext::context
ssl_ctx_st * context
Definition: pssl.h:412
PSSLDiffieHellman::PSSLDiffieHellman
PSSLDiffieHellman()
Create an empty set of Diffie-Hellman parameters.
PSSLContext::~PSSLContext
~PSSLContext()
Clean up the SSL context.
PSSLFileTypes
PSSLFileTypes
Definition: pssl.h:47