What is the correct order of the ICP-Brazil certificate chain so that the certificate of an e-CPF and e-CNPJ is requested via TLS Handshake? [closed]

7

To authenticate a user using the digital certificate, and to obtain this certificate in the backend it is necessary to enable the "SSL / TSL Handshake" option on the web server with the option to export the certificate as environment variable - allowing access, after being authorized and selected, by the language behind the web application .

However, only certificates that are in the property " CA bundle " are allowed and listed at the prompt. The CA bundle defines the certificate chain that is trusted for authentication to this site.

In the case of e-CPF and e-CNPJ, which are digital certificates signed by the certification chain of ICP-Brasil a>.

I have used a script to download and generate the bundle with all the certificates publicly available on the official website, for those who are interested the script is as follows , but I did not succeed in implementing the generated file in my webserver because the order generated by this script is random.

As this script lowers all certificates, it is still allowing the inclusion of NF-e and OAB type certificates, which is not the focus.

The expected result looks something like this:

Tryingonallthecombinationswouldnotbeanoptionatthemomentbecausetherearemorethan133certificatesfromthemaindirectory(availablehereforthosewhoneedtodownload: link ).

    
asked by anonymous 04.04.2017 / 21:30

1 answer

5

After some searches on several sites, I got the expected result.

To complete the SSL Handshake flow, the server needs to tell which certificates are accepted, so the browser will display the selection prompt with only valid certificates to complete this request, as shown in the diagram below:

Inthisway,youneedtoaddonlythe"Root" certificates in this "bundle" of CAs. This combined file must respect the RFC 4346 using the delimiters correctly for the file to be read correctly by the web server.

The order that is working with me is as follows:

  • Brazilian Root Certification Authority v5 (NF-e / e-CPF / e-CNPJ v5)
  • Brazilian Root V2 (e-CPF / e-CNPJ v2)
  • In this way:

    CA do HTTPS do site 
    ==========
    (...)
    = CA ICP Brasil =
    (NF-e/e-CPF/e-CNPJ v5)Autoridade Certificadora Raiz Brasileira v5
    ==========
    -----BEGIN CERTIFICATE-----
    MIIGoTCCBImgAwIBAgIBATANBgkqhkiG9w0BAQ0FADCBlzELMAkGA1UEBhMCQlIx
    EzARBgNVBAoMCklDUC1CcmFzaWwxPTA7BgNVBAsMNEluc3RpdHV0byBOYWNpb25h
    bCBkZSBUZWNub2xvZ2lhIGRhIEluZm9ybWFjYW8gLSBJVEkxNDAyBgN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
    yzamEQIDAQABo4H1MIHyME4GA1UdIARHMEUwQwYFYEwBAQAwOjA4BggrBgEFBQcC
    ARYsaHR0cDovL2FjcmFpei5pY3BicmFzaWwuZ292LmJyL0RQQ2FjcmFpei5wZGYw
    PwYDVR0fBDgwNjA0oDKgMIYuaHR0cDovL2FjcmFpei5pY3BicmFzaWwuZ292LmJy
    L0xDUmFjcmFpenY1LmNybDAfBgNVHSMEGDAWgBRpqL512cTvbOcTReRhbuVo+LZA
    XjAdBgNVHQ4EFgQUaai+ddnE72znE0XkYW7laPi2QF4wDwYDVR0TAQH/BAUwAwEB
    /zAOBgNVHQ8BAf8EBAMCAQYwDQYJKoZIhvcNAQENBQADggIBABRt2/JiWapef7o/
    plhR4PxymlMIp/JeZ5F0BZ1XafmYpl5g6pRokFrIRMFXLyEhlgo51I05InyCc9Td
    6UXjlsOASTc/LRavyjB/8NcQjlRYDh6xf7OdP05mFcT/0+6bYRtNgsnUbr10pfsK
    /UzyUvQWbumGS57hCZrAZOyd9MzukiF/azAa6JfoZk2nDkEudKOY8tRyTpMmDzN5
    fufPSC3v7tSJUqTqo5z7roN/FmckRzGAYyz5XulbOc5/UsAT/tk+KP/clbbqd/hh
    evmmdJclLr9qWZZcOgzuFU2YsgProtVu0fFNXGr6KK9fu44pOHajmMsTXK3X7r/P
    wh19kFRow5F3RQMUZC6Re0YLfXh+ypnUSCzA+uL4JPtHIGyvkbWiulkustpOKUSV
    wBPzvA2sQUOvqdbAR7C8jcHYFJMuK2HZFji7pxcWWab/NKsFcJ3sluDjmhizpQax
    bYTfAVXu3q8yd0su/BHHhBpteyHvYyyz0Eb9LUysR2cMtWvfPU6vnoPgYvOGO1Cz
    iyGEsgKULkCH4o2Vgl1gQuKWO4V68rFW8a/jvq28sbY+y/Ao0I5ohpnBcQOAawiF
    bz6yJtObajYMuztDDP8oY656EuuJXBJhuKAJPI/7WDtgfV8ffOh/iQGQATVMtgDN
    0gv8bn5NdUX8UMNX1sHhU3H1UpoW
    -----END CERTIFICATE-----
    
    
    
    (e-CPF/e-CNPJ v2) Raiz Brasileira V2
    ===========================================
    -----BEGIN CERTIFICATE-----
    MIIGoTCCBImgAwIBAgIBATANBgkqhkiG9w0BAQ0FADCBlzELMAkGA1UEBhMCQlIx
    EzARBgNVBAoTCklDUC1CcmFzaWwxPTA7BgNVBAsTNEluc3RpdHV0byBOYWNpb25h
    bCBkZSBUZWNub2xvZ2lhIGRhIEluZm9ybWFjYW8gLSBJVEkxNDAyBgNVBAMTK0F1
    dG9yaWRhZGUgQ2VydGlmaWNhZG9yYSBSYWl6IEJyYXNpbGVpcmEgdjIwHhcNMTAw
    NjIxMTkwNDU3WhcNMjMwNjIxMTkwNDU3WjCBlzELMAkGA1UEBhMCQlIxEzARBgNV
    BAoTCklDUC1CcmFzaWwxPTA7BgNVBAsTNEluc3RpdHV0byBOYWNpb25hbCBkZSBU
    ZWNub2xvZ2lhIGRhIEluZm9ybWFjYW8gLSBJVEkxNDAyBgNVBAMTK0F1dG9yaWRh
    ZGUgQ2VydGlmaWNhZG9yYSBSYWl6IEJyYXNpbGVpcmEgdjIwggIiMA0GCSqGSIb3
    DQEBAQUAA4ICDwAwggIKAoICAQC6RqQO3edA8rWgfFKVV0X8bYTzhgHJhQOtmKvS
    8l4Fmcm7b2Jn/XdEuQMHPNIbAGLUcCxCg3lmq5lWroG8akm983QPYrfrWwdmlEIk
    nUasmkIYMPAkqFFB6quV8agrAnhptSknXpwuc8b+I6Xjps79bBtrAFTrAK1POkw8
    5wqIW9pemgtW5LVUOB3yCpNkTsNBklMgKs/8dG7U2zM4YuT+jkxYHPePKk3/xZLZ
    CVK9z3AAnWmaM2qIh0UhmRZRDTTfgr20aah8fNTd0/IVXEvFWBDqhRnLNiJYKnIM
    mpbeys8IUWG/tAUpBiuGkP7pTcMEBUfLz3bZf3Gmh3sVQOQzgHgHHaTyjptAO8ly
    UN9pvvAslh+QtdWudONltIwa6Wob+3JcxYJU6uBTB8TMEun33tcv1EgvRz8mYQSx
    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CsNid3kXFsygETUQuwq8/JAhzHVPuIKMgwUjdVybQvm/Y3kqPMFjXUX
    d5sKufqQkplliDJnQwWOLQsVuzXxYejZZ3ftFuXoAS1rND+Og7P36g9KHj41hJ2M
    gDQ/qZXow63EzZ7KFBYsGZ7kNou5uaNCJQc+w+XVaE+gZhyms7ZzHJAaP0C5GlZC
    cIf/by0PEf0e//eFMBUO4xcx7ieVzMnpmR6Xx21bB7UFaj3yRd+6gnkkcC6bgh9m
    qaVtJ8z2KqLRX4Vv4EadqtKlTlUO
    -----END CERTIFICATE-----
    

    These 2 meet the newest certificates. You can download them from the official website:

    link

        
    11.04.2017 / 17:49