Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dotNET Platform
runtime
提交
56acd2ed
R
runtime
项目概览
dotNET Platform
/
runtime
12 个月 前同步成功
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
runtime
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
56acd2ed
编写于
11月 15, 2021
作者:
K
Kevin Jones
提交者:
GitHub
11月 15, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add tests for CNG symmetric key algorithm mismatches
上级
e10532af
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
39 addition
and
32 deletion
+39
-32
src/libraries/System.Security.Cryptography.Cng/tests/AesCngTests.cs
...ies/System.Security.Cryptography.Cng/tests/AesCngTests.cs
+9
-0
src/libraries/System.Security.Cryptography.Cng/tests/SymmetricCngTestHelpers.cs
...ecurity.Cryptography.Cng/tests/SymmetricCngTestHelpers.cs
+21
-32
src/libraries/System.Security.Cryptography.Cng/tests/TripleDESCngTests.cs
...stem.Security.Cryptography.Cng/tests/TripleDESCngTests.cs
+9
-0
未找到文件。
src/libraries/System.Security.Cryptography.Cng/tests/AesCngTests.cs
浏览文件 @
56acd2ed
...
...
@@ -108,6 +108,15 @@ public static void VerifyUnsupportedFeedbackSizeForPersistedCfb()
notSupportedFeedbackSizeInBits
:
128
);
}
[
OuterLoop
(
"Creates/Deletes a persisted key, limit exposure to key leaking"
)]
[
ConditionalFact
(
nameof
(
SupportsPersistedSymmetricKeys
))]
public
static
void
VerifyRequiresAesCngKey
()
{
SymmetricCngTestHelpers
.
VerifyMismatchAlgorithmFails
(
s_cngAlgorithm
,
keyName
=>
new
TripleDESCng
(
keyName
,
CngProvider
.
MicrosoftSoftwareKeyStorageProvider
));
}
public
static
bool
SupportsPersistedSymmetricKeys
{
get
{
return
SymmetricCngTestHelpers
.
SupportsPersistedSymmetricKeys
;
}
...
...
src/libraries/System.Security.Cryptography.Cng/tests/SymmetricCngTestHelpers.cs
浏览文件 @
56acd2ed
...
...
@@ -61,7 +61,7 @@ public static class SymmetricCngTestHelpers
PaddingMode
paddingMode
,
int
feedbackSizeInBits
)
{
byte
[]
plainBytes
=
GenerateRandom
(
plainBytesCount
);
byte
[]
plainBytes
=
RandomNumberGenerator
.
GetBytes
(
plainBytesCount
);
using
(
SymmetricAlgorithm
persisted
=
persistedFunc
(
keyName
))
using
(
SymmetricAlgorithm
ephemeral
=
ephemeralFunc
())
...
...
@@ -195,7 +195,7 @@ public static class SymmetricCngTestHelpers
stable
.
GenerateIV
();
// Generate (4 * 8) = 32 blocks of plaintext
byte
[]
plainTextBytes
=
GenerateRandom
(
4
*
stable
.
BlockSize
);
byte
[]
plainTextBytes
=
RandomNumberGenerator
.
GetBytes
(
4
*
stable
.
BlockSize
);
byte
[]
iv
=
stable
.
IV
;
regenKey
.
IV
=
replaceKey
.
IV
=
iv
;
...
...
@@ -348,44 +348,33 @@ public static class SymmetricCngTestHelpers
}
}
private
static
bool
?
s_supportsPersistedSymmetricKeys
;
internal
static
bool
SupportsPersistedSymmetricKeys
internal
static
void
VerifyMismatchAlgorithmFails
(
CngAlgorithm
algorithm
,
Func
<
string
,
SymmetricAlgorithm
>
createFromKey
)
{
get
{
if
(!
s_supportsPersistedSymmetricKeys
.
HasValue
)
{
// Windows 7 (Microsoft Windows 6.1) does not support persisted symmetric keys
// in the Microsoft Software KSP
s_supportsPersistedSymmetricKeys
=
!
RuntimeInformation
.
OSDescription
.
Contains
(
"Windows 6.1"
);
}
string
keyName
=
Guid
.
NewGuid
().
ToString
();
return
s_supportsPersistedSymmetricKeys
.
Value
;
}
}
// We try to delete the key later which will also dispose of it, so no need
// to put this in a using.
CngKey
cngKey
=
CngKey
.
Create
(
algorithm
,
keyName
);
private
static
readonly
Lazy
<
bool
>
s_isAdministrator
=
new
Lazy
<
bool
>(
()
=>
try
{
using
(
WindowsIdentity
identity
=
WindowsIdentity
.
GetCurrent
())
{
WindowsPrincipal
principal
=
new
WindowsPrincipal
(
identity
);
return
principal
.
IsInRole
(
WindowsBuiltInRole
.
Administrator
);
}
});
internal
static
bool
IsAdministrator
=>
s_isAdministrator
.
Value
;
internal
static
byte
[]
GenerateRandom
(
int
count
)
{
byte
[]
buffer
=
new
byte
[
count
];
using
(
RandomNumberGenerator
rng
=
RandomNumberGenerator
.
Create
())
CryptographicException
ce
=
Assert
.
Throws
<
CryptographicException
>(()
=>
createFromKey
(
keyName
));
Assert
.
Contains
(
$"'
{
algorithm
.
Algorithm
}
'"
,
ce
.
Message
);
}
finally
{
rng
.
GetBytes
(
buffer
);
cngKey
.
Delete
(
);
}
return
buffer
;
}
// Windows 7 (Microsoft Windows 6.1) does not support persisted symmetric keys
// in the Microsoft Software KSP
internal
static
bool
SupportsPersistedSymmetricKeys
=>
PlatformDetection
.
IsWindows8xOrLater
;
internal
static
bool
IsAdministrator
=>
PlatformDetection
.
IsWindowsAndElevated
;
internal
static
void
AssertTransformsEqual
(
byte
[]
plainTextBytes
,
ICryptoTransform
decryptor
,
byte
[]
encryptedBytes
)
{
byte
[]
decrypted
=
decryptor
.
TransformFinalBlock
(
encryptedBytes
,
0
,
encryptedBytes
.
Length
);
...
...
src/libraries/System.Security.Cryptography.Cng/tests/TripleDESCngTests.cs
浏览文件 @
56acd2ed
...
...
@@ -114,6 +114,15 @@ public static void VerifyUnsupportedFeedbackSizeForPersistedCfb()
notSupportedFeedbackSizeInBits
:
64
);
}
[
OuterLoop
(
"Creates/Deletes a persisted key, limit exposure to key leaking"
)]
[
ConditionalFact
(
nameof
(
SupportsPersistedSymmetricKeys
))]
public
static
void
VerifyRequiresTripleDESCngKey
()
{
SymmetricCngTestHelpers
.
VerifyMismatchAlgorithmFails
(
s_cngAlgorithm
,
keyName
=>
new
AesCng
(
keyName
,
CngProvider
.
MicrosoftSoftwareKeyStorageProvider
));
}
public
static
bool
SupportsPersistedSymmetricKeys
{
get
{
return
SymmetricCngTestHelpers
.
SupportsPersistedSymmetricKeys
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录