From f572419fcf5edc9f2e10641e45f295ee60ac2097 Mon Sep 17 00:00:00 2001 From: Lukasz Janyst Date: Sun, 2 Jan 2022 15:06:19 +0100 Subject: [PATCH] peroxide-user: Implement credential key generation --- cmd/peroxide-user/main.go | 51 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 cmd/peroxide-user/main.go diff --git a/cmd/peroxide-user/main.go b/cmd/peroxide-user/main.go new file mode 100644 index 0000000..8115133 --- /dev/null +++ b/cmd/peroxide-user/main.go @@ -0,0 +1,51 @@ +// Copyright (c) 2022 Lukasz Janyst +// +// This file is part of Peroxide. +// +// Peroxide is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Peroxide is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Peroxide. If not, see . + +package main + +import ( + "crypto/rand" + "encoding/base64" + "flag" + "fmt" + "io" + "os" +) + +var genKey = flag.Bool("gen-key", false, "generate a random key for the encryption of credentials") + +func main() { + flag.Parse() + done := false + + if *genKey { + var key [32]byte + if _, err := io.ReadFull(rand.Reader, key[:]); err != nil { + fmt.Fprintf(os.Stderr, "Can't read random bytes: %s:\n", err) + os.Exit(1) + } + password := base64.StdEncoding.EncodeToString(key[:]) + fmt.Println(password) + done = true + } + + if !done { + fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0]) + flag.PrintDefaults() + os.Exit(1) + } +}