Skip to content

Commit ab0c6af

Browse files
committed
FEAT: using safe scheme to handle persistent encrypted system user's data
1 parent c0ff574 commit ab0c6af

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

src/mezz/mezz-shell.reb

+50
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,53 @@ more: func [
4747
word! path! [to-file file]
4848
]
4949
]
50+
51+
user's: func[
52+
"Resolves user's data value"
53+
'key /local data
54+
][
55+
all [
56+
data: select system/user 'data
57+
select :data :key
58+
]
59+
]
60+
61+
su: set-user: func[
62+
"Initialize user's persistent data under system/user"
63+
'name [word! ref! string! unset!] "User's name"
64+
/p "Password used to encrypt the data"
65+
password [string! binary!]
66+
/f "Use custom persistent data file location"
67+
file [file!]
68+
/n "Setup a user if does not exists"
69+
/local su
70+
][
71+
su: system/user
72+
if unset? :name [su/name: none su/data: make map! 1 exit]
73+
74+
sys/log/info 'REBOL ["Initialize user:" as-green :name]
75+
file: to-real-file any [file rejoin [system/options/home #"." :name %.safe]]
76+
sys/log/more 'REBOL ["Checking if exists: " as-green file]
77+
unless exists? file [
78+
unless n [
79+
sys/log/error 'REBOL "User's persistent storage file not found!"
80+
exit
81+
]
82+
sys/log/info 'REBOL ["Creating a new persistent storage file:" as-green file]
83+
]
84+
password: any [
85+
password
86+
get-env "REBOL_SAFE_PASS"
87+
ask/hide "Enter password: "
88+
]
89+
90+
if port? su/data [ close su/data ]
91+
su/name: to ref! :name
92+
file: split-path :file
93+
su/data: open [
94+
scheme: 'safe
95+
pass: password
96+
path: file/1
97+
target: file/2
98+
]
99+
]

0 commit comments

Comments
 (0)