Skip to content

Commit 67e5f72

Browse files
authored
Merge pull request #18 from trco/add-cert-to-image
Add and use built-in openssl certificate
2 parents 60cc6be + 11e74b4 commit 67e5f72

7 files changed

Lines changed: 97 additions & 58 deletions

File tree

.gitignore

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
/data
22
config*
3-
!config_structs.go
4-
!config/
5-
x_example_requests.txt
6-
x_notes.txt
7-
/x_proxy_setup
8-
demo.crt
9-
demo.key
3+
.vscode/
4+
!certs/
5+
wannabe.crt
6+
wannabe.key

Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@ FROM alpine
1616
WORKDIR /usr/src/app
1717

1818
COPY --from=builder /build/wannabe /usr/src/app/wannabe
19+
COPY certs/wannabe.crt /usr/src/app/certs/wannabe.crt
20+
COPY certs/wannabe.key /usr/src/app/certs/wannabe.key
1921

2022
RUN apk add --no-cache bash curl
2123

22-
ENV RUNNING_IN_CONTAINER=true
24+
ENV CERT_PATH=/usr/src/app/certs/wannabe.crt
25+
ENV CERT_KEY_PATH=/usr/src/app/certs/wannabe.key
2326

2427
EXPOSE 6789
2528
EXPOSE 6790

README.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,46 +8,52 @@ Official docker images are available at [Docker Hub](https://hub.docker.com/r/tr
88

99
For a successful startup, Wannabe requires the configuration and SSL certificate files.
1010

11-
For information on configuration see the [Configuration](#configuration) section. You must generate and use the self-signed SSL certificate for Wannabe to securely proxy HTTPS requests to other servers. It's crucial to ensure that the client's operating system, whether on a local machine or within a containerized environment, trusts the SSL certificate for secure communication with Wannabe. For guidance on adding the SSL certificate to your operating system and configuring trust settings, please refer to the relevant documentation.
11+
For information on configuration, see the [Configuration](#configuration) section. Wannabe comes with a built-in self-signed SSL certificate that can be used out of the box for securely proxying HTTPS requests to other servers. It's crucial to ensure that the client's operating system, whether on a local machine or within a containerized environment, trusts the SSL certificate for secure communication with Wannabe. You can find the built-in certificate and its key in the `certs` folder of this repository. For guidance on adding the SSL certificate to your operating system and configuring trust settings, please refer to the relevant documentation.
12+
13+
However, if you prefer to use your own custom SSL certificate, you have the option to generate and use a self-signed certificate. See the [Running as a standalone server](#running-as-a-standalone-server) or [Running in docker](#running-in-docker) sections for details on how to use your own custom SSL certificate.
1214

1315
### Generate self-signed SSL certificate
1416

1517
```
1618
// generate 2048-bit private key
17-
openssl genrsa -out wannabe.key 2048
19+
openssl genrsa -out custom_certificate_wannabe.key 2048
1820
```
1921

2022
```
2123
// generate self-signed SSL certificate valid for 10 years
22-
openssl req -new -x509 -key wannabe.key -out wannabe.crt -days 3650
24+
openssl req -new -x509 -key custom_certificate_wannabe.key -out custom_certificate_wannabe.crt -days 3650
2325
```
2426

2527
### Running as a standalone server
2628

27-
Like any Go program, Wannabe can be launched by simply cloning the repository, adding a `config.json`, `wannabe.crt` and `wannabe.key` to the root of the cloned repository, compiling the source code into an executable binary file using the `go build` command, and then running the program with the `go run` command.
29+
Like any Go program, Wannabe can be launched by following these steps:
30+
1. Clone the repository.
31+
2. Add a `config.json` file to the root of the cloned repository.
32+
3. Use either the built-in certificate `wannabe.crt` and its key `wannabe.key` in the `certs` folder of the repository, or overwrite both certificate files with your own custom certificate and key.
33+
4. Compile the source code into an executable binary file using the `go build` command, then run the program with the `./wannabe` command (or `wannabe.exe` on Windows).
2834

2935
### Running in Docker
3036

3137
Wannabe provides official [Docker images](https://hub.docker.com/r/trco/.wannabe) for running the application within a container.
3238

33-
To ensure a successful launch of the application, the configuration `.json` file and SSL certificate `.crt` and `.key` files should be mounted from the host operating system to the `/usr/src/app` directory of the Wannabe container. The environment variables `CONFIG_PATH`, `CERT_PATH`, and `CERT_KEY_PATH` should be set to the paths where the relevant files are mounted. Inside the container, the Wannabe server operates on port 6789, and the API is accessible through port 6790.
39+
To ensure a successful launch of the application, the configuration `.json` file should be present at the defined `CONFIG_PATH` environment variable. In case of using your own custom SSL certificate, the certificate `.crt` and key `.key` files should be present at the defined `CERT_PATH` and `CERT_KEY_PATH` environment variables. Inside the container, the Wannabe server operates on port 6789, and the API is accessible through port 6790.
3440

3541
```
3642
// pull the latest Wannabe image from Docker Hub
3743
docker pull trco/wannabe
3844
```
3945

4046
```
41-
// run Wannabe container using config.json and SSL certificate files wannabe.crt and wannabe.key
47+
// example of running Wannabe container using config.json and custom SSL certificate files
4248
docker run -d \
4349
-p 6789:6789 \
4450
-p 6790:6790 \
4551
-v $(pwd)/config.json:/usr/src/app/config.json \
46-
-v $(pwd)/wannabe.crt:/usr/src/app/wannabe.crt \
47-
-v $(pwd)/wannabe.key:/usr/src/app/wannabe.key \
52+
-v $(pwd)/custom_certificate_wannabe.crt:/usr/src/app/custom_certificate_wannabe.crt \
53+
-v $(pwd)/custom_certificate_wannabe.key:/usr/src/app/custom_certificate_wannabe.key \
4854
-e CONFIG_PATH=/usr/src/app/config.json \
49-
-e CERT_PATH=/usr/src/app/wannabe.crt \
50-
-e CERT_KEY_PATH=/usr/src/app/wannabe.key \
55+
-e CERT_PATH=/usr/src/app/custom_certificate_wannabe.crt \
56+
-e CERT_KEY_PATH=/usr/src/app/custom_certificate_wannabe.key \
5157
--name wannabe \
5258
trco/wannabe
5359
```
@@ -630,4 +636,5 @@ Your pull request will be reviewed, and you may be asked to make further changes
630636
If you're eager to contribute to Wannabe but aren't sure where to begin, we've got you covered! You can dive right in by exploring our open issues or checking out our existing "next step" ideas. Simply head over to the Issues tab to get started!
631637
632638
## Author
633-
Uroš Trstenjak (Trčo), [github.com/trco](https://github.com/trco), [Connect on LinkedIn](https://www.linkedin.com/in/uros-trstenjak/).
639+
Uroš Trstenjak (Trčo), [github.com/trco](https://github.com/trco), [Connect on LinkedIn](https://www.linkedin.com/in/uros-trstenjak/).
640+

certs/wannabe.crt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIID4zCCAsugAw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0jjTuAA0ZahxT1/UpZA
18+
38anDY5g3felgOudgOdRR+bC95vic9YN3gl424iXWSXrIGxpWpibaT36TpDTXAXe
19+
s5H86S5CwNzuTog3em19PHXMrq3jv/nnwm1o6BPh9aQAarp7rmxq1uGlJMq4bjpu
20+
aJEM1tF6zd7fv9CfE7FM3o94vtBo+6gvbccoB4mJNxm8NVRD150Orb6NcSnnobbo
21+
s+FNbLq1RHYcBsWgpgb1EcB/kqNpZZ7Yf3FcUl1v51LP9XXznV84/2BTSvrInN5x
22+
XvVluktbNA3oPMxlqR05/zY+83YyQvLz+f3cZrVkyXdWCT+VdM2N
23+
-----END CERTIFICATE-----

certs/wannabe.key

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-----BEGIN PRIVATE KEY-----
2+
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDoKOkiHVguNjC/
3+
HNvhMZwjPstSbndgpvaXxrDhSjtE6yWjF+HNRcpY1CxQcBSrTpP3KIzksdTYomE0
4+
MyY7c/iwP6VQopk1Y+y2MXhzcOvxYJs/2iM+7ou4X3IknN39+dJMcZgv5HW+lwHr
5+
JrLs8HM5MJdTWWs9ynd/44rmIDNHCytxhv55f1G7rP2fVGDwVVU2O0I5q/ETadn/
6+
w0CIDBWovjlPtp0LARZRLWwvedAh7FayusqLl3z5KW2CqiZz4LrEMN3mYYY8eQtZ
7+
1PS4FEkdUIrC0Pt+ZLXPExB41eLpIUvGY3rd973ObWuBZBBnTjkM+Uc5adlYZTxg
8+
dyOgHMxdAgMBAAECggEASKkROkej4ya7v/zIxqTvwMo0+ZIwU7Q95ofdsU052pqc
9+
F3zwg34N1Bpn2i8SEQGRZuAupJ8RxlGgCaXel+n2kjcBRwj02ZRyMB2wnLTha5T4
10+
UhY0RMyFN0nMIDBmfEhVrO46mvaucV2y0IW2p1ikP2h5XDFW0qqNFx5AyUCXu+pm
11+
6JnPdJOmYWPpfhnI61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5WnIirF1
28+
-----END PRIVATE KEY-----

internal/config/load_config.go

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,13 @@ func LoadConfig() (Config, error) {
3434
}
3535

3636
func getConfigPath() (string, error) {
37-
var configPath string
38-
39-
if os.Getenv(RunningInContainer) == "" {
40-
// check if config.json exists
41-
_, err := os.Stat("config.json")
42-
if err != nil && !os.IsNotExist(err) {
43-
return "", fmt.Errorf("failed checking if config.json file exists in the root folder")
44-
} else if os.IsNotExist(err) {
45-
return "", nil
46-
}
47-
48-
return "config.json", nil
49-
}
50-
51-
configPath = os.Getenv(ConfigPath)
37+
configPath := os.Getenv(ConfigPath)
5238
if configPath == "" {
53-
return "", fmt.Errorf("%v env variable not set", ConfigPath)
39+
configPath = "config.json"
40+
41+
if _, err := os.Stat(configPath); err != nil {
42+
return "", fmt.Errorf("failed loading config file: %v", err)
43+
}
5444
}
5545

5646
return configPath, nil

internal/config/load_mitm_config.go

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ import (
1111
)
1212

1313
func LoadMitmConfig() (*mitm.Config, error) {
14-
// var certPath, certKeyPath string
1514
certPath, certKeyPath, err := getCertPaths()
15+
if err != nil {
16+
return nil, err
17+
}
1618

1719
tlsCert, err := tls.LoadX509KeyPair(certPath, certKeyPath)
1820
if err != nil {
@@ -34,34 +36,23 @@ func LoadMitmConfig() (*mitm.Config, error) {
3436
}
3537

3638
func getCertPaths() (string, string, error) {
37-
var certPath, certKeyPath string
38-
39-
if os.Getenv(RunningInContainer) == "" {
40-
_, err := os.Stat("wannabe.crt")
41-
if err != nil {
42-
return "", "", fmt.Errorf("failed loading wannabe.crt file: %v", err)
43-
}
44-
certPath = "wannabe.crt"
39+
certPath := os.Getenv(CertPath)
40+
if certPath == "" {
41+
certPath = "certs/wannabe.crt"
4542

46-
_, err = os.Stat("wannabe.key")
47-
if err != nil {
48-
return "", "", fmt.Errorf("failed loading wannabe.key file: %v", err)
43+
if _, err := os.Stat(certPath); err != nil {
44+
return "", "", fmt.Errorf("failed loading certificate file: %v", err)
4945
}
50-
certKeyPath = "wannabe.key"
51-
52-
return certPath, certKeyPath, nil
5346
}
5447

55-
certPath = os.Getenv(CertPath)
56-
if certPath == "" {
57-
return "", "", fmt.Errorf("%v env variable not set", CertPath)
58-
}
48+
certKeyPath := os.Getenv(CertKeyPath)
49+
if certKeyPath == "" {
50+
certKeyPath = "certs/wannabe.key"
5951

60-
certKeyPath = os.Getenv(CertKeyPath)
61-
if certPath == "" {
62-
return "", "", fmt.Errorf("%v env variable not set", CertKeyPath)
52+
if _, err := os.Stat(certKeyPath); err != nil {
53+
return "", "", fmt.Errorf("failed loading key file: %v", err)
54+
}
6355
}
6456

6557
return certPath, certKeyPath, nil
66-
6758
}

0 commit comments

Comments
 (0)