16f971622SJuan Castillo /* 26f971622SJuan Castillo * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved. 36f971622SJuan Castillo * 4*82cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause 56f971622SJuan Castillo */ 66f971622SJuan Castillo 76f971622SJuan Castillo #ifndef CERT_H_ 86f971622SJuan Castillo #define CERT_H_ 96f971622SJuan Castillo 106f971622SJuan Castillo #include <openssl/ossl_typ.h> 116f971622SJuan Castillo #include <openssl/x509.h> 1255e291a4SJuan Castillo #include "ext.h" 136f971622SJuan Castillo #include "key.h" 146f971622SJuan Castillo 1555e291a4SJuan Castillo #define CERT_MAX_EXT 4 1655e291a4SJuan Castillo 176f971622SJuan Castillo /* 186f971622SJuan Castillo * This structure contains information related to the generation of the 196f971622SJuan Castillo * certificates. All these fields must be known and specified at build time 206f971622SJuan Castillo * except for the file name, which is picked up from the command line at 216f971622SJuan Castillo * run time. 226f971622SJuan Castillo * 236f971622SJuan Castillo * One instance of this structure must be created for each of the certificates 246f971622SJuan Castillo * present in the chain of trust. 256f971622SJuan Castillo * 266f971622SJuan Castillo * If the issuer points to this same instance, the generated certificate will 276f971622SJuan Castillo * be self-signed. 286f971622SJuan Castillo */ 296f971622SJuan Castillo typedef struct cert_s cert_t; 306f971622SJuan Castillo struct cert_s { 316f971622SJuan Castillo int id; /* Unique identifier */ 326f971622SJuan Castillo 33ad2c1a9aSJuan Castillo const char *opt; /* Command line option to pass filename */ 346f971622SJuan Castillo const char *fn; /* Filename to save the certificate */ 356f971622SJuan Castillo const char *cn; /* Subject CN (Company Name) */ 36159807e2SJuan Castillo const char *help_msg; /* Help message */ 376f971622SJuan Castillo 3855e291a4SJuan Castillo /* These fields must be defined statically */ 3955e291a4SJuan Castillo int key; /* Key to be signed */ 4055e291a4SJuan Castillo int issuer; /* Issuer certificate */ 4155e291a4SJuan Castillo int ext[CERT_MAX_EXT]; /* Certificate extensions */ 4255e291a4SJuan Castillo int num_ext; /* Number of extensions in the certificate */ 436f971622SJuan Castillo 4455e291a4SJuan Castillo X509 *x; /* X509 certificate container */ 456f971622SJuan Castillo }; 466f971622SJuan Castillo 4755e291a4SJuan Castillo /* Exported API */ 48ad2c1a9aSJuan Castillo int cert_init(void); 49ad2c1a9aSJuan Castillo cert_t *cert_get_by_opt(const char *opt); 506f971622SJuan Castillo int cert_add_ext(X509 *issuer, X509 *subject, int nid, char *value); 516f971622SJuan Castillo int cert_new(cert_t *cert, int days, int ca, STACK_OF(X509_EXTENSION) * sk); 526f971622SJuan Castillo 5355e291a4SJuan Castillo /* Macro to register the certificates used in the CoT */ 5455e291a4SJuan Castillo #define REGISTER_COT(_certs) \ 5555e291a4SJuan Castillo cert_t *certs = &_certs[0]; \ 56aa856917SSandrine Bailleux const unsigned int num_certs = sizeof(_certs)/sizeof(_certs[0]) 5755e291a4SJuan Castillo 5855e291a4SJuan Castillo /* Exported variables */ 5955e291a4SJuan Castillo extern cert_t *certs; 6055e291a4SJuan Castillo extern const unsigned int num_certs; 6155e291a4SJuan Castillo 626f971622SJuan Castillo #endif /* CERT_H_ */ 63