Keyfactor / ejbca-ce

EJBCA® – Open-source public key infrastructure (PKI) and certificate authority (CA) software.
https://www.ejbca.org/
GNU Lesser General Public License v2.1
617 stars 107 forks source link

Cisco SCEP not working post-7.4.3.2 #176

Closed sbingner closed 1 year ago

sbingner commented 1 year ago

I don't know exactly where this broke but somewhere between 7.4.3.2 (working) and 7.9.0.2 (those were the 2 images I found to test in docker) it starting using an encryption algorithm that apparently Cisco does not support and does not seem to have any options to configure the alogrithms. If I use 7.9.0.2 (or latest) I get the below errors on the Cisco side after crypto pki enroll but there are no errors on the EJBCA side and it generates the cert fine... just doesn't get loaded by Cisco.

Nov 28 08:36:34.383: CRYPTO_PKI(Cert Lookup) issuer="cn=TestCA" serial number= 
     29 39 B6 B0 84 85 C4 48 3E 8D AB 27 43 9D 66 FC 
     A2 D1 87 71                                     

Nov 28 08:36:34.383: CRYPTO_PKI: looking for cert in handle=3EB7737C, digest=
 CD 71 D7 88 E4 BA AE 26 05 B6 83 3E 74 B4 80 14 

Nov 28 08:36:34.385: ../cert-c/source/p7spprt.c(633) : E_ENCRYPT_ALG_NOT_SUPPORTED : message encryption algorithms not supported
Nov 28 08:36:34.385:  Invalid signer count value 0
Nov 28 08:36:34.385: CRYPTO_PKI: Remove global revocation service providers
Nov 28 08:36:34.385: CRYPTO_PKI: status = 0x762(E_ENCRYPT_ALG_NOT_SUPPORTED : message encryption algorithms not supported): failed to verify
Nov 28 08:36:34.388: CRYPTO_PKI: set re-enroll timer to 47303133-second
Nov 28 08:36:34.388: CRYPTO_PKI: All enrollment requests completed for trustpoint TestCA.
primetomas commented 1 year ago

Just thinking...there was a lot of work done to SCEP for Intune lately. Perhaps related to this. If you enable DEBUG logging in EJBCA it should log what algorithms it uses to protect messages, and what it receives. DEBUG logs from 7.4.3.2 and 7.9.0.2 (or perhaps rather the latest 7.10.0.2) would be interesting.

sbingner commented 1 year ago

7.10.0.2

2022-12-03 09:03:41,396+0000 DEBUG [org.ejbca.core.protocol.scep.ScepResponseMessage] (default task-1) Setting 1.3.14.3.2.7 as preferred content encryption algorithm in SCEP response.
2022-12-03 09:03:41,396+0000 DEBUG [org.ejbca.core.protocol.scep.ScepResponseMessage] (default task-1) Creating a STATUS_OK message.
2022-12-03 09:03:41,396+0000 DEBUG [org.ejbca.core.protocol.scep.ScepResponseMessage] (default task-1) Adding certificates to response message
2022-12-03 09:03:41,397+0000 DEBUG [org.ejbca.core.protocol.scep.ScepResponseMessage] (default task-1) Including explicitly set CA certificate in SCEP response.
2022-12-03 09:03:41,397+0000 DEBUG [org.ejbca.core.protocol.scep.ScepResponseMessage] (default task-1) Added recipient information - issuer: 'CN=TestCA', serno: '3109593F2B4163EAE443223F421637983A781A7F
2022-12-03 09:03:41,398+0000 DEBUG [org.ejbca.core.protocol.scep.ScepResponseMessage] (default task-1) Enveloped data is 2313 bytes long
2022-12-03 09:03:41,398+0000 DEBUG [org.ejbca.core.protocol.scep.ScepResponseMessage] (default task-1) Added transactionId: 7970AD5B96A8DACF53C4BD1AB46BD94F
2022-12-03 09:03:41,398+0000 DEBUG [org.ejbca.core.protocol.scep.ScepResponseMessage] (default task-1) Added senderNonce: qIj8QfMZujLsV6hes9hTJw==
2022-12-03 09:03:41,398+0000 DEBUG [org.ejbca.core.protocol.scep.ScepResponseMessage] (default task-1) Added recipientNonce: tDbt8AAOQa8owqXdeas1rA==
2022-12-03 09:03:41,398+0000 DEBUG [org.ejbca.core.protocol.scep.ScepResponseMessage] (default task-1) Signing SCEP message with cert: CN=TestCA
2022-12-03 09:03:41,399+0000 DEBUG [org.cesecore.certificates.util.AlgorithmTools] (default task-1) getSignAlgOidFromDigestAndKey: 1.2.840.113549.1.1.11
2022-12-03 09:03:41,403+0000 DEBUG [org.ejbca.core.protocol.scep.ScepResponseMessage] (default task-1) Creating a STATUS_OK message.
2022-12-03 09:03:41,403+0000 DEBUG [org.ejbca.core.protocol.scep.ScepResponseMessage] (default task-1) Adding certificates to response message
2022-12-03 09:03:41,403+0000 DEBUG [org.ejbca.core.protocol.scep.ScepResponseMessage] (default task-1) Including explicitly set CA certificate in SCEP response.
2022-12-03 09:03:41,404+0000 DEBUG [org.ejbca.core.protocol.scep.ScepResponseMessage] (default task-1) Added recipient information - issuer: 'CN=TestCA', serno: '3109593F2B4163EAE443223F421637983A781A7F
2022-12-03 09:03:41,405+0000 DEBUG [org.ejbca.core.protocol.scep.ScepResponseMessage] (default task-1) Enveloped data is 2313 bytes long
2022-12-03 09:03:41,405+0000 DEBUG [org.ejbca.core.protocol.scep.ScepResponseMessage] (default task-1) Added transactionId: 7970AD5B96A8DACF53C4BD1AB46BD94F
2022-12-03 09:03:41,405+0000 DEBUG [org.ejbca.core.protocol.scep.ScepResponseMessage] (default task-1) Added senderNonce: qIj8QfMZujLsV6hes9hTJw==
2022-12-03 09:03:41,405+0000 DEBUG [org.ejbca.core.protocol.scep.ScepResponseMessage] (default task-1) Added recipientNonce: tDbt8AAOQa8owqXdeas1rA==
2022-12-03 09:03:41,405+0000 DEBUG [org.ejbca.core.protocol.scep.ScepResponseMessage] (default task-1) Signing SCEP message with cert: CN=TestCA
2022-12-03 09:03:41,405+0000 DEBUG [org.cesecore.certificates.util.AlgorithmTools] (default task-1) getSignAlgOidFromDigestAndKey: 1.2.840.113549.1.1.11
2022-12-03 09:03:41,409+0000 DEBUG [org.ejbca.core.protocol.scep.ScepMessageDispatcherSessionBean] (default task-1) Adding Intune fields to SCEP response: org.ejbca.core.protocol.scep.ScepMessageDispatcherSessionBean$IntuneScepData@4cfecedf
2022-12-03 09:03:41,415+0000 DEBUG [org.ejbca.ui.web.RequestHelper] (default task-1) Sent 3047 bytes to client
2022-12-03 09:03:41,415+0000 INFO  [org.ejbca.ui.web.protocol.ScepServlet] (default task-1) Sent a SCEP PKIOperation response to 172.16.2.1.

7.4.3.2

2022-12-03 09:09:43,292+0000 DEBUG [org.ejbca.core.protocol.scep.ScepResponseMessage] (default task-1) Setting 1.3.14.3.2.7 as preferred content encryption algorithm in SCEP response.
2022-12-03 09:09:43,293+0000 DEBUG [org.ejbca.core.protocol.scep.ScepResponseMessage] (default task-1) Creating a STATUS_OK message.
2022-12-03 09:09:43,293+0000 DEBUG [org.ejbca.core.protocol.scep.ScepResponseMessage] (default task-1) Adding certificates to response message
2022-12-03 09:09:43,293+0000 DEBUG [org.ejbca.core.protocol.scep.ScepResponseMessage] (default task-1) Including explicitly set CA certificate in SCEP response.
2022-12-03 09:09:43,294+0000 DEBUG [org.ejbca.core.protocol.scep.ScepResponseMessage] (default task-1) Added recipient information - issuer: 'CN=TestCA', serno: '3109593F2B4163EAE443223F421637983A781A7F
2022-12-03 09:09:43,300+0000 DEBUG [org.ejbca.core.protocol.scep.ScepResponseMessage] (default task-1) Enveloped data is 2313 bytes long
2022-12-03 09:09:43,300+0000 DEBUG [org.ejbca.core.protocol.scep.ScepResponseMessage] (default task-1) Added transactionId: 7970AD5B96A8DACF53C4BD1AB46BD94F
2022-12-03 09:09:43,301+0000 DEBUG [org.ejbca.core.protocol.scep.ScepResponseMessage] (default task-1) Added senderNonce: vxB+G/mU7CEVe7uMKYT2rQ==
2022-12-03 09:09:43,301+0000 DEBUG [org.ejbca.core.protocol.scep.ScepResponseMessage] (default task-1) Added recipientNonce: nQ26BymJ5Jhhi9L2xoTFxQ==
2022-12-03 09:09:43,301+0000 DEBUG [org.ejbca.core.protocol.scep.ScepResponseMessage] (default task-1) Signing SCEP message with cert: CN=TestCA
2022-12-03 09:09:43,301+0000 DEBUG [org.cesecore.certificates.util.AlgorithmTools] (default task-1) getSignAlgOidFromDigestAndKey: 1.2.840.113549.1.1.5
2022-12-03 09:09:43,312+0000 DEBUG [org.ejbca.core.protocol.scep.ScepResponseMessage] (default task-1) Creating a STATUS_OK message.
2022-12-03 09:09:43,312+0000 DEBUG [org.ejbca.core.protocol.scep.ScepResponseMessage] (default task-1) Adding certificates to response message
2022-12-03 09:09:43,312+0000 DEBUG [org.ejbca.core.protocol.scep.ScepResponseMessage] (default task-1) Including explicitly set CA certificate in SCEP response.
2022-12-03 09:09:43,312+0000 DEBUG [org.ejbca.core.protocol.scep.ScepResponseMessage] (default task-1) Added recipient information - issuer: 'CN=TestCA', serno: '3109593F2B4163EAE443223F421637983A781A7F
2022-12-03 09:09:43,313+0000 DEBUG [org.ejbca.core.protocol.scep.ScepResponseMessage] (default task-1) Enveloped data is 2313 bytes long
2022-12-03 09:09:43,313+0000 DEBUG [org.ejbca.core.protocol.scep.ScepResponseMessage] (default task-1) Added transactionId: 7970AD5B96A8DACF53C4BD1AB46BD94F
2022-12-03 09:09:43,313+0000 DEBUG [org.ejbca.core.protocol.scep.ScepResponseMessage] (default task-1) Added senderNonce: vxB+G/mU7CEVe7uMKYT2rQ==
2022-12-03 09:09:43,313+0000 DEBUG [org.ejbca.core.protocol.scep.ScepResponseMessage] (default task-1) Added recipientNonce: nQ26BymJ5Jhhi9L2xoTFxQ==
2022-12-03 09:09:43,313+0000 DEBUG [org.ejbca.core.protocol.scep.ScepResponseMessage] (default task-1) Signing SCEP message with cert: CN=TestCA
2022-12-03 09:09:43,314+0000 DEBUG [org.cesecore.certificates.util.AlgorithmTools] (default task-1) getSignAlgOidFromDigestAndKey: 1.2.840.113549.1.1.5
2022-12-03 09:09:43,333+0000 DEBUG [org.ejbca.ui.web.RequestHelper] (default task-1) Sent 3029 bytes to client
2022-12-03 09:09:43,333+0000 INFO  [org.ejbca.ui.web.protocol.ScepServlet] (default task-1) Sent a SCEP PKIOperation response to 172.16.2.1.

The only difference I see is getSignAlgOidFromDigestAndKey: 1.2.840.113549.1.1.11 to getSignAlgOidFromDigestAndKey: 1.2.840.113549.1.1.5

sbingner commented 1 year ago

I looked up the OIDs - it seems that the older version (working) used sha1-with-rsa-signature and the newer one (not working) uses sha256WithRSAEncryption

I believe those are really both signatures not encryption? (rsa signature encryption)

primetomas commented 1 year ago

That would be aweful if it does not support SHA256. Since the error says "failed to verify" it might be that.
Can you provide details about the Cisco hardware/software? Are there any updates?

Looking at the code, I don't see that part changing between the two versions though. There are a few things more to discover. You can enable trace logging, which will show even more details (warning it will be a lot of logging now, but only for EJBCA classes).

/subsystem=logging/logger=org.ejbca:write-attribute(name=level, value=TRACE) /subsystem=logging/logger=org.cesecore:write-attribute(name=level, value=TRACE)

If you capable of modifying source, it should be possible to force it to use SHA1 also in later EJBCA, byt modifying AlgorithmTools.java, method getSignAlgOidFromDigestAndKey around line 1076:

    // Default to SHA256WithRSA if everything else fails
    ASN1ObjectIdentifier oid = PKCSObjectIdentifiers.sha256WithRSAEncryption;

-> ASN1ObjectIdentifier oid = PKCSObjectIdentifiers.sha1WithRSAEncryption; and probable the line 1094 as well: oid = PKCSObjectIdentifiers.sha256WithRSAEncryption; -> oid = PKCSObjectIdentifiers.sha1WithRSAEncryption;

Only temporary as it may have unwanted consequences.

primetomas commented 1 year ago

Can you provide some information on the Cisco device you are testing against? Firmware version and so?

primetomas commented 1 year ago

Closing due to inctivity. If you have any new information @sbingner, please let us know.