rubeepass 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ require "rubeepass/error"
2
+
3
+ class RubeePass::Error::InvalidGzipError < RubeePass::Error
4
+ def initialize
5
+ super("Invalid gzip format!")
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require "rubeepass/error"
2
+
3
+ class RubeePass::Error::InvalidHeaderError < RubeePass::Error
4
+ def initialize
5
+ super("Invalid header format!")
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require "rubeepass/error"
2
+
3
+ class RubeePass::Error::InvalidMagicError < RubeePass::Error
4
+ def initialize
5
+ super("Invalid magic values detected!")
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require "rubeepass/error"
2
+
3
+ class RubeePass::Error::InvalidPasswordError < RubeePass::Error
4
+ def initialize
5
+ super("Invalid password provided!")
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require "rubeepass/error"
2
+
3
+ class RubeePass::Error::InvalidProtectedDataError < RubeePass::Error
4
+ def initialize
5
+ super("Invalid protected data!")
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require "rubeepass/error"
2
+
3
+ class RubeePass::Error::InvalidProtectedStreamKeyError < RubeePass::Error
4
+ def initialize
5
+ super("Invalid protected stream key!")
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require "rubeepass/error"
2
+
3
+ class RubeePass::Error::InvalidVersionError < RubeePass::Error
4
+ def initialize
5
+ super("Invalid version detected!")
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require "rubeepass/error"
2
+
3
+ class RubeePass::Error::NotAESError < RubeePass::Error
4
+ def initialize
5
+ super("Not AES!")
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require "rubeepass/error"
2
+
3
+ class RubeePass::Error::NotSalsa20Error < RubeePass::Error
4
+ def initialize
5
+ super("Not a Salsa20 CrsAlgorithm!")
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ class RubeePass::Error < RuntimeError
2
+ end
3
+
4
+ require "rubeepass/error/invalid_gzip_error"
5
+ require "rubeepass/error/invalid_header_error"
6
+ require "rubeepass/error/invalid_magic_error"
7
+ require "rubeepass/error/invalid_password_error"
8
+ require "rubeepass/error/invalid_protected_data_error"
9
+ require "rubeepass/error/invalid_protected_stream_key_error"
10
+ require "rubeepass/error/invalid_version_error"
11
+ require "rubeepass/error/not_aes_error"
12
+ require "rubeepass/error/not_salsa20_error"
@@ -0,0 +1,133 @@
1
+ require "string"
2
+
3
+ class RubeePass::Group
4
+ include Comparable
5
+
6
+ attr_accessor :entries
7
+ attr_accessor :group
8
+ attr_accessor :groups
9
+ attr_accessor :keepass
10
+ attr_accessor :name
11
+ attr_accessor :path
12
+ attr_accessor :uuid
13
+
14
+ def ==(other)
15
+ return (self.uuid == other.uuid)
16
+ end
17
+
18
+ def <=>(other)
19
+ return (self.name.downcase <=> other.name.downcase)
20
+ end
21
+
22
+ def details(level = 0)
23
+ out = Array.new
24
+ lvl = Array.new(level, " ").join
25
+
26
+ group_details = [ "#{@name}".blue ]
27
+ group_details[0] = "#{@path}".blue if (level == 0)
28
+
29
+ group_details.each do |line|
30
+ out.push("#{lvl}#{line}")
31
+ end
32
+
33
+ @groups.values.each do |group|
34
+ out.push(group.details(level + 1))
35
+ end
36
+
37
+ @entries.values.each do |entry|
38
+ out.push(entry.details(level + 1))
39
+ end
40
+
41
+ return out.join("\n")
42
+ end
43
+
44
+ def entry_titles
45
+ return @entries.keys.sort
46
+ end
47
+
48
+ def find_group(path)
49
+ return nil if (@keepass.nil?)
50
+
51
+ path = @keepass.absolute_path(path, @path)
52
+ cwd = @keepass.db
53
+
54
+ path.split("/").each do |group|
55
+ next if (group.empty?)
56
+ if (cwd.has_group?(group))
57
+ cwd = cwd.groups[group]
58
+ else
59
+ return nil
60
+ end
61
+ end
62
+
63
+ return cwd
64
+ end
65
+
66
+ def fuzzy_find(input)
67
+ return [ [], [], [] ] if (@keepass.nil?)
68
+
69
+ input = @path if (input.nil? || input.empty?)
70
+ input = @keepass.absolute_path(input, @path)
71
+ path, target = input.rsplit("/")
72
+
73
+ new_cwd = find_group(path)
74
+ return [ input, [], [] ] if (new_cwd.nil?)
75
+
76
+ if (new_cwd.has_group?(target))
77
+ new_cwd = new_cwd.groups[target]
78
+ target = ""
79
+ input += "/"
80
+ end
81
+
82
+ group_completions = new_cwd.group_names
83
+ entry_completions = new_cwd.entry_titles
84
+
85
+ if (target.empty?)
86
+ return [ input, group_completions, entry_completions ]
87
+ end
88
+
89
+ group_completions.delete_if do |group|
90
+ !group.downcase.start_with?(target.downcase)
91
+ end
92
+ entry_completions.delete_if do |entry|
93
+ !entry.downcase.start_with?(target.downcase)
94
+ end
95
+
96
+ return [ input, group_completions, entry_completions ]
97
+ end
98
+
99
+ def group_names
100
+ return @groups.keys.sort
101
+ end
102
+
103
+ def has_entry?(title)
104
+ entry_titles.each do |entry|
105
+ return true if (title.downcase == entry.downcase)
106
+ end
107
+ return false
108
+ end
109
+
110
+ def has_group?(name)
111
+ group_names.each do |group|
112
+ return true if (name.downcase == group.downcase)
113
+ end
114
+ return false
115
+ end
116
+
117
+ def initialize(params)
118
+ @entries = Hash.new
119
+ @group = params.fetch("Group", nil)
120
+ @groups = Hash.new
121
+ @keepass = params.fetch("Keepass", nil)
122
+ @name = params.fetch("Name", "")
123
+ @uuid = params.fetch("UUID", "")
124
+
125
+ @path = @name
126
+ @path = "#{@group.path}/#{@name}" if (@group)
127
+ @path.gsub!(%r{^//}, "/")
128
+ end
129
+
130
+ def to_s
131
+ return details
132
+ end
133
+ end
@@ -0,0 +1,30 @@
1
+ require "salsa20"
2
+
3
+ class RubeePass::ProtectedDecryptor
4
+ def add_to_stream(str)
5
+ @ciphertext.push(str)
6
+ return (@ciphertext.length - 1)
7
+ end
8
+
9
+ def get_password(index)
10
+ return nil if (@iv.nil? || @key.nil?)
11
+ return nil if ((index < 0) || (index >= @ciphertext.length))
12
+
13
+ plaintext = Salsa20.new(@key, @iv).decrypt(@ciphertext.join)
14
+
15
+ start = 0
16
+ index.times do |i|
17
+ start += @ciphertext[i].length
18
+ end
19
+
20
+ stop = start + @ciphertext[index].length
21
+
22
+ return plaintext[start...stop]
23
+ end
24
+
25
+ def initialize(key, iv)
26
+ @ciphertext = Array.new
27
+ @iv = iv
28
+ @key = key
29
+ end
30
+ end