Added generic implementations for crl_is_newer/certificate_is_newer
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "certificate.h"
|
||||
|
||||
#include <debug.h>
|
||||
#include <credentials/certificates/x509.h>
|
||||
|
||||
ENUM(certificate_type_names, CERT_ANY, CERT_PLUTO_CRL,
|
||||
@@ -40,3 +41,24 @@ ENUM(cert_validation_names, VALIDATION_GOOD, VALIDATION_REVOKED,
|
||||
"REVOKED",
|
||||
);
|
||||
|
||||
/**
|
||||
* See header
|
||||
*/
|
||||
bool certificate_is_newer(certificate_t *this, certificate_t *other)
|
||||
{
|
||||
time_t this_update, that_update;
|
||||
char *type = "certificate";
|
||||
bool newer;
|
||||
|
||||
if (this->get_type(this) == CERT_X509_CRL)
|
||||
{
|
||||
type = "crl";
|
||||
}
|
||||
this->get_validity(this, NULL, &this_update, NULL);
|
||||
other->get_validity(other, NULL, &that_update, NULL);
|
||||
newer = this_update > that_update;
|
||||
DBG1(DBG_LIB, " %s from %T is %s - existing %s from %T %s",
|
||||
type, &this_update, FALSE, newer ? "newer" : "not newer",
|
||||
type, &that_update, FALSE, newer ? "replaced" : "retained");
|
||||
return newer;
|
||||
}
|
||||
|
||||
@@ -197,4 +197,13 @@ struct certificate_t {
|
||||
void (*destroy)(certificate_t *this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Generic check if a given certificate is newer than another.
|
||||
*
|
||||
* @param this first certificate to check
|
||||
* @param other second certificate
|
||||
* @return TRUE if this newer than other
|
||||
*/
|
||||
bool certificate_is_newer(certificate_t *this, certificate_t *other);
|
||||
|
||||
#endif /** CERTIFICATE_H_ @}*/
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
#include "crl.h"
|
||||
|
||||
#include <debug.h>
|
||||
|
||||
ENUM(crl_reason_names, CRL_REASON_UNSPECIFIED, CRL_REASON_REMOVE_FROM_CRL,
|
||||
"unspecified",
|
||||
"key compromise",
|
||||
@@ -27,3 +29,29 @@ ENUM(crl_reason_names, CRL_REASON_UNSPECIFIED, CRL_REASON_REMOVE_FROM_CRL,
|
||||
"reason #7",
|
||||
"remove from crl",
|
||||
);
|
||||
|
||||
/**
|
||||
* Check if this CRL is newer
|
||||
*/
|
||||
bool crl_is_newer(crl_t *this, crl_t *other)
|
||||
{
|
||||
chunk_t this_num, other_num;
|
||||
bool newer;
|
||||
|
||||
this_num = this->get_serial(this);
|
||||
other_num = other->get_serial(other);
|
||||
|
||||
/* compare crlNumbers if available - otherwise use generic cert compare */
|
||||
if (this_num.ptr != NULL && other_num.ptr != NULL)
|
||||
{
|
||||
newer = chunk_compare(this_num, other_num) > 0;
|
||||
DBG1(DBG_LIB, " crl #%#B is %s - existing crl #%#B %s",
|
||||
&this_num, newer ? "newer" : "not newer",
|
||||
&other_num, newer ? "replaced" : "retained");
|
||||
}
|
||||
else
|
||||
{
|
||||
newer = certificate_is_newer(&this->certificate, &other->certificate);
|
||||
}
|
||||
return newer;
|
||||
}
|
||||
|
||||
@@ -80,7 +80,15 @@ struct crl_t {
|
||||
* @return enumerator over revoked certificates.
|
||||
*/
|
||||
enumerator_t* (*create_enumerator)(crl_t *this);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Generic check if a given CRL is newer than another.
|
||||
*
|
||||
* @param this first CRL to check
|
||||
* @param other second CRL
|
||||
* @return TRUE if this newer than other
|
||||
*/
|
||||
bool crl_is_newer(crl_t *this, crl_t *other);
|
||||
|
||||
#endif /** CRL_H_ @}*/
|
||||
|
||||
Reference in New Issue
Block a user