Skip to content

Commit f3bf597

Browse files
author
Boran
committed
Update
1 parent 4011d54 commit f3bf597

File tree

4 files changed

+68
-74
lines changed

4 files changed

+68
-74
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,21 @@
1515

1616
## How to Install?
1717
+ You can download it from the Releases section
18-
+ After downloading, make sure to set the location of the exe file and add the path of that configured location to your PATH file. The database will be automatically created in the documents or users file.
18+
+ After downloading, make sure to set the location of the exe file and add the path of that configured location to your PATH file. The database will be automatically created in `C:\Users\<username>\gosecDB` PATH.
1919
+ Note: Please be cautious while manipulating the PATH environment variable, as it directly affects how your operating system finds and executes files.
2020
+ When downloading an executable (exe) file, you might receive a virus warning, but this can be misleading. If you'd like, you can examine the code from the source to verify.
2121
+ If the virus threat warning doesn't go away, you can download the source code and create the exe file by writing the code below.
2222
+ `go build main.go` After writing this, the exe file will be created inside the current folder.
2323

24+
## First Open
25+
+ When you open it for the first time, gosec will ask you for a master key.
26+
+ This is an extra security. It is useful not to forget this master key.
27+
+ Even if you forget, you can check it in settings.json.
28+
+ You might ask, "Why expose the master key openly in the source code?"
29+
+ Well, imagine someone developing a program based on this source code. Let's say they are building an API and they want to decrypt their own passwords, hosting a site locally for easy access. To achieve this, they would need access to the master key. However, if the master key is embedded within the binary, it could create complications.
30+
+ Therefore, I have incorporated this approach to address such a scenario.
31+
32+
2433
## Modes
2534
+ The application comprises five primary modes: Register, Config, Key, DeleteUser and Password.
2635
+ All modes feature a single global option, namely -P. This argument will prompt for the password you entered during registration. It will be requested in both the password and config modes, including their sub-modes. This mechanism can be likened to an authentication check, helping us discern which user is performing the operation.

database/database.go

Lines changed: 8 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@ var GosecDb gojson.Database
99

1010
func DatabaseInit() {
1111

12-
// Otomatik db pathi ayarlıyor hiç biri işe yaramaz ise ./ a otomatik db oluşturuyor.
13-
//targetDir := GetPath()
14-
1512
// Init DB
16-
GosecDb = gojson.CreateDatabase("gosecDB", "./")
13+
GosecDb = gojson.CreateDatabase("gosecDB", SetPath())
1714

1815
// Users Table
1916
UsersT := gojson.CreateTable("users")
@@ -36,82 +33,21 @@ func DatabaseInit() {
3633
PasswordsT.AddProperty("url", "string", "")
3734
PasswordsT.AddProperty("password", "string", "")
3835

36+
// Settings Table
37+
SettingsT := gojson.CreateTable("settings")
38+
SettingsT.AddProperty("masterkey", "string", "")
39+
3940
// Adds table to the Database
4041
GosecDb.AddTable(&UsersT)
4142
GosecDb.AddTable(&ConfigT)
4243
GosecDb.AddTable(&PasswordsT)
44+
GosecDb.AddTable(&SettingsT)
4345

4446
// Creates Database Files.
4547
GosecDb.CreateFiles()
4648

47-
// UsersT.Save(gojson.DataInit([]string{"username", "password"}, []interface{}{"BORANBORAN", "1"}, &UsersT))
48-
49-
}
50-
51-
/* Bu kodu virüs olarak algılıyor microsoft. içerideki verilere eriştiği için o yüzden sildim.
52-
func GetPath() string {
53-
// Gets the file path.
54-
baseDir, err := os.UserHomeDir()
55-
if err != nil {
56-
fmt.Println("Hata:", err)
57-
return "./"
58-
}
49+
SetSettings(&SettingsT)
5950

60-
var targetDir string
61-
62-
check := true
63-
switch runtime.GOOS {
64-
case "windows":
65-
fnames := []string{"Documents", "Belgeler"}
66-
67-
// Bütün olasılıkları deniyorum documents, belgeler gibi
68-
for _, v := range fnames {
69-
targetDir = filepath.Join(baseDir, v)
70-
71-
_, err = os.Stat(targetDir)
72-
if err != nil {
73-
// Böyle klasör yok
74-
check = false
75-
continue
76-
} else {
77-
check = true
78-
targetDir += "\\"
79-
break
80-
}
81-
}
82-
// Eğer hiçbir olasılık çalışmadıysa users'ın altına veritabanını yerleştiriyorum
83-
if !check {
84-
targetDir = "./"
85-
}
86-
break
87-
case "linux", "darwin":
88-
fnames := []string{"Documents", "Belgeler"}
89-
90-
// Bütün olasılıkları deniyorum documents, belgeler gibi
91-
for _, v := range fnames {
92-
targetDir = filepath.Join(baseDir, v)
93-
94-
_, err = os.Stat(targetDir)
95-
if err != nil {
96-
// Böyle klasör yok
97-
check = false
98-
continue
99-
} else {
100-
check = true
101-
targetDir += "/"
102-
break
103-
}
104-
}
105-
// Eğer hiçbir olasılık çalışmadıysa users'ın altına veritabanını yerleştiriyorum
106-
if !check {
107-
targetDir = "./"
108-
}
109-
break
110-
default:
111-
targetDir = "./"
112-
break
113-
}
51+
// UsersT.Save(gojson.DataInit([]string{"username", "password"}, []interface{}{"BORANBORAN", "1"}, &UsersT))
11452

115-
return targetDir
11653
}
117-
*/

database/settings.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package database
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"runtime"
7+
8+
"github.com/cetinboran/gojson/gojson"
9+
)
10+
11+
func SetSettings(SettingsT *gojson.Table) {
12+
if len(SettingsT.Get()) == 0 {
13+
for {
14+
var masterKey string
15+
fmt.Println("please enter the master secret key. This secret key encrypts your secret keys")
16+
fmt.Print(">: ")
17+
fmt.Scanln(&masterKey)
18+
19+
if len(masterKey) != 16 && len(masterKey) != 24 && len(masterKey) != 32 {
20+
fmt.Println("The Master key length must be 16, 24 or 32")
21+
} else {
22+
SettingsT.Save(gojson.DataInit([]string{"masterkey"}, []interface{}{masterKey}, SettingsT))
23+
break
24+
}
25+
}
26+
}
27+
}
28+
29+
func SetPath() string {
30+
baseDir, err := os.UserHomeDir()
31+
if err != nil {
32+
fmt.Println("Hata:", err)
33+
}
34+
35+
switch runtime.GOOS {
36+
case "windows":
37+
baseDir += "\\"
38+
case "linux", "darwin":
39+
baseDir += "/"
40+
break
41+
}
42+
43+
return baseDir
44+
}

settings/settings.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package settings
22

3+
import "github.com/cetinboran/gosec/database"
4+
35
func GetSecretForSecrets() []byte {
4-
return []byte("^FAIXvY7QdV4TK6cJLneqHWZ")
6+
SettingsT := database.GosecDb.Tables["settings"]
7+
masterKey := SettingsT.Get()[0]["masterkey"].(string)
8+
9+
return []byte(masterKey)
510
}

0 commit comments

Comments
 (0)