encode registration key on command line
This commit is contained in:
parent
952f80dbc2
commit
b7888158b8
4 changed files with 27 additions and 9 deletions
18
cmd/cmd.go
18
cmd/cmd.go
|
@ -1,16 +1,28 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
_ "fmt"
|
"fmt"
|
||||||
|
"hacklab.nilfm.cc/felt/register"
|
||||||
"hacklab.nilfm.cc/quartzgun/auth"
|
"hacklab.nilfm.cc/quartzgun/auth"
|
||||||
_ "strings"
|
"strconv"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ProcessCmd(args []string, userStore auth.UserStore) bool {
|
func ProcessCmd(args []string, userStore auth.UserStore, crypto register.SymmetricCrypto) bool {
|
||||||
if len(args) == 1 {
|
if len(args) == 1 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
switch args[1] {
|
switch args[1] {
|
||||||
|
case "register":
|
||||||
|
now := time.Now().UnixMicro()
|
||||||
|
strNow := strconv.FormatInt(now, 10)
|
||||||
|
self, err := crypto.Encrypt(strNow)
|
||||||
|
if err == nil {
|
||||||
|
fmt.Print("This is the registration key: ")
|
||||||
|
fmt.Println(self)
|
||||||
|
} else {
|
||||||
|
fmt.Printf("%v\n", err)
|
||||||
|
}
|
||||||
case "adduser":
|
case "adduser":
|
||||||
if len(args) < 4 {
|
if len(args) < 4 {
|
||||||
return help()
|
return help()
|
||||||
|
|
|
@ -174,6 +174,8 @@ func parseConfig(configFile string) *Config {
|
||||||
k := strings.TrimSpace(kvp[0])
|
k := strings.TrimSpace(kvp[0])
|
||||||
v := strings.TrimSpace(kvp[1])
|
v := strings.TrimSpace(kvp[1])
|
||||||
switch k {
|
switch k {
|
||||||
|
case "registrationSecret":
|
||||||
|
cfg.RegistrationSecret = v
|
||||||
case "mongoURI":
|
case "mongoURI":
|
||||||
cfg.MongoURI = v
|
cfg.MongoURI = v
|
||||||
case "uploads":
|
case "uploads":
|
||||||
|
|
4
main.go
4
main.go
|
@ -6,6 +6,7 @@ import (
|
||||||
"hacklab.nilfm.cc/felt/config"
|
"hacklab.nilfm.cc/felt/config"
|
||||||
"hacklab.nilfm.cc/felt/gametable"
|
"hacklab.nilfm.cc/felt/gametable"
|
||||||
"hacklab.nilfm.cc/felt/mongodb"
|
"hacklab.nilfm.cc/felt/mongodb"
|
||||||
|
"hacklab.nilfm.cc/felt/register"
|
||||||
"hacklab.nilfm.cc/quartzgun/indentalUserDB"
|
"hacklab.nilfm.cc/quartzgun/indentalUserDB"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
|
@ -33,7 +34,8 @@ func run() error {
|
||||||
udb := indentalUserDB.CreateIndentalUserDB(
|
udb := indentalUserDB.CreateIndentalUserDB(
|
||||||
filepath.Join(config.GetConfigLocation(), "user.db"))
|
filepath.Join(config.GetConfigLocation(), "user.db"))
|
||||||
|
|
||||||
if cmd.ProcessCmd(os.Args, udb) {
|
crypto := ®ister.SymmetricCrypt{Secret: cfg.RegistrationSecret}
|
||||||
|
if cmd.ProcessCmd(os.Args, udb, crypto) {
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/aes"
|
"crypto/aes"
|
||||||
"crypto/cipher"
|
"crypto/cipher"
|
||||||
"encoding/base64"
|
"encoding/hex"
|
||||||
"html/template"
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ import (
|
||||||
"hacklab.nilfm.cc/quartzgun/router"
|
"hacklab.nilfm.cc/quartzgun/router"
|
||||||
)
|
)
|
||||||
|
|
||||||
var bytes = []byte{99, 207, 33, 57, 28, 01, 50, 76, 01}
|
var bytes = []byte{99, 207, 33, 57, 28, 01, 50, 76, 01, 92, 33, 10, 48, 07, 00, 250}
|
||||||
|
|
||||||
type SymmetricCrypto interface {
|
type SymmetricCrypto interface {
|
||||||
Encode(b []byte) string
|
Encode(b []byte) string
|
||||||
|
@ -27,11 +27,11 @@ type SymmetricCrypt struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *SymmetricCrypt) Encode(b []byte) string {
|
func (self *SymmetricCrypt) Encode(b []byte) string {
|
||||||
return base64.StdEncoding.EncodeToString(b)
|
return hex.EncodeToString(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *SymmetricCrypt) Decode(s string) []byte {
|
func (self *SymmetricCrypt) Decode(s string) []byte {
|
||||||
data, err := base64.StdEncoding.DecodeString(s)
|
data, err := hex.DecodeString(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,9 @@ func (self *SymmetricCrypt) Decrypt(text string) (string, error) {
|
||||||
|
|
||||||
func WithCrypto(next http.Handler, crypto SymmetricCrypto) http.Handler {
|
func WithCrypto(next http.Handler, crypto SymmetricCrypto) http.Handler {
|
||||||
handlerFunc := func(w http.ResponseWriter, req *http.Request) {
|
handlerFunc := func(w http.ResponseWriter, req *http.Request) {
|
||||||
*req = *req.WithContext(context.WithValue(req.Context(), "crypto", crypto))
|
//urlParams := req.Context().Value("params").(map[string]string)
|
||||||
|
//cipher := urlParams["cipher"]
|
||||||
|
|
||||||
next.ServeHTTP(w, req)
|
next.ServeHTTP(w, req)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue