32 Commits

Author SHA1 Message Date
idk
d79ea5d92f Bump version and re-release, repos were out of sync 2021-08-19 19:56:21 -04:00
idk
77c7e6c08c produce a windows executable as well 2021-08-17 19:38:49 -04:00
idk
36783b4587 make it build unmanaged plugins so that you can run a reseed server from a desktop I2P installation. Defaults to hosting both an .onion and .i2p service for now, even though the .i2p service is arguably useless, because it's much easier to test. In the future I will either need to disable .onion or embed libtor so that there is a Tor SOCKSPort and Control Port to connect to 2021-08-17 19:25:29 -04:00
idk
71e6743206 make it build unmanaged plugins so that you can run a reseed server from a desktop I2P installation. Defaults to hosting both an .onion and .i2p service for now, even though the .i2p service is arguably useless, because it's much easier to test. In the future I will either need to disable .onion or embed libtor so that there is a Tor SOCKSPort and Control Port to connect to 2021-08-17 19:24:08 -04:00
idk
33cdebd325 Merge branch 'acme' into 'master'
Adds support for generating certificates using Let's Encrypt or other ACME providers

See merge request idk/reseed-tools!5
2021-08-17 22:40:14 +00:00
idk
86a183c9fa add missing update types to su3.go 2021-07-01 21:00:53 -04:00
idk
accce088e6 Make it automatically renew 2 days before the cert expires 2021-05-11 21:44:06 -04:00
idk
42beefd223 Merge branch 'acme' of 127.0.0.1:idk/reseed-tools into make-a-plugin-su3 2021-05-11 21:12:33 -04:00
idk
12b71780a1 Make it automatically renew 2 days before the cert expires 2021-05-11 21:03:36 -04:00
idk
b444857549 clean up the modules 2021-05-11 19:53:02 -04:00
idk
2004e84df8 Merge branch 'master' of 127.0.0.1:idk/reseed-tools into make-a-plugin-su3 2021-05-11 19:49:20 -04:00
idk
7441572846 Switch to prod 2021-05-11 19:47:22 -04:00
idk
93dd1b4e8d Switch to prod 2021-05-11 19:34:12 -04:00
idk
398a6182af Merge branch 'one-time-links' into 'master'
add the ability for browsers to download via a one-time link with a short timeout.

Closes #1

See merge request idk/reseed-tools!4
2021-05-11 22:53:03 +00:00
idk
d467b652ec First try, how about that? 2021-05-11 18:49:37 -04:00
idk
19c29cfdc6 Move TLS certificate generation for clearnet sites to the front, use same cert across all domains, will be invalid on .onion and .i2p when using Let's Encrypt 2021-05-11 17:23:18 -04:00
idk
1548d1e36b Rate limit it too 2021-05-11 16:39:34 -04:00
idk
3e8ace902d add the ability for browsers to download via a one-time link with a short timeout. 2021-05-11 16:26:55 -04:00
idk
8afd6c6f28 Merge branch 'bug-cannot-autogenerate-self_signed-keys' into 'master'
fix: auto-generate keys when --yes is passed

See merge request idk/reseed-tools!2
2021-03-26 23:26:17 +00:00
idk
b94bd86d03 Merge branch 'bug-cannot-start-container' into 'master'
fix: Use correct command name in entrypoint.sh

See merge request idk/reseed-tools!3
2021-03-26 23:25:41 +00:00
idk
7829962acd Merge branch 'ci-build-images' into 'master'
CI build images

See merge request idk/reseed-tools!1
2021-03-26 23:25:22 +00:00
idk
299421e0fe Create a jar file of the reseed server library 2021-02-04 14:09:35 -05:00
a7c097d232 fix: auto-generate keys when --yes is passed
Probably a typo in the if condition as the same commit uses the correct condition elsewhere.
Only if --yes isn't passed should the user be queried interactively
2021-01-01 16:21:56 +01:00
7282cb5fa0 fix: Use correct command name in entrypoint.sh
The generated executable isn't called i2p-tools-1 but reseed-tools.
Without the correct name, the container wouldn't start.
2021-01-01 16:18:33 +01:00
2f8508ee92 ci: Use multiline chomp in YAML
It put the backslashes right into the bash command bash didn't really like that.
Bash escaped spaces and that lead to a bad command
2020-12-29 16:21:29 +01:00
b036b9e8f8 ci: Quote variables properly 2020-12-29 10:47:08 +01:00
f36a500210 ci: Improve tag regex for pushing docker 2020-12-29 10:34:29 +01:00
dbcf640320 ci: Push README to dockerhub 2020-12-29 10:26:48 +01:00
08f2f9031d Add more comments to .gitlab-ci.yml 2020-12-29 01:07:27 +01:00
d40d687f6e ci: limit builds to tags with certain names 2020-12-29 01:05:21 +01:00
b12bf1bf22 docker: ignore IDE files 2020-12-29 00:55:38 +01:00
7bcc9344ec Use correct syntax to ignore folders for docker 2020-12-29 00:54:23 +01:00
18 changed files with 1019 additions and 300 deletions

View File

@@ -1,6 +1,8 @@
.git/
.idea
.git
.gitlab-ci.yml
.vscode
# CI cache folder storing docker images
ci-exports/
ci-exports

4
.gitignore vendored
View File

@@ -7,3 +7,7 @@ i2pseeds.su3
onion.key
tmp/
i2p-tools-*
*.crl
*.crt
*.pem
plugin

View File

@@ -28,12 +28,13 @@ services:
.docker_cache:
cache:
# The same key should be used across branches
key: "$CI_COMMIT_REF_SLUG"
paths:
- ci-exports/*.tar
# Make sure we can build a docker image
# It's pushed to the pipeline-local registry which acts as a cache
# It's cached for later jobs
build_docker:
extends:
- .docker_cache
@@ -61,11 +62,13 @@ push_ci_registry:
- docker push $CI_REGISTRY_IMAGE:latest
only:
refs:
- master
# Make sure to protect these tags!
- /^v(\d+\.){2,3}\d+$/
- /.+-release$/
variables:
- $CI_REGISTRY
- $CI_REGISTRY_USER
- $CI_REGISTRY_PASSWORD
- $CI_REGISTRY
- $CI_REGISTRY_IMAGE
# Publishes the cached image to docker
@@ -83,13 +86,21 @@ push_dockerhub_registry:
- docker tag $CI_REGISTRY_IMAGE:latest $DOCKERHUB_REGISTRY_IMAGE:latest
- docker push $DOCKERHUB_REGISTRY_IMAGE:$CI_COMMIT_TAG
- docker push $DOCKERHUB_REGISTRY_IMAGE:latest
# TODO: Use rules https://docs.gitlab.com/ee/ci/yaml/README.html#rules
# Push the readme to dockerhub
- >-
docker run -v $PWD:/workspace
-e DOCKERHUB_USERNAME="$DOCKERHUB_REGISTRY_USER"
-e DOCKERHUB_PASSWORD="$DOCKERHUB_REGISTRY_PASSWORD"
-e DOCKERHUB_REPOSITORY="$DOCKERHUB_REGISTRY_IMAGE"
-e README_FILEPATH='/workspace/README.md'
peterevans/dockerhub-description:2
only:
refs:
# - master
- tags
# Make sure to protect these tags!
- /^v(\d+\.){2,3}\d+$/
- /.+-release$/
variables:
- $DOCKERHUB_REGISTRY
- $DOCKERHUB_REGISTRY_USER
- $DOCKERHUB_REGISTRY_PASSWORD
- $DOCKERHUB_REGISTRY
- $DOCKERHUB_REGISTRY_IMAGE

View File

@@ -1,6 +1,6 @@
VERSION=0.0.6
APP=i2p-tools-1
VERSION=0.0.9
APP=reseed-tools
USER_GH=eyedeekay
GOOS?=$(shell uname -s | tr A-Z a-z)
@@ -26,13 +26,13 @@ edit:
cat README.md | gothub edit -s $(GITHUB_TOKEN) -u $(USER_GH) -r $(APP) -t v$(VERSION) -d -
upload: binary tar
gothub upload -s $(GITHUB_TOKEN) -u $(USER_GH) -r $(APP) -t v$(VERSION) -f ../i2p-tools.tar.xz -n "i2p-tools.tar.xz"
gothub upload -s $(GITHUB_TOKEN) -u $(USER_GH) -r $(APP) -t v$(VERSION) -f ../reseed-tools.tar.xz -n "reseed-tools.tar.xz"
build: gofmt
/usr/lib/go-$(MIN_GO_VERSION)/bin/go build $(ARG) -o i2p-tools-$(GOOS)-$(GOARCH)
/usr/lib/go-$(MIN_GO_VERSION)/bin/go build $(ARG) -o reseed-tools-$(GOOS)-$(GOARCH)
clean:
rm i2p-tools-* *.key *.i2pKeys *.crt *.crl *.pem tmp -rf
rm reseed-tools-* *.key *.i2pKeys *.crt *.crl *.pem tmp -rfv
binary:
GOOS=darwin GOARCH=amd64 make build
@@ -43,12 +43,13 @@ binary:
GOOS=openbsd GOARCH=amd64 make build
GOOS=freebsd GOARCH=386 make build
GOOS=freebsd GOARCH=amd64 make build
GOOS=windows GOARCH=amd64 make build
tar:
tar --exclude="./.git" --exclude="./tmp" -cvf ../i2p-tools.tar.xz .
tar --exclude="./.git" --exclude="./tmp" -cvf ../reseed-tools.tar.xz .
install:
install -m755 i2p-tools-$(GOOS)-$(GOARCH) /usr/local/bin/i2p-tools
install -m755 reseed-tools-$(GOOS)-$(GOARCH) /usr/local/bin/reseed-tools
install -m755 etc/init.d/reseed /etc/init.d/reseed
### You shouldn't need to use these now that the go mod require rule is fixed,
@@ -56,10 +57,10 @@ install:
## versions behaved the same way. -idk
build-fork:
/usr/lib/go-$(MIN_GO_VERSION)/bin/go build -o i2p-tools-idk
/usr/lib/go-$(MIN_GO_VERSION)/bin/go build -o reseed-tools-idk
build-unfork:
/usr/lib/go-$(MIN_GO_VERSION)/bin/go build -o i2p-tools-md
/usr/lib/go-$(MIN_GO_VERSION)/bin/go build -o reseed-tools-md
fork:
sed -i 's|idk/reseed-tools|idk/reseed-tools|g' main.go cmd/*.go reseed/*.go su3/*.go
@@ -67,7 +68,7 @@ fork:
unfork:
sed -i 's|idk/reseed-tools|idk/reseed-tools|g' main.go cmd/*.go reseed/*.go su3/*.go
sed -i 's|RTradeLtd/i2p-tools-1|idk/reseed-tools|g' main.go cmd/*.go reseed/*.go su3/*.go
sed -i 's|RTradeLtd/reseed-tools|idk/reseed-tools|g' main.go cmd/*.go reseed/*.go su3/*.go
make gofmt build-unfork
gofmt:
@@ -76,12 +77,12 @@ gofmt:
try:
mkdir -p tmp && \
cd tmp && \
../i2p-tools-$(GOOS)-$(GOARCH) reseed --signer=you@mail.i2p --netdb=/home/idk/.i2p/netDb --tlsHost=your-domain.tld --onion --p2p --i2p --littleboss=start
../reseed-tools-$(GOOS)-$(GOARCH) reseed --signer=you@mail.i2p --netdb=/home/idk/.i2p/netDb --tlsHost=your-domain.tld --onion --p2p --i2p --littleboss=start
stop:
mkdir -p tmp && \
cd tmp && \
../i2p-tools-$(GOOS)-$(GOARCH) reseed --signer=you@mail.i2p --netdb=/home/idk/.i2p/netDb --tlsHost=your-domain.tld --onion --p2p --i2p --littleboss=stop
../reseed-tools-$(GOOS)-$(GOARCH) reseed --signer=you@mail.i2p --netdb=/home/idk/.i2p/netDb --tlsHost=your-domain.tld --onion --p2p --i2p --littleboss=stop
docker:
docker build -t eyedeekay/reseed .
@@ -109,7 +110,7 @@ docker-server:
--publish 8443:8443 \
--restart=always \
--volume /var/lib/i2p/i2p-config/netDb:/var/lib/i2p/i2p-config/netDb:z \
--volume reseed-keyss:/var/lib/i2p/i2p-config/reseed \
--volume reseed-keys:/var/lib/i2p/i2p-config/reseed \
eyedeekay/reseed \
--signer=hankhill19580@gmail.com
docker logs -f reseed
@@ -135,3 +136,44 @@ docker-homerun:
--volume reseed-keys:/var/lib/i2p/i2p-config/reseed:z \
eyedeekay/reseed \
--signer=hankhill19580@gmail.com
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre/
export CGO_CFLAGS=-I/usr/lib/jvm/java-8-openjdk-amd64/include/ -I/usr/lib/jvm/java-8-openjdk-amd64/include/linux/
gojava:
go get -u -v github.com/sridharv/gojava
cp -v ~/go/bin/gojava ./gojava
jar: gojava
echo $(JAVA_HOME)
./gojava -v -o reseed.jar -s . build ./reseed
plugins: binary
GOOS=darwin GOARCH=amd64 make su3s
GOOS=linux GOARCH=386 make su3s
GOOS=linux GOARCH=amd64 make su3s
GOOS=linux GOARCH=arm make su3s
GOOS=linux GOARCH=arm64 make su3s
GOOS=openbsd GOARCH=amd64 make su3s
GOOS=freebsd GOARCH=386 make su3s
GOOS=freebsd GOARCH=amd64 make su3s
GOOS=windows GOARCH=amd64 make su3s
su3s:
i2p.plugin.native -name=reseed-tools-$(GOOS)-$(GOARCH) \
-signer=hankhill19580@gmail.com \
-version "$(VERSION)" \
-author=hankhill19580@gmail.com \
-autostart=true \
-clientname=reseed-tools-$(GOOS)-$(GOARCH) \
-command="\$$PLUGIN/lib/reseed-tools-$(GOOS)-$(GOARCH)s -dir=\$$PLUGIN/lib reseed --signer=you@mail.i2p --netdb=\$$CONFIG/netDb --onion --i2p" \
-consolename="Reseed Tools" \
-delaystart="200" \
-desc="Reseed Tools Plugin" \
-exename=reseed-tools-$(GOOS)-$(GOARCH) \
-targetos="$(GOOS)" \
-license=MIT
unzip -o reseed-tools-$(GOOS)-$(GOARCH).zip -d reseed-tools-$(GOOS)-$(GOARCH)-zip
#export sumbblinux=`sha256sum "../reseed-tools-linux.su3"`
#export sumbbwindows=`sha256sum "../reseed-tools-windows.su3"`

View File

@@ -10,7 +10,7 @@ If you have go installed you can download, build, and install this tool with `go
```
go get i2pgit.org/idk/reseed-tools
i2p-tools -h
reseed-tools -h
```
## Usage
@@ -76,13 +76,13 @@ work for you. In that case, just copy-and-paste:
### Locally behind a webserver (reverse proxy setup), preferred:
```
i2p-tools reseed --signer=you@mail.i2p --netdb=/home/i2p/.i2p/netDb --port=8443 --ip=127.0.0.1 --trustProxy
reseed-tools reseed --signer=you@mail.i2p --netdb=/home/i2p/.i2p/netDb --port=8443 --ip=127.0.0.1 --trustProxy
```
### Without a webserver, standalone with TLS support
```
i2p-tools reseed --signer=you@mail.i2p --netdb=/home/i2p/.i2p/netDb --tlsHost=your-domain.tld
reseed-tools reseed --signer=you@mail.i2p --netdb=/home/i2p/.i2p/netDb --tlsHost=your-domain.tld
```
If this is your first time running a reseed server (ie. you don't have any existing keys),
@@ -103,25 +103,25 @@ Requires ```go mod``` and at least go 1.13. To build the idk/reseed-tools
fork, from anywhere:
git clone https://i2pgit.org/idk/reseed-tools
cd i2p-tools-1
cd reseed-tools
make build
### Without a webserver, standalone, self-supervising(Automatic restarts)
```
./i2p-tools-1 reseed --signer=you@mail.i2p --netdb=/home/i2p/.i2p/netDb --littleboss=start
./reseed-tools reseed --signer=you@mail.i2p --netdb=/home/i2p/.i2p/netDb --littleboss=start
```
### Without a webserver, standalone, automatic OnionV3 with TLS support
```
./i2p-tools-1 reseed --signer=you@mail.i2p --netdb=/home/i2p/.i2p/netDb --onion --i2p --p2p
./reseed-tools reseed --signer=you@mail.i2p --netdb=/home/i2p/.i2p/netDb --onion --i2p --p2p
```
### Without a webserver, standalone, serve P2P with LibP2P
```
./i2p-tools-1 reseed --signer=you@mail.i2p --netdb=/home/i2p/.i2p/netDb --p2p
./reseed-tools reseed --signer=you@mail.i2p --netdb=/home/i2p/.i2p/netDb --p2p
```
### Without a webserver, standalone, upload a single signed .su3 to github
@@ -129,29 +129,29 @@ fork, from anywhere:
* This one isn't working yet, I'll get to it eventually, I've got a cooler idea now.
```
./i2p-tools-1 reseed --signer=you@mail.i2p --netdb=/home/i2p/.i2p/netDb --github --ghrepo=i2p-tools-1 --ghuser=eyedeekay
./reseed-tools reseed --signer=you@mail.i2p --netdb=/home/i2p/.i2p/netDb --github --ghrepo=reseed-tools --ghuser=eyedeekay
```
### Without a webserver, standalone, in-network reseed
```
./i2p-tools-1 reseed --signer=you@mail.i2p --netdb=/home/i2p/.i2p/netDb --i2p
./reseed-tools reseed --signer=you@mail.i2p --netdb=/home/i2p/.i2p/netDb --i2p
```
### Without a webserver, standalone, Regular TLS, OnionV3 with TLS
```
./i2p-tools-1 reseed --tlsHost=your-domain.tld --signer=you@mail.i2p --netdb=/home/i2p/.i2p/netDb --onion
./reseed-tools reseed --tlsHost=your-domain.tld --signer=you@mail.i2p --netdb=/home/i2p/.i2p/netDb --onion
```
### Without a webserver, standalone, Regular TLS, OnionV3 with TLS, and LibP2P
```
./i2p-tools-1 reseed --tlsHost=your-domain.tld --signer=you@mail.i2p --netdb=/home/i2p/.i2p/netDb --onion --p2p
./reseed-tools reseed --tlsHost=your-domain.tld --signer=you@mail.i2p --netdb=/home/i2p/.i2p/netDb --onion --p2p
```
### Without a webserver, standalone, Regular TLS, OnionV3 with TLS, I2P In-Network reseed, and LibP2P, self-supervising
```
./i2p-tools-1 reseed --tlsHost=your-domain.tld --signer=you@mail.i2p --netdb=/home/i2p/.i2p/netDb --onion --p2p --littleboss=start
./reseed-tools reseed --tlsHost=your-domain.tld --signer=you@mail.i2p --netdb=/home/i2p/.i2p/netDb --onion --p2p --littleboss=start
```

View File

@@ -133,6 +133,15 @@ func NewReseedCommand() cli.Command {
Value: "start",
Usage: "Self-Supervise this application",
},
cli.BoolFlag{
Name: "acme",
Usage: "Automatically generate a TLS certificate with the ACME protocol, defaults to Let's Encrypt",
},
cli.StringFlag{
Name: "acmeserver",
Value: "https://acme-staging-v02.api.letsencrypt.org/directory",
Usage: "Use this server to issue a certificate with the ACME protocol",
},
},
}
}
@@ -208,13 +217,53 @@ func reseedAction(c *cli.Context) {
var i2pTlsCert, i2pTlsKey string
var i2pkey i2pkeys.I2PKeys
if tlsHost != "" {
onionTlsHost = tlsHost
i2pTlsHost = tlsHost
tlsKey = c.String("tlsKey")
// if no key is specified, default to the host.pem in the current dir
if tlsKey == "" {
tlsKey = tlsHost + ".pem"
onionTlsKey = tlsHost + ".pem"
i2pTlsKey = tlsHost + ".pem"
}
tlsCert = c.String("tlsCert")
// if no certificate is specified, default to the host.crt in the current dir
if tlsCert == "" {
tlsCert = tlsHost + ".crt"
onionTlsCert = tlsHost + ".crt"
i2pTlsCert = tlsHost + ".crt"
}
// prompt to create tls keys if they don't exist?
auto := c.Bool("yes")
// use ACME?
acme := c.Bool("acme")
if acme {
acmeserver := c.String("acmeserver")
err := checkUseAcmeCert(tlsHost, signerID, acmeserver, &tlsCert, &tlsKey, auto)
if nil != err {
log.Fatalln(err)
}
} else {
err := checkOrNewTLSCert(tlsHost, &tlsCert, &tlsKey, auto)
if nil != err {
log.Fatalln(err)
}
}
}
if c.Bool("i2p") {
var err error
i2pkey, err = LoadKeys("reseed.i2pkeys", c)
if err != nil {
log.Fatalln(err)
}
i2pTlsHost = i2pkey.Addr().Base32()
if i2pTlsHost == "" {
i2pTlsHost = i2pkey.Addr().Base32()
}
if i2pTlsHost != "" {
// if no key is specified, default to the host.pem in the current dir
if i2pTlsKey == "" {
@@ -250,7 +299,9 @@ func reseedAction(c *cli.Context) {
}
ok = []byte(key.PrivateKey())
}
onionTlsHost = torutil.OnionServiceIDFromPrivateKey(ed25519.PrivateKey(ok)) + ".onion"
if onionTlsHost == "" {
onionTlsHost = torutil.OnionServiceIDFromPrivateKey(ed25519.PrivateKey(ok)) + ".onion"
}
err = ioutil.WriteFile(c.String("onionKey"), ok, 0644)
if err != nil {
log.Fatalln(err.Error())
@@ -275,27 +326,6 @@ func reseedAction(c *cli.Context) {
}
}
if tlsHost != "" {
tlsKey = c.String("tlsKey")
// if no key is specified, default to the host.pem in the current dir
if tlsKey == "" {
tlsKey = tlsHost + ".pem"
}
tlsCert = c.String("tlsCert")
// if no certificate is specified, default to the host.crt in the current dir
if tlsCert == "" {
tlsCert = tlsHost + ".crt"
}
// prompt to create tls keys if they don't exist?
auto := c.Bool("yes")
err := checkOrNewTLSCert(tlsHost, &tlsCert, &tlsKey, auto)
if nil != err {
log.Fatalln(err)
}
}
reloadIntvl, err := time.ParseDuration(c.String("interval"))
if nil != err {
fmt.Printf("'%s' is not a valid time interval.\n", reloadIntvl)
@@ -362,7 +392,7 @@ func reseedAction(c *cli.Context) {
}
}
func reseedHTTPS(c *cli.Context, tlsCert, tlsKey string, reseeder reseed.Reseeder) {
func reseedHTTPS(c *cli.Context, tlsCert, tlsKey string, reseeder *reseed.ReseederImpl) {
server := reseed.NewServer(c.String("prefix"), c.Bool("trustProxy"))
server.Reseeder = reseeder
server.Addr = net.JoinHostPort(c.String("ip"), c.String("port"))
@@ -391,7 +421,7 @@ func reseedHTTPS(c *cli.Context, tlsCert, tlsKey string, reseeder reseed.Reseede
}
}
func reseedHTTP(c *cli.Context, reseeder reseed.Reseeder) {
func reseedHTTP(c *cli.Context, reseeder *reseed.ReseederImpl) {
server := reseed.NewServer(c.String("prefix"), c.Bool("trustProxy"))
server.Reseeder = reseeder
server.Addr = net.JoinHostPort(c.String("ip"), c.String("port"))
@@ -428,7 +458,7 @@ func makeRandomHost(port int) (host.Host, error) {
return host, nil
}
func reseedP2P(c *cli.Context, reseeder reseed.Reseeder) {
func reseedP2P(c *cli.Context, reseeder *reseed.ReseederImpl) {
server := reseed.NewServer(c.String("prefix"), c.Bool("trustProxy"))
server.Reseeder = reseeder
server.Addr = net.JoinHostPort(c.String("ip"), c.String("port"))
@@ -466,7 +496,7 @@ func reseedP2P(c *cli.Context, reseeder reseed.Reseeder) {
}
}
func reseedOnion(c *cli.Context, onionTlsCert, onionTlsKey string, reseeder reseed.Reseeder) {
func reseedOnion(c *cli.Context, onionTlsCert, onionTlsKey string, reseeder *reseed.ReseederImpl) {
server := reseed.NewServer(c.String("prefix"), c.Bool("trustProxy"))
server.Reseeder = reseeder
server.Addr = net.JoinHostPort(c.String("ip"), c.String("port"))
@@ -541,7 +571,7 @@ func reseedOnion(c *cli.Context, onionTlsCert, onionTlsKey string, reseeder rese
log.Printf("Onion server started on %s\n", server.Addr)
}
func reseedI2P(c *cli.Context, i2pTlsCert, i2pTlsKey string, i2pIdentKey i2pkeys.I2PKeys, reseeder reseed.Reseeder) {
func reseedI2P(c *cli.Context, i2pTlsCert, i2pTlsKey string, i2pIdentKey i2pkeys.I2PKeys, reseeder *reseed.ReseederImpl) {
server := reseed.NewServer(c.String("prefix"), c.Bool("trustProxy"))
server.Reseeder = reseeder
server.Addr = net.JoinHostPort(c.String("ip"), c.String("port"))

View File

@@ -2,10 +2,12 @@ package cmd
import (
"bufio"
"crypto"
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"crypto/rsa"
"crypto/tls"
"crypto/x509"
"crypto/x509/pkix"
"encoding/asn1"
@@ -18,6 +20,13 @@ import (
"i2pgit.org/idk/reseed-tools/reseed"
"i2pgit.org/idk/reseed-tools/su3"
"github.com/go-acme/lego/v4/certcrypto"
"github.com/go-acme/lego/v4/certificate"
"github.com/go-acme/lego/v4/challenge/http01"
"github.com/go-acme/lego/v4/challenge/tlsalpn01"
"github.com/go-acme/lego/v4/lego"
"github.com/go-acme/lego/v4/registration"
)
func loadPrivateKey(path string) (*rsa.PrivateKey, error) {
@@ -35,6 +44,24 @@ func loadPrivateKey(path string) (*rsa.PrivateKey, error) {
return privKey, nil
}
// Taken directly from the lego example, since we need very minimal support
// https://go-acme.github.io/lego/usage/library/
type MyUser struct {
Email string
Registration *registration.Resource
key crypto.PrivateKey
}
func (u *MyUser) GetEmail() string {
return u.Email
}
func (u MyUser) GetRegistration() *registration.Resource {
return u.Registration
}
func (u *MyUser) GetPrivateKey() crypto.PrivateKey {
return u.key
}
func signerFile(signerID string) string {
return strings.Replace(signerID, "@", "_at_", 1)
}
@@ -60,6 +87,165 @@ func getOrNewSigningCert(signerKey *string, signerID string, auto bool) (*rsa.Pr
return loadPrivateKey(*signerKey)
}
func checkUseAcmeCert(tlsHost, signer, cadirurl string, tlsCert, tlsKey *string, auto bool) error {
_, certErr := os.Stat(*tlsCert)
_, keyErr := os.Stat(*tlsKey)
if certErr != nil || keyErr != nil {
if certErr != nil {
fmt.Printf("Unable to read TLS certificate '%s'\n", *tlsCert)
}
if keyErr != nil {
fmt.Printf("Unable to read TLS key '%s'\n", *tlsKey)
}
if !auto {
fmt.Printf("Would you like to generate a new certificate with Let's Encrypt or a custom ACME server? '%s'? (y or n): ", tlsHost)
reader := bufio.NewReader(os.Stdin)
input, _ := reader.ReadString('\n')
if []byte(input)[0] != 'y' {
fmt.Println("Continuing without TLS")
return nil
}
}
} else {
TLSConfig := &tls.Config{}
TLSConfig.NextProtos = []string{"http/1.1"}
TLSConfig.Certificates = make([]tls.Certificate, 1)
var err error
TLSConfig.Certificates[0], err = tls.LoadX509KeyPair(*tlsCert, *tlsKey)
if err != nil {
return err
}
if time.Now().Sub(TLSConfig.Certificates[0].Leaf.NotAfter) < (time.Hour * 48) {
ecder, err := ioutil.ReadFile(tlsHost + signer + ".acme.key")
if err != nil {
return err
}
privateKey, err := x509.ParseECPrivateKey(ecder)
if err != nil {
return err
}
user := MyUser{
Email: signer,
key: privateKey,
}
config := lego.NewConfig(&user)
config.CADirURL = cadirurl
config.Certificate.KeyType = certcrypto.RSA2048
client, err := lego.NewClient(config)
if err != nil {
return err
}
renewAcmeIssuedCert(client, user, tlsHost, tlsCert, tlsKey)
} else {
return nil
}
}
privateKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
if err != nil {
return err
}
ecder, err := x509.MarshalECPrivateKey(privateKey)
if err != nil {
return err
}
filename := tlsHost + signer + ".acme.key"
keypem, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
return err
}
defer keypem.Close()
err = pem.Encode(keypem, &pem.Block{Type: "EC PRIVATE KEY", Bytes: ecder})
if err != nil {
return err
}
user := MyUser{
Email: signer,
key: privateKey,
}
config := lego.NewConfig(&user)
config.CADirURL = cadirurl
config.Certificate.KeyType = certcrypto.RSA2048
client, err := lego.NewClient(config)
if err != nil {
return err
}
return newAcmeIssuedCert(client, user, tlsHost, tlsCert, tlsKey)
}
func renewAcmeIssuedCert(client *lego.Client, user MyUser, tlsHost string, tlsCert, tlsKey *string) error {
var err error
err = client.Challenge.SetHTTP01Provider(http01.NewProviderServer("", "8000"))
if err != nil {
return err
}
err = client.Challenge.SetTLSALPN01Provider(tlsalpn01.NewProviderServer("", "8443"))
if err != nil {
return err
}
// New users will need to register
if user.Registration, err = client.Registration.QueryRegistration(); err != nil {
reg, err := client.Registration.Register(registration.RegisterOptions{TermsOfServiceAgreed: true})
if err != nil {
return err
}
user.Registration = reg
}
resource, err := client.Certificate.Get(tlsHost, true)
if err != nil {
return err
}
certificates, err := client.Certificate.Renew(*resource, true, false, "")
if err != nil {
return err
}
ioutil.WriteFile(tlsHost+".pem", certificates.PrivateKey, 0600)
ioutil.WriteFile(tlsHost+".crt", certificates.Certificate, 0600)
// ioutil.WriteFile(tlsHost+".crl", certificates.PrivateKey, 0600)
*tlsCert = tlsHost + ".crt"
*tlsKey = tlsHost + ".pem"
return nil
}
func newAcmeIssuedCert(client *lego.Client, user MyUser, tlsHost string, tlsCert, tlsKey *string) error {
var err error
err = client.Challenge.SetHTTP01Provider(http01.NewProviderServer("", "8000"))
if err != nil {
return err
}
err = client.Challenge.SetTLSALPN01Provider(tlsalpn01.NewProviderServer("", "8443"))
if err != nil {
return err
}
// New users will need to register
if user.Registration, err = client.Registration.QueryRegistration(); err != nil {
reg, err := client.Registration.Register(registration.RegisterOptions{TermsOfServiceAgreed: true})
if err != nil {
return err
}
user.Registration = reg
}
request := certificate.ObtainRequest{
Domains: []string{tlsHost},
Bundle: true,
}
certificates, err := client.Certificate.Obtain(request)
if err != nil {
return err
}
ioutil.WriteFile(tlsHost+".pem", certificates.PrivateKey, 0600)
ioutil.WriteFile(tlsHost+".crt", certificates.Certificate, 0600)
// ioutil.WriteFile(tlsHost+".crl", certificates.PrivateKey, 0600)
*tlsCert = tlsHost + ".crt"
*tlsKey = tlsHost + ".pem"
return nil
}
func checkOrNewTLSCert(tlsHost string, tlsCert, tlsKey *string, auto bool) error {
_, certErr := os.Stat(*tlsCert)
_, keyErr := os.Stat(*tlsKey)
@@ -71,7 +257,7 @@ func checkOrNewTLSCert(tlsHost string, tlsCert, tlsKey *string, auto bool) error
fmt.Printf("Unable to read TLS key '%s'\n", *tlsKey)
}
if auto {
if !auto {
fmt.Printf("Would you like to generate a new self-signed certificate for '%s'? (y or n): ", tlsHost)
reader := bufio.NewReader(os.Stdin)
input, _ := reader.ReadString('\n')

10
content/index.html Normal file
View File

@@ -0,0 +1,10 @@
<h1 id="you-have-found-an-i2p-reseed">You have found an I2P Reseed</h1>
<p>Maybe it was by accident, or maybe you visited the URL because you saw it in the software somewhere. While weve got your attention, were going to take this opportunity to tell you a little about what we do here. I2P is a peer-to-peer network which uses “Garlic Routing” to maintain privacy. Reseed nodes help you get connected to I2P for the first time, and even though you should only have to use them once in a great while, they are very important services.</p>
<h2 id="to-learn-more-about-i2p-visit"><a href="https://geti2p.net">To learn more about I2P, visit</a></h2>
<p><a href="https://geti2p.net"><img src="images/reseed.png" alt="Help reseed" /></a></p>
<ul>
<li><a href="https://geti2p.net/en/docs/reseed">Learn more about reseeds here:</a></li>
<li><a href="https://geti2p.net/en/get-involved/guides/reseed">Learn how to run a reseed here:</a></li>
<li><a href="https://i2pgit.org/idk/reseed-tools">Read the reseed server code and learn about more reseed options here:</a></li>
</ul>
<p>Here on purpose? Heres a one-time link to a reseed bundle for you.</p>

View File

@@ -6,4 +6,13 @@ your attention, we're going to take this opportunity to tell you a little about
network which uses "Garlic Routing" to maintain privacy. Reseed nodes help you get connected to I2P for the first time,
and even though you should only have to use them once in a great while, they are very important services.
![Help reseed](images/reseed.png)
[To learn more about I2P, visit the project website](https://geti2p.net)
------------------------------------------------------------------------
[![Help reseed](images/reseed.png)](https://geti2p.net)
- [Learn more about reseeds here:](https://geti2p.net/en/docs/reseed)
- [Learn how to run a reseed here:](https://geti2p.net/en/get-involved/guides/reseed)
- [Read the reseed server code and learn about more reseed options here:](https://i2pgit.org/idk/reseed-tools)
### Here on purpose? Here's a one-time link to a reseed bundle for you.

View File

@@ -8,8 +8,30 @@ h1 {
}
img {
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
}
.inline {
display: inline;
}
.link-button {
background: none;
border: none;
color: blue;
text-decoration: underline;
cursor: pointer;
font-size: 1em;
font-family: serif;
}
.link-button:focus {
outline: none;
}
.link-button:active {
color:red;
}

View File

@@ -2,4 +2,4 @@
cp -r /var/lib/i2p/go/src/i2pgit.org/idk/reseed-tools/content ./content
/var/lib/i2p/go/src/i2pgit.org/idk/reseed-tools/i2p-tools-1 reseed --yes=true --netdb=/var/lib/i2p/i2p-config/netDb $@
/var/lib/i2p/go/src/i2pgit.org/idk/reseed-tools/reseed-tools reseed --yes=true --netdb=/var/lib/i2p/i2p-config/netDb $@

27
go.mod
View File

@@ -3,36 +3,17 @@ module i2pgit.org/idk/reseed-tools
go 1.13
require (
github.com/btcsuite/btcd v0.21.0-beta // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
github.com/cretz/bine v0.1.0
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
github.com/eyedeekay/ramp v0.0.0-20190429201811-305b382042ab // indirect
github.com/eyedeekay/sam3 v0.32.32
github.com/gomodule/redigo v1.8.3 // indirect
github.com/google/gopacket v1.1.19 // indirect
github.com/google/uuid v1.1.2 // indirect
github.com/go-acme/lego/v4 v4.3.1
github.com/gorilla/handlers v1.5.1
github.com/jackpal/gateway v1.0.6 // indirect
github.com/justinas/alice v1.2.0
github.com/koron/go-ssdp v0.0.2 // indirect
github.com/libp2p/go-libp2p v0.13.0
github.com/libp2p/go-libp2p-core v0.8.0
github.com/libp2p/go-libp2p-gostream v0.3.0
github.com/libp2p/go-libp2p-gostream v0.3.1
github.com/libp2p/go-libp2p-http v0.2.0
github.com/libp2p/go-libp2p-noise v0.1.2 // indirect
github.com/libp2p/go-netroute v0.1.4 // indirect
github.com/libp2p/go-sockaddr v0.1.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/throttled/throttled v2.2.4+incompatible
github.com/throttled/throttled/v2 v2.7.1
github.com/urfave/cli v1.22.5
gitlab.com/golang-commonmark/linkify v0.0.0-20200225224916-64bca66f6ad3 // indirect
gitlab.com/golang-commonmark/markdown v0.0.0-20191127184510-91b5b3c99c19
go.opencensus.io v0.22.5 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.16.0 // indirect
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad // indirect
golang.org/x/net v0.0.0-20201224014010-6772e930b67b // indirect
golang.org/x/sys v0.0.0-20201223074533-0d417f636930 // indirect
golang.org/x/text v0.3.4
golang.org/x/text v0.3.5
)

709
go.sum

File diff suppressed because it is too large Load Diff

View File

@@ -18,7 +18,7 @@ func main() {
runtime.GOMAXPROCS(runtime.NumCPU() / 2)
app := cli.NewApp()
app.Name = "i2p-tools-1"
app.Name = "reseed-tools"
app.Version = "0.1.7"
app.Usage = "I2P tools and reseed server"
app.Author = "eyedeekay"

View File

@@ -47,7 +47,7 @@ func ContentPath() (string, error) {
return filepath.Join(exPath, "content"), nil
}
func HandleARealBrowser(w http.ResponseWriter, r *http.Request) {
func (srv *Server) HandleARealBrowser(w http.ResponseWriter, r *http.Request) {
if ContentPathError != nil {
http.Error(w, "403 Forbidden", http.StatusForbidden)
return
@@ -73,6 +73,12 @@ func HandleARealBrowser(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html")
w.Write([]byte(header))
HandleALocalizedFile(w, base.String())
w.Write([]byte(`<ul><li><form method="post" action="/i2pseeds" class="inline">
<input type="hidden" name="onetime" value="` + srv.Acceptable() + `">
<button type="submit" name="submit_param" value="submit_value" class="link-button">
Bundle
</button>
</form></li></ul>`))
w.Write([]byte(footer))
}
}
@@ -116,6 +122,7 @@ func HandleALocalizedFile(w http.ResponseWriter, dirPath string) {
f = append(f, []byte(`<div id="`+trimmedName+`">`)...)
f = append(f, []byte(md.RenderToString(b))...)
f = append(f, []byte(`</div>`)...)
}
CachedLanguagePages[dirPath] = string(f)
w.Write([]byte(CachedLanguagePages[dirPath]))

View File

@@ -3,6 +3,7 @@ package reseed
import (
"bytes"
"context"
"crypto/rand"
"crypto/tls"
"io"
"log"
@@ -20,8 +21,8 @@ import (
"github.com/libp2p/go-libp2p-core/host"
gostream "github.com/libp2p/go-libp2p-gostream"
p2phttp "github.com/libp2p/go-libp2p-http"
"github.com/throttled/throttled"
"github.com/throttled/throttled/store"
throttled "github.com/throttled/throttled/v2"
"github.com/throttled/throttled/v2/store"
)
const (
@@ -34,9 +35,10 @@ type Server struct {
I2PSession *sam3.StreamSession
I2PListener *sam3.StreamListener
I2PKeys i2pkeys.I2PKeys
Reseeder Reseeder
Reseeder *ReseederImpl
Blacklist *Blacklist
OnionListener *tor.OnionService
acceptables map[string]time.Time
}
func NewServer(prefix string, trustProxy bool) *Server {
@@ -65,6 +67,7 @@ func NewServer(prefix string, trustProxy bool) *Server {
server := Server{Server: h, Reseeder: nil}
th := throttled.RateLimit(throttled.PerHour(4), &throttled.VaryBy{RemoteAddr: true}, store.NewMemStore(200000))
thw := throttled.RateLimit(throttled.PerHour(30), &throttled.VaryBy{RemoteAddr: true}, store.NewMemStore(200000))
middlewareChain := alice.New()
if trustProxy {
@@ -79,13 +82,85 @@ func NewServer(prefix string, trustProxy bool) *Server {
})
mux := http.NewServeMux()
mux.Handle("/", middlewareChain.Append(disableKeepAliveMiddleware, loggingMiddleware, browsingMiddleware).Then(errorHandler))
mux.Handle("/", middlewareChain.Append(disableKeepAliveMiddleware, loggingMiddleware, thw.Throttle, server.browsingMiddleware).Then(errorHandler))
mux.Handle(prefix+"/i2pseeds.su3", middlewareChain.Append(disableKeepAliveMiddleware, loggingMiddleware, verifyMiddleware, th.Throttle).Then(http.HandlerFunc(server.reseedHandler)))
server.Handler = mux
return &server
}
// See use of crypto/rand on:
// https://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-go
const (
letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" // 52 possibilities
letterIdxBits = 6 // 6 bits to represent 64 possibilities / indexes
letterIdxMask = 1<<letterIdxBits - 1 // All 1-bits, as many as letterIdxBits
)
func SecureRandomAlphaString() string {
length := 16
result := make([]byte, length)
bufferSize := int(float64(length) * 1.3)
for i, j, randomBytes := 0, 0, []byte{}; i < length; j++ {
if j%bufferSize == 0 {
randomBytes = SecureRandomBytes(bufferSize)
}
if idx := int(randomBytes[j%length] & letterIdxMask); idx < len(letterBytes) {
result[i] = letterBytes[idx]
i++
}
}
return string(result)
}
// SecureRandomBytes returns the requested number of bytes using crypto/rand
func SecureRandomBytes(length int) []byte {
var randomBytes = make([]byte, length)
_, err := rand.Read(randomBytes)
if err != nil {
log.Fatal("Unable to generate random bytes")
}
return randomBytes
}
//
func (srv *Server) Acceptable() string {
if srv.acceptables == nil {
srv.acceptables = make(map[string]time.Time)
}
if len(srv.acceptables) > 50 {
for val := range srv.acceptables {
srv.CheckAcceptable(val)
}
for val := range srv.acceptables {
if len(srv.acceptables) < 50 {
break
}
delete(srv.acceptables, val)
}
}
acceptme := SecureRandomAlphaString()
srv.acceptables[acceptme] = time.Now()
return acceptme
}
func (srv *Server) CheckAcceptable(val string) bool {
if srv.acceptables == nil {
srv.acceptables = make(map[string]time.Time)
}
if timeout, ok := srv.acceptables[val]; ok {
checktime := time.Now().Sub(timeout)
if checktime > (4 * time.Minute) {
delete(srv.acceptables, val)
return false
}
delete(srv.acceptables, val)
return true
}
return false
}
func (srv *Server) ListenAndServe() error {
addr := srv.Addr
if addr == "" {
@@ -245,7 +320,7 @@ func (srv *Server) ListenAndServeI2P(samaddr string, I2PKeys i2pkeys.I2PKeys) er
if err != nil {
return err
}
log.Printf("I2P server started on http://%v.onion\n", srv.OnionListener.ID)
log.Printf("I2P server started on http://%v.b32.i2p\n", srv.I2PListener.Addr().(i2pkeys.I2PAddr).Base32())
return srv.Serve(srv.I2PListener)
}
@@ -291,10 +366,13 @@ func loggingMiddleware(next http.Handler) http.Handler {
return handlers.CombinedLoggingHandler(os.Stdout, next)
}
func browsingMiddleware(next http.Handler) http.Handler {
func (srv *Server) browsingMiddleware(next http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
if srv.CheckAcceptable(r.FormValue("onetime")) {
srv.reseedHandler(w, r)
}
if i2pUserAgent != r.UserAgent() {
HandleARealBrowser(w, r)
srv.HandleARealBrowser(w, r)
return
}
next.ServeHTTP(w, r)

View File

@@ -33,13 +33,13 @@ func (p Peer) Hash() int {
return int(crc32.ChecksumIEEE(c))
}
type Reseeder interface {
/*type Reseeder interface {
// get an su3 file (bytes) for a peer
PeerSu3Bytes(peer Peer) ([]byte, error)
}
}*/
type ReseederImpl struct {
netdb NetDbProvider
netdb *LocalNetDbImpl
su3s chan [][]byte
SigningKey *rsa.PrivateKey
@@ -49,7 +49,7 @@ type ReseederImpl struct {
NumSu3 int
}
func NewReseeder(netdb NetDbProvider) *ReseederImpl {
func NewReseeder(netdb *LocalNetDbImpl) *ReseederImpl {
return &ReseederImpl{
netdb: netdb,
su3s: make(chan [][]byte),
@@ -224,10 +224,10 @@ func (rs *ReseederImpl) createSu3(seeds []routerInfo) (*su3.File, error) {
return su3File, nil
}
type NetDbProvider interface {
/*type NetDbProvider interface {
// Get all router infos
RouterInfos() ([]routerInfo, error)
}
}*/
type LocalNetDbImpl struct {
Path string

View File

@@ -23,16 +23,20 @@ const (
SigTypeRSAWithSHA384 = uint16(5)
SigTypeRSAWithSHA512 = uint16(6)
ContentTypeUnknown = uint8(0)
ContentTypeRouter = uint8(1)
ContentTypePlugin = uint8(2)
ContentTypeReseed = uint8(3)
ContentTypeNews = uint8(4)
ContentTypeUnknown = uint8(0)
ContentTypeRouter = uint8(1)
ContentTypePlugin = uint8(2)
ContentTypeReseed = uint8(3)
ContentTypeNews = uint8(4)
ContentTypeBlocklist = uint8(5)
FileTypeZIP = uint8(0)
FileTypeXML = uint8(1)
FileTypeHTML = uint8(2)
FileTypeXMLGZ = uint8(3)
FileTypeTXTGZ = uint8(4)
FileTypeDMG = uint8(5)
FileTypeEXE = uint8(6)
magicBytes = "I2Psu3"
)