Esempio n. 1
0
UA_Int32 UA_OPCUATcpHelloMessage_encodeBinary(UA_OPCUATcpHelloMessage const * src, UA_Int32* pos, UA_ByteString* dst) {
	UA_Int32 retval = UA_SUCCESS;
	retval |= UA_UInt32_encodeBinary(&(src->protocolVersion),pos,dst);
	retval |= UA_UInt32_encodeBinary(&(src->receiveBufferSize),pos,dst);
	retval |= UA_UInt32_encodeBinary(&(src->sendBufferSize),pos,dst);
	retval |= UA_UInt32_encodeBinary(&(src->maxMessageSize),pos,dst);
	retval |= UA_UInt32_encodeBinary(&(src->maxChunkCount),pos,dst);
	retval |= UA_String_encodeBinary(&(src->endpointUrl),pos,dst);
	return retval;
}
Esempio n. 2
0
static int sendOpenSecureChannel(UA_Int32 sock) {
	UA_TcpMessageHeader msghdr;
	msghdr.messageTypeAndFinal = UA_MESSAGETYPEANDFINAL_OPNF;

	UA_UInt32 secureChannelId = 0;
	UA_String securityPolicy;
	UA_String_copycstring("http://opcfoundation.org/UA/SecurityPolicy#None", &securityPolicy);

	UA_String senderCert;
	senderCert.data = UA_NULL;
	senderCert.length = -1;

	UA_String receiverCertThumb;
	receiverCertThumb.data = UA_NULL;
	receiverCertThumb.length = -1;

	UA_UInt32 sequenceNumber = 51;

	UA_UInt32 requestId = 1;

	UA_NodeId type;
	type.identifier.numeric = 446; // id of opensecurechannelrequest
	type.identifierType = UA_NODEIDTYPE_NUMERIC;
	type.namespaceIndex = 0;

	UA_OpenSecureChannelRequest opnSecRq;
	UA_OpenSecureChannelRequest_init(&opnSecRq);
	opnSecRq.requestHeader.timestamp = UA_DateTime_now();
	UA_ByteString_newMembers(&opnSecRq.clientNonce, 1);
	opnSecRq.clientNonce.data[0] = 0;
	opnSecRq.clientProtocolVersion = 0;
	opnSecRq.requestedLifetime = 30000;
	opnSecRq.securityMode = UA_MESSAGESECURITYMODE_NONE;
	opnSecRq.requestType = UA_SECURITYTOKENREQUESTTYPE_ISSUE;
	opnSecRq.requestHeader.authenticationToken.identifier.numeric = 10;
	opnSecRq.requestHeader.authenticationToken.identifierType = UA_NODEIDTYPE_NUMERIC;
	opnSecRq.requestHeader.authenticationToken.namespaceIndex = 10;

	msghdr.messageSize = 135; // todo: compute the message size from the actual content

	UA_ByteString message;
	UA_ByteString_newMembers(&message, 1000);
	size_t offset = 0;
	UA_TcpMessageHeader_encodeBinary(&msghdr, &message, &offset);
	UA_UInt32_encodeBinary(&secureChannelId, &message, &offset);
	UA_String_encodeBinary(&securityPolicy, &message, &offset);
	UA_String_encodeBinary(&senderCert, &message, &offset);
	UA_String_encodeBinary(&receiverCertThumb, &message, &offset);
	UA_UInt32_encodeBinary(&sequenceNumber, &message, &offset);
	UA_UInt32_encodeBinary(&requestId, &message, &offset);
	UA_NodeId_encodeBinary(&type, &message, &offset);
	UA_OpenSecureChannelRequest_encodeBinary(&opnSecRq, &message, &offset);

    UA_OpenSecureChannelRequest_deleteMembers(&opnSecRq);
	UA_String_deleteMembers(&securityPolicy);

	UA_Int32 sendret = send(sock, message.data, offset, 0);
	UA_ByteString_deleteMembers(&message);
	if (sendret < 0) {
		printf("send opensecurechannel failed");
		return 1;
	}
	return 0;
}
Esempio n. 3
0
UA_Int32 UA_SecureConversationMessageAbortBody_encodeBinary(UA_SecureConversationMessageAbortBody const * src, UA_Int32* pos, UA_ByteString* dst) {
	UA_Int32 retval = UA_SUCCESS;
	retval |= UA_UInt32_encodeBinary(&(src->error),pos,dst);
	retval |= UA_String_encodeBinary(&(src->reason),pos,dst);
	return retval;
}