convertersystems / opc-ua-samples

Sample HMIs using OPC Unified Architecture (OPC UA) and Visual Studio.
MIT License
107 stars 43 forks source link

Unable to connect to RobotServer using ConsoleApp due to Certificate issue #41

Closed PieterWillemen closed 6 years ago

PieterWillemen commented 6 years ago

Hi,

I just forked the samples repo and simply tried to run the RobotServer and the ConsoleApp. In step 3 of the ConsoleApp, the app gets stuck. After about 15 seconds I get this in the console:

Step 1 - Describe this app.
Step 2 - Create a certificate store.
Step 3 - Create a session with your server.
Error connecting to endpoint. Did the server reject our certificate?
Could not verify security on OpenSecureChannel request.
Press any key to close the program...

Do I have to configure anything related to the certificates? Maybe in the '\opc-ua-samples\RobotServer\Workstation.RobotServer.Config.xml' config file?

I checked that the ConsoleApp created the following files: \AppData\Local\Workstation.ConsoleApp\pki\own\certs\********.crt \AppData\Local\Workstation.ConsoleApp\pki\own\private\********.key

Thanks!

awcullen commented 6 years ago

I'm glad to see the ConsoleApp created it's client certificate. Next, let's check if the RobotServer accepted it. The RobotServer stores certificates it rejects in the directory: C:\ProgramData\OPC Foundation\CertificateStores\RejectedCertificates\certs

If the ConsoleApp certificate is there, you can move it to: C:\ProgramData\OPC Foundation\CertificateStores\UA Applications\certs

awcullen commented 6 years ago

Also, please send the text from the Debug Output window. There may be more info there that can help. Andrew

PieterWillemen commented 6 years ago

The following files are found in the server certificate folders:

\OPC Foundation\CertificateStores\UA Applications\certs\Connectivity Explorer [*******].der
\OPC Foundation\CertificateStores\UA Applications\certs\Workstation.RobotServer [********].der
\OPC Foundation\CertificateStores\MachineDefault\certs\Connectivity Explorer [*******].der
\OPC Foundation\CertificateStores\MachineDefault\certs\Workstation.RobotServer [********].der
\OPC Foundation\CertificateStores\MachineDefault\private\Connectivity Explorer [*******].pfx
\OPC Foundation\CertificateStores\MachineDefault\private\Workstation.RobotServer [********].pfx

Here's the debug output of the RobotServer:

'Workstation.RobotServer.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Workstation.RobotServer.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Projects\Ecophos\WBSServices\DevTestProjects\DCS\MIT_Repos\opc-ua-samples\RobotServer\bin\Debug\Workstation.RobotServer.exe'. Symbols loaded.
'Workstation.RobotServer.exe' (CLR v4.0.30319: Workstation.RobotServer.exe): Loaded 'C:\Projects\Ecophos\WBSServices\DevTestProjects\DCS\MIT_Repos\opc-ua-samples\RobotServer\bin\Debug\Opc.Ua.Configuration.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Workstation.RobotServer.exe' (CLR v4.0.30319: Workstation.RobotServer.exe): Loaded 'C:\Projects\Ecophos\WBSServices\DevTestProjects\DCS\MIT_Repos\opc-ua-samples\RobotServer\bin\Debug\Opc.Ua.Core.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Workstation.RobotServer.exe' (CLR v4.0.30319: Workstation.RobotServer.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Workstation.RobotServer.exe' (CLR v4.0.30319: Workstation.RobotServer.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Workstation.RobotServer.exe' (CLR v4.0.30319: Workstation.RobotServer.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Workstation.RobotServer.exe' (CLR v4.0.30319: Workstation.RobotServer.exe): Loaded 'C:\Projects\Ecophos\WBSServices\DevTestProjects\DCS\MIT_Repos\opc-ua-samples\RobotServer\bin\Debug\Opc.Ua.Server.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Workstation.RobotServer.exe' (CLR v4.0.30319: Workstation.RobotServer.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Serialization\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Workstation.RobotServer.exe' (CLR v4.0.30319: Workstation.RobotServer.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\SMDiagnostics\v4.0_4.0.0.0__b77a5c561934e089\SMDiagnostics.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Workstation.RobotServer.exe' (CLR v4.0.30319: Workstation.RobotServer.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Workstation.RobotServer.exe' (CLR v4.0.30319: Workstation.RobotServer.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Internals\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Internals.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Workstation.RobotServer.exe' (CLR v4.0.30319: Workstation.RobotServer.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Workstation.RobotServer.exe' (CLR v4.0.30319: Workstation.RobotServer.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Workstation.RobotServer.exe' (CLR v4.0.30319: Workstation.RobotServer.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel\v4.0_4.0.0.0__b77a5c561934e089\System.ServiceModel.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Workstation.RobotServer.exe' (CLR v4.0.30319: Workstation.RobotServer.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.IdentityModel\v4.0_4.0.0.0__b77a5c561934e089\System.IdentityModel.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
The thread 0x40d8 has exited with code 0 (0x0).
The thread 0x3fa8 has exited with code 0 (0x0).
The thread 0x48f4 has exited with code 0 (0x0).
The thread 0x57fc has exited with code 0 (0x0).
The thread 0x1bb4 has exited with code 0 (0x0).
The thread 0x1054 has exited with code 0 (0x0).
The thread 0x698 has exited with code 0 (0x0).
The thread 0x638c has exited with code 0 (0x0).
The thread 0x5888 has exited with code 0 (0x0).

Here's the debug output of the ConsoleApp:

'Workstation.ConsoleApp.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Workstation.ConsoleApp.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Projects\Ecophos\WBSServices\DevTestProjects\DCS\MIT_Repos\opc-ua-samples\ConsoleApp\bin\Debug\Workstation.ConsoleApp.exe'. Symbols loaded.
'Workstation.ConsoleApp.exe' (CLR v4.0.30319: Workstation.ConsoleApp.exe): Loaded 'C:\Projects\Ecophos\WBSServices\DevTestProjects\DCS\MIT_Repos\opc-ua-samples\ConsoleApp\bin\Debug\Workstation.UaClient.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Workstation.ConsoleApp.exe' (CLR v4.0.30319: Workstation.ConsoleApp.exe): Loaded 'C:\Projects\Ecophos\WBSServices\DevTestProjects\DCS\MIT_Repos\opc-ua-samples\ConsoleApp\bin\Debug\System.Threading.Tasks.Dataflow.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Workstation.ConsoleApp.exe' (CLR v4.0.30319: Workstation.ConsoleApp.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Runtime\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Runtime.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Workstation.ConsoleApp.exe' (CLR v4.0.30319: Workstation.ConsoleApp.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Threading.Tasks\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Threading.Tasks.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Workstation.ConsoleApp.exe' (CLR v4.0.30319: Workstation.ConsoleApp.exe): Loaded 'C:\Projects\Ecophos\WBSServices\DevTestProjects\DCS\MIT_Repos\opc-ua-samples\ConsoleApp\bin\Debug\System.Reactive.Linq.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Workstation.ConsoleApp.exe' (CLR v4.0.30319: Workstation.ConsoleApp.exe): Loaded 'C:\Projects\Ecophos\WBSServices\DevTestProjects\DCS\MIT_Repos\opc-ua-samples\ConsoleApp\bin\Debug\System.Reactive.Core.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Workstation.ConsoleApp.exe' (CLR v4.0.30319: Workstation.ConsoleApp.exe): Loaded 'C:\Projects\Ecophos\WBSServices\DevTestProjects\DCS\MIT_Repos\opc-ua-samples\ConsoleApp\bin\Debug\Microsoft.Extensions.Logging.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Workstation.ConsoleApp.exe' (CLR v4.0.30319: Workstation.ConsoleApp.exe): Loaded 'C:\Projects\Ecophos\WBSServices\DevTestProjects\DCS\MIT_Repos\opc-ua-samples\ConsoleApp\bin\Debug\Microsoft.Extensions.Logging.Abstractions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Workstation.ConsoleApp.exe' (CLR v4.0.30319: Workstation.ConsoleApp.exe): Loaded 'C:\Projects\Ecophos\WBSServices\DevTestProjects\DCS\MIT_Repos\opc-ua-samples\ConsoleApp\bin\Debug\Microsoft.Extensions.Logging.Debug.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Workstation.ConsoleApp.exe' (CLR v4.0.30319: Workstation.ConsoleApp.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Workstation.ConsoleApp.exe' (CLR v4.0.30319: Workstation.ConsoleApp.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Extensions\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Runtime.Extensions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Workstation.ConsoleApp.exe' (CLR v4.0.30319: Workstation.ConsoleApp.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Collections\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Collections.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Workstation.ConsoleApp.exe' (CLR v4.0.30319: Workstation.ConsoleApp.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Threading\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Threading.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Workstation.ConsoleApp.exe' (CLR v4.0.30319: Workstation.ConsoleApp.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Linq\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Linq.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Workstation.ConsoleApp.exe' (CLR v4.0.30319: Workstation.ConsoleApp.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Workstation.ConsoleApp.exe' (CLR v4.0.30319: Workstation.ConsoleApp.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Workstation.ConsoleApp.exe' (CLR v4.0.30319: Workstation.ConsoleApp.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Workstation.ConsoleApp.exe' (CLR v4.0.30319: Workstation.ConsoleApp.exe): Loaded 'C:\Projects\Ecophos\WBSServices\DevTestProjects\DCS\MIT_Repos\opc-ua-samples\ConsoleApp\bin\Debug\BouncyCastle.Crypto.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Workstation.ConsoleApp.exe' (CLR v4.0.30319: Workstation.ConsoleApp.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Workstation.ConsoleApp.exe' (CLR v4.0.30319: Workstation.ConsoleApp.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Reflection\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Reflection.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Workstation.ConsoleApp.exe' (CLR v4.0.30319: Workstation.ConsoleApp.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Diagnostics.Tracing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Diagnostics.Tracing.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Workstation.ConsoleApp.exe' (CLR v4.0.30319: Workstation.ConsoleApp.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Collections.Concurrent\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Collections.Concurrent.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Workstation.ServiceModel.Ua.Channels.UaTcpSessionChannel: Information: Discovering endpoints of 'opc.tcp://localhost:26543'.
Workstation.ServiceModel.Ua.Channels.UaTcpSessionChannel: Trace: Success discovering endpoints of 'opc.tcp://localhost:26543'.
Workstation.ServiceModel.Ua.Channels.UaTcpSessionChannel: Trace: Channel opening.
Workstation.ServiceModel.Ua.Channels.UaTcpSecureChannel: Trace: Found certificate with subject alt name 'urn:LAPTOP01:MyHomework'.
Workstation.ServiceModel.Ua.Channels.UaTcpSessionChannel: Information: Opening session channel with endpoint 'opc.tcp://localhost:26543'.
Workstation.ServiceModel.Ua.Channels.UaTcpSessionChannel: Information: SecurityPolicy: 'http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256'.
Workstation.ServiceModel.Ua.Channels.UaTcpSessionChannel: Information: SecurityMode: 'SignAndEncrypt'.
Workstation.ServiceModel.Ua.Channels.UaTcpSessionChannel: Information: UserIdentity: 'Workstation.ServiceModel.Ua.AnonymousIdentity'.
Workstation.ServiceModel.Ua.Channels.UaTcpSecureChannel: Trace: Sending OpenSecureChannelRequest, Handle: 2
Workstation.ServiceModel.Ua.Channels.UaTcpSecureChannel: Trace: Received OpenSecureChannelResponse, Handle: 2 Result: 0x00000000
Workstation.ServiceModel.Ua.Channels.UaTcpSecureChannel: Trace: Sending CreateSessionRequest, Handle: 3
Workstation.ServiceModel.Ua.Channels.UaTcpSecureChannel: Trace: Installed new security token 1.
Workstation.ServiceModel.Ua.Channels.UaTcpSecureChannel: Trace: Received CreateSessionResponse, Handle: 3 Result: 0x00000000
Workstation.ServiceModel.Ua.Channels.UaTcpSecureChannel: Trace: Sending ActivateSessionRequest, Handle: 4
Workstation.ServiceModel.Ua.Channels.UaTcpSecureChannel: Trace: Received ActivateSessionResponse, Handle: 4 Result: 0x00000000
Workstation.ServiceModel.Ua.Channels.UaTcpSecureChannel: Trace: Sending ReadRequest, Handle: 5
Workstation.ServiceModel.Ua.Channels.UaTcpSecureChannel: Trace: Received ReadResponse, Handle: 5 Result: 0x00000000
Workstation.ServiceModel.Ua.Channels.UaTcpSecureChannel: Trace: Sending CreateSubscriptionRequest, Handle: 6
Workstation.ServiceModel.Ua.Channels.UaTcpSecureChannel: Trace: Received CreateSubscriptionResponse, Handle: 6 Result: 0x00000000
Workstation.ServiceModel.Ua.Channels.UaTcpSessionChannel: Trace: Channel opened.
Workstation.ServiceModel.Ua.Channels.UaTcpSecureChannel: Trace: Sending PublishRequest, Handle: 7
Workstation.ServiceModel.Ua.Channels.UaTcpSecureChannel: Trace: Sending PublishRequest, Handle: 8
Workstation.ServiceModel.Ua.Channels.UaTcpSecureChannel: Trace: Sending PublishRequest, Handle: 9
The thread 0x5e98 has exited with code 0 (0x0).
The thread 0x4790 has exited with code 0 (0x0).
The thread 0x59e0 has exited with code 0 (0x0).
The thread 0x63d0 has exited with code 0 (0x0).
The thread 0x237c has exited with code 0 (0x0).
awcullen commented 6 years ago

The debug output for the ConsoleApp shows the client opening a secure channel, creating a session, reading the namespace table, and creating a subscription (for keep-alive purposes). If the client certificate was not accepted, then there would errors.