Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FXAS21002 FXOS8700Q
arm_uc_certificate.c
00001 // ---------------------------------------------------------------------------- 00002 // Copyright 2016-2017 ARM Ltd. 00003 // 00004 // SPDX-License-Identifier: Apache-2.0 00005 // 00006 // Licensed under the Apache License, Version 2.0 (the "License"); 00007 // you may not use this file except in compliance with the License. 00008 // You may obtain a copy of the License at 00009 // 00010 // http://www.apache.org/licenses/LICENSE-2.0 00011 // 00012 // Unless required by applicable law or agreed to in writing, software 00013 // distributed under the License is distributed on an "AS IS" BASIS, 00014 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 // See the License for the specific language governing permissions and 00016 // limitations under the License. 00017 // ---------------------------------------------------------------------------- 00018 00019 #include "update-client-control-center/arm_uc_certificate.h" 00020 #include "update-client-common/arm_uc_config.h" 00021 00022 #if defined(ARM_UC_FEATURE_MANIFEST_PUBKEY) && (ARM_UC_FEATURE_MANIFEST_PUBKEY == 1) 00023 00024 #if defined(ARM_UC_FEATURE_CERT_STORE_KCM) && (ARM_UC_FEATURE_CERT_STORE_KCM==1) 00025 00026 extern const struct arm_uc_certificate_api arm_uc_certificate_kcm_api; 00027 static const struct arm_uc_certificate_api *arm_uc_registered_certificate_api = 00028 &arm_uc_certificate_kcm_api; 00029 00030 #elif defined(ARM_UC_FEATURE_CERT_STORE_RAW) && (ARM_UC_FEATURE_CERT_STORE_RAW==1) 00031 00032 extern const struct arm_uc_certificate_api arm_uc_certificate_raw_api; 00033 static const struct arm_uc_certificate_api *arm_uc_registered_certificate_api = 00034 &arm_uc_certificate_raw_api; 00035 00036 #else 00037 00038 #error No configuration store set 00039 00040 #endif /* ARM_UC_FEATURE_CERT_STORE_KCM/RAW */ 00041 00042 /** 00043 * @brief Add certificate. 00044 * @details [long description] 00045 * 00046 * @param certificate Pointer to certiface being added. 00047 * @param certificate_size Certificate length. 00048 * @param fingerprint Pointer to the fingerprint of the certificate being added. 00049 * @param fingerprint_size Fingerprint length. 00050 * @return Error code. 00051 */ 00052 arm_uc_error_t ARM_UC_Certificate_Add(const uint8_t *certificate, 00053 uint16_t certificate_size, 00054 const uint8_t *fingerprint, 00055 uint16_t fingerprint_size, 00056 void (*callback)(arm_uc_error_t, const arm_uc_buffer_t *)) 00057 { 00058 //cert Name: base64(fingerprint) 00059 const arm_uc_buffer_t fingerprintBuffer = { 00060 .size = fingerprint_size, 00061 .size_max = fingerprint_size, 00062 .ptr = (uint8_t *)fingerprint /* Const Cast safe because target is in a const struct */ 00063 }; 00064 00065 const arm_uc_buffer_t certBuffer = { 00066 .size = certificate_size, 00067 .size_max = certificate_size, 00068 .ptr = (uint8_t *)certificate /* Const Cast safe because target is in a const struct */ 00069 }; 00070 00071 const struct arm_uc_certificate_api *api = arm_uc_registered_certificate_api; 00072 00073 if (api == NULL || api->store == NULL) { 00074 return (arm_uc_error_t) { ARM_UC_CM_ERR_INVALID_PARAMETER}; 00075 } 00076 00077 arm_uc_error_t err = api->store(&certBuffer, &fingerprintBuffer, callback); 00078 00079 if (err.error != 0) { 00080 return err; 00081 } 00082 00083 return (arm_uc_error_t) {ERR_NONE}; 00084 } 00085 00086 arm_uc_error_t ARM_UC_certificateFetch(arm_uc_buffer_t *certificate, 00087 const arm_uc_buffer_t *fingerprint, 00088 const arm_uc_buffer_t *DERCertificateList, 00089 void (*callback)(arm_uc_error_t, const arm_uc_buffer_t *, const arm_uc_buffer_t *)) 00090 { 00091 if (arm_uc_registered_certificate_api == NULL || 00092 arm_uc_registered_certificate_api->fetch == NULL) { 00093 return (arm_uc_error_t) {ARM_UC_CM_ERR_INVALID_PARAMETER}; 00094 } 00095 00096 return arm_uc_registered_certificate_api->fetch(certificate, fingerprint, DERCertificateList, callback); 00097 } 00098 00099 #endif /* ARM_UC_FEATURE_MANIFEST_PUBKEY */
Generated on Tue Jul 12 2022 20:20:56 by
