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.
Fork of mbed-cloud-workshop-connect-HTS221 by
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 ARM_UC_USE_KCM 00023 extern const struct arm_uc_certificate_api arm_uc_certificate_kcm_api; 00024 static const struct arm_uc_certificate_api* arm_uc_registered_certificate_api = 00025 &arm_uc_certificate_kcm_api; 00026 #elif ARM_UC_USE_CFSTORE 00027 extern const struct arm_uc_certificate_api arm_uc_certificate_cfstore_api; 00028 static const struct arm_uc_certificate_api* arm_uc_registered_certificate_api = 00029 &arm_uc_certificate_cfstore_api; 00030 #else 00031 #error No configuration store set 00032 #endif 00033 00034 /** 00035 * @brief Add certificate. 00036 * @details [long description] 00037 * 00038 * @param certificate Pointer to certiface being added. 00039 * @param certificate_size Certificate length. 00040 * @param fingerprint Pointer to the fingerprint of the certificate being added. 00041 * @param fingerprint_size Fingerprint length. 00042 * @return Error code. 00043 */ 00044 arm_uc_error_t ARM_UC_Certificate_Add(const uint8_t* certificate, 00045 uint16_t certificate_size, 00046 const uint8_t* fingerprint, 00047 uint16_t fingerprint_size, 00048 void (*callback)(arm_uc_error_t, const arm_uc_buffer_t*)) 00049 { 00050 //cert Name: base64(fingerprint) 00051 const arm_uc_buffer_t fingerprintBuffer = { 00052 .size = fingerprint_size, 00053 .size_max = fingerprint_size, 00054 .ptr = (uint8_t *)fingerprint /* Const Cast safe because target is in a const struct */ 00055 }; 00056 00057 const arm_uc_buffer_t certBuffer = { 00058 .size = certificate_size, 00059 .size_max = certificate_size, 00060 .ptr = (uint8_t *)certificate /* Const Cast safe because target is in a const struct */ 00061 }; 00062 00063 const struct arm_uc_certificate_api* api = arm_uc_registered_certificate_api; 00064 00065 if (api == NULL || api->store == NULL) 00066 { 00067 return (arm_uc_error_t){ ARM_UC_CM_ERR_INVALID_PARAMETER}; 00068 } 00069 00070 arm_uc_error_t err = api->store(&certBuffer, &fingerprintBuffer, callback); 00071 00072 if (err.error != 0) 00073 { 00074 return err; 00075 } 00076 00077 return (arm_uc_error_t){ARM_UC_CM_ERR_NONE}; 00078 } 00079 00080 arm_uc_error_t ARM_UC_certificateFetch(arm_uc_buffer_t* certificate, 00081 const arm_uc_buffer_t* fingerprint, 00082 const arm_uc_buffer_t* DERCertificateList, 00083 void (*callback)(arm_uc_error_t, const arm_uc_buffer_t*, const arm_uc_buffer_t*)) 00084 { 00085 if (arm_uc_registered_certificate_api == NULL || 00086 arm_uc_registered_certificate_api->fetch == NULL) 00087 { 00088 return (arm_uc_error_t){ARM_UC_CM_ERR_INVALID_PARAMETER}; 00089 } 00090 00091 return arm_uc_registered_certificate_api->fetch(certificate, fingerprint, DERCertificateList, callback); 00092 }
Generated on Tue Jul 12 2022 19:12:11 by
1.7.2
