securesocket.hpp 3.5 KB

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