dovecot_crammd5 0.0.2 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/README.md +53 -1
- data/dovecot_crammd5.gemspec +3 -1
- data/examples/calc_crammd5.rb +24 -1
- data/lib/dovecot_crammd5/version.rb +1 -1
- data/lib/dovecot_crammd5.rb +7 -2
- data/spec/dovecot_crammd5/calc_spec.rb +76 -0
- data/spec/spec_helper.rb +1 -0
- metadata +33 -25
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 7e599997ebc7d23ced914aaa33cddf2142d791cdce3750a5f04c6d00c052bedc
|
|
4
|
+
data.tar.gz: 9e05da410a03caddee4c9a6581f90574cdaa8570aa038f8e8b562f67ca5d01b5
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: '09f145c2342a8f507a29b48ad9e84abaae370a66642754d32315e6da3b88ff4a74247570ec731ef887018b8f3ad3eeab2c5e54d5b67c21179c37768712d3939e'
|
|
7
|
+
data.tar.gz: 3eb88b3bf825826e1f71f5d08ba0d7dcaccd66a59fb19941cebe1242635a60a3de6cbd992cc621bc987fe08e6e2a322043e9ea4443c9bd524cbf3d880c8c8a91
|
data/.gitignore
CHANGED
data/README.md
CHANGED
|
@@ -16,9 +16,61 @@ Or install it yourself as:
|
|
|
16
16
|
|
|
17
17
|
$ gem install dovecot_crammd5
|
|
18
18
|
|
|
19
|
+
## Test
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
$ bundle
|
|
23
|
+
$ rspec -fd --color
|
|
24
|
+
|
|
25
|
+
DovecotCrammd5
|
|
26
|
+
pattern normal
|
|
27
|
+
returns cram-md5 hash when strings passed.
|
|
28
|
+
returns cram-md5 hash when string and numbers passed.
|
|
29
|
+
returns cram-md5 hash when upcase and downcase strings passed.
|
|
30
|
+
returns cram-md5 hash when long strings(100) passed
|
|
31
|
+
returns cram-md5 hash when none alphabetical charactors
|
|
32
|
+
pattern abnormal
|
|
33
|
+
case none String
|
|
34
|
+
raise expection when nil passed.
|
|
35
|
+
raise expection when Fixnum passed.
|
|
36
|
+
raise expection when Array passed.
|
|
37
|
+
raise expection when Hash passed.
|
|
38
|
+
|
|
39
|
+
Finished in 0.0139 seconds
|
|
40
|
+
9 examples, 0 failures
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
|
|
19
44
|
## Usage
|
|
20
45
|
|
|
21
|
-
|
|
46
|
+
```ruby
|
|
47
|
+
require 'dovecot_crammd5'
|
|
48
|
+
|
|
49
|
+
"{CRAM-MD5}" + DovecotCrammd5.calc(password)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The secret is used as raw bytes, whatever its encoding is. A UTF-8 string and
|
|
53
|
+
the same bytes in ASCII-8BIT give the same result. Normalize the password
|
|
54
|
+
(e.g. Unicode NFC) in the caller if needed; this library does not.
|
|
55
|
+
|
|
56
|
+
`examples/calc_crammd5.rb` reads the password from stdin (no echo on a
|
|
57
|
+
terminal), so it does not appear in the process list or shell history:
|
|
58
|
+
|
|
59
|
+
$ ruby -Ilib examples/calc_crammd5.rb
|
|
60
|
+
Password:
|
|
61
|
+
{CRAM-MD5}...
|
|
62
|
+
|
|
63
|
+
## Security notes
|
|
64
|
+
|
|
65
|
+
- The CRAM-MD5 value is password-equivalent. Anyone who can read it can log
|
|
66
|
+
in via CRAM-MD5 without knowing the password, and can test password
|
|
67
|
+
guesses at MD5 speed (no salt, no cost factor). Protect it like a
|
|
68
|
+
plaintext password (access control, backups, logs).
|
|
69
|
+
- Prefer a salted, slow scheme (e.g. ARGON2ID, BLF-CRYPT, SHA512-CRYPT)
|
|
70
|
+
with PLAIN/LOGIN over TLS when CRAM-MD5 is not required.
|
|
71
|
+
- Versions up to 0.0.4 computed a wrong value for multibyte (e.g. UTF-8)
|
|
72
|
+
passwords: only the first N bytes were used, where N is the number of
|
|
73
|
+
characters. Values generated for such passwords should be regenerated.
|
|
22
74
|
|
|
23
75
|
## Contributing
|
|
24
76
|
|
data/dovecot_crammd5.gemspec
CHANGED
|
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
19
|
spec.require_paths = ["lib"]
|
|
20
20
|
|
|
21
|
-
spec.add_development_dependency "bundler", "
|
|
21
|
+
spec.add_development_dependency "bundler", ">= 2.2.10"
|
|
22
22
|
spec.add_development_dependency "rake"
|
|
23
|
+
|
|
24
|
+
spec.add_development_dependency "rspec"
|
|
23
25
|
end
|
data/examples/calc_crammd5.rb
CHANGED
|
@@ -1,7 +1,30 @@
|
|
|
1
1
|
#!/bin/env ruby
|
|
2
|
+
#
|
|
3
|
+
# Usage:
|
|
4
|
+
# ruby examples/calc_crammd5.rb # prompts without echo
|
|
5
|
+
# ruby examples/calc_crammd5.rb < file # reads the first line from stdin
|
|
6
|
+
#
|
|
7
|
+
# The password is read from stdin, not from the command line, so that it does
|
|
8
|
+
# not appear in the process list or shell history.
|
|
2
9
|
|
|
3
10
|
require 'dovecot_crammd5'
|
|
4
11
|
|
|
5
|
-
|
|
12
|
+
if STDIN.tty?
|
|
13
|
+
require 'io/console'
|
|
14
|
+
STDERR.print 'Password: '
|
|
15
|
+
secret = STDIN.noecho(&:gets)
|
|
16
|
+
STDERR.print "\n"
|
|
17
|
+
else
|
|
18
|
+
secret = STDIN.gets
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
if secret.nil?
|
|
22
|
+
abort 'error: no password given'
|
|
23
|
+
end
|
|
24
|
+
secret = secret.chomp
|
|
25
|
+
if secret.empty?
|
|
26
|
+
abort 'error: empty password'
|
|
27
|
+
end
|
|
28
|
+
|
|
6
29
|
str = DovecotCrammd5.calc(secret)
|
|
7
30
|
print "{CRAM-MD5}#{str}\n"
|
data/lib/dovecot_crammd5.rb
CHANGED
|
@@ -19,7 +19,7 @@ module DovecotCrammd5
|
|
|
19
19
|
def self.str_xor(str, xor)
|
|
20
20
|
ret = ""
|
|
21
21
|
(0..63).each do |i|
|
|
22
|
-
c = str
|
|
22
|
+
c = str.getbyte(i) || 0
|
|
23
23
|
ret = ret + (c ^ xor).chr
|
|
24
24
|
end
|
|
25
25
|
return ret
|
|
@@ -101,7 +101,12 @@ module DovecotCrammd5
|
|
|
101
101
|
end
|
|
102
102
|
|
|
103
103
|
def self.calc(secret)
|
|
104
|
-
|
|
104
|
+
raise ArgumentError unless secret.is_a?(String)
|
|
105
|
+
|
|
106
|
+
# Dovecot treats the secret as raw bytes (HMAC key), regardless of encoding.
|
|
107
|
+
secret = secret.b
|
|
108
|
+
|
|
109
|
+
if secret.bytesize > 64
|
|
105
110
|
secret = Digest::MD5.digest(secret)
|
|
106
111
|
end
|
|
107
112
|
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe DovecotCrammd5 do
|
|
4
|
+
describe 'pattern normal' do
|
|
5
|
+
it 'returns cram-md5 hash when strings passed.' do
|
|
6
|
+
expect(DovecotCrammd5.calc('hogehoge')).to eql 'dcbe8064d829ee98ad16817611150a6c7ee5fe1c9dfd79f5395be892f162bfd3'
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it 'returns cram-md5 hash when string and numbers passed.' do
|
|
10
|
+
expect(DovecotCrammd5.calc('knight2000')).to eql '527435f1729f9f52e1ff10ce6e72a6a26a43e2937823849d83500c6c55690565'
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'returns cram-md5 hash when upcase and downcase strings passed.' do
|
|
14
|
+
expect(DovecotCrammd5.calc('HOGEhoge')).to eql '764cc43ce35fced4614805835d5925f5254505fba878adb050403cefcb1e70d8'
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'returns cram-md5 hash when long strings(100) passed' do
|
|
18
|
+
expect(DovecotCrammd5.calc('a'*100)).to eql 'f468fcff219b517f6814f5fefa4e894aa8abc2884f2718fa15e07f4cda81f854'
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'returns cram-md5 hash when none alphabetical charactors' do
|
|
22
|
+
expect(DovecotCrammd5.calc('!@#$%^&*()')).to eql '75a21ee215b3ca9a9efdbe712076324414c7388a6a04bedcfdc47c852fd67b25'
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
describe 'pattern multibyte' do
|
|
27
|
+
# Expected values are computed over the raw UTF-8 bytes, as Dovecot does.
|
|
28
|
+
it 'returns cram-md5 hash when multibyte strings passed.' do
|
|
29
|
+
expect(DovecotCrammd5.calc('あいう')).to eql '34c985493d532bc2a45bebe9207d6d2e308be2bf974a95bdcfeb7378b59e0e80'
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'returns cram-md5 hash when ascii and multibyte strings passed.' do
|
|
33
|
+
expect(DovecotCrammd5.calc('pass日本語')).to eql '78dbaeb6e7e61959e2d3b68075415a14ea98eef1e91d1efae4860bde8b5d84a4'
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'returns different hashes when only the last character differs.' do
|
|
37
|
+
expect(DovecotCrammd5.calc('あい')).not_to eql DovecotCrammd5.calc('あう')
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it 'returns cram-md5 hash when exactly 64 bytes passed.' do
|
|
41
|
+
expect(DovecotCrammd5.calc('あ' * 21 + 'a')).to eql '225f4e03e3a7a3915c477ae85ca1b81f2fb75a714579733d5935967f3d05f889'
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it 'returns cram-md5 hash when 65 bytes (22 characters) passed.' do
|
|
45
|
+
expect(DovecotCrammd5.calc('あ' * 21 + 'ab')).to eql '240bf3f8f708f74b4414d12f37235060515a37bffc5c466887edc373863e9d68'
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it 'returns cram-md5 hash when more than 64 characters passed.' do
|
|
49
|
+
expect(DovecotCrammd5.calc('あ' * 65)).to eql '31cfc53dbc9ffd0748bf5c5ff037184f7e3c989a41904f362faef690e5fce0a5'
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it 'returns the same hash regardless of string encoding tag.' do
|
|
53
|
+
expect(DovecotCrammd5.calc('あ' * 22)).to eql DovecotCrammd5.calc(('あ' * 22).b)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
describe 'pattern abnormal' do
|
|
58
|
+
describe 'case none String' do
|
|
59
|
+
it 'raise expection when nil passed.' do
|
|
60
|
+
expect{DovecotCrammd5.calc(nil)}.to raise_error(ArgumentError)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it 'raise expection when Fixnum passed.' do
|
|
64
|
+
expect{DovecotCrammd5.calc(1)}.to raise_error(ArgumentError)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it 'raise expection when Array passed.' do
|
|
68
|
+
expect{DovecotCrammd5.calc([])}.to raise_error(ArgumentError)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it 'raise expection when Hash passed.' do
|
|
72
|
+
expect{DovecotCrammd5.calc({})}.to raise_error(ArgumentError)
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'dovecot_crammd5'
|
metadata
CHANGED
|
@@ -1,46 +1,54 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dovecot_crammd5
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
5
|
-
prerelease:
|
|
4
|
+
version: 0.0.5
|
|
6
5
|
platform: ruby
|
|
7
6
|
authors:
|
|
8
7
|
- KAWAHARA Masashi
|
|
9
|
-
autorequire:
|
|
10
8
|
bindir: bin
|
|
11
9
|
cert_chain: []
|
|
12
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
13
11
|
dependencies:
|
|
14
12
|
- !ruby/object:Gem::Dependency
|
|
15
13
|
name: bundler
|
|
16
14
|
requirement: !ruby/object:Gem::Requirement
|
|
17
|
-
none: false
|
|
18
15
|
requirements:
|
|
19
|
-
- -
|
|
16
|
+
- - ">="
|
|
20
17
|
- !ruby/object:Gem::Version
|
|
21
|
-
version:
|
|
18
|
+
version: 2.2.10
|
|
22
19
|
type: :development
|
|
23
20
|
prerelease: false
|
|
24
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
-
none: false
|
|
26
22
|
requirements:
|
|
27
|
-
- -
|
|
23
|
+
- - ">="
|
|
28
24
|
- !ruby/object:Gem::Version
|
|
29
|
-
version:
|
|
25
|
+
version: 2.2.10
|
|
30
26
|
- !ruby/object:Gem::Dependency
|
|
31
27
|
name: rake
|
|
32
28
|
requirement: !ruby/object:Gem::Requirement
|
|
33
|
-
none: false
|
|
34
29
|
requirements:
|
|
35
|
-
- -
|
|
30
|
+
- - ">="
|
|
36
31
|
- !ruby/object:Gem::Version
|
|
37
32
|
version: '0'
|
|
38
33
|
type: :development
|
|
39
34
|
prerelease: false
|
|
40
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
41
|
-
none: false
|
|
42
36
|
requirements:
|
|
43
|
-
- -
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: rspec
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0'
|
|
47
|
+
type: :development
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
44
52
|
- !ruby/object:Gem::Version
|
|
45
53
|
version: '0'
|
|
46
54
|
description: generate dovecot's cram-md5 password hash
|
|
@@ -50,7 +58,7 @@ executables: []
|
|
|
50
58
|
extensions: []
|
|
51
59
|
extra_rdoc_files: []
|
|
52
60
|
files:
|
|
53
|
-
- .gitignore
|
|
61
|
+
- ".gitignore"
|
|
54
62
|
- Gemfile
|
|
55
63
|
- LICENSE.txt
|
|
56
64
|
- README.md
|
|
@@ -59,29 +67,29 @@ files:
|
|
|
59
67
|
- examples/calc_crammd5.rb
|
|
60
68
|
- lib/dovecot_crammd5.rb
|
|
61
69
|
- lib/dovecot_crammd5/version.rb
|
|
70
|
+
- spec/dovecot_crammd5/calc_spec.rb
|
|
71
|
+
- spec/spec_helper.rb
|
|
62
72
|
homepage: ''
|
|
63
73
|
licenses:
|
|
64
74
|
- MIT
|
|
65
|
-
|
|
75
|
+
metadata: {}
|
|
66
76
|
rdoc_options: []
|
|
67
77
|
require_paths:
|
|
68
78
|
- lib
|
|
69
79
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
70
|
-
none: false
|
|
71
80
|
requirements:
|
|
72
|
-
- -
|
|
81
|
+
- - ">="
|
|
73
82
|
- !ruby/object:Gem::Version
|
|
74
83
|
version: '0'
|
|
75
84
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
|
-
none: false
|
|
77
85
|
requirements:
|
|
78
|
-
- -
|
|
86
|
+
- - ">="
|
|
79
87
|
- !ruby/object:Gem::Version
|
|
80
88
|
version: '0'
|
|
81
89
|
requirements: []
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
signing_key:
|
|
85
|
-
specification_version: 3
|
|
90
|
+
rubygems_version: 3.6.9
|
|
91
|
+
specification_version: 4
|
|
86
92
|
summary: generate dovecot's cram-md5 password hash
|
|
87
|
-
test_files:
|
|
93
|
+
test_files:
|
|
94
|
+
- spec/dovecot_crammd5/calc_spec.rb
|
|
95
|
+
- spec/spec_helper.rb
|