summaryrefslogtreecommitdiffstats
path: root/src/crypto
diff options
context:
space:
mode:
authorMichael Brown2016-08-25 16:38:58 +0200
committerMichael Brown2016-08-31 16:41:02 +0200
commit9a1a42f2830ac797070cb6f807869872d7e7c19a (patch)
tree1ddddac488c2fd20a17a0e7df895411f05769f19 /src/crypto
parent[crypto] Expose certstore_del() to explicitly remove stored certificates (diff)
downloadipxe-9a1a42f2830ac797070cb6f807869872d7e7c19a.tar.gz
ipxe-9a1a42f2830ac797070cb6f807869872d7e7c19a.tar.xz
ipxe-9a1a42f2830ac797070cb6f807869872d7e7c19a.zip
[crypto] Allow certificates to be marked as having been added explicitly
Allow certificates to be marked as having been added explicitly at run time. Such certificates will not be discarded via the certificate store cache discarder. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/crypto')
-rw-r--r--src/crypto/certstore.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/crypto/certstore.c b/src/crypto/certstore.c
index 9809413a..d0ef5c5d 100644
--- a/src/crypto/certstore.c
+++ b/src/crypto/certstore.c
@@ -152,6 +152,10 @@ void certstore_add ( struct x509_certificate *cert ) {
*/
void certstore_del ( struct x509_certificate *cert ) {
+ /* Ignore attempts to remove permanent certificates */
+ if ( cert->flags & X509_FL_PERMANENT )
+ return;
+
/* Remove certificate from store */
DBGC ( &certstore, "CERTSTORE removed certificate %s\n",
x509_name ( cert ) );
@@ -171,11 +175,22 @@ static unsigned int certstore_discard ( void ) {
* only reference is held by the store itself.
*/
list_for_each_entry_reverse ( cert, &certstore.links, store.list ) {
- if ( cert->refcnt.count == 0 ) {
- certstore_del ( cert );
- return 1;
- }
+
+ /* Skip certificates for which another reference is held */
+ if ( cert->refcnt.count > 0 )
+ continue;
+
+ /* Skip certificates that were added at build time or
+ * added explicitly at run time.
+ */
+ if ( cert->flags & ( X509_FL_PERMANENT | X509_FL_EXPLICIT ) )
+ continue;
+
+ /* Discard certificate */
+ certstore_del ( cert );
+ return 1;
}
+
return 0;
}