Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers mbedtls_stub.c Source File

mbedtls_stub.c

00001 /*
00002  * Copyright (c) 2015-2017, Arm Limited and affiliates.
00003  * SPDX-License-Identifier: Apache-2.0
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License");
00006  * you may not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  *     http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 #include "mbedtls_stub.h"
00019 
00020 mbedtls_stub_def mbedtls_stub;
00021 
00022 //From ssl.h
00023 int mbedtls_ssl_handshake_step(mbedtls_ssl_context *ssl)
00024 {
00025     if (mbedtls_stub.useCounter) {
00026 
00027         if (mbedtls_stub.retArray[mbedtls_stub.counter] == HANDSHAKE_FINISHED_VALUE ||
00028                 mbedtls_stub.retArray[mbedtls_stub.counter] == HANDSHAKE_FINISHED_VALUE_RETURN_ZERO) {
00029 
00030             ssl->state = MBEDTLS_SSL_HANDSHAKE_OVER;
00031             if (mbedtls_stub.retArray[mbedtls_stub.counter] == HANDSHAKE_FINISHED_VALUE_RETURN_ZERO) {
00032                 return 0;
00033             }
00034         }
00035         return mbedtls_stub.retArray[mbedtls_stub.counter++];
00036     }
00037     return mbedtls_stub.expected_int;
00038 }
00039 
00040 int mbedtls_ssl_close_notify(mbedtls_ssl_context *a)
00041 {
00042     if (mbedtls_stub.useCounter) {
00043         return mbedtls_stub.retArray[mbedtls_stub.counter++];
00044     }
00045     return mbedtls_stub.expected_int;
00046 }
00047 
00048 void mbedtls_ssl_init(mbedtls_ssl_context *a)
00049 {
00050 
00051 }
00052 void mbedtls_ssl_conf_min_version(mbedtls_ssl_config *conf, int major, int minor)
00053 {
00054 
00055 }
00056 
00057 void mbedtls_ssl_conf_max_version(mbedtls_ssl_config *conf, int major, int minor)
00058 {
00059 
00060 }
00061 
00062 void mbedtls_ssl_conf_transport(mbedtls_ssl_config *conf, int transport)
00063 {
00064 
00065 }
00066 
00067 void mbedtls_ssl_config_init(mbedtls_ssl_config *a)
00068 {
00069 
00070 }
00071 
00072 void mbedtls_ssl_conf_handshake_timeout(mbedtls_ssl_config *a, uint32_t b, uint32_t c)
00073 {
00074 
00075 }
00076 
00077 void mbedtls_ssl_free(mbedtls_ssl_context *a)
00078 {
00079 
00080 }
00081 
00082 int mbedtls_ssl_conf_own_cert(mbedtls_ssl_config *a,
00083                               mbedtls_x509_crt *b,
00084                               mbedtls_pk_context *c)
00085 {
00086     if (mbedtls_stub.useCounter) {
00087         return mbedtls_stub.retArray[mbedtls_stub.counter++];
00088     }
00089     return mbedtls_stub.expected_int;
00090 }
00091 
00092 void mbedtls_ssl_conf_authmode(mbedtls_ssl_config *a, int c)
00093 {
00094 
00095 }
00096 
00097 void mbedtls_ssl_conf_ca_chain(mbedtls_ssl_config *a,
00098                                mbedtls_x509_crt *b,
00099                                mbedtls_x509_crl *c)
00100 {
00101 
00102 }
00103 
00104 int mbedtls_ssl_conf_psk(mbedtls_ssl_config *a,
00105                          const unsigned char *b, size_t c,
00106                          const unsigned char *d, size_t e)
00107 {
00108     if (mbedtls_stub.useCounter) {
00109         return mbedtls_stub.retArray[mbedtls_stub.counter++];
00110     }
00111     return mbedtls_stub.expected_int;
00112 }
00113 
00114 int mbedtls_ssl_config_defaults(mbedtls_ssl_config *a,
00115                                 int b, int c, int d)
00116 {
00117     if (mbedtls_stub.useCounter) {
00118         return mbedtls_stub.retArray[mbedtls_stub.counter++];
00119     }
00120     return mbedtls_stub.expected_int;
00121 }
00122 
00123 void mbedtls_ssl_conf_rng(mbedtls_ssl_config *a,
00124                           int (*f_rng)(void *, unsigned char *, size_t),
00125                           void *b)
00126 {
00127 
00128 }
00129 
00130 void mbedtls_ssl_conf_ciphersuites(mbedtls_ssl_config *a,
00131                                    const int *b)
00132 {
00133 
00134 }
00135 
00136 int mbedtls_ssl_setup(mbedtls_ssl_context *a,
00137                       const mbedtls_ssl_config *b)
00138 {
00139     if (mbedtls_stub.useCounter) {
00140         return mbedtls_stub.retArray[mbedtls_stub.counter++];
00141     }
00142     return mbedtls_stub.expected_int;
00143 }
00144 
00145 void mbedtls_ssl_set_bio(mbedtls_ssl_context *ssl,
00146                          void *p_bio,
00147                          int (*f_send)(void *, const unsigned char *, size_t),
00148                          int (*f_recv)(void *, unsigned char *, size_t),
00149                          int (*f_recv_timeout)(void *, unsigned char *, size_t, uint32_t))
00150 {
00151     if (p_bio != NULL) {
00152         if (f_send) {
00153             f_send(p_bio, NULL, 0);
00154         }
00155         if (f_recv) {
00156             f_recv(p_bio, NULL, 0);
00157         }
00158         if (f_recv_timeout) {
00159             f_recv_timeout(p_bio, NULL, 0, 0);
00160         }
00161     }
00162 }
00163 
00164 void mbedtls_ssl_set_timer_cb(mbedtls_ssl_context *a,
00165                               void *ctx,
00166                               void (*f_set_timer)(void *, uint32_t int_ms, uint32_t fin_ms),
00167                               int (*f_get_timer)(void *))
00168 {
00169     f_set_timer(ctx, 1, 2);
00170     f_get_timer(ctx);
00171     if (mbedtls_stub.invalidate_timer) {
00172         f_set_timer(ctx, 0, 0);
00173     }
00174     f_get_timer(ctx);
00175 }
00176 
00177 int mbedtls_ssl_handshake(mbedtls_ssl_context *ssl)
00178 {
00179     if (mbedtls_stub.useCounter) {
00180         return mbedtls_stub.retArray[mbedtls_stub.counter++];
00181     }
00182     return mbedtls_stub.expected_int;
00183 }
00184 
00185 uint32_t mbedtls_ssl_get_verify_result(const mbedtls_ssl_context *a)
00186 {
00187     return mbedtls_stub.uint32_value;
00188 }
00189 
00190 int mbedtls_ssl_read(mbedtls_ssl_context *a, unsigned char *b, size_t c)
00191 {
00192     if (mbedtls_stub.useCounter) {
00193         return mbedtls_stub.retArray[mbedtls_stub.counter++];
00194     }
00195     return mbedtls_stub.expected_int;
00196 }
00197 
00198 int mbedtls_ssl_write(mbedtls_ssl_context *a, const unsigned char *b, size_t c)
00199 {
00200     if (mbedtls_stub.useCounter) {
00201         return mbedtls_stub.retArray[mbedtls_stub.counter++];
00202     }
00203     return mbedtls_stub.expected_int;
00204 }
00205 
00206 int mbedtls_ssl_set_hostname(mbedtls_ssl_context *ssl, const char *hostname)
00207 {
00208     return 0;
00209 }
00210 
00211 const mbedtls_x509_crt *mbedtls_ssl_get_peer_cert(const mbedtls_ssl_context *ssl)
00212 {
00213     return NULL;
00214 }
00215 
00216 
00217 
00218 //From crt_drbg.h
00219 int mbedtls_ctr_drbg_seed(mbedtls_ctr_drbg_context *a,
00220                           int (*f_entropy)(void *, unsigned char *, size_t),
00221                           void *b,
00222                           const unsigned char *c,
00223                           size_t d)
00224 {
00225     return mbedtls_stub.crt_expected_int;
00226 }
00227 
00228 void mbedtls_ctr_drbg_init(mbedtls_ctr_drbg_context *a)
00229 {
00230 
00231 }
00232 
00233 void mbedtls_ctr_drbg_free(mbedtls_ctr_drbg_context *a)
00234 {
00235 
00236 }
00237 
00238 int mbedtls_ctr_drbg_random_with_add(void *a,
00239                                      unsigned char *b, size_t c,
00240                                      const unsigned char *d, size_t e)
00241 {
00242     return mbedtls_stub.crt_expected_int;
00243 }
00244 
00245 int mbedtls_ctr_drbg_random(void *p_rng,
00246                             unsigned char *output, size_t output_len)
00247 {
00248     return mbedtls_stub.crt_expected_int;
00249 }
00250 
00251 //From x509_crt.h
00252 void mbedtls_x509_crt_init(mbedtls_x509_crt *a)
00253 {
00254 
00255 }
00256 
00257 void mbedtls_x509_crt_free(mbedtls_x509_crt *a)
00258 {
00259 
00260 }
00261 
00262 int mbedtls_x509_crt_parse(mbedtls_x509_crt *a, const unsigned char *b, size_t c)
00263 {
00264     if (mbedtls_stub.useCounter) {
00265         return mbedtls_stub.retArray[mbedtls_stub.counter++];
00266     }
00267     return mbedtls_stub.expected_int;
00268 }
00269 
00270 int mbedtls_x509_crt_info(char *buf, size_t size, const char *prefix,
00271                           const mbedtls_x509_crt *crt)
00272 {
00273     return 0;
00274 }
00275 
00276 int mbedtls_x509_crt_verify_info(char *buf, size_t size, const char *prefix,
00277                                  uint32_t flags)
00278 {
00279     return 0;
00280 }
00281 
00282 //From entropy.h
00283 void mbedtls_entropy_init(mbedtls_entropy_context *a)
00284 {
00285 
00286 }
00287 
00288 void mbedtls_entropy_free(mbedtls_entropy_context *ctx)
00289 {
00290 
00291 }
00292 
00293 int mbedtls_entropy_func(void *a, unsigned char *b, size_t c)
00294 {
00295     if (mbedtls_stub.useCounter) {
00296         return mbedtls_stub.retArray[mbedtls_stub.counter++];
00297     }
00298     return mbedtls_stub.expected_int;
00299 }
00300 
00301 int mbedtls_entropy_add_source(mbedtls_entropy_context *a,
00302                                mbedtls_entropy_f_source_ptr f_source, void *b,
00303                                size_t c, int d)
00304 {
00305     unsigned char buf[2];
00306     size_t len;
00307     f_source(NULL, buf, 1, &len);
00308 
00309     if (mbedtls_stub.useCounter) {
00310         return mbedtls_stub.retArray[mbedtls_stub.counter++];
00311     }
00312     return mbedtls_stub.expected_int;
00313 }
00314 
00315 //From pk.h
00316 int mbedtls_pk_parse_key(mbedtls_pk_context *a,
00317                          const unsigned char *b, size_t c,
00318                          const unsigned char *d, size_t e)
00319 {
00320     if (mbedtls_stub.useCounter) {
00321         return mbedtls_stub.retArray[mbedtls_stub.counter++];
00322     }
00323     return mbedtls_stub.expected_int;
00324 }
00325 
00326 void mbedtls_pk_init(mbedtls_pk_context *ctx)
00327 {
00328 
00329 }
00330 
00331 void mbedtls_pk_free(mbedtls_pk_context *ctx)
00332 {
00333 
00334 }
00335 
00336 void mbedtls_ssl_config_free(mbedtls_ssl_config *a)
00337 {
00338 
00339 }
00340 
00341 int mbedtls_ssl_set_hs_ecjpake_password(mbedtls_ssl_context *ssl,
00342                                         const unsigned char *pw,
00343                                         size_t pw_len)
00344 {
00345     if (mbedtls_stub.useCounter) {
00346         return mbedtls_stub.retArray[mbedtls_stub.counter++];
00347     }
00348     return mbedtls_stub.expected_int;
00349 }
00350 
00351 void mbedtls_ssl_conf_dtls_cookies(mbedtls_ssl_config *conf,
00352                                    mbedtls_ssl_cookie_write_t *f_cookie_write,
00353                                    mbedtls_ssl_cookie_check_t *f_cookie_check,
00354                                    void *p_cookie)
00355 {
00356     if (mbedtls_stub.cookie_obj && f_cookie_check && mbedtls_stub.cookie_len > 0) {
00357         f_cookie_check(mbedtls_stub.cookie_obj, &mbedtls_stub.cookie_value, mbedtls_stub.cookie_len, NULL, 0);
00358     }
00359     if (mbedtls_stub.cookie_obj && f_cookie_write && mbedtls_stub.cookie_len > 0) {
00360         unsigned char out[16];
00361         unsigned char *ptr = &out;
00362         f_cookie_write(mbedtls_stub.cookie_obj, &ptr, ptr + mbedtls_stub.cookie_len, NULL, 0);
00363     }
00364 }
00365 
00366 void mbedtls_ssl_conf_export_keys_cb(mbedtls_ssl_config *conf,
00367                                      mbedtls_ssl_export_keys_t *f_export_keys,
00368                                      void *p_export_keys)
00369 {
00370     if (f_export_keys && p_export_keys) {
00371         unsigned char value[40];
00372         memset(&value, 1, 40);
00373         f_export_keys(p_export_keys, &value, "", 0, 0, 0); //failure case
00374 
00375         f_export_keys(p_export_keys, &value, "", 0, 20, 0); //success case
00376     }
00377 }
00378 
00379 int mbedtls_ssl_session_reset(mbedtls_ssl_context *ssl)
00380 {
00381     if (mbedtls_stub.useCounter) {
00382         return mbedtls_stub.retArray[mbedtls_stub.counter++];
00383     }
00384     return mbedtls_stub.expected_int;
00385 }
00386 
00387 void mbedtls_strerror(int ret, char *buf, size_t buflen)
00388 {
00389 }
00390 
00391 int mbedtls_platform_setup(mbedtls_platform_context *ctx)
00392 {
00393     (void)ctx;
00394 
00395     return (0);
00396 }
00397 
00398 void mbedtls_platform_teardown(mbedtls_platform_context *ctx)
00399 {
00400     (void)ctx;
00401 }