Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dotNET Platform
runtime
提交
d3d537fa
R
runtime
项目概览
dotNET Platform
/
runtime
大约 1 年 前同步成功
通知
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,发现更多精彩内容 >>
未验证
提交
d3d537fa
编写于
6月 29, 2023
作者:
K
Kevin Jones
提交者:
GitHub
6月 29, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support displaying X.500 AttributeValue in binary form
上级
205ac766
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
130 addition
and
4 deletion
+130
-4
src/libraries/System.Security.Cryptography/src/System.Security.Cryptography.csproj
...rity.Cryptography/src/System.Security.Cryptography.csproj
+1
-1
src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X500DirectoryStringHelper.cs
...ryptography/X509Certificates/X500DirectoryStringHelper.cs
+1
-1
src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X500NameEncoder.ManagedDecode.cs
...ography/X509Certificates/X500NameEncoder.ManagedDecode.cs
+50
-2
src/libraries/System.Security.Cryptography/tests/X509Certificates/X500DistinguishedNameTests.cs
...aphy/tests/X509Certificates/X500DistinguishedNameTests.cs
+78
-0
未找到文件。
src/libraries/System.Security.Cryptography/src/System.Security.Cryptography.csproj
浏览文件 @
d3d537fa
...
...
@@ -530,7 +530,7 @@
<Compile Include="System\Security\Cryptography\X509Certificates\StoreName.cs" />
<Compile Include="System\Security\Cryptography\X509Certificates\StorePal.cs" />
<Compile Include="System\Security\Cryptography\X509Certificates\SubjectAlternativeNameBuilder.cs" />
<Compile Include="System\Security\Cryptography\X509Certificates\X500Di
ctiona
ryStringHelper.cs" />
<Compile Include="System\Security\Cryptography\X509Certificates\X500Di
recto
ryStringHelper.cs" />
<Compile Include="System\Security\Cryptography\X509Certificates\X500DistinguishedName.cs" />
<Compile Include="System\Security\Cryptography\X509Certificates\X500DistinguishedNameBuilder.cs" />
<Compile Include="System\Security\Cryptography\X509Certificates\X500DistinguishedNameFlags.cs" />
...
...
src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X500Di
ctiona
ryStringHelper.cs
→
src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X500Di
recto
ryStringHelper.cs
浏览文件 @
d3d537fa
...
...
@@ -5,7 +5,7 @@
namespace
System.Security.Cryptography.X509Certificates
{
internal
static
class
X500Di
ctiona
ryStringHelper
internal
static
class
X500Di
recto
ryStringHelper
{
internal
static
string
ReadAnyAsnString
(
this
AsnReader
tavReader
)
{
...
...
src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X500NameEncoder.ManagedDecode.cs
浏览文件 @
d3d537fa
...
...
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
using
System.Collections.Generic
;
using
System.Diagnostics
;
using
System.Formats.Asn1
;
using
System.Text
;
...
...
@@ -92,7 +93,7 @@ internal static partial class X500NameEncoder
{
AsnReader
tavReader
=
rdnReader
.
ReadSequence
();
string
oid
=
tavReader
.
ReadObjectIdentifier
();
string
attributeValue
=
tavReader
.
ReadAnyAsnString
(
);
string
attributeValue
=
ReadAttributeValue
(
tavReader
,
out
bool
fallback
);
tavReader
.
ThrowIfNotEmpty
();
...
...
@@ -110,7 +111,7 @@ internal static partial class X500NameEncoder
AppendOid
(
ref
decodedName
,
oid
);
}
bool
quote
=
quoteIfNeeded
&&
NeedsQuoting
(
attributeValue
);
bool
quote
=
quoteIfNeeded
&&
NeedsQuoting
(
attributeValue
)
&&
!
fallback
;
if
(
quote
)
{
...
...
@@ -144,5 +145,52 @@ internal static partial class X500NameEncoder
throw
new
CryptographicException
(
SR
.
Cryptography_Der_Invalid_Encoding
,
e
);
}
}
private
static
string
ReadAttributeValue
(
AsnReader
tavReader
,
out
bool
binaryFallback
)
{
Debug
.
Assert
(
tavReader
.
RuleSet
==
AsnEncodingRules
.
DER
);
Asn1Tag
tag
=
tavReader
.
PeekTag
();
if
(
tag
.
TagClass
==
TagClass
.
Universal
)
{
switch
((
UniversalTagNumber
)
tag
.
TagValue
)
{
case
UniversalTagNumber
.
BMPString
:
case
UniversalTagNumber
.
IA5String
:
case
UniversalTagNumber
.
NumericString
:
case
UniversalTagNumber
.
PrintableString
:
case
UniversalTagNumber
.
UTF8String
:
case
UniversalTagNumber
.
T61String
:
// .NET's string comparisons start by checking the length, so a trailing
// NULL character which was literally embedded in the DER would cause a
// failure in .NET whereas it wouldn't have with strcmp.
binaryFallback
=
false
;
return
tavReader
.
ReadCharacterString
((
UniversalTagNumber
)
tag
.
TagValue
).
TrimEnd
(
'\0'
);
case
UniversalTagNumber
.
OctetString
:
// Windows will implicitly unwrap one OCTET STRING and display only the contents.
if
(
tavReader
.
TryReadPrimitiveOctetString
(
out
ReadOnlyMemory
<
byte
>
contents
))
{
binaryFallback
=
true
;
return
BinaryEncode
(
contents
);
}
Debug
.
Fail
(
"TryReadPrimitiveOctetString should either succeed or throw with DER."
);
throw
new
CryptographicException
(
SR
.
Cryptography_Der_Invalid_Encoding
);
}
}
binaryFallback
=
true
;
return
BinaryEncode
(
tavReader
.
ReadEncodedValue
());
static
string
BinaryEncode
(
ReadOnlyMemory
<
byte
>
data
)
{
return
string
.
Create
(
1
+
data
.
Length
*
2
,
data
,
static
(
buff
,
state
)
=>
{
buff
[
0
]
=
'#'
;
HexConverter
.
EncodeToUtf16
(
state
.
Span
,
buff
.
Slice
(
1
));
});
}
}
}
}
src/libraries/System.Security.Cryptography/tests/X509Certificates/X500DistinguishedNameTests.cs
浏览文件 @
d3d537fa
...
...
@@ -458,6 +458,84 @@ public static void CheckCachedOids()
Assert
.
Equal
(
"1.2.840.113549.1.9.1"
,
rdns
[
2
].
GetSingleElementType
().
Value
);
}
[
Theory
]
[
InlineData
(
new
[]
{
"2.5.4.3"
},
new
[]
{
"3000"
},
"CN=#3000"
)]
[
InlineData
(
new
[]
{
"2.5.4.5"
},
new
[]
{
"0603550406"
},
"SERIALNUMBER=#0603550406"
)]
[
InlineData
(
new
[]
{
"0.0"
},
new
[]
{
"31020500"
},
"OID.0.0=#31020500"
)]
[
InlineData
(
new
[]
{
"2.5.4.3"
},
new
[]
{
"04023000"
},
"CN=#3000"
)]
// OCTET STRING is implicitly stripped
[
InlineData
(
new
[]
{
"2.5.4.3"
},
new
[]
{
"040404023000"
},
"CN=#04023000"
)]
// Only one OCTET STRING is stripped
[
InlineData
(
new
[]
{
"2.5.4.3"
},
new
[]
{
"0303003000"
},
"CN=#0303003000"
)]
// BIT STRING is not implicitly stripped
[
InlineData
(
new
[]
{
"2.5.4.8"
},
new
[]
{
"0500"
},
"S=#0500"
)]
[
InlineData
(
new
[]
{
"2.5.4.8"
},
new
[]
{
"0101FF"
},
"S=#0101FF"
)]
[
InlineData
(
new
[]
{
"2.5.4.3"
,
"2.5.4.8"
},
new
[]
{
"0101FF"
,
"3000"
},
"CN=#0101FF, S=#3000"
)]
[
InlineData
(
new
[]
{
"2.5.4.3"
,
"2.5.4.8"
,
"0.0"
},
new
[]
{
"0C02504A"
,
"3000"
,
"0C024141"
},
"CN=PJ, S=#3000, OID.0.0=AA"
)]
[
InlineData
(
new
[]
{
"2.5.4.3"
,
"2.5.4.8"
},
new
[]
{
"0C03233030"
,
"3000"
},
"CN=\"#00\", S=#3000"
)]
[
SkipOnPlatform
(
TestPlatforms
.
Browser
,
"Browser doesn't support an X.509 PAL"
)]
public
static
void
Format_ComponentWithNonStringContent
(
string
[]
oids
,
string
[]
attributeValues
,
string
expected
)
{
AsnWriter
writer
=
new
AsnWriter
(
AsnEncodingRules
.
DER
);
using
(
writer
.
PushSequence
())
{
for
(
int
i
=
0
;
i
<
oids
.
Length
;
i
++)
{
using
(
writer
.
PushSetOf
())
using
(
writer
.
PushSequence
())
{
writer
.
WriteObjectIdentifier
(
oids
[
i
]);
writer
.
WriteEncodedValue
(
Convert
.
FromHexString
(
attributeValues
[
i
]));
}
}
}
X500DistinguishedName
distinguishedName
=
new
X500DistinguishedName
(
writer
.
Encode
());
string
dnString
=
distinguishedName
.
Format
(
false
);
Assert
.
Equal
(
expected
,
dnString
);
string
decode
=
distinguishedName
.
Decode
(
X500DistinguishedNameFlags
.
None
);
Assert
.
Equal
(
expected
,
decode
);
}
[
Fact
]
[
SkipOnPlatform
(
TestPlatforms
.
Browser
,
"Browser doesn't support an X.509 PAL"
)]
public
static
void
Format_MultiValueComponentWithNonStringContent
()
{
AsnWriter
writer
=
new
AsnWriter
(
AsnEncodingRules
.
DER
);
using
(
writer
.
PushSequence
())
{
using
(
writer
.
PushSetOf
())
{
WriteRDNComponent
(
writer
,
"2.5.4.3"
,
"3000"
);
WriteRDNComponent
(
writer
,
"2.5.4.8"
,
"3100"
);
}
using
(
writer
.
PushSetOf
())
{
WriteRDNComponent
(
writer
,
"2.5.4.5"
,
"0C0430313233"
);
WriteRDNComponent
(
writer
,
"2.5.4.10"
,
"31055050505050"
);
WriteRDNComponent
(
writer
,
"2.5.4.9"
,
"0C075441434F434154"
);
}
}
const
string
Expected
=
"CN=#3000 + S=#3100, SERIALNUMBER=0123 + O=#31055050505050 + STREET=TACOCAT"
;
X500DistinguishedName
distinguishedName
=
new
X500DistinguishedName
(
writer
.
Encode
());
string
dnString
=
distinguishedName
.
Format
(
false
);
Assert
.
Equal
(
Expected
,
dnString
);
string
decode
=
distinguishedName
.
Decode
(
X500DistinguishedNameFlags
.
None
);
Assert
.
Equal
(
Expected
,
decode
);
static
void
WriteRDNComponent
(
AsnWriter
writer
,
string
oid
,
string
value
)
{
using
(
writer
.
PushSequence
())
{
writer
.
WriteObjectIdentifier
(
oid
);
writer
.
WriteEncodedValue
(
Convert
.
FromHexString
(
value
));
}
}
}
public
static
readonly
object
[][]
WhitespaceBeforeCases
=
{
// Regular space.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录