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

added fips flag #290

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
16 changes: 16 additions & 0 deletions docs/gemstash-configuration.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ gemstash-configuration
:protected_fetch: true
:fetch_timeout: 10
:log_file: gemstash.log
:fips: false
```

# Base Path
Expand Down Expand Up @@ -246,3 +247,18 @@ Any valid file name, or `:stdout` to log to `$stdout`

*Note: Using `:stdout` for the `:log_file` requires [running with
`--no-daemonize`](docs/gemstash-start.1.md#options).*

# FIPS

`:fips`

Whether or not to use FIPS compliant ciphers. Controls whether
cached files are named using an MD5 hash or a SHA256 hash.

## Default value

`false`

## Valid values

Boolean values `true` or `false`
9 changes: 9 additions & 0 deletions lib/gemstash/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Gemstash
class Configuration
DEFAULTS = {
cache_type: "memory",
fips: false,
base_path: File.expand_path("~/.gemstash"),
db_adapter: "sqlite3",
bind: "tcp://0.0.0.0:9292",
Expand Down Expand Up @@ -78,6 +79,14 @@ def database_connection_config
end
end

def digest_class
@digest_class ||= if self[:fips]
Digest::SHA256
else
Digest::MD5
end
end

private

def default_file
Expand Down
2 changes: 1 addition & 1 deletion lib/gemstash/storage_services/local_storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def initialize(folder, name)
trie_parents = safe_name[0...3].downcase.split("")
# The digest is included in case the name differs only by case
# Some file systems are case insensitive, so such collisions will be a problem
digest = Digest::MD5.hexdigest(@name)
digest = Gemstash::Env.current.config.digest_class.hexdigest(@name)
child_folder = "#{safe_name}-#{digest}"
@folder = File.join(@base_path, *trie_parents, child_folder)
@properties = nil
Expand Down
2 changes: 1 addition & 1 deletion lib/gemstash/storage_services/s3_storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def initialize(folder, name, client, bucket_name)
@folder = folder
@name = name
safe_name = sanitize(@name)
digest = Digest::MD5.hexdigest(@name)
digest = Gemstash::Env.current.config.digest_class.hexdigest(@name)
child_folder = "#{safe_name}-#{digest}"
@folder = File.join(@folder, child_folder)
@client = client
Expand Down
2 changes: 1 addition & 1 deletion lib/gemstash/upstream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def host_id
private

def hash
Digest::MD5.hexdigest(to_s)
Gemstash::Env.current.config.digest_class.hexdigest(to_s)
end

#:nodoc:
Expand Down
6 changes: 6 additions & 0 deletions spec/gemstash/cli/info_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
let(:defaults) do
<<~DEFAULT
cache_type: memory
fips: false
base_path: #{File.expand_path("~/.gemstash")}
db_adapter: sqlite3
bind: tcp://0.0.0.0:9292
Expand All @@ -18,11 +19,14 @@
puma_workers: 1
cache_expiration: 1800
cache_max_size: 500
storage_adapter: local
s3_path: gemstash/s3_storage
DEFAULT
end
let(:with_protected_fetch_true) do
<<~DEFAULT
cache_type: memory
fips: false
base_path: #{File.expand_path("~/.gemstash")}
db_adapter: sqlite3
bind: tcp://0.0.0.0:9292
Expand All @@ -35,6 +39,8 @@
puma_workers: 1
cache_expiration: 1800
cache_max_size: 500
storage_adapter: local
s3_path: gemstash/s3_storage
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were not due to changes I made, but were needed to get the spec to pass

DEFAULT
end
let(:cli) do
Expand Down