42 struct evp_cipher_ctx_st;
58 #define PDECLARE_SSLPasswordNotifier(cls, fn) PDECLARE_NOTIFIER2(PString, cls, fn, bool)
77 void (*callback)(
int,
int,
void *) = NULL,
110 evp_pkey_st * privKey,
111 bool duplicate =
true
120 evp_pkey_st * privKay
129 operator evp_pkey_st *()
const {
return m_pkey; }
133 void Attach(evp_pkey_st * key);
139 void (*callback)(
int,
int,
void *) = NULL,
221 const BYTE * certData,
244 bool duplicate =
true
266 void Attach(x509_st * cert);
284 const char * digest = NULL,
335 void PrintOn(ostream & strm)
const;
363 CheckHostNormalRules,
364 CheckHostAlwaysUseSubject,
365 CheckHostNoWildcards,
366 CheckHostNoPartialWildcards,
367 CheckHostMultiLabelWildcards,
368 CheckHostSingleLabelDomains
375 CheckHostFlags flags = CheckHostNormalRules
430 HashType
GetHash()
const {
return m_hashAlogorithm; }
431 void SetHash(HashType hash) { m_hashAlogorithm = hash; }
434 HashType m_hashAlogorithm;
470 const BYTE * pubKey = NULL
504 operator dh_st *()
const {
return m_dh; }
541 bool Construct(
const BYTE * pData, PINDEX pSize,
542 const BYTE * gData, PINDEX gSize,
543 const BYTE * kData, PINDEX kSize);
551 class PAESContext :
public PObject
557 PAESContext(
bool encrypt,
const void * key, PINDEX numBits);
560 void SetEncrypt(
const void * key, PINDEX numBits);
561 void SetDecrypt(
const void * key, PINDEX numBits);
563 void Encrypt(
const void * in,
void * out);
564 void Decrypt(
const void * in,
void * out);
585 operator evp_cipher_ctx_st *()
const {
return m_context; }
604 bool SetKey(
const BYTE * keyPtr, PINDEX keyLen);
609 bool SetIV(
const BYTE * ivPtr, PINDEX ivLen);
670 bool UpdateCTS(
unsigned char *out,
int *outl,
const unsigned char *in,
int inl);
675 bool UpdateLoose(
unsigned char *out,
int *outl,
const unsigned char *in,
int inl);
676 bool DecryptUpdateLoose(
unsigned char *out,
int *outl,
const unsigned char *in,
int inl);
695 void Update(
const void * data, PINDEX length);
701 static void Process(
const void * data, PINDEX length,
Digest result);
745 const void * sessionId = NULL,
750 const void * sessionId = NULL,
857 const char * extension
863 void Construct(
const void * sessionId, PINDEX idSize);
979 #define PDECLARE_SSLVerifyNotifier(cls, fn) PDECLARE_NOTIFIER2(PSSLChannel, cls, fn, PSSLChannel::VerifyInfo &)
980 #define PCREATE_SSLVerifyNotifier(fn) PCREATE_NOTIFIER2(fn, PSSLChannel::VerifyInfo &)
1018 PSSLCertificate::CheckHostFlags flags = PSSLCertificate::CheckHostNormalRules
1025 operator ssl_st *()
const {
return m_ssl; }
1034 static int BioRead(bio_st * bio,
char * buf,
int len);
1035 static int BioWrite(bio_st * bio,
const char * buf,
int len);
1036 static long BioControl(bio_st * bio,
int cmd,
long num,
void * ptr);
1039 virtual int BioRead(
char * buf,
int len);
1040 virtual int BioWrite(
const char * buf,
int len);
1041 virtual long BioControl(
int cmd,
long num,
void * ptr);
1068 bool autoDeleteContext =
false
1101 PINDEX materialSize,
1111 #endif // PTLIB_PSSL_H
PSSLPrivateKey & operator=(const PSSLPrivateKey &privKay)
Create a copy of the private key.
SHAstate_st * m_context
Definition: pssl.h:705
std::list< x509_st * > X509_Chain
Definition: pssl.h:380
x509_st * m_certificate
Definition: pssl.h:385
static int BioRead(bio_st *bio, char *buf, int len)
virtual void OnVerify(VerifyInfo &info)
Call back for certificate verification.
bool DecryptFinalLoose(unsigned char *out, int *outl)
bool SetCredentials(const PString &authority, const PString &certificate, const PString &privateKey, bool create=false)
Set the credentials for the context.
bool SetServerNameIndication(const PString &name)
Set the Server Name Indication TLS extension.
PadMode m_padMode
Definition: pssl.h:661
static void Process(const void *data, PINDEX length, Digest result)
PBYTEArray GetKeyMaterial(PINDEX materialSize, const char *name) const
Get the key material after exchange completed.
Definition: channel.h:255
PCaselessString GetSelectedProfile() const
Get the selected profile name.
static const Method HighestDTLS
Definition: pssl.h:734
virtual PString GetErrorText(ErrorGroup group=NumErrorGroups) const
Get error message description.
bool ComputeSessionKey(const PBYTEArray &otherHalf)
Compute the session key, geven other half-key.
P_DECLARE_ENUM(HashType, HashMd5, HashSha1, HashSha256, HashSha512)
PString GetCommonName() const
#define PCLASSINFO(cls, par)
Declare all the standard PTLib class information.
Definition: object.h:2164
~PSSLCertificate()
Destroy and release storage for certificate.
PBoolean UseCertificate(const PSSLCertificate &certificate)
Use the certificate specified.
PBoolean Create(unsigned modulus, void(*callback)(int, int, void *)=NULL, void *cb_arg=NULL)
Create a new private key.
const PBYTEArray & GetSessionKey() const
Get the session key value.
Definition: pssl.h:538
PString AsString(int indent=-1) const
bool FromString(const PString &str)
void SetVerifyMode(VerifyMode mode, const VerifyNotifier ¬ifier=VerifyNotifier())
Set certificate verification mode for connection.
Error during other operation, eg Open()
Definition: channel.h:254
virtual PBoolean Write(const void *buf, PINDEX len)
Low level write to the channel.
bool m_ok
Definition: pssl.h:974
PSSLContext(const void *sessionId=NULL, PINDEX idSize=0)
Create a new context for SSL channels.
void Attach(evp_pkey_st *key)
Set internal OpenSSL private key structure.
bool IsValid() const
Return true if is a valid certificate.
Definition: pssl.h:270
virtual bool InternalConnect()
PBoolean UsePrivateKey(const PSSLPrivateKey &key)
Use the private key file specified.
static long BioControl(bio_st *bio, int cmd, long num, void *ptr)
PDECLARE_MUTEX(m_writeMutex)
Certificate for SSL.
Definition: pssl.h:200
This class describes a full description for a file on the particular platform.
Definition: filepath.h:61
PSSLCertificate m_peerCertificate
Definition: pssl.h:975
PINDEX GetBlockSize() const
Get the cipher block size.
PString AsString() const
Get the certificate as ASN1 DER base64 encoded data.
~PSSLPrivateKey()
Destroy and release storage for private key.
Comparison
Result of the comparison operation performed by the Compare() function.
Definition: object.h:2251
bool IsValid() const
Definition: pssl.h:337
bool SetExtension(const char *extension)
Set TLS extension.
bool UpdateCTS(unsigned char *out, int *outl, const unsigned char *in, int inl)
PBoolean Load(const PFilePath &certFile, PSSLFileTypes fileType=PSSLFileTypeDEFAULT)
Load certificate from file.
PINDEX GetIVLength() const
Get the cipher initial vector length.
dh_st * m_dh
Definition: pssl.h:545
This is a channel that operates indirectly through another channel(s).
Definition: indchan.h:45
bool DecryptUpdateLoose(unsigned char *out, int *outl, const unsigned char *in, int inl)
This class is a variation of a string that ignores case.
Definition: pstring.h:2012
bool EncryptFinalCTS(unsigned char *out, int *outl)
virtual PBoolean ConvertOSError(P_INT_PTR libcReturnValue, ErrorGroup group=LastGeneralError)
Convert an operating system error into platform independent error.
const X509_Chain & GetChain() const
Definition: pssl.h:381
bool AddClientCA(const PSSLCertificate &certificate)
Set the CA certificate(s) to send to client from server.
unsigned char m_pad_buf[32]
Definition: pssl.h:666
void Update(const PString &str)
Definition: pssl.h:696
Method GetMethod() const
Definition: pssl.h:860
PSSLCertificateFingerprint()
Create empty fingerprint.
static int BioWrite(bio_st *bio, const char *buf, int len)
PBYTEArray GetData() const
Get the certificate as binary ASN1 DER encoded data.
Encryption/decryption context.
Definition: pssl.h:573
bool SetVerifySystemDefault()
Set the locations for CA certificates used to verify peer certificates.
P_DECLARE_ENUM(VerifyMode, VerifyNone, VerifyPeer, VerifyPeerMandatory)
ShutdownValue
Definition: channel.h:589
bio_method_st * m_bioMethod
Definition: pssl.h:1047
Private key for SSL.
Definition: pssl.h:65
PBoolean Save(const PFilePath &keyFile, PBoolean append=false, PSSLFileTypes fileType=PSSLFileTypeDEFAULT)
Save private key to file.
bool Process(const PBYTEArray &in, PBYTEArray &out)
Encrypt/Decrypt a block of data.
PBYTEArray GetData() const
Get the certificate as binary ASN1 DER encoded data.
This template class maps the PAbstractList to a specific object type.
Definition: lists.h:322
bool UsePrivateKey(const PSSLPrivateKey &key)
Use the private key specified.
ssl_st * m_ssl
Definition: pssl.h:1046
bool DecryptFinalCTS(unsigned char *out, int *outl)
virtual bool InternalAccept()
bool m_pad_final_used
Definition: pssl.h:669
PSSLContext * m_context
Definition: pssl.h:1044
Class to represent a directory in the operating system file system.
Definition: pdirect.h:173
VerifyMode GetVerifyMode() const
Set certificate verification mode for connection.
bool IsValid() const
Return true if is a valid private key.
Definition: pssl.h:145
PSSLChannel(PSSLContext *context=NULL, PBoolean autoDeleteContext=false)
Create a new channel given the context.
PINDEX GetBlockedDataSize(PINDEX size) const
Calculate the rounded up size for encrypted data.
PString GetSubjectName() const
bool UseDiffieHellman(const PSSLDiffieHellman &dh)
Use the Diffie-Hellman parameters specified.
Array of unsigned characters.
Definition: array.h:605
PBYTEArray GetGenerator() const
Get the G value.
bool m_autoDeleteContext
Definition: pssl.h:1045
bool CreateRoot(const PString &subject, const PSSLPrivateKey &key, const char *digest=NULL, unsigned version=0)
Create a new root certificate.
virtual bool InternalAccept()
static const Method HighestTLS
Definition: pssl.h:733
VerifyNotifier m_verifyNotifier
Definition: pssl.h:1049
HashType GetHash() const
Definition: pssl.h:430
PINDEX GetNumBits() const
Get number of bits being used.
PString GetAlgorithm() const
Get selected algorithm.
Create a "fingerprint" for SSL certificate.
Definition: pssl.h:392
virtual PBoolean Read(void *buf, PINDEX len)
Low level read from the channel.
void SetPasswordNotifier(const PSSLPasswordNotifier ¬ifier)
Set the notifier for when SSL needs to get a password to unlock a private key.
X509_Name(X509_name_st *name=NULL)
Definition: pssl.h:332
Abstract class defining I/O channel semantics.
Definition: channel.h:103
This class will start a secure SSL based channel.
Definition: pssl.h:1059
Comparison Compare(const PObject &other) const
Compare the two objects and return their relative rank.
virtual PINDEX GetSize() const
Get the current size of the container.
PBYTEArray GetHalfKey() const
Get the "half-key" value.
bool SetVerifyDirectory(const PDirectory &caDir)
Set the locations for CA certificates used to verify peer certificates.
PBoolean Connect()
Connect to remote server.
bool Construct(const BYTE *pData, PINDEX pSize, const BYTE *gData, PINDEX gSize, const BYTE *kData, PINDEX kSize)
void Construct(const void *sessionId, PINDEX idSize)
bool PBoolean
Definition: object.h:174
Comparison Compare(const PObject &other) const
Compare the two objects and return their relative rank.
~PSSLChannel()
Close and clear the SSL channel.
PSSLContext::VerifyMode VerifyMode
Definition: pssl.h:969
bool GetPeerCertificate(PSSLCertificate &certificate, PString *error=NULL)
Get the peer certificate, if there is one.
P_DECLARE_BITWISE_ENUM(CheckHostFlags, 5,(CheckHostNormalRules, CheckHostAlwaysUseSubject, CheckHostNoWildcards, CheckHostNoPartialWildcards, CheckHostMultiLabelWildcards, CheckHostSingleLabelDomains))
bool GetIssuerName(X509_Name &name) const
Get certificate issuer name.
intptr_t P_INT_PTR
Definition: object.h:2646
PSSLCipherContext(bool encrypt)
BYTE Digest[20]
Definition: pssl.h:698
The character string class.
Definition: pstring.h:108
X509_Chain m_chain
Definition: pssl.h:386
~PSSLDiffieHellman()
Destroy and release storage for Diffie-Hellman parameters.
void Finalise(Digest result)
Context for SSL channels.
Definition: pssl.h:718
virtual void PrintOn(ostream &strm) const
Output the contents of the object to the stream.
Definition: pssl.h:378
PSSLDiffieHellman & operator=(const PSSLDiffieHellman &dh)
Create a copy of the Diffie-Hellman parameters.
bool SetIV(const PBYTEArray &iv)
Set encryption/decryption initial vector.
Definition: pssl.h:608
ssl_ctx_st * m_context
Definition: pssl.h:866
This class will start a secure SSL based channel.
Definition: pssl.h:877
bool SetAlgorithm(const PString &name)
Set encryption/decryption algorithm.
Method m_method
Definition: pssl.h:865
bool SetVerifyLocations(const PFilePath &caFile, const PDirectory &caDir)
Set the locations for CA certificates used to verify peer certificates.
PadMode
Definition: pssl.h:611
PString AsString() const
Get the certificate as ASN1 DER base64 encoded data.
ErrorGroup
Error groups.
Definition: channel.h:251
bool MatchForCertificate(const PSSLCertificate &cert) const
int m_pad_buf_len
Definition: pssl.h:668
int m_errorCode
Definition: pssl.h:976
virtual bool InternalConnect()
PBoolean Load(const PFilePath &dhFile, PSSLFileTypes fileType=PSSLFileTypeDEFAULT)
Load Diffie-Hellman parameters from file.
PSSLCertificate()
Create an empty certificate.
virtual PBoolean Shutdown(ShutdownValue)
Close one or both of the data streams associated with a channel.
bio_st * m_bio
Definition: pssl.h:1048
P_REMOVE_VIRTUAL(PBoolean, RawSSLRead(void *, PINDEX &), false)
virtual PBoolean Write(const void *buf, PINDEX len)
Low level write to the channel.
PBYTEArray m_sessionKey
Definition: pssl.h:546
void Update(const void *data, PINDEX length)
void Attach(x509_st *cert)
Set internal OpenSSL X509 structure.
bool SetVerifyCertificate(const PSSLCertificate &cert)
Set the CA certificate used to verify peer certificates.
PBoolean Load(const PFilePath &keyFile, PSSLFileTypes fileType=PSSLFileTypeDEFAULT, const PSSLPasswordNotifier ¬ifier=PSSLPasswordNotifier())
Load private key from file.
PadMode GetPadding() const
Get padding mode.
Definition: pssl.h:628
PBoolean Accept()
Accept a new inbound connection (server).
virtual PBoolean Read(void *buf, PINDEX len)
Low level read from the channel.
bool SetPadding(PadMode pad)
Set padding mode.
static void Process(const PString &str, Digest result)
Definition: pssl.h:702
bool CheckHostName(const PString &hostname, PSSLCertificate::CheckHostFlags flags=PSSLCertificate::CheckHostNormalRules)
Check the host name against the certificate.
PString GetSubjectAltName() const
Get certificate alternate subject name.
PINDEX GetKeyLength() const
Get the cipher key length.
virtual PBoolean Close()
Close the channel.
void SetHash(HashType hash)
Definition: pssl.h:431
bool CheckHostName(const PString &hostname, CheckHostFlags flags=CheckHostNormalRules)
Check the host name against the certificate.
PString GetNID(int id) const
SHA1 digest scheme.
Definition: pssl.h:686
bool Parse(const PString &keyStr)
Set the certificate from ASN1 DER base64 encoded data.
bool IsServer() const
Indicate we are operating as a server.
PSSLCertificate & operator=(const PSSLCertificate &cert)
Create a copy of the certificate.
bool m_encrypt
Definition: pssl.h:662
bool AddClientCA(const PSSLCertificate &certificate)
Set the CA certificate(s) to send to client from server.
PBoolean Save(const PFilePath &keyFile, PBoolean append=false, PSSLFileTypes fileType=PSSLFileTypeDEFAULT)
Save certificate to file.
PSSLPrivateKey()
Create an empty private key.
PString GetCipherList() const
Get the available ciphers.
bool IsEncrypt() const
Indicate we are encrypting data.
bool SetData(const PBYTEArray &data)
Set the certificate as binary ASN1 DER encoded data.
bool SetData(const PBYTEArray &data)
Set the certificate as binary ASN1 DER encoded data.
bool SetKey(const PBYTEArray &key)
Set encryption/decryption key.
Definition: pssl.h:603
PBYTEArray GetModulus() const
Get the P value.
~PSSLChannelDTLS()
Close and clear the SSL channel.
PNotifierTemplate< VerifyInfo & > VerifyNotifier
Definition: pssl.h:978
PNotifierTemplate< bool > PSSLPasswordNotifier
Definition: pssl.h:57
virtual PINDEX GetLength() const
Determine the length of the null terminated string.
Definition: pstring.h:595
void SetVerifyMode(VerifyMode mode, unsigned depth=9)
Set certificate verification mode for connection.
Diffie-Hellman key exchange conteext.
Definition: pssl.h:443
bool SetMTU(unsigned bytes)
Set the MTU for DTLS handshake.
P_DECLARE_TRACED_ENUM(Method, SSLv23, SSLv3, TLSv1, TLSv1_1, TLSv1_2, DTLSv1, DTLSv1_2, DTLSv1_2_v1_0)
X509_name_st * m_name
Definition: pssl.h:346
unsigned char m_pad_final_buf[32]
Definition: pssl.h:667
bool SetVerifyFile(const PFilePath &caFile)
Set the locations for CA certificates used to verify peer certificates.
bool UseCertificate(const PSSLCertificate &certificate)
Use the certificate specified.
bool IsValid() const
Return true if is a valid Diffie-Hellman context.
Definition: pssl.h:500
evp_pkey_st * m_pkey
Definition: pssl.h:192
PSSLPasswordNotifier m_passwordNotifier
Definition: pssl.h:867
void PrintOn(ostream &strm) const
Output the contents of the object to the stream.
evp_cipher_ctx_st * m_context
Definition: pssl.h:663
bool ExecuteHandshake()
Perform negotiation handshake.
PSSLContext * GetContext() const
Definition: pssl.h:1021
Ultimate parent class for all objects in the class library.
Definition: object.h:2204
bool UpdateLoose(unsigned char *out, int *outl, const unsigned char *in, int inl)
PSSLChannelDTLS(PSSLContext *context=NULL, bool autoDeleteContext=false)
Create a new channel given the context.
VerifyInfo(bool ok, const PSSLCertificate &cert, int err)
Definition: pssl.h:973
PSSLDiffieHellman()
Create an empty set of Diffie-Hellman parameters.
~PSSLContext()
Clean up the SSL context.
bool Parse(const PString &certStr)
Set the certificate from ASN1 DER base64 encoded data.
bool SetCipherList(const PString &ciphers)
Set the available ciphers to those listed.
PSSLFileTypes
Definition: pssl.h:50