16f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo/*
26f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved.
36f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo *
46f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo * Redistribution and use in source and binary forms, with or without
56f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo * modification, are permitted provided that the following conditions are met:
66f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo *
76f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo * Redistributions of source code must retain the above copyright notice, this
86f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo * list of conditions and the following disclaimer.
96f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo *
106f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo * Redistributions in binary form must reproduce the above copyright notice,
116f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo * this list of conditions and the following disclaimer in the documentation
126f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo * and/or other materials provided with the distribution.
136f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo *
146f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo * Neither the name of ARM nor the names of its contributors may be used
156f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo * to endorse or promote products derived from this software without specific
166f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo * prior written permission.
176f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo *
186f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
196f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
206f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
216f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
226f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
236f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
246f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
256f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
266f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
276f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
286f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo * POSSIBILITY OF SUCH DAMAGE.
296f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo */
306f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo
316f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo#ifndef CERT_H_
326f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo#define CERT_H_
336f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo
346f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo#include <openssl/ossl_typ.h>
356f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo#include <openssl/x509.h>
366f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo#include "key.h"
376f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo
386f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo/*
396f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo * This structure contains information related to the generation of the
406f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo * certificates. All these fields must be known and specified at build time
416f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo * except for the file name, which is picked up from the command line at
426f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo * run time.
436f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo *
446f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo * One instance of this structure must be created for each of the certificates
456f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo * present in the chain of trust.
466f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo *
476f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo * If the issuer points to this same instance, the generated certificate will
486f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo * be self-signed.
496f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo */
506f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillotypedef struct cert_s cert_t;
516f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillostruct cert_s {
526f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo	int id;			/* Unique identifier */
536f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo
546f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo	const char *fn;		/* Filename to save the certificate */
556f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo	const char *bin;	/* Image associated to this certificate */
566f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo
576f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo	const char *cn;		/* Subject CN (Company Name) */
586f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo
596f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo	X509 *x;		/* X509 certificate container */
606f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo	key_t *key;		/* Key to be signed */
616f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo
626f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo	cert_t *issuer;		/* Issuer certificate */
636f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo};
646f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo
656f97162237603eb6e5c497e5ba903512bdd428a9Juan Castilloint cert_add_ext(X509 *issuer, X509 *subject, int nid, char *value);
666f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo
676f97162237603eb6e5c497e5ba903512bdd428a9Juan Castilloint cert_new(cert_t *cert, int days, int ca, STACK_OF(X509_EXTENSION) * sk);
686f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo
696f97162237603eb6e5c497e5ba903512bdd428a9Juan Castillo#endif /* CERT_H_ */
70