大网数据广告活动
服务器运维问答

SAN certificate with URI fragment

· 52CE 我爱测

I need to generate a TLS certificate with a SAN URI where the URI has a fragment (has a hash '#'). But when I try to generate a certificate using openssl, the fragment gets stripped. # generate key and CSR for client certificate …

问题原文

原帖链接 · Rich Remer · CC BY-SA 4.0

I need to generate a TLS certificate with a SAN URI where the URI has a fragment (has a hash '#'). But when I try to generate a certificate using openssl, the fragment gets stripped.

# generate key and CSR for client certificate
openssl req -nodes -new -keyout me.key -out me.csr -subj "/O=Acme/CN=me"

# sign cert
openssl x509 -req -in me.csr -CA My-CA.crt -CAkey My-CA.key -set_serial 01 -out me.crt -extfile <(echo 'subjectAltName=URI:https://my.example/profile#me')

# verify result
openssl x509 -text -noout -in me.crt
#         X509v3 extensions:
#             X509v3 Subject Alternative Name:
#                 URI:https://my.example/profile

I've tried a few different ways of escaping the value, but nothing seems to work as expected. I think the escapes may work for fields like Common Name, but don't work in the SAN section.

I'm open to openssl alternatives. But it would be helpful to see a proof-of-concept certificate I can use to verify that it works.

NOTE: This is essentially a requirement of WebID-TLS (https://www.w3.org/2005/Incubator/webid/spec/tls/#dfn-webid_certificate). While it's possible to use a URL without a fragment for WebID, it's not recommended and requires extra work. It definitely should be supported.

社区高分解答

原帖链接 · Steffen Ullrich · CC BY-SA 4.0

A hash sign in OpenSSL config is treated as the beginning of a comment, no matter if the config is given in a real file or by generating it on the fly. If you want to include it in the SAN you therefore need to escape or quote the hash in order to prevent treating it as start as comment. Quoted it looks like this:

... -extfile <(echo 'subjectAltName="URI:https://my.example/profile#me"')

or escaped:

... -extfile <(echo 'subjectAltName=URI:https://my.example/profile\#me')

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2023-04-06)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。