Difference between revisions of "How to publish or subscribe to secure OPC UA PubSub messages"

From OPC Labs Knowledge Base
Jump to navigation Jump to search
Line 27: Line 27:
 
; <span>--SksTemplateUser root:secret</span> : Specifies the user name and password used for "logging in" to the SKS.
 
; <span>--SksTemplateUser root:secret</span> : Specifies the user name and password used for "logging in" to the SKS.
 
; --SecurityGroupId TestGroup : Specifies the Id of the security group in the SKS that will be used (the security group in the SKS is configured to use certain security policy, and has other parameters detailing how the security keys are generated).
 
; --SecurityGroupId TestGroup : Specifies the Id of the security group in the SKS that will be used (the security group in the SKS is configured to use certain security policy, and has other parameters detailing how the security keys are generated).
== Use publisher configuration, and subscribe to fixed layout messages ==
+
== Use publisher configuration and/or subscribe to fixed layout messages ==
 
In order to subscribe to fixed layout messages, the subscriber needs to have the metadata about the published dataset. If the publisher is the UADemoPublisher (see above), it gives you a PubSub configuration file that contains (among other information) the metadata needed.  
 
In order to subscribe to fixed layout messages, the subscriber needs to have the metadata about the published dataset. If the publisher is the UADemoPublisher (see above), it gives you a PubSub configuration file that contains (among other information) the metadata needed.  
  

Revision as of 09:37, 3 April 2021

Publish secure messages in UADemoPublisher

Enter the following command at the UADemoPublisher> prompt:

publish --EnabledConnection DynamicLayoutConnection --EnabledDataSetWriter SimpleWriter --SecurityMode SignAndEncrypt --SecurityKeyServiceUri opc.tcp://localhost:48010 --SecurityKeyServiceMessageSecurity SignAndEncrypt --SecurityKeyServiceUserInfo root:secret --SecurityGroupId TestGroup --SaveConfiguration

Explanation of the command line arguments and options used:

--EnabledConnection DynamicLayoutConnection 
Normally, messages are published on multiple connections. For easier troubleshooting, this option selects just one of them.
--EnabledDataSetWriter SimpleWriter 
Normally, multiple dataset writers contribute to a network message. For easier troubleshooting, this option selects just one of them.
--SecurityMode SignAndEncrypt 
Specifies the security mode for the PubSub network messages produced.
--SecurityKeyServiceUri opc.tcp://localhost:48010 
Specifies the URL of the SKS (Security Key Service) endpoint.
--SecurityKeyServiceMessageSecurity SignAndEncrypt 
Specifies the security mode that will be used to connect to the SKS.
--SecurityKeyServiceUserInfo root:secret 
Specifies the user name and password used for "logging in" to the SKS.
--SecurityGroupId TestGroup 
Specifies the Id of the security group in the SKS that will be used (the security group in the SKS is configured to use certain security policy, and has other parameters detailing how the security keys are generated).
--SaveConfiguration 
Tells the application to create a file named UADemoPublisher.uabinary with the configuration the publisher is using (influenced by all the other options provided). The configuration file also contains metadata for the published datasets, and might be used by subscribers in consuming the published messages.

This command publishes message with dynamic layout that are (to certain extent) self-describing, and data can be extracted from them by subscribers without the necessity to have the associated metadata available too.

Publish (secure) messages with fixed layout

In order to publish (secure) messages with fixed layout, replace --EnabledConnection DynamicLayoutConnection in the above command by --EnabledConnection FixedLayoutConnection. In this case, subscribers will need the associated metadata in order to fully parse the published messages. The metadata is contained in the UADemoPublisher.uabinary file generated by the command.

Subscribe to secure messages in OpcCmd utility

Enter the following command at the OpcCmd> prompt:

uaSubscriber subscribeDataSet opc.udp://239.0.0.1:4840 --SecurityKeyServiceUri opc.tcp://localhost:48010 --SksTemplateMessageSecurity SecuritySignAndEncrypt --SksTemplateUser root:secret --SecurityGroupId TestGroup --SecurityMode SecuritySignAndEncrypt 

Explanation of the command line arguments and options used:

opc.udp://239.0.0.1:4840 
The URL of the UDP multicast group on which the subscriber will be listening for PubSub network messages.
--SecurityMode SecuritySignAndEncrypt 
Specifies the security mode for the PubSub network messages received.
--SecurityKeyServiceUri opc.tcp://localhost:48010 
Specifies the URL of the SKS (Security Key Service) endpoint.
--SksTemplateMessageSecurity SecuritySignAndEncrypt 
Specifies the security mode that will be used to connect to the SKS.
--SksTemplateUser root:secret 
Specifies the user name and password used for "logging in" to the SKS.
--SecurityGroupId TestGroup 
Specifies the Id of the security group in the SKS that will be used (the security group in the SKS is configured to use certain security policy, and has other parameters detailing how the security keys are generated).

Use publisher configuration and/or subscribe to fixed layout messages

In order to subscribe to fixed layout messages, the subscriber needs to have the metadata about the published dataset. If the publisher is the UADemoPublisher (see above), it gives you a PubSub configuration file that contains (among other information) the metadata needed.

Enter the following command at the OpcCmd> prompt:

uaSubscriber subscribeDataSet --ResolverPublisherFileResourceUri UADemoPublisher.uabinary --PublishedDataSetName Simple

Compared to the previous command, not only does this command get the metadata from the configuration file, but it also uses the configuration file to determine all other parameters necessary for communication with the SKS, and interpreting the PubSub network messages. All that was really needed was to specify the name of the published dataset you want to subscribe to, using the --PublishedDataSetName command option. Note that this only works if the publisher configuration has only one (currently enabled) way of publishing the dataset with the specified name. Otherwise, you will need to narrow down the search by specifying e.g. the connection name, or writer group name, using more command options of the subscribeDataSet command.

Publishers other than the UADemoPublisher can also be OPC UA servers, and provide the PubSub configuration (and metadata) online, as part of their information model. In such case, use the --ResolverPublisherEndpointUri command option instead of --ResolverPublisherFileResourceUri to specify where to look for the configuration.

Enable security event tracing in command-line tools

Use the following command in the OpcCmd utility or in UADemoPublisher (at the beginning of the program session) to enable tracing of security-related events:

!diagnostics switches setValue 1 --multiple --contains Security --typeName BooleanSwitch

Use the following command to show the trace entries after a command has been run:

traceEntries?

Related reading