
/*
 * =====================================================================================
 *
 *       Filename:  hdm_x509.h
 *
 *    Description:  HDM definitions for x509 certificates manipulation
 *
 *        Version:  1.0
 *        Created:  09/16/2019 15:26:11 PM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *        Company:  Samsung Electronics
 *        Copyright (c) 2015 by Samsung Electronics, All rights reserved.
 *
 * =====================================================================================
 */

#ifndef _HDM_x509_H_
#define _HDM_x509_H_

/**
 * HDM includes
 */
#include "tz_hdm_interface.h"
#include "hdm_defs.h"
#include "hdm_drk.h"
#include "base64.h"
#include "hdm_utils.h"
#include "hdm_core.h"

/**
 * External includes
 */
#include <openssl/base.h>
#include <openssl/x509.h>
#include <openssl/x509v3.h>
#include <openssl/bio.h>
#include <openssl/pem.h>
#include <openssl/x509_vfy.h>
#include <openssl/safestack.h>

/**
 * @brief
 * verify_cert_chain
 * Validates x509 certificates chain
 *
 * @param[in] certificates[]     - certificates chain
 * @param[in] certificates_count - number of certificates
 * @param[in] key                - envelopped key
 *
 * @return HDM status code
 */
hdm_return_code_t verify_cert_chain(tz_hdm_header_x5c_t certificates[], uint32_t certificates_count, EVP_PKEY **pkey);

/**
 * @brief
 * convert_der_to_b64
 * Convert der certificates to PEM.
 * 
 * @param[in]     cert_chain  - array of certificates to be converted
 * @param[in]     num_certs   - the number of certificates in the array
 *
 * @return Status Code
*/
hdm_return_code_t convert_der_to_b64(drk_cert_chain_t *cert_chain, uint32_t num_certs);

#endif /* _HDM_x509_H_ */
