Skip to content

Cookbook

Worked examples for less obvious setups.

Testing SMTP submission with swaks

swaks (brew install swaks) is a scriptable SMTP test client. It can submit a message over STARTTLS without needing a username/password, which makes it a quick way to check that a mail tunnel (e.g. a submission service, or a Mailrouter tunnel) is accepting mail.

swaks --to recipient@example.com \
      --from sender@example.com \
      --h-Subject: "Test message" \
      --server smtp.example.com:587 \
      --tls-sni smtp.example.com \
      --tls \
      --body "This is a test email."

--server and --tls-sni must use the same hostname — --server determines what swaks connects to (and can also carry :port), while --tls-sni is the name sent in the TLS handshake and is what a Dioad Connect tunnel uses to route the connection.

  • --tls requires STARTTLS to be negotiated and fails if the server doesn't offer it. Use --tls-on-connect instead for implicit TLS (e.g. port 465).
  • Omitting --auth/--auth-user/--auth-password sends the message with no authentication — fine for servers that allow unauthenticated relay from trusted networks (e.g. testing over a SOCKS5 forward tunnel).
  • Certificate verification is off by default, which is useful for self-signed/dev certs. Add --tls-verify to enforce it.
  • Use --body @/path/to/message.txt to send a message body from a file instead of inline text.

SSH through reverse tunnel

If you have a reverse tunnel set up to forward to SSH, you can use socat or stunnel to route SSH connections over the tunnel. You can also use mutual TLS to secure these connections to the agent before sending SSH traffic over the tunnel.

This doesn't currently work with ACME Let's Encrypt certificates without a bit of a hack — use either the echo or hello tunnel type first to fetch the certificate to the cache directory, then change type: back to tcp.

agent.yaml:

traffic:
  tunnels:
    - name: ssh
      type: tcp
      tls-server:
        local:
          cert: /path/to/TestServerCertificate.pem
          key: /path/to/TestServerCertificate.key
      config:
        target-address: 127.0.0.1:22

~/.ssh/config:

Host ssh.<username>.traffic.lab.dioad.net
  ProxyCommand socat - OPENSSL:%h:9443,verify=0