I want to receive a TCP connection over TLS. I want to validate client certificate and use it to authenticate the client to my application.
Go has the standard crypto/tls
package. It can validate client/server certificates. But I can't find way to get details of the remote (client) certificate, like the common name.
相关问题
- Mechanize getting “Errno::ECONNRESET: Connection r
- Golang mongodb aggregation
- Tomcat and SSL Client certificate
- How to flatten out a nested json structure in go
- how to install private repo using glide golang
相关文章
- ssl配置问题
- Can I run a single test in a suite?
- Intermittent “sslv3 alert handshake failure” under
- How to check if a request was cancelled
- Is it possible to implement an interface with unex
- How to access value of first index of array in Go
- Making a two way SSL authentication between apache
- decrypt TLS 1.2 AES-GCM packet
Have to call crypto/tls/Conn.Handshake. Then you can read peer certificate: tlsconn.ConnectionState().PeerCertificates[0].Subject.CommonName
There is an easier way to do that:
When working with crypto/tls you can query any Conn object for ConnectionState:
The ConnectionState struct contains information about the client certificate:
The x509.Certificate should be pretty straightforward to work with.
Before the server requests for client authentication, you have to configure the connection with the server certificate, client CA (otherwise you will have to verify the trust chain manually, you really don't want that), and tls.RequireAndVerifyClientCert. For example: