error no private key certificate

Questions regarding the use of the .NET SDK 2.0 for Server or Client development or integration into customer products ...

Moderator: uasdknet

Post Reply
DANILOMARIO
Jr. Member
Jr. Member
Posts: 3
Joined: 05 Jul 2021, 17:00

error no private key certificate

Post by DANILOMARIO »

Hi
i try to connect to my opc-UA but it have always the same message :

ERROR NO PRIVATE KEY CERTIFICATE

Below the code
thanks

If m_application Is Nothing Then
m_application = New ApplicationInstance()

End If

m_application.ApplicationName = My.Application.ApplicationContext.MainForm.Name

AddHandler m_application.UntrustedCertificate, AddressOf Application_UntrustedCertificate


If m_session Is Nothing Then
m_session = New Session(m_application)
End If
m_session.UserIdentity = New UserIdentity
m_session.UseDnsNameAndPortFromDiscoveryUrl = True

m_session.UserIdentity.IdentityType = UserIdentityType.UserName
m_session.UserIdentity.UserName = "JDF"
m_session.UserIdentity.Password = "Nilpeter"

AddHandler m_session.ConnectionStatusUpdate, AddressOf OnConnectionStatusUpdate
If (m_session.ConnectionStatus <> ServerConnectionStatus.Disconnected) Then

m_session.Disconnect()
End If
m_session.AllowInsecureCredentials = False
CampoOPC.Text = Uri.EscapeUriString(CampoOPC.Text)
Dim Discovery = New Discovery(m_application)
Dim EndpointSecure As EndpointDescription = Nothing

EndpointSecure = Discovery.GetMostSecureEndpoint("opc.tcp://212.124.185.17:4840")
Dim certificateSecure As ICertificate = SecurityUtils.LoadCertificate(EndpointSecure.ServerCertificate)
If certificateSecure Is Nothing Then
MessageDialog.Show(Me, "No server has been selected.")
Exit Sub

End If
settingsSecure.Application = m_application
settingsSecure.UntrustedCertificate = certificateSecure
settingsSecure.Application.ApplicationCertificate = certificateSecure
'settingsSecure.Application.AutoCreateCertificate = True

Dim result As IAsyncResult

Try
m_session.BeginConnect(CampoOPC.Text, SecuritySelection.BestAvailable, Nothing, RetryInitialConnect.No, m_session.DefaultRequestSettings, AddressOf OnConnectCompleted, m_session)
Catch ex As Exception

End Try

Public Sub Application_UntrustedCertificate(ByVal sender As Object, ByVal e As UntrustedCertificateEventArgs)

e.Accept = True


End Sub
Public Sub OnConnectCompleted(ByVal result As IAsyncResult)




Dim session1 As Session = DirectCast(result.AsyncState, Session)

Try
session1.EndConnect(result)
Catch ex As Exception
MsgBox("errore " + ex.Message)
End Try



End Sub
Public Sub OnConnectionStatusUpdate(sender As Session, e As ServerConnectionStatusUpdateEventArgs)



End Sub

Post Reply