fluent-plugin-encrypt-1.0 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +10 -0
- data/Gemfile +4 -0
- data/LICENSE +202 -0
- data/README.md +90 -0
- data/Rakefile +14 -0
- data/bin/fluent-plugin-encrypt-genkey +19 -0
- data/fluent-plugin-encrypt.gemspec +24 -0
- data/lib/fluent/plugin/filter_encrypt.rb +79 -0
- data/mytest/encrypted.data +2 -0
- data/mytest/private.secure.pem +30 -0
- data/mytest/private_key.pem +27 -0
- data/mytest/public_key.pem +9 -0
- data/mytest/test.rb +94 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4c213d6d998e509e2be6925c4a69a07414c248573e2f7da9747a20b228834046
|
4
|
+
data.tar.gz: 4542a7f36e7a1d14f7c0afb7ca6f385e03e659b0ec10e19637846b58b30bc5f5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9eca2c8395413ade3432ba7dcfd82ebf4bcd96f55452a6ffec3043dac381a33636e2181873e1d90f3a296c54b0549df0b40ba0b1f50e8a5d6b4801f53d5bf0c2
|
7
|
+
data.tar.gz: 764937f4e064c4424841857c3a50e77bec0eb996799fbfe7f70d0d5ef4267aba5284fbede370f37210fdc1f70a55476d6194551db50a36d55e61dcc1012537a9
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
# fluent-plugin-encrypt
|
2
|
+
|
3
|
+
This is a [Fluentd](http://www.fluentd.org) filter plugin to encrypt data of specified fields using AES. This works in same way with [embulk-filter-encrypt](https://github.com/embulk/embulk-filter-encrypt).
|
4
|
+
|
5
|
+
Encrypted data is encoded using base64. For example, if you have following input records:
|
6
|
+
|
7
|
+
{"id":1, "password":"super", "comment":"a"}
|
8
|
+
{"id":2, "password":"secret", "comment":"b"}
|
9
|
+
|
10
|
+
You can apply encryption to password column and get following outputs:
|
11
|
+
|
12
|
+
{"id":1, "password":"ayxU9lMA1iASdHGy/eAlWw==", "comment":"a"}
|
13
|
+
{"id":2, "password":"v8ffsUOfspaqZ1KI7tPz+A==", "comment":"b"}
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
Install with `gem` or `fluent-gem` (or `td-agent-gem`) command:
|
18
|
+
|
19
|
+
```
|
20
|
+
$ gem install fluent-plugin-encrypt
|
21
|
+
|
22
|
+
$ fluent-gem install fluent-plugin-encrypt
|
23
|
+
```
|
24
|
+
|
25
|
+
## Configuration
|
26
|
+
|
27
|
+
Key and IV hex string generation is required for AES (CBC) encryption before configuring Fluentd. This plugin gem includes the script to do it.
|
28
|
+
|
29
|
+
### Key and IV generation
|
30
|
+
|
31
|
+
Once you installed this plugin by `gem`, the script will be executable from your shell directly. Define password for encryption at first, then execute it.
|
32
|
+
|
33
|
+
```
|
34
|
+
$ fluent-plugin-encrypt-genkey AES-256-CBC "my secret passphrase"
|
35
|
+
key=668F3B7EA156BC3C4332CDD7C5AFDD604155F152C9055B0EACDFBB7708B687BA
|
36
|
+
iv =25443F5277938A2FD21725F273345C69
|
37
|
+
```
|
38
|
+
|
39
|
+
Copy these hex strings for Fluentd configuration.
|
40
|
+
|
41
|
+
### Filter plugin configuration
|
42
|
+
|
43
|
+
An example configuration to encrypt a field (named as "device_id"):
|
44
|
+
|
45
|
+
```apache
|
46
|
+
<source>
|
47
|
+
@type forward
|
48
|
+
@label @myservice
|
49
|
+
port 24224
|
50
|
+
</source>
|
51
|
+
|
52
|
+
<label @myservice>
|
53
|
+
<filter **>
|
54
|
+
@type encrypt
|
55
|
+
algorithm aes_256_cbc # default
|
56
|
+
encrypt_key_hex 668F3B7EA156BC3C4332CDD7C5AFDD604155F152C9055B0EACDFBB7708B687BA
|
57
|
+
encrypt_iv_hex 25443F5277938A2FD21725F273345C69
|
58
|
+
key device_id
|
59
|
+
# Or, to encrypt values in some fields
|
60
|
+
# keys ["device_id","user_id","session"]
|
61
|
+
</filter>
|
62
|
+
<match **>
|
63
|
+
@type stdout
|
64
|
+
</match>
|
65
|
+
</label>
|
66
|
+
```
|
67
|
+
|
68
|
+
Available algorithms (`algorithm` in configuration) are:
|
69
|
+
|
70
|
+
* **aes\_256\_cbc** (recommended)
|
71
|
+
* aes\_192\_cbc
|
72
|
+
* aes\_128\_cbc
|
73
|
+
* aes\_256\_ecb
|
74
|
+
* aes\_192\_ecb
|
75
|
+
* aes\_128\_ecb
|
76
|
+
|
77
|
+
For `fluent-plugin-encrypt-genkey`, use names with upcased chars and `-` instead of `_` (e.g. `AES-256-CBC`).
|
78
|
+
|
79
|
+
Other configuration parameters are:
|
80
|
+
|
81
|
+
* `encrypt_key_hex`: hex string for encryption key generated by scripts (NOT PASSWORD) [required]
|
82
|
+
* `encrypt_iv_hex`: hex string for encryption iv generated by scripts (omit for some encryption mode like ECB)
|
83
|
+
* `key`: key name of fields in records to be encrypted
|
84
|
+
* `keys`: JSON format list of key names to be encrypted
|
85
|
+
|
86
|
+
## Copyright
|
87
|
+
|
88
|
+
* Copyright (c) 2016- TAGOMORI Satoshi (tagomoris)
|
89
|
+
* License
|
90
|
+
* Apache License, Version 2.0
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
require 'bundler'
|
3
|
+
Bundler::GemHelper.install_tasks
|
4
|
+
|
5
|
+
require 'rake/testtask'
|
6
|
+
|
7
|
+
Rake::TestTask.new(:test) do |test|
|
8
|
+
test.libs << 'lib' << 'test'
|
9
|
+
test.test_files = FileList['test/**/test_*.rb']
|
10
|
+
test.verbose = true
|
11
|
+
end
|
12
|
+
|
13
|
+
task :default => [:test]
|
14
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'openssl'
|
3
|
+
|
4
|
+
if ARGV.length != 2
|
5
|
+
puts "Usage: #{$0} <algorithm> <password>"
|
6
|
+
exit 1
|
7
|
+
end
|
8
|
+
|
9
|
+
cipher = OpenSSL::Cipher.new ARGV[0]
|
10
|
+
password = ARGV[1]
|
11
|
+
|
12
|
+
cipher.encrypt
|
13
|
+
iv = cipher.random_iv
|
14
|
+
salt = OpenSSL::Random.random_bytes(16)
|
15
|
+
key = OpenSSL::PKCS5.pbkdf2_hmac(password, salt, 20000, 32, OpenSSL::Digest::SHA256.new)
|
16
|
+
|
17
|
+
puts "key=#{key.unpack('H*')[0].upcase}"
|
18
|
+
puts "iv =#{iv.unpack('H*')[0].upcase}"
|
19
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "fluent-plugin-encrypt-1.0"
|
5
|
+
spec.version = "0.1.8"
|
6
|
+
spec.authors = ["TAGOMORI Satoshi"]
|
7
|
+
spec.email = ["tagomoris@gmail.com"]
|
8
|
+
|
9
|
+
spec.summary = %q{Fluentd filter plugin to encrypt fields}
|
10
|
+
spec.description = %q{This plugin converts data of specified fields, by encrypting using AES and base64 encoding for encrypted values}
|
11
|
+
spec.homepage = "https://github.com/tagomoris/fluent-plugin-encrypt"
|
12
|
+
spec.license = "Apache-2.0"
|
13
|
+
|
14
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
15
|
+
spec.bindir = "bin"
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_runtime_dependency "fluentd", ">= 0.12"
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "test-unit", "~> 3.0"
|
24
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'fluent/filter'
|
2
|
+
require 'openssl'
|
3
|
+
require 'base64'
|
4
|
+
|
5
|
+
module Fluent
|
6
|
+
class EncryptFilter < Filter
|
7
|
+
Fluent::Plugin.register_filter('encrypt', self)
|
8
|
+
|
9
|
+
SUPPORTED_ALGORITHMS = {
|
10
|
+
aes_256_cbc: { name: "AES-256-CBC", use_iv: true },
|
11
|
+
aes_256_ctr: { name: "AES-256-CTR", use_iv: true },
|
12
|
+
aes_256_cfb: { name: "AES-256-CFB", use_iv: true },
|
13
|
+
aes_192_cbc: { name: "AES-192-CBC", use_iv: true },
|
14
|
+
aes_128_cbc: { name: "AES-128-CBC", use_iv: true },
|
15
|
+
aes_256_ecb: { name: "AES-256-ECB", use_iv: false },
|
16
|
+
aes_192_ecb: { name: "AES-192-ECB", use_iv: false },
|
17
|
+
aes_128_ecb: { name: "AES-128-ECB", use_iv: false },
|
18
|
+
}
|
19
|
+
|
20
|
+
config_param :algorithm, :enum, list: SUPPORTED_ALGORITHMS.keys, default: :aes_256_cbc
|
21
|
+
config_param :encrypt_key_hex, :string
|
22
|
+
config_param :encrypt_iv_hex, :string, default: nil
|
23
|
+
|
24
|
+
config_param :key, :string, default: nil
|
25
|
+
config_param :keys, :array, default: []
|
26
|
+
|
27
|
+
attr_reader :target_keys
|
28
|
+
|
29
|
+
def configure(conf)
|
30
|
+
super
|
31
|
+
|
32
|
+
@target_keys = @keys + [@key]
|
33
|
+
if @target_keys.empty?
|
34
|
+
raise Fluent::ConfigError, "no keys specified to be encrypted"
|
35
|
+
end
|
36
|
+
|
37
|
+
algorithm = SUPPORTED_ALGORITHMS[@algorithm]
|
38
|
+
if algorithm[:use_iv] && !@encrypt_iv_hex
|
39
|
+
raise Fluent::ConfigError, "Encryption algorithm #{@algorithm} requires 'encrypt_iv_hex'"
|
40
|
+
end
|
41
|
+
|
42
|
+
@enc_key = Base64.decode64(@encrypt_key_hex)
|
43
|
+
@enc_iv = if @encrypt_iv_hex
|
44
|
+
Base64.decode64(@encrypt_iv_hex)
|
45
|
+
else
|
46
|
+
nil
|
47
|
+
end
|
48
|
+
@enc_generator = ->(){
|
49
|
+
enc = OpenSSL::Cipher.new(algorithm[:name])
|
50
|
+
enc.encrypt
|
51
|
+
enc.key = @enc_key[0..31]
|
52
|
+
enc.iv = @enc_iv[0..15] if @enc_iv
|
53
|
+
enc
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
def filter_stream(tag, es)
|
58
|
+
new_es = MultiEventStream.new
|
59
|
+
es.each do |time, record|
|
60
|
+
r = record.dup
|
61
|
+
record.each_pair do |key, value|
|
62
|
+
if @target_keys.include?(key)
|
63
|
+
r[key] = encrypt(value)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
new_es.add(time, r)
|
67
|
+
end
|
68
|
+
new_es
|
69
|
+
end
|
70
|
+
|
71
|
+
def encrypt(value)
|
72
|
+
encrypted = ""
|
73
|
+
enc = @enc_generator.call()
|
74
|
+
encrypted << enc.update(value)
|
75
|
+
encrypted << enc.final
|
76
|
+
Base64.encode64(encrypted)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
-----BEGIN RSA PRIVATE KEY-----
|
2
|
+
Proc-Type: 4,ENCRYPTED
|
3
|
+
DEK-Info: AES-128-CBC,B8EA152FD807BC4C09E4D39135663A24
|
4
|
+
|
5
|
+
Mdk35HIB4JLPLCLYG2ZAvl68TkZit9JEdGu3aVVSXg/7QEWxSjQXv4DVlNZnMhXT
|
6
|
+
6kjvSISpfc7hz2rX6Be5tQiy5rrC8o8YUykrWFMyh4VraewMznyGjdTE1U4yYf/m
|
7
|
+
cVP1kkUJjhgV/RNbD4c3K8xl7tj/pfGuU2MxCsTssgaosgr26oArYngMjzS07B5A
|
8
|
+
7nxSXvVmFugKAgHyLjTfkkO4R+dywtTc2J50ZZM1IJJq+JzoNMKmwAB9pbV6Axgo
|
9
|
+
JUuf+wPc4drUMtNA6jQz2KT8C4+vfWHLQlEVF1kTw7Q1L5JOw2gI96ZKQMp/QY5S
|
10
|
+
9u9FW+k3zmN0UmlCccu4a+f1DwtGghv2ybD7Uh2kU24ZyWw+TsjZl+BPrQnVAx9Q
|
11
|
+
P93iZf1gXD5WIsU3reT+90bXsrIifGUcrnSrq8ePRYZ+mItD48x+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sPcAx1etYhQ==
|
27
|
+
-----END RSA PRIVATE KEY-----
|
@@ -0,0 +1,9 @@
|
|
1
|
+
-----BEGIN PUBLIC KEY-----
|
2
|
+
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA5DCA0JjA6E1g61mmIy3t
|
3
|
+
27XSQyWvKRErt/VY5nzo2v5AnOBtXCLekq+DPmjpmpAplqOyqa2ducN+3bD9MjOj
|
4
|
+
JEpRMvOrCA0RNgfpBqVvJ2H0pmogA6CwNcf0UtrlJbWz7FQHyv68daO620QAR5/Q
|
5
|
+
sl/TP+CyCQtzspE+g7uzPkW0voye5HXArWma/KXzGnK343MeGLN/g9brqQ6yqume
|
6
|
+
hpvfR8KipuwTHgUex9wyTh8diOaXfbNLyq9t3lSxzkugX4LrQ66/40czwMCsn7t1
|
7
|
+
/1rwbxfNXfzi13nGUOppt9lz3wYZojENwBNToqJgKwlmSM2zc49AhjvufLEXIJtd
|
8
|
+
nQIDAQAB
|
9
|
+
-----END PUBLIC KEY-----
|
data/mytest/test.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#!/usr/bin/env ruby
|
3
|
+
require 'openssl'
|
4
|
+
require 'base64'
|
5
|
+
|
6
|
+
# cipher = OpenSSL::Cipher.new 'AES-256-CBC'
|
7
|
+
# cipher.encrypt
|
8
|
+
# iv = cipher.random_iv
|
9
|
+
|
10
|
+
# pwd = 'some hopefully not to easily guessable password'
|
11
|
+
# salt = OpenSSL::Random.random_bytes 16
|
12
|
+
# iter = 20000
|
13
|
+
# key_len = cipher.key_len
|
14
|
+
# digest = OpenSSL::Digest::SHA256.new
|
15
|
+
|
16
|
+
# key = OpenSSL::PKCS5.pbkdf2_hmac(pwd, salt, iter, key_len, digest)
|
17
|
+
# cipher.key = key
|
18
|
+
# puts "#{key.unpack('H*')[0].upcase}"
|
19
|
+
# puts "#{iv.unpack('H*')[0].upcase}"
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
# encrypted = cipher.update 'A top secret'
|
24
|
+
# encrypted << cipher.final
|
25
|
+
# puts "#{encrypted}"
|
26
|
+
|
27
|
+
# open 'encrypted.data', 'w' do |io|
|
28
|
+
# io.write encrypted
|
29
|
+
# end
|
30
|
+
|
31
|
+
# cipher = OpenSSL::Cipher.new 'AES-256-CBC'
|
32
|
+
# cipher.decrypt
|
33
|
+
# cipher.iv = iv # the one generated with #random_iv
|
34
|
+
|
35
|
+
# pwd = 'some hopefully not to easily guessable password'
|
36
|
+
# # salt = ... # the one generated above
|
37
|
+
# iter = 20000
|
38
|
+
# key_len = cipher.key_len
|
39
|
+
# digest = OpenSSL::Digest::SHA256.new
|
40
|
+
|
41
|
+
# key = OpenSSL::PKCS5.pbkdf2_hmac(pwd, salt, iter, key_len, digest)
|
42
|
+
# cipher.key = key
|
43
|
+
|
44
|
+
|
45
|
+
# decrypted = cipher.update encrypted
|
46
|
+
# decrypted << cipher.final
|
47
|
+
|
48
|
+
# puts "#{decrypted}"
|
49
|
+
|
50
|
+
enc_key = Base64.decode64('6DE95F046ABA7BC0BDFD16C9659372A7C11D18386046EB8674C038502C8C49B0')
|
51
|
+
enc_iv = Base64.decode64('BD6525736534075422B04474A3487061')
|
52
|
+
|
53
|
+
cipher = OpenSSL::Cipher.new 'AES-256-CBC'
|
54
|
+
cipher.encrypt
|
55
|
+
iv = enc_iv
|
56
|
+
|
57
|
+
|
58
|
+
iter = 20000
|
59
|
+
key_len = cipher.key_len
|
60
|
+
digest = OpenSSL::Digest::SHA256.new
|
61
|
+
|
62
|
+
key = enc_key[0..31]
|
63
|
+
cipher.key = key
|
64
|
+
cipher.iv = iv[0..15]
|
65
|
+
# puts "#{key.unpack('H*')[0].upcase}"
|
66
|
+
# puts "#{iv.unpack('H*')[0].upcase}"
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
encrypted = cipher.update 'A top secret'
|
71
|
+
encrypted << cipher.final
|
72
|
+
puts "#{encrypted}"
|
73
|
+
|
74
|
+
|
75
|
+
# cipher = OpenSSL::Cipher.new 'AES-256-CBC'
|
76
|
+
# cipher.decrypt
|
77
|
+
# # cipher.iv = enc_iv[0..16] # the one generated with #random_iv
|
78
|
+
# # cipher.iv = cipher.random_iv
|
79
|
+
|
80
|
+
# pwd = 'some hopefully not to easily guessable password'
|
81
|
+
# # # salt = ... # the one generated above
|
82
|
+
# # salt = OpenSSL::Random.random_bytes 16
|
83
|
+
# iter = 20000
|
84
|
+
# key_len = cipher.key_len
|
85
|
+
# digest = OpenSSL::Digest::SHA256.new
|
86
|
+
|
87
|
+
# key = OpenSSL::PKCS5.pbkdf2_hmac(pwd, salt, iter, key_len, digest)
|
88
|
+
# cipher.key = enc_key[0..31]
|
89
|
+
|
90
|
+
|
91
|
+
# decrypted = cipher.update encrypted
|
92
|
+
# decrypted << cipher.final
|
93
|
+
|
94
|
+
# puts "#{decrypted}"
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-encrypt-1.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.8
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- TAGOMORI Satoshi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-11-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: fluentd
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.12'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.11'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.11'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: test-unit
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: This plugin converts data of specified fields, by encrypting using AES
|
70
|
+
and base64 encoding for encrypted values
|
71
|
+
email:
|
72
|
+
- tagomoris@gmail.com
|
73
|
+
executables:
|
74
|
+
- fluent-plugin-encrypt-genkey
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- ".gitignore"
|
79
|
+
- ".travis.yml"
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/fluent-plugin-encrypt-genkey
|
85
|
+
- fluent-plugin-encrypt.gemspec
|
86
|
+
- lib/fluent/plugin/filter_encrypt.rb
|
87
|
+
- mytest/encrypted.data
|
88
|
+
- mytest/private.secure.pem
|
89
|
+
- mytest/private_key.pem
|
90
|
+
- mytest/public_key.pem
|
91
|
+
- mytest/test.rb
|
92
|
+
homepage: https://github.com/tagomoris/fluent-plugin-encrypt
|
93
|
+
licenses:
|
94
|
+
- Apache-2.0
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubygems_version: 3.1.4
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Fluentd filter plugin to encrypt fields
|
115
|
+
test_files: []
|