Skip to content

Commit

Permalink
aeon: load system CAs by default
Browse files Browse the repository at this point in the history
System certificates must be used unless the user specifies a custom
one.

Closes #1049
  • Loading branch information
oleg-jukovec committed Jan 29, 2025
1 parent f13b13e commit 8eca1dd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Fixed

- `tt aeon`: did not use system CAs by default.

## [2.7.0] - 2025-01-22

The release introduces an experimental support of console for AeonDB and
Expand Down
33 changes: 20 additions & 13 deletions cli/aeon/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,35 @@ func getCertificate(args cmd.Ssl) (tls.Certificate, error) {
}

func getTlsConfig(args cmd.Ssl) (*tls.Config, error) {
var pool *x509.CertPool

if args.CaFile == "" {
return &tls.Config{
ClientAuth: tls.NoClientCert,
}, nil
}
p, err := x509.SystemCertPool()
if err != nil {
return nil, fmt.Errorf("failed to load system cert pool: %w", err)
}

ca, err := os.ReadFile(args.CaFile)
if err != nil {
return nil, fmt.Errorf("failed to read CA file: %w", err)
}
certPool := x509.NewCertPool()
if !certPool.AppendCertsFromPEM(ca) {
return nil, errors.New("failed to append CA data")
pool = p
} else {
ca, err := os.ReadFile(args.CaFile)
if err != nil {
return nil, fmt.Errorf("failed to read CA file: %w", err)
}

pool = x509.NewCertPool()
if !pool.AppendCertsFromPEM(ca) {
return nil, errors.New("failed to append CA data")
}
}

cert, err := getCertificate(args)
if err != nil {
return nil, fmt.Errorf("failed get certificate: %w", err)
}

return &tls.Config{
Certificates: []tls.Certificate{cert},
ClientAuth: tls.RequireAndVerifyClientCert,
RootCAs: certPool,
RootCAs: pool,
}, nil
}

Expand Down

0 comments on commit 8eca1dd

Please sign in to comment.