securesocket.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. #ifdef _WIN32
  17. #ifndef SECURESOCKET_EXPORTS
  18. #define SECURESOCKET_API __declspec(dllimport)
  19. #else
  20. #define SECURESOCKET_API __declspec(dllexport)
  21. #endif //SECURESOCKET_EXPORTS
  22. #else
  23. #define SECURESOCKET_API
  24. #endif //_WIN32
  25. #endif
  26. #include "jsocket.hpp"
  27. #include "jptree.hpp"
  28. #ifdef _WIN32
  29. #define SSLIB "securesocket.dll"
  30. #else
  31. #define SSLIB "libsecuresocket.so"
  32. #endif
  33. enum SecureSocketType
  34. {
  35. ClientSocket = 0,
  36. ServerSocket = 1
  37. };
  38. #define SSLogNone 0
  39. #define SSLogMin 1
  40. #define SSLogNormal 5
  41. #define SSLogMax 10
  42. // One instance per connection
  43. interface ISecureSocket : implements ISocket
  44. {
  45. virtual int secure_accept() = 0;
  46. virtual int secure_connect() = 0;
  47. };
  48. // One instance per program running
  49. interface ISecureSocketContext : implements IInterface
  50. {
  51. virtual ISecureSocket* createSecureSocket(ISocket* sock, int loglevel = SSLogNormal) = 0;
  52. virtual ISecureSocket* createSecureSocket(int sockfd, int loglevel = SSLogNormal) = 0;
  53. };
  54. interface ICertificate : implements IInterface
  55. {
  56. virtual void setDestAddr(const char* destaddr) = 0;
  57. virtual void setDays(int days) = 0;
  58. virtual void setPassphrase(const char* passphrase) = 0;
  59. virtual void setCountry(const char* country) = 0;
  60. virtual void setState(const char* state) = 0;
  61. virtual void setCity(const char* city) = 0;
  62. virtual void setOrganization(const char* o) = 0;
  63. virtual void setOrganizationalUnit(const char* ou) = 0;
  64. virtual void setEmail(const char* email) = 0;
  65. virtual int generate(StringBuffer& certificate, StringBuffer& privkey) = 0;
  66. virtual int generate(StringBuffer& certificate, const char* privkey) = 0;
  67. virtual int generateCSR(StringBuffer& privkey, StringBuffer& csr) = 0;
  68. virtual int generateCSR(const char* privkey, StringBuffer& csr) = 0;
  69. };
  70. typedef ISecureSocketContext* (*createSecureSocketContext_t)(SecureSocketType);
  71. typedef ISecureSocketContext* (*createSecureSocketContextEx_t)(const char* certfile, const char* privkeyfile, const char* passphrase, SecureSocketType);
  72. typedef ISecureSocketContext* (*createSecureSocketContextEx2_t)(IPropertyTree* config, SecureSocketType);
  73. extern "C" {
  74. SECURESOCKET_API ISecureSocketContext* createSecureSocketContext(SecureSocketType);
  75. SECURESOCKET_API ISecureSocketContext* createSecureSocketContextEx(const char* certfile, const char* privkeyfile, const char* passphrase, SecureSocketType);
  76. SECURESOCKET_API ISecureSocketContext* createSecureSocketContextEx2(IPropertyTree* config, SecureSocketType);
  77. SECURESOCKET_API ICertificate *createCertificate();
  78. SECURESOCKET_API int signCertificate(const char* csr, const char* ca_certificate, const char* ca_privkey, const char* ca_passphrase, int days, StringBuffer& certificate);
  79. };
  80. #endif