config, register: gofmt and make sure secret is 32 bytes

This commit is contained in:
Iris Lightshard 2023-07-10 22:41:23 -06:00
parent e7caa27a35
commit faccff3fb2
2 changed files with 37 additions and 28 deletions

View file

@ -83,13 +83,23 @@ func (self *Config) RunWizard() {
self.UploadMaxMB = ensureNumberOption(&inputBuf)
fmt.Printf("Encryption secret for admin invite codes? ")
ensureNonEmptyOption(&inputBuf)
ensure32BytePassphrase(&inputBuf)
self.RegistrationSecret = inputBuf
fmt.Printf("Configuration complete!\n")
self.Write()
}
func ensure32BytePassphrase(buffer *string) {
for {
fmt.Scanln(buffer)
if len([]byte(strings.TrimSpace(*buffer))) == 32 {
break
}
fmt.Println("Please enter a 32-byte string")
}
}
func ensureNonEmptyOption(buffer *string) {
for {
fmt.Scanln(buffer)

View file

@ -4,12 +4,11 @@ import (
"crypto/aes"
"crypto/cipher"
"encoding/hex"
"fmt"
"html/template"
"net/http"
"time"
"strconv"
"fmt"
"time"
"hacklab.nilfm.cc/quartzgun/auth"
"hacklab.nilfm.cc/quartzgun/renderer"
@ -84,7 +83,7 @@ func (self *SymmetricCrypt) Decrypt(text string) (string, error) {
func WithCrypto(next http.Handler, crypto SymmetricCrypto) http.Handler {
handlerFunc := func(w http.ResponseWriter, req *http.Request) {
util.AddContextValue(req, "crypto", crypto);
util.AddContextValue(req, "crypto", crypto)
next.ServeHTTP(w, req)
}
@ -101,7 +100,7 @@ func WithUserStoreAndCrypto(next http.Handler, udb auth.UserStore, crypto Symmet
if crypto.IsValid(cipher) && len(username) > 0 && len(password) > 0 {
success = udb.AddUser(username, password) == nil
}
util.AddContextValue(req, "success", success);
util.AddContextValue(req, "success", success)
next.ServeHTTP(w, req)
}