Simple interface for Mbed Cloud Client
Embed:
(wiki syntax)
Show/hide line numbers
CertificateParser.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 <stdint.h> 00020 #include "pal.h" 00021 #include "mbed-trace/mbed_trace.h" 00022 00023 #define TRACE_GROUP "mClt" 00024 00025 bool extract_cn_from_certificate(const uint8_t* cer, size_t cer_len, char* common_name) 00026 { 00027 tr_debug("extract_cn_from_certificate"); 00028 palX509Handle_t cert; 00029 size_t len; 00030 palStatus_t ret; 00031 00032 ret = pal_x509Initiate(&cert); 00033 if (ret != PAL_SUCCESS) { 00034 tr_error("extract_cn_from_certificate - cert init failed: %d", (int)ret); 00035 pal_x509Free(&cert); 00036 return false; 00037 } 00038 ret = pal_x509CertParse(cert, cer, cer_len); 00039 if (ret != PAL_SUCCESS) { 00040 tr_error("extract_cn_from_certificate - cert parse failed: %d", (int)ret); 00041 pal_x509Free(&cert); 00042 return false; 00043 } 00044 ret = pal_x509CertGetAttribute(cert, PAL_X509_CN_ATTR, common_name, 64, &len); 00045 if (ret != PAL_SUCCESS) { 00046 tr_error("extract_cn_from_certificate - cert attr get failed: %d", (int)ret); 00047 pal_x509Free(&cert); 00048 return false; 00049 } 00050 pal_x509Free(&cert); 00051 return true; 00052 } 00053
Generated on Tue Jul 12 2022 19:01:33 by 1.7.2