Skip to content

Conversation

@metachris
Copy link
Collaborator

@metachris metachris commented Apr 24, 2025

This pull request introduces a new utility function, GetOrGenerateTLS, in the tls/tls_generate.go file. The function simplifies handling TLS certificates by attempting to load them from specified paths or generating and saving new ones if they do not exist.

TLS Certificate Management:

  • Added the GetOrGenerateTLS function to load TLS certificates and keys from specified paths, or generate and save new self-signed certificates and keys if the files are missing. This includes error handling for file operations and certificate generation. (tls/tls_generate.go, tls/tls_generate.goR14-R54)

@metachris metachris requested review from Copilot and dvush April 24, 2025 10:52
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a new utility function, GetOrGenerateTLS, to manage TLS certificate and key retrieval by either loading existing files or generating and saving new self-signed certificates and keys.

  • New function GetOrGenerateTLS added to check for existing certificate files and generate new ones if missing.
  • Implements file operations for reading and writing TLS certificates and keys.
Comments suppressed due to low confidence (1)

tls/tls_generate.go:26

  • [nitpick] Consider avoiding the shadowing of the function's named return variables by using '=' instead of ':=' when calling GenerateTLS. This helps improve code clarity.
cert, key, err := GenerateTLS(validFor, hosts)

@metachris metachris merged commit 90486a8 into main Apr 25, 2025
2 checks passed
@metachris metachris deleted the GetOrGenerateTLS branch April 25, 2025 08:27
metachris added a commit to flashbots/buildernet-orderflow-proxy that referenced this pull request Apr 28, 2025
This pull request introduces support for specifying file paths for
storing generated TLS certificates and keys in the `receiver-proxy`
component. It also updates the test suite to accommodate these changes.
Below are the most important changes grouped by theme:

### TLS Certificate Management:
* Added new flags `cert-path` and `cert-key-path` to specify file paths
for storing TLS certificates and keys in `cmd/receiver-proxy/main.go`.
These flags are validated to ensure they are set.
[[1]](diffhunk://#diff-8dc9f20362894c1681a9404a0afc3a3c4ce35e72655d6bbc9f2a885f48d5e81dR26-R28)
[[2]](diffhunk://#diff-8dc9f20362894c1681a9404a0afc3a3c4ce35e72655d6bbc9f2a885f48d5e81dR117-R126)
[[3]](diffhunk://#diff-8dc9f20362894c1681a9404a0afc3a3c4ce35e72655d6bbc9f2a885f48d5e81dL219-R232)
[[4]](diffhunk://#diff-8dc9f20362894c1681a9404a0afc3a3c4ce35e72655d6bbc9f2a885f48d5e81dR242-R256)
* Updated `ReceiverProxyConfig` in `proxy/receiver_proxy.go` to include
`CertPath` and `CertKeyPath` fields.
* Modified the `NewReceiverProxy` function to use
`utils_tls.GetOrGenerateTLS`, which either retrieves existing
certificates from the specified paths or generates new ones.

### Dependency Update:
* Updated the `github.com/flashbots/go-utils` dependency in `go.mod` to
a newer version.

### Test Suite Updates:
* Updated test functions in `proxy/receiver_proxy_test.go` to pass
`certPath` and `certKeyPath` arguments, ensuring the new certificate
management logic is tested.
[[1]](diffhunk://#diff-7f9b65fb33b7a91e2caffaa780307669209ea8085fccf4262e2427d01bb25308L77-R81)
[[2]](diffhunk://#diff-7f9b65fb33b7a91e2caffaa780307669209ea8085fccf4262e2427d01bb25308L172-R172)
[[3]](diffhunk://#diff-7f9b65fb33b7a91e2caffaa780307669209ea8085fccf4262e2427d01bb25308L187-R187)
[[4]](diffhunk://#diff-7f9b65fb33b7a91e2caffaa780307669209ea8085fccf4262e2427d01bb25308R197-R199)
[[5]](diffhunk://#diff-7f9b65fb33b7a91e2caffaa780307669209ea8085fccf4262e2427d01bb25308L554-R557)

---

Needs flashbots/go-utils#44 -- should merge that
one first and then tag and update the dep.
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