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.
simple-mbed-cloud-client/mbed-cloud-client/source/include/EstClient.h@0:8f0bb79ddd48, 2021-05-04 (annotated)
- Committer:
- leothedragon
- Date:
- Tue May 04 08:55:12 2021 +0000
- Revision:
- 0:8f0bb79ddd48
nmn
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
leothedragon | 0:8f0bb79ddd48 | 1 | // ---------------------------------------------------------------------------- |
leothedragon | 0:8f0bb79ddd48 | 2 | // Copyright 2018 ARM Ltd. |
leothedragon | 0:8f0bb79ddd48 | 3 | // |
leothedragon | 0:8f0bb79ddd48 | 4 | // SPDX-License-Identifier: Apache-2.0 |
leothedragon | 0:8f0bb79ddd48 | 5 | // |
leothedragon | 0:8f0bb79ddd48 | 6 | // Licensed under the Apache License, Version 2.0 (the "License"); |
leothedragon | 0:8f0bb79ddd48 | 7 | // you may not use this file except in compliance with the License. |
leothedragon | 0:8f0bb79ddd48 | 8 | // You may obtain a copy of the License at |
leothedragon | 0:8f0bb79ddd48 | 9 | // |
leothedragon | 0:8f0bb79ddd48 | 10 | // http://www.apache.org/licenses/LICENSE-2.0 |
leothedragon | 0:8f0bb79ddd48 | 11 | // |
leothedragon | 0:8f0bb79ddd48 | 12 | // Unless required by applicable law or agreed to in writing, software |
leothedragon | 0:8f0bb79ddd48 | 13 | // distributed under the License is distributed on an "AS IS" BASIS, |
leothedragon | 0:8f0bb79ddd48 | 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
leothedragon | 0:8f0bb79ddd48 | 15 | // See the License for the specific language governing permissions and |
leothedragon | 0:8f0bb79ddd48 | 16 | // limitations under the License. |
leothedragon | 0:8f0bb79ddd48 | 17 | // ---------------------------------------------------------------------------- |
leothedragon | 0:8f0bb79ddd48 | 18 | |
leothedragon | 0:8f0bb79ddd48 | 19 | #ifndef __EST_CLIENT_H__ |
leothedragon | 0:8f0bb79ddd48 | 20 | #define __EST_CLIENT_H__ |
leothedragon | 0:8f0bb79ddd48 | 21 | |
leothedragon | 0:8f0bb79ddd48 | 22 | #include "mbed-client/m2minterface.h" |
leothedragon | 0:8f0bb79ddd48 | 23 | #include "est_defs.h" |
leothedragon | 0:8f0bb79ddd48 | 24 | |
leothedragon | 0:8f0bb79ddd48 | 25 | #include <stdint.h> |
leothedragon | 0:8f0bb79ddd48 | 26 | #include <stddef.h> |
leothedragon | 0:8f0bb79ddd48 | 27 | |
leothedragon | 0:8f0bb79ddd48 | 28 | class ConnectorClient; |
leothedragon | 0:8f0bb79ddd48 | 29 | |
leothedragon | 0:8f0bb79ddd48 | 30 | /** |
leothedragon | 0:8f0bb79ddd48 | 31 | * \brief EstClient |
leothedragon | 0:8f0bb79ddd48 | 32 | * This class is an interface towards the EST service and is used to enroll |
leothedragon | 0:8f0bb79ddd48 | 33 | * certificates using a CSR. |
leothedragon | 0:8f0bb79ddd48 | 34 | */ |
leothedragon | 0:8f0bb79ddd48 | 35 | class EstClient { |
leothedragon | 0:8f0bb79ddd48 | 36 | |
leothedragon | 0:8f0bb79ddd48 | 37 | public: |
leothedragon | 0:8f0bb79ddd48 | 38 | |
leothedragon | 0:8f0bb79ddd48 | 39 | /** |
leothedragon | 0:8f0bb79ddd48 | 40 | * \brief Constructor. |
leothedragon | 0:8f0bb79ddd48 | 41 | */ |
leothedragon | 0:8f0bb79ddd48 | 42 | EstClient(ConnectorClient& connector_client); |
leothedragon | 0:8f0bb79ddd48 | 43 | |
leothedragon | 0:8f0bb79ddd48 | 44 | /** |
leothedragon | 0:8f0bb79ddd48 | 45 | * \brief Destructor. |
leothedragon | 0:8f0bb79ddd48 | 46 | */ |
leothedragon | 0:8f0bb79ddd48 | 47 | ~EstClient(); |
leothedragon | 0:8f0bb79ddd48 | 48 | |
leothedragon | 0:8f0bb79ddd48 | 49 | /** |
leothedragon | 0:8f0bb79ddd48 | 50 | * \brief Request certificate enrollment from the EST service. |
leothedragon | 0:8f0bb79ddd48 | 51 | * \param cert_name, The name of certificate to enroll. Null enrolls a LwM2M certificate. |
leothedragon | 0:8f0bb79ddd48 | 52 | * \param cert_name_length, The length of cert_name buffer. |
leothedragon | 0:8f0bb79ddd48 | 53 | * \param csr_length, The length of the certificate signing request within csr buffer. |
leothedragon | 0:8f0bb79ddd48 | 54 | * \param csr, A buffer containing the certificate signing request. |
leothedragon | 0:8f0bb79ddd48 | 55 | * \param result_cb, The callback function that is called when EST enrollment has completed. |
leothedragon | 0:8f0bb79ddd48 | 56 | * \param context, The user context that is passed to the result_cb callback. |
leothedragon | 0:8f0bb79ddd48 | 57 | */ |
leothedragon | 0:8f0bb79ddd48 | 58 | est_status_e est_request_enrollment(const char *cert_name, |
leothedragon | 0:8f0bb79ddd48 | 59 | const size_t cert_name_length, |
leothedragon | 0:8f0bb79ddd48 | 60 | uint8_t *csr, |
leothedragon | 0:8f0bb79ddd48 | 61 | const size_t csr_length, |
leothedragon | 0:8f0bb79ddd48 | 62 | est_enrollment_result_cb result_cb, |
leothedragon | 0:8f0bb79ddd48 | 63 | void *context) const; |
leothedragon | 0:8f0bb79ddd48 | 64 | |
leothedragon | 0:8f0bb79ddd48 | 65 | static void free_cert_chain_context(cert_chain_context_s *context); |
leothedragon | 0:8f0bb79ddd48 | 66 | |
leothedragon | 0:8f0bb79ddd48 | 67 | protected: |
leothedragon | 0:8f0bb79ddd48 | 68 | static void est_post_data_cb(const uint8_t *buffer, |
leothedragon | 0:8f0bb79ddd48 | 69 | size_t buffer_size, |
leothedragon | 0:8f0bb79ddd48 | 70 | size_t total_size, |
leothedragon | 0:8f0bb79ddd48 | 71 | bool last_block, |
leothedragon | 0:8f0bb79ddd48 | 72 | void *context); |
leothedragon | 0:8f0bb79ddd48 | 73 | |
leothedragon | 0:8f0bb79ddd48 | 74 | static void est_post_data_error_cb(get_data_req_error_t error_code, |
leothedragon | 0:8f0bb79ddd48 | 75 | void *context); |
leothedragon | 0:8f0bb79ddd48 | 76 | |
leothedragon | 0:8f0bb79ddd48 | 77 | private: |
leothedragon | 0:8f0bb79ddd48 | 78 | |
leothedragon | 0:8f0bb79ddd48 | 79 | static char* make_est_uri(const char *cert_name, |
leothedragon | 0:8f0bb79ddd48 | 80 | const size_t cert_name_length); |
leothedragon | 0:8f0bb79ddd48 | 81 | |
leothedragon | 0:8f0bb79ddd48 | 82 | static cert_chain_context_s* parse_cert_chain(uint8_t *cert_chain_data, |
leothedragon | 0:8f0bb79ddd48 | 83 | uint16_t cert_chain_data_len); |
leothedragon | 0:8f0bb79ddd48 | 84 | |
leothedragon | 0:8f0bb79ddd48 | 85 | private: |
leothedragon | 0:8f0bb79ddd48 | 86 | ConnectorClient &_connector_client; |
leothedragon | 0:8f0bb79ddd48 | 87 | |
leothedragon | 0:8f0bb79ddd48 | 88 | }; |
leothedragon | 0:8f0bb79ddd48 | 89 | |
leothedragon | 0:8f0bb79ddd48 | 90 | #endif // !__EST_CLIENT_H__ |