-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
122 lines (116 loc) · 2.89 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package main
import (
"encoding/csv"
"encoding/json"
"fmt"
"log"
"os"
)
type EnpassJson struct {
CustomIcons []struct {
Data string `json:"data"`
UUID string `json:"uuid"`
} `json:"custom_icons"`
Folders []struct {
Icon string `json:"icon"`
ParentUUID string `json:"parent_uuid"`
Title string `json:"title"`
UpdatedAt int `json:"updated_at"`
UUID string `json:"uuid"`
} `json:"folders"`
Items []struct {
Archived int `json:"archived"`
AutoSubmit int `json:"auto_submit"`
Category string `json:"category"`
CreatedAt int `json:"createdAt"`
Favorite int `json:"favorite"`
Fields []struct {
Deleted int `json:"deleted"`
Label string `json:"label"`
Order int `json:"order"`
Sensitive int `json:"sensitive"`
Type string `json:"type"`
UID int `json:"uid"`
UpdatedAt int `json:"updated_at"`
Value string `json:"value"`
ValueUpdatedAt int `json:"value_updated_at"`
} `json:"fields"`
Icon struct {
Fav string `json:"fav"`
Image struct {
File string `json:"file"`
} `json:"image"`
Type int `json:"type"`
UUID string `json:"uuid"`
} `json:"icon"`
Note string `json:"note"`
Subtitle string `json:"subtitle"`
TemplateType string `json:"template_type"`
Title string `json:"title"`
Trashed int `json:"trashed"`
UpdatedAt int `json:"updated_at"`
UUID string `json:"uuid"`
} `json:"items"`
}
func main() {
if len(os.Args) < 3 {
log.Fatalln("\n./enpass-to-keepassxc input_file.json output_file.csv\nOR\ngo run main.go input_file.json output_file.csv")
}
input := os.Args[1]
output := os.Args[2]
b, err := os.ReadFile(input)
if err != nil {
log.Fatalln(err)
}
enpassData := &EnpassJson{}
err = json.Unmarshal(b, enpassData)
if err != nil {
log.Fatalln(err)
}
keepassxc_records := [][]string{
{"Group", "Title", "Username", "Password", "URL", "Notes", "TOTP", "Icon", "Last Modified", "Created"},
}
for _, item := range enpassData.Items {
var username, password, url, totp string
for _, fl := range item.Fields {
if fl.Type == "username" || fl.Type == "email" {
if fl.Value != "" {
username = fl.Value
}
}
if fl.Type == "password" {
password = fl.Value
}
if fl.Type == "url" {
url = fl.Value
}
if fl.Type == "totp" {
totp = fl.Value
}
}
record := []string{
item.Category,
item.Title,
username,
password,
url,
item.Note,
totp,
"",
fmt.Sprintf("%d", item.UpdatedAt),
fmt.Sprintf("%d", item.CreatedAt),
}
keepassxc_records = append(keepassxc_records, record)
}
f, err := os.Create(output)
if err != nil {
log.Fatalln(err)
}
defer f.Close()
w := csv.NewWriter(f)
err = w.WriteAll(keepassxc_records)
if err := w.Error(); err != nil {
log.Fatalln(err)
}
log.Println("Success")
}