Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update tls cert for test #227

Merged
merged 1 commit into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions docs/transport.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,29 @@ By default, `rathole` forwards traffic as it is. Different options can be enable
Checkout the [example](../examples/tls)
### Client
Normally, a self-signed certificate is used. In this case, the client needs to trust the CA. `trusted_root` is the path to the root CA's certificate PEM file.
`hostname` is the hostname that the client used to validate aginst the certificate that the server presents.
`hostname` is the hostname that the client used to validate aginst the certificate that the server presents. Note that it does not have to be the same with the `remote_addr` in `[client]`.
```
[client.transport.tls]
trusted_root = "example/tls/ca-cert.pem"
hostname = "0.0.0.0"
trusted_root = "example/tls/rootCA.crt"
hostname = "localhost"
```

### Server
PKCS#12 archives are needed to run the server.

It can be created using openssl like:
```
openssl pkcs12 -export -out identity.pfx -inkey server-key.pem -in server-cert.pem -certfile ca_chain_certs.pem
openssl pkcs12 -export -out identity.pfx -inkey server.key -in server.crt -certfile ca_chain_certs.crt
```

Aruguments are:

- `-inkey`: Server Private Key
- `-in`: Server Certificate
- `-certfile`: CA Certificate

Creating self-signed certificate with one's own CA is a non-trival task. However, a script is provided under tls example folder for reference.

## Noise Protocol
### Quickstart for the Noise Protocl
In one word, the [Noise Protocol](http://noiseprotocol.org/noise.html) is a lightweigt, easy to configure and drop-in replacement of TLS. No need to create a self-sign certificate to secure the connection.
Expand Down
31 changes: 0 additions & 31 deletions examples/tls/ca-cert.pem

This file was deleted.

6 changes: 3 additions & 3 deletions examples/tls/client.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[client]
remote_addr = "localhost:2333"
remote_addr = "127.0.0.1:2333"
default_token = "123"

[client.transport]
type = "tls"
[client.transport.tls]
trusted_root = "examples/tls/ca-cert.pem"
hostname = "0.0.0.0"
trusted_root = "examples/tls/rootCA.crt"
hostname = "localhost"

[client.services.foo1]
local_addr = "127.0.0.1:80"
62 changes: 62 additions & 0 deletions examples/tls/create_self_signed_cert.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/sh

# create CA
openssl req -x509 \
-sha256 -days 356 \
-nodes \
-newkey rsa:2048 \
-subj "/CN=MyOwnCA/C=US/L=San Fransisco" \
-keyout rootCA.key -out rootCA.crt

# create server private key
openssl genrsa -out server.key 2048

# create certificate signing request (CSR)
cat > csr.conf <<EOF
[ req ]
default_bits = 2048
prompt = no
default_md = sha256
req_extensions = req_ext
distinguished_name = dn

[ dn ]
C = US
ST = California
L = San Fransisco
O = Someone
OU = Someone
CN = localhost

[ req_ext ]
subjectAltName = @alt_names

[ alt_names ]
DNS.1 = localhost
EOF

openssl req -new -key server.key -out server.csr -config csr.conf

# create server cert
cat > cert.conf <<EOF
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names

[alt_names]
DNS.1 = localhost
EOF

openssl x509 -req \
-in server.csr \
-CA rootCA.crt -CAkey rootCA.key \
-out server.crt \
-days 365 \
-sha256 -extfile cert.conf

# create pkcs12
openssl pkcs12 -export -out identity.pfx -inkey server.key -in server.crt -certfile rootCA.crt -passout pass:1234

# clean up
rm server.csr csr.conf cert.conf
Binary file modified examples/tls/identity.pfx
Binary file not shown.
20 changes: 20 additions & 0 deletions examples/tls/rootCA.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-----BEGIN CERTIFICATE-----
MIIDTzCCAjegAwIBAgIUT2Hjb+eORMuX0zIwClSygNTJiSQwDQYJKoZIhvcNAQEL
BQAwNzEQMA4GA1UEAwwHT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ERTIFICATE-----
4 changes: 2 additions & 2 deletions tests/for_tcp/tls_transport.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ default_token = "default_token_if_not_specify"
[client.transport]
type = "tls"
[client.transport.tls]
trusted_root = "examples/tls/ca-cert.pem"
hostname = "0.0.0.0"
trusted_root = "examples/tls/rootCA.crt"
hostname = "localhost"

[client.services.echo]
local_addr = "127.0.0.1:8080"
Expand Down
4 changes: 2 additions & 2 deletions tests/for_udp/tls_transport.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ default_token = "default_token_if_not_specify"
[client.transport]
type = "tls"
[client.transport.tls]
trusted_root = "examples/tls/ca-cert.pem"
hostname = "0.0.0.0"
trusted_root = "examples/tls/rootCA.crt"
hostname = "localhost"

[client.services.echo]
type = "udp"
Expand Down