Browse Source

Merge branch 'master' of https://github.com/acplt/open62541.git

Leon Urbas 11 years ago
parent
commit
7b6b54a894

+ 1 - 1
README.md

@@ -58,7 +58,7 @@ $ git clone https://github.com/acplt/open62541.git
 ```bash
 $ cd open62541
 $ ./autogen.sh
-$ ./configure
+$ ./configure --enable-debug
 $ make
 $ make check
 ```

+ 6 - 1
configure.ac

@@ -7,8 +7,10 @@ AC_INIT(OPCUAServer, 1.0)
 AC_CANONICAL_SYSTEM
 AM_INIT_AUTOMAKE()
 AC_PROG_MAKE_SET
+#default CFLAGS is -g -02
+#reset it just to -g and make optimization dependend on --enable-debug
 if test -z $CFLAGS; then
-    CFLAGS='-O0'
+    CFLAGS='-g'
 fi
 AC_PROG_CC
 AC_PROG_LN_S
@@ -37,6 +39,9 @@ esac],
 [debug=false])
 
 AM_CONDITIONAL(DEBUG, test x"$debug" = x"true")
+AM_COND_IF([DEBUG],
+    AC_DEFINE([DEBUG])) #define DEBUG is accessible from pre-processor
+
    
 AC_LIBTOOL_WIN32_DLL
 AC_PROG_LIBTOOL

+ 7 - 1
examples/src/Makefile.am

@@ -1,5 +1,11 @@
-
 bin_PROGRAMS= $(top_builddir)/bin/exampleServer
 __top_builddir__bin_exampleServer_LDFLAGS = -all-static
 __top_builddir__bin_exampleServer_SOURCES = opcuaServer.c
 __top_builddir__bin_exampleServer_LDADD= ../../lib/libopen62541.a
+
+#optimization levels depending on debug
+if DEBUG
+        AM_CFLAGS = -O0
+else
+        AM_CFLAGS = -O2
+endif

+ 7 - 30
src/Makefile.am

@@ -1,21 +1,3 @@
-
-#__top_builddir__bin_stackTest_out_SOURCES =	opcuaServer.c\
-#											opcua_builtInDatatypes.c\
-#											opcua_binaryEncDec.c\
-#											opcua_transportLayer.c\
-#											opcua_builtInDatatypes.h\
-#											opcua_binaryEncDec.h\
-#											opcua_transportLayer.h\
-#											opcua_advancedDatatypes.h\
-#											opcua_types.h\
-#											opcua_connectionHelper.h\
-#											tcp_layer.h
-
-#lib_LTLIBRARIES = libstack.la
-#libstack_la_SOURCES = opcua_transportLayer.c\
-#					  opcua_transportLayer.h\
-#					  opcua_advancedDatatypes.h\
-#					  opcua_connectionHelper.h	
 lib_LTLIBRARIES = libopen62541.la
 libopen62541_la_LDFLAGS = -avoid-version -no-undefined
 libopen62541_la_SOURCES = opcua_builtInDatatypes.c\
@@ -38,18 +20,6 @@ libopen62541_la_SOURCES = opcua_builtInDatatypes.c\
 						opcua_time.h\
 						tcp_layer.h						
 
-#bin_PROGRAMS= $(top_builddir)/bin/open62541.out
-#__top_builddir__bin_libOpen62541_out_SOURCES = opcuaServer.c
-#libOpen62541_la_LIBADD = ../lib/libOpen62541.la		  										
-
-if DEBUG
-AM_CFLAGS = -g -O0
-AM_CXXFLAGS = -g -O0
-else
-AM_CFLAGS = -O2
-AM_CXXFLAGS = -O2
-endif
-
 .PHONY: convenience-link clean-convenience-link
 
 convenience-link: $(lib_LTLIBRARIES)
@@ -76,3 +46,10 @@ all-local: convenience-link
 
 clean-local: clean-convenience-link
 
+#optimization levels depending on debug
+if DEBUG
+        AM_CFLAGS = -O0
+else
+        AM_CFLAGS = -O2
+endif
+

+ 8 - 8
src/opcua_advancedDatatypes.h

@@ -724,16 +724,16 @@ enum BED_RequestReturnDiagnositcs
 * Chapter: 7.27
 * Page: 133
 */
-struct BED_ResponseHeader
+/*typedef struct UA_AD_ResponseHeader
 {
 	UA_DateTime timestamp;
-	BED_IntegerId requestHandle;
+	UInt32 requestHandle;
 	UA_StatusCode serviceResult;
 	UA_DiagnosticInfo *serviceDiagnostics;
-	UA_String stringTable[];
-//ToDo	struct BED_ExtensibleParameterAdditionalHeader additionalHeader;		//ToDo
-};
-
+	UA_String *stringTable;
+    UA_AD_ExtensibleParameter *additionalHeader;
+}UA_AD_ResponseHeader;
+*/
 
 /**
 * ServiceFault
@@ -741,11 +741,11 @@ struct BED_ResponseHeader
 * Chapter: 7.28
 * Page: 133
 */
-struct BED_ServiceFault
+/*struct BED_ServiceFault
 {
 	struct BED_ResponseHeader responseHeader;
 };
-
+*/
 
 //ToDo: Own DataType with typeDef?
 /**

+ 2 - 2
src/opcua_connectionHelper.h

@@ -63,12 +63,12 @@ struct SL_connection
 	UInt32 sequenceNumber;
 	UInt32 requestType;
 	UA_String secureChannelId;
-	UInt32 UInt32_secureChannelId;
+	//UInt32 UInt32_secureChannelId;
 	UInt32 securityMode;
 	UA_ByteString clientNonce;
 	UInt32 connectionState;
 	SL_ChannelSecurityToken securityToken;
-
+	UInt32 requestId; // request Id of the current request
 };
 
 struct SS_connection

+ 121 - 42
src/opcua_secureChannelLayer.c

@@ -6,50 +6,133 @@
  */
 #include "opcua_secureChannelLayer.h"
 #include <stdio.h>
+#include "opcua_time.h"
 
-/*
- * opens a secureChannel (server side)
- */
-Int32 SL_secureChannel_open(const UA_connection *connection,
-		const AD_RawMessage *secureChannelPacket,
-		const SL_SecureConversationMessageHeader *SCMHeader,
-		const SL_AsymmetricAlgorithmSecurityHeader *AASHeader,
-		const SL_SequenceHeader *SequenceHeader) {
-	UA_AD_ResponseHeader responseHeader;
-	AD_RawMessage rawMessage;
-	Int32 position = 0;
-	//SL_secureChannel_ResponseHeader_get(connection,&responseHeader);
-	Int32 size = responseHeader_calcSize(&responseHeader);
-	rawMessage.message = (char*) opcua_malloc(size);
+Int32 SL_send(UA_connection *connection, UA_ByteString responseMessage, Int32 type)
+{
+	UInt32 sequenceNumber;
+	UInt32 requestId;
+	//TODO: fill with valid information
+	char securityPolicy[] = "http://opcfoundation.org/UA/SecurityPolicy#None";
 
-	encodeResponseHeader(&responseHeader, &position, &rawMessage);
+	//sequence header
+	sequenceNumber = connection->secureLayer.sequenceNumber;
+	requestId = connection->secureLayer.requestId;
 
-	rawMessage.length = position;
 
+
+	if(type == 449) //openSecureChannelResponse -> asymmetric algorithm
+	{
+		//TODO add Asymmetric Security Header
+	}
+	else
+	{
+		//TODO add Symmetric Security
+	}
 	return UA_NO_ERROR;
 }
+/*
+ * opens a secure channel
+ */
+Int32 SL_openSecureChannel(UA_connection *connection, IntegerId requestHandle, UA_StatusCode serviceResult, UA_AD_DiagnosticInfo *serviceDiagnostics)
+{
 
-Int32 SL_openSecureChannel_responseMessage_get(UA_connection *connection,
-		SL_Response *response, Int32* sizeInOut) {
 
-	response->ServerNonce.Length = 0; // TODO set a valid value for the Server Nonce
-	response->ServerProtocolVersion = 0; //
-	response->SecurityToken.createdAt = opcua_getTime(); //
-	response->SecurityToken.revisedLifetime = 300000; //TODO set Lifetime of Security Token
-	response->SecurityToken.secureChannelId =
-			connection->secureLayer.UInt32_secureChannelId; //TODO set a valid value for secureChannel id
-	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;
-}
+	UA_AD_ResponseHeader responseHeader;
+	SL_ChannelSecurityToken securityToken;
+	UA_ByteString serverNonce;
+	UA_NodeId responseType;
+	//sizes for memory allocation
+	Int32 sizeResponse;
+	Int32 sizeRespHeader;
+	Int32 sizeRespMessage;
+	Int32 sizeSecurityToken;
+	UA_ByteString response;
+	UInt32 serverProtocolVersion;
+	Int32 *pos;
+
+	/*--------------type ----------------------*/
+	//Four Bytes Encoding
+	responseType.EncodingByte = NIEVT_FOUR_BYTE;
+	//openSecureChannelResponse = 449
+	responseType.Identifier.Numeric = 449;
+
+	/*--------------responseHeader-------------*/
+
+	/* 	Res-1) ResponseHeader responseHeader
+	 * 		timestamp UtcTime
+	 * 		requestHandle IntegerId
+	 * 		serviceResult StatusCode
+	 * 		serviceDiagnostics DiagnosticInfo
+	 * 		stringTable[] String
+	 * 		addtionalHeader Extensible Parameter
+	 */
+	//current time
+	responseHeader.timestamp = opcua_getTime();
+	//request Handle which client sent
+	responseHeader.requestHandle = requestHandle;
+	// StatusCode which informs client about quality of response
+	responseHeader.serviceResult = serviceResult;
+	//retrive diagnosticInfo if client demands
+	responseHeader.serviceDiagnostics = serviceDiagnostics;
+
+	//text of fields defined in the serviceDiagnostics
+	responseHeader.noOfStringTable = 0;
+	responseHeader.stringTable = NULL;
+
+
+	// no additional header
+	responseHeader.additionalHeader->Encoding = 0;
+	responseHeader.additionalHeader->TypeId.EncodingByte = 0;
+	responseHeader.additionalHeader->TypeId.Identifier.Numeric = 0;
+
+	//calculate the size
+	sizeRespHeader = responseHeader_calcSize(&responseHeader);
+
+	/*--------------responseMessage-------------*/
+	/* 	Res-2) UInt32 ServerProtocolVersion
+	 * 	Res-3) SecurityToken channelSecurityToken
+	 *  Res-5) ByteString ServerNonce
+	*/
+	//                  secureChannelId + TokenId + CreatedAt + RevisedLifetime
+	sizeSecurityToken = sizeof(UInt32) + sizeof(UInt32) + sizeof(UA_DateTime) + sizeof(Int32);
+
+	//ignore server nonce
+	serverNonce.Length = 0;
+	serverNonce.Data = NULL;
+
+	//fill toke structure with default server information
+	securityToken.secureChannelId = connection->secureLayer.securityToken.secureChannelId;
+	securityToken.tokenId = connection->secureLayer.securityToken.tokenId;
+	securityToken.createdAt = opcua_getTime();
+	securityToken.revisedLifetime = connection->secureLayer.securityToken.revisedLifetime;
+
+	serverProtocolVersion = connection->transportLayer.localConf.protocolVersion;
+
+	//                ProtocolVersion + SecurityToken + Nonce
+	sizeRespMessage = sizeof(UInt32) + sizeSecurityToken + serverNonce.Length + sizeof(Int32) + sizeSecurityToken;
+
+	//get memory for response
+	response.Data = (char*)opcua_malloc(nodeId_calcSize(responseType) + sizeRespHeader + sizeRespMessage);
+	*pos = 0;
+	//encode responseType (NodeId)
+	encoder_encodeBuiltInDatatype(responseType,NODE_ID,pos,response.Data);
+	//encode header
+	encodeResponseHeader(&responseHeader,pos, &response);
+	//encode message
+	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);
+	encoder_encodeBuiltInDatatype(serverNonce, BYTE_STRING, pos,response.Data);
+
+	//449 = openSecureChannelResponse
+	SL_send(connection,response,449);
 
+	return UA_NO_ERROR;
+}
 /*
  * closes a secureChannel (server side)
  */
@@ -268,7 +351,8 @@ void SL_receive(UA_connection *connection, UA_ByteString *serviceMessage) {
 					SequenceHeader.RequestId);
 			printf("SL_receive - SequenceHeader.SequenceNr=%d\n",
 					SequenceHeader.SequenceNumber);
-
+			//save request id to return it to client
+			connection->secureLayer.requestId = SequenceHeader.RequestId;
 			//TODO check that the sequence number is smaller than MaxUInt32 - 1024
 			connection->secureLayer.sequenceNumber =
 					SequenceHeader.SequenceNumber;
@@ -285,7 +369,7 @@ void SL_receive(UA_connection *connection, UA_ByteString *serviceMessage) {
 					== connectionState_ESTABLISHED) {
 
 				if (SCM_Header.SecureChannelId
-						== connection->secureLayer.UInt32_secureChannelId) {
+						== connection->secureLayer.securityToken.secureChannelId) {
 
 				} else {
 					//TODO generate ERROR_Bad_SecureChannelUnkown
@@ -416,12 +500,7 @@ Int32 decodeSequenceHeader(UA_ByteString *rawMessage, Int32 *pos,
 	decodeUInt32(rawMessage->Data, pos, &(SequenceHeader->SequenceNumber));
 	return UA_NO_ERROR;
 }
-Int32 encodeSequenceHeader(SL_SequenceHeader *sequenceHeader, Int32 *pos,
-		AD_RawMessage *dstRawMessage) {
-	encodeUInt32(sequenceHeader->SequenceNumber, pos,
-			&dstRawMessage->message[*pos]);
-	return UA_NO_ERROR;
-}
+
 /*
  * get the asymmetric algorithm security header
  */

+ 1 - 1
src/opcua_types.h

@@ -808,7 +808,7 @@ typedef struct UA_AD_ResponseHeader
 	UA_DiagnosticInfo *serviceDiagnostics;
 	UInt16 noOfStringTable;
 	UA_String* stringTable;
-	UA_ExtensionObject additionalHeader;
+	UA_ExtensionObject *additionalHeader;
 }
 UA_AD_ResponseHeader;
 

+ 7 - 0
tests/Makefile.am

@@ -4,3 +4,10 @@ check_stack_SOURCES = check_stack.c
 
 check_stack_CFLAGS = @CHECK_CFLAGS@
 check_stack_LDADD = $(top_builddir)/src/libopen62541.la @CHECK_LIBS@
+
+#optimization levels depending on debug
+if DEBUG
+        AM_CFLAGS = -O0
+else
+        AM_CFLAGS = -O2
+endif