Discussion:
[openssl-dev] Clear X509 OBJECT cache
(too old to reply)
Patel, Anirudh (Anirudh)
2016-07-20 07:27:47 UTC
Permalink
Hi,

This is related to the X509 store cache (had a similar ticket openssl.org #4615 which I guess has already become stale). But, I believe that the documentation regarding X509_LOOKUP_hash_dir is not at all clear and is quite misleading:
From the manual page: X509_LOOKUP_hash_dir<https://www.openssl.org/docs/manmaster/crypto/X509_LOOKUP_file.html>
"X509_LOOKUP_hash_dir is a more advanced method, which loads certificates and CRLs on demand, and caches them in memory once they are loaded. As of OpenSSL 1.0.0, it also checks for newer CRLs upon each lookup, so that newer CRLs are as soon as they appear in the directory. When checking for new CRLs once one CRL for given hash value is loaded, hash_dir lookup method checks only for certificates with sequence number greater than that of the already cached CRL" - This certainly not happens. It should have stated that only unique file names will be loaded for once from the disk and the new ones for the same issuer will not be looked up even if you change the sequence number. This is a big problem and a difficult one to address, once for a unique issuer name a CRL file is loaded from the disk and stored in the cache, no matter if you replace the old CRL file with a new one, keeping the naming convention to whatever $hash.r0 or$hash.r1 this is never going to be looked up and loaded in the cache since the issuer name is already present in the cache. I guess this should be fixed.

Quoting one of the explanations that I got from you guys:
"The point is that they are loaded when a new file appears, meaning, a file with a name not yet present. Once that file is loaded, it's not been loaded from disk again (as implied by the 'caches'), also not when it changes"

Just to solve my problem:
Is there any way to clear the store cache every time before openssl kicks off with the validation process (invoke X509_verify_cert and the results verify_callback). I would want to clear the cache so that during every (current) lookup at the time of handshake - CRL files present on the disk are referenced and are loaded in the cache (since we cleared it earlier, thus the file name will be unique/new)? Is there any API which clears the cache?
Dr. Stephen Henson
2016-07-20 14:07:37 UTC
Permalink
Post by Patel, Anirudh (Anirudh)
"X509_LOOKUP_hash_dir is a more advanced method, which loads certificates
and CRLs on demand, and caches them in memory once they are loaded. As of
OpenSSL 1.0.0, it also checks for newer CRLs upon each lookup, so that newer
CRLs are as soon as they appear in the directory. When checking for new CRLs
once one CRL for given hash value is loaded, hash_dir lookup method checks
only for certificates with sequence number greater than that of the already
cached CRL" - This certainly not happens. It should have stated that only
unique file names will be loaded for once from the disk and the new ones for
the same issuer will not be looked up even if you change the sequence
number.
They should be looked up: if they aren't this is a bug.

The problem is that unless the current time exceeds the nextUpdate field of
the new CRL it wont be used: it will use the first one where the current time
is between lastUpdate and nextUpdate.

When you added a new CRL was it just "newer" (i.e. thisUpdate later than the
current one) or had the current time exceeded nextUpdate? If the latter and
the new CRL wasn't used that's a bug which should be fixed.

Steve.
--
Dr Stephen N. Henson. OpenSSL project core developer.
Commercial tech support now available see: http://www.openssl.org
--
openssl-dev mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-dev
Dr. Stephen Henson
2016-07-20 14:09:14 UTC
Permalink
Post by Dr. Stephen Henson
Post by Patel, Anirudh (Anirudh)
"X509_LOOKUP_hash_dir is a more advanced method, which loads certificates
and CRLs on demand, and caches them in memory once they are loaded. As of
OpenSSL 1.0.0, it also checks for newer CRLs upon each lookup, so that newer
CRLs are as soon as they appear in the directory. When checking for new CRLs
once one CRL for given hash value is loaded, hash_dir lookup method checks
only for certificates with sequence number greater than that of the already
cached CRL" - This certainly not happens. It should have stated that only
unique file names will be loaded for once from the disk and the new ones for
the same issuer will not be looked up even if you change the sequence
number.
They should be looked up: if they aren't this is a bug.
The problem is that unless the current time exceeds the nextUpdate field of
the new CRL it wont be used: it will use the first one where the current time
is between lastUpdate and nextUpdate.
When you added a new CRL was it just "newer" (i.e. thisUpdate later than the
the new CRL wasn't used that's a bug which should be fixed.
Argh... I mean "lastUpdate" not "lastUpdate".

Steve.
--
Dr Stephen N. Henson. OpenSSL project core developer.
Commercial tech support now available see: http://www.openssl.org
--
openssl-dev mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-dev
Dr. Stephen Henson
2016-07-20 14:11:53 UTC
Permalink
Post by Dr. Stephen Henson
Post by Dr. Stephen Henson
Post by Patel, Anirudh (Anirudh)
"X509_LOOKUP_hash_dir is a more advanced method, which loads certificates
and CRLs on demand, and caches them in memory once they are loaded. As of
OpenSSL 1.0.0, it also checks for newer CRLs upon each lookup, so that newer
CRLs are as soon as they appear in the directory. When checking for new CRLs
once one CRL for given hash value is loaded, hash_dir lookup method checks
only for certificates with sequence number greater than that of the already
cached CRL" - This certainly not happens. It should have stated that only
unique file names will be loaded for once from the disk and the new ones for
the same issuer will not be looked up even if you change the sequence
number.
They should be looked up: if they aren't this is a bug.
The problem is that unless the current time exceeds the nextUpdate field of
the new CRL it wont be used: it will use the first one where the current time
is between lastUpdate and nextUpdate.
When you added a new CRL was it just "newer" (i.e. thisUpdate later than the
the new CRL wasn't used that's a bug which should be fixed.
Argh... I mean "lastUpdate" not "lastUpdate".
Oops.. ;-)

Err... I'll try that again. I meant "lastUpdate" not "thisUpdate".

Steve.
--
Dr Stephen N. Henson. OpenSSL project core developer.
Commercial tech support now available see: http://www.openssl.org
--
openssl-dev mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-dev
Patel, Anirudh (Anirudh)
2016-07-20 18:04:12 UTC
Permalink
Thanks a lot for explaining this so clearly.

OLD CRL (present in cache): Last Update: Jul 18 11:42:52 2016 GMT
Next Update: Aug 17 11:42:52 2016 GMT
X509v3 CRL Number: 20480
When you added a new CRL was it just "newer" (i.e. lastUpdate later than the current one)
Yes.
NEW CRL on disk: Last Update: Jul 18 12:24:39 2016 GMT
Next Update: Aug 17 12:24:39 2016 GMT
X509v3 CRL Number: 20481

Got an incoming connection when the current time is still between OLD CRL's (lastUpdate and nextUpdate) i.e current time has not exceeded OLD CRL's nextUpdate and thus the newer CRL file is never looked up(ignored).

You rightly said that we should have taken CRL Number into consideration during lookups.

So, now can you tell me how to go about it. I cannot restart my server to load the CRL files again. Is it possible for me to clear the cache before validation kicks off for every incoming connection? If yes, please tell me the API which can do this.

Thanks,
Anirudh

-----Original Message-----
From: openssl-dev [mailto:openssl-dev-***@openssl.org] On Behalf Of Dr. Stephen Henson
Sent: Wednesday, July 20, 2016 7:42 PM
To: openssl-***@openssl.org
Subject: Re: [openssl-dev] Clear X509 OBJECT cache
Post by Dr. Stephen Henson
Post by Patel, Anirudh (Anirudh)
"X509_LOOKUP_hash_dir is a more advanced method, which loads
certificates and CRLs on demand, and caches them in memory once
they are loaded. As of OpenSSL 1.0.0, it also checks for newer
CRLs upon each lookup, so that newer CRLs are as soon as they
appear in the directory. When checking for new CRLs once one CRL
for given hash value is loaded, hash_dir lookup method checks only
for certificates with sequence number greater than that of the
already cached CRL" - This certainly not happens. It should have
stated that only unique file names will be loaded for once from
the disk and the new ones for the same issuer will not be looked up even if you change the sequence number.
They should be looked up: if they aren't this is a bug.
The problem is that unless the current time exceeds the nextUpdate
field of the new CRL it wont be used: it will use the first one
where the current time is between lastUpdate and nextUpdate.
When you added a new CRL was it just "newer" (i.e. thisUpdate later
than the the new CRL wasn't used that's a bug which should be fixed.
Argh... I mean "lastUpdate" not "lastUpdate".
Oops.. ;-)

Err... I'll try that again. I meant "lastUpdate" not "thisUpdate".

Steve.
--
Dr Stephen N. Henson. OpenSSL project core developer.
Commercial tech support now available see: https://urldefense.proofpoint.com/v2/url?u=http-3A__www.openssl.org&d=CwICAg&c=BFpWQw8bsuKpl1SgiZH64Q&r=r_yFHjnA3pyorIMQVU-vjyndTmY6-rsuMCBf8EzS6oU&m=PFSfcnSGg1bGMDtJ40-ga01mSVP5ue8Pkfes0hfaw-E&s=_B-3I5EwxUCu1umKQkjmPAo0rDCElpGg0akAD6ecDcU&e=
--
openssl-dev mailing list
To unsubscribe: https://urldefense.proofpoint.com/v2/url?u=https-3A__mta.openssl.org_mailman_listinfo_openssl-2Ddev&d=CwICAg&c=BFpWQw8bsuKpl1SgiZH64Q&r=r_yFHjnA3pyorIMQVU-vjyndTmY6-rsuMCBf8EzS6oU&m=PFSfcnSGg1bGMDtJ40-ga01mSVP5ue8Pkfes0hfaw-E&s=e09sSwcDm-McZPDbgwFI6MlsKM9oiwB0pgLEhvlKvg4&e=
--
openssl-dev mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-dev
Loading...