Timothy Beight / Mbed 2 deprecated 6_songs-from-the-cloud

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Fork of 6_songs-from-the-cloud by MakingMusicWorkshop

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers m2mconnectionsecuritypimpl.h Source File

m2mconnectionsecuritypimpl.h

00001 /*
00002  * Copyright (c) 2015 ARM Limited. All rights reserved.
00003  * SPDX-License-Identifier: Apache-2.0
00004  * Licensed under the Apache License, Version 2.0 (the License); you may
00005  * not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
00012  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef __M2M_CONNECTION_SECURITY_PIMPL_H__
00018 #define __M2M_CONNECTION_SECURITY_PIMPL_H__
00019 
00020 #include "mbed-client/m2mconnectionsecurity.h"
00021 #include "mbed-client/m2mtimerobserver.h"
00022 
00023 #include "mbedtls/config.h"
00024 #include "mbedtls/debug.h"
00025 #include "mbedtls/ssl.h"
00026 #include "mbedtls/entropy.h"
00027 #include "mbedtls/ctr_drbg.h"
00028 #include "mbedtls/error.h"
00029 #include "mbedtls/certs.h"
00030 #include "mbedtls/entropy_poll.h"
00031 
00032 class M2MSecurity;
00033 class M2MTimer;
00034 
00035 //TODO: Should we let application to select these or not??
00036 const static int PSK_SUITES[] = {
00037     MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA256,
00038     MBEDTLS_TLS_PSK_WITH_AES_256_CCM_8,
00039     MBEDTLS_TLS_PSK_WITH_AES_128_CCM_8,
00040     0
00041 };
00042 
00043 
00044 class M2MConnectionSecurityPimpl : public M2MTimerObserver {
00045 private:
00046     // Prevents the use of assignment operator by accident.
00047     M2MConnectionSecurityPimpl& operator=( const M2MConnectionSecurityPimpl& /*other*/ );
00048     // Prevents the use of copy constructor by accident
00049     M2MConnectionSecurityPimpl( const M2MConnectionSecurityPimpl& /*other*/ );
00050 
00051 public:
00052     M2MConnectionSecurityPimpl(M2MConnectionSecurity::SecurityMode mode);
00053 
00054     virtual ~M2MConnectionSecurityPimpl();
00055 
00056     void reset();
00057 
00058     int init(const M2MSecurity *security);
00059 
00060     int start_connecting_non_blocking(M2MConnectionHandler* connHandler);
00061     int continue_connecting();
00062 
00063     int connect(M2MConnectionHandler* connHandler);
00064 
00065     int send_message(unsigned char *message, int len);
00066 
00067     int read(unsigned char* buffer, uint16_t len);
00068 
00069 public: //From M2MTimerObserver
00070     virtual void timer_expired(M2MTimerObserver::Type type);
00071 
00072 private:
00073     bool                        _init_done;
00074     mbedtls_ssl_config          _conf;
00075     mbedtls_ssl_context         _ssl;
00076 
00077     mbedtls_x509_crt            _cacert;
00078     mbedtls_x509_crt            _owncert;
00079     mbedtls_pk_context          _pkey;
00080 
00081     mbedtls_ctr_drbg_context    _ctr_drbg;
00082     mbedtls_entropy_context     _entropy;
00083 
00084     uint32_t                    _flags;
00085     M2MTimer                    *_timmer;
00086 
00087     M2MConnectionSecurity::SecurityMode _sec_mode;
00088     bool                        _is_blocking;
00089 
00090     unsigned char               _buf[1024];
00091 
00092     friend class Test_M2MConnectionSecurityPimpl;
00093 };
00094 
00095 #endif //__M2M_CONNECTION_SECURITY_PIMPL_H__