![](/media/cache/profiles/debfdc81854eac26ec993b55a659c6e1.jpg.50x50_q85.jpg)
mbed client on ethernet with LWIP
Dependencies: mbed Socket lwip-eth lwip-sys lwip
Fork of mbed-client-classic-example-lwip by
mbed-client-mbedtls/mbed-client-mbedtls/m2mconnectionsecuritypimpl.h@11:cada08fc8a70, 2016-06-09 (annotated)
- Committer:
- mbedAustin
- Date:
- Thu Jun 09 17:08:36 2016 +0000
- Revision:
- 11:cada08fc8a70
Commit for public Consumption
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedAustin | 11:cada08fc8a70 | 1 | /* |
mbedAustin | 11:cada08fc8a70 | 2 | * Copyright (c) 2015 ARM Limited. All rights reserved. |
mbedAustin | 11:cada08fc8a70 | 3 | * SPDX-License-Identifier: Apache-2.0 |
mbedAustin | 11:cada08fc8a70 | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
mbedAustin | 11:cada08fc8a70 | 5 | * not use this file except in compliance with the License. |
mbedAustin | 11:cada08fc8a70 | 6 | * You may obtain a copy of the License at |
mbedAustin | 11:cada08fc8a70 | 7 | * |
mbedAustin | 11:cada08fc8a70 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
mbedAustin | 11:cada08fc8a70 | 9 | * |
mbedAustin | 11:cada08fc8a70 | 10 | * Unless required by applicable law or agreed to in writing, software |
mbedAustin | 11:cada08fc8a70 | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
mbedAustin | 11:cada08fc8a70 | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mbedAustin | 11:cada08fc8a70 | 13 | * See the License for the specific language governing permissions and |
mbedAustin | 11:cada08fc8a70 | 14 | * limitations under the License. |
mbedAustin | 11:cada08fc8a70 | 15 | */ |
mbedAustin | 11:cada08fc8a70 | 16 | |
mbedAustin | 11:cada08fc8a70 | 17 | #ifndef __M2M_CONNECTION_SECURITY_PIMPL_H__ |
mbedAustin | 11:cada08fc8a70 | 18 | #define __M2M_CONNECTION_SECURITY_PIMPL_H__ |
mbedAustin | 11:cada08fc8a70 | 19 | |
mbedAustin | 11:cada08fc8a70 | 20 | #include "mbed-client/m2mconnectionsecurity.h" |
mbedAustin | 11:cada08fc8a70 | 21 | #include "mbed-client/m2mtimerobserver.h" |
mbedAustin | 11:cada08fc8a70 | 22 | |
mbedAustin | 11:cada08fc8a70 | 23 | #include "mbedtls/config.h" |
mbedAustin | 11:cada08fc8a70 | 24 | #include "mbedtls/debug.h" |
mbedAustin | 11:cada08fc8a70 | 25 | #include "mbedtls/ssl.h" |
mbedAustin | 11:cada08fc8a70 | 26 | #include "mbedtls/entropy.h" |
mbedAustin | 11:cada08fc8a70 | 27 | #include "mbedtls/ctr_drbg.h" |
mbedAustin | 11:cada08fc8a70 | 28 | #include "mbedtls/error.h" |
mbedAustin | 11:cada08fc8a70 | 29 | #include "mbedtls/certs.h" |
mbedAustin | 11:cada08fc8a70 | 30 | #include "mbedtls/entropy_poll.h" |
mbedAustin | 11:cada08fc8a70 | 31 | |
mbedAustin | 11:cada08fc8a70 | 32 | class M2MSecurity; |
mbedAustin | 11:cada08fc8a70 | 33 | class M2MTimer; |
mbedAustin | 11:cada08fc8a70 | 34 | |
mbedAustin | 11:cada08fc8a70 | 35 | //TODO: Should we let application to select these or not?? |
mbedAustin | 11:cada08fc8a70 | 36 | const static int PSK_SUITES[] = { |
mbedAustin | 11:cada08fc8a70 | 37 | MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA256, |
mbedAustin | 11:cada08fc8a70 | 38 | MBEDTLS_TLS_PSK_WITH_AES_256_CCM_8, |
mbedAustin | 11:cada08fc8a70 | 39 | MBEDTLS_TLS_PSK_WITH_AES_128_CCM_8, |
mbedAustin | 11:cada08fc8a70 | 40 | 0 |
mbedAustin | 11:cada08fc8a70 | 41 | }; |
mbedAustin | 11:cada08fc8a70 | 42 | |
mbedAustin | 11:cada08fc8a70 | 43 | |
mbedAustin | 11:cada08fc8a70 | 44 | class M2MConnectionSecurityPimpl : public M2MTimerObserver { |
mbedAustin | 11:cada08fc8a70 | 45 | private: |
mbedAustin | 11:cada08fc8a70 | 46 | // Prevents the use of assignment operator by accident. |
mbedAustin | 11:cada08fc8a70 | 47 | M2MConnectionSecurityPimpl& operator=( const M2MConnectionSecurityPimpl& /*other*/ ); |
mbedAustin | 11:cada08fc8a70 | 48 | // Prevents the use of copy constructor by accident |
mbedAustin | 11:cada08fc8a70 | 49 | M2MConnectionSecurityPimpl( const M2MConnectionSecurityPimpl& /*other*/ ); |
mbedAustin | 11:cada08fc8a70 | 50 | |
mbedAustin | 11:cada08fc8a70 | 51 | public: |
mbedAustin | 11:cada08fc8a70 | 52 | M2MConnectionSecurityPimpl(M2MConnectionSecurity::SecurityMode mode); |
mbedAustin | 11:cada08fc8a70 | 53 | |
mbedAustin | 11:cada08fc8a70 | 54 | virtual ~M2MConnectionSecurityPimpl(); |
mbedAustin | 11:cada08fc8a70 | 55 | |
mbedAustin | 11:cada08fc8a70 | 56 | void reset(); |
mbedAustin | 11:cada08fc8a70 | 57 | |
mbedAustin | 11:cada08fc8a70 | 58 | int init(const M2MSecurity *security); |
mbedAustin | 11:cada08fc8a70 | 59 | |
mbedAustin | 11:cada08fc8a70 | 60 | int start_connecting_non_blocking(M2MConnectionHandler* connHandler); |
mbedAustin | 11:cada08fc8a70 | 61 | int continue_connecting(); |
mbedAustin | 11:cada08fc8a70 | 62 | |
mbedAustin | 11:cada08fc8a70 | 63 | int connect(M2MConnectionHandler* connHandler); |
mbedAustin | 11:cada08fc8a70 | 64 | |
mbedAustin | 11:cada08fc8a70 | 65 | int send_message(unsigned char *message, int len); |
mbedAustin | 11:cada08fc8a70 | 66 | |
mbedAustin | 11:cada08fc8a70 | 67 | int read(unsigned char* buffer, uint16_t len); |
mbedAustin | 11:cada08fc8a70 | 68 | |
mbedAustin | 11:cada08fc8a70 | 69 | public: //From M2MTimerObserver |
mbedAustin | 11:cada08fc8a70 | 70 | virtual void timer_expired(M2MTimerObserver::Type type); |
mbedAustin | 11:cada08fc8a70 | 71 | |
mbedAustin | 11:cada08fc8a70 | 72 | private: |
mbedAustin | 11:cada08fc8a70 | 73 | bool _init_done; |
mbedAustin | 11:cada08fc8a70 | 74 | mbedtls_ssl_config _conf; |
mbedAustin | 11:cada08fc8a70 | 75 | mbedtls_ssl_context _ssl; |
mbedAustin | 11:cada08fc8a70 | 76 | |
mbedAustin | 11:cada08fc8a70 | 77 | mbedtls_x509_crt _cacert; |
mbedAustin | 11:cada08fc8a70 | 78 | mbedtls_x509_crt _owncert; |
mbedAustin | 11:cada08fc8a70 | 79 | mbedtls_pk_context _pkey; |
mbedAustin | 11:cada08fc8a70 | 80 | |
mbedAustin | 11:cada08fc8a70 | 81 | mbedtls_ctr_drbg_context _ctr_drbg; |
mbedAustin | 11:cada08fc8a70 | 82 | mbedtls_entropy_context _entropy; |
mbedAustin | 11:cada08fc8a70 | 83 | |
mbedAustin | 11:cada08fc8a70 | 84 | uint32_t _flags; |
mbedAustin | 11:cada08fc8a70 | 85 | M2MTimer *_timmer; |
mbedAustin | 11:cada08fc8a70 | 86 | |
mbedAustin | 11:cada08fc8a70 | 87 | M2MConnectionSecurity::SecurityMode _sec_mode; |
mbedAustin | 11:cada08fc8a70 | 88 | bool _is_blocking; |
mbedAustin | 11:cada08fc8a70 | 89 | |
mbedAustin | 11:cada08fc8a70 | 90 | unsigned char _buf[1024]; |
mbedAustin | 11:cada08fc8a70 | 91 | |
mbedAustin | 11:cada08fc8a70 | 92 | friend class Test_M2MConnectionSecurityPimpl; |
mbedAustin | 11:cada08fc8a70 | 93 | }; |
mbedAustin | 11:cada08fc8a70 | 94 | |
mbedAustin | 11:cada08fc8a70 | 95 | #endif //__M2M_CONNECTION_SECURITY_PIMPL_H__ |