1 { config, lib, pkgs, ... }:
7 cfg = config.networking.tcpcrypt;
17 networking.tcpcrypt.enable = mkOption {
21 Whether to enable opportunistic TCP encryption. If the other end
22 speaks Tcpcrypt, then your traffic will be encrypted; otherwise
23 it will be sent in clear text. Thus, Tcpcrypt alone provides no
24 guarantees -- it is best effort. If, however, a Tcpcrypt
25 connection is successful and any attackers that exist are
26 passive, then Tcpcrypt guarantees privacy.
31 config = mkIf cfg.enable {
33 users.users.tcpcryptd = {
34 uid = config.ids.uids.tcpcryptd;
35 description = "tcpcrypt daemon user";
38 systemd.services.tcpcrypt = {
39 description = "tcpcrypt";
41 wantedBy = [ "multi-user.target" ];
42 after = [ "network.target" ];
44 path = [ pkgs.iptables pkgs.tcpcrypt pkgs.procps ];
47 mkdir -p /run/tcpcryptd
48 chown tcpcryptd /run/tcpcryptd
49 sysctl -n net.ipv4.tcp_ecn > /run/tcpcryptd/pre-tcpcrypt-ecn-state
50 sysctl -w net.ipv4.tcp_ecn=0
52 iptables -t raw -N nixos-tcpcrypt
53 iptables -t raw -A nixos-tcpcrypt -p tcp -m mark --mark 0x0/0x10 -j NFQUEUE --queue-num 666
54 iptables -t raw -I PREROUTING -j nixos-tcpcrypt
56 iptables -t mangle -N nixos-tcpcrypt
57 iptables -t mangle -A nixos-tcpcrypt -p tcp -m mark --mark 0x0/0x10 -j NFQUEUE --queue-num 666
58 iptables -t mangle -I POSTROUTING -j nixos-tcpcrypt
61 script = "tcpcryptd -x 0x10";
64 if [ -f /run/tcpcryptd/pre-tcpcrypt-ecn-state ]; then
65 sysctl -w net.ipv4.tcp_ecn=$(cat /run/tcpcryptd/pre-tcpcrypt-ecn-state)
68 iptables -t mangle -D POSTROUTING -j nixos-tcpcrypt || true
69 iptables -t raw -D PREROUTING -j nixos-tcpcrypt || true
71 iptables -t raw -F nixos-tcpcrypt || true
72 iptables -t raw -X nixos-tcpcrypt || true
74 iptables -t mangle -F nixos-tcpcrypt || true
75 iptables -t mangle -X nixos-tcpcrypt || true