X509Certificate.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // X509Certificate.h
  3. //
  4. // Library: NetSSL_OpenSSL
  5. // Package: SSLCore
  6. // Module: X509Certificate
  7. //
  8. // Definition of the X509Certificate class.
  9. //
  10. // Copyright (c) 2006-2009, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #ifndef NetSSL_X509Certificate_INCLUDED
  16. #define NetSSL_X509Certificate_INCLUDED
  17. #include "Poco/Net/NetSSL.h"
  18. #include "Poco/Net/SocketDefs.h"
  19. #include "Poco/Crypto/X509Certificate.h"
  20. #include "Poco/DateTime.h"
  21. #include "Poco/SharedPtr.h"
  22. #include <set>
  23. namespace Poco {
  24. namespace Net {
  25. class HostEntry;
  26. class NetSSL_API X509Certificate: public Poco::Crypto::X509Certificate
  27. /// This class extends Poco::Crypto::X509Certificate with the
  28. /// feature to validate a certificate.
  29. {
  30. public:
  31. explicit X509Certificate(std::istream& istr);
  32. /// Creates the X509Certificate object by reading
  33. /// a certificate in PEM format from a stream.
  34. explicit X509Certificate(const std::string& path);
  35. /// Creates the X509Certificate object by reading
  36. /// a certificate in PEM format from a file.
  37. explicit X509Certificate(X509* pCert);
  38. /// Creates the X509Certificate from an existing
  39. /// OpenSSL certificate. Ownership is taken of
  40. /// the certificate.
  41. X509Certificate(X509* pCert, bool shared);
  42. /// Creates the X509Certificate from an existing
  43. /// OpenSSL certificate. Ownership is taken of
  44. /// the certificate. If shared is true, the
  45. /// certificate's reference count is incremented.
  46. X509Certificate(const Poco::Crypto::X509Certificate& cert);
  47. /// Creates the certificate by copying another one.
  48. X509Certificate& operator = (const Poco::Crypto::X509Certificate& cert);
  49. /// Assigns a certificate.
  50. ~X509Certificate();
  51. /// Destroys the X509Certificate.
  52. bool verify(const std::string& hostName) const;
  53. /// Verifies the validity of the certificate against the host name.
  54. ///
  55. /// For this check to be successful, the certificate must contain
  56. /// a domain name that matches the domain name
  57. /// of the host.
  58. ///
  59. /// Returns true if verification succeeded, or false otherwise.
  60. static bool verify(const Poco::Crypto::X509Certificate& cert, const std::string& hostName);
  61. /// Verifies the validity of the certificate against the host name.
  62. ///
  63. /// For this check to be successful, the certificate must contain
  64. /// a domain name that matches the domain name
  65. /// of the host.
  66. ///
  67. /// Returns true if verification succeeded, or false otherwise.
  68. protected:
  69. static bool containsWildcards(const std::string& commonName);
  70. static bool matchWildcard(const std::string& alias, const std::string& hostName);
  71. private:
  72. enum
  73. {
  74. NAME_BUFFER_SIZE = 256
  75. };
  76. };
  77. } } // namespace Poco::Net
  78. #endif // NetSSL_X509Certificate_INCLUDED