8000 Support pinned certificates by ghjm · Pull Request #526 · ansible/receptor · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Support pinned certificates #526

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

Merged
merged 4 commits into from
Feb 4, 2022
Merged

Conversation

ghjm
Copy link
Contributor
@ghjm ghjm commented Jan 27, 2022

Receptor currently allows a user to specify a CA, or list of CAs, that must sign a certificate in order to trust it for a connection. However, there are situations where you want to be able to identify a single certificate, or one of a list of certificates, that should be allowed to connect, and it's not sufficient to just say "any certificate signed by such-and-so CA." The solution to this is certificate pinning, where you list specific certificate fingerprints that should be the only ones to be trusted.

Here are example configuration files exercising this feature:

---
- node:
    id: foo

- log-level: debug

- tls-server:
    name: foo_tls
    cert: certs/testcert-foo.crt
    key: certs/testcert-foo.key
    requireclientcert: true
    clientcas: certs/ca.crt
    pinnedclientcert: E6:9B:98:A7:A5:DB:17:D6:E4:2C:DE:76:45:42:A8:79:A3:0A:C5:6D:10:42:7A:6A:C4:54:57:83:F1:0F:E
2:95

- tcp-listener:
    port: 2222
    tls: foo_tls

- control-service:
    service: control
    filename: receptor.sock
---
- node:
    id: bar

- log-level: debug

- tls-client:
    name: bar_tls
    cert: certs/testcert-bar.crt
    key: certs/testcert-bar.key
    rootcas: certs/ca.crt
    pinnedservercert: 91:4B:90:C4:D2:33:94:62:37:2F:0C:83:7A:20:C1:E3:61:FB:0D:EE:9F:6B:E7:1C:2B:76:A2:97:63:21:4
E:F4

- control-service:
    service: control
    filename: bar.sock

- tcp-peer:
    address: localhost:2222
    redial: true
    tls: bar_tls

You can find the fingerprint of a given certificate using openssl x509 -in certs/testcert-foo.crt -noout -fingerprint -sha256. This PR supports sha256 and sha512, but not sha1, because sha1 is now considered insecure. If sha1 support is desired it can easily be added.

@ghjm ghjm requested review from eqrx and fosterseth January 27, 2022 19:59
tlscfg.ClientCAs = clientCAs
}

if len(cfg.PinnedClientCert) > 0 {
tlscfg.VerifyPeerCertificate, err = GetPeerCertificatePinVerifier(cfg.PinnedClientCert)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the quic connections, will this conflict with

tlscfg.VerifyPeerCertificate = s.receptorVerifyFunc(tlscfg, remoteNode, VerifyClient)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, this will indeed conflict.

@ghjm
Copy link
Contributor Author
ghjm commented Jan 28, 2022

@fosterseth I fixed the conflict by having the netceptor verify function wrap the pinning verify function, if it exists. Let me know what you think of this. I guess the other solution would be to add a map to the netceptor struct that stores per-config pin fingerprints and have the netceptor-internal verify function do the pinning checks, but that seems like a lot of work.

@ghjm ghjm force-pushed the pinned_certificates branch from 788614b to be2ee9f Compare January 29, 2022 17:16
@ghjm
Copy link
Contributor Author
ghjm commented Jan 31, 2022

@fosterseth @eqrx @shanemcd Can I get a ✔️ on this?

@fosterseth
Copy link
Member
fosterseth commented Jan 31, 2022

@ghjm any chance we could get you to put a small paragraph / snippet describing this feature in the docs, maybe after this Generate Certs paragraph here

Generating certs

maybe include that openssl command to get the fingerprint too

that would be very valuable for us

@ghjm
Copy link
Contributor Author
ghjm commented Jan 31, 2022

@fosterseth Docs added as requested

@fosterseth
Copy link
Member

pulled this down and tested, works well!

Users of course will need to know that if certs are ever refreshed, then this fingerprint will need to be manually updated in the config files. I think that is okay, we don't really have an automatic way to manage certs within receptor mesh as of right now anyways.

@shanemcd I'm good with this PR if you are

@@ -152,7 +152,6 @@ func (li *Listener) sendResult(conn net.Conn, err error) {
err: err,
}:
case <-li.doneChan:
case <-li.doneChan:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was going on here? Nice find.

Copy link
Member
@shanemcd shanemcd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ghjm, hope you are doing well!

@shanemcd shanemcd merged commit e9fb27f into ansible:devel Feb 4, 2022
shanemcd added a commit that referenced this pull request Feb 17, 2022
This reverts commit e9fb27f, reversing
changes made to ca1bc69.
shanemcd added a commit that referenced this pull request Feb 17, 2022
This reverts commit e9fb27f, reversing
changes made to ca1bc69.
shanemcd added a commit that referenced this pull request Feb 17, 2022
This reverts commit e9fb27f, reversing
changes made to ca1bc69.
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

Successfully merging this pull request may close these issues.

3 participants
0