Skip to content

Commit 0f3117c

Browse files
committed
rename dbobj.hash to dbobj.salt for clarity
1 parent 53b839d commit 0f3117c

6 files changed

Lines changed: 19 additions & 19 deletions

File tree

src/bunker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var version string
3030
type dbcon struct {
3131
store storage.BackendDB
3232
masterKey []byte
33-
hash []byte
33+
salt []byte
3434
}
3535

3636
// Config is u sed to store application configuration

src/conf.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@ func (dbobj dbcon) GlobalUserChangeEmail(oldEmail string, newEmail string) {
7272
}
7373

7474
func (dbobj dbcon) GetCode() []byte {
75-
code := dbobj.hash[4:12]
75+
code := dbobj.salt[4:12]
7676
return code
7777
}

src/service.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ func loadService() {
8888
log.Printf("Filed to open db: %s", err)
8989
os.Exit(0)
9090
}
91-
hash := md5.Sum(masterKey)
92-
db := &dbcon{store, masterKey, hash[:]}
91+
md5hash := md5.Sum(masterKey)
92+
db := &dbcon{store, masterKey, md5hash[:]}
9393
e := mainEnv{db, cfg, make(chan struct{})}
9494
e.dbCleanup()
9595
initGeoIP()
96-
initCaptcha(hash)
96+
initCaptcha(md5hash)
9797
router := e.setupRouter()
9898
router = e.setupConfRouter(router)
9999
tlsConfig := &tls.Config{
@@ -180,7 +180,7 @@ func setupDB(dbPtr *string, masterKeyPtr *string, customRootToken string) (*dbco
180180
}
181181
log.Printf("Master key: %x\n", masterKey)
182182
}
183-
hash := md5.Sum(masterKey)
183+
md5hash := md5.Sum(masterKey)
184184
log.Println("Init database")
185185
store, err := storage.InitDB(dbPtr)
186186
for numAttempts := 60; err != nil && numAttempts > 0; numAttempts-- {
@@ -193,7 +193,7 @@ func setupDB(dbPtr *string, masterKeyPtr *string, customRootToken string) (*dbco
193193
log.Fatalf("Databunker failed to init database, error %s\n\n", err.Error())
194194
os.Exit(0)
195195
}
196-
db := &dbcon{store, masterKey, hash[:]}
196+
db := &dbcon{store, masterKey, md5hash[:]}
197197
rootToken, err := db.createRootXtoken(customRootToken)
198198
if err != nil {
199199
//log.Panic("error %s", err.Error())

src/users_db.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,16 @@ func (dbobj dbcon) createUserRecord(parsedData utils.UserJSONStruct, event *Audi
4444
// I use original md5(master_key) as a kind of salt here,
4545
// so no additional configuration field is needed here.
4646
if len(parsedData.LoginIdx) > 0 {
47-
bdoc["loginidx"] = utils.HashString(dbobj.hash, parsedData.LoginIdx)
47+
bdoc["loginidx"] = utils.HashString(dbobj.salt, parsedData.LoginIdx)
4848
}
4949
if len(parsedData.EmailIdx) > 0 {
50-
bdoc["emailidx"] = utils.HashString(dbobj.hash, parsedData.EmailIdx)
50+
bdoc["emailidx"] = utils.HashString(dbobj.salt, parsedData.EmailIdx)
5151
}
5252
if len(parsedData.PhoneIdx) > 0 {
53-
bdoc["phoneidx"] = utils.HashString(dbobj.hash, parsedData.PhoneIdx)
53+
bdoc["phoneidx"] = utils.HashString(dbobj.salt, parsedData.PhoneIdx)
5454
}
5555
if len(parsedData.CustomIdx) > 0 {
56-
bdoc["customidx"] = utils.HashString(dbobj.hash, parsedData.CustomIdx)
56+
bdoc["customidx"] = utils.HashString(dbobj.salt, parsedData.CustomIdx)
5757
}
5858
if event != nil {
5959
event.After = encodedStr
@@ -235,7 +235,7 @@ func (dbobj dbcon) updateUserRecordDo(jsonDataPatch []byte, userTOKEN string, ol
235235
}
236236
if idxOldValue, ok := oldUserBson[idx+"idx"]; ok {
237237
if len(newIdxFinalValue) > 0 && len(idxOldValue.(string)) >= 0 {
238-
idxStringHashHex := utils.HashString(dbobj.hash, newIdxFinalValue)
238+
idxStringHashHex := utils.HashString(dbobj.salt, newIdxFinalValue)
239239
if idxStringHashHex == idxOldValue.(string) {
240240
//log.Println("Index value NOT changed!")
241241
actionCode = 0
@@ -255,7 +255,7 @@ func (dbobj dbcon) updateUserRecordDo(jsonDataPatch []byte, userTOKEN string, ol
255255
return nil, nil, true, fmt.Errorf("duplicate %s index", idx)
256256
}
257257
//log.Printf("Adding index3? %s\n", raw[idx])
258-
bdoc[idx+"idx"] = utils.HashString(dbobj.hash, newIdxFinalValue)
258+
bdoc[idx+"idx"] = utils.HashString(dbobj.salt, newIdxFinalValue)
259259
} else if len(newIdxFinalValue) == 0 {
260260
bdel = append(bdel, idx+"idx")
261261
}
@@ -314,7 +314,7 @@ func (dbobj dbcon) lookupUserRecordByIndex(indexName string, indexValue string,
314314
if indexName == "exptoken" {
315315
return dbobj.store.GetRecord(storage.TblName.Users, "exptoken", indexValue)
316316
}
317-
idxStringHashHex := utils.HashString(dbobj.hash, indexValue)
317+
idxStringHashHex := utils.HashString(dbobj.salt, indexValue)
318318
//log.Printf("Loading by %s, value: %s\n", indexName, indexValue)
319319
return dbobj.store.GetRecord(storage.TblName.Users, indexName+"idx", idxStringHashHex)
320320
}

src/utils/utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ func GetArgEnvFileVariable(vname string, masterKeyPtr *string) string {
225225
return strings.TrimSpace(strvalue)
226226
}
227227

228-
func HashString(md5Salt []byte, src string) string {
229-
stringToHash := append(md5Salt, []byte(src)...)
228+
func HashString(salt []byte, src string) string {
229+
stringToHash := append(salt, []byte(src)...)
230230
hashed := sha256.Sum256(stringToHash)
231231
return base64.StdEncoding.EncodeToString(hashed[:])
232232
}

src/xtokens_db.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (dbobj dbcon) createRootXtoken(customRootXtoken string) (string, error) {
4040
}
4141
}
4242
bdoc := bson.M{}
43-
bdoc["xtoken"] = utils.HashString(dbobj.hash, rootToken)
43+
bdoc["xtoken"] = utils.HashString(dbobj.salt, rootToken)
4444
bdoc["type"] = "root"
4545
bdoc["token"] = ""
4646
_, err = dbobj.store.CreateRecord(storage.TblName.Xtokens, &bdoc)
@@ -60,7 +60,7 @@ func (dbobj dbcon) genUserLoginXtoken(userTOKEN string) (string, string, error)
6060
if err != nil {
6161
return "", "", err
6262
}
63-
hashedToken := utils.HashString(dbobj.hash, tokenUUID)
63+
hashedToken := utils.HashString(dbobj.salt, tokenUUID)
6464
// by default login token for 30 minutes only
6565
expired := int32(time.Now().Unix()) + 10*60
6666
bdoc := bson.M{}
@@ -77,7 +77,7 @@ func (dbobj dbcon) checkUserAuthXToken(xtokenUUID string) (tokenAuthResult, erro
7777
if xtokenUUID != "DEMO" && utils.CheckValidUUID(xtokenUUID) == false {
7878
return result, errors.New("failed to authenticate")
7979
}
80-
xtokenHashed := utils.HashString(dbobj.hash, xtokenUUID)
80+
xtokenHashed := utils.HashString(dbobj.salt, xtokenUUID)
8181
if len(rootXTOKEN) > 0 && rootXTOKEN == xtokenHashed {
8282
//log.Println("It is a root token")
8383
result.ttype = "root"

0 commit comments

Comments
 (0)