|
@@ -8,36 +8,147 @@
|
|
#include <stdio.h>
|
|
#include <stdio.h>
|
|
#include "opcua_time.h"
|
|
#include "opcua_time.h"
|
|
|
|
|
|
|
|
+#define SIZE_SECURECHANNEL_HEADER 12
|
|
|
|
+#define SIZE_SEQHEADER_HEADER 8
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+/*
|
|
|
|
+ * inits a connection object for secure channel layer
|
|
|
|
+ */
|
|
|
|
+Int32 SL_initConnectionObject(UA_connection *connection)
|
|
|
|
+{
|
|
|
|
+
|
|
|
|
+ //TODO: fill with valid information
|
|
|
|
+ connection->secureLayer.localtAsymAlgSettings.ReceiverCertificateThumbprint.Data = NULL;
|
|
|
|
+ connection->secureLayer.localtAsymAlgSettings.ReceiverCertificateThumbprint.Length = 0;
|
|
|
|
+
|
|
|
|
+ connection->secureLayer.localtAsymAlgSettings.SecurityPolicyUri.Data = "http://opcfoundation.org/UA/SecurityPolicy#None";
|
|
|
|
+ connection->secureLayer.localtAsymAlgSettings.SecurityPolicyUri.Length = 47;
|
|
|
|
+
|
|
|
|
+ connection->secureLayer.localtAsymAlgSettings.SenderCertificate.Data = NULL;
|
|
|
|
+ connection->secureLayer.localtAsymAlgSettings.SenderCertificate.Length = 0;
|
|
|
|
+
|
|
|
|
+ connection->secureLayer.remoteNonce.Data = NULL;
|
|
|
|
+ connection->secureLayer.remoteNonce.Length = 0;
|
|
|
|
+
|
|
|
|
+ connection->secureLayer.localNonce.Data = (Byte*)opcua_malloc(sizeof(Byte));
|
|
|
|
+ *connection->secureLayer.localNonce.Data = sizeof(Byte);
|
|
|
|
+ connection->secureLayer.localNonce.Length = 1;
|
|
|
|
+
|
|
|
|
+ connection->secureLayer.connectionState = connectionState_CLOSED;
|
|
|
|
+
|
|
|
|
+ connection->secureLayer.requestId = 0;
|
|
|
|
+
|
|
|
|
+ connection->secureLayer.requestType = 0;
|
|
|
|
+
|
|
|
|
+ connection->secureLayer.secureChannelId.Data = NULL;
|
|
|
|
+ connection->secureLayer.secureChannelId.Length = 0;
|
|
|
|
+
|
|
|
|
+ connection->secureLayer.securityMode = securityMode_INVALID;
|
|
|
|
+ //TODO set a valid start secureChannelId number
|
|
|
|
+ connection->secureLayer.securityToken.secureChannelId = 25;
|
|
|
|
+
|
|
|
|
+ //TODO set a valid start TokenId
|
|
|
|
+ connection->secureLayer.securityToken.tokenId = 1;
|
|
|
|
+ connection->secureLayer.sequenceNumber = 1;
|
|
|
|
+
|
|
|
|
+ return UA_NO_ERROR;
|
|
|
|
+}
|
|
|
|
+
|
|
Int32 SL_send(UA_connection *connection, UA_ByteString responseMessage, Int32 type)
|
|
Int32 SL_send(UA_connection *connection, UA_ByteString responseMessage, Int32 type)
|
|
{
|
|
{
|
|
UInt32 sequenceNumber;
|
|
UInt32 sequenceNumber;
|
|
UInt32 requestId;
|
|
UInt32 requestId;
|
|
- char securityPolicy[] = "http://opcfoundation.org/UA/SecurityPolicy#None";
|
|
|
|
- SL_AsymmetricAlgorithmSecurityHeader AAS_header;
|
|
|
|
-
|
|
|
|
|
|
+ Int32 pos;
|
|
|
|
+ Int32 sizeAsymAlgHeader;
|
|
|
|
+ UA_ByteString responsePacket;
|
|
|
|
+ Int32 packetSize;
|
|
|
|
+ Int32 sizePadding;
|
|
|
|
+ Int32 sizeSignature;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ sizeAsymAlgHeader = 3 * sizeof(UInt32) +
|
|
|
|
+ connection->secureLayer.localtAsymAlgSettings.SecurityPolicyUri.Length +
|
|
|
|
+ connection->secureLayer.localtAsymAlgSettings.SenderCertificate.Length +
|
|
|
|
+ connection->secureLayer.localtAsymAlgSettings.ReceiverCertificateThumbprint.Length;
|
|
|
|
+ pos = 0;
|
|
//sequence header
|
|
//sequence header
|
|
sequenceNumber = connection->secureLayer.sequenceNumber;
|
|
sequenceNumber = connection->secureLayer.sequenceNumber;
|
|
- requestId = connection->secureLayer.requestId;
|
|
|
|
|
|
+ requestId = connection->secureLayer.requestId;
|
|
|
|
|
|
|
|
|
|
if(type == 449) //openSecureChannelResponse -> asymmetric algorithm
|
|
if(type == 449) //openSecureChannelResponse -> asymmetric algorithm
|
|
{
|
|
{
|
|
- AAS_header.SecurityPolicyUri.Length = strlen(securityPolicy);
|
|
|
|
- AAS_header.SecurityPolicyUri.Data = securityPolicy;
|
|
|
|
- AAS_header.SenderCertificate.Length = -1;
|
|
|
|
- AAS_header.ReceiverThumbprint.Length = -1;
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- //TODO add Symmetric Security
|
|
|
|
|
|
+ //TODO fill with valid sizes
|
|
|
|
+ sizePadding = 0;
|
|
|
|
+ sizeSignature = 0;
|
|
|
|
+
|
|
|
|
+ //TODO: size calculation need
|
|
|
|
+ packetSize = SIZE_SECURECHANNEL_HEADER +
|
|
|
|
+ SIZE_SEQHEADER_HEADER +
|
|
|
|
+ sizeAsymAlgHeader +
|
|
|
|
+ responseMessage.Length +
|
|
|
|
+ sizePadding +
|
|
|
|
+ sizeSignature;
|
|
|
|
+
|
|
|
|
+ //get memory for response
|
|
|
|
+ responsePacket.Data = (char*)opcua_malloc(packetSize);
|
|
|
|
+
|
|
|
|
+ responsePacket.Length = packetSize;
|
|
|
|
+
|
|
|
|
+ /*---encode Secure Conversation Message Header ---*/
|
|
|
|
+ //encode MessageType - OPN message
|
|
|
|
+ responsePacket.Data[0] = 'O';
|
|
|
|
+ responsePacket.Data[1] = 'P';
|
|
|
|
+ responsePacket.Data[2] = 'N';
|
|
|
|
+ pos += 3;
|
|
|
|
+ //encode Chunk Type - set to final
|
|
|
|
+ responsePacket.Data[3] = 'F';
|
|
|
|
+ pos += 1;
|
|
|
|
+ encoder_encodeBuiltInDatatype(&packetSize,INT32,&pos,responsePacket.Data);
|
|
|
|
+ encoder_encodeBuiltInDatatype(&(connection->secureLayer.securityToken.secureChannelId),
|
|
|
|
+ INT32,&pos,responsePacket.Data);
|
|
|
|
+
|
|
|
|
+ /*---encode Asymmetric Algorithm Header ---*/
|
|
|
|
+ encoder_encodeBuiltInDatatype(&(connection->secureLayer.localtAsymAlgSettings.SecurityPolicyUri),
|
|
|
|
+ BYTE_STRING,&pos,responsePacket.Data);
|
|
|
|
+ encoder_encodeBuiltInDatatype(&(connection->secureLayer.localtAsymAlgSettings.SenderCertificate),
|
|
|
|
+ BYTE_STRING,&pos,responsePacket.Data );
|
|
|
|
+ encoder_encodeBuiltInDatatype(&(connection->secureLayer.localtAsymAlgSettings.ReceiverCertificateThumbprint),
|
|
|
|
+ BYTE_STRING,&pos,responsePacket.Data );
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /*---encode Sequence Header ---*/
|
|
|
|
+ encoder_encodeBuiltInDatatype(&sequenceNumber,UINT32,&pos,responsePacket.Data);
|
|
|
|
+ encoder_encodeBuiltInDatatype(&requestId,UINT32,&pos,responsePacket.Data);
|
|
|
|
+
|
|
|
|
+ /*---add encoded Message ---*/
|
|
|
|
+ memcpy(&(responsePacket.Data[pos]), responseMessage.Data, responseMessage.Length);
|
|
|
|
+
|
|
|
|
+ /* sign Data*/
|
|
|
|
+
|
|
|
|
+ /* encrypt Data */
|
|
|
|
+
|
|
|
|
+ /* send Data */
|
|
|
|
+ TL_send(connection,&responsePacket);
|
|
|
|
+
|
|
|
|
+
|
|
return UA_NO_ERROR;
|
|
return UA_NO_ERROR;
|
|
}
|
|
}
|
|
|
|
+
|
|
/*
|
|
/*
|
|
* opens a secure channel
|
|
* opens a secure channel
|
|
*/
|
|
*/
|
|
-Int32 SL_openSecureChannel(UA_connection *connection, IntegerId requestHandle, UA_StatusCode serviceResult, UA_DiagnosticInfo *serviceDiagnostics)
|
|
|
|
|
|
+Int32 SL_openSecureChannel(UA_connection *connection,
|
|
|
|
+ UA_AD_RequestHeader *requestHeader,
|
|
|
|
+ UA_StatusCode serviceResult)
|
|
{
|
|
{
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
UA_AD_ResponseHeader responseHeader;
|
|
UA_AD_ResponseHeader responseHeader;
|
|
UA_ExtensionObject additionalHeader;
|
|
UA_ExtensionObject additionalHeader;
|
|
SL_ChannelSecurityToken securityToken;
|
|
SL_ChannelSecurityToken securityToken;
|
|
@@ -46,17 +157,32 @@ Int32 SL_openSecureChannel(UA_connection *connection, IntegerId requestHandle, U
|
|
//sizes for memory allocation
|
|
//sizes for memory allocation
|
|
Int32 sizeResponse;
|
|
Int32 sizeResponse;
|
|
Int32 sizeRespHeader;
|
|
Int32 sizeRespHeader;
|
|
|
|
+ Int32 sizeResponseType;
|
|
Int32 sizeRespMessage;
|
|
Int32 sizeRespMessage;
|
|
Int32 sizeSecurityToken;
|
|
Int32 sizeSecurityToken;
|
|
UA_ByteString response;
|
|
UA_ByteString response;
|
|
UInt32 serverProtocolVersion;
|
|
UInt32 serverProtocolVersion;
|
|
- Int32 pos = 0;
|
|
|
|
|
|
+ Int32 pos;
|
|
|
|
+ UA_DiagnosticInfo serviceDiagnostics;
|
|
|
|
|
|
|
|
+ if(requestHeader->returnDiagnostics != 0)
|
|
|
|
+ {
|
|
|
|
+ printf("SL_openSecureChannel - diagnostics demanded by the client\n");
|
|
|
|
+ printf("SL_openSecureChannel - retrieving diagnostics not implemented!\n");
|
|
|
|
+ //TODO fill with demanded information part 4, 7.8 - Table 123
|
|
|
|
+ serviceDiagnostics.EncodingMask = 0;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ serviceDiagnostics.EncodingMask = 0;
|
|
|
|
+ }
|
|
/*--------------type ----------------------*/
|
|
/*--------------type ----------------------*/
|
|
|
|
+
|
|
//Four Bytes Encoding
|
|
//Four Bytes Encoding
|
|
responseType.EncodingByte = NIEVT_FOUR_BYTE;
|
|
responseType.EncodingByte = NIEVT_FOUR_BYTE;
|
|
- responseType.Namespace = 0;
|
|
|
|
|
|
+ //openSecureChannelResponse = 449
|
|
responseType.Identifier.Numeric = 449;
|
|
responseType.Identifier.Numeric = 449;
|
|
|
|
+ responseType.Namespace = 0;
|
|
|
|
|
|
/*--------------responseHeader-------------*/
|
|
/*--------------responseHeader-------------*/
|
|
|
|
|
|
@@ -69,68 +195,113 @@ Int32 SL_openSecureChannel(UA_connection *connection, IntegerId requestHandle, U
|
|
* addtionalHeader Extensible Parameter
|
|
* addtionalHeader Extensible Parameter
|
|
*/
|
|
*/
|
|
//current time
|
|
//current time
|
|
- responseHeader.timestamp = opcua_getTime();
|
|
|
|
|
|
+
|
|
|
|
+ responseHeader.timestamp = opcua_time_now();
|
|
//request Handle which client sent
|
|
//request Handle which client sent
|
|
- responseHeader.requestHandle = requestHandle;
|
|
|
|
|
|
+ responseHeader.requestHandle = requestHeader->requestHandle;
|
|
// StatusCode which informs client about quality of response
|
|
// StatusCode which informs client about quality of response
|
|
responseHeader.serviceResult = serviceResult;
|
|
responseHeader.serviceResult = serviceResult;
|
|
//retrieve diagnosticInfo if client demands
|
|
//retrieve diagnosticInfo if client demands
|
|
- responseHeader.serviceDiagnostics = serviceDiagnostics;
|
|
|
|
|
|
+ responseHeader.serviceDiagnostics = &serviceDiagnostics;
|
|
|
|
|
|
//text of fields defined in the serviceDiagnostics
|
|
//text of fields defined in the serviceDiagnostics
|
|
responseHeader.noOfStringTable = 0;
|
|
responseHeader.noOfStringTable = 0;
|
|
responseHeader.stringTable = NULL;
|
|
responseHeader.stringTable = NULL;
|
|
|
|
|
|
|
|
+
|
|
// no additional header
|
|
// no additional header
|
|
- responseHeader.additionalHeader = &the_empty_UA_ExtensionObject;
|
|
|
|
|
|
+ additionalHeader.Encoding = 0;
|
|
|
|
+
|
|
|
|
+ additionalHeader.Body.Data = NULL;
|
|
|
|
+ additionalHeader.Body.Length = 0;
|
|
|
|
|
|
|
|
+ additionalHeader.TypeId.EncodingByte = 0;
|
|
|
|
+ additionalHeader.TypeId.Namespace = 0;
|
|
|
|
+ additionalHeader.TypeId.Identifier.Numeric = 0;
|
|
|
|
|
|
|
|
+ responseHeader.additionalHeader = &additionalHeader;
|
|
|
|
+ printf("SL_openSecureChannel - built response header\n");
|
|
|
|
+
|
|
|
|
+ //calculate the size
|
|
|
|
+ sizeRespHeader = responseHeader_calcSize(&responseHeader);
|
|
|
|
+ printf("SL_openSecureChannel - size response header =%d\n",sizeRespHeader);
|
|
/*--------------responseMessage-------------*/
|
|
/*--------------responseMessage-------------*/
|
|
/* Res-2) UInt32 ServerProtocolVersion
|
|
/* Res-2) UInt32 ServerProtocolVersion
|
|
* Res-3) SecurityToken channelSecurityToken
|
|
* Res-3) SecurityToken channelSecurityToken
|
|
* Res-5) ByteString ServerNonce
|
|
* Res-5) ByteString ServerNonce
|
|
*/
|
|
*/
|
|
|
|
+
|
|
// secureChannelId + TokenId + CreatedAt + RevisedLifetime
|
|
// secureChannelId + TokenId + CreatedAt + RevisedLifetime
|
|
sizeSecurityToken = sizeof(UInt32) + sizeof(UInt32) + sizeof(UA_DateTime) + sizeof(Int32);
|
|
sizeSecurityToken = sizeof(UInt32) + sizeof(UInt32) + sizeof(UA_DateTime) + sizeof(Int32);
|
|
|
|
|
|
- serverProtocolVersion = connection->transportLayer.localConf.protocolVersion;
|
|
|
|
|
|
+ //ignore server nonce
|
|
|
|
+ serverNonce.Length = -1;
|
|
|
|
+ serverNonce.Data = NULL;
|
|
|
|
+
|
|
|
|
+ serverNonce.Length = connection->secureLayer.localNonce.Length;
|
|
|
|
+ serverNonce.Data = connection->secureLayer.localNonce.Data;
|
|
|
|
|
|
- //fill toke structure with default server information
|
|
|
|
|
|
+ //fill token structure with default server information
|
|
securityToken.secureChannelId = connection->secureLayer.securityToken.secureChannelId;
|
|
securityToken.secureChannelId = connection->secureLayer.securityToken.secureChannelId;
|
|
securityToken.tokenId = connection->secureLayer.securityToken.tokenId;
|
|
securityToken.tokenId = connection->secureLayer.securityToken.tokenId;
|
|
- securityToken.createdAt = opcua_getTime();
|
|
|
|
|
|
+ securityToken.createdAt = opcua_time_now();
|
|
securityToken.revisedLifetime = connection->secureLayer.securityToken.revisedLifetime;
|
|
securityToken.revisedLifetime = connection->secureLayer.securityToken.revisedLifetime;
|
|
|
|
|
|
- // server nonce
|
|
|
|
- serverNonce.Length = -1;
|
|
|
|
|
|
+ serverProtocolVersion = connection->transportLayer.localConf.protocolVersion;
|
|
|
|
|
|
- //calculate the size
|
|
|
|
- sizeRespHeader = responseHeader_calcSize(&responseHeader);
|
|
|
|
// ProtocolVersion + SecurityToken + Nonce
|
|
// ProtocolVersion + SecurityToken + Nonce
|
|
- sizeRespMessage = sizeof(Int32) + sizeSecurityToken + UAByteString_calcSize(&serverNonce);
|
|
|
|
|
|
+ sizeRespMessage = sizeof(UInt32) + serverNonce.Length + sizeof(Int32) + sizeSecurityToken;
|
|
|
|
+ printf("SL_openSecureChannel - size of response message=%d\n",sizeRespMessage);
|
|
|
|
+
|
|
|
|
|
|
//get memory for response
|
|
//get memory for response
|
|
- response.Length = nodeId_calcSize(&responseType) + sizeRespHeader + sizeRespMessage;
|
|
|
|
- response.Data = (char*) opcua_malloc(response.Length);
|
|
|
|
|
|
+ sizeResponseType = nodeId_calcSize(&responseType);
|
|
|
|
+
|
|
|
|
+ response.Length = sizeResponseType + sizeRespHeader + sizeRespMessage;
|
|
|
|
|
|
|
|
+ //get memory for response
|
|
|
|
+ response.Data = (char*)opcua_malloc(nodeId_calcSize(&responseType) + sizeRespHeader + sizeRespMessage);
|
|
|
|
+ pos = 0;
|
|
//encode responseType (NodeId)
|
|
//encode responseType (NodeId)
|
|
- encoder_encodeBuiltInDatatype(&responseType,NODE_ID,&pos,response.Data);
|
|
|
|
|
|
+ UA_NodeId_printf("SL_openSecureChannel - TypeId =",&responseType);
|
|
|
|
+ encoder_encodeBuiltInDatatype(&responseType, NODE_ID, &pos, response.Data);
|
|
|
|
+
|
|
//encode header
|
|
//encode header
|
|
- encodeResponseHeader(&responseHeader,&pos, &response);
|
|
|
|
|
|
+ printf("SL_openSecureChannel - encoding response header \n");
|
|
|
|
+
|
|
|
|
+ encodeResponseHeader(&responseHeader, &pos, &response);
|
|
|
|
+ printf("SL_openSecureChannel - response header encoded \n");
|
|
|
|
+
|
|
//encode message
|
|
//encode message
|
|
|
|
+ printf("SL_openSecureChannel - serverProtocolVersion = %d \n",serverProtocolVersion);
|
|
encoder_encodeBuiltInDatatype(&serverProtocolVersion, UINT32, &pos,response.Data);
|
|
encoder_encodeBuiltInDatatype(&serverProtocolVersion, UINT32, &pos,response.Data);
|
|
- encoder_encodeBuiltInDatatype(&securityToken.secureChannelId, UINT32, &pos,response.Data);
|
|
|
|
- encoder_encodeBuiltInDatatype(&securityToken.tokenId, INT32, &pos,response.Data);
|
|
|
|
- encoder_encodeBuiltInDatatype(&securityToken.createdAt, DATE_TIME, &pos,response.Data);
|
|
|
|
- encoder_encodeBuiltInDatatype(&securityToken.revisedLifetime, INT32, &pos,response.Data);
|
|
|
|
|
|
+ printf("SL_openSecureChannel - secureChannelId = %d \n",securityToken.secureChannelId);
|
|
|
|
+ encoder_encodeBuiltInDatatype(&(securityToken.secureChannelId), UINT32, &pos,response.Data);
|
|
|
|
+ printf("SL_openSecureChannel - tokenId = %d \n",securityToken.tokenId);
|
|
|
|
+ encoder_encodeBuiltInDatatype(&(securityToken.tokenId), INT32, &pos,response.Data);
|
|
|
|
+
|
|
|
|
+ encoder_encodeBuiltInDatatype(&(securityToken.createdAt), DATE_TIME, &pos,response.Data);
|
|
|
|
+ printf("SL_openSecureChannel - revisedLifetime = %d \n",securityToken.revisedLifetime);
|
|
|
|
+ encoder_encodeBuiltInDatatype(&(securityToken.revisedLifetime), INT32, &pos,response.Data);
|
|
|
|
+
|
|
encoder_encodeBuiltInDatatype(&serverNonce, BYTE_STRING, &pos,response.Data);
|
|
encoder_encodeBuiltInDatatype(&serverNonce, BYTE_STRING, &pos,response.Data);
|
|
|
|
|
|
|
|
+ printf("SL_openSecureChannel - response.Length = %d \n",response.Length);
|
|
//449 = openSecureChannelResponse
|
|
//449 = openSecureChannelResponse
|
|
- UA_ByteString_printx("SL_processMessage - response=", &response);
|
|
|
|
- SL_send(connection,response,449);
|
|
|
|
|
|
+ SL_send(connection, response, 449);
|
|
|
|
|
|
return UA_NO_ERROR;
|
|
return UA_NO_ERROR;
|
|
}
|
|
}
|
|
|
|
+/*
|
|
|
|
+Int32 SL_openSecureChannel_responseMessage_calcSize(SL_Response *response,
|
|
|
|
+ Int32* sizeInOut) {
|
|
|
|
+ Int32 length = 0;
|
|
|
|
+ length += sizeof(response->SecurityToken);
|
|
|
|
+ length += UAString_calcSize(response->ServerNonce);
|
|
|
|
+ length += sizeof(response->ServerProtocolVersion);
|
|
|
|
+ return length;
|
|
|
|
+}
|
|
|
|
+*/
|
|
/*
|
|
/*
|
|
* closes a secureChannel (server side)
|
|
* closes a secureChannel (server side)
|
|
*/
|
|
*/
|
|
@@ -148,11 +319,16 @@ Int32 SL_processMessage(UA_connection *connection, UA_ByteString message) {
|
|
UA_DiagnosticInfo serviceDiagnostics;
|
|
UA_DiagnosticInfo serviceDiagnostics;
|
|
|
|
|
|
Int32 pos = 0;
|
|
Int32 pos = 0;
|
|
- // Every Message starts with a NodeID which names the serviceRequestType
|
|
|
|
|
|
+ UA_AD_RequestHeader requestHeader;
|
|
|
|
+ UInt32 clientProtocolVersion;
|
|
UA_NodeId serviceRequestType;
|
|
UA_NodeId serviceRequestType;
|
|
|
|
+ Int32 requestType;
|
|
|
|
+ Int32 securityMode;
|
|
|
|
+ Int32 requestedLifetime;
|
|
|
|
+ UA_ByteString clientNonce;
|
|
|
|
+ UA_StatusCode serviceResult;
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+ // Every Message starts with a NodeID which names the serviceRequestType
|
|
decoder_decodeBuiltInDatatype(message.Data, NODE_ID, &pos,
|
|
decoder_decodeBuiltInDatatype(message.Data, NODE_ID, &pos,
|
|
&serviceRequestType);
|
|
&serviceRequestType);
|
|
UA_NodeId_printf("SL_processMessage - serviceRequestType=",
|
|
UA_NodeId_printf("SL_processMessage - serviceRequestType=",
|
|
@@ -232,6 +408,8 @@ Int32 SL_processMessage(UA_connection *connection, UA_ByteString message) {
|
|
printf("SL_processMessage - securityMode=%d\n", securityMode);
|
|
printf("SL_processMessage - securityMode=%d\n", securityMode);
|
|
switch (securityMode) {
|
|
switch (securityMode) {
|
|
case securityMode_INVALID:
|
|
case securityMode_INVALID:
|
|
|
|
+ connection->secureLayer.remoteNonce.Data = NULL;
|
|
|
|
+ connection->secureLayer.remoteNonce.Length = 0;
|
|
printf("SL_processMessage - client demands no security \n");
|
|
printf("SL_processMessage - client demands no security \n");
|
|
break;
|
|
break;
|
|
|
|
|
|
@@ -258,11 +436,12 @@ Int32 SL_processMessage(UA_connection *connection, UA_ByteString message) {
|
|
//TODO process requestedLifetime
|
|
//TODO process requestedLifetime
|
|
|
|
|
|
// 62541-4 §7.27 "The requestHandle given by the Client to the request."
|
|
// 62541-4 §7.27 "The requestHandle given by the Client to the request."
|
|
- return SL_openSecureChannel(connection, requestHeader.requestHandle, SC_Good, &serviceDiagnostics);
|
|
|
|
|
|
+ return SL_openSecureChannel(connection, &requestHeader, SC_Good);
|
|
} else {
|
|
} else {
|
|
printf("SL_processMessage - unknown service request");
|
|
printf("SL_processMessage - unknown service request");
|
|
//TODO change error code
|
|
//TODO change error code
|
|
return UA_ERROR;
|
|
return UA_ERROR;
|
|
|
|
+
|
|
}
|
|
}
|
|
return UA_NO_ERROR;
|
|
return UA_NO_ERROR;
|
|
}
|
|
}
|
|
@@ -304,7 +483,7 @@ void SL_receive(UA_connection *connection, UA_ByteString *serviceMessage) {
|
|
if (SCM_Header.SecureChannelId != 0) {
|
|
if (SCM_Header.SecureChannelId != 0) {
|
|
|
|
|
|
iTmp = UA_ByteString_compare(
|
|
iTmp = UA_ByteString_compare(
|
|
- &(connection->secureLayer.SenderCertificate),
|
|
|
|
|
|
+ &(connection->secureLayer.remoteAsymAlgSettings.SenderCertificate),
|
|
&(AAS_Header.SenderCertificate));
|
|
&(AAS_Header.SenderCertificate));
|
|
if (iTmp != UA_EQUAL) {
|
|
if (iTmp != UA_EQUAL) {
|
|
printf("SL_receive - UA_ERROR_BadSecureChannelUnknown \n");
|
|
printf("SL_receive - UA_ERROR_BadSecureChannelUnknown \n");
|
|
@@ -312,6 +491,10 @@ void SL_receive(UA_connection *connection, UA_ByteString *serviceMessage) {
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ //TODO invalid securechannelId
|
|
|
|
+ }
|
|
|
|
|
|
decodeSequenceHeader(&secureChannelPacket, &pos, &SequenceHeader);
|
|
decodeSequenceHeader(&secureChannelPacket, &pos, &SequenceHeader);
|
|
printf("SL_receive - SequenceHeader.RequestId=%d\n",
|
|
printf("SL_receive - SequenceHeader.RequestId=%d\n",
|
|
@@ -431,6 +614,7 @@ Int32 decodeSCMHeader(UA_ByteString *rawMessage, Int32 *pos,
|
|
return UA_NO_ERROR;
|
|
return UA_NO_ERROR;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+/*
|
|
Int32 encodeSCMHeader(SL_SecureConversationMessageHeader *SC_Header, Int32 *pos,
|
|
Int32 encodeSCMHeader(SL_SecureConversationMessageHeader *SC_Header, Int32 *pos,
|
|
AD_RawMessage *rawMessage) {
|
|
AD_RawMessage *rawMessage) {
|
|
const char *type = "ERR";
|
|
const char *type = "ERR";
|
|
@@ -461,8 +645,11 @@ Int32 encodeSCMHeader(SL_SecureConversationMessageHeader *SC_Header, Int32 *pos,
|
|
|
|
|
|
return UA_NO_ERROR;
|
|
return UA_NO_ERROR;
|
|
}
|
|
}
|
|
|
|
+*/
|
|
|
|
+
|
|
Int32 decodeSequenceHeader(UA_ByteString *rawMessage, Int32 *pos,
|
|
Int32 decodeSequenceHeader(UA_ByteString *rawMessage, Int32 *pos,
|
|
SL_SequenceHeader *SequenceHeader) {
|
|
SL_SequenceHeader *SequenceHeader) {
|
|
|
|
+ decodeUInt32(rawMessage->Data, pos, &(SequenceHeader->SequenceNumber));
|
|
decodeUInt32(rawMessage->Data, pos, &(SequenceHeader->RequestId));
|
|
decodeUInt32(rawMessage->Data, pos, &(SequenceHeader->RequestId));
|
|
decodeUInt32(rawMessage->Data, pos, &(SequenceHeader->SequenceNumber));
|
|
decodeUInt32(rawMessage->Data, pos, &(SequenceHeader->SequenceNumber));
|
|
return UA_NO_ERROR;
|
|
return UA_NO_ERROR;
|