⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pssl.h

📁 pwlib源码库
💻 H
📖 第 1 页 / 共 2 页
字号:
    );    /**Get the certificate as binary ASN1 DER encoded data.      */    PBYTEArray GetData() const;    /**Get the certificate as ASN1 DER base64 encoded data.      */    PString AsString() const;    /**Load certificate from file.       The type of the certificate key can be specified explicitly, or if       PSSLFileTypeDEFAULT it will be determined from the file extension,       ".pem" is a text file, anything else eg ".der" is a binary ASN1 file.      */    BOOL Load(      const PFilePath & certFile, /// Certificate file      PSSLFileTypes fileType = PSSLFileTypeDEFAULT  /// Type of file to read    );    /**Save certificate to file.       The type of the certificate key can be specified explicitly, or if       PSSLFileTypeDEFAULT it will be determined from the file extension,       ".pem" is a text file, anything else eg ".der" is a binary ASN1 file.      */    BOOL Save(      const PFilePath & keyFile,  /// Certificate key file      BOOL append = FALSE,        /// Append to file      PSSLFileTypes fileType = PSSLFileTypeDEFAULT  /// Type of file to write    );  protected:    x509_st * certificate;};/**Diffie-Hellman parameters for SSL.   This class embodies a set of Diffie Helman parameters as used by   PSSLContext and PSSLChannel classes.  */class PSSLDiffieHellman : public PObject{  PCLASSINFO(PSSLDiffieHellman, PObject);  public:    /**Create an empty set of Diffie-Hellman parameters.      */    PSSLDiffieHellman();    /**Create a new set of Diffie-Hellman parameters given the file.       The type of the file can be specified explicitly, or if       PSSLFileTypeDEFAULT it will be determined from the file extension,       ".pem" is a text file, anything else eg ".der" is a binary ASN1 file.      */    PSSLDiffieHellman(      const PFilePath & dhFile, /// Diffie-Hellman parameters file      PSSLFileTypes fileType = PSSLFileTypeDEFAULT  /// Type of file to read    );    /**Create a set of Diffie-Hellman parameters.      */    PSSLDiffieHellman(      const BYTE * pData, /// P data      PINDEX pSize,       /// Size of P data      const BYTE * gData, /// G data      PINDEX gSize        /// Size of G data    );    /**Create a copy of the Diffie-Hellman parameters.      */    PSSLDiffieHellman(      const PSSLDiffieHellman & dh    );    /**Create a copy of the Diffie-Hellman parameters.      */    PSSLDiffieHellman & operator=(      const PSSLDiffieHellman & dh    );    /**Destroy and release storage for Diffie-Hellman parameters.      */    ~PSSLDiffieHellman();    /**Get internal OpenSSL DH structure.      */    operator dh_st *() const { return dh; }    /**Load Diffie-Hellman parameters from file.       The type of the file can be specified explicitly, or if       PSSLFileTypeDEFAULT it will be determined from the file extension,       ".pem" is a text file, anything else eg ".der" is a binary ASN1 file.      */    BOOL Load(      const PFilePath & dhFile, /// Diffie-Hellman parameters file      PSSLFileTypes fileType = PSSLFileTypeDEFAULT  /// Type of file to read    );  protected:    dh_st * dh;};/**Context for SSL channels.   This class embodies a common environment for all connections made via SSL   using the PSSLChannel class. It includes such things as the version of SSL   and certificates, CA's etc.  */class PSSLContext {  public:    /**Create a new context for SSL channels.       An optional session ID may be provided in the context. This is used       to identify sessions across multiple channels in this context. The       session ID is a completely arbitrary block of data. If sessionId is       non NULL and idSize is zero, then sessionId is assumed to be a pointer       to a C string.      */    PSSLContext(      const void * sessionId = NULL,  /// Pointer to session ID      PINDEX idSize = 0               /// Size of session ID    );    /**Clean up the SSL context.      */    ~PSSLContext();    /**Get the internal SSL context structure.      */    operator ssl_ctx_st *() const { return context; }    /**Set the path to locate CA certificates.      */    BOOL SetCAPath(      const PDirectory & caPath   /// Directory for CA certificates    );    /**Set the CA certificate file.      */    BOOL SetCAFile(      const PFilePath & caFile    /// CA certificate file    );    /**Use the certificate specified.      */    BOOL UseCertificate(      const PSSLCertificate & certificate    );    /**Use the private key specified.      */    BOOL UsePrivateKey(      const PSSLPrivateKey & key    );    /**Use the Diffie-Hellman parameters specified.      */    BOOL UseDiffieHellman(      const PSSLDiffieHellman & dh    );    /**Set the available ciphers to those listed.      */    BOOL SetCipherList(      const PString & ciphers   /// List of cipher names.    );  protected:    ssl_ctx_st * context;};/**This class will start a secure SSL based channel.  */class PSSLChannel : public PIndirectChannel{  PCLASSINFO(PSSLChannel, PIndirectChannel)  public:    /**Create a new channel given the context.       If no context is given a default one is created.      */    PSSLChannel(      PSSLContext * context = NULL,   /// Context for SSL channel      BOOL autoDeleteContext = FALSE  /// Flag for context to be automatically deleted.    );    PSSLChannel(      PSSLContext & context           /// Context for SSL channel    );    /**Close and clear the SSL channel.      */    ~PSSLChannel();    // Overrides from PChannel    virtual BOOL Read(void * buf, PINDEX len);    virtual BOOL Write(const void * buf, PINDEX len);    virtual BOOL Close();    virtual BOOL Shutdown(ShutdownValue) { return TRUE; }    virtual PString GetErrorText(ErrorGroup group = NumErrorGroups) const;    virtual BOOL ConvertOSError(int error, ErrorGroup group = LastGeneralError);    // New functions    /**Accept a new inbound connection (server).       This version expects that the indirect channel has already been opened       using Open() beforehand.      */    BOOL Accept();    /**Accept a new inbound connection (server).      */    BOOL Accept(      PChannel & channel  /// Channel to attach to.    );    /**Accept a new inbound connection (server).      */    BOOL Accept(      PChannel * channel,     /// Channel to attach to.      BOOL autoDelete = TRUE  /// Flag for if channel should be automatically deleted.    );    /**Connect to remote server.       This version expects that the indirect channel has already been opened       using Open() beforehand.      */    BOOL Connect();    /**Connect to remote server.      */    BOOL Connect(      PChannel & channel  /// Channel to attach to.    );    /**Connect to remote server.      */    BOOL Connect(      PChannel * channel,     /// Channel to attach to.      BOOL autoDelete = TRUE  /// Flag for if channel should be automatically deleted.    );    /**Use the certificate specified.      */    BOOL UseCertificate(      const PSSLCertificate & certificate    );    /**Use the private key file specified.      */    BOOL UsePrivateKey(      const PSSLPrivateKey & key    );    enum VerifyMode {      VerifyNone,      VerifyPeer,      VerifyPeerMandatory,    };    void SetVerifyMode(      VerifyMode mode    );    PSSLContext * GetContext() const { return context; }    virtual BOOL RawSSLRead(void * buf, PINDEX & len);  protected:    /**This callback is executed when the Open() function is called with       open channels. It may be used by descendent channels to do any       handshaking required by the protocol that channel embodies.       The default behaviour "connects" the channel to the OpenSSL library.       @return       Returns TRUE if the protocol handshaking is successful.     */    virtual BOOL OnOpen();  protected:    PSSLContext * context;    BOOL          autoDeleteContext;    ssl_st      * ssl;};#endif // _PSSL_H

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -