Skip to content

Commit

Permalink
Merge pull request #158 from Ethernal-Tech/feat/tls
Browse files Browse the repository at this point in the history
TLS certificate on CI
  • Loading branch information
oliverbundalo authored Mar 15, 2024
2 parents ccea3a8 + c7995d8 commit efdee00
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/e2e-polybft-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ jobs:
with:
go-version: 1.20.x
check-latest: true
- name: Generate OpenSSL certificate
run: openssl req -x509 -out localhost.crt -keyout localhost.key -newkey rsa:2048 -nodes -sha256 -subj '/CN=localhost' -extensions EXT -config <(printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")
- name: Copy certificate key
run: sudo cp localhost.key /etc/ssl/private/localhost.key
- name: Copy certificate itself
run: sudo cp localhost.crt /usr/local/share/ca-certificates/localhost.crt
- name: Add certificate to trusted list
run: sudo update-ca-certificates
- name: Update certificate key folder permissions
run: sudo chmod -R 755 /etc/ssl/private
- name: Update certificate key file permissions
run: sudo chmod 644 /etc/ssl/private/localhost.key
- name: Check certificate key permissions
run: ls -l /etc/ssl/private/localhost.key
- name: Run tests
run: make test-e2e-polybft
- name: Run tests failed
Expand Down
2 changes: 1 addition & 1 deletion e2e-polybft/e2e/jsonrpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestE2E_JsonRPC(t *testing.T) {

cluster := framework.NewTestCluster(t, 4,
framework.WithPremine(types.Address(acct.Address())),
// framework.WithHTTPS("/etc/ssl/certs/ssl-cert-snakeoil.pem", "/etc/ssl/private/ssl-cert-snakeoil.key"),
framework.WithHTTPS("/etc/ssl/certs/localhost.pem", "/etc/ssl/private/localhost.key"),
)
defer cluster.Stop()

Expand Down
4 changes: 1 addition & 3 deletions e2e-polybft/framework/test-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ func (t *TestServer) GrpcAddr() string {

func (t *TestServer) JSONRPCAddr() string {
if t.config.TLSCertFile != "" && t.config.TLSKeyFile != "" {
host, _ := os.Hostname()

return fmt.Sprintf("https://%s:%d", host, t.config.JSONRPCPort)
return fmt.Sprintf("https://localhost:%d", t.config.JSONRPCPort)
} else {
return fmt.Sprintf("http://%s:%d", hostIP, t.config.JSONRPCPort)
}
Expand Down
4 changes: 2 additions & 2 deletions jsonrpc/jsonrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ func (j *JSONRPC) setupHTTP() error {
}

if j.config.TLSCertFile != "" && j.config.TLSKeyFile != "" {
j.logger.Info("https cert file", j.config.TLSCertFile)
j.logger.Info("https key file", j.config.TLSKeyFile)
j.logger.Info("TLS", "cert file", j.config.TLSCertFile)
j.logger.Info("TLS", "key file", j.config.TLSKeyFile)

go func() {
if err := srv.ServeTLS(lis, j.config.TLSCertFile, j.config.TLSKeyFile); err != nil {
Expand Down

0 comments on commit efdee00

Please sign in to comment.