forked from drk1wi/Modlishka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
443 lines (329 loc) · 21.4 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
/**
"Modlishka" Reverse Proxy.
Copyright 2018 (C) Piotr Duszyński piotr[at]duszynski.eu. All rights reserved.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
You should have received a copy of the Modlishka License along with this program.
**/
package main
import (
"encoding/base64"
"github.com/drk1wi/Modlishka/config"
"github.com/drk1wi/Modlishka/log"
"github.com/drk1wi/Modlishka/plugin"
"io/ioutil"
"math/rand"
"os"
"reflect"
"strings"
"testing"
"github.com/drk1wi/Modlishka/core"
"golang.org/x/net/publicsuffix"
)
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
func init() {
core.MakeRegexes()
//var f = false
//config.C.Debug = &f
}
func randSeq(n int) string {
b := make([]rune, n)
for i := range b {
b[i] = letters[rand.Intn(len(letters))]
}
return string(b)
}
var TestsTranslatePhishtoURL = []struct {
input string // input
expected string // expected result
}{
{"uc45bnjw1b6gyp4z7ab0.google.dev", "accounts.youtube.com"},
{"www.google.dev", "www.google.com"},
{"www.google.com", "www.google.com"},
}
var TestsTranslateURLtoPhish = []struct {
input string // input
expected string // expected result
}{
{"assets-cdn.github.com", "assets-cdn.phish-github.dev"},
{"accounts.youtube.com", "uc45bnjw1b6gyp4z7ab0.phish-github.dev"},
{"github.com", "phish-github.dev"},
}
func TestEncodeDecode(t *testing.T) {
input := randSeq(20)
encoded, err := core.EncodeSubdomain(input)
if err != nil {
t.Errorf("TestEncodeDecode(%s): error %s ", "encode", err.Error())
}
decoded, err := core.DecodeSubdomain(encoded)
if err != nil {
t.Errorf("TestEncodeDecode(%s): error %s ", "decode", err.Error())
}
if input != decoded {
t.Errorf("TestEncodeDecode(%s): expected %s, actual %s", input, input, decoded)
}
}
func TestRegex(t *testing.T) {
core.RC4_KEY = `7afa263b3d6efb65dfde80875cf3883cdc4da6cef9b64034a5ba895317e98e39`
core.PhishingDomain = "google.dev"
core.TopLevelDomain = "google.com"
core.MakeRegexes()
}
func TestTranslatePhishtoURL(t *testing.T) {
core.RC4_KEY = `7afa263b3d6efb65dfde80875cf3883cdc4da6cef9b64034a5ba895317e98e39`
target := "google.com"
phishing := "google.dev"
core.PhishingDomain = phishing
core.TopLevelDomain = target
core.MakeRegexes()
domain, _ := publicsuffix.EffectiveTLDPlusOne(target)
core.TopLevelDomain = strings.Replace(domain, "https://", "", -1)
core.TopLevelDomain = strings.Replace(core.TopLevelDomain, "http://", "", -1)
core.PhishingDomain = string(phishing)
// core.Logger = core.InitializeLogger(*debugInfo)
for _, tt := range TestsTranslatePhishtoURL {
actual := core.PhishURLToRealURL(tt.input)
if actual != tt.expected {
t.Errorf("TestsTranslatePhishtoURL(%s): expected %s, actual %s", tt.input, tt.expected, actual)
}
}
}
func TestTranslateURLtoPhish(t *testing.T) {
core.RC4_KEY = `7afa263b3d6efb65dfde80875cf3883cdc4da6cef9b64034a5ba895317e98e39`
target := "github.com"
phishing := "phish-github.dev"
core.PhishingDomain = phishing
core.TopLevelDomain = target
core.MakeRegexes()
domain, _ := publicsuffix.EffectiveTLDPlusOne(target)
core.TopLevelDomain = strings.Replace(domain, "https://", "", -1)
core.TopLevelDomain = strings.Replace(core.TopLevelDomain, "http://", "", -1)
core.PhishingDomain = string(phishing)
// core.Logger = core.InitializeLogger(*debugInfo)
for _, tt := range TestsTranslateURLtoPhish {
actual := core.RealURLtoPhish(tt.input)
if actual != tt.expected {
t.Errorf("TestsTranslateURLtoPhish(%s): expected %s, actual %s", tt.input, tt.expected, actual)
}
}
}
func getFieldString(v *config.Options, field string) string {
out := reflect.ValueOf(v).Elem().FieldByName(field)
return out.Elem().String()
}
func getFieldBool(v *config.Options, field string) bool {
out := reflect.ValueOf(v).Elem().FieldByName(field)
return out.Elem().Bool()
}
func TestCmdLineFlags(t *testing.T) {
in := map[string]string{
"PhishingDomain": "https://google.dev",
"ListeningPort": "443",
"ListeningAddress": "0.0.0.0",
"Target": "google.com",
"TargetRes": "test.google.com,test1.google.com",
"TerminateTriggers": "terminate.google.dev,terminate2.google.dev",
"TerminateRedirectUrl": "redirect.google.com",
"TargetRules": "eHh4:eXl5", //xxx:yyy
"TrackingCookie": "id",
"TrackingParam": "id",
"LogFile": "logfile",
"Plugins": "plugin1,plugin2,plugin2",
"TLSCertificate": "-----BEGIN CERTIFICATE-----\nMIIDEDCCAfigAwIBAgIEKfekOzANBgkqhkiG9w0BAQsFADASMRAwDgYDVQQKEwdB\nY21lIENvMB4XDTE4MTIwMjIwMTc1NloXDTI0MDUwNzE5MTc1NlowPTEOMAwGA1UE\nBhMFRWFydGgxFjAUBgNVBAoTDU1vdGhlciBOYXR1cmUxEzARBgNVBAMTCmdvb2ds\nZS5kZXYwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDBzp66XCX6iPGK\n3DSy2ZcvcyDzL263U6CGHqwkFGySr8J3qrNeh4NZcnlYoAnobUlna9OCUPXFqA4/\nHjL6BuBsrLE//8gnrqP5Bga0ZYaTcq00EQuYxEpNuHBPsX0VBev/5qmJGa20Rd2O\nXajNGyK5S2eJhSOEDYY14tIVocPD9DTXsZ8TkVUxXZ8UqEaBDPp23OHL/HAFY/rd\nOybt1e9SZWC2bqsFjeoVM/xHBpuNDfhjivHI5AMNJGYvOxGtiqfOVUFNDc3zE1TC\nnBCpsesrpG4jB/6Q1yWdYogy5/7aUtM69GiXDDD4wG3l5MMxGhVFaspfKSc28IFG\nfJjMxH37AgMBAAGjQzBBMAwGA1UdEwEB/wQCMAAwDAYDVR0OBAUEAwECAzAjBgNV\nHREEHDAaggpnb29nbGUuZGV2ggwqLmdvb2dsZS5kZXYwDQYJKoZIhvcNAQELBQAD\nggEBAKSaZ04Q Pv00PpugEi3FQtQOBz6JK/Exz8BOW6zOeY0NhfGrXjfa9rTqGdx\n0yxU1LQZhcNrdLKgIN3GGY/lYN0GKqBJFqmyy9zRxdob19Lb5HcL8ZY4fvFdrXBK\nI6D8eJhRmVY2Mr v8fc2mDYg7q/kmgrcAtANtx3KC5QLtIWRxWn6iu NO7FDKcsZ\nmJmHRikPR4PrhKyzu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SBZfcdb2dJSIO/PEgWn4CCN9sjSD9OwGLM5hyKxWRzAoGBANfY\nNDbj aPg7hRbDFm4ZV1n nwIGWq4M77/EuOPZcppfVrYl8EfCGcuoG k8Wld2SoS\nz2N4kT2mnowSFE5OW0hRBojhOyUOPR7hLx8VoOF8Ymjl4WFsahELvQuXP 1Apq7Q\nZ0h Gb2NkpRrgTJK8cUQf 8uIQM4SYpgAGw2dqZZAoGBANjdSoeDOJsVFXzWDwv1\nRh4VIDBt2jD3BoAhh 8ZVffwGGnTyK67q6W8qmxbjBkzTx35ed9o9CK9qSRDN2TT\nJUpzUAZ5jKEfIohltjyMQef5iFj7xlpewO8 Wrn1LZQZsWWRi6jcXYmd60tZNj9x\nEKUGtjoKjJQl8X6FgCi3iEofAoGARYgoieY27UvwZi5OdDiqrsRoNLyHM5HTWZvi\nAdyX9fS1pSZQ/K16j4K9vDlua3sIEj2tAWY9o5ahTI4mbHNhhJJVgJLN8sn7do8k\nFudoxDrFmPU0/aVnJcaaR7mZplxFVdtc6kV1FVMd/SIEpKbv64O9MtexWtAvIJx8\nhl lKUECgYEAu9sAdc0pbzmdTeNterIScCXnclpANW1jsfCQvOv3qWqvU0uBreyd\nhVW67M9XzMzn6baZ3jLi0RxmIkxnLwkfLUTpMcmQO 1WY77MkROXDBmDQ87sBIDP\nluG0g5iz09m0QIt8nFUAZlogqgUXoMsBTtNk/jY4jpdTSzoh1kUeZIw=\n-----END PRIVATE KEY-----\n",
}
in_bool := map[string]bool{
"UseTls": true,
"Debug": true,
"DisableSecurity": false,
"LogPostOnly": false,
}
encodedCert := base64.StdEncoding.EncodeToString([]byte(in["TLSCertificate"]))
encodedKey := base64.StdEncoding.EncodeToString([]byte(in["TLSKey"]))
args := " -phishingDomain " in["PhishingDomain"]
" -target " in["Target"]
" -listeningPort " in["ListeningPort"]
" -listeningAddress " in["ListeningAddress"]
" -targetRes " in["TargetRes"]
" -terminateTriggers " in["TerminateTriggers"]
" -terminateUrl " in["TerminateRedirectUrl"]
" -rules " in["TargetRules"]
" -trackingCookie " in["TrackingCookie"]
" -trackingParam " in["TrackingParam"]
" -log " in["LogFile"]
" -cert " encodedCert
" -certKey " encodedKey
" -plugins " in["Plugins"]
if in_bool["Debug"] {
args = " -debug "
}
if in_bool["UseTls"] {
args = " -tls "
}
if in_bool["DisableSecurity"] {
args = " -disableSecurity "
}
if in_bool["LogPostOnly"] {
args = " -LogPostOnly "
}
arg := []string{os.Args[0]}
for _, v := range strings.Fields(args) {
arg = append(arg, v)
}
os.Args = arg
options := config.ParseConfiguration()
conf := Configuration{
options,
}
for k, _ := range in {
if getFieldString(&options, k) != in[k] {
t.Errorf("TestCmdLineFlags ParseConfiguration (%s): expected %s, actual %s", k, in[k], getFieldString(&options, k))
}
}
for k, _ := range in_bool {
if getFieldBool(&options, k) != in_bool[k] {
t.Errorf("TestCmdLineFlags ParseConfiguration (%s): expected %t, actual %t", k, in_bool[k], getFieldBool(&options, k))
}
}
// Set up runtime core config
core.SetCoreRuntimeConfig(conf.Options)
if getFieldString(&options, "PhishingDomain") != core.PhishingDomain {
t.Errorf("TestCmdLineFlags SetCoreRuntimeConfig (%s): expected %s, actual %s", "PhishingDomain", getFieldString(&options, "PhishingDomain"), core.PhishingDomain)
}
if getFieldString(&options, "TrackingCookie") != core.TrackingCookie {
t.Errorf("TestCmdLineFlags SetCoreRuntimeConfig (%s): expected %s, actual %s", "TrackingCookie", getFieldString(&options, "TrackingCookie"), core.TrackingCookie)
}
if getFieldString(&options, "TrackingParam") != core.TrackingParam {
t.Errorf("TestCmdLineFlags SetCoreRuntimeConfig (%s): expected %s, actual %s", "TrackingParam", getFieldString(&options, "TrackingParam"), core.TrackingParam)
}
if "google.com" != core.TopLevelDomain {
t.Errorf("TestCmdLineFlags SetCoreRuntimeConfig (%s): expected %s, actual %s", "TopLevelDomain", "google.com", core.TopLevelDomain)
}
if "yyy" != core.ReplaceStrings["xxx"] {
t.Errorf("TestCmdLineFlags SetCoreRuntimeConfig (%s): expected %s, actual %s", "ReplaceStrings", "xxx", core.ReplaceStrings["xxx"])
}
if strings.Join(core.TargetResources, ",") != getFieldString(&options, "TargetRes") {
t.Errorf("TestCmdLineFlags SetCoreRuntimeConfig (%s): expected %s, actual %s", "TargetResources", getFieldString(&options, "TargetRes"), strings.Join(core.TargetResources, ","))
}
if strings.Join(core.TerminateTriggers, ",") != getFieldString(&options, "TerminateTriggers") {
t.Errorf("TestCmdLineFlags SetCoreRuntimeConfig (%s): expected %s, actual %s", "TerminateTriggers", getFieldString(&options, "TerminateRedirectUrl"), strings.Join(core.TerminateTriggers, ","))
}
// Set up runtime server config
core.SetServerRuntimeConfig(conf.Options)
if in["TLSCertificate"] != *core.ServerRuntimeConfig.TLSCertificate {
t.Errorf("TestCmdLineFlags SetServerRuntimeConfig (%s): expected %s, actual %s", "TLSCertificate", in["TLSCertificate"], *core.ServerRuntimeConfig.TLSCertificate)
}
if in["TLSKey"] != *core.ServerRuntimeConfig.TLSKey {
t.Errorf("TestCmdLineFlags SetServerRuntimeConfig (%s): expected %s, actual %s", "TLSKey", in["TLSKey"], *core.ServerRuntimeConfig.TLSKey)
}
// Set up runtime plugin config
plugin.SetPluginRuntimeConfig(conf.Options)
}
var jsonfile1 = `{
"phishingDomain": "https://google.dev",
"listeningPort": "443",
"listeningAddress": "0.0.0.0",
"target": "google.com",
"targetResources": "test.google.com,test1.google.com",
"targetRules": "eHh4:eXl5",
"terminateTriggers": "terminate.google.dev,terminate2.google.dev",
"terminateUrl": "redirect.google.com",
"trackingCookie": "id",
"trackingParam": "id",
"useTls": true,
"debug": true,
"logPostOnly": false,
"disableSecurity": false,
"log": "logfile",
"plugins": "plugin1,plugin2,plugin2",
"cert": "-----BEGIN CERTIFICATE-----\nMIIDEDCCAfigAwIBAgIEKfekOzANBgkqhkiG9w0BAQsFADASMRAwDgYDVQQKEwdB\nY21lIENvMB4XDTE4MTIwMjIwMTc1NloXDTI0MDUwNzE5MTc1NlowPTEOMAwGA1UE\nBhMFRWFydGgxFj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 8ZVffwGGnTyK67q6W8qmxbjBkzTx35ed9o9CK9qSRDN2TT\nJUpzUAZ5jKEfIohltjyMQef5iFj7xlpewO8 Wrn1LZQZsWWRi6jcXYmd60tZNj9x\nEKUGtjoKjJQl8X6FgCi3iEofAoGARYgoieY27UvwZi5OdDiqrsRoNLyHM5HTWZvi\nAdyX9fS1pSZQ/K16j4K9vDlua3sIEj2tAWY9o5ahTI4mbHNhhJJVgJLN8sn7do8k\nFudoxDrFmPU0/aVnJcaaR7mZplxFVdtc6kV1FVMd/SIEpKbv64O9MtexWtAvIJx8\nhl lKUECgYEAu9sAdc0pbzmdTeNterIScCXnclpANW1jsfCQvOv3qWqvU0uBreyd\nhVW67M9XzMzn6baZ3jLi0RxmIkxnLwkfLUTpMcmQO 1WY77MkROXDBmDQ87sBIDP\nluG0g5iz09m0QIt8nFUAZlogqgUXoMsBTtNk/jY4jpdTSzoh1kUeZIw=\n-----END PRIVATE KEY-----\n",
"certPool": ""
}`
func TestJSONConfig(t *testing.T) {
configFile, err := ioutil.TempFile("", "")
if err != nil {
log.Fatalf(err.Error() " . Terminating.")
}
err = ioutil.WriteFile(configFile.Name(), []byte(jsonfile1), 0644)
if err != nil {
log.Fatalf(err.Error() " . Terminating.")
}
defer os.Remove(configFile.Name())
in := map[string]string{
"PhishingDomain": "https://google.dev",
"ListeningPort": "443",
"ListeningAddress": "0.0.0.0",
"Target": "google.com",
"TargetRes": "test.google.com,test1.google.com",
"TerminateTriggers": "terminate.google.dev,terminate2.google.dev",
"TerminateRedirectUrl": "redirect.google.com",
"TargetRules": "eHh4:eXl5", //xxx:yyy
"TrackingCookie": "id",
"TrackingParam": "id",
"LogFile": "logfile",
"Plugins": "plugin1,plugin2,plugin2",
"TLSCertificate": "-----BEGIN CERTIFICATE-----\nMIIDEDCCAfigAwIBAgIEKfekOzANBgkqhkiG9w0BAQsFADASMRAwDgYDVQQKEwdB\nY21lIENvMB4XDTE4MTIwMjIwMTc1NloXDTI0MDUwNzE5MTc1N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OJsVFXzWDwv1\nRh4VIDBt2jD3BoAhh 8ZVffwGGnTyK67q6W8qmxbjBkzTx35ed9o9CK9qSRDN2TT\nJUpzUAZ5jKEfIohltjyMQef5iFj7xlpewO8 Wrn1LZQZsWWRi6jcXYmd60tZNj9x\nEKUGtjoKjJQl8X6FgCi3iEofAoGARYgoieY27UvwZi5OdDiqrsRoNLyHM5HTWZvi\nAdyX9fS1pSZQ/K16j4K9vDlua3sIEj2tAWY9o5ahTI4mbHNhhJJVgJLN8sn7do8k\nFudoxDrFmPU0/aVnJcaaR7mZplxFVdtc6kV1FVMd/SIEpKbv64O9MtexWtAvIJx8\nhl lKUECgYEAu9sAdc0pbzmdTeNterIScCXnclpANW1jsfCQvOv3qWqvU0uBreyd\nhVW67M9XzMzn6baZ3jLi0RxmIkxnLwkfLUTpMcmQO 1WY77MkROXDBmDQ87sBIDP\nluG0g5iz09m0QIt8nFUAZlogqgUXoMsBTtNk/jY4jpdTSzoh1kUeZIw=\n-----END PRIVATE KEY-----\n",
}
in_bool := map[string]bool{
"UseTls": true,
"Debug": true,
"DisableSecurity": false,
"LogPostOnly": false,
}
args := " -config " configFile.Name()
arg := []string{os.Args[0]}
for _, v := range strings.Fields(args) {
arg = append(arg, v)
}
os.Args = arg
options := config.ParseConfiguration()
conf := Configuration{
options,
}
for k, _ := range in {
if getFieldString(&options, k) != in[k] {
t.Errorf("TestCmdLineFlags ParseConfiguration (%s): expected %s, actual %s", k, in[k], getFieldString(&options, k))
}
}
for k, _ := range in_bool {
if getFieldBool(&options, k) != in_bool[k] {
t.Errorf("TestCmdLineFlags ParseConfiguration (%s): expected %t, actual %t", k, in_bool[k], getFieldBool(&options, k))
}
}
// Set up runtime core config
core.SetCoreRuntimeConfig(conf.Options)
if getFieldString(&options, "PhishingDomain") != core.PhishingDomain {
t.Errorf("TestCmdLineFlags SetCoreRuntimeConfig (%s): expected %s, actual %s", "PhishingDomain", getFieldString(&options, "PhishingDomain"), core.PhishingDomain)
}
if getFieldString(&options, "TrackingCookie") != core.TrackingCookie {
t.Errorf("TestCmdLineFlags SetCoreRuntimeConfig (%s): expected %s, actual %s", "TrackingCookie", getFieldString(&options, "TrackingCookie"), core.TrackingCookie)
}
if getFieldString(&options, "TrackingParam") != core.TrackingParam {
t.Errorf("TestCmdLineFlags SetCoreRuntimeConfig (%s): expected %s, actual %s", "TrackingParam", getFieldString(&options, "TrackingParam"), core.TrackingParam)
}
if "google.com" != core.TopLevelDomain {
t.Errorf("TestCmdLineFlags SetCoreRuntimeConfig (%s): expected %s, actual %s", "TopLevelDomain", "google.com", core.TopLevelDomain)
}
if "yyy" != core.ReplaceStrings["xxx"] {
t.Errorf("TestCmdLineFlags SetCoreRuntimeConfig (%s): expected %s, actual %s", "ReplaceStrings", "xxx", core.ReplaceStrings["xxx"])
}
if strings.Join(core.TargetResources, ",") != getFieldString(&options, "TargetRes") {
t.Errorf("TestCmdLineFlags SetCoreRuntimeConfig (%s): expected %s, actual %s", "TargetResources", getFieldString(&options, "TargetRes"), strings.Join(core.TargetResources, ","))
}
if strings.Join(core.TerminateTriggers, ",") != getFieldString(&options, "TerminateTriggers") {
t.Errorf("TestCmdLineFlags SetCoreRuntimeConfig (%s): expected %s, actual %s", "TerminateTriggers", getFieldString(&options, "TerminateRedirectUrl"), strings.Join(core.TerminateTriggers, ","))
}
// Set up runtime server config
core.SetServerRuntimeConfig(conf.Options)
if in["TLSCertificate"] != *core.ServerRuntimeConfig.TLSCertificate {
t.Errorf("TestCmdLineFlags SetServerRuntimeConfig (%s): expected %s, actual %s", "TLSCertificate", in["TLSCertificate"], *core.ServerRuntimeConfig.TLSCertificate)
}
if in["TLSKey"] != *core.ServerRuntimeConfig.TLSKey {
t.Errorf("TestCmdLineFlags SetServerRuntimeConfig (%s): expected %s, actual %s", "TLSKey", in["TLSKey"], *core.ServerRuntimeConfig.TLSKey)
}
// Set up runtime plugin config
plugin.SetPluginRuntimeConfig(conf.Options)
}