Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get session info from srv #14

Closed
FranckEtienne opened this issue Mar 3, 2023 · 3 comments
Closed

Get session info from srv #14

FranckEtienne opened this issue Mar 3, 2023 · 3 comments

Comments

@FranckEtienne
Copy link

I launch an OpcUa server with srv.ListenAndServe().

When an OpcUa client connect, I would have an event or retreive information.

I try with :
if srv.ChannelManager().Len() > 0 {
ssc, ret := srv.ChannelManager().Get(0)
if ret {
fmt.Printf("ssc: %d; SecurityMode: TODO\n", ssc.ChannelID())
} else {
fmt.Printf("ssc: NIL !!!\n")
}
}

But, it's always retrun NIL :-(
What is the id in Get method: Get(id uint32)?
How can I retrieve it ?

Thank's a lot for your response and your job on OpcUa in Go :-)

@awcullen
Copy link
Owner

awcullen commented Mar 4, 2023

You pass the ChannelID to ChannelManger.Get(id uint32).
But the ChannelID's start at random number, not zero based.

I didn't plan for external access to channels and sessions or adding an event handler. Good idea!

Did you know about the option to add server diagnostics?

srv, err := server.New(
		...
		server.WithServerDiagnostics(true),
)

This adds nodes to the server namespace, for each open session.

@FranckEtienne
Copy link
Author

Hi Andrew,
What I want to do is to have info about a client which connect to the server.
It is the case with WithServerDiagnostics?
Is it possible to trust a client which connect with X509 certificates?
Thank's for your response and your work.

@awcullen
Copy link
Owner

Hi Franck,
If you add option WithServerDiagnostics, the server will add nodes to the namespace that can be observed using an OPC client such as UAExpert.

image

Also, in the release v1.0.2 you will find client may activate a session with X509Identity. Server must be provided with function that checks X509Identity, returning nil if authenticated.

server.WithAuthenticateX509IdentityFunc(func(userIdentity ua.X509Identity, applicationURI string, endpointURL string) error {
	cert, err := x509.ParseCertificate([]byte(userIdentity.Certificate))
	if err != nil {
		return ua.BadUserAccessDenied
	}
	log.Printf("Login %s from %s\n", cert.Subject, applicationURI)
	return nil
}),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants