Mayank Gupta / Mbed OS pelion-example-frdm

Dependencies:   FXAS21002 FXOS8700Q

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers EstClient.h Source File

EstClient.h

00001 // ----------------------------------------------------------------------------
00002 // Copyright 2018 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 #ifndef __EST_CLIENT_H__
00020 #define __EST_CLIENT_H__
00021 
00022 #include "mbed-client/m2minterface.h"
00023 #include "est_defs.h"
00024 
00025 #include <stdint.h>
00026 #include <stddef.h>
00027 
00028 class ConnectorClient;
00029 
00030 /**
00031  * \brief EstClient
00032  * This class is an interface towards the EST service and is used to enroll
00033  * certificates using a CSR.
00034  */
00035 class EstClient {
00036 
00037 public:
00038 
00039     /**
00040      * \brief Constructor.
00041      */
00042     EstClient(ConnectorClient& connector_client);
00043 
00044     /**
00045      * \brief Destructor.
00046      */
00047     ~EstClient();
00048 
00049     /**
00050      * \brief Request certificate enrollment from the EST service.
00051      * \param cert_name, The name of certificate to enroll. Null enrolls a LwM2M certificate.
00052      * \param cert_name_length, The length of cert_name buffer.
00053      * \param csr_length, The length of the certificate signing request within csr buffer.
00054      * \param csr, A buffer containing the certificate signing request.
00055      * \param result_cb, The callback function that is called when EST enrollment has completed.
00056      * \param context, The user context that is passed to the result_cb callback.
00057      */
00058     est_status_e est_request_enrollment(const char *cert_name,
00059                                         const size_t cert_name_length,
00060                                         uint8_t *csr,
00061                                         const size_t csr_length,
00062                                         est_enrollment_result_cb result_cb,
00063                                         void *context) const;
00064 
00065     static void free_cert_chain_context(cert_chain_context_s *context);
00066 
00067 protected:
00068     static void est_post_data_cb(const uint8_t *buffer,
00069                                  size_t buffer_size,
00070                                  size_t total_size,
00071                                  bool last_block,
00072                                  void *context);
00073 
00074     static void est_post_data_error_cb(get_data_req_error_t error_code,
00075                                        void *context);
00076 
00077 private:
00078 
00079     static char* make_est_uri(const char *cert_name,
00080                               const size_t cert_name_length);
00081 
00082     static cert_chain_context_s* parse_cert_chain(uint8_t *cert_chain_data,
00083                                                   uint16_t cert_chain_data_len);
00084 
00085 private:
00086     ConnectorClient           &_connector_client;
00087 
00088 };
00089 
00090 #endif // !__EST_CLIENT_H__