Shouldn't CSRs automatically add default version?

本文讨论了在使用OpenSSL生成证书签名请求(CSR)时,默认版本号设置的重要性。作者指出,若未显式设置版本号,则可能导致某些系统无法正确解析CSR。文章探讨了OpenSSL是否应在未指定版本时自动添加默认版本。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Shouldn't CSRs automatically add default version?

classicClassiclistListthreadedThreaded
3 messages  Options  Options 
Reply |  Threaded |  More       star

Shouldn't CSRs automatically add default version?

Ken Smith
3 posts
(I originally sent this to openssl-users but it is a question about 
the implementation of OpenSSL more than the usage so I'm reposting 
here.) 

I'm programmatically generating CSRs per the example in 10.3.1 of 
Network Programming with OpenSSL. This CSR is fine according to the 
openssl command line tool and to Bouncy Castle's .NET PKCS#10 handling 
code. The Windows Crypto API function, CryptDecodeObjectEx refuses to 
parse the CSR claiming that it is corrupted ASN.1. Here's an example. 

-----BEGIN CERTIFICATE REQUEST----- 
MIICbzCCAVcCADArMSkwJwYDVQQDEyBiYjA2NGU1MDIwMTcwOTE4MTY0ZTlmMDY2 
MWMyNmVhMjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMWfPXnVtnMj 
e2WvpNuBQW7lg3cxztBbPPyis+KoWysslWjA2Z2JpKN3GY25ncpZoJWbCMetIFPA 
Ue/cqOM0IWlck9tjPOFby+Zjftz5icdaJ1+xGryX9NizyCuAFlxWlKwToH8d22sG 
xYnKK/ioRKXjZb14tyME0tA3MOXO3JN+2+KK6A0BC54GO03ce72PYpbx0FYkt9VF 
bAgc42Xq9wiNJfzH/gbyk/avFvMHNL+5pJ1oBWjbbGUiPCHqONuVmKFsGP81lNJG 
HUrK7J1cKfyfV2YR7RJZLKDXBf6UKh0Qntrpm5f5lYIgNekt/AY2DDHBoyBItjIk 
/pUWfnvXTcsCAwEAAaAAMA0GCSqGSIb3DQEBCwUAA4IBAQBse8alivTZxKF2Uw2f 
3xM84buzbrvTsMAVDpGGgkuOd54lcShMvhIMpHDmuQgDrJgRuhbLhKpcXJIpQxj9 
zZbvlZnKPuvqOQX0+4rTgl4QTq42dCOnRxSLrmuh1kZoB40bp7iICKQq3zXsz89v 
HNPC54Pnwxv1sp0J2C2EG6c3WdBJ9Z8F8yhUPdJWQla91i5rLVSrZClDm80bCpPf 
WYmmGRhyCwZ6XeD0FkvcUTxXpJkyhzYlyG7KndW0EScazJdBens8ox2YdUtpw2BT 
OYy6Bu/cFhgqdYKUxd0iVQ9lP4xrLzKYl3x0Np2Qay8n59rDhsAfgk0bSc0Lxok3 
0s8Z 
-----END CERTIFICATE REQUEST----- 

OpenSSL's command line asn1parse tool reads this just fine. Peter 
Gutmann's dumpasn1 (www.cs.auckland.ac.nz/~pgut001/dumpasn1.c) claims 
that there are two ASN.1 errors in this CSR. 

  0 623: SEQUENCE { 
  4 343:   SEQUENCE { 
  8   0:     INTEGER 
       :       Error: Object has zero length. 
 10  43:     SEQUENCE { 
... 
349   0:     [0] 
       :       Error: Object has zero length. 
       :     } 
351  13:   SEQUENCE { 
353   9:     OBJECT IDENTIFIER '1 2 840 113549 1 1 11' 
364   0:     NULL 
       :     } 

This could be an error with Mr. Gutmann's tool but the fact that 
Windows Crypto API doesn't like the CSR is curious. I followed this 
advice 

http://stackoverflow.com/questions/15294964/windows-2008r2-ca-openssl-csr-error-parsing-csr-asn1-bad-value-met

and added a call to X509_REQ_set_version(req, 0). Now Windows Crypto 
API will accept CSRs I generate. 

Section 4.1 of RFC 2986 says, "Certification request information shall 
have...CertificationRequestInfo ::= SEQUENCE { version INTEGER { v1(0) 
} (v1,...),". Shouldn't OpenSSL be adding a version with a default 
value of 0 even when X509_REQ_set_version is not called? 

   Kind regards, 
   Ken Smith 
   :{> 
______________________________________________________________________ 
OpenSSL Project                                  http://www.openssl.org
Development Mailing List                        [hidden email] 
Automated List Manager                            [hidden email] 
Reply |  Threaded |  More       star

Re: [openssl-dev] Shouldn't CSRs automatically add default version?

Erwann ABALEA
221 posts
That CSR is clearly invalid, because one of its objects isn't properly 
DER encoded. 
The INTEGER encoding its version has a length equal to zero, and this 
isn't permitted by X.690 (BER/DER/CER encoding): 
"8.3.1 The encoding of an integer value shall be primitive. The contents 
octets shall consist of one or more octets." 

OpenSSL could set the version to 0 by default when creating the X509_REQ 
object (this is done when you call the X509_to_X509_REQ() function). 
But the version field is not declared as "INTEGER DEFAULT v1", so it 
could be acceptable to consider that explicitely setting the version is 
the responsibility of the application creating the request. 

-- 
Erwann ABALEA 

Le 16/03/2013 19:22, Ken Smith a écrit :

> -----BEGIN CERTIFICATE REQUEST----- 
> MIICbzCCAVcCADArMSkwJwYDVQQDEyBiYjA2NGU1MDIwMTcwOTE4MTY0ZTlmMDY2 
> [...] 
> 0s8Z 
> -----END CERTIFICATE REQUEST----- 
> [...] 
> Section 4.1 of RFC 2986 says, "Certification request information shall 
> have...CertificationRequestInfo ::= SEQUENCE { version INTEGER { v1(0) 
> } (v1,...),". Shouldn't OpenSSL be adding a version with a default 
> value of 0 even when X509_REQ_set_version is not called?

______________________________________________________________________ 
OpenSSL Project                                  http://www.openssl.org
Development Mailing List                        [hidden email] 
Automated List Manager                            [hidden email] 
Reply |  Threaded |  More       star

Re: [openssl-dev] Shouldn't CSRs automatically add default version?

Ken Smith
3 posts
On Mon, Mar 18, 2013 at 5:42 AM, Erwann Abalea 
< [hidden email]> wrote: 
> That CSR is clearly invalid, because one of its objects isn't properly DER 
> encoded. 

This is precisely my point. All of the OpenSSL calls I make succeed 
including PEM_write_X509_REQ. Either, 

 - the call to PEM_write_X509_REQ should fail indicating that it can't 
construct valid ASN.1 because the structure lacks a version 
 - or the X509_REQ should encode a default version of 0 in the event 
the user failed to specify. 

As it stands, it is possible to sail through successful calls to the 
OpenSSL API and end up with something invalid. This violates the the 
principle of least surprise. 

   :{> 
______________________________________________________________________ 
OpenSSL Project                                  http://www.openssl.org
Development Mailing List                        [hidden email] 
Automated List Manager                            [hidden email] 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值