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.
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_field_from_certificate(const uint8_t* cer, size_t cer_len, const char *field, char* value) 00026 { 00027 #if 1 // TODO : Uncomment once PAL has feature to extract "L" from certificate 00028 tr_debug("extract_field_from_certificate"); 00029 00030 palX509Attr_t attr = PAL_X509_L_ATTR; 00031 if (strcmp(field,"CN") == 0) { 00032 attr = PAL_X509_CN_ATTR; 00033 } else if (strcmp(field,"L") == 0) { 00034 attr = PAL_X509_L_ATTR; 00035 } else { 00036 return false; 00037 } 00038 00039 palX509Handle_t cert = 0; 00040 size_t len = 0; 00041 palStatus_t ret = pal_x509Initiate(&cert); 00042 if (ret != PAL_SUCCESS) { 00043 tr_error("extract_field_from_certificate - cert init failed: %d", (int)ret); 00044 pal_x509Free(&cert); 00045 return false; 00046 } 00047 ret = pal_x509CertParse(cert, cer, cer_len); 00048 if (ret != PAL_SUCCESS) { 00049 tr_error("extract_field_from_certificate - cert parse failed: %d", (int)ret); 00050 pal_x509Free(&cert); 00051 return false; 00052 } 00053 ret = pal_x509CertGetAttribute(cert, attr, value, 64, &len); 00054 if (ret != PAL_SUCCESS) { 00055 tr_error("extract_field_from_certificate - cert attr get failed: %d", (int)ret); 00056 pal_x509Free(&cert); 00057 return false; 00058 } 00059 pal_x509Free(&cert); 00060 return true; 00061 #else 00062 return false; 00063 #endif 00064 } 00065 00066
Generated on Mon Aug 29 2022 19:53:38 by
