| 529 | printf("ssl: [%d] %s\n", level, str); |
| 530 | } |
| 531 | static bool _openSSL |
| 532 | ( |
| 533 | void *ps, |
| 534 | SSLCtx *ctx |
| 535 | ) |
| 536 | { |
| 537 | ssl_set_endpoint(&ctx->ssl, SSL_IS_CLIENT); |
| 538 | ssl_set_authmode(&ctx->ssl, SSL_VERIFY_OPTIONAL); |
| 539 | ssl_set_ca_chain(&ctx->ssl, &ctx->cacert, NULL, NULL); |
| 540 | |
| 541 | /* SSLv3 is deprecated, set minimum to TLS 1.0 */ |
| 542 | ssl_set_min_version(&ctx->ssl, SSL_MAJOR_VERSION_3, SSL_MINOR_VERSION_1); |
| 543 | |
| 544 | // The following is removed from newer polarssl versions |
| 545 | #ifdef SSL_ARC4_DISABLED |
| 546 | /* RC4 is deprecated, disable it */ |
| 547 | ssl_set_arc4_support(&ctx->ssl, SSL_ARC4_DISABLED ); |
| 548 | #endif |
| 549 | |
| 550 | ssl_set_rng(&ctx->ssl, ctr_drbg_random, &ctx->ctr_drbg); |
| 551 | ssl_set_dbg(&ctx->ssl, traceprint_ssl, NULL); |
| 552 | //ssl_set_ciphersuites( &ctx->ssl, ssl_default_ciphersuites); // FIXME |
| 553 | ssl_set_bio(&ctx->ssl, net_recv, ps, net_send, ps); |
| 554 | |
| 555 | traceprint("SSL handshake now...\n"); |
| 556 | int err; |
| 557 | while( (err = ssl_handshake(&ctx->ssl)) ) |
| 558 | { |
| 559 | if(err != POLARSSL_ERR_NET_WANT_READ && err != POLARSSL_ERR_NET_WANT_WRITE) |
| 560 | { |
| 561 | traceprint("open_ssl: ssl_handshake returned -0x%x\n\n", -err); |
| 562 | return false; |
| 563 | } |
| 564 | } |
| 565 | traceprint("SSL handshake done\n"); |
| 566 | return true; |
| 567 | } |
| 568 | #endif |
| 569 | |
| 570 | bool TcpSocket::open |