config, register: gofmt and make sure secret is 32 bytes
This commit is contained in:
parent
e7caa27a35
commit
faccff3fb2
2 changed files with 37 additions and 28 deletions
|
@ -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)
|
||||
|
|
|
@ -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"
|
||||
|
@ -29,8 +28,8 @@ type SymmetricCrypt struct {
|
|||
Secret string
|
||||
}
|
||||
|
||||
var iv []byte = []byte {107, 53, 46, 249, 52, 70, 36, 185,
|
||||
168, 139, 144, 249, 242, 2, 125, 183 }
|
||||
var iv []byte = []byte{107, 53, 46, 249, 52, 70, 36, 185,
|
||||
168, 139, 144, 249, 242, 2, 125, 183}
|
||||
|
||||
func (self *SymmetricCrypt) IsValid(cipher string) bool {
|
||||
stringTimestamp, err := self.Decrypt(cipher)
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue