Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
73691783
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
73691783
编写于
6月 28, 2016
作者:
A
Aaron Patterson
提交者:
GitHub
6月 28, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #25192 from vipulnsward/25185-default-key-length
Fix default key length on cipher
上级
cf8605ad
8ee269cf
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
7 addition
and
9 deletion
+7
-9
activesupport/lib/active_support/key_generator.rb
activesupport/lib/active_support/key_generator.rb
+4
-6
activesupport/test/key_generator_test.rb
activesupport/test/key_generator_test.rb
+1
-1
activesupport/test/message_encryptor_test.rb
activesupport/test/message_encryptor_test.rb
+2
-2
未找到文件。
activesupport/lib/active_support/key_generator.rb
浏览文件 @
73691783
...
...
@@ -15,9 +15,8 @@ def initialize(secret, options = {})
end
# Returns a derived key suitable for use. The default key_size is chosen
# to be compatible with the default settings of ActiveSupport::MessageVerifier.
# i.e. OpenSSL::Digest::SHA1#block_length
def
generate_key
(
salt
,
key_size
=
64
)
# to be compatible with the acceptable key length of aes-256-cbc, the default cipher.
def
generate_key
(
salt
,
key_size
=
32
)
OpenSSL
::
PKCS5
.
pbkdf2_hmac_sha1
(
@secret
,
salt
,
@iterations
,
key_size
)
end
end
...
...
@@ -32,9 +31,8 @@ def initialize(key_generator)
end
# Returns a derived key suitable for use. The default key_size is chosen
# to be compatible with the default settings of ActiveSupport::MessageVerifier.
# i.e. OpenSSL::Digest::SHA1#block_length
def
generate_key
(
salt
,
key_size
=
64
)
# to be compatible with the acceptable key length of aes-256-cbc, the default cipher.
def
generate_key
(
salt
,
key_size
=
32
)
@cache_keys
[
"
#{
salt
}#{
key_size
}
"
]
||=
@key_generator
.
generate_key
(
salt
,
key_size
)
end
end
...
...
activesupport/test/key_generator_test.rb
浏览文件 @
73691783
...
...
@@ -19,7 +19,7 @@ def setup
test
"Generating a key of the default length"
do
derived_key
=
@generator
.
generate_key
(
"some_salt"
)
assert_kind_of
String
,
derived_key
assert_equal
OpenSSL
::
Digest
::
SHA1
.
new
.
block_length
,
derived_key
.
length
,
"Should have generated a key of the default size"
assert_equal
OpenSSL
::
Cipher
.
new
(
'aes-256-cbc'
).
key_len
,
derived_key
.
length
,
"Should have generated a key of the default size"
end
test
"Generating a key of an alternative length"
do
...
...
activesupport/test/message_encryptor_test.rb
浏览文件 @
73691783
...
...
@@ -15,7 +15,7 @@ def load(value)
end
def
setup
@secret
=
SecureRandom
.
hex
(
64
)
@secret
=
SecureRandom
.
random_bytes
(
32
)
@verifier
=
ActiveSupport
::
MessageVerifier
.
new
(
@secret
,
:serializer
=>
ActiveSupport
::
MessageEncryptor
::
NullSerializer
)
@encryptor
=
ActiveSupport
::
MessageEncryptor
.
new
(
@secret
)
@data
=
{
:some
=>
"data"
,
:now
=>
Time
.
local
(
2010
)
}
...
...
@@ -51,7 +51,7 @@ def test_signed_round_tripping
def
test_alternative_serialization_method
prev
=
ActiveSupport
.
use_standard_json_time_format
ActiveSupport
.
use_standard_json_time_format
=
true
encryptor
=
ActiveSupport
::
MessageEncryptor
.
new
(
SecureRandom
.
hex
(
64
),
SecureRandom
.
hex
(
64
),
:serializer
=>
JSONSerializer
.
new
)
encryptor
=
ActiveSupport
::
MessageEncryptor
.
new
(
SecureRandom
.
random_bytes
(
32
),
SecureRandom
.
random_bytes
(
128
),
:serializer
=>
JSONSerializer
.
new
)
message
=
encryptor
.
encrypt_and_sign
({
:foo
=>
123
,
'bar'
=>
Time
.
utc
(
2010
)
})
exp
=
{
"foo"
=>
123
,
"bar"
=>
"2010-01-01T00:00:00.000Z"
}
assert_equal
exp
,
encryptor
.
decrypt_and_verify
(
message
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录