Skip to content

Commit d0d3437

Browse files
authored
remove tls cfg (#105)
1 parent b5d3b3a commit d0d3437

10 files changed

Lines changed: 35 additions & 419 deletions

File tree

Dockerfile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,5 @@ WORKDIR /app
3535
COPY --from=builder /app/bin/* /app/
3636

3737
ENV PATH="/app:${PATH}"
38-
ENV EMULATOR_DATADIR=/app/data
39-
40-
VOLUME /app/data
4138

4239
ENTRYPOINT [ "emulator" ]

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,7 @@ The service can be configured using environment variables:
183183
|----------|-------------|---------|
184184
| `EMULATOR_SECRET_KEY` | Private key for signing (hex encoded) | Required |
185185
| `EMULATOR_DEPRECATED_KEYS` | Comma-separated deprecated private keys (hex encoded) still accepted for signing. Empty means none. CSV is strict: leading commas, trailing commas, empty entries, whitespace, duplicates, and the current key are rejected. | Empty |
186-
| `EMULATOR_DATADIR` | Data directory path | OS-specific app data dir |
187186
| `EMULATOR_PORT` | Server port (gRPC + HTTP REST gateway) | 7073 |
188-
| `EMULATOR_NO_TLS` | Disable TLS encryption | false |
189-
| `EMULATOR_TLS_EXTRA_IPS` | Additional IPs for TLS cert | [] |
190-
| `EMULATOR_TLS_EXTRA_DOMAINS` | Additional domains for TLS cert | [] |
191187
| `EMULATOR_LOG_LEVEL` | Log level (0-6) | 4 (Debug) |
192188
| `EMULATOR_ARKD_URL` | URL of the `arkd` instance used for attempted finalization in [`SubmitTx`](#submittx) | Required |
193189
| `EMULATOR_COMPUTE_LIMITS` | Comma-separated `OPCODE=limit` overrides for per-input opcode execution caps, for example `OP_ECPAIRING=8,OP_MODEXP=128`. Overrides are applied on top of defaults; use an empty value such as `OP_ECADD=` to remove a default cap. | Default compute limits |

cmd/emulator.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,8 @@ func main() {
2121
}
2222

2323
log.WithFields(log.Fields{
24-
"version": Version,
25-
"port": cfg.Port,
26-
"no_tls": cfg.NoTLS,
27-
"tls_extra_ips": cfg.TLSExtraIPs,
28-
"tls_extra_domains": cfg.TLSExtraDomains,
29-
"datadir": cfg.Datadir,
24+
"version": Version,
25+
"port": cfg.Port,
3026
}).Info("config loaded")
3127

3228
svc, err := grpcservice.NewService(Version, cfg)

docker-compose.regtest.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@ services:
1111
# public key has odd y
1212
- EMULATOR_SECRET_KEY=5646b2e23bbb82491fb4ef262079ff17594d5e873fc6bcea5f1453edbe1029b1
1313
- EMULATOR_DEPRECATED_KEYS=0202020202020202020202020202020202020202020202020202020202020202,0303030303030303030303030303030303030303030303030303030303030303
14-
- EMULATOR_NO_TLS=true
1514
- EMULATOR_ARKD_URL=arkd:7070
16-
volumes:
17-
- type: tmpfs
18-
target: /app/data
1915
depends_on:
2016
- arkd
2117
pgnbxplorer:

envs/emulator.dev.env

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
EMULATOR_SECRET_KEY=f40f6e7a5cf262f4093d4605b8f40cbaf9da9e59bf32f24bb27a4ffc74f71eab
2-
EMULATOR_NO_TLS=true
1+
EMULATOR_SECRET_KEY=f40f6e7a5cf262f4093d4605b8f40cbaf9da9e59bf32f24bb27a4ffc74f71eab

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ require (
3434
github.com/stretchr/testify v1.11.1
3535
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.63.0
3636
go.opentelemetry.io/otel v1.41.0
37-
golang.org/x/net v0.55.0
3837
google.golang.org/grpc v1.79.3
3938
)
4039

@@ -152,6 +151,7 @@ require (
152151
golang.org/x/crypto v0.52.0 // indirect
153152
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 // indirect
154153
golang.org/x/mod v0.35.0 // indirect
154+
golang.org/x/net v0.55.0 // indirect
155155
golang.org/x/sync v0.20.0 // indirect
156156
golang.org/x/sys v0.45.0 // indirect
157157
golang.org/x/term v0.43.0 // indirect

internal/config/config.go

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"strconv"
88
"strings"
99

10-
arklib "github.com/arkade-os/arkd/pkg/ark-lib"
1110
"github.com/arkade-os/emulator/internal/application"
1211
"github.com/arkade-os/emulator/pkg/arkade"
1312
"github.com/btcsuite/btcd/btcec/v2"
@@ -16,48 +15,32 @@ import (
1615
)
1716

1817
const (
19-
SecretKey = "SECRET_KEY"
20-
DeprecatedKeys = "DEPRECATED_KEYS"
21-
Datadir = "DATADIR"
22-
Port = "PORT"
23-
NoTLS = "NO_TLS"
24-
TLSExtraIPs = "TLS_EXTRA_IPS"
25-
TLSExtraDomains = "TLS_EXTRA_DOMAINS"
26-
LogLevel = "LOG_LEVEL"
27-
ArkdURL = "ARKD_URL"
28-
ComputeLimits = "COMPUTE_LIMITS"
18+
SecretKey = "SECRET_KEY"
19+
DeprecatedKeys = "DEPRECATED_KEYS"
20+
Port = "PORT"
21+
LogLevel = "LOG_LEVEL"
22+
ArkdURL = "ARKD_URL"
23+
ComputeLimits = "COMPUTE_LIMITS"
2924
)
3025

3126
var (
32-
defaultDatadir = arklib.AppDataDir("emulator", false)
33-
defaultPort = uint32(7073)
34-
defaultNoTLS = false
35-
defaultTLSExtraIPs = []string{}
36-
defaultTLSExtraDomains = []string{}
37-
defaultLogLevel = log.DebugLevel
27+
defaultPort = uint32(7073)
28+
defaultLogLevel = log.DebugLevel
3829
)
3930

4031
type Config struct {
41-
CurrentKey *btcec.PrivateKey
42-
DeprecatedKeys []*btcec.PrivateKey
43-
Datadir string
44-
Port uint32
45-
NoTLS bool
46-
TLSExtraIPs []string
47-
TLSExtraDomains []string
48-
ArkdURL string
49-
ComputeLimits arkade.ComputeLimits
32+
CurrentKey *btcec.PrivateKey
33+
DeprecatedKeys []*btcec.PrivateKey
34+
Port uint32
35+
ArkdURL string
36+
ComputeLimits arkade.ComputeLimits
5037
}
5138

5239
func LoadConfig() (*Config, error) {
5340
viper.SetEnvPrefix("EMULATOR")
5441
viper.AutomaticEnv()
5542

56-
viper.SetDefault(Datadir, defaultDatadir)
5743
viper.SetDefault(Port, defaultPort)
58-
viper.SetDefault(NoTLS, defaultNoTLS)
59-
viper.SetDefault(TLSExtraIPs, defaultTLSExtraIPs)
60-
viper.SetDefault(TLSExtraDomains, defaultTLSExtraDomains)
6144
viper.SetDefault(LogLevel, defaultLogLevel)
6245

6346
currentKey, err := parsePrivateKey(viper.GetString(SecretKey), "secret key")
@@ -94,15 +77,11 @@ func LoadConfig() (*Config, error) {
9477
}
9578

9679
cfg := &Config{
97-
CurrentKey: currentKey,
98-
DeprecatedKeys: deprecatedKeys,
99-
Datadir: viper.GetString(Datadir),
100-
Port: viper.GetUint32(Port),
101-
NoTLS: viper.GetBool(NoTLS),
102-
TLSExtraIPs: viper.GetStringSlice(TLSExtraIPs),
103-
TLSExtraDomains: viper.GetStringSlice(TLSExtraDomains),
104-
ArkdURL: viper.GetString(ArkdURL),
105-
ComputeLimits: computeLimits,
80+
CurrentKey: currentKey,
81+
DeprecatedKeys: deprecatedKeys,
82+
Port: viper.GetUint32(Port),
83+
ArkdURL: viper.GetString(ArkdURL),
84+
ComputeLimits: computeLimits,
10685
}
10786
if cfg.ArkdURL == "" {
10887
return nil, fmt.Errorf("missing arkd url")

internal/interface/grpc/config.go

Lines changed: 1 addition & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
11
package grpcservice
22

33
import (
4-
"crypto/rand"
5-
"crypto/tls"
64
"fmt"
75
"net"
8-
"os"
9-
"path/filepath"
10-
11-
"golang.org/x/net/http2"
126
)
137

148
type Config struct {
15-
Datadir string
16-
Port uint32
17-
NoTLS bool
18-
TLSExtraIPs []string
19-
TLSExtraDomains []string
9+
Port uint32
2010
}
2111

2212
func (c Config) Validate() error {
@@ -27,95 +17,13 @@ func (c Config) Validate() error {
2717
// nolint:all
2818
defer lis.Close()
2919

30-
if !c.NoTLS {
31-
tlsDir := c.tlsDatadir()
32-
tlsKeyExists := pathExists(filepath.Join(tlsDir, tlsKeyFile))
33-
tlsCertExists := pathExists(filepath.Join(tlsDir, tlsCertFile))
34-
if !tlsKeyExists && tlsCertExists {
35-
return fmt.Errorf(
36-
"found %s file but %s is missing. Please delete %s to make the "+
37-
"daemon recreating both files in path %s",
38-
tlsCertFile, tlsKeyFile, tlsCertFile, tlsDir,
39-
)
40-
}
41-
42-
if len(c.TLSExtraIPs) > 0 {
43-
for _, ip := range c.TLSExtraIPs {
44-
if net.ParseIP(ip) == nil {
45-
return fmt.Errorf("invalid operator extra ip %s", ip)
46-
}
47-
}
48-
}
49-
}
50-
5120
return nil
5221
}
5322

54-
func (c Config) insecure() bool {
55-
return c.NoTLS
56-
}
57-
5823
func (c Config) address() string {
5924
return fmt.Sprintf(":%d", c.Port)
6025
}
6126

6227
func (c Config) gatewayAddress() string {
6328
return fmt.Sprintf("127.0.0.1:%d", c.Port)
6429
}
65-
66-
func (c Config) tlsDatadir() string {
67-
return filepath.Join(c.Datadir, tlsFolder)
68-
}
69-
70-
func (c Config) tlsKey() string {
71-
if c.NoTLS {
72-
return ""
73-
}
74-
return filepath.Join(c.tlsDatadir(), tlsKeyFile)
75-
}
76-
77-
func (c Config) tlsCert() string {
78-
if c.NoTLS {
79-
return ""
80-
}
81-
return filepath.Join(c.tlsDatadir(), tlsCertFile)
82-
}
83-
84-
func (c Config) tlsConfig() (*tls.Config, error) {
85-
if c.NoTLS {
86-
return nil, nil
87-
}
88-
89-
if c.tlsKey() == "" || c.tlsCert() == "" {
90-
return nil, fmt.Errorf("tls_key and tls_cert both needs to be provided")
91-
}
92-
93-
certificate, err := tls.LoadX509KeyPair(c.tlsCert(), c.tlsKey())
94-
if err != nil {
95-
return nil, err
96-
}
97-
98-
config := &tls.Config{
99-
MinVersion: tls.VersionTLS12,
100-
NextProtos: []string{
101-
"http/1.1", http2.NextProtoTLS, "h2-14",
102-
}, // h2-14 is just for compatibility. will be eventually removed.
103-
Certificates: []tls.Certificate{certificate},
104-
CipherSuites: []uint16{
105-
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
106-
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
107-
},
108-
}
109-
config.Rand = rand.Reader
110-
111-
return config, nil
112-
}
113-
114-
func pathExists(path string) bool {
115-
if _, err := os.Stat(path); err != nil {
116-
if os.IsNotExist(err) {
117-
return false
118-
}
119-
}
120-
return true
121-
}

0 commit comments

Comments
 (0)