+9
-3
appview/db/registration.go
+9
-3
appview/db/registration.go
···
1
package db
2
3
import (
4
"database/sql"
5
"fmt"
6
"log"
7
"time"
8
-
9
-
"github.com/google/uuid"
10
)
11
12
type Registration struct {
···
101
return ®istration, nil
102
}
103
104
func (d *DB) GenerateRegistrationKey(domain, did string) (string, error) {
105
// sanity check: does this domain already have a registration?
106
reg, err := d.RegistrationByDomain(domain)
···
120
}
121
}
122
123
-
secret := uuid.New().String()
124
125
_, err = d.db.Exec(`
126
insert into registrations (domain, did, secret)
···
1
package db
2
3
import (
4
+
"crypto/rand"
5
"database/sql"
6
+
"encoding/hex"
7
"fmt"
8
"log"
9
"time"
10
)
11
12
type Registration struct {
···
101
return ®istration, nil
102
}
103
104
+
func genSecret() string {
105
+
key := make([]byte, 32)
106
+
rand.Read(key)
107
+
return hex.EncodeToString(key)
108
+
}
109
+
110
func (d *DB) GenerateRegistrationKey(domain, did string) (string, error) {
111
// sanity check: does this domain already have a registration?
112
reg, err := d.RegistrationByDomain(domain)
···
126
}
127
}
128
129
+
secret := genSecret()
130
131
_, err = d.db.Exec(`
132
insert into registrations (domain, did, secret)