-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from copiousfreetime/feature/support-argon2
Feature/support argon2
- Loading branch information
Showing
32 changed files
with
276 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,6 @@ blocks: | |
- 3.1.4 | ||
- 3.2.2 | ||
- 3.3.0 | ||
- jruby-9.3.13.0 | ||
- jruby-9.4.5.0 | ||
- truffleruby-23.1.2 | ||
commands: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
# DO NOT EDIT - This file is automatically generated | ||
# Make changes to Manifest.txt and/or Rakefile and regenerate | ||
# -*- encoding: utf-8 -*- | ||
# stub: htauth 2.2.0 ruby lib | ||
# stub: htauth 2.3.0 ruby lib | ||
|
||
Gem::Specification.new do |s| | ||
s.name = "htauth".freeze | ||
s.version = "2.2.0".freeze | ||
s.version = "2.3.0".freeze | ||
|
||
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version= | ||
s.metadata = { "bug_tracker_uri" => "https://github.com/copiousfreetime/htauth/issues", "changelog_uri" => "https://github.com/copiousfreetime/htauth/blob/master/HISTORY.md", "homepage_uri" => "https://github.com/copiousfreetime/htauth", "source_code_uri" => "https://github.com/copiousfreetime/htauth" } if s.respond_to? :metadata= | ||
s.require_paths = ["lib".freeze] | ||
s.authors = ["Jeremy Hinegardner".freeze] | ||
s.date = "2024-01-16" | ||
s.description = "HTAuth is a pure ruby replacement for the Apache support programs htdigest and htpasswd. Command line and API access are provided for access to htdigest and htpasswd files.".freeze | ||
s.date = "2024-02-04" | ||
s.description = "HTAuth provides an API and commandline tools for managing Apache/httpd style htpasswd and htdigest files.".freeze | ||
s.email = "[email protected]".freeze | ||
s.executables = ["htdigest-ruby".freeze, "htpasswd-ruby".freeze] | ||
s.extra_rdoc_files = ["CONTRIBUTING.md".freeze, "HISTORY.md".freeze, "Manifest.txt".freeze, "README.md".freeze] | ||
|
@@ -22,12 +22,14 @@ Gem::Specification.new do |s| | |
s.rdoc_options = ["--main".freeze, "README.md".freeze, "--markup".freeze, "tomdoc".freeze] | ||
s.required_ruby_version = Gem::Requirement.new(">= 2.3.0".freeze) | ||
s.rubygems_version = "3.5.3".freeze | ||
s.summary = "HTAuth is a pure ruby replacement for the Apache support programs htdigest and htpasswd. Command line and API access are provided for access to htdigest and htpasswd files.".freeze | ||
s.summary = "HTAuth provides an API and commandline tools for managing Apache/httpd style htpasswd and htdigest files.".freeze | ||
s.test_files = ["spec/algorithm_spec.rb".freeze, "spec/bcrypt_spec.rb".freeze, "spec/cli/digest_spec.rb".freeze, "spec/cli/passwd_spec.rb".freeze, "spec/crypt_spec.rb".freeze, "spec/digest_entry_spec.rb".freeze, "spec/digest_file_spec.rb".freeze, "spec/md5_spec.rb".freeze, "spec/passwd_entry_spec.rb".freeze, "spec/passwd_file_spec.rb".freeze, "spec/plaintext_spec.rb".freeze, "spec/sha1_spec.rb".freeze, "spec/spec_helper.rb".freeze, "spec/test.add.digest".freeze, "spec/test.add.passwd".freeze, "spec/test.delete.digest".freeze, "spec/test.delete.passwd".freeze, "spec/test.original.digest".freeze, "spec/test.original.passwd".freeze, "spec/test.update.digest".freeze, "spec/test.update.passwd".freeze] | ||
|
||
s.specification_version = 4 | ||
|
||
s.add_runtime_dependency(%q<bcrypt>.freeze, ["~> 3.1".freeze]) | ||
s.add_runtime_dependency(%q<base64>.freeze, ["~> 0.2".freeze]) | ||
s.add_development_dependency(%q<argon2>.freeze, ["~> 2.3".freeze]) | ||
s.add_development_dependency(%q<rake>.freeze, ["~> 13.1".freeze]) | ||
s.add_development_dependency(%q<minitest>.freeze, ["~> 5.21".freeze]) | ||
s.add_development_dependency(%q<minitest-junit>.freeze, ["~> 1.1".freeze]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
require 'htauth/algorithm' | ||
begin | ||
require 'argon2' | ||
rescue LoadError | ||
end | ||
|
||
module HTAuth | ||
# Internal: Support of the argon2id algorithm and password format. | ||
|
||
class Argon2 < Algorithm | ||
class NotSupportedError < ::HTAuth::InvalidAlgorithmError | ||
def message | ||
"Unfortunately Argon2 passwords are not supported on `#{RUBY_PLATFORM} at this time. This because the upstream argon2 gem does not support windows." | ||
end | ||
end | ||
class NotInstalledError < ::HTAuth::InvalidAlgorithmError | ||
def message | ||
"Argon2 passwords are supported if the `argon2' gem is installed. Add `gem 'argon2', '~> 2.3'` to your Gemfile" | ||
end | ||
end | ||
|
||
# from upstream, used to help make a nice error message if its not installed | ||
# https://github.com/technion/ruby-argon2/blob/3388d7e05e8b486ea4ba8bd2aeb1e9988f025f13/lib/argon2/hash_format.rb#L45 | ||
PREFIX = /^\$argon2(id?|d).{,113}/.freeze | ||
ARGON2_GEM_INSTALLED = defined?(::Argon2) | ||
|
||
def self.supported? | ||
!::Gem.win_platform? | ||
end | ||
|
||
def self.ensure_available! | ||
raise NotSupportedError unless supported? | ||
raise NotInstalledError unless ARGON2_GEM_INSTALLED | ||
end | ||
|
||
attr_accessor :options | ||
|
||
def self.handles?(password_entry) | ||
return false unless PREFIX.match?(password_entry) | ||
ensure_available! | ||
|
||
return ::Argon2::Password.valid_hash?(password_entry) | ||
end | ||
|
||
def self.extract_options_from_existing_password_field(existing) | ||
hash_format = ::Argon2::HashFormat.new(existing) | ||
|
||
# m_cost on the input is the 2**m_cost, but in the hash its the number of | ||
# bytes, so need to convert it back to a power of 2, which is the | ||
# log2(m_cost) | ||
|
||
{ | ||
t_cost: hash_format.t_cost, | ||
m_cost: ::Math.log2(hash_format.m_cost).floor, | ||
p_cost: hash_format.p_cost, | ||
} | ||
end | ||
|
||
def initialize(params = { profile: :rfc_9106_low_memory }) | ||
self.class.ensure_available! | ||
if existing = (params['existing'] || params[:existing]) then | ||
@options = self.class.extract_options_from_existing_password_field(existing) | ||
else | ||
@options = params | ||
end | ||
end | ||
|
||
def encode(password) | ||
argon2 = ::Argon2::Password.new(options) | ||
argon2.create(password) | ||
end | ||
|
||
def verify_password?(password, digest) | ||
::Argon2::Password.verify_password(password, digest) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
require 'htauth' | ||
require 'htauth/console' | ||
module HTAuth | ||
module CLI | ||
|
||
end | ||
end | ||
require 'htauth/cli/digest' | ||
require 'htauth/cli/passwd' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.