certificate factory can load certs from file

This commit is contained in:
Andreas Steffen
2008-03-25 22:28:27 +00:00
parent ff98c85b57
commit 26930a8c3e
12 changed files with 481 additions and 261 deletions
@@ -1,55 +0,0 @@
/*
* Copyright (C) 2002 Ueli Galizzi, Ariane Seiler
* Copyright (C) 2003 Martin Berner, Lukas Suter
* Copyright (C) 2002-2008 Andreas Steffen
*
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* $Id: ac.h 3300 2007-10-12 21:53:18Z andreas $
*/
#include <library.h>
#include <debug.h>
#include <asn1/pem.h>
#include "ac.h"
/*
* Defined in header.
*/
ac_t* ac_create_from_file(char *path)
{
ac_t *ac;
bool pgp = FALSE;
chunk_t chunk;
if (!pem_asn1_load_file(path, NULL, &chunk, &pgp))
{
DBG1(" could not load attr cert file '%s'", path);
return NULL;
}
/* ac = (ac_t*)lib->creds->create(lib->creds,
CRED_CERTIFICATE, CERT_X509_AC,
BUILD_BLOB_ASN1_DER, chunk, BUILD_END);
*/
ac = NULL;
if (ac == NULL)
{
DBG1(" could not parse loaded attr cert file '%s'", path);
return NULL;
}
DBG1(" loaded attr cert file '%s'", path);
return ac;
}
@@ -54,10 +54,5 @@ 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,9 +16,6 @@
* $Id$
*/
#include <library.h>
#include <debug.h>
#include <asn1/pem.h>
#include "crl.h"
ENUM(crl_reason_names, CRL_UNSPECIFIED, CRL_REMOVE_FROM_CRL,
@@ -32,29 +29,3 @@ ENUM(crl_reason_names, CRL_UNSPECIFIED, CRL_REMOVE_FROM_CRL,
"reason #7",
"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,9 +85,4 @@ struct crl_t {
};
/**
* Load and parse an X.509 crl file
*/
crl_t* crl_create_from_file(char *path);
#endif /* CRL_H_ @}*/
@@ -15,10 +15,6 @@
* $Id$
*/
#include <library.h>
#include <debug.h>
#include <asn1/pem.h>
#include "x509.h"
ENUM(x509_flag_names, X509_CA, X509_SELF_SIGNED,
@@ -28,49 +24,3 @@ ENUM(x509_flag_names, X509_CA, X509_SELF_SIGNED,
"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,9 +104,4 @@ 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_ @}*/