Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
hotfix 2
  • Loading branch information
0xdcarns committed Feb 16, 2022
1 parent 3d4f44e commit 9bee126
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
6 changes: 5 additions & 1 deletion logic/jwts.go
Expand Up @@ -17,7 +17,11 @@ var jwtSecretKey []byte
func SetJWTSecret() {
currentSecret, jwtErr := FetchJWTSecret()
if jwtErr != nil {
jwtSecretKey = []byte(RandomString(64)) // 512 bit random password
newValue, err := GenerateCryptoString(64)
if err != nil {
logger.FatalLog("something went wrong when generating JWT signature")
}
jwtSecretKey = []byte(newValue) // 512 bit random password
if err := StoreJWTSecret(string(jwtSecretKey)); err != nil {
logger.FatalLog("something went wrong when configuring JWT authentication")
}
Expand Down
37 changes: 15 additions & 22 deletions logic/util.go
Expand Up @@ -2,9 +2,11 @@
package logic

import (
crand "crypto/rand"
"encoding/base64"
"encoding/json"
"fmt"
"math/big"
"math/rand"
"net"
"os"
Expand Down Expand Up @@ -85,29 +87,20 @@ func SetNetworkNodesLastModified(networkName string) error {
return nil
}

// // GetNode - fetches a node from database
// func GetNode(macaddress string, network string) (models.Node, error) {
// var node models.Node

// key, err := GetRecordKey(macaddress, network)
// if err != nil {
// return node, err
// }
// data, err := database.FetchRecord(database.NODES_TABLE_NAME, key)
// if err != nil {
// if data == "" {
// data, _ = database.FetchRecord(database.DELETED_NODES_TABLE_NAME, key)
// err = json.Unmarshal([]byte(data), &node)
// }
// return node, err
// }
// if err = json.Unmarshal([]byte(data), &node); err != nil {
// return node, err
// }
// SetNodeDefaults(&node)
// GenerateCryptoString - generates random string of n length
func GenerateCryptoString(n int) (string, error) {
const chars = "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-"
ret := make([]byte, n)
for i := range ret {
num, err := crand.Int(crand.Reader, big.NewInt(int64(len(chars))))
if err != nil {
return "", err
}
ret[i] = chars[num.Int64()]
}

// return node, err
// }
return string(ret), nil
}

// DeleteNodeByID - deletes a node from database or moves into delete nodes table
func DeleteNodeByID(node *models.Node, exterminate bool) error {
Expand Down

0 comments on commit 9bee126

Please sign in to comment.