Skip to content

Commit

Permalink
make openssl digest objects thread local (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsvd authored Nov 23, 2018
1 parent aa7d522 commit 5fe864d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 3.2.1
- Fixed concurrent SHA fingerprinting by making the instances thread local

## 3.2.0
- Added support for non-keyed, regular hash functions [#18](https://github.com/logstash-plugins/logstash-filter-fingerprint/issues/18)

Expand Down
17 changes: 12 additions & 5 deletions lib/logstash/filters/fingerprint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ class << self; alias_method :fingerprint, :fingerprint_murmur3; end
# nothing
else
class << self; alias_method :fingerprint, :fingerprint_openssl; end
@digest = select_digest(@method)
end
end

Expand Down Expand Up @@ -153,19 +152,27 @@ def fingerprint_ipv4_network(ip_string)
end

def fingerprint_openssl(data)
# since OpenSSL::Digest instances aren't thread safe, we must ensure that
# each pipeline worker thread gets its own instance.
# Also, since a logstash pipeline may contain multiple fingerprint filters
# we must include the id in the thread local variable name, so that we can
# store multiple digest instances
digest_string = "digest-#{id}"
Thread.current[digest_string] ||= select_digest(@method)
digest = Thread.current[digest_string]
# in JRuby 1.7.11 outputs as ASCII-8BIT
if @key.nil?
if @base64encode
@digest.base64digest(data.to_s).force_encoding(Encoding::UTF_8)
digest.base64digest(data.to_s).force_encoding(Encoding::UTF_8)
else
@digest.hexdigest(data.to_s).force_encoding(Encoding::UTF_8)
digest.hexdigest(data.to_s).force_encoding(Encoding::UTF_8)
end
else
if @base64encode
hash = OpenSSL::HMAC.digest(@digest, @key, data.to_s)
hash = OpenSSL::HMAC.digest(digest, @key, data.to_s)
Base64.strict_encode64(hash).force_encoding(Encoding::UTF_8)
else
OpenSSL::HMAC.hexdigest(@digest, @key, data.to_s).force_encoding(Encoding::UTF_8)
OpenSSL::HMAC.hexdigest(digest, @key, data.to_s).force_encoding(Encoding::UTF_8)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion logstash-filter-fingerprint.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|

s.name = 'logstash-filter-fingerprint'
s.version = '3.2.0'
s.version = '3.2.1'
s.licenses = ['Apache-2.0']
s.summary = "Fingerprints fields by replacing values with a consistent hash"
s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
Expand Down

0 comments on commit 5fe864d

Please sign in to comment.