[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-taldir] 02/02: Add salt from configuration; fix bug where config
From: |
gnunet |
Subject: |
[taler-taldir] 02/02: Add salt from configuration; fix bug where config is not used |
Date: |
Tue, 19 Apr 2022 15:26:39 +0200 |
This is an automated email from the git hooks/post-receive script.
martin-schanzenbach pushed a commit to branch master
in repository taldir.
commit a23141ba64eca8630f037ef592753fe292b7e331
Author: Martin Schanzenbach <mschanzenbach@posteo.de>
AuthorDate: Tue Apr 19 15:26:34 2022 +0200
Add salt from configuration; fix bug where config is not used
---
config.json | 4 +++-
taldir.go | 24 ++++++++++++++----------
2 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/config.json b/config.json
index 3c1f173..9e0d381 100644
--- 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
index 8e2520f..b4c4eaf 100644
--- 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
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.