defined *_create_from_file() constructors in libstrongswan/credentials/certificates

This commit is contained in:
Andreas Steffen
2008-03-25 10:12:45 +00:00
parent 63cb8a7fee
commit 3e6ee16478
7 changed files with 158 additions and 107 deletions
@@ -1,7 +1,7 @@
/*
* Copyright (C) 2002 Ueli Galizzi, Ariane Seiler
* Copyright (C) 2003 Martin Berner, Lukas Suter
* Copyright (C) 2007 Andreas Steffen
* Copyright (C) 2002-2008 Andreas Steffen
*
* Hochschule fuer Technik Rapperswil
*
@@ -15,7 +15,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* RCSID $Id: ac.h 3300 2007-10-12 21:53:18Z andreas $
* $Id: ac.h 3300 2007-10-12 21:53:18Z andreas $
*/
/**
@@ -54,5 +54,10 @@ struct ac_t {
bool (*equals_holder) (const ac_t *this, const ac_t *other);
};
/**
* Load and parse an X.509 attribute certificate file
*/
ac_t* ac_create_from_file(char *path);
#endif /* AC_H_ @}*/
@@ -16,6 +16,9 @@
* $Id$
*/
#include <library.h>
#include <debug.h>
#include <asn1/pem.h>
#include "crl.h"
ENUM(crl_reason_names, CRL_UNSPECIFIED, CRL_REMOVE_FROM_CRL,
@@ -30,3 +33,28 @@ ENUM(crl_reason_names, CRL_UNSPECIFIED, CRL_REMOVE_FROM_CRL,
"remove from crl",
);
/*
* Defined in header.
*/
crl_t* crl_create_from_file(char *path)
{
crl_t *crl;
bool pgp = FALSE;
chunk_t chunk;
if (!pem_asn1_load_file(path, NULL, &chunk, &pgp))
{
DBG1(" could not load crl file '%s'", path);
return NULL;
}
crl = (crl_t*)lib->creds->create(lib->creds,
CRED_CERTIFICATE, CERT_X509_CRL,
BUILD_BLOB_ASN1_DER, chunk, BUILD_END);
if (crl == NULL)
{
DBG1(" could not parse loaded crl file '%s'", path);
return NULL;
}
DBG1(" loaded crl file '%s'", path);
return crl;
}
@@ -85,4 +85,9 @@ struct crl_t {
};
/**
* Load and parse an X.509 crl file
*/
crl_t* crl_create_from_file(char *path);
#endif /* CRL_H_ @}*/
@@ -15,6 +15,10 @@
* $Id$
*/
#include <library.h>
#include <debug.h>
#include <asn1/pem.h>
#include "x509.h"
ENUM(x509_flag_names, X509_CA, X509_SELF_SIGNED,
@@ -23,3 +27,50 @@ ENUM(x509_flag_names, X509_CA, X509_SELF_SIGNED,
"X509_OCSP_SIGNER",
"X509_SELF_SIGNED",
);
/*
* Defined in header.
*/
x509_t* x509_create_from_file(char *path, char *label, x509_flag_t flag)
{
bool pgp = FALSE;
chunk_t chunk;
x509_t *x509;
certificate_t *cert;
time_t notBefore, notAfter, now;
if (!pem_asn1_load_file(path, NULL, &chunk, &pgp))
{
DBG1(" could not load %s file '%s'", label, path);
return NULL;
}
x509 = (x509_t*)lib->creds->create(lib->creds,
CRED_CERTIFICATE, CERT_X509,
BUILD_BLOB_ASN1_DER, chunk,
BUILD_X509_FLAG, flag,
BUILD_END);
if (x509 == NULL)
{
DBG1(" could not parse loaded %s file '%s'",label, path);
return NULL;
}
DBG1(" loaded %s file '%s'", label, path);
/* check validity */
cert = &x509->interface;
now = time(NULL);
cert->get_validity(cert, &now, &notBefore, &notAfter);
if (now > notAfter)
{
DBG1(" certificate expired at %T, discarded", &notAfter);
cert->destroy(cert);
return NULL;
}
if (now < notBefore)
{
DBG1(" certificate not valid before %T", &notBefore);
}
return x509;
}
@@ -104,4 +104,9 @@ struct x509_t {
enumerator_t* (*create_ocsp_uri_enumerator)(x509_t *this);
};
/**
* Load and parse an X.509 certificate file
*/
x509_t* x509_create_from_file(char *path, char *label, x509_flag_t flag);
#endif /* X509_H_ @}*/