Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support FIPS 140-2 compliant digest calls #1887

Merged
merged 1 commit into from
Jun 3, 2017
Merged
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
5 changes: 4 additions & 1 deletion lib/fetchers/local.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# author: Dominik Richter
# author: Christoph Hartmann

require 'openssl'

module Fetchers
class Local < Inspec.fetcher(1)
name 'local'
Expand Down Expand Up @@ -65,7 +67,8 @@ def cache_key

def sha256
return nil if File.directory?(@target)
@archive_shasum ||= Digest::SHA256.hexdigest File.read(@target)
@archive_shasum ||=
OpenSSL::Digest::SHA256.digest(File.read(@target)).unpack('H*')[0]
end

def resolved_source
Expand Down
4 changes: 2 additions & 2 deletions lib/fetchers/url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# author: Christoph Hartmann

require 'uri'
require 'digest'
require 'openssl'
require 'tempfile'
require 'open-uri'

Expand Down Expand Up @@ -101,7 +101,7 @@ def to_s

def sha256
file = @archive_path || temp_archive_path
Digest::SHA256.hexdigest File.read(file)
OpenSSL::Digest::SHA256.digest(File.read(file)).unpack('H*')[0]
end

def file_type_from_remote(remote)
Expand Down
1 change: 0 additions & 1 deletion lib/inspec/dependencies/cache.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# encoding: utf-8
require 'digest'
require 'fileutils'

module Inspec
Expand Down
1 change: 0 additions & 1 deletion lib/inspec/dependencies/requirement.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# encoding: utf-8
require 'inspec/cached_fetcher'
require 'inspec/dependencies/dependency_set'
require 'digest'

module Inspec
#
Expand Down
1 change: 0 additions & 1 deletion lib/inspec/plugins/fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# author: Christoph Hartmann
require 'utils/plugin_registry'
require 'inspec/file_provider'
require 'digest'

module Inspec
module Plugins
Expand Down
6 changes: 3 additions & 3 deletions lib/inspec/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# author: Christoph Hartmann

require 'forwardable'
require 'digest'
require 'openssl'
require 'inspec/polyfill'
require 'inspec/cached_fetcher'
require 'inspec/file_provider'
Expand Down Expand Up @@ -406,7 +406,7 @@ def sha256
# get all dependency checksums
deps = Hash[locked_dependencies.list.map { |k, v| [k, v.profile.sha256] }]

res = Digest::SHA256.new
res = OpenSSL::Digest::SHA256.new
files = source_reader.tests.to_a + source_reader.libraries.to_a +
source_reader.data_files.to_a +
[['inspec.yml', source_reader.metadata.content]] +
Expand All @@ -415,7 +415,7 @@ def sha256
files.sort { |a, b| a[0] <=> b[0] }
.map { |f| res << f[0] << "\0" << f[1] << "\0" }

res.hexdigest
res.digest.unpack('H*')[0]
end

private
Expand Down