opcua_secureChannelLayer.h 3.2 KB

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