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

added WithTLS and WithSecurityBuilder #20

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

critterjohnson
Copy link

Josh - is this what you were looking for? I added WithTLS and WithSecurityBuilder, but I had to change a couple of things.

@@ -45,8 +46,14 @@ func (b *ClientBuilder) WithPort(port int) *ClientBuilder {
return b
}

// WithSecurity sets the TLS configuration of the client.
func (b *ClientBuilder) WithSecurity(security SecurityConfig) *ClientBuilder {
Copy link
Contributor

Choose a reason for hiding this comment

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

So removing this is a breaking change and we should avoid it. The goal was to make this a patch only so you'd need to keep this method and potentially mark it as deprecated.

@@ -18,7 +18,7 @@ import "crypto/tls"

// SecurityBuilder provides an builder for client tls.Config instances.
type SecurityBuilder struct {
config SecurityConfig
Config SecurityConfig
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are you opening this up to public access?

@@ -34,14 +34,24 @@ type ClientConfig struct {

// Security defines the TLS configuration used by the client.
Security SecurityConfig `json:"security" mapstructure:"security" yaml:"security"`

// config is the tls config passed by ClientBuilder.WithTLS.
config *tls.Config
Copy link
Contributor

Choose a reason for hiding this comment

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

Another way to do this a bit cleaner than tracking a few things is to create a SecurityConfig from a tls.Config. It's not the easiest but it might make the behavior easier to understand when using this.

Copy link
Author

Choose a reason for hiding this comment

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

Would that be cleaner? It's definitely a bit messy to track the tls.Config, but in order to create a SecurityConfig wouldn't it involve essentially doing the inverse of the SecurityConfig.Build() method, which would would involve re-encoding the certs, only to be re-built and unencoded later? Unless I'm completely misunderstanding this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, you'd add a method that encodes it to base64 a la https://github.com/DecipherNow/acert/blob/master/stores/filesystem/identity_store.go#L128. It's a bit of indirection but will make maintenance easier in the long run.

Copy link
Author

Choose a reason for hiding this comment

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

Makes sense - I'll get started on that.

documented precedence order

quick fixes
@critterjohnson critterjohnson force-pushed the client_builder_changes branch from 2424156 to 5ee043b Compare January 4, 2020 03:47
Copy link
Author

@critterjohnson critterjohnson left a comment

Choose a reason for hiding this comment

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

Ran into a couple more things I don't quite understand. By the way - sorry this is taking so long, it's hard to find the time to work on it with school sucking up most of my hours.

// ? is the config.PrivateKey what needs to be converted into the SecurityConfig.Key?

// config.RootCAs is a x509.CertPool, needs to become SecurityConfig.Authorities
// ! x509.CertPool has no method to export the certs
Copy link
Author

Choose a reason for hiding this comment

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

How would I convert config.RootCAs into a url if there's no exported fields or methods that allow access to the certs?

// parse each cert into an x509.Certificate so encoding can handle them
x509Certs := make([]*x509.Certificate, len(config.Certificates[0].Certificate))
var err error
for index, certificate := range config.Certificates[0].Certificate {
Copy link
Author

Choose a reason for hiding this comment

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

The tls.Config could potentially have multiple cert chains - how should I handle that?

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.

2 participants