Skip to content

Commit d5b6122

Browse files
jmartin82claude
andauthored
Feature/tls password support (#205)
* Implement mock definition validation and enhance error handling * Refactor mappingCreateHandler to validate mock definition directly * Add request path validation to Definition struct * Fix Validate method receiver type Change from pointer receiver to value receiver to fix compilation error in mapping.go where mock.Validate() is called on a value type. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Add support for password-protected TLS private keys Resolves #116 This feature allows mmock to work with encrypted TLS private key files by adding support for password authentication. Features added: - New --tls-key-password command line flag for specifying key password - Environment variable MMOCK_TLS_KEY_PASSWORD for secure password input - Automatic fallback to standard loading for unencrypted keys - Support for multiple private key formats (PKCS#1, PKCS#8, EC) - Comprehensive error handling with descriptive messages Usage examples: mmock --tls-key-password mypassword MMOCK_TLS_KEY_PASSWORD=mypassword mmock 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent a7550b3 commit d5b6122

File tree

8 files changed

+243
-213
lines changed

8 files changed

+243
-213
lines changed

cmd/mmock/main.go

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,18 +119,19 @@ func getVarsProcessor() *vars.ResponseMessageEvaluator {
119119
return vars.NewResponseMessageEvaluator(ff)
120120
}
121121

122-
func startServer(ip string, port, portTLS int, configTLS string, done chan struct{}, router server.RequestResolver, mLog chan match.Transaction, scenario match.ScenearioStorer, varsProcessor vars.Evaluator, spier match.TransactionSpier) {
122+
func startServer(ip string, port, portTLS int, configTLS, tlsKeyPassword string, done chan struct{}, router server.RequestResolver, mLog chan match.Transaction, scenario match.ScenearioStorer, varsProcessor vars.Evaluator, spier match.TransactionSpier) {
123123
dispatcher := server.Dispatcher{
124-
IP: ip,
125-
Port: port,
126-
PortTLS: portTLS,
127-
ConfigTLS: configTLS,
128-
Resolver: router,
129-
Translator: mock.HTTP{},
130-
Evaluator: varsProcessor,
131-
Scenario: scenario,
132-
Spier: spier,
133-
Mlog: mLog,
124+
IP: ip,
125+
Port: port,
126+
PortTLS: portTLS,
127+
ConfigTLS: configTLS,
128+
TLSKeyPassword: tlsKeyPassword,
129+
Resolver: router,
130+
Translator: mock.HTTP{},
131+
Evaluator: varsProcessor,
132+
Scenario: scenario,
133+
Spier: spier,
134+
Mlog: mLog,
134135
}
135136
dispatcher.Start()
136137
done <- struct{}{}
@@ -167,11 +168,19 @@ func main() {
167168
console := flag.Bool("console", true, "Console enabled (true/false)")
168169
cPath := flag.String("config-path", path, "Mocks config folder")
169170
cTLS := flag.String("tls-path", TLS, "TLS config folder (server.crt and server.key should be inside)")
171+
cTLSPassword := flag.String("tls-key-password", "", "Password for encrypted TLS private key files (can also be set via MMOCK_TLS_KEY_PASSWORD env var)")
170172
cStorageCapacity := flag.Int("request-storage-capacity", 100, "Request storage capacity (0 = infinite)")
171173
cResultsPerPage := flag.Int("results-per-page", 25, "Number of results per page")
172174

173175
flag.Parse()
174176

177+
// Check for TLS key password in environment variable if not provided via flag
178+
if *cTLSPassword == "" {
179+
if envPassword := os.Getenv("MMOCK_TLS_KEY_PASSWORD"); envPassword != "" {
180+
*cTLSPassword = envPassword
181+
}
182+
}
183+
175184
//chanels
176185
mLog := make(chan match.Transaction)
177186
done := make(chan struct{})
@@ -197,7 +206,7 @@ func main() {
197206

198207
defer statistics.Stop()
199208

200-
go startServer(*sIP, *sPort, *sPortTLS, *cTLS, done, router, mLog, scenario, varsProcessor, spy)
209+
go startServer(*sIP, *sPort, *sPortTLS, *cTLS, *cTLSPassword, done, router, mLog, scenario, varsProcessor, spy)
201210
log.Infof("HTTP Server running at http://%s:%d\n", *sIP, *sPort)
202211
log.Infof("HTTPS Server running at https://%s:%d\n", *sIP, *sPortTLS)
203212
if *console {

internal/console/ui/assets/AboutView-8P2Yqvj2.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)