dovecot_crammd5 0.0.3 → 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/README.md +28 -1
- data/dovecot_crammd5.gemspec +1 -1
- data/examples/calc_crammd5.rb +24 -1
- data/lib/dovecot_crammd5/version.rb +1 -1
- data/lib/dovecot_crammd5.rb +5 -2
- data/spec/dovecot_crammd5/calc_spec.rb +31 -0
- metadata +16 -28
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/README.md
CHANGED
|
@@ -43,7 +43,34 @@ Finished in 0.0139 seconds
|
|
|
43
43
|
|
|
44
44
|
## Usage
|
|
45
45
|
|
|
46
|
-
|
|
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.
|
|
47
74
|
|
|
48
75
|
## Contributing
|
|
49
76
|
|
data/dovecot_crammd5.gemspec
CHANGED
|
@@ -18,7 +18,7 @@ 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
23
|
|
|
24
24
|
spec.add_development_dependency "rspec"
|
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
|
|
@@ -103,7 +103,10 @@ module DovecotCrammd5
|
|
|
103
103
|
def self.calc(secret)
|
|
104
104
|
raise ArgumentError unless secret.is_a?(String)
|
|
105
105
|
|
|
106
|
-
|
|
106
|
+
# Dovecot treats the secret as raw bytes (HMAC key), regardless of encoding.
|
|
107
|
+
secret = secret.b
|
|
108
|
+
|
|
109
|
+
if secret.bytesize > 64
|
|
107
110
|
secret = Digest::MD5.digest(secret)
|
|
108
111
|
end
|
|
109
112
|
|
|
@@ -23,6 +23,37 @@ describe DovecotCrammd5 do
|
|
|
23
23
|
end
|
|
24
24
|
end
|
|
25
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
|
+
|
|
26
57
|
describe 'pattern abnormal' do
|
|
27
58
|
describe 'case none String' do
|
|
28
59
|
it 'raise expection when nil passed.' do
|
metadata
CHANGED
|
@@ -1,62 +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
|
+
- - ">="
|
|
44
38
|
- !ruby/object:Gem::Version
|
|
45
39
|
version: '0'
|
|
46
40
|
- !ruby/object:Gem::Dependency
|
|
47
41
|
name: rspec
|
|
48
42
|
requirement: !ruby/object:Gem::Requirement
|
|
49
|
-
none: false
|
|
50
43
|
requirements:
|
|
51
|
-
- -
|
|
44
|
+
- - ">="
|
|
52
45
|
- !ruby/object:Gem::Version
|
|
53
46
|
version: '0'
|
|
54
47
|
type: :development
|
|
55
48
|
prerelease: false
|
|
56
49
|
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
-
none: false
|
|
58
50
|
requirements:
|
|
59
|
-
- -
|
|
51
|
+
- - ">="
|
|
60
52
|
- !ruby/object:Gem::Version
|
|
61
53
|
version: '0'
|
|
62
54
|
description: generate dovecot's cram-md5 password hash
|
|
@@ -66,7 +58,7 @@ executables: []
|
|
|
66
58
|
extensions: []
|
|
67
59
|
extra_rdoc_files: []
|
|
68
60
|
files:
|
|
69
|
-
- .gitignore
|
|
61
|
+
- ".gitignore"
|
|
70
62
|
- Gemfile
|
|
71
63
|
- LICENSE.txt
|
|
72
64
|
- README.md
|
|
@@ -80,27 +72,23 @@ files:
|
|
|
80
72
|
homepage: ''
|
|
81
73
|
licenses:
|
|
82
74
|
- MIT
|
|
83
|
-
|
|
75
|
+
metadata: {}
|
|
84
76
|
rdoc_options: []
|
|
85
77
|
require_paths:
|
|
86
78
|
- lib
|
|
87
79
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
88
|
-
none: false
|
|
89
80
|
requirements:
|
|
90
|
-
- -
|
|
81
|
+
- - ">="
|
|
91
82
|
- !ruby/object:Gem::Version
|
|
92
83
|
version: '0'
|
|
93
84
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
|
-
none: false
|
|
95
85
|
requirements:
|
|
96
|
-
- -
|
|
86
|
+
- - ">="
|
|
97
87
|
- !ruby/object:Gem::Version
|
|
98
88
|
version: '0'
|
|
99
89
|
requirements: []
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
signing_key:
|
|
103
|
-
specification_version: 3
|
|
90
|
+
rubygems_version: 3.6.9
|
|
91
|
+
specification_version: 4
|
|
104
92
|
summary: generate dovecot's cram-md5 password hash
|
|
105
93
|
test_files:
|
|
106
94
|
- spec/dovecot_crammd5/calc_spec.rb
|