aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorGabriel A. Giovanini <mail@gabrielgio.me>2024-10-05 15:32:53 +0200
committerGabriel A. Giovanini <mail@gabrielgio.me>2024-10-05 15:32:53 +0200
commit5fb240326bba79f6963f5d042dea824cdb9e8e45 (patch)
treeb1e35fbefd8e8e023e3250fbec3cebaaa0b80d93 /main.go
parenta36e98b8ae350eed0e9cde2ffeea0626c0f570c5 (diff)
downloadcerrado-5fb240326bba79f6963f5d042dea824cdb9e8e45.tar.gz
cerrado-5fb240326bba79f6963f5d042dea824cdb9e8e45.tar.bz2
cerrado-5fb240326bba79f6963f5d042dea824cdb9e8e45.zip
feat: Add command to generate hash and aes key
This makes easier for an user to setup those value later.
Diffstat (limited to 'main.go')
-rw-r--r--main.go28
1 files changed, 26 insertions, 2 deletions
diff --git a/main.go b/main.go
index b891c88..8bf5141 100644
--- a/main.go
+++ b/main.go
@@ -2,6 +2,8 @@ package main
import (
"context"
+ "crypto/rand"
+ "encoding/base64"
"flag"
"fmt"
"log/slog"
@@ -24,14 +26,23 @@ func main() {
if len(os.Args) == 4 && os.Args[1] == "hash" {
err := hash(os.Args[2], os.Args[3])
if err != nil {
- slog.Error("Error", "error", err)
+ slog.Error("Hash", "error", err)
+ os.Exit(1)
+ }
+ return
+ }
+
+ if len(os.Args) == 2 && os.Args[1] == "key" {
+ err := key()
+ if err != nil {
+ slog.Error("Key", "error", err)
os.Exit(1)
}
return
}
if err := run(ctx); err != nil {
- slog.Error("Error", "error", err)
+ slog.Error("Server", "error", err)
os.Exit(1)
}
}
@@ -46,6 +57,19 @@ func hash(username string, password string) error {
return nil
}
+func key() error {
+ key := make([]byte, 64)
+
+ _, err := rand.Read(key)
+ if err != nil {
+ return err
+ }
+
+ en := base64.StdEncoding.EncodeToString(key)
+ fmt.Println(en)
+ return nil
+}
+
func run(ctx context.Context) error {
var (
configPath = flag.String("config", "/etc/cerrado.scfg", "File path for the configuration file")