|
@@ -6,8 +6,10 @@
|
|
|
*/
|
|
|
#include "opcua_secureChannelLayer.h"
|
|
|
|
|
|
+//memory calculation
|
|
|
|
|
|
-Int32 SL_openSecureChannelRequest_check(const UA_connection *connection, secureChannelMessage)
|
|
|
+
|
|
|
+Int32 SL_openSecureChannelRequest_check(const UA_connection *connection, AD_RawMessage *secureChannelMessage)
|
|
|
{
|
|
|
return 0;
|
|
|
}
|
|
@@ -30,59 +32,40 @@ Int32 SL_secureChannel_ResponseHeader_form(UA_connection *connection, T_Response
|
|
|
responseHeader->additionalHeader.Encoding = 0;
|
|
|
responseHeader->additionalHeader.Length = 0;
|
|
|
|
|
|
+
|
|
|
responseHeader->additionalHeader.TypeId.Namespace = 0;
|
|
|
- responseHeader->additionalHeader.TypeId.Identifier = 0;
|
|
|
+ responseHeader->additionalHeader.TypeId.Identifier.Numeric = 0;
|
|
|
|
|
|
|
|
|
responseHeader->requestHandle = 0;
|
|
|
return 0;
|
|
|
}
|
|
|
-/*
|
|
|
- *
|
|
|
- */
|
|
|
-Int32 SL_secureChannel_Response_form(UA_connection *connection, SL_Response *response)
|
|
|
-{
|
|
|
- response->ServerProtocolVersion = connection->transportLayer//TODO must be set
|
|
|
- response->SecurityToken.ChannelId = connection->secureLayer.UInt32_secureChannelId;
|
|
|
- response->SecurityToken.CreatedAt = connection->secureLayer.requestedAt;
|
|
|
- response->SecurityToken.TokenId = connection->secureLayer.tokenId; //TODO must be generated;
|
|
|
- response->SecurityToken.RevisedLifeTime = connection->secureLayer.revisedLifetime;
|
|
|
- response->ServerNonce.Length = 0; // TODO
|
|
|
- return 0;
|
|
|
-}
|
|
|
+
|
|
|
/*
|
|
|
* opens a secureChannel (server side)
|
|
|
*/
|
|
|
Int32 SL_secureChannel_open(const UA_connection *connection,
|
|
|
const AD_RawMessage *secureChannelMessage,
|
|
|
- const SL_SecureConversationMessageHeader *SCM_Header,
|
|
|
- const SL_AsymmetricAlgorithmSecurityHeader *AAS_Header)
|
|
|
+ const SL_SecureConversationMessageHeader *SCMHeader,
|
|
|
+ const SL_AsymmetricAlgorithmSecurityHeader *AASHeader,
|
|
|
+ const SL_SequenceHeader *SequenceHeader)
|
|
|
{
|
|
|
- SL_Response response;
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
- TL_send();
|
|
|
- //client protocol Version
|
|
|
|
|
|
-return 0;
|
|
|
+ return 0;
|
|
|
|
|
|
}
|
|
|
-/*
|
|
|
- void SL_secureChannel_Request_get(AD_RawMessage *secureChannelMessage,
|
|
|
- secureChannelRequest *SC_request)
|
|
|
- {
|
|
|
|
|
|
- }
|
|
|
+Int32 SL_openSecureChannel_responseMessage_getSize(SL_Response *response, Int32* sizeInOut)
|
|
|
+{
|
|
|
+
|
|
|
+}
|
|
|
|
|
|
/*
|
|
|
* closes a secureChannel (server side)
|
|
|
*/
|
|
|
-void SL_secureChannel_formResponse()
|
|
|
-{
|
|
|
-
|
|
|
-}
|
|
|
void SL_secureChannel_close(UA_connection *connection)
|
|
|
{
|
|
|
|
|
@@ -96,23 +79,32 @@ void SL_receive(UA_connection *connection, AD_RawMessage *serviceMessage)
|
|
|
AD_RawMessage* secureChannelMessage;
|
|
|
SL_SecureConversationMessageHeader SCM_Header;
|
|
|
SL_AsymmetricAlgorithmSecurityHeader AAS_Header;
|
|
|
+ SL_SequenceHeader SequenceHeader;
|
|
|
|
|
|
+ //TODO Error Handling, length checking
|
|
|
//get data from transport layer
|
|
|
- TL_receive(UA_connection, secureChannelMessage);
|
|
|
+
|
|
|
+ TL_receive(connection, secureChannelMessage);
|
|
|
+
|
|
|
+ Int32 readPosition = 0;
|
|
|
|
|
|
//get the Secure Channel Message Header
|
|
|
- UInt32 readPosition = SL_secureChannel_SCMHeader_get(connection,
|
|
|
- secureChannelMessage, &SCM_Header);
|
|
|
+ SL_secureChannel_SCMHeader_get(connection,secureChannelMessage,
|
|
|
+ &readPosition, &SCM_Header);
|
|
|
|
|
|
//get the Secure Channel Asymmetric Algorithm Security Header
|
|
|
- readPosition = SL_secureChannel_AASHeader_get(connection, secureChannelMessage,
|
|
|
- readPosition, &AAS_Header);
|
|
|
+ SL_secureChannel_AASHeader_get(connection, secureChannelMessage,
|
|
|
+ &readPosition, &AAS_Header);
|
|
|
+
|
|
|
+ //get the Sequence Header
|
|
|
+ SL_secureChannel_SequenceHeader_get(connection,secureChannelMessage,
|
|
|
+ &readPosition,&SequenceHeader);
|
|
|
|
|
|
//get Secure Channel Message
|
|
|
- SL_secureChannel_Message_get(connection, secureChannelMessage, readPosition,
|
|
|
- serviceMessage);
|
|
|
+ SL_secureChannel_Message_get(connection, secureChannelMessage,
|
|
|
+ &readPosition,serviceMessage);
|
|
|
|
|
|
- if (secureChannelMessage.length > 0)
|
|
|
+ if (secureChannelMessage->length > 0)
|
|
|
{
|
|
|
switch (SCM_Header.MessageType)
|
|
|
{
|
|
@@ -134,91 +126,61 @@ void SL_receive(UA_connection *connection, AD_RawMessage *serviceMessage)
|
|
|
//check if the request is valid
|
|
|
SL_openSecureChannelRequest_check(connection, secureChannelMessage);
|
|
|
}
|
|
|
- SL_secureChannel_open(connection, serviceMessage);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- //TODO send back Error Message
|
|
|
- }
|
|
|
-
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //TODO send back Error Message
|
|
|
+ }
|
|
|
//Client Handling
|
|
|
|
|
|
//TODO free memory for secureChannelMessage
|
|
|
|
|
|
break;
|
|
|
case packetType_CLO:
|
|
|
- SL_secureChannel_close(connection, secureChannelMessage);
|
|
|
+
|
|
|
|
|
|
//TODO free memory for secureChannelMessage
|
|
|
break;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|
|
|
/*
|
|
|
* get the secure channel message header
|
|
|
*/
|
|
|
-UInt32 SL_secureChannel_SCMHeader_get(UA_connection *connection,
|
|
|
- AD_RawMessage *rawMessage, SL_SecureConversationMessageHeader* SC_Header)
|
|
|
+Int32 SL_secureChannel_SCMHeader_get(UA_connection *connection,
|
|
|
+ AD_RawMessage *rawMessage,Int32 *pos, SL_SecureConversationMessageHeader* SC_Header)
|
|
|
{
|
|
|
- Int32 pos = 0;
|
|
|
SC_Header->MessageType = TL_getPacketType(rawMessage);
|
|
|
- pos += TL_MESSAGE_TYPE_LEN;
|
|
|
- SC_Header->IsFinal = rawMessage[pos];
|
|
|
- pos += sizeof(Byte);
|
|
|
- SC_Header->MessageSize = decodeUInt32(rawMessage, pos);
|
|
|
- pos += sizeof(UInt32);
|
|
|
- SC_Header->SecureChannelId = decodeUInt32(rawMessage, pos);
|
|
|
- pos += sizeof(UInt32);
|
|
|
- return pos;
|
|
|
+ *pos += 3;//TL_MESSAGE_TYPE_LEN;
|
|
|
+ SC_Header->IsFinal = rawMessage->message[*pos];
|
|
|
+ SC_Header->MessageSize = decodeUInt32(rawMessage, *pos);
|
|
|
+ SC_Header->SecureChannelId = decodeUInt32(rawMessage, *pos);
|
|
|
+ return 0;
|
|
|
|
|
|
}
|
|
|
+Int32 SL_secureChannel_SequenceHeader_get(UA_connection *connection,
|
|
|
+ AD_RawMessage *rawMessage, Int32 *pos,
|
|
|
+ SL_SequenceHeader *SequenceHeader)
|
|
|
+{
|
|
|
+ SequenceHeader->RequestId = decodeUInt32(rawMessage->message, pos);
|
|
|
+ SequenceHeader->SequenceNumber = decodeUInt32(rawMessage->message, pos);
|
|
|
+ return 0;
|
|
|
+}
|
|
|
/*
|
|
|
* get the asymmetric algorithm security header
|
|
|
*/
|
|
|
-UInt32 SL_secureChannel_AASHeader_get(UA_connection *connection,
|
|
|
- AD_RawMessage *rawMessage, UInt32 pos,
|
|
|
+Int32 SL_secureChannel_AASHeader_get(UA_connection *connection,
|
|
|
+ AD_RawMessage *rawMessage, Int32 *pos,
|
|
|
SL_AsymmetricAlgorithmSecurityHeader* AAS_Header)
|
|
|
{
|
|
|
-
|
|
|
- AAS_Header->SecurityPolicyUri.Length = decodeInt32(rawMessage, pos);
|
|
|
-
|
|
|
- pos += sizeof(Int32);
|
|
|
- AAS_Header->SecurityPolicyUri.Data = rawMessage[pos];
|
|
|
-
|
|
|
- if (AAS_Header->SecurityPolicyUri.Length < 0)
|
|
|
- {
|
|
|
- AAS_Header->SecurityPolicyUri.Length = 0;
|
|
|
- }
|
|
|
- pos += AAS_Header->SecurityPolicyUri.Length;
|
|
|
-
|
|
|
- AAS_Header->SenderCertificate.Length = decodeInt32(rawMessage, pos);
|
|
|
- pos += sizeof(Int32);
|
|
|
- if (AAS_Header->SenderCertificate.Length < 0)
|
|
|
- {
|
|
|
- AAS_Header->SenderCertificate.Length = 0;
|
|
|
- }
|
|
|
- AAS_Header->SenderCertificate.Data = rawMessage[pos];
|
|
|
-
|
|
|
- pos += AAS_Header->SenderCertificate.Length;
|
|
|
-
|
|
|
- AAS_Header->ReceiverThumbprint.Length = decodeInt32(rawMessage, pos);
|
|
|
- pos += sizeof(Int32);
|
|
|
-
|
|
|
- if (AAS_Header->ReceiverThumbprint.Length < 0)
|
|
|
- {
|
|
|
- AAS_Header->ReceiverThumbprint.Length = 0;
|
|
|
- }
|
|
|
- AAS_Header->ReceiverThumbprint.Data = rawMessage[pos];
|
|
|
-
|
|
|
- pos += AAS_Header->ReceiverThumbprint.Length;
|
|
|
- return pos;
|
|
|
+ Int32 err = 0;
|
|
|
+ err += decodeUAByteString(rawMessage->message,pos,AAS_Header->SecurityPolicyUri);
|
|
|
+ err += decodeUAByteString(rawMessage->message,pos,AAS_Header->SenderCertificate);
|
|
|
+ err += decodeUAByteString(rawMessage->message,pos,AAS_Header->ReceiverThumbprint);
|
|
|
+ return err;
|
|
|
}
|
|
|
void SL_secureChannel_Footer_get()
|
|
|
{
|
|
|
|
|
|
}
|
|
|
-void SL_secureChannel_Message_get(UA_connection *connection,
|
|
|
- AD_RawMessage *rawMessage, UInt32 pos, AD_RawMessage *message)
|
|
|
-{
|
|
|
-
|
|
|
-}
|