Bug 2015511

Summary: certmonger creates CSRs with invalid DER syntax for X509v3 extensions with critical=FALSE
Product: Red Hat Enterprise Linux 7 Reporter: Rob Crittenden <rcritten>
Component: certmongerAssignee: Rob Crittenden <rcritten>
Status: CLOSED ERRATA QA Contact: ipa-qe <ipa-qe>
Severity: high Docs Contact:
Priority: high    
Version: 7.9CC: amore, ipa-qe, jreznik, ssidhaye, tapazogl
Target Milestone: rcKeywords: Triaged, ZStream
Target Release: ---Flags: pm-rhel: mirror+
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: certmonger-0.78.4-17.el7_9 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: 2012258 Environment:
Last Closed: 2021-11-23 17:17:25 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 2012258    
Bug Blocks: 2012261    

Description Rob Crittenden 2021-10-19 11:58:01 UTC
+++ This bug was initially created as a clone of Bug #2012258 +++

Description of problem:

certmonger's template for X509v3 extensions is wrong and generate invalid DER for extensions with critical=FALSE. Since FALSE is the default value, a standard conform CSR or cert must not encode the critical flag.

$ openssl asn1parse -inform PEM -in freeipa.csr
...
  421:d=7  hl=2 l=   3 prim: OBJECT            :X509v3 Subject Alternative Name
  426:d=7  hl=2 l=   1 prim: BOOLEAN           :0
  429:d=7  hl=3 l= 135 prim: OCTET STRING      [HEX DUMP]:...

The line BOOLEAN 0 should not be present.

/* RFC 5280, 4.1 */
const SEC_ASN1Template
cm_certext_cert_extension_template[] = {
        {
        .kind = SEC_ASN1_SEQUENCE,
        .offset = 0,
        .sub = NULL,
        .size = sizeof(CERTCertExtension),
        },
        {
        .kind = SEC_ASN1_OBJECT_ID,
        .offset = offsetof(CERTCertExtension, id),
        .sub = NULL,
        .size = sizeof(SECItem),
        },
        {
        .kind = SEC_ASN1_BOOLEAN,
        .offset = offsetof(CERTCertExtension, critical),
        .sub = NULL,
        .size = sizeof(SECItem),
        },
        {
        .kind = SEC_ASN1_OCTET_STRING,
        .offset = offsetof(CERTCertExtension, value),
        .sub = NULL,
        .size = sizeof(SECItem),
        },
        {0, 0, NULL, 0},
};

The correct kind for the critical extension is SEC_ASN1_OPTIONAL | SEC_ASN1_BOOLEAN.

    https://github.com/servo/nss/blob/949eb9848f4fa5f83756f3ab7fdf9b0d3f20d37f/lib/certdb/certdb.c#L50
    https://github.com/pyca/cryptography/issues/6368
    https://pagure.io/freeipa/issue/9005

Version-Release number of selected component (if applicable):

certmonger-0.79.13-3

How reproducible:


Steps to Reproduce:
1. install an IPA server
2. pull the csr= value from /var/lib/certmonger/reqeusts/<some id> into a separate file
3. openssl asn1parse -inform PEM -in /path/to/file

Expected results:

There should be no BOOLEAN value for the critical flag, so nothing between the SAN and the start of the HEX DUMP.

--- Additional comment from Rob Crittenden on 2021-10-08 17:04:16 UTC ---

Fixed in master:

9312d1892c611d9f0e814cb915488182da2b76cc
e3e4679693efc60bc7a25983909ddfa6883ab2ec

Comment 10 anuja 2021-11-11 07:59:56 UTC
Verified using nightly compose:

[root@master ~]# rpm -qa ipa-server certmonger
certmonger-0.78.4-17.el7_9.x86_64
ipa-server-4.6.8-5.el7_9.9.x86_64
[root@master ~]# vi /var/lib/certmonger/requests/20211111074501 
[root@master ~]# vi fixed
[root@master ~]# ipactl status
Directory Service: RUNNING
krb5kdc Service: RUNNING
kadmin Service: RUNNING
named Service: RUNNING
httpd Service: RUNNING
ipa-custodia Service: RUNNING
ntpd Service: RUNNING
pki-tomcatd Service: RUNNING
ipa-otpd Service: RUNNING
ipa-dnskeysyncd Service: RUNNING
ipa: INFO: The ipactl command was successful
[root@master ~]# openssl asn1parse -inform PEM -in fixed 
    0:d=0  hl=4 l= 881 cons: SEQUENCE          
    4:d=1  hl=4 l= 601 cons: SEQUENCE          
    8:d=2  hl=2 l=   1 prim: INTEGER           :00
   11:d=2  hl=2 l=  36 cons: SEQUENCE          
   13:d=3  hl=2 l=  17 cons: SET               
   15:d=4  hl=2 l=  15 cons: SEQUENCE          
   17:d=5  hl=2 l=   3 prim: OBJECT            :organizationName
   22:d=5  hl=2 l=   8 prim: UTF8STRING        :IPA.TEST
   32:d=3  hl=2 l=  15 cons: SET               
   34:d=4  hl=2 l=  13 cons: SEQUENCE          
   36:d=5  hl=2 l=   3 prim: OBJECT            :commonName
   41:d=5  hl=2 l=   6 prim: PRINTABLESTRING   :IPA RA
   49:d=2  hl=4 l= 290 cons: SEQUENCE          
   53:d=3  hl=2 l=  13 cons: SEQUENCE          
   55:d=4  hl=2 l=   9 prim: OBJECT            :rsaEncryption
   66:d=4  hl=2 l=   0 prim: NULL              
   68:d=3  hl=4 l= 271 prim: BIT STRING        
  343:d=2  hl=4 l= 262 cons: cont [ 0 ]        
  347:d=3  hl=2 l=  43 cons: SEQUENCE          
  349:d=4  hl=2 l=   9 prim: OBJECT            :friendlyName
  360:d=4  hl=2 l=  30 cons: SET               
  362:d=5  hl=2 l=  28 prim: BMPSTRING         
  392:d=3  hl=3 l= 214 cons: SEQUENCE          
  395:d=4  hl=2 l=   9 prim: OBJECT            :Extension Request
  406:d=4  hl=3 l= 200 cons: SET               
  409:d=5  hl=3 l= 197 cons: SEQUENCE          
  412:d=6  hl=2 l= 109 cons: SEQUENCE          
  414:d=7  hl=2 l=   3 prim: OBJECT            :X509v3 Subject Alternative Name
  419:d=7  hl=2 l= 102 prim: OCTET STRING      [HEX DUMP]:3064A024060A2B060104018237140203A0160C14686F73742F6D61737465722E6970612E74657374A03C06062B0601050202A0323030A00A1B084950412E54455354A1223020A003020101A11930171B04686F73741B0F6D61737465722E6970612E74657374
  523:d=6  hl=2 l=  12 cons: SEQUENCE          
  525:d=7  hl=2 l=   3 prim: OBJECT            :X509v3 Basic Constraints
  530:d=7  hl=2 l=   1 prim: BOOLEAN           :255
  533:d=7  hl=2 l=   2 prim: OCTET STRING      [HEX DUMP]:3000
  537:d=6  hl=2 l=  29 cons: SEQUENCE          
  539:d=7  hl=2 l=   3 prim: OBJECT            :X509v3 Subject Key Identifier
  544:d=7  hl=2 l=  22 prim: OCTET STRING      [HEX DUMP]:041413D246A8B3CAFA8787CF3A63EAA22D91A030F218
  568:d=6  hl=2 l=  39 cons: SEQUENCE          
  570:d=7  hl=2 l=   9 prim: OBJECT            :1.3.6.1.4.1.311.20.2
  581:d=7  hl=2 l=  26 prim: OCTET STRING      [HEX DUMP]:1E18006300610053006500720076006500720043006500720074
  609:d=1  hl=2 l=  13 cons: SEQUENCE          
  611:d=2  hl=2 l=   9 prim: OBJECT            :sha256WithRSAEncryption
  622:d=2  hl=2 l=   0 prim: NULL              
  624:d=1  hl=4 l= 257 prim: BIT STRING        
[root@master ~]# 
[root@master ~]# date ; openssl asn1parse -inform PEM -in fixed  | grep -B 1 -A 1 BOOLEAN
Thu Nov 11 02:54:26 EST 2021
  525:d=7  hl=2 l=   3 prim: OBJECT            :X509v3 Basic Constraints
  530:d=7  hl=2 l=   1 prim: BOOLEAN           :255
  533:d=7  hl=2 l=   2 prim: OCTET STRING      [HEX DUMP]:3000
[root@master ~]# 

No boolean value assigned between the SAN and the start of the HEX DUMP.

Comment 14 errata-xmlrpc 2021-11-23 17:17:25 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (certmonger bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2021:4795