commit 7c7ea95a9fb12362d704e98499cb894b7919a87d
parent d4d181c180256b41c0c65f01fed00bd9a5bb7cd5
Author: Martin Schanzenbach <mschanzenbach@posteo.de>
Date: Tue, 19 Apr 2022 17:15:06 +0200
Switch to postgres
Diffstat:
3 files changed, 30 insertions(+), 13 deletions(-)
diff --git a/config.json b/config.json
@@ -1,9 +1,13 @@
{
"production": false,
- "db_backend": "sqlite",
"validators": ["email","phone"],
"email_sender": "taldir@taler.net",
"host": "https://taldir.net/",
- "bind_to": "localhost:10000",
- "salt": "ChangeMe"
+ "bind_to": "localhost:11000",
+ "salt": "ChangeMe",
+ "pq_host": "localhost",
+ "pq_port": 5432,
+ "pq_user": "taldir",
+ "pq_password": "secret",
+ "pq_dbname": "taldir"
}
diff --git a/go.mod b/go.mod
@@ -3,10 +3,16 @@ module taler.net/taldir
go 1.16
require (
- github.com/gorilla/mux v1.8.0 // indirect
+ github.com/alexbrainman/sspi v0.0.0-20180613141037-e580b900e9f5 // indirect
+ github.com/gorilla/mux v1.8.0
+ github.com/jcmturner/gokrb5/v8 v8.2.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
- github.com/mattn/go-sqlite3 v1.14.12 // indirect
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
- gorm.io/driver/sqlite v1.3.1 // indirect
- gorm.io/gorm v1.23.4 // indirect
+ gopkg.in/jcmturner/aescts.v1 v1.0.1 // indirect
+ gopkg.in/jcmturner/dnsutils.v1 v1.0.1 // indirect
+ gopkg.in/jcmturner/goidentity.v3 v3.0.0 // indirect
+ gopkg.in/jcmturner/gokrb5.v7 v7.5.0 // indirect
+ gopkg.in/jcmturner/rpc.v1 v1.1.0 // indirect
+ gorm.io/driver/postgres v1.3.4
+ gorm.io/gorm v1.23.4
)
diff --git a/taldir.go b/taldir.go
@@ -8,26 +8,29 @@ import (
"encoding/json"
"github.com/gorilla/mux"
"gorm.io/gorm"
- "gorm.io/driver/sqlite"
"encoding/base32"
"math/rand"
"net/smtp"
- "golang.org/x/crypto/argon2"
"crypto/sha256"
+ "gorm.io/driver/postgres"
)
type Configuration struct {
Production bool
- DbBackend string `json:"db_backend"`
Validators []string
EmailSender string `json:"email_sender"`
Salt string `json:"salt"`
Host string `json:"host"`
BindTo string `json:"bind_to"`
+ PqUser string `json:"pq_user"`
+ PqPassword string `json:"pq_pw"`
+ PqHost string `json:"pq_host"`
+ PqPort int `json:"pq_port"`
+ PqDbname string `json:"pq_dbname"`
}
// A mappind entry from the identity key hash to a wallet key
-// The identity key hash is argon2(sha256(identity)) where identity is
+// The identity key hash is sha256(sha256(identity)|salt) where identity is
// one of the identity key types supported (e.g. email)
type Entry struct {
gorm.Model
@@ -99,7 +102,10 @@ func returnSingleEntry(w http.ResponseWriter, r *http.Request){
func hashIdentityKey(idkey string) string {
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))
+ h := sha256.New()
+ h.Write([]byte(idkey))
+ h.Write(salt)
+ return base32.StdEncoding.EncodeToString(h.Sum(nil))
}
// Called by the registrant to validate the registration request. The reference ID was
@@ -220,7 +226,8 @@ func main() {
for _, a := range config.Validators {
validators[a] = true
}
- _db, err := gorm.Open(sqlite.Open("./taldir.db"), &gorm.Config{})
+ psqlconn := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable", config.PqHost, config.PqPort, config.PqUser, config.PqPassword, config.PqDbname)
+ _db, err := gorm.Open(postgres.Open(psqlconn), &gorm.Config{})
if err != nil {
panic(err)
}