work on actually improving the save/load keys system

This commit is contained in:
idk
2019-02-09 13:41:53 -05:00
parent d134080415
commit 148ef4096c
7 changed files with 87 additions and 13 deletions

View File

@ -75,6 +75,7 @@ deps:
go get -u github.com/eyedeekay/sam-forwarder/config
go get -u github.com/eyedeekay/sam-forwarder/manager
go get -u github.com/eyedeekay/sam3
go get -u github.com/eyedeekay/littleboss
go get -u github.com/eyedeekay/samcatd-web
mine:
@ -85,11 +86,12 @@ webdep:
build: clean bin/$(appname)
install: bin/$(appname) bin/$(samcatd) bin/$(samcatd)-web
install:
install -m755 ./bin/$(appname) $(PREFIX)$(USR)$(LOCAL)/bin/
install -m755 ./bin/$(samcatd) $(PREFIX)$(USR)$(LOCAL)/bin/
install -m755 ./bin/$(samcatd)-web $(PREFIX)$(USR)$(LOCAL)/bin/
install -m644 ./etc/init.d/samcatd $(PREFIX)$(ETC)/init.d
mkdir -p $(PREFIX)$(ETC)/samcatd/ $(PREFIX)$(ETC)/sam-forwarder/ $(PREFIX)$(ETC)/i2pvpn/
install -m644 ./etc/samcatd/tunnels.ini $(PREFIX)$(ETC)/samcatd/
install -m644 ./etc/sam-forwarder/tunnels.ini $(PREFIX)$(ETC)/sam-forwarder/
install -m644 ./etc/i2pvpn/i2pvpn.ini $(PREFIX)$(ETC)/i2pvpn/
@ -123,7 +125,7 @@ bin/$(samcatd)-web:
-o ./bin/$(samcatd)-web \
./daemon/*.go
all: daemon build server
all: daemon daemon-web build server
clean-all: clean clean-server clean-daemon clean-daemon-web

View File

@ -75,6 +75,8 @@ CAP\_NET\_BIND\_SERVICE or something. This might work:
But I need to learn more about capabilities before I make that part of the
thing.
Some kind of reverse-proxy or filter is also an obvious choice.
I've only enabled the use of a subset of the i2cp and tunnel configuration
options, the ones I use the most and for no other real reason assume other
people use the most. They're pretty easy to add, it's just boring. *If you*
@ -104,6 +106,8 @@ in a different repo though. This is looking a little cluttered.
TLS configuration is experimental.
I've made it self-supervising, but I need to make better use of contexts.
## Stuff that's using it:
Mostly mine, but this is all Free-as-in-Freedom for anyone to use:

View File

@ -78,6 +78,8 @@ CAP\_NET\_BIND\_SERVICE or something. This might work:
But I need to learn more about capabilities before I make that part of the
thing.
Some kind of reverse-proxy or filter is also an obvious choice.
I've only enabled the use of a subset of the i2cp and tunnel configuration
options, the ones I use the most and for no other real reason assume other
people use the most. They're pretty easy to add, it's just boring. *If you*
@ -107,6 +109,8 @@ in a different repo though. This is looking a little cluttered.
TLS configuration is experimental.
I've made it self-supervising, but I need to make better use of contexts.
## Stuff that's using it:
Mostly mine, but this is all Free-as-in-Freedom for anyone to use:
@ -127,12 +131,12 @@ Donate
BTC:159M8MEUwhTzE9RXmcZxtigKaEjgfwRbHt
-----BEGIN PGP SIGNATURE-----
iQEzBAEBCgAdFiEEcNIGBzi++AUjrK/311wDs5teFOEFAlxNQywACgkQ11wDs5te
FOFPJggAqU5vcYfIivUX5aZyRZ4qEXJQ3T9vrlEVC46S6oKUzJI+AZEYzAAY2Bul
qz0bA/Jpa/iA2uqLDKSsDQNMw8ytruBRlbB75j8ya+jdNTfsnu6S5eitVWD0y5iQ
3iXXd7J88GpAePSNiNxx/QnPM0TA8pAANhRxIHUseSEBqigmdTrY/Nw8ehzqH4vR
B0OINqE5M/jqhu7Nwu7/677ptuDE4FHvHRxkun1JBqFVS4/s8/RnsTxDhHLy6GRK
UjdLOSUScI74DFQ9mVzxm8qGklomixbqXbcuDmiSXxLCcBgFWR2RPG09Shi4J8La
9tBWN2IAeCqiX9l2SLhQTud2AO4WcQ==
=sGca
iQEzBAEBCgAdFiEEcNIGBzi++AUjrK/311wDs5teFOEFAlxfHusACgkQ11wDs5te
FOFU3Af/cJOaCkvHxf9HyvevCFyfIEUyQ79fQ0vtBWeA5bnQQ861NU5WBSGn5j+1
9d32EQj5Ct5rc1+/uhBA/CB6Sy83No32KDj28x7DcxLTH+XTg7ucSg0Wurc1d6hI
jWncRpjSGAQ4HOmzejesM1/7SbdrI9B4IiZpPJQ7INsI7+V1RmmcQx/iR0dnNJLV
IlxNdGH/907vcX22vTg2/41t+Pxd9c4gEi0HG2GVkWYHFgdTgBdylsa5DQeoWVp3
IiLB5wbwz/X+nnlc3ddbeDQTQ3mz6jvswm9BYdi6EP8o/weheRgrvyyoIaDWwiEc
a6x1q6qaPNiovx1Ax460/ubfSF0LhQ==
=4hVu
-----END PGP SIGNATURE-----

View File

@ -6,12 +6,14 @@ import (
"os"
"os/signal"
"strings"
"context"
)
import (
"github.com/eyedeekay/sam-forwarder/config"
"github.com/eyedeekay/sam-forwarder/manager"
"github.com/eyedeekay/samcatd-web"
"github.com/eyedeekay/littleboss"
)
type flagOpts []string
@ -132,6 +134,14 @@ var (
)
func main() {
lb := littleboss.New("service-name")
lb.Run(func(ctx context.Context) {
lbMain(ctx)
})
}
func lbMain(ctx context.Context) {
flag.Var(&accessList, "accesslist", "Specify an access list member(can be used multiple times)")
flag.Parse()
@ -205,4 +215,5 @@ func main() {
} else {
log.Fatal(err)
}
ctx.Done()
}

View File

@ -397,6 +397,9 @@ func NewSAMForwarderFromOptions(opts ...func(*SAMForwarder) error) (*SAMForwarde
return nil, err
}
log.Println("SAM Bridge connection established.")
//if s.SamKeys, err = i2pkeys.Load(s.FilePath, s.TunName, s.passfile, s.samConn); err != nil {
//return nil, err
//}
if s.SamKeys, err = s.samConn.NewKeys(); err != nil {
return nil, err
}

View File

@ -1,11 +1,12 @@
package i2pkeys
import (
"github.com/eyedeekay/sam3"
"github.com/gtank/cryptopasta"
"io/ioutil"
"io/ioutil"
"os"
"path/filepath"
"github.com/eyedeekay/sam3"
"github.com/gtank/cryptopasta"
)
func bytes(k [32]byte) []byte {
@ -106,3 +107,26 @@ func Save(FilePath, TunName, passfile string, SamKeys *sam3.I2PKeys) error {
}
return nil
}
func Load(FilePath, TunName, passfile string, samConn *sam3.SAM) (*sam3.I2PKeys, error) {
if _, err := os.Stat(filepath.Join(FilePath, TunName+".i2pkeys")); os.IsNotExist(err) {
SamKeys, err := samConn.NewKeys()
if err != nil {
return nil, err
}
return &SamKeys, nil
}
file, err := os.Open(filepath.Join(FilePath, TunName+".i2pkeys"))
if err != nil {
return nil, err
}
err = Decrypt(filepath.Join(FilePath, TunName+".i2pkeys"), passfile)
if err != nil {
return nil, err
}
SamKeys, err := sam3.LoadKeysIncompat(file)
if err != nil {
return nil, err
}
return &SamKeys, nil
}

26
i2pkeys/common_test.go Normal file
View File

@ -0,0 +1,26 @@
package i2pkeys
import (
//"os"
"log"
"testing"
//"path/filepath"
"github.com/eyedeekay/sam3"
)
func TestKeysGenLoad(t *testing.T) {
sc, err := sam3.NewSAM("127.0.0.1:7656")
if err != nil {
t.Fatal(err)
}
log.Println("Initialized SAM connection")
sk, err := Load("./", "test", "", sc)
if err != nil {
t.Fatal(err)
}
err = Save("./", "test", "", sk)
if err != nil {
t.Fatal(err)
}
}