Class: RubeePass
- Inherits:
-
Object
show all
- Defined in:
- lib/rubeepass.rb
Defined Under Namespace
Classes: Entry, Error, Group, ProtectedDecryptor
Constant Summary
collapse
0
1
- @@CIPHER_ID =
2
- @@COMPRESSION =
3
- @@MASTER_SEED =
4
- @@TRANSFORM_SEED =
5
- @@TRANSFORM_ROUNDS =
6
- @@ENCRYPTION_IV =
7
- @@PROTECTED_STREAM_KEY =
8
- @@STREAM_START_BYTES =
9
- @@INNER_RANDOM_STREAM_ID =
10
- @@MAGIC_SIG1 =
0x9aa2d903
- @@MAGIC_SIG2 =
0xb54bfb67
- @@VERSION =
0x00030000
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(kdbx, password, keyfile = nil) ⇒ RubeePass
Returns a new instance of RubeePass.
176
177
178
179
180
|
# File 'lib/rubeepass.rb', line 176
def initialize(kdbx, password, keyfile = nil)
@kdbx = kdbx
@keyfile = keyfile
@password = password
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
|
# File 'lib/rubeepass.rb', line 227
def method_missing(method_name, *args)
if (method_name.to_s.match(/^clear_clipboard_after_/))
mn = method_name.to_s.gsub!(/^clear_clipboard_after_/, "")
case mn
when /^[0-9]+_sec(ond)?s$/
time = mn.gsub(/_sec(ond)?s$/, "").to_i
clear_clipboard(time)
when /^[0-9]+_min(ute)?s$/
time = mn.gsub(/_min(ute)?s$/, "").to_i
clear_clipboard(time * 60)
else
super
end
else
super
end
end
|
Instance Attribute Details
#db ⇒ Object
Returns the value of attribute db.
29
30
31
|
# File 'lib/rubeepass.rb', line 29
def db
@db
end
|
#gzip ⇒ Object
Returns the value of attribute gzip.
30
31
32
|
# File 'lib/rubeepass.rb', line 30
def gzip
@gzip
end
|
#protected_decryptor ⇒ Object
Returns the value of attribute protected_decryptor.
31
32
33
|
# File 'lib/rubeepass.rb', line 31
def protected_decryptor
@protected_decryptor
end
|
#xml ⇒ Object
Returns the value of attribute xml.
32
33
34
|
# File 'lib/rubeepass.rb', line 32
def xml
@xml
end
|
Instance Method Details
#absolute_path(to, from = "/") ⇒ Object
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
|
# File 'lib/rubeepass.rb', line 34
def absolute_path(to, from = "/")
return "/" if (to.nil? || to.empty? || (to == "/"))
from = "/" if (to.start_with?("/"))
path = Array.new
from.split("/").each do |group|
next if (group.empty?)
case group
when "."
when ".."
path.pop
else
path.push(group)
end
end
to.split("/").each do |group|
next if (group.empty?)
case group
when "."
when ".."
path.pop
else
path.push(group)
end
end
return "/#{path.join("/")}"
end
|
#clear_clipboard(time = 0) ⇒ Object
67
68
69
70
71
72
73
|
# File 'lib/rubeepass.rb', line 67
def clear_clipboard(time = 0)
@thread.kill if (@thread)
@thread = Thread.new do
sleep time
copy_to_clipboard("", false)
end
end
|
#copy_to_clipboard(string, err = true) ⇒ Object
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
123
124
125
126
127
128
129
130
|
# File 'lib/rubeepass.rb', line 75
def copy_to_clipboard(string, err = true)
string = "" if (string.nil?)
if (OS::Underlying.windows?)
puts "Your OS is not currently supported!" if (err)
return
end
return if (ENV["DISPLAY"].nil? || ENV["DISPLAY"].empty?)
echo = ScoobyDoo.where_are_you("echo")
if (OS.mac?)
pbcopy = ScoobyDoo.where_are_you("pbcopy")
rn = ScoobyDoo.where_are_you("reattach-to-user-namespace")
cp = pbcopy
if (ENV["TMUX"])
cp = nil
cp = "#{rn} #{pbcopy}" if (rn)
end
if (cp)
system("#{echo} -n #{string.shellescape} | #{cp}")
else
if (err)
puts "Please install reattach-to-user-namespace!"
end
return
end
elsif (OS.posix?)
xclip = ScoobyDoo.where_are_you("xclip")
xsel = ScoobyDoo.where_are_you("xsel")
["clipboard", "primary", "secondary"].each do |sel|
cp = nil
if (xclip)
cp = "xclip -i -selection #{sel}"
elsif (xsel)
cp = "xsel -i --#{sel}"
end
if (cp)
system("#{echo} -n #{string.shellescape} | #{cp}")
else
if (err)
puts "Please install either xclip or xsel!"
end
return
end
end
else
puts "Your OS is not currently supported!" if (err)
return
end
end
|
#export(export_file, format) ⇒ Object
150
151
152
153
154
155
156
157
158
159
160
161
|
# File 'lib/rubeepass.rb', line 150
def export(export_file, format)
start_opening
File.open(export_file, "w") do |f|
case format
when "gzip"
f.write(@gzip)
when "xml"
f.write(@xml)
end
end
end
|
#find_group(path) ⇒ Object
168
169
170
|
# File 'lib/rubeepass.rb', line 168
def find_group(path)
return @db.find_group(path)
end
|
#fuzzy_find(input) ⇒ Object
172
173
174
|
# File 'lib/rubeepass.rb', line 172
def fuzzy_find(input)
return @db.fuzzy_find(input)
end
|
#open ⇒ Object
245
246
247
248
249
250
251
252
253
254
255
256
257
258
|
# File 'lib/rubeepass.rb', line 245
def open
start_opening
@protected_decryptor = ProtectedDecryptor.new(
Digest::SHA256.digest(
@header[@@PROTECTED_STREAM_KEY]
),
["E830094B97205D2A"].pack("H*")
)
parse_xml
return self
end
|
#to_s ⇒ Object
432
433
434
|
# File 'lib/rubeepass.rb', line 432
def to_s
return @db.to_s
end
|
#wait_to_exit ⇒ Object
436
437
438
439
440
441
442
443
|
# File 'lib/rubeepass.rb', line 436
def wait_to_exit
return if (@thread.nil?)
begin
@thread.join
rescue Interrupt => e
puts
end
end
|