Read public GPG key from file

This commit is contained in:
clerie 2024-11-24 17:34:12 +01:00
parent 58e99d6dae
commit cd6b508436
2 changed files with 28 additions and 120 deletions

View File

@ -11,6 +11,8 @@
Username for login (default "admin")
-pass string
Password for login (default "123456")
-gpgkey path
File of the public GPG key to encrypt files to
```

146
main.go
View File

@ -13,6 +13,7 @@ import (
)
type ForwarderDriver struct {
RecipientKey *crypto.Key
server.Perm
}
@ -106,125 +107,9 @@ func (driver *ForwarderDriver) PutFile(destPath string, data io.Reader, appendDa
return 0, err
}
pubkey := `-----BEGIN PGP PUBLIC KEY BLOCK-----
mQINBGYdTGwBEACj6qML9iydxEqXWNGakFTRaNNf+a7PBGSF6N4S21zJ3KOIENJH
NR5Rid6iKSa9j/z3eC2mqgxeSrQBlZ5jGp1yTaa83hdQFiB/XWEg7xR6XNRsoHSk
DohvzWB2RjAAd/QlQfLELjOXXSZQxBoPemt2nDpJTW6oC1BXZgaiezdxQhPDrakI
eGI/Ge1vMCyv3XBKdcSv9jIAeiEGK9/GLJ/rTUj5Pe3ie2GRdHifvwTdyXEc3pAo
TAmQo+xY5tchJFY7G4jhkel+tkhofb3+TSNZ1bqhJcidlk4DYwLhuY8D2Pdj7eye
652cJc69swWlb/id7lPuoMib1BgNAN4uH2qSNrEyFgi8YpuBQAR7kLDLO4roFNk1
gyT/1knxmKiF6VGJy5vxFFTzs6qL2UEBeD05gJLbGNwseg9d/rEMXtsMd+07S7Rr
ZNIX9nxX2rqmNLgpZndjXn0ZsggF045vR9zVGVNePRoeTUu9uu0qXhOc7V0o27Qp
afX/tI2BWWSd6wUt+5znDPvapOAnhWomEFnDzD66ApVNPQf6QT9lYmwrGWZlw+ht
I2/YUMGxaeYG9auSCvq9wSysr/3BbCxUyUt8mUeSBDvIG3Bf8CRftd7XeYuIMtkd
xA5+7m9uZD+aszq12gCve+8ZPEsIUXXWGiAAGOfXVfoqKftySmaQUMCdtwARAQAB
tBljbGVyaWUgPGNsZXJpZUBjbGVyaWUuZGU+iQJX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xI9TnRa3ZQrHLbUAEmW/MgmV5QuHrDq1/cJzFe6+fCPXhYH8qrYnvGEgiat6
B2Qh6aRJpZrN2EVxw4piUTqBuNXmQCE0jrmeNfTYLjFFjinjyUGCjUJilBA+UzC0
fXyex0Se4ayfrhAG7vidSbAYAiUwQpRP4N+AVORpYb0IqnRvo0ScPEUMmelzKWFK
j4awEUvw5qC5s74WsUa2QdPecj6KmRQNKjupJdQVmEMYy5nXfM6yKBfbX8C8e2Vm
iif/zu1p6tQAI9s1nFwbmexzmmXOWq+t1KNj+/8ZthtE2Jhy8iGSCbpMjkF3Diq6
AU0O/9ReszcRBHJWavGta8Vfhs9YG2XJjt0JZvGQNjs3kJ0apLLUpJfh1s0Ez5sh
y7vmqlcrC9y86RrfGTOL7OeO30a8CVfGEZi5ut2EqmWKk9s6RwCAqxNn89XU4rCD
weGu/A/SRFy/KKzKhiY4pZCwUzDpslmlNelEWDXwOJmIfO0IbPWIb8yoZZpvYMWR
3oWqqWmw/IR/6xS7sKoKo3A6PVQRzWeLmywRjjfPlkMg5lE60zn6jdL+dyEXBfip
eioP7bhmesMcSxs89lJr6bJ6+gWm4/JJUOJgUFWUbZsjTb8iPITi+UJa1DWmesN0
cnkT
=NbZJ
-----END PGP PUBLIC KEY BLOCK-----`
log.Printf("NewKeyFromArmored…")
publicKey, err := crypto.NewKeyFromArmored(pubkey)
if err != nil {
log.Printf("Error: %v", err)
return 0, err
}
log.Printf("crypto.PGP…")
pgp := crypto.PGP()
encHandle, err := pgp.Encryption().Recipient(publicKey).New()
encHandle, err := pgp.Encryption().Recipient(driver.RecipientKey).New()
if err != nil {
log.Printf("Error: %v", err)
return 0, err
@ -250,11 +135,12 @@ cnkT
}
type ForwarderDriverFactory struct {
RecipientKey *crypto.Key
server.Perm
}
func (factory *ForwarderDriverFactory) NewDriver() (server.Driver, error) {
return &ForwarderDriver{factory.Perm}, nil
return &ForwarderDriver{factory.RecipientKey, factory.Perm}, nil
}
@ -266,10 +152,30 @@ func main() {
port = flag.Int("port", 2121, "Port")
host = flag.String("host", "localhost", "Host")
passiveports = flag.String("passiveports", "2130-2134", "Passive ports")
gpgkey_path = flag.String("gpgkey", "", "File of the public GPG key to encrypt files to")
)
flag.Parse()
if *gpgkey_path == "" {
log.Fatalf("Specify path to GPG key with -gpgkey")
}
factory := &ForwarderDriverFactory{Perm: server.NewSimplePerm("user","group")}
gpgkey_file, err := os.Open(*gpgkey_path)
if err != nil {
log.Fatalf("Error: %v", err)
}
gpgkey, err := crypto.NewKeyFromReader(gpgkey_file)
if err != nil {
log.Fatalf("Error: %v", err)
}
factory := &ForwarderDriverFactory{
RecipientKey: gpgkey,
Perm: server.NewSimplePerm("user","group"),
}
opts := &server.ServerOpts{
Factory: factory,
@ -282,7 +188,7 @@ func main() {
log.Printf("Starting ftp server on %v:%v", opts.Hostname, opts.Port)
log.Printf("Username %v, Password %v", *user, *pass)
server := server.NewServer(opts)
err := server.ListenAndServe()
server.ListenAndServe()
if err != nil {
log.Fatal("Error starting server:", err)
}