gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-taldir] branch master updated: refactor; config flag


From: gnunet
Subject: [taler-taldir] branch master updated: refactor; config flag
Date: Wed, 06 Jul 2022 17:22:33 +0200

This is an automated email from the git hooks/post-receive script.

martin-schanzenbach pushed a commit to branch master
in repository taldir.

The following commit(s) were added to refs/heads/master by this push:
     new 2c22b54  refactor; config flag
2c22b54 is described below

commit 2c22b54ad3d144363a37da15f1ecca70894ee14b
Author: Martin Schanzenbach <schanzen@gnunet.org>
AuthorDate: Wed Jul 6 17:22:31 2022 +0200

    refactor; config flag
---
 cmd/taldir-server/main.go | 30 +++++++++++-------------------
 util/helper.go            | 11 ++++++++++-
 2 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/cmd/taldir-server/main.go b/cmd/taldir-server/main.go
index 395bdf9..6ce547a 100644
--- a/cmd/taldir-server/main.go
+++ b/cmd/taldir-server/main.go
@@ -42,7 +42,6 @@ import (
   "gorm.io/gorm"
   "encoding/base64"
   "taler.net/taldir/util"
-  "math/rand"
   "crypto/sha512"
   "gorm.io/driver/postgres"
   "gopkg.in/ini.v1"
@@ -214,11 +213,10 @@ var validationTpl *template.Template
 
 // Primary lookup function.
 // Allows the caller to query a wallet key using the hash(!) of the
-// identity, e.g. sha256(<email address>)
+// identity, e.g. SHA512(<email address>)
 func getSingleEntry(w http.ResponseWriter, r *http.Request){
   vars := mux.Vars(r)
   var entry Entry
-  //identityKeyHash := hashIdentityKey(vars["identity_key"])
   hs_address := saltHAddress(vars["h_address"])
   var err = db.First(&entry, "hs_address = ?", hs_address).Error
   if err == nil {
@@ -300,16 +298,6 @@ func validationRequest(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 util.EncodeBinaryToString(randBytes)
-}
-
 func registerRequest(w http.ResponseWriter, r *http.Request){
   vars := mux.Vars(r)
   var req RegisterMessage
@@ -376,7 +364,7 @@ func registerRequest(w http.ResponseWriter, r 
*http.Request){
     w.WriteHeader(202)
     return
   } else {
-    validation.Code = generateToken()
+    validation.Code = util.GenerateCode()
     validation.Inbox = req.Inbox
     validation.Duration = req.Duration
     validation.PublicKey = req.PublicKey
@@ -464,8 +452,6 @@ func handleRequests() {
 
 
   /* Registration API */
-  //myRouter.HandleFunc("/directory/{identity_key}", 
returnSingleEntry).Methods("GET")
-  //myRouter.HandleFunc("/validation/{reference}", 
validateSingleEntry).Methods("GET")
   myRouter.HandleFunc("/{h_address}", getSingleEntry).Methods("GET")
   myRouter.HandleFunc("/register/{method}", registerRequest).Methods("POST")
   myRouter.HandleFunc("/register/{h_address}/{validation_code}", 
validationPage).Methods("GET")
@@ -475,7 +461,14 @@ func handleRequests() {
 }
 
 func main() {
-  _cfg, err := ini.Load("taldir.conf")
+  var dropFlag = flag.Bool("D", false, "Drop all data in table (DANGEROUS!)")
+  var cfgFlag = flag.String("c", "", "Configuration file to use")
+  flag.Parse()
+  cfgfile := "taldir.conf"
+  if len(*cfgFlag) != 0 {
+    cfgfile = *cfgFlag
+  }
+  _cfg, err := ini.Load(cfgfile)
   if err != nil {
     fmt.Printf("Failed to read config: %v", err)
     os.Exit(1)
@@ -484,8 +477,7 @@ func main() {
   if cfg.Section("taldir").Key("production").MustBool(false) {
     fmt.Println("Production mode enabled") 
   }
-  var dropFlag = flag.Bool("D", false, "Drop all data in table (DANGEROUS!)")
-  flag.Parse()
+
   validators = make(map[string]bool)
   for _, a := range 
strings.Split(cfg.Section("taldir").Key("validators").String(), " ") {
     validators[a] = true
diff --git a/util/helper.go b/util/helper.go
index 36c0ea0..d2f7a49 100644
--- a/util/helper.go
+++ b/util/helper.go
@@ -22,6 +22,7 @@ package util
 import (
   "fmt"
   "crypto/sha512"
+  "math/rand"
 )
 
 
@@ -38,4 +39,12 @@ func GenerateSolution(pubkeyEncoded string, code string) 
string {
   return EncodeBinaryToString(h.Sum(nil))
 }
 
-
+// Generates random reference token used in the validation flow.
+func GenerateCode() string {
+  randBytes := make([]byte, 32)
+  _, err := rand.Read(randBytes)
+  if err != nil {
+    panic(err)
+  }
+  return EncodeBinaryToString(randBytes)
+}

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]