Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ language: ruby
cache: bundler
rvm:
- jruby-1.7.23
script:
script:
- bundle exec rspec spec
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# 2.1
- Support for LogStash 5.x and added mutex.
# 2.0.5
- Depend on logstash-core-plugin-api instead of logstash-core, removing the need to mass update plugins on major releases of logstash
# 2.0.4
- New dependency requirements for logstash-core for the 5.0 release
## 2.0.3
- fixes base64 encoding issue, adds support for random IVs
- fixes base64 encoding issue, adds support for random IVs

## 2.0.0
- Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully,
- Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully,
instead of using Thread.raise on the plugins' threads. Ref: https://github.com/elastic/logstash/pull/3895
- Dependency on logstash-core update to 2.0

19 changes: 12 additions & 7 deletions lib/logstash/filters/cipher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require "logstash/filters/base"
require "logstash/namespace"
require "openssl"
require "thread"


# This filter parses a source and apply a cipher or decipher before
Expand Down Expand Up @@ -35,7 +36,7 @@ class LogStash::Filters::Cipher < LogStash::Filters::Base
#
# NOTE: If you encounter an error message at runtime containing the following:
#
# "java.security.InvalidKeyException: Illegal key size: possibly you need to install
# "java.security.InvalidKeyException: Illegal key size: possibly you need to install
# Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files for your JRE"
#
# Please read the following: https://github.com/jruby/jruby/wiki/UnlimitedStrengthCrypto
Expand All @@ -47,7 +48,7 @@ class LogStash::Filters::Cipher < LogStash::Filters::Base
# It depends of the cipher algorithm. If your key doesn't need
# padding, don't set this parameter
#
# Example, for AES-128, we must have 16 char long key. AES-256 = 32 chars
# Example, for AES-128, we must have 16 char long key. AES-256 = 32 chars
# [source,ruby]
# filter { cipher { key_size => 16 }
#
Expand Down Expand Up @@ -136,24 +137,27 @@ class LogStash::Filters::Cipher < LogStash::Filters::Base

def register
require 'base64' if @base64
init_cipher
@semaphore = Mutex.new
@semaphore.synchronize {
init_cipher
}
end # def register


def filter(event)


@semaphore.synchronize {

#If decrypt or encrypt fails, we keep it it intact.
begin

if (event[@source].nil? || event[@source].empty?)
if (event.get(@source).nil? || event.get(@source).empty?)
@logger.debug("Event to filter, event 'source' field: " + @source + " was null(nil) or blank, doing nothing")
return
end

#@logger.debug("Event to filter", :event => event)
data = event[@source]
data = event.get(@source)
if @mode == "decrypt"
data = Base64.strict_decode64(data) if @base64 == true

Expand Down Expand Up @@ -197,7 +201,7 @@ def filter(event)

result = result.force_encoding("utf-8") if @mode == "decrypt"

event[@target]= result
event.set(@target, result)

#Is it necessary to add 'if !result.nil?' ? exception have been already catched.
#In doubt, I keep it.
Expand All @@ -209,6 +213,7 @@ def filter(event)
end

end
}
end # def filter

def init_cipher
Expand Down
5 changes: 2 additions & 3 deletions logstash-filter-cipher.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ Gem::Specification.new do |s|
s.metadata = { "logstash_plugin" => "true", "logstash_group" => "filter" }

# Gem dependencies
s.add_runtime_dependency "logstash-core-plugin-api", "~> 1.0"

s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
s.add_development_dependency 'logstash-devutils'
end

end
Loading