Browse Source

[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>
tags/v1.20.1
Michael Brown 8 years ago
parent
commit
9a1a42f283
2 changed files with 23 additions and 4 deletions
  1. 19
    4
      src/crypto/certstore.c
  2. 4
    0
      src/include/ipxe/x509.h

+ 19
- 4
src/crypto/certstore.c View File

152
  */
152
  */
153
 void certstore_del ( struct x509_certificate *cert ) {
153
 void certstore_del ( struct x509_certificate *cert ) {
154
 
154
 
155
+	/* Ignore attempts to remove permanent certificates */
156
+	if ( cert->flags & X509_FL_PERMANENT )
157
+		return;
158
+
155
 	/* Remove certificate from store */
159
 	/* Remove certificate from store */
156
 	DBGC ( &certstore, "CERTSTORE removed certificate %s\n",
160
 	DBGC ( &certstore, "CERTSTORE removed certificate %s\n",
157
 	       x509_name ( cert ) );
161
 	       x509_name ( cert ) );
171
 	 * only reference is held by the store itself.
175
 	 * only reference is held by the store itself.
172
 	 */
176
 	 */
173
 	list_for_each_entry_reverse ( cert, &certstore.links, store.list ) {
177
 	list_for_each_entry_reverse ( cert, &certstore.links, store.list ) {
174
-		if ( cert->refcnt.count == 0 ) {
175
-			certstore_del ( cert );
176
-			return 1;
177
-		}
178
+
179
+		/* Skip certificates for which another reference is held */
180
+		if ( cert->refcnt.count > 0 )
181
+			continue;
182
+
183
+		/* Skip certificates that were added at build time or
184
+		 * added explicitly at run time.
185
+		 */
186
+		if ( cert->flags & ( X509_FL_PERMANENT | X509_FL_EXPLICIT ) )
187
+			continue;
188
+
189
+		/* Discard certificate */
190
+		certstore_del ( cert );
191
+		return 1;
178
 	}
192
 	}
193
+
179
 	return 0;
194
 	return 0;
180
 }
195
 }
181
 
196
 

+ 4
- 0
src/include/ipxe/x509.h View File

220
 enum x509_flags {
220
 enum x509_flags {
221
 	/** Certificate has been validated */
221
 	/** Certificate has been validated */
222
 	X509_FL_VALIDATED = 0x0001,
222
 	X509_FL_VALIDATED = 0x0001,
223
+	/** Certificate was added at build time */
224
+	X509_FL_PERMANENT = 0x0002,
225
+	/** Certificate was added explicitly at run time */
226
+	X509_FL_EXPLICIT = 0x0004,
223
 };
227
 };
224
 
228
 
225
 /**
229
 /**

Loading…
Cancel
Save