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
simple-mbed-cloud-client/mbed-cloud-client/source/CertificateParser.c@2:990c985a69ae, 2020-03-20 (annotated)
- Committer:
- vithyat
- Date:
- Fri Mar 20 20:15:18 2020 +0000
- Revision:
- 2:990c985a69ae
- Parent:
- 0:977e87915078
Update to work with P2Scan runtime
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vithyat | 0:977e87915078 | 1 | // ---------------------------------------------------------------------------- |
vithyat | 0:977e87915078 | 2 | // Copyright 2016-2017 ARM Ltd. |
vithyat | 0:977e87915078 | 3 | // |
vithyat | 0:977e87915078 | 4 | // SPDX-License-Identifier: Apache-2.0 |
vithyat | 0:977e87915078 | 5 | // |
vithyat | 0:977e87915078 | 6 | // Licensed under the Apache License, Version 2.0 (the "License"); |
vithyat | 0:977e87915078 | 7 | // you may not use this file except in compliance with the License. |
vithyat | 0:977e87915078 | 8 | // You may obtain a copy of the License at |
vithyat | 0:977e87915078 | 9 | // |
vithyat | 0:977e87915078 | 10 | // http://www.apache.org/licenses/LICENSE-2.0 |
vithyat | 0:977e87915078 | 11 | // |
vithyat | 0:977e87915078 | 12 | // Unless required by applicable law or agreed to in writing, software |
vithyat | 0:977e87915078 | 13 | // distributed under the License is distributed on an "AS IS" BASIS, |
vithyat | 0:977e87915078 | 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
vithyat | 0:977e87915078 | 15 | // See the License for the specific language governing permissions and |
vithyat | 0:977e87915078 | 16 | // limitations under the License. |
vithyat | 0:977e87915078 | 17 | // ---------------------------------------------------------------------------- |
vithyat | 0:977e87915078 | 18 | |
vithyat | 0:977e87915078 | 19 | #include <stdint.h> |
vithyat | 0:977e87915078 | 20 | #include "pal.h" |
vithyat | 0:977e87915078 | 21 | #include "mbed-trace/mbed_trace.h" |
vithyat | 0:977e87915078 | 22 | |
vithyat | 0:977e87915078 | 23 | #define TRACE_GROUP "mClt" |
vithyat | 0:977e87915078 | 24 | |
vithyat | 0:977e87915078 | 25 | bool extract_field_from_certificate(const uint8_t* cer, size_t cer_len, const char *field, char* value) |
vithyat | 0:977e87915078 | 26 | { |
vithyat | 0:977e87915078 | 27 | #if 1 // TODO : Uncomment once PAL has feature to extract "L" from certificate |
vithyat | 0:977e87915078 | 28 | tr_debug("extract_field_from_certificate"); |
vithyat | 0:977e87915078 | 29 | |
vithyat | 0:977e87915078 | 30 | palX509Attr_t attr = PAL_X509_L_ATTR; |
vithyat | 0:977e87915078 | 31 | if (strcmp(field,"CN") == 0) { |
vithyat | 0:977e87915078 | 32 | attr = PAL_X509_CN_ATTR; |
vithyat | 0:977e87915078 | 33 | } else if (strcmp(field,"L") == 0) { |
vithyat | 0:977e87915078 | 34 | attr = PAL_X509_L_ATTR; |
vithyat | 0:977e87915078 | 35 | } else { |
vithyat | 0:977e87915078 | 36 | return false; |
vithyat | 0:977e87915078 | 37 | } |
vithyat | 0:977e87915078 | 38 | |
vithyat | 0:977e87915078 | 39 | palX509Handle_t cert = 0; |
vithyat | 0:977e87915078 | 40 | size_t len = 0; |
vithyat | 0:977e87915078 | 41 | palStatus_t ret = pal_x509Initiate(&cert); |
vithyat | 0:977e87915078 | 42 | if (ret != PAL_SUCCESS) { |
vithyat | 0:977e87915078 | 43 | tr_error("extract_field_from_certificate - cert init failed: %d", (int)ret); |
vithyat | 0:977e87915078 | 44 | pal_x509Free(&cert); |
vithyat | 0:977e87915078 | 45 | return false; |
vithyat | 0:977e87915078 | 46 | } |
vithyat | 0:977e87915078 | 47 | ret = pal_x509CertParse(cert, cer, cer_len); |
vithyat | 0:977e87915078 | 48 | if (ret != PAL_SUCCESS) { |
vithyat | 0:977e87915078 | 49 | tr_error("extract_field_from_certificate - cert parse failed: %d", (int)ret); |
vithyat | 0:977e87915078 | 50 | pal_x509Free(&cert); |
vithyat | 0:977e87915078 | 51 | return false; |
vithyat | 0:977e87915078 | 52 | } |
vithyat | 0:977e87915078 | 53 | ret = pal_x509CertGetAttribute(cert, attr, value, 64, &len); |
vithyat | 0:977e87915078 | 54 | if (ret != PAL_SUCCESS) { |
vithyat | 0:977e87915078 | 55 | tr_error("extract_field_from_certificate - cert attr get failed: %d", (int)ret); |
vithyat | 0:977e87915078 | 56 | pal_x509Free(&cert); |
vithyat | 0:977e87915078 | 57 | return false; |
vithyat | 0:977e87915078 | 58 | } |
vithyat | 0:977e87915078 | 59 | pal_x509Free(&cert); |
vithyat | 0:977e87915078 | 60 | return true; |
vithyat | 0:977e87915078 | 61 | #else |
vithyat | 0:977e87915078 | 62 | return false; |
vithyat | 0:977e87915078 | 63 | #endif |
vithyat | 0:977e87915078 | 64 | } |
vithyat | 0:977e87915078 | 65 | |
vithyat | 0:977e87915078 | 66 |