ronin-support 1.0.1 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog.md +38 -0
- data/README.md +0 -1
- data/lib/ronin/support/archive/core_ext/file.rb +43 -0
- data/lib/ronin/support/archive/core_ext.rb +1 -1
- data/lib/ronin/support/binary/array.rb +1 -1
- data/lib/ronin/support/binary/buffer.rb +3 -3
- data/lib/ronin/support/binary/core_ext.rb +2 -0
- data/lib/ronin/support/binary/cstring.rb +43 -0
- data/lib/ronin/support/binary/ctypes/array_type.rb +1 -1
- data/lib/ronin/support/binary/ctypes/os/bsd.rb +1 -1
- data/lib/ronin/support/binary/ctypes/unbounded_array_type.rb +1 -1
- data/lib/ronin/support/binary/packet.rb +77 -0
- data/lib/ronin/support/binary/stack.rb +3 -3
- data/lib/ronin/support/binary/template.rb +1 -5
- data/lib/ronin/support/binary.rb +1 -0
- data/lib/ronin/support/cli/io_shell.rb +2 -0
- data/lib/ronin/support/compression/core_ext/file.rb +16 -0
- data/lib/ronin/support/core_ext/kernel.rb +0 -4
- data/lib/ronin/support/crypto/cert.rb +17 -9
- data/lib/ronin/support/crypto/core_ext/file.rb +32 -0
- data/lib/ronin/support/crypto/core_ext/string.rb +34 -2
- data/lib/ronin/support/encoding/base16.rb +1 -1
- data/lib/ronin/support/encoding/base32.rb +1 -1
- data/lib/ronin/support/encoding/c/core_ext/string.rb +1 -1
- data/lib/ronin/support/encoding/c.rb +2 -2
- data/lib/ronin/support/encoding/core_ext/string.rb +2 -2
- data/lib/ronin/support/encoding/hex/core_ext/string.rb +1 -1
- data/lib/ronin/support/encoding/hex.rb +2 -2
- data/lib/ronin/support/encoding/js.rb +1 -1
- data/lib/ronin/support/encoding/powershell.rb +1 -1
- data/lib/ronin/support/encoding/quoted_printable.rb +3 -1
- data/lib/ronin/support/encoding/ruby.rb +1 -1
- data/lib/ronin/support/encoding/uuencoding.rb +3 -1
- data/lib/ronin/support/encoding/xml.rb +1 -1
- data/lib/ronin/support/network/dns/mixin.rb +2 -10
- data/lib/ronin/support/network/http/core_ext/uri/http.rb +8 -0
- data/lib/ronin/support/network/ip.rb +45 -14
- data/lib/ronin/support/network/ip_range.rb +4 -4
- data/lib/ronin/support/network/ssl/mixin.rb +2 -0
- data/lib/ronin/support/path.rb +1 -1
- data/lib/ronin/support/text/homoglyph/core_ext/string.rb +33 -0
- data/lib/ronin/support/text/patterns/network.rb +20 -20
- data/lib/ronin/support/text/random/mixin.rb +17 -17
- data/lib/ronin/support/text/random.rb +23 -23
- data/lib/ronin/support/text/typo/core_ext/string.rb +24 -0
- data/lib/ronin/support/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f47bb5e6e9e8b720f2b2e66cfd1eb49bcb4562e5ed0025a3ed491ee7e39f106
|
4
|
+
data.tar.gz: a68c5f263d3d7caf40f789354e51a977ada25c52cb7a93f58c4c10208c40da67
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 302af7c9324ba08daff8107236734c211b10f969723f55cac2843ec52a5e367357c1b3c06d4138215553960a994ae4c3338e3a4302105979fedb1dac51b2cc20
|
7
|
+
data.tar.gz: 542b8b0d1caab51fce5fedf516b3b849c2a673492995916db6a43b3522090cd8bb1acc1b3200741832153e874522fcd60eae76f74e2aa90bb76d57dafb6daa1e
|
data/ChangeLog.md
CHANGED
@@ -1,3 +1,41 @@
|
|
1
|
+
### 1.0.3 / 2023-09-19
|
2
|
+
|
3
|
+
* {Ronin::Support::Crypto::Cert::Name#entries} now returns UTF-8 encoded
|
4
|
+
Strings.
|
5
|
+
* {Ronin::Support::Crypto::Cert.Name} now passes through
|
6
|
+
{Ronin::Support::Crypto::Cert::Name} objects instead of copying them.
|
7
|
+
* Fixed a bug in {Ronin::Support::Crypto::Cert.generate} when it is given a
|
8
|
+
`OpenSSL::PKey::EC` signing key.
|
9
|
+
* Fixed a bug in {Ronin::Support::Network::SSL::Mixin#ssl_connect} where the
|
10
|
+
`OpenSSL::SSL::SSLSocket#hostname` attribute was not being set to the
|
11
|
+
host being connected to, which prevented connecting to TLS servers that use
|
12
|
+
SNI.
|
13
|
+
* Fixed {Ronin::Support::Network::IP#set} to return `self`.
|
14
|
+
* Fixed {Ronin::Support::Network::IP#inspect} to call the lazy-initialized
|
15
|
+
{Ronin::Support::Network::IP#address} method instead of the `@address`
|
16
|
+
instance variable directly.
|
17
|
+
|
18
|
+
### 1.0.2 / 2023-06-09
|
19
|
+
|
20
|
+
* Fixed a bug in {Ronin::Support::Encoding::Base32.decode},
|
21
|
+
{Ronin::Support::Encoding::Hex.unescape},
|
22
|
+
{Ronin::Support::Encoding::C.unescape},
|
23
|
+
{Ronin::Support::Encoding::JS.unescape},
|
24
|
+
{Ronin::Support::Encoding::PowerShell.unescape},
|
25
|
+
{Ronin::Support::Encoding::Ruby.unescape},
|
26
|
+
{Ronin::Support::Encoding::XML.unescape},
|
27
|
+
{Ronin::Support::Path#join}, {String#encode_bytes}, and {String#encode_chars}
|
28
|
+
where ASCII-bit Strings were always being returned instead of UTF-8 Strings.
|
29
|
+
* Fixed a bug where {Ronin::Support::Network::IP#address} was being improperly
|
30
|
+
cached.
|
31
|
+
* Added missing `require` for {File.tar}, {File.untar}, {File.zip}, and
|
32
|
+
{File.unzip} core-ext methods.
|
33
|
+
* Added missing `require` for {Integer#pack} and {Float#pack} core-ext methods.
|
34
|
+
* No longer include {Ronin::Support::Mixin} into {Kernel} which caused Mixin
|
35
|
+
methods to be included into *every* Class and object.
|
36
|
+
* Added more example code to documentation.
|
37
|
+
* Documentation fixes.
|
38
|
+
|
1
39
|
### 1.0.1 / 2023-03-01
|
2
40
|
|
3
41
|
* {Ronin::Support::Network::HTTP.connect_uri} can now infer when to enable
|
data/README.md
CHANGED
@@ -8,7 +8,6 @@
|
|
8
8
|
* [Issues](https://github.com/ronin-rb/ronin-support/issues)
|
9
9
|
* [Documentation](https://ronin-rb.dev/docs/ronin-support/frames)
|
10
10
|
* [Discord](https://discord.gg/6WAb3PsVX9) |
|
11
|
-
[Twitter](https://twitter.com/ronin_rb) |
|
12
11
|
[Mastodon](https://infosec.exchange/@ronin_rb)
|
13
12
|
|
14
13
|
## Description
|
@@ -38,6 +38,22 @@ class File
|
|
38
38
|
# @return [Ronin::Support::Archive::Tar::Reader]
|
39
39
|
# The tar reader object.
|
40
40
|
#
|
41
|
+
# @example Enumerating over each entry in the tar archive:
|
42
|
+
# File.untar('file.tar') do |tar|
|
43
|
+
# tar.each do |entry|
|
44
|
+
# puts entry.full_name
|
45
|
+
# puts '-' * 80
|
46
|
+
# puts entry.read
|
47
|
+
# puts '-' * 80
|
48
|
+
# end
|
49
|
+
# end
|
50
|
+
#
|
51
|
+
# @example Reads a specific file from the tar archive:
|
52
|
+
# File.untar('file.tar') do |tar|
|
53
|
+
# data = tar.read('foo.txt')
|
54
|
+
# # ...
|
55
|
+
# end
|
56
|
+
#
|
41
57
|
# @api public
|
42
58
|
#
|
43
59
|
# @since 1.0.0
|
@@ -61,6 +77,12 @@ class File
|
|
61
77
|
# @return [Ronin::Support::Archive::Tar::Writer]
|
62
78
|
# The tar writer object.
|
63
79
|
#
|
80
|
+
# @example
|
81
|
+
# File.tar('output.tar') do |tar|
|
82
|
+
# tar.mkdir('foo')
|
83
|
+
# tar.add_file('foo/bar.txt','Hello World!')
|
84
|
+
# end
|
85
|
+
#
|
64
86
|
# @api public
|
65
87
|
#
|
66
88
|
# @since 1.0.0
|
@@ -84,6 +106,22 @@ class File
|
|
84
106
|
# @return [Ronin::Support::Archive::Zip::Reader]
|
85
107
|
# The zip reader object.
|
86
108
|
#
|
109
|
+
# @example Enumerating over each file in a zip archive:
|
110
|
+
# File.unzip('file.zip') do |zip|
|
111
|
+
# zip.each do |entry|
|
112
|
+
# puts entry.name
|
113
|
+
# puts '-' * 80
|
114
|
+
# puts entry.read
|
115
|
+
# puts '-' * 80
|
116
|
+
# end
|
117
|
+
# end
|
118
|
+
#
|
119
|
+
# @example Reads a specific file from a zip archive:
|
120
|
+
# File.unzip('file.zip') do |zip|
|
121
|
+
# data = zip.read('foo.txt')
|
122
|
+
# # ...
|
123
|
+
# end
|
124
|
+
#
|
87
125
|
# @api public
|
88
126
|
#
|
89
127
|
# @since 1.0.0
|
@@ -107,6 +145,11 @@ class File
|
|
107
145
|
# @return [Ronin::Support::Archive::Zip::Writer]
|
108
146
|
# The zip writer object.
|
109
147
|
#
|
148
|
+
# @example
|
149
|
+
# File.zip('output.zip') do |zip|
|
150
|
+
# zip.add_file('foo/bar.txt','Hello World!')
|
151
|
+
# end
|
152
|
+
#
|
110
153
|
# @api public
|
111
154
|
#
|
112
155
|
# @since 1.0.0
|
@@ -35,7 +35,7 @@ module Ronin
|
|
35
35
|
#
|
36
36
|
# Creating an array of `int32`s:
|
37
37
|
#
|
38
|
-
# array = Binary::Array.new(:int32, 4)
|
38
|
+
# array = Binary::Binary::Array.new(:int32, 4)
|
39
39
|
# # => #<Ronin::Support::Binary::Binary::Array: "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00">
|
40
40
|
# array[0] = 0x11111111
|
41
41
|
# array[1] = 0x22222222
|
@@ -30,7 +30,7 @@ module Ronin
|
|
30
30
|
#
|
31
31
|
# Writing bytes into an empty buffer:
|
32
32
|
#
|
33
|
-
# buffer = Buffer.new(10)
|
33
|
+
# buffer = Binary::Buffer.new(10)
|
34
34
|
# # => #<Ronin::Support::Binary::Buffer: "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00">
|
35
35
|
# buffer[0] = 0x41
|
36
36
|
# buffer[1] = 0x42
|
@@ -40,7 +40,7 @@ module Ronin
|
|
40
40
|
#
|
41
41
|
# Writing different types of data to a buffer:
|
42
42
|
#
|
43
|
-
# buffer = Buffer.new(16)
|
43
|
+
# buffer = Binary::Buffer.new(16)
|
44
44
|
# # => #<Ronin::Support::Binary::Buffer: "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00">
|
45
45
|
# buffer.put_uint32(0,0x11223344)
|
46
46
|
# buffer.put_int32(4,-1)
|
@@ -51,7 +51,7 @@ module Ronin
|
|
51
51
|
#
|
52
52
|
# Creating a buffer from an existing String:
|
53
53
|
#
|
54
|
-
# buffer = Buffer.new("\x41\x00\x00\x00\x42\x00\x00\x00")
|
54
|
+
# buffer = Binary::Buffer.new("\x41\x00\x00\x00\x42\x00\x00\x00")
|
55
55
|
# # => #<Ronin::Support::Binary::Buffer: "A\u0000\u0000\u0000B\u0000\u0000\u0000">
|
56
56
|
# buffer.get_uint32(0)
|
57
57
|
# # => 65
|
@@ -16,6 +16,8 @@
|
|
16
16
|
# along with ronin-support. If not, see <https://www.gnu.org/licenses/>.
|
17
17
|
#
|
18
18
|
|
19
|
+
require 'ronin/support/binary/core_ext/integer'
|
20
|
+
require 'ronin/support/binary/core_ext/float'
|
19
21
|
require 'ronin/support/binary/core_ext/string'
|
20
22
|
require 'ronin/support/binary/core_ext/array'
|
21
23
|
require 'ronin/support/binary/core_ext/io'
|
@@ -24,6 +24,49 @@ module Ronin
|
|
24
24
|
#
|
25
25
|
# Represents a null terminated C string.
|
26
26
|
#
|
27
|
+
# ## Examples
|
28
|
+
#
|
29
|
+
# ### Initializing C Strings
|
30
|
+
#
|
31
|
+
# From a String:
|
32
|
+
#
|
33
|
+
# str = Binary::CString.new("hello ")
|
34
|
+
# # => #<Ronin::Support::Binary::CString:0x00007fc94ba577f8 @string="hello \u0000">
|
35
|
+
#
|
36
|
+
# From a binary C string:
|
37
|
+
#
|
38
|
+
# str = Binary::CString.new("world\0".b)
|
39
|
+
# # => #<Ronin::Support::Binary::CString:0x00007fc94ba06f88 @string="world\u0000">
|
40
|
+
#
|
41
|
+
# From characters:
|
42
|
+
#
|
43
|
+
# str = Binary::CString['A', 'B', 'C']
|
44
|
+
# # => #<Ronin::Support::Binary::CString:0x00007fc94ba6f268 @string="ABC\x00">
|
45
|
+
#
|
46
|
+
# ### Modifying C Strings
|
47
|
+
#
|
48
|
+
# Concating Strings to a C String:
|
49
|
+
#
|
50
|
+
# str = Binary::CString.new("hello ")
|
51
|
+
# str.concat("world")
|
52
|
+
# # => #<Ronin::Support::Binary::CString:0x00007fc94b978df0 @string="hello world\u0000">
|
53
|
+
# str.to_s
|
54
|
+
# # => "hello world"
|
55
|
+
#
|
56
|
+
# Appending two C Strings:
|
57
|
+
#
|
58
|
+
# str1 = Binary::CString.new("hello ")
|
59
|
+
# str2 = Binary::CString.new("world\0")
|
60
|
+
# str = str1 + str2
|
61
|
+
# # => #<Ronin::Support::Binary::CString:0x00007fc94b9523f8 @string="hello world\u0000">
|
62
|
+
#
|
63
|
+
# Setting characters:
|
64
|
+
#
|
65
|
+
# str = Binary::CString.new("hello")
|
66
|
+
# str[0] = 'X'
|
67
|
+
# str.to_s
|
68
|
+
# # => "Xello"
|
69
|
+
#
|
27
70
|
# @api public
|
28
71
|
#
|
29
72
|
# @since 1.0.0
|
@@ -24,6 +24,83 @@ module Ronin
|
|
24
24
|
#
|
25
25
|
# Represents a network packet in network byte-order.
|
26
26
|
#
|
27
|
+
# ## Examples
|
28
|
+
#
|
29
|
+
# ### Defining Packet Fields
|
30
|
+
#
|
31
|
+
# class Packet < Ronin::Support::Binary::Packet
|
32
|
+
#
|
33
|
+
# member :flags, :uint8
|
34
|
+
# member :src, :uint32
|
35
|
+
# member :dst, :uint32
|
36
|
+
# member :length, :uint32
|
37
|
+
#
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
# ### Initializing Packets
|
41
|
+
#
|
42
|
+
# From a Hash:
|
43
|
+
#
|
44
|
+
# packet = Packet.new(
|
45
|
+
# flags: 0x0c,
|
46
|
+
# src: IPAddr.new('1.2.3.4').to_i,
|
47
|
+
# dst: IPAddr.new('5.6.7.8').to_i,
|
48
|
+
# length: 1024
|
49
|
+
# )
|
50
|
+
#
|
51
|
+
# From a buffer:
|
52
|
+
#
|
53
|
+
# packet = Packet.unpack("\f\x01\x02\x03\x04\x05\x06\a\b\x00\x00\x04\x00")
|
54
|
+
#
|
55
|
+
# ### Reading Fields
|
56
|
+
#
|
57
|
+
# packet = Packet.new("\f\x01\x02\x03\x04\x05\x06\a\b\x00\x00\x04\x00")
|
58
|
+
# packet[:flags]
|
59
|
+
# # => 12
|
60
|
+
# packet.flags
|
61
|
+
# # => 12
|
62
|
+
#
|
63
|
+
# ### Packing Packets
|
64
|
+
#
|
65
|
+
# class Packet < Ronin::Support::Binary::Packet
|
66
|
+
#
|
67
|
+
# member :flags, :uint8
|
68
|
+
# member :src, :uint32
|
69
|
+
# member :dst, :uint32
|
70
|
+
# member :length, :uint32
|
71
|
+
#
|
72
|
+
# end
|
73
|
+
#
|
74
|
+
# packet = Packet.new(
|
75
|
+
# flags: 0x0c,
|
76
|
+
# src: IPAddr.new('1.2.3.4').to_i,
|
77
|
+
# dst: IPAddr.new('5.6.7.8').to_i,
|
78
|
+
# length: 1024
|
79
|
+
# )
|
80
|
+
# packet.pack
|
81
|
+
# # => "\f\x01\x02\x03\x04\x05\x06\a\b\x00\x00\x04\x00"
|
82
|
+
#
|
83
|
+
# ### Unpacking Packets
|
84
|
+
#
|
85
|
+
# class Packet < Ronin::Support::Binary::Packet
|
86
|
+
#
|
87
|
+
# member :flags, :uint8
|
88
|
+
# member :src, :uint32
|
89
|
+
# member :dst, :uint32
|
90
|
+
# member :length, :uint32
|
91
|
+
#
|
92
|
+
# end
|
93
|
+
#
|
94
|
+
# packet = Packet.unpack("\f\x01\x02\x03\x04\x05\x06\a\b\x00\x00\x04\x00")
|
95
|
+
# packet.flags
|
96
|
+
# # => 12
|
97
|
+
# packet.src
|
98
|
+
# # => 16909060
|
99
|
+
# packet.dst
|
100
|
+
# # => 84281096
|
101
|
+
# packet.length
|
102
|
+
# # => 1024
|
103
|
+
#
|
27
104
|
class Packet < Binary::Struct
|
28
105
|
|
29
106
|
platform endian: :net
|
@@ -36,7 +36,7 @@ module Ronin
|
|
36
36
|
#
|
37
37
|
# Creating a new stack:
|
38
38
|
#
|
39
|
-
# stack = Stack.new
|
39
|
+
# stack = Binary::Stack.new
|
40
40
|
# # => #<Ronin::Support::Binary::Stack: "">
|
41
41
|
# stack.push 0x41414141
|
42
42
|
# # => #<Ronin::Support::Binary::Stack: "AAAA\x00\x00\x00\x00">
|
@@ -49,7 +49,7 @@ module Ronin
|
|
49
49
|
#
|
50
50
|
# Creating a stack from an existing String:
|
51
51
|
#
|
52
|
-
# stack = Stack.new("\x41\x00\x00\x00\x00\x00\x00\x00\x42\x00\x00\x00\x00\x00\x00\x00")
|
52
|
+
# stack = Binary::Stack.new("\x41\x00\x00\x00\x00\x00\x00\x00\x42\x00\x00\x00\x00\x00\x00\x00")
|
53
53
|
# stack[0]
|
54
54
|
# # => 65
|
55
55
|
# stack[8]
|
@@ -125,7 +125,7 @@ module Ronin
|
|
125
125
|
@size = @string.bytesize
|
126
126
|
@length = @size / @machine_word.size
|
127
127
|
else
|
128
|
-
@string = String.new
|
128
|
+
@string = String.new
|
129
129
|
@size = 0
|
130
130
|
@length = 0
|
131
131
|
end
|
@@ -36,10 +36,6 @@ module Ronin
|
|
36
36
|
# * `:int16` - signed 16-bit integer.
|
37
37
|
# * `:int32` - signed 32-bit integer.
|
38
38
|
# * `:int64` - signed 64-bit integer.
|
39
|
-
# * `:uint16_le` - unsigned 16-bit integer, little endian.
|
40
|
-
# * `:uint32_le` - unsigned 32-bit integer, little endian.
|
41
|
-
# * `:uint16_be` - unsigned 16-bit integer, big endian.
|
42
|
-
# * `:uint32_be` - unsigned 32-bit integer, big endian.
|
43
39
|
# * `:uchar` - unsigned character.
|
44
40
|
# * `:ushort` - unsigned short integer, native endian.
|
45
41
|
# * `:uint` - unsigned integer, native endian.
|
@@ -209,7 +205,7 @@ module Ronin
|
|
209
205
|
|
210
206
|
values.pack(@pack_string)
|
211
207
|
else
|
212
|
-
buffer = String.new
|
208
|
+
buffer = String.new
|
213
209
|
|
214
210
|
@types.each do |type|
|
215
211
|
# shift off the next value and pack it
|
data/lib/ronin/support/binary.rb
CHANGED
@@ -19,6 +19,7 @@
|
|
19
19
|
require 'ronin/support/binary/core_ext'
|
20
20
|
require 'ronin/support/binary/template'
|
21
21
|
require 'ronin/support/binary/buffer'
|
22
|
+
require 'ronin/support/binary/cstring'
|
22
23
|
require 'ronin/support/binary/array'
|
23
24
|
require 'ronin/support/binary/stack'
|
24
25
|
require 'ronin/support/binary/struct'
|
@@ -36,6 +36,13 @@ class File
|
|
36
36
|
# @return [Ronin::Support::Compression::Gzip::Reader]
|
37
37
|
# The gzip reader object.
|
38
38
|
#
|
39
|
+
# @example
|
40
|
+
# File.gunzip('wordlist.gz') do |gz|
|
41
|
+
# gz.each_line do |line|
|
42
|
+
# # ...
|
43
|
+
# end
|
44
|
+
# end
|
45
|
+
#
|
39
46
|
# @api public
|
40
47
|
#
|
41
48
|
# @since 1.0.0
|
@@ -59,6 +66,15 @@ class File
|
|
59
66
|
# @return [Ronin::Support::Compression::Gzip::Writer]
|
60
67
|
# The gzip writer object.
|
61
68
|
#
|
69
|
+
# @example
|
70
|
+
# File.gunzip('file.gz') do |gz|
|
71
|
+
# # gzip header info
|
72
|
+
# gz.mtime = Time.now
|
73
|
+
# gz.orig_name = 'file.txt'
|
74
|
+
#
|
75
|
+
# gz.write('Hello World!')
|
76
|
+
# end
|
77
|
+
#
|
62
78
|
# @api public
|
63
79
|
#
|
64
80
|
# @since 1.0.0
|
@@ -18,6 +18,7 @@
|
|
18
18
|
|
19
19
|
require 'ronin/support/crypto/openssl'
|
20
20
|
require 'ronin/support/crypto/key/rsa'
|
21
|
+
require 'ronin/support/crypto/key/ec'
|
21
22
|
|
22
23
|
module Ronin
|
23
24
|
module Support
|
@@ -83,7 +84,9 @@ module Ronin
|
|
83
84
|
# @return [Hash{String => String}]
|
84
85
|
#
|
85
86
|
def entries
|
86
|
-
@entries ||= to_a.to_h
|
87
|
+
@entries ||= to_a.to_h do |(oid,value,type)|
|
88
|
+
[oid, value && value.force_encoding(Encoding::UTF_8)]
|
89
|
+
end
|
87
90
|
end
|
88
91
|
|
89
92
|
alias to_h entries
|
@@ -160,7 +163,7 @@ module Ronin
|
|
160
163
|
#
|
161
164
|
# Coerces a value into a {Name} object.
|
162
165
|
#
|
163
|
-
# @param [String, Hash, OpenSSL::X509::Name] name
|
166
|
+
# @param [String, Hash, OpenSSL::X509::Name, Name] name
|
164
167
|
# The name value to coerce.
|
165
168
|
#
|
166
169
|
# @return [Cert::Name]
|
@@ -170,8 +173,9 @@ module Ronin
|
|
170
173
|
#
|
171
174
|
def self.Name(name)
|
172
175
|
case name
|
173
|
-
when String
|
174
|
-
when Hash
|
176
|
+
when String then Name.parse(name)
|
177
|
+
when Hash then Name.build(**name)
|
178
|
+
when Name then name
|
175
179
|
when OpenSSL::X509::Name
|
176
180
|
new_name = Name.allocate
|
177
181
|
new_name.send(:initialize_copy,name)
|
@@ -269,7 +273,7 @@ module Ronin
|
|
269
273
|
# key: key,
|
270
274
|
# subject: {
|
271
275
|
# common_name: 'localhost',
|
272
|
-
# organization: 'Test Co
|
276
|
+
# organization: 'Test Co.',
|
273
277
|
# organizational_unit: 'Test Dept',
|
274
278
|
# locality: 'Test City',
|
275
279
|
# state: 'XX',
|
@@ -288,7 +292,7 @@ module Ronin
|
|
288
292
|
# key: ca_key,
|
289
293
|
# subject: {
|
290
294
|
# common_name: 'Test CA',
|
291
|
-
# organization: 'Test CA, Inc
|
295
|
+
# organization: 'Test CA, Inc.',
|
292
296
|
# organizational_unit: 'Test Dept',
|
293
297
|
# locality: 'Test City',
|
294
298
|
# state: 'XX',
|
@@ -309,7 +313,7 @@ module Ronin
|
|
309
313
|
# ca_cert: ca_cert,
|
310
314
|
# subject: {
|
311
315
|
# common_name: 'test.com',
|
312
|
-
# organization: 'Test Co
|
316
|
+
# organization: 'Test Co.',
|
313
317
|
# organizational_unit: 'Test Dept',
|
314
318
|
# locality: 'Test City',
|
315
319
|
# state: 'XX',
|
@@ -343,7 +347,10 @@ module Ronin
|
|
343
347
|
|
344
348
|
cert.not_before = not_before
|
345
349
|
cert.not_after = not_after
|
346
|
-
cert.public_key = key
|
350
|
+
cert.public_key = case key
|
351
|
+
when OpenSSL::PKey::EC then key
|
352
|
+
else key.public_key
|
353
|
+
end
|
347
354
|
cert.subject = Name(subject) if subject
|
348
355
|
cert.issuer = if ca_cert then ca_cert.subject
|
349
356
|
else cert.subject
|
@@ -491,7 +498,7 @@ module Ronin
|
|
491
498
|
#
|
492
499
|
# Coerces a value into a {Cert} object.
|
493
500
|
#
|
494
|
-
# @param [String, OpenSSL::X509::Certificate] cert
|
501
|
+
# @param [String, OpenSSL::X509::Certificate, Cert] cert
|
495
502
|
# The certificate String or `OpenSSL::X509::Certificate` value.
|
496
503
|
#
|
497
504
|
# @return [Cert]
|
@@ -505,6 +512,7 @@ module Ronin
|
|
505
512
|
def self.Cert(cert)
|
506
513
|
case cert
|
507
514
|
when String then Cert.parse(cert)
|
515
|
+
when Cert then cert
|
508
516
|
when OpenSSL::X509::Certificate
|
509
517
|
new_cert = Cert.allocate
|
510
518
|
new_cert.send(:initialize_copy,cert)
|
@@ -224,6 +224,10 @@ class File
|
|
224
224
|
# @return [String]
|
225
225
|
# The encrypted data.
|
226
226
|
#
|
227
|
+
# @example
|
228
|
+
# File.encrypt('file.txt', 'aes-256-cbc', password: 's3cr3t')
|
229
|
+
# # => "..."
|
230
|
+
#
|
227
231
|
# @see http://rubydoc.info/stdlib/openssl/OpenSSL/Cipher
|
228
232
|
#
|
229
233
|
# @since 0.6.0
|
@@ -281,6 +285,10 @@ class File
|
|
281
285
|
# @return [String]
|
282
286
|
# The decrypted data.
|
283
287
|
#
|
288
|
+
# @example
|
289
|
+
# File.decrypt('encrypted.bin', 'aes-256-cbc', password: 's3cr3t')
|
290
|
+
# # => "..."
|
291
|
+
#
|
284
292
|
# @see http://rubydoc.info/stdlib/openssl/OpenSSL/Cipher
|
285
293
|
#
|
286
294
|
# @since 0.6.0
|
@@ -338,6 +346,10 @@ class File
|
|
338
346
|
# @raise [ArgumentError]
|
339
347
|
# Either the the `key:` or `password:` keyword argument must be given.
|
340
348
|
#
|
349
|
+
# @example
|
350
|
+
# File.aes_encrypt('file.txt', key_size: 256, password: 's3cr3t')
|
351
|
+
# # => "..."
|
352
|
+
#
|
341
353
|
# @since 1.0.0
|
342
354
|
#
|
343
355
|
def self.aes_encrypt(path, block_size: 16384, output: nil, **kwargs,&block)
|
@@ -390,6 +402,10 @@ class File
|
|
390
402
|
# @raise [ArgumentError]
|
391
403
|
# Either the the `key:` or `password:` keyword argument must be given.
|
392
404
|
#
|
405
|
+
# @example
|
406
|
+
# File.aes_decrypt('encrypted.bin', key_size: 256, password: 's3cr3t')
|
407
|
+
# # => "..."
|
408
|
+
#
|
393
409
|
# @since 1.0.0
|
394
410
|
#
|
395
411
|
def self.aes_decrypt(path, block_size: 16384, output: nil, **kwargs,&block)
|
@@ -439,6 +455,10 @@ class File
|
|
439
455
|
# @raise [ArgumentError]
|
440
456
|
# Either the the `key:` or `password:` keyword argument must be given.
|
441
457
|
#
|
458
|
+
# @example
|
459
|
+
# File.aes128_encrypt('file.txt', password: 's3cr3t')
|
460
|
+
# # => "..."
|
461
|
+
#
|
442
462
|
# @since 1.0.0
|
443
463
|
#
|
444
464
|
def self.aes128_encrypt(path, block_size: 16384, output: nil, **kwargs,&block)
|
@@ -488,6 +508,10 @@ class File
|
|
488
508
|
# @raise [ArgumentError]
|
489
509
|
# Either the the `key:` or `password:` keyword argument must be given.
|
490
510
|
#
|
511
|
+
# @example
|
512
|
+
# File.aes256_decrypt('encrypted.bin', password: 's3cr3t')
|
513
|
+
# # => "..."
|
514
|
+
#
|
491
515
|
# @since 1.0.0
|
492
516
|
#
|
493
517
|
def self.aes128_decrypt(path, block_size: 16384, output: nil, **kwargs,&block)
|
@@ -537,6 +561,10 @@ class File
|
|
537
561
|
# @raise [ArgumentError]
|
538
562
|
# Either the the `key:` or `password:` keyword argument must be given.
|
539
563
|
#
|
564
|
+
# @example
|
565
|
+
# File.aes256_encrypt('file.txt', password: 's3cr3t')
|
566
|
+
# # => "..."
|
567
|
+
#
|
540
568
|
# @since 1.0.0
|
541
569
|
#
|
542
570
|
def self.aes256_encrypt(path, block_size: 16384, output: nil, **kwargs,&block)
|
@@ -586,6 +614,10 @@ class File
|
|
586
614
|
# @raise [ArgumentError]
|
587
615
|
# Either the the `key:` or `password:` keyword argument must be given.
|
588
616
|
#
|
617
|
+
# @example
|
618
|
+
# File.aes256_decrypt('encrypted.bin', password: 's3cr3t')
|
619
|
+
# # => "..."
|
620
|
+
#
|
589
621
|
# @since 1.0.0
|
590
622
|
#
|
591
623
|
def self.aes256_decrypt(path, block_size: 16384, output: nil, **kwargs,&block)
|