Simple interface for Mbed Cloud Client

Dependents:  

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers kcm_internal.h Source File

kcm_internal.h

00001 // ----------------------------------------------------------------------------
00002 // Copyright 2016-2017 ARM Ltd.
00003 //
00004 // Licensed under the Apache License, Version 2.0 (the "License");
00005 // you may not use this file except in compliance with the License.
00006 // You may obtain a copy of the License at
00007 //
00008 //     http://www.apache.org/licenses/LICENSE-2.0
00009 //
00010 // Unless required by applicable law or agreed to in writing, software
00011 // distributed under the License is distributed on an "AS IS" BASIS,
00012 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013 // See the License for the specific language governing permissions and
00014 // limitations under the License.
00015 // ----------------------------------------------------------------------------
00016 
00017 #ifndef KEYS_CONFIG_MANAGER_INTERNAL_H
00018 #define KEYS_CONFIG_MANAGER_INTERNAL_H
00019 
00020 #include <stdlib.h>
00021 #include <stdbool.h>
00022 #include <inttypes.h>
00023 #include "esfs.h"
00024 
00025 #ifdef __cplusplus
00026 extern "C" {
00027 #endif
00028 
00029 /* === Definitions and Prototypes === */
00030 
00031 /* === Defines === */
00032 #define FCC_ENTROPY_SIZE                   48
00033 #define FCC_ROT_SIZE                       16
00034 #define FCC_CA_IDENTIFICATION_SIZE         33 //PAL_CERT_ID_SIZE
00035 
00036 
00037 /**
00038 * KCM file prefixes defines
00039 */
00040 #define KCM_FILE_PREFIX_PRIVATE_KEY       "PrvKey_"
00041 #define KCM_FILE_PREFIX_PUBLIC_KEY        "PubKey_"
00042 #define KCM_FILE_PREFIX_SYMMETRIC_KEY     "SymKey_"
00043 #define KCM_FILE_PREFIX_CERTIFICATE       "Cert_"
00044 #define KCM_FILE_PREFIX_CONFIG_PARAM      "CfgParam_"
00045 #define KCM_FILE_PREFIX_CERT_CHAIN_0      KCM_FILE_PREFIX_CERTIFICATE
00046 #define KCM_FILE_PREFIX_CERT_CHAIN_X      "Crt1_" // must be same length as KCM_FILE_PREFIX_CERT_CHAIN_0
00047 #define KCM_FILE_PREFIX_CERT_CHAIN_X_OFFSET 3
00048 
00049 #define KCM_FILE_PREFIX_MAX_SIZE 12
00050 
00051     typedef enum {
00052         /* KCM_LOCAL_ACL_MD_TYPE,
00053            KCM_REMOTE_ACL_MD_TYPE,
00054            KCM_AUDIT_MD_TYPE,
00055            KCM_NAME_MD_TYPE,
00056            KCM_USAGE_MD_TYPE,*/
00057         KCM_CERT_CHAIN_LEN_MD_TYPE,
00058         KCM_MD_TYPE_MAX_SIZE // can't be bigger than ESFS_MAX_TYPE_LENGTH_VALUES
00059     } kcm_meta_data_type_e;
00060 
00061 #if ESFS_MAX_TYPE_LENGTH_VALUES < KCM_MD_TYPE_MAX_SIZE
00062 #error "KCM_MD_TYPE_MAX_SIZE can't be greater than ESFS_MAX_TYPE_LENGTH_VALUES"
00063 #endif
00064 
00065     typedef struct kcm_meta_data_ {
00066         kcm_meta_data_type_e type;
00067         size_t data_size;
00068         uint8_t *data;
00069     } kcm_meta_data_s;
00070 
00071     typedef struct kcm_meta_data_list_ {
00072         // allocate a single meta data for each type
00073         kcm_meta_data_s meta_data[KCM_MD_TYPE_MAX_SIZE];
00074         size_t meta_data_count;
00075     } kcm_meta_data_list_s;
00076 
00077     typedef struct kcm_ctx_ {
00078         esfs_file_t esfs_file_h;
00079         size_t file_size;
00080         bool is_file_size_checked;
00081     } kcm_ctx_s;
00082 
00083     typedef enum {
00084         KCM_CHAIN_OP_TYPE_CREATE = 1,
00085         KCM_CHAIN_OP_TYPE_OPEN,
00086         KCM_CHAIN_OP_TYPE_MAX
00087     } kcm_chain_operation_type_e;
00088 
00089     /** The chain context used internally only and should not be changed by user.
00090     */
00091     typedef struct kcm_cert_chain_context_int_ {
00092         uint8_t *chain_name;                      //!< The name of certificate chain.
00093         size_t  chain_name_len;                   //!< The size of certificate chain name.
00094         size_t num_of_certificates_in_chain;      //!< The number of certificate in the chain.
00095         kcm_ctx_s current_kcm_ctx;                //!< Current KCM operation context.
00096         uint32_t current_cert_index;              //!< Current certificate iterator.
00097         kcm_chain_operation_type_e operation_type;//!< Type of Current operation.
00098         bool chain_is_factory;                    //!< Is chain is a factory item, otherwise false.
00099     } kcm_cert_chain_context_int_s;
00100 
00101 #ifdef __cplusplus
00102 }
00103 #endif
00104 
00105 #endif //KEYS_CONFIG_MANAGER_INTERNAL_H
00106