commit a23141ba64eca8630f037ef592753fe292b7e331
parent 3227d99e8d14d56e88f07355c04fc1618c4a9cbf
Author: Martin Schanzenbach <mschanzenbach@posteo.de>
Date: Tue, 19 Apr 2022 15:26:34 +0200
Add salt from configuration; fix bug where config is not used
Diffstat:
2 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/config.json b/config.json
@@ -3,5 +3,7 @@
"db_backend": "sqlite",
"validators": ["email","phone"],
"email_sender": "taldir@taler.net",
- "host": "https://taldir.net/"
+ "host": "https://taldir.net/",
+ "bind_to": "localhost:10000",
+ "salt": "ChangeMe"
}
diff --git a/taldir.go b/taldir.go
@@ -23,6 +23,7 @@ type Configuration struct {
EmailSender string `json:"email_sender"`
Salt string `json:"salt"`
Host string `json:"host"`
+ BindTo string `json:"bind_to"`
}
// A mappind entry from the identity key hash to a wallet key
@@ -96,8 +97,9 @@ func returnSingleEntry(w http.ResponseWriter, r *http.Request){
// Hashes an identity key (e.g. sha256(<email address>)) with a salt for
// Lookup and storage.
func hashIdentityKey(idkey string) string {
- salt := make([]byte, len(config.Salt))
- return base32.StdEncoding.EncodeToString(argon2.IDKey([]byte(idkey), salt, 1, 64*1024, 4, 32))
+ fmt.Println("Using salt " + config.Salt)
+ salt := make([]byte, len(config.Salt))
+ return base32.StdEncoding.EncodeToString(argon2.IDKey([]byte(idkey), salt, 1, 64*1024, 4, 32))
}
// Called by the registrant to validate the registration request. The reference ID was
@@ -136,12 +138,12 @@ func validateSingleEntry(w http.ResponseWriter, r *http.Request){
// Generates random reference token used in the validation flow.
func generateToken() string {
- randBytes := make([]byte, 32)
- _, err := rand.Read(randBytes)
- if err != nil {
- panic(err)
- }
- return base32.StdEncoding.EncodeToString(randBytes)
+ randBytes := make([]byte, 32)
+ _, err := rand.Read(randBytes)
+ if err != nil {
+ panic(err)
+ }
+ return base32.StdEncoding.EncodeToString(randBytes)
}
// Initiate a registration request for an identity
@@ -196,14 +198,15 @@ func handleRequests() {
myRouter.HandleFunc("/directory/{identity_key}", returnSingleEntry).Methods("GET")
myRouter.HandleFunc("/validation/{reference}", validateSingleEntry).Methods("GET")
myRouter.HandleFunc("/register/{identity}", addPendingValidation).Methods("POST")
- log.Fatal(http.ListenAndServe(":10000", myRouter))
+ fmt.Println("Listening on " + config.BindTo)
+ log.Fatal(http.ListenAndServe(config.BindTo, myRouter))
}
func main() {
file, _ := os.Open("config.json")
defer file.Close()
decoder := json.NewDecoder(file)
- config := Configuration{}
+ config = Configuration{}
err := decoder.Decode(&config)
if err != nil {
fmt.Println("error:", err)
@@ -212,6 +215,7 @@ func main() {
fmt.Println("Production mode enabled")
}
validators = make(map[string]bool)
+ fmt.Println(config.BindTo)
fmt.Println("Enabled validators:", config.Validators)
for _, a := range config.Validators {
validators[a] = true