From 741c792835ffb522e8d422bcafaf899f58fc3a87 Mon Sep 17 00:00:00 2001 From: eyedeekay Date: Sat, 8 Feb 2025 17:00:24 -0500 Subject: [PATCH] Add TODO's for tunnel filters that match Java I2P's IRC filter --- .gitignore | 2 + go.mod | 34 +++++++++++ go.sum | 116 +++++++++++++++++++++++++++++++++++++ lib/irc/client/dcc.go | 54 +++++++++++++++++ lib/irc/client/sanitize.go | 34 +++++++++++ lib/irc/server/sanitize.go | 49 ++++++++++++++++ lib/udp/const/doc.md | 16 +++++ 7 files changed, 305 insertions(+) create mode 100644 .gitignore create mode 100644 go.mod create mode 100644 go.sum create mode 100644 lib/irc/client/dcc.go create mode 100644 lib/udp/const/doc.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..84f3ccd --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.jar +*.aar \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..25972ad --- /dev/null +++ b/go.mod @@ -0,0 +1,34 @@ +module github.com/go-i2p/go-i2ptunnel + +go 1.23.5 + +require ( + github.com/go-i2p/go-connfilter v0.0.0-20250205023438-0f2b889a80f6 + github.com/go-i2p/go-forward v0.0.0-20250202052226-ee8a43dcb664 + github.com/go-i2p/go-i2ptunnel-config v0.0.0-20250208035926-cff0b0758eda + github.com/go-i2p/go-limit v0.0.0-20250203203118-210616857c15 + github.com/go-i2p/i2pkeys v0.33.92 + github.com/go-i2p/onramp v0.33.92 + github.com/txthinking/socks5 v0.0.0-20230325130024-4230056ae301 +) + +require ( + github.com/cpuguy83/go-md2man/v2 v2.0.6 // indirect + github.com/cretz/bine v0.2.0 // indirect + github.com/go-i2p/sam3 v0.33.9 // indirect + github.com/magiconair/properties v1.8.9 // indirect + github.com/patrickmn/go-cache v2.1.0+incompatible // indirect + github.com/russross/blackfriday/v2 v2.1.0 // indirect + github.com/sirupsen/logrus v1.9.3 // indirect + github.com/txthinking/runnergroup v0.0.0-20210608031112-152c7c4432bf // indirect + github.com/urfave/cli v1.22.16 // indirect + golang.org/x/crypto v0.32.0 // indirect + golang.org/x/mobile v0.0.0-20250106192035-c31d5b91ecc3 // indirect + golang.org/x/mod v0.23.0 // indirect + golang.org/x/net v0.34.0 // indirect + golang.org/x/sync v0.11.0 // indirect + golang.org/x/sys v0.30.0 // indirect + golang.org/x/time v0.9.0 // indirect + golang.org/x/tools v0.29.0 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..dac84d7 --- /dev/null +++ b/go.sum @@ -0,0 +1,116 @@ +github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= +github.com/cpuguy83/go-md2man/v2 v2.0.5 h1:ZtcqGrnekaHpVLArFSe4HK5DoKx1T0rq2DwVB0alcyc= +github.com/cpuguy83/go-md2man/v2 v2.0.5/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/cpuguy83/go-md2man/v2 v2.0.6 h1:XJtiaUW6dEEqVuZiMTn1ldk455QWwEIsMIJlo5vtkx0= +github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= +github.com/cretz/bine v0.2.0 h1:8GiDRGlTgz+o8H9DSnsl+5MeBK4HsExxgl6WgzOCuZo= +github.com/cretz/bine v0.2.0/go.mod h1:WU4o9QR9wWp8AVKtTM1XD5vUHkEqnf2vVSo6dBqbetI= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/go-i2p/go-connfilter v0.0.0-20250205023438-0f2b889a80f6 h1:kOJH77NTMYNrG1+dX/T/ZO2RX1xp7ZA1eViqy4uZy5M= +github.com/go-i2p/go-connfilter v0.0.0-20250205023438-0f2b889a80f6/go.mod h1:qSZ3m4cEeyQc391rRXIGYEq9zakEPMJG9WfeQ49gByU= +github.com/go-i2p/go-forward v0.0.0-20250202052226-ee8a43dcb664 h1:j+RzLt8jZPT9CeiLFDWEXvJPb6Orn3UQgywTx8iL1O4= +github.com/go-i2p/go-forward v0.0.0-20250202052226-ee8a43dcb664/go.mod h1:+R0jJkt7KIjVs2h83ENnORyaHJtPE9QCLpbYDiU6r84= +github.com/go-i2p/go-i2ptunnel-config v0.0.0-20250203061220-6b5e19741c47 h1:3F1vbqVvh12ge45nIsZtadP5n/rQ3f0+i1kJeCcrJGo= +github.com/go-i2p/go-i2ptunnel-config v0.0.0-20250203061220-6b5e19741c47/go.mod h1:u8CgiYIfehSFpoVWNe1up6TO4sasPpRUHxZw7W2e4sM= +github.com/go-i2p/go-i2ptunnel-config v0.0.0-20250208035926-cff0b0758eda h1:I5z+lG0tk6TB/GY1wEZLVJZer8kuA9KCG0IdrJWGghQ= +github.com/go-i2p/go-i2ptunnel-config v0.0.0-20250208035926-cff0b0758eda/go.mod h1:u8CgiYIfehSFpoVWNe1up6TO4sasPpRUHxZw7W2e4sM= +github.com/go-i2p/go-limit v0.0.0-20250203203118-210616857c15 h1:ASjMbwlepoDQfrhv+H2B5ICBPJU5ES1JzmOxzPDx3YQ= +github.com/go-i2p/go-limit v0.0.0-20250203203118-210616857c15/go.mod h1:4jjmVRhvKj47sQ6B6wdDhN1IrEZunE6KwkYLQx/BeVE= +github.com/go-i2p/i2pkeys v0.0.0-20241108200332-e4f5ccdff8c4/go.mod h1:m5TlHjPZrU5KbTd7Lr+I2rljyC6aJ88HdkeMQXV0U0E= +github.com/go-i2p/i2pkeys v0.33.92 h1:e2vx3vf7tNesaJ8HmAlGPOcfiGM86jzeIGxh27I9J2Y= +github.com/go-i2p/i2pkeys v0.33.92/go.mod h1:BRURQ/twxV0WKjZlFSKki93ivBi+MirZPWudfwTzMpE= +github.com/go-i2p/onramp v0.33.92 h1:Dk3A0SGpdEw829rSjW2LqN8o16pUvuhiN0vn36z7Gpc= +github.com/go-i2p/onramp v0.33.92/go.mod h1:5sfB8H2xk05gAS2K7XAUZ7ekOfwGJu3tWF0fqdXzJG4= +github.com/go-i2p/sam3 v0.33.9 h1:3a+gunx75DFc6jxloUZTAVJbdP6736VU1dy2i7I9fKA= +github.com/go-i2p/sam3 v0.33.9/go.mod h1:oDuV145l5XWKKafeE4igJHTDpPwA0Yloz9nyKKh92eo= +github.com/magiconair/properties v1.8.9 h1:nWcCbLq1N2v/cpNsy5WvQ37Fb+YElfq20WJ/a8RkpQM= +github.com/magiconair/properties v1.8.9/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= +github.com/miekg/dns v1.1.51 h1:0+Xg7vObnhrz/4ZCZcZh7zPXlmU0aveS2HDBd0m0qSo= +github.com/miekg/dns v1.1.51/go.mod h1:2Z9d3CP1LQWihRZUf29mQ19yDThaI4DAYzte2CaQW5c= +github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc= +github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= +github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/txthinking/runnergroup v0.0.0-20210608031112-152c7c4432bf h1:7PflaKRtU4np/epFxRXlFhlzLXZzKFrH5/I4so5Ove0= +github.com/txthinking/runnergroup v0.0.0-20210608031112-152c7c4432bf/go.mod h1:CLUSJbazqETbaR+i0YAhXBICV9TrKH93pziccMhmhpM= +github.com/txthinking/socks5 v0.0.0-20230325130024-4230056ae301 h1:d/Wr/Vl/wiJHc3AHYbYs5I3PucJvRuw3SvbmlIRf+oM= +github.com/txthinking/socks5 v0.0.0-20230325130024-4230056ae301/go.mod h1:ntmMHL/xPq1WLeKiw8p/eRATaae6PiVRNipHFJxI8PM= +github.com/urfave/cli v1.22.16 h1:MH0k6uJxdwdeWQTwhSO42Pwr4YLrNLwBtg1MRgTqPdQ= +github.com/urfave/cli v1.22.16/go.mod h1:EeJR6BKodywf4zciqrdw6hpCPk68JO9z5LazXZMn5Po= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc= +golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc= +golang.org/x/mobile v0.0.0-20250106192035-c31d5b91ecc3 h1:8LrYkH99trX3onYF3dT9frUSRDXokkceG+9tHBaDAFQ= +golang.org/x/mobile v0.0.0-20250106192035-c31d5b91ecc3/go.mod h1:sY92m3V/rTEa4JCJ1FkKHK978K6wxOSX1PStMYo+6wI= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.23.0 h1:Zb7khfcRGKk+kqfxFaP5tZqCnDZMjC5VtUBs87Hr6QM= +golang.org/x/mod v0.23.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= +golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0= +golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w= +golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU= +golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= +golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/time v0.9.0 h1:EsRrnYcQiGH+5FfbgvV4AP7qEZstoyrHB0DzarOQ4ZY= +golang.org/x/time v0.9.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.3.0/go.mod h1:/rWhSS2+zyEVwoJf8YAX6L2f0ntZ7Kn/mGgAWcipA5k= +golang.org/x/tools v0.29.0 h1:Xx0h3TtM9rzQpQuR4dKLrdglAmCEN5Oi+P74JdhdzXE= +golang.org/x/tools v0.29.0/go.mod h1:KMQVMRsVxU6nHCFXrBPhDB8XncLNLM0lIy/F14RP588= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/lib/irc/client/dcc.go b/lib/irc/client/dcc.go new file mode 100644 index 0000000..b830b31 --- /dev/null +++ b/lib/irc/client/dcc.go @@ -0,0 +1,54 @@ +package ircclient + +/** TODO: implement filters from Java I2P using IRC Filter from go-connfilter. +Java filters copied here: + // DCC command patterns + private static final Pattern DCC_SEND = Pattern.compile("^\\s*DCC\\s+SEND\\s+(\\S+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s*$"); + private static final Pattern DCC_CHAT = Pattern.compile("^\\s*DCC\\s+CHAT\\s+chat\\s+(\\d+)\\s+(\\d+)\\s*$"); + + // Core filtering methods + public String filterDCCRequest(String line) { + // Block direct IP-based DCC + if (line.toUpperCase().startsWith("DCC SEND") || + line.toUpperCase().startsWith("DCC CHAT")) { + return null; + } + + // Filter numeric IPs + if (line.matches(".*\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}.*")) { + return null; + } + + return line; + } + + // DCC SEND protection + private void handleDCCSend(String filename, String ip, int port, long size) { + // Validate parameters + if (port < 1024 || port > 65535) { + throw new SecurityException("Invalid DCC port"); + } + + // Block private/local IPs + if (isPrivateIP(ip)) { + throw new SecurityException("Private IP not allowed"); + } + } + + // DCC CHAT protection + private void handleDCCChat(String ip, int port) { + // Similar port validation + if (port < 1024 || port > 65535) { + throw new SecurityException("Invalid DCC port"); + } + } + + // IP validation + private boolean isPrivateIP(String ip) { + // Check for private IP ranges + return ip.startsWith("10.") || + ip.startsWith("172.16.") || + ip.startsWith("192.168.") || + ip.equals("127.0.0.1"); + } +*/ diff --git a/lib/irc/client/sanitize.go b/lib/irc/client/sanitize.go index a733467..6fdabeb 100644 --- a/lib/irc/client/sanitize.go +++ b/lib/irc/client/sanitize.go @@ -1 +1,35 @@ package ircclient + +/** TODO: implement filters from Java I2P using IRC Filter from go-connfilter. +Java filters copied here: + +// Replaces real hostnames with .i2p addresses +if (line.startsWith("PING ")) { + line = "PING " + _webircHost; +} else if (hostPattern.matcher(line).find()) { + line = line.replaceAll("([:.])[-a-zA-Z0-9.]+(\\.[a-zA-Z]{2,})", "$1" + _webircHost); +} + +// Blocks unsafe CTCP commands +if (line.indexOf("\001") >= 0) { + // CTCP filtering + if (line.toUpperCase().indexOf("DCC") >= 0) + return null; +} + +// DCC command protection +private void filterDCC(String line) { + if (line.toUpperCase().startsWith(":DCC ")) { + // Block DCC + return null; + } +} + +// Masks real user identities +private String filterUserHost(String line) { + if (userPattern.matcher(line).matches()) { + return line.replaceAll("![^@]+@[^ ]+", "!user@" + _webircHost); + } + return line; +} +*/ diff --git a/lib/irc/server/sanitize.go b/lib/irc/server/sanitize.go index 3afb07f..5a32600 100644 --- a/lib/irc/server/sanitize.go +++ b/lib/irc/server/sanitize.go @@ -1 +1,50 @@ package ircserver + +/** TODO: implement filters from Java I2P using IRC Filter from go-connfilter. +Java filters copied here: + + // Server-side filtering logic + protected void handleConnection(Socket socket) { + // Transforms incoming connections + String dest = socket.getInetAddress().toString(); + // Masks real destination with .i2p + dest = dest.replace(getRealHost(), getI2PHost()); + } + + // Command filtering + private String filterLine(String line) { + // Block administrative commands + if (line.startsWith("/ADMIN") || + line.startsWith("/OPER") || + line.startsWith("/DIE") || + line.startsWith("/RESTART")) + return null; + + // Replace real IPs with .i2p addresses + if (line.contains("@")) { + line = line.replaceAll("@[^\\s]+", "@" + getI2PHost()); + } + + // Filter WHOIS responses + if (line.startsWith("311 ")) { + // Mask user host information + return maskWhoisResponse(line); + } + + return line; + } + + // Host information masking + private String maskWhoisResponse(String line) { + // Replace real hostnames with .i2p + return line.replaceAll("\\s+[^\\s!]+@[^\\s]+", " unknown@" + getI2PHost()); + } + + // DCC command blocking + private void blockDCC(String line) { + if (line.toUpperCase().contains("DCC")) { + // Block all DCC attempts + throw new SecurityException("DCC not allowed"); + } + } +*/ diff --git a/lib/udp/const/doc.md b/lib/udp/const/doc.md new file mode 100644 index 0000000..3af7d10 --- /dev/null +++ b/lib/udp/const/doc.md @@ -0,0 +1,16 @@ +# udpconst +-- + import "github.com/go-i2p/go-i2ptunnel/lib/udp/const" + + +## Usage + +```go +var DatagramForwardConfig = &config.ForwardConfig{ + BufferSize: 32 * 1024, + IdleTimeout: 30 * time.Second, + MaxPacketSize: 65507 / 6, + EnableMetrics: true, + ShutdownSignal: make(chan struct{}), +} +```