# README #

### Clone this repository onto an Ubuntu VM

If you are spinning up a VM in the MOP Sandbox account, choose "Launch from template" and select the `frontdoor-mtls-testing`
VM from the list. This template uses the Netfoundry Sandbox SSH key, which is in sandbox secrets manager. Reach out to Mike
Guthrie if you need access to this key.

The URL is pre-authenticated.
```
git clone https://x-token-auth:ATCTT3xFfGN0jdsN1xttgQDXb7xmu1EoVO0ZkLr3gqBsdodC1vqIPZK8gaR9Lqj_2q5QsKKaf7eSLBjsoFVrr8l0ymygx7bYT7Veo26iN9b-mK27igA5i0YQehkId1hMbvvmfqDwT3B40GAxw2sEduK0B0e53epxd0KbvqvkShnAClwzRVY0K54=EE2999B5@bitbucket.org/netfoundry/mtls-tcp-testing-scripts.git
```


### Enroll the frontdoor-agent

Create and enroll the agent by following the **agent enrollment instructions in the
Console**. The Console walks you through installing the `frontdoor-agent` package,
enrolling it against your environment, and enabling the service.


### Start a TCP echo server

The TCP Share targets a local echo server on `:9000`. On the Ubuntu VM, start one
with Docker:
```
sudo docker run -d --name tcp-echo -p 9000:9000 venilnoronha/tcp-echo-server:latest
```

Alternatively, use Podman (rootless, no daemon). Install it and run the same image:
```
sudo apt-get update && sudo apt-get install -y podman
podman run -d --name tcp-echo -p 9000:9000 venilnoronha/tcp-echo-server:latest
```

### Generate a certificate and keypair
```
./generate_certs.sh
```

You should now have the following files in the current directory:
- `pinned-client.crt` (Upload this to the Console)
- `pinned-client.key`

### Create the TCP Shares in the Console
- Target host port should be `localhost:9000`
- Use the `pinned-client.crt` for your service's certificate
- Create the share and monitor the Change Log in the console to verify all steps completed

### Testing the TCP Share
This step assumes the share created successfully in the Console.
This will open a persistent TCP connection to the share and attempt to send a simple message
"I am groot" to the TCP echo server every 10 seconds, if it's working you should get a reply
"hello I am groot".
```
  python3 echo.py --host mtls.sandbox.netfoundry.io \
                             --port 2129 \
                             --cert pinned-client.crt \
                             --key pinned-client.key
```

### Resetting the environment for a fresh test
- Delete the agent from the Console first so that all zrok and Ziti records are cleaned up
- Run `./reset_env.sh` to reset the current machine back to a clean state, and then re-enroll as needed.
