opcua_secureChannelLayer.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * opcua_secureChannelLayer.h
  3. *
  4. * Created on: Dec 19, 2013
  5. * Author: opcua
  6. */
  7. #ifndef OPCUA_SECURECHANNELLAYER_H_
  8. #define OPCUA_SECURECHANNELLAYER_H_
  9. #include "opcua_advancedDatatypes.h"
  10. #include "opcua_encodingLayer.h"
  11. #include "opcua_connectionHelper.h"
  12. static const Int32 SL_HEADER_LENGTH = 0;
  13. typedef enum
  14. {
  15. securityToken_ISSUE = 0,
  16. securityToken_RENEW = 1
  17. }SecurityTokenRequestType;
  18. typedef enum
  19. {
  20. securityMode_INVALID = 0,
  21. securityMode_SIGN = 1,
  22. securityMode_SIGNANDENCRYPT = 2
  23. }securityMode;
  24. typedef struct
  25. {
  26. UInt32 ServerProtocolVersion;
  27. SL_ChannelSecurityToken SecurityToken;
  28. UA_String ServerNonce;
  29. }SL_Response;
  30. typedef struct
  31. {
  32. UInt32 MessageType;
  33. Byte IsFinal;
  34. UInt32 MessageSize;
  35. UInt32 SecureChannelId;
  36. }SL_SecureConversationMessageHeader;
  37. typedef struct
  38. {
  39. UA_String SecurityPolicyUri;
  40. UA_String SenderCertificate;
  41. UA_String ReceiverThumbprint;
  42. }SL_AsymmetricAlgorithmSecurityHeader;
  43. typedef struct _SL_SequenceHeader
  44. {
  45. UInt32 SequenceNumber;
  46. UInt32 RequestId;
  47. }SL_SequenceHeader;
  48. /*
  49. * optional, only if there is encryption present
  50. */
  51. typedef struct _SL_AsymmetricAlgorithmSecurityFooter
  52. {
  53. Byte PaddingSize;
  54. Byte *Padding;
  55. UInt32 SignatureSize;
  56. Byte *Signature;
  57. }SL_AsymmetricAlgorithmSecurityFooter;
  58. /*
  59. typedef struct _SL_ResponseHeader
  60. {
  61. UA_DateTime timestamp;
  62. IntegerId requestHandle;
  63. UA_StatusCode serviceResult;
  64. UA_DiagnosticInfo serviceDiagnostics;
  65. UA_String *stringTable;
  66. UInt32 stringTableLength;
  67. UA_ExtensionObject additionalHeader;
  68. }SL_ResponseHeader;
  69. */
  70. Int32 SL_openSecureChannel_responseMessage_get(UA_connection *connection,
  71. SL_Response *response, Int32* sizeInOut);
  72. /**
  73. *
  74. * @param connection
  75. * @param rawMessage
  76. * @param pos
  77. * @param SC_Header
  78. * @return
  79. */
  80. Int32 decodeSCMHeader(UA_ByteString *rawMessage,Int32 *pos,
  81. SL_SecureConversationMessageHeader* SC_Header);
  82. /**
  83. *
  84. * @param SC_Header
  85. * @param pos
  86. * @param rawMessage
  87. * @return
  88. */
  89. Int32 encodeSCMHeader(SL_SecureConversationMessageHeader *SC_Header,
  90. Int32 *pos,AD_RawMessage *rawMessage);
  91. /**
  92. *
  93. * @param rawMessage
  94. * @param pos
  95. * @param SequenceHeader
  96. * @return
  97. */
  98. Int32 decodeSequenceHeader(UA_ByteString *rawMessage, Int32 *pos,
  99. SL_SequenceHeader *sequenceHeader);
  100. /**
  101. *
  102. * @param sequenceHeader
  103. * @param pos
  104. * @param dstRawMessage
  105. * @return
  106. */
  107. Int32 encodeSequenceHeader(SL_SequenceHeader *sequenceHeader,Int32 *pos,
  108. AD_RawMessage *dstRawMessage);
  109. /**
  110. *
  111. * @param rawMessage
  112. * @param pos
  113. * @param AAS_Header
  114. * @return
  115. */
  116. Int32 decodeAASHeader(UA_ByteString *rawMessage, Int32 *pos,
  117. SL_AsymmetricAlgorithmSecurityHeader* AAS_Header);
  118. /**
  119. *
  120. * @param AAS_Header
  121. * @param pos
  122. * @param dstRawMessage
  123. * @return
  124. */
  125. Int32 encodeAASHeader(SL_AsymmetricAlgorithmSecurityHeader *AAS_Header,
  126. Int32 *pos, AD_RawMessage* dstRawMessage);
  127. /**
  128. *
  129. * @param connection
  130. * @param serviceMessage
  131. */
  132. void SL_receive(UA_connection *connection, UA_ByteString *serviceMessage);
  133. #endif /* OPCUA_SECURECHANNELLAYER_H_ */