Class: RubeePass
- Inherits:
-
Object
show all
- Defined in:
- lib/rubeepass.rb
Defined Under Namespace
Classes: AttachmentDecoder, 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
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(kdbx, password, keyfile = nil, hilight = false) ⇒ RubeePass
Returns a new instance of RubeePass.
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
# File 'lib/rubeepass.rb', line 186
def initialize(kdbx, password, keyfile = nil, hilight = false)
@@hilight = hilight
@kdbx = Pathname.new(kdbx).expand_path
@keyfile = nil
@keyfile = Pathname.new(keyfile).expand_path if (keyfile)
@password = password
if (@kdbx.nil?)
elsif (!@kdbx.exist?)
raise RubeePass::Error::FileNotFound.new(@kdbx)
elsif (!@kdbx.readable?)
raise RubeePass::Error::FileNotReadable.new(@kdbx)
end
if (@keyfile)
if (!@keyfile.exist?)
raise RubeePass::Error::FileNotFound.new(@keyfile)
elsif (!@keyfile.readable?)
raise RubeePass::Error::FileNotReadable.new(@keyfile)
end
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
|
# File 'lib/rubeepass.rb', line 258
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
#attachment_decoder ⇒ Object
Returns the value of attribute attachment_decoder.
29
30
31
|
# File 'lib/rubeepass.rb', line 29
def attachment_decoder
@attachment_decoder
end
|
#db ⇒ Object
Returns the value of attribute db.
30
31
32
|
# File 'lib/rubeepass.rb', line 30
def db
@db
end
|
#gzip ⇒ Object
Returns the value of attribute gzip.
31
32
33
|
# File 'lib/rubeepass.rb', line 31
def gzip
@gzip
end
|
#protected_decryptor ⇒ Object
Returns the value of attribute protected_decryptor.
32
33
34
|
# File 'lib/rubeepass.rb', line 32
def protected_decryptor
@protected_decryptor
end
|
#xml ⇒ Object
Returns the value of attribute xml.
33
34
35
|
# File 'lib/rubeepass.rb', line 33
def xml
@xml
end
|
Class Method Details
.hilight? ⇒ Boolean
76
77
78
79
|
# File 'lib/rubeepass.rb', line 76
def self.hilight?
@@hilight ||= false
return @@hilight
end
|
Instance Method Details
#absolute_path(to, from = "/") ⇒ Object
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
|
# File 'lib/rubeepass.rb', line 35
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
68
69
70
71
72
73
74
|
# File 'lib/rubeepass.rb', line 68
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
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
131
132
133
134
135
136
|
# File 'lib/rubeepass.rb', line 81
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
156
157
158
159
160
161
162
163
164
165
166
167
|
# File 'lib/rubeepass.rb', line 156
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
174
175
176
|
# File 'lib/rubeepass.rb', line 174
def find_group(path)
return @db.find_group(path)
end
|
#find_group_like(path) ⇒ Object
178
179
180
|
# File 'lib/rubeepass.rb', line 178
def find_group_like(path)
return @db.find_group(path, true)
end
|
#fuzzy_find(input) ⇒ Object
182
183
184
|
# File 'lib/rubeepass.rb', line 182
def fuzzy_find(input)
return @db.fuzzy_find(input)
end
|
#open ⇒ Object
276
277
278
279
280
281
282
283
284
285
286
287
288
289
|
# File 'lib/rubeepass.rb', line 276
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
461
462
463
|
# File 'lib/rubeepass.rb', line 461
def to_s
return @db.to_s
end
|
#wait_to_exit ⇒ Object
465
466
467
468
469
470
471
472
|
# File 'lib/rubeepass.rb', line 465
def wait_to_exit
return if (@thread.nil?)
begin
@thread.join
rescue Interrupt
puts
end
end
|