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

OPC-UA server can have multiple certificates #636

Open
geoynomous opened this issue Feb 8, 2023 · 4 comments
Open

OPC-UA server can have multiple certificates #636

geoynomous opened this issue Feb 8, 2023 · 4 comments

Comments

@geoynomous
Copy link

geoynomous commented Feb 8, 2023

The OPC-UA might announce multiple certificates - concatenated. Then

x509.ParseCertificate(cert) does not work - it will report a x509: trailing data error.

It is better to use x509.ParseCertificates(certsByteArray) (Plural!) and then to chose one of them. The first?

Honestly I do not understand why some servers provide multiple certs - maybe there should be a way to select one of them? You know it better ...

EDIT: Or is there a way to choose the cert during a config step?

EDIT2: Here is a diff - it's probably not complete, but gives an idea .. sorry it's for v0.3.9


diff -r [email protected]/client.go [email protected]/client.go
9a10
> 	"crypto/x509"
730c741,750
< 		err := c.SecureChannel().VerifySessionSignature(res.ServerCertificate, nonce, res.ServerSignature.Signature)
---
> 		remoteX509Certs, err := x509.ParseCertificates(res.ServerCertificate)
> 		if err != nil {
> 			return err
> 		}
> 		if len(remoteX509Certs) > 0 {
> 			res.ServerCertificate = remoteX509Certs[0].Raw
> 		}
>
> 		err = c.SecureChannel().VerifySessionSignature(res.ServerCertificate, nonce, res.ServerSignature.Signature)
diff -r [email protected]/uasc/secure_channel.go [email protected]/uasc/secure_channel.go
12a13
> 	"fmt"
491c492
< 		remoteCert, err := x509.ParseCertificate(s.cfg.RemoteCertificate)
---
> 		remoteCerts, err := x509.ParseCertificates(s.cfg.RemoteCertificate)
496c498
< 		if remoteKey, ok = remoteCert.PublicKey.(*rsa.PublicKey); !ok {
---
> 		if remoteKey, ok = remoteCerts[0].PublicKey.(*rsa.PublicKey); !ok {
@geoynomous
Copy link
Author

Any comment here?

@geoynomous
Copy link
Author

This is still open

@allenlu1990
Copy link

and why Private Key must be RSA PRIVATE KEY?

@geoynomous
Copy link
Author

@allenlu1990 I understand your question - but this is unrelated to this issue. It might be a requirement by the standard. Here we are dealing with the fact that multiple certificates are announced.

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