opcua_secureChannelLayer.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * opcua_secureChannelLayer.c
  3. *
  4. * Created on: Jan 13, 2014
  5. * Author: opcua
  6. */
  7. #include "opcua_secureChannelLayer.h"
  8. SL_getRequestHeader()
  9. {
  10. }
  11. /*
  12. * opens a secureChannel (server side)
  13. */
  14. void SL_secureChannel_open(const UA_connection *connection,
  15. const AD_RawMessage *secureChannelMessage,
  16. const SL_SecureConversationMessageHeader *SCM_Header,
  17. const SL_AsymmetricAlgorithmSecurityHeader *AAS_Header)
  18. {
  19. TL_send();
  20. //client protocol Version
  21. connection->secureLayer.
  22. //connection->secureLayer.
  23. }
  24. /*
  25. void SL_secureChannel_Request_get(AD_RawMessage *secureChannelMessage,
  26. secureChannelRequest *SC_request)
  27. {
  28. }
  29. */
  30. /*
  31. * closes a secureChannel (server side)
  32. */
  33. void SL_secureChannel_formResponse()
  34. {
  35. }
  36. void SL_secureChannel_close(UA_connection *connection)
  37. {
  38. }
  39. /*
  40. * receive and process data from underlying layer
  41. */
  42. void SL_receive(UA_connection *connection, AD_RawMessage *serviceMessage)
  43. {
  44. AD_RawMessage* secureChannelMessage;
  45. SL_SecureConversationMessageHeader SCM_Header;
  46. SL_AsymmetricAlgorithmSecurityHeader AAS_Header;
  47. //get data from transport layer
  48. TL_receive(UA_connection, secureChannelMessage);
  49. //get the Secure Channel Message Header
  50. UInt32 readPosition = SL_secureChannel_SCMHeader_get(connection,
  51. secureChannelMessage, &SCM_Header);
  52. //get the Secure Channel Asymmetric Algorithm Security Header
  53. readPosition = SL_secureChannel_AASHeader_get(connection, secureChannelMessage,
  54. readPosition, &AAS_Header);
  55. //get Secure Channel Message
  56. SL_secureChannel_Message_get(connection, secureChannelMessage, readPosition,
  57. serviceMessage);
  58. if (secureChannelMessage.length > 0)
  59. {
  60. switch (SCM_Header.MessageType)
  61. {
  62. case packetType_MSG:
  63. if (connection->secureLayer.connectionState
  64. == connectionState_ESTABLISHED)
  65. {
  66. }
  67. else //receiving message, without secure channel
  68. {
  69. //TODO send back Error Message
  70. }
  71. break;
  72. case packetType_OPN:
  73. //Server Handling
  74. if (openSecureChannelHeader_check(connection, secureChannelMessage))
  75. {
  76. }
  77. SL_secureChannel_open(connection, serviceMessage);
  78. }
  79. else
  80. {
  81. //TODO send back Error Message
  82. }
  83. //Client Handling
  84. //TODO free memory for secureChannelMessage
  85. break;
  86. case packetType_CLO:
  87. SL_secureChannel_close(connection, secureChannelMessage);
  88. //TODO free memory for secureChannelMessage
  89. break;
  90. }
  91. }
  92. UInt32 SL_secureChannel_SCMHeader_get(UA_connection *connection,
  93. AD_RawMessage *rawMessage, SL_SecureConversationMessageHeader* SC_Header)
  94. {
  95. Int32 pos = 0;
  96. SC_Header->MessageType = TL_getPacketType(rawMessage);
  97. pos += TL_MESSAGE_TYPE_LEN;
  98. SC_Header->IsFinal = rawMessage[pos];
  99. pos += sizeof(Byte);
  100. SC_Header->MessageSize = convertToUInt32(rawMessage, pos);
  101. pos += sizeof(UInt32);
  102. SC_Header->SecureChannelId = convertToUInt32(rawMessage, pos);
  103. pos += sizeof(UInt32);
  104. return pos;
  105. }
  106. UInt32 SL_secureChannel_AASHeader_get(UA_connection *connection,
  107. AD_RawMessage *rawMessage, UInt32 pos,
  108. SL_AsymmetricAlgorithmSecurityHeader* AAS_Header)
  109. {
  110. AAS_Header->SecurityPolicyUri.Length = convertToInt32(rawMessage, pos);
  111. pos += sizeof(Int32);
  112. AAS_Header->SecurityPolicyUri.Data = rawMessage[pos];
  113. if (AAS_Header->SecurityPolicyUri.Length < 0)
  114. {
  115. AAS_Header->SecurityPolicyUri.Length = 0;
  116. }
  117. pos += AAS_Header->SecurityPolicyUri.Length;
  118. AAS_Header->SenderCertificate.Length = convertToInt32(rawMessage, pos);
  119. pos += sizeof(Int32);
  120. if (AAS_Header->SenderCertificate.Length < 0)
  121. {
  122. AAS_Header->SenderCertificate.Length = 0;
  123. }
  124. AAS_Header->SenderCertificate.Data = rawMessage[pos];
  125. pos += AAS_Header->SenderCertificate.Length;
  126. AAS_Header->ReceiverThumbprint.Length = convertToInt32(rawMessage, pos);
  127. pos += sizeof(Int32);
  128. if (AAS_Header->ReceiverThumbprint.Length < 0)
  129. {
  130. AAS_Header->ReceiverThumbprint.Length = 0;
  131. }
  132. AAS_Header->ReceiverThumbprint.Data = rawMessage[pos];
  133. pos += AAS_Header->ReceiverThumbprint.Length;
  134. return pos;
  135. }
  136. void SL_secureChannel_Footer_get()
  137. {
  138. }
  139. void SL_secureChannel_Message_get(UA_connection *connection,
  140. AD_RawMessage *rawMessage, UInt32 pos, AD_RawMessage *message)
  141. {
  142. }