securesocket.hpp 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #ifndef SECURESOCKET_HPP__
  14. #define SECURESOCKET_HPP__
  15. #ifndef SECURESOCKET_API
  16. #ifndef SECURESOCKET_EXPORTS
  17. #define SECURESOCKET_API DECL_IMPORT
  18. #else
  19. #define SECURESOCKET_API DECL_EXPORT
  20. #endif //SECURESOCKET_EXPORTS
  21. #endif
  22. #include "jsocket.hpp"
  23. #include "jptree.hpp"
  24. #include "jsmartsock.hpp"
  25. #define SSLIB "securesocket"
  26. enum SecureSocketType
  27. {
  28. ClientSocket = 0,
  29. ServerSocket = 1
  30. };
  31. #define SSLogNone 0
  32. #define SSLogMin 1
  33. #define SSLogNormal 5
  34. #define SSLogMax 10
  35. // One instance per connection
  36. interface ISecureSocket : implements ISocket
  37. {
  38. virtual int secure_accept(int logLevel=1) = 0;
  39. virtual int secure_connect(int logLevel=1) = 0;
  40. };
  41. // One instance per program running
  42. interface ISecureSocketContext : implements IInterface
  43. {
  44. virtual ISecureSocket* createSecureSocket(ISocket* sock, int loglevel = SSLogNormal) = 0;
  45. virtual ISecureSocket* createSecureSocket(int sockfd, int loglevel = SSLogNormal) = 0;
  46. };
  47. interface ICertificate : implements IInterface
  48. {
  49. virtual void setDestAddr(const char* destaddr) = 0;
  50. virtual void setDays(int days) = 0;
  51. virtual void setPassphrase(const char* passphrase) = 0;
  52. virtual void setCountry(const char* country) = 0;
  53. virtual void setState(const char* state) = 0;
  54. virtual void setCity(const char* city) = 0;
  55. virtual void setOrganization(const char* o) = 0;
  56. virtual void setOrganizationalUnit(const char* ou) = 0;
  57. virtual void setEmail(const char* email) = 0;
  58. virtual int generate(StringBuffer& certificate, StringBuffer& privkey) = 0;
  59. virtual int generate(StringBuffer& certificate, const char* privkey) = 0;
  60. virtual int generateCSR(StringBuffer& privkey, StringBuffer& csr) = 0;
  61. virtual int generateCSR(const char* privkey, StringBuffer& csr) = 0;
  62. };
  63. typedef ISecureSocketContext* (*createSecureSocketContext_t)(SecureSocketType);
  64. typedef ISecureSocketContext* (*createSecureSocketContextEx_t)(const char* certfile, const char* privkeyfile, const char* passphrase, SecureSocketType);
  65. typedef ISecureSocketContext* (*createSecureSocketContextEx2_t)(IPropertyTree* config, SecureSocketType);
  66. extern "C" {
  67. SECURESOCKET_API ISecureSocketContext* createSecureSocketContext(SecureSocketType);
  68. SECURESOCKET_API ISecureSocketContext* createSecureSocketContextEx(const char* certfile, const char* privkeyfile, const char* passphrase, SecureSocketType);
  69. SECURESOCKET_API ISecureSocketContext* createSecureSocketContextEx2(IPropertyTree* config, SecureSocketType);
  70. SECURESOCKET_API ICertificate *createCertificate();
  71. SECURESOCKET_API int signCertificate(const char* csr, const char* ca_certificate, const char* ca_privkey, const char* ca_passphrase, int days, StringBuffer& certificate);
  72. };
  73. SECURESOCKET_API ISmartSocketFactory *createSecureSmartSocketFactory(const char *_socklist, bool _retry = false, unsigned _retryInterval = 60, unsigned _dnsInterval = (unsigned) -1);
  74. #endif