Skip to content

Commit 476478b

Browse files
committed
dpi solver for http using nfqueue
1 parent 1e2793f commit 476478b

File tree

5 files changed

+233
-0
lines changed

5 files changed

+233
-0
lines changed

cmd/flags.go

+4
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ func CreateFlags(defaultPath string) []cli.Flag {
8585
Name: "http.memcached-host",
8686
Usage: "Set the memcached host(s) to use for HTTP based challenges. Challenges will be written to all specified hosts.",
8787
},
88+
&cli.StringFlag{
89+
Name: "http.nfqueueport",
90+
Usage: "Set the port to use for HTTP based challange. but unlike http it will not bind that port and while other thing already binding that port.",
91+
},
8892
&cli.BoolFlag{
8993
Name: "tls",
9094
Usage: "Use the TLS challenge to solve challenges. Can be mixed with other types of challenges.",

cmd/setup_challenges.go

+7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/go-acme/lego/v4/log"
1414
"github.com/go-acme/lego/v4/providers/dns"
1515
"github.com/go-acme/lego/v4/providers/http/memcached"
16+
nfqueue "github.com/go-acme/lego/v4/providers/http/nfqueue"
1617
"github.com/go-acme/lego/v4/providers/http/webroot"
1718
"github.com/urfave/cli/v2"
1819
)
@@ -55,6 +56,12 @@ func setupHTTPProvider(ctx *cli.Context) challenge.Provider {
5556
log.Fatal(err)
5657
}
5758
return ps
59+
case ctx.IsSet("http.nfqueueport"):
60+
ps, err := nfqueue.NewHttpDpiProvider(ctx.String("http.nfqueueport"))
61+
if err != nil {
62+
log.Fatal(err)
63+
}
64+
return ps
5865
case ctx.IsSet("http.port"):
5966
iface := ctx.String("http.port")
6067
if !strings.Contains(iface, ":") {

go.mod

+10
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ require (
7171
software.sslmate.com/src/go-pkcs12 v0.2.0
7272
)
7373

74+
require (
75+
github.com/florianl/go-nfqueue v1.3.1
76+
github.com/google/gopacket v1.1.19
77+
)
78+
7479
require (
7580
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
7681
github.com/Azure/go-autorest/autorest/adal v0.9.18 // indirect
@@ -92,18 +97,22 @@ require (
9297
github.com/golang-jwt/jwt/v4 v4.2.0 // indirect
9398
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
9499
github.com/golang/protobuf v1.5.2 // indirect
100+
github.com/google/go-cmp v0.5.8 // indirect
95101
github.com/google/uuid v1.3.0 // indirect
96102
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
97103
github.com/hashicorp/errwrap v1.0.0 // indirect
98104
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
99105
github.com/hashicorp/go-multierror v1.1.1 // indirect
100106
github.com/jmespath/go-jmespath v0.4.0 // indirect
107+
github.com/josharian/native v1.0.0 // indirect
101108
github.com/json-iterator/go v1.1.12 // indirect
102109
github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213 // indirect
103110
github.com/kolo/xmlrpc v0.0.0-20200310150728-e0350524596b // indirect
104111
github.com/labbsr0x/goh v1.0.1 // indirect
105112
github.com/liquidweb/go-lwApi v0.0.5 // indirect
106113
github.com/liquidweb/liquidweb-cli v0.6.9 // indirect
114+
github.com/mdlayher/netlink v1.6.0 // indirect
115+
github.com/mdlayher/socket v0.1.1 // indirect
107116
github.com/mitchellh/go-homedir v1.1.0 // indirect
108117
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
109118
github.com/modern-go/reflect2 v1.0.2 // indirect
@@ -123,6 +132,7 @@ require (
123132
go.opencensus.io v0.22.3 // indirect
124133
go.uber.org/ratelimit v0.2.0 // indirect
125134
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
135+
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
126136
golang.org/x/sys v0.4.0 // indirect
127137
golang.org/x/text v0.6.0 // indirect
128138
golang.org/x/tools v0.1.12 // indirect

go.sum

+16
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5Kwzbycv
132132
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
133133
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
134134
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
135+
github.com/florianl/go-nfqueue v1.3.1 h1:khQ9fYCrjbu5CF8dZF55G2RTIEIQRI0Aj5k3msJR6Gw=
136+
github.com/florianl/go-nfqueue v1.3.1/go.mod h1:aHWbgkhryJxF5XxYvJ3oRZpdD4JP74Zu/hP1zuhja+M=
135137
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
136138
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
137139
github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU=
@@ -215,13 +217,17 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
215217
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
216218
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
217219
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
220+
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
218221
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
219222
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
223+
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
220224
github.com/google/go-github/v32 v32.1.0/go.mod h1:rIEpZD9CTDQwDK9GDrtMTycQNA4JU3qBsCizh3q2WCI=
221225
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
222226
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
223227
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
224228
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
229+
github.com/google/gopacket v1.1.19 h1:ves8RnFZPGiFnTS0uPQStjwru6uO6h+nlr9j6fL7kF8=
230+
github.com/google/gopacket v1.1.19/go.mod h1:iJ8V8n6KS+z2U1A8pUwu8bW5SyEMkXJB8Yo/Vo+TKTo=
225231
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
226232
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
227233
github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
@@ -300,6 +306,8 @@ github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHW
300306
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
301307
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
302308
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
309+
github.com/josharian/native v1.0.0 h1:Ts/E8zCSEsG17dUqv7joXJFybuMLjQfWE04tsBODTxk=
310+
github.com/josharian/native v1.0.0/go.mod h1:7X/raswPFr05uY3HiLlYeyQntB6OO7E/d2Cu7qoaN2w=
303311
github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
304312
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
305313
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
@@ -373,6 +381,10 @@ github.com/mattn/go-runewidth v0.0.6/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m
373381
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
374382
github.com/mattn/go-tty v0.0.3/go.mod h1:ihxohKRERHTVzN+aSVRwACLCeqIoZAWpoICkkvrWyR0=
375383
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
384+
github.com/mdlayher/netlink v1.6.0 h1:rOHX5yl7qnlpiVkFWoqccueppMtXzeziFjWAjLg6sz0=
385+
github.com/mdlayher/netlink v1.6.0/go.mod h1:0o3PlBmGst1xve7wQ7j/hwpNaFaH4qCRyWCdcZk8/vA=
386+
github.com/mdlayher/socket v0.1.1 h1:q3uOGirUPfAV2MUoaC7BavjQ154J7+JOkTWyiV+intI=
387+
github.com/mdlayher/socket v0.1.1/go.mod h1:mYV5YIZAfHh4dzDVzI8x8tWLWCliuX8Mon5Awbj+qDs=
376388
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
377389
github.com/miekg/dns v1.1.47/go.mod h1:e3IlAVfNqAllflbibAZEWOXOQ+Ynzk/dDozDxY7XnME=
378390
github.com/miekg/dns v1.1.50 h1:DQUfb9uc6smULcREF09Uc+/Gd46YWqJd5DbpPE9xkcA=
@@ -675,7 +687,9 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b
675687
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
676688
golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
677689
golang.org/x/net v0.0.0-20210913180222-943fd674d43e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
690+
golang.org/x/net v0.0.0-20210928044308-7d9f5e0b762b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
678691
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
692+
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
679693
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
680694
golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw=
681695
golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws=
@@ -696,6 +710,7 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ
696710
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
697711
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
698712
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 h1:uVc8UZUe6tr40fFVnUP5Oj+veunVezqYl9z7DYw9xzw=
713+
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
699714
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
700715
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
701716
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -745,6 +760,7 @@ golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBc
745760
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
746761
golang.org/x/sys v0.0.0-20211103235746-7861aae1554b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
747762
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
763+
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
748764
golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
749765
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
750766
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

providers/http/nfqueue/nfqueue.go

+196
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
// Package nfqueue implements a HTTP provider for solving the HTTP-01 challenge using nfqueue
2+
// by captureing http challange pacet in fly and answering it by ourself
3+
package nfqueue
4+
5+
import (
6+
"bufio"
7+
"bytes"
8+
"context"
9+
"fmt"
10+
"log"
11+
"net"
12+
"net/http"
13+
"os/exec"
14+
"runtime"
15+
"strings"
16+
"time"
17+
18+
gnfqueue "github.com/florianl/go-nfqueue"
19+
"github.com/google/gopacket"
20+
"github.com/google/gopacket/layers"
21+
)
22+
23+
// HTTPProvider implements HTTPProvider for `http-01` challenge.
24+
type HTTPProvider struct {
25+
port string
26+
context context.Context
27+
cancel context.CancelFunc
28+
}
29+
30+
// NewHttpDpiProvider returns a HTTPProvider instance with a configured port.
31+
func NewHttpDpiProvider(port string) (*HTTPProvider, error) {
32+
33+
c := &HTTPProvider{
34+
port: port,
35+
}
36+
37+
return c, nil
38+
}
39+
40+
// this craft acme challange response in HTTP level
41+
func craftkeyauthresponse(keyAuth string) []byte {
42+
var reply []byte
43+
reply = fmt.Append(reply, "HTTP/1.1 200 OK\r\n")
44+
reply = fmt.Append(reply, "Content-Type: text/plain\r\n")
45+
reply = fmt.Append(reply, "server: go-acme-nfqueue\r\n")
46+
reply = fmt.Appendf(reply, "Content-Length: %d\r\n", len(keyAuth))
47+
reply = fmt.Append(reply, "\r\n", keyAuth)
48+
49+
return reply
50+
}
51+
52+
// craft packet
53+
func craftReplyPacketBytes(keyAuth string, inputpacket gopacket.Packet) []byte {
54+
outbuffer := gopacket.NewSerializeBuffer()
55+
opt := gopacket.SerializeOptions{
56+
FixLengths: true,
57+
ComputeChecksums: true,
58+
}
59+
inputTcp := inputpacket.Layer(layers.LayerTypeTCP).(*layers.TCP)
60+
inputIPv4 := inputpacket.Layer(layers.LayerTypeIPv4).(*layers.IPv4)
61+
62+
httplayer := gopacket.Payload(craftkeyauthresponse(keyAuth))
63+
tcplayer := &layers.TCP{
64+
// we reply back so reverse src and dst ports
65+
SrcPort: inputTcp.DstPort,
66+
DstPort: inputTcp.SrcPort,
67+
Ack: inputTcp.Seq + uint32(len(inputTcp.Payload)),
68+
Seq: inputTcp.Ack,
69+
PSH: true,
70+
ACK: true,
71+
}
72+
// log.Infof("dstp: %s, srcp %s", tcplayer.DstPort.String(), tcp)
73+
//check network layer
74+
// this is reply so we reverse sorce and dst ip
75+
iplayer := &layers.IPv4{
76+
SrcIP: inputIPv4.DstIP,
77+
DstIP: inputIPv4.SrcIP,
78+
}
79+
tcplayer.SetNetworkLayerForChecksum(iplayer)
80+
gopacket.SerializeLayers(outbuffer, opt, tcplayer, httplayer)
81+
82+
return outbuffer.Bytes()
83+
}
84+
85+
// sendPacket sends packet: TODO: call cleanup if errors out
86+
func sendPacket(packet []byte, DstIP *net.IP) error {
87+
var err error
88+
con, err := net.Dial("ip:6", DstIP.String())
89+
if err != nil {
90+
return err
91+
}
92+
_, err = con.Write(packet)
93+
if err != nil {
94+
return err
95+
}
96+
return nil
97+
}
98+
99+
// serve runs server by sniffing packets on firewall and inject response into it.
100+
// iptables ://
101+
func (w *HTTPProvider) serve(domain, token, keyAuth string) error {
102+
//run nfqueue start
103+
cmd := exec.Command("iptables", "-I", "INPUT", "-p", "tcp", "--dport", w.port, "-j", "NFQUEUE", "--queue-num", "8555")
104+
err := cmd.Run()
105+
// ensure even if clean funtion failed to called
106+
defer exec.Command("iptables", "-D", "INPUT", "-p", "tcp", "--dport", w.port, "-j", "NFQUEUE", "--queue-num", "8555").Run()
107+
if err != nil {
108+
return err
109+
}
110+
config := gnfqueue.Config{
111+
NfQueue: 8555,
112+
MaxPacketLen: 0xFFFF,
113+
MaxQueueLen: 0xFF,
114+
Copymode: gnfqueue.NfQnlCopyPacket,
115+
WriteTimeout: 15 * time.Millisecond,
116+
}
117+
nf, err := gnfqueue.Open(&config)
118+
if err != nil {
119+
return err
120+
}
121+
defer nf.Close()
122+
123+
//handle Packet
124+
handlepacket := func(a gnfqueue.Attribute) int {
125+
id := *a.PacketID
126+
opt := gopacket.DecodeOptions{
127+
NoCopy: true,
128+
Lazy: false,
129+
}
130+
//assume ipv4 for now, will segfault
131+
payload := gopacket.NewPacket(*a.Payload, layers.LayerTypeIPv4, opt)
132+
ipL := payload.Layer(layers.LayerTypeIPv4)
133+
srcip := ipL.(*layers.IPv4).SrcIP
134+
if tcpLayer := payload.Layer(layers.LayerTypeTCP); tcpLayer != nil {
135+
// Get actual TCP data from this layer
136+
inputTcp, _ := tcpLayer.(*layers.TCP)
137+
// this should be HTTP payload
138+
httpPayload, err := http.ReadRequest(bufio.NewReader((bytes.NewReader(inputTcp.LayerPayload()))))
139+
if err != nil {
140+
nf.SetVerdict(id, gnfqueue.NfAccept)
141+
return 0
142+
}
143+
// check token in http
144+
if strings.Contains(httpPayload.URL.Path, token) {
145+
//we got the token!, block the packet to backend server.
146+
nf.SetVerdict(id, gnfqueue.NfDrop)
147+
//forge our new reply
148+
replypacket := craftReplyPacketBytes(keyAuth, payload)
149+
// Send the modified packet back to VA, ignore err as it won't crash
150+
sendPacket(replypacket, &srcip)
151+
// packet sent, end of function
152+
return 0
153+
} else {
154+
nf.SetVerdict(id, gnfqueue.NfAccept)
155+
return 0
156+
}
157+
158+
} else {
159+
nf.SetVerdict(id, gnfqueue.NfAccept)
160+
}
161+
162+
return 0
163+
}
164+
165+
// Register your function to listen on nflqueue queue
166+
err = nf.Register(w.context, handlepacket)
167+
if err != nil {
168+
fmt.Println(err)
169+
return nil
170+
}
171+
172+
// Block till the context expires
173+
<-w.context.Done()
174+
return nil
175+
}
176+
177+
func (w *HTTPProvider) Present(domain, token, keyAuth string) error {
178+
// test if OS is linux, otherwise no point running this nfqueue is linux thing
179+
if runtime.GOOS != "linux" {
180+
log.Panicf("[%s] http-nfq provider isn't implimented non-linux", domain)
181+
}
182+
w.context, w.cancel = context.WithCancel(context.Background())
183+
go w.serve(domain, token, keyAuth)
184+
return nil
185+
}
186+
187+
// CleanUp removes the firewall rule created for the challenge.
188+
// solve should removed it already but just do be safe:
189+
// iptables -D INPUT -p tcp --dport Port -j NFQUEUE --queue-num 8555
190+
func (w *HTTPProvider) CleanUp(domain, token, keyAuth string) error {
191+
cmd := exec.Command("iptables", "-D", "INPUT", "-p", "tcp", "--dport", w.port, "-j", "NFQUEUE", "--queue-num", "8555")
192+
cmd.Run()
193+
// tell nfqueue to shut down
194+
w.cancel()
195+
return nil
196+
}

0 commit comments

Comments
 (0)