Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * SSL client for SMTP servers |
| 3 | * |
Manuel Pégourié-Gonnard | a658a40 | 2015-01-23 09:45:19 +0000 | [diff] [blame] | 4 | * Copyright (C) 2006-2012, ARM Limited, All Rights Reserved |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 5 | * |
Manuel Pégourié-Gonnard | fe44643 | 2015-03-06 13:17:10 +0000 | [diff] [blame^] | 6 | * This file is part of mbed TLS (https://tls.mbed.org) |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 7 | * |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along |
| 19 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | */ |
| 22 | |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 23 | #if !defined(POLARSSL_CONFIG_FILE) |
Manuel Pégourié-Gonnard | abd6e02 | 2013-09-20 13:30:43 +0200 | [diff] [blame] | 24 | #include "polarssl/config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 25 | #else |
| 26 | #include POLARSSL_CONFIG_FILE |
| 27 | #endif |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 28 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 29 | #if defined(POLARSSL_PLATFORM_C) |
| 30 | #include "polarssl/platform.h" |
| 31 | #else |
Rich Evans | 18b78c7 | 2015-02-11 14:06:19 +0000 | [diff] [blame] | 32 | #include <stdio.h> |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 33 | #define polarssl_fprintf fprintf |
Rich Evans | 18b78c7 | 2015-02-11 14:06:19 +0000 | [diff] [blame] | 34 | #define polarssl_printf printf |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 35 | #endif |
| 36 | |
Rich Evans | 18b78c7 | 2015-02-11 14:06:19 +0000 | [diff] [blame] | 37 | #if defined(POLARSSL_BIGNUM_C) && defined(POLARSSL_ENTROPY_C) && \ |
| 38 | defined(POLARSSL_SSL_TLS_C) && defined(POLARSSL_SSL_CLI_C) && \ |
| 39 | defined(POLARSSL_NET_C) && defined(POLARSSL_RSA_C) && \ |
| 40 | defined(POLARSSL_CTR_DRBG_C) && defined(POLARSSL_X509_CRT_PARSE_C) && \ |
| 41 | defined(POLARSSL_FS_IO) |
| 42 | #include "polarssl/base64.h" |
| 43 | #include "polarssl/error.h" |
| 44 | #include "polarssl/net.h" |
| 45 | #include "polarssl/ssl.h" |
| 46 | #include "polarssl/entropy.h" |
| 47 | #include "polarssl/ctr_drbg.h" |
| 48 | #include "polarssl/certs.h" |
| 49 | #include "polarssl/x509.h" |
| 50 | |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 51 | #include <stdio.h> |
Rich Evans | 18b78c7 | 2015-02-11 14:06:19 +0000 | [diff] [blame] | 52 | #include <stdlib.h> |
| 53 | #include <string.h> |
| 54 | #endif |
Paul Bakker | fdda785 | 2013-11-30 15:15:31 +0100 | [diff] [blame] | 55 | |
| 56 | #if !defined(_MSC_VER) || defined(EFIX64) || defined(EFI32) |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 57 | #include <unistd.h> |
Paul Bakker | fdda785 | 2013-11-30 15:15:31 +0100 | [diff] [blame] | 58 | #else |
| 59 | #include <io.h> |
| 60 | #define read _read |
| 61 | #define write _write |
| 62 | #endif |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 63 | |
Paul Bakker | 5a83522 | 2011-10-12 09:19:31 +0000 | [diff] [blame] | 64 | #if defined(_WIN32) || defined(_WIN32_WCE) |
Paul Bakker | 5a83522 | 2011-10-12 09:19:31 +0000 | [diff] [blame] | 65 | #include <winsock2.h> |
| 66 | #include <windows.h> |
| 67 | |
Paul Bakker | f0fc2a2 | 2013-12-30 15:42:43 +0100 | [diff] [blame] | 68 | #if defined(_MSC_VER) |
Paul Bakker | 5a83522 | 2011-10-12 09:19:31 +0000 | [diff] [blame] | 69 | #if defined(_WIN32_WCE) |
| 70 | #pragma comment( lib, "ws2.lib" ) |
| 71 | #else |
| 72 | #pragma comment( lib, "ws2_32.lib" ) |
| 73 | #endif |
Paul Bakker | f0fc2a2 | 2013-12-30 15:42:43 +0100 | [diff] [blame] | 74 | #endif /* _MSC_VER */ |
Paul Bakker | 5a83522 | 2011-10-12 09:19:31 +0000 | [diff] [blame] | 75 | #endif |
| 76 | |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 77 | #define DFL_SERVER_NAME "localhost" |
| 78 | #define DFL_SERVER_PORT 465 |
| 79 | #define DFL_USER_NAME "user" |
| 80 | #define DFL_USER_PWD "password" |
| 81 | #define DFL_MAIL_FROM "" |
| 82 | #define DFL_MAIL_TO "" |
| 83 | #define DFL_DEBUG_LEVEL 0 |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 84 | #define DFL_CA_FILE "" |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 85 | #define DFL_CRT_FILE "" |
| 86 | #define DFL_KEY_FILE "" |
| 87 | #define DFL_FORCE_CIPHER 0 |
| 88 | #define DFL_MODE 0 |
| 89 | #define DFL_AUTHENTICATION 0 |
| 90 | |
| 91 | #define MODE_SSL_TLS 0 |
| 92 | #define MODE_STARTTLS 0 |
| 93 | |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 94 | #if defined(POLARSSL_BASE64_C) |
| 95 | #define USAGE_AUTH \ |
| 96 | " authentication=%%d default: 0 (disabled)\n" \ |
| 97 | " user_name=%%s default: \"user\"\n" \ |
Manuel Pégourié-Gonnard | 6c5abfa | 2015-02-13 14:12:07 +0000 | [diff] [blame] | 98 | " user_pwd=%%s default: \"password\"\n" |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 99 | #else |
| 100 | #define USAGE_AUTH \ |
| 101 | " authentication options disabled. (Require POLARSSL_BASE64_C)\n" |
| 102 | #endif /* POLARSSL_BASE64_C */ |
| 103 | |
| 104 | #if defined(POLARSSL_FS_IO) |
| 105 | #define USAGE_IO \ |
| 106 | " ca_file=%%s default: \"\" (pre-loaded)\n" \ |
| 107 | " crt_file=%%s default: \"\" (pre-loaded)\n" \ |
| 108 | " key_file=%%s default: \"\" (pre-loaded)\n" |
| 109 | #else |
| 110 | #define USAGE_IO \ |
| 111 | " No file operations available (POLARSSL_FS_IO not defined)\n" |
| 112 | #endif /* POLARSSL_FS_IO */ |
| 113 | |
| 114 | #define USAGE \ |
| 115 | "\n usage: ssl_mail_client param=<>...\n" \ |
| 116 | "\n acceptable parameters:\n" \ |
| 117 | " server_name=%%s default: localhost\n" \ |
| 118 | " server_port=%%d default: 4433\n" \ |
| 119 | " debug_level=%%d default: 0 (disabled)\n" \ |
| 120 | " mode=%%d default: 0 (SSL/TLS) (1 for STARTTLS)\n" \ |
| 121 | USAGE_AUTH \ |
| 122 | " mail_from=%%s default: \"\"\n" \ |
| 123 | " mail_to=%%s default: \"\"\n" \ |
| 124 | USAGE_IO \ |
| 125 | " force_ciphersuite=<name> default: all enabled\n"\ |
| 126 | " acceptable ciphersuite names:\n" |
| 127 | |
Rich Evans | 18b78c7 | 2015-02-11 14:06:19 +0000 | [diff] [blame] | 128 | #if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_ENTROPY_C) || \ |
| 129 | !defined(POLARSSL_SSL_TLS_C) || !defined(POLARSSL_SSL_CLI_C) || \ |
| 130 | !defined(POLARSSL_NET_C) || !defined(POLARSSL_RSA_C) || \ |
Manuel Pégourié-Gonnard | 013bffe | 2015-02-13 14:09:44 +0000 | [diff] [blame] | 131 | !defined(POLARSSL_CTR_DRBG_C) || !defined(POLARSSL_X509_CRT_PARSE_C) || \ |
Rich Evans | 18b78c7 | 2015-02-11 14:06:19 +0000 | [diff] [blame] | 132 | !defined(POLARSSL_FS_IO) |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 133 | int main( void ) |
Rich Evans | 18b78c7 | 2015-02-11 14:06:19 +0000 | [diff] [blame] | 134 | { |
Rich Evans | 18b78c7 | 2015-02-11 14:06:19 +0000 | [diff] [blame] | 135 | polarssl_printf("POLARSSL_BIGNUM_C and/or POLARSSL_ENTROPY_C and/or " |
| 136 | "POLARSSL_SSL_TLS_C and/or POLARSSL_SSL_CLI_C and/or " |
| 137 | "POLARSSL_NET_C and/or POLARSSL_RSA_C and/or " |
| 138 | "POLARSSL_CTR_DRBG_C and/or POLARSSL_X509_CRT_PARSE_C " |
| 139 | "not defined.\n"); |
| 140 | return( 0 ); |
| 141 | } |
| 142 | #else |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 143 | /* |
| 144 | * global options |
| 145 | */ |
| 146 | struct options |
| 147 | { |
Paul Bakker | ef3f8c7 | 2013-06-24 13:01:08 +0200 | [diff] [blame] | 148 | const char *server_name; /* hostname of the server (client only) */ |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 149 | int server_port; /* port on which the ssl service runs */ |
| 150 | int debug_level; /* level of debugging */ |
| 151 | int authentication; /* if authentication is required */ |
| 152 | int mode; /* SSL/TLS (0) or STARTTLS (1) */ |
Paul Bakker | ef3f8c7 | 2013-06-24 13:01:08 +0200 | [diff] [blame] | 153 | const char *user_name; /* username to use for authentication */ |
| 154 | const char *user_pwd; /* password to use for authentication */ |
| 155 | const char *mail_from; /* E-Mail address to use as sender */ |
| 156 | const char *mail_to; /* E-Mail address to use as recipient */ |
| 157 | const char *ca_file; /* the file with the CA certificate(s) */ |
| 158 | const char *crt_file; /* the file with the client certificate */ |
| 159 | const char *key_file; /* the file with the client key */ |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 160 | int force_ciphersuite[2]; /* protocol/ciphersuite to use, or all */ |
| 161 | } opt; |
| 162 | |
Paul Bakker | 3c5ef71 | 2013-06-25 16:37:45 +0200 | [diff] [blame] | 163 | static void my_debug( void *ctx, int level, const char *str ) |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 164 | { |
| 165 | if( level < opt.debug_level ) |
| 166 | { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 167 | polarssl_fprintf( (FILE *) ctx, "%s", str ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 168 | fflush( (FILE *) ctx ); |
| 169 | } |
| 170 | } |
| 171 | |
Paul Bakker | 3c5ef71 | 2013-06-25 16:37:45 +0200 | [diff] [blame] | 172 | static int do_handshake( ssl_context *ssl, struct options *opt ) |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 173 | { |
| 174 | int ret; |
| 175 | unsigned char buf[1024]; |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 176 | memset(buf, 0, 1024); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 177 | |
| 178 | /* |
| 179 | * 4. Handshake |
| 180 | */ |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 181 | polarssl_printf( " . Performing the SSL/TLS handshake..." ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 182 | fflush( stdout ); |
| 183 | |
| 184 | while( ( ret = ssl_handshake( ssl ) ) != 0 ) |
| 185 | { |
| 186 | if( ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE ) |
| 187 | { |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 188 | #if defined(POLARSSL_ERROR_C) |
Paul Bakker | 03a8a79 | 2013-06-30 12:18:08 +0200 | [diff] [blame] | 189 | polarssl_strerror( ret, (char *) buf, 1024 ); |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 190 | #endif |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 191 | polarssl_printf( " failed\n ! ssl_handshake returned %d: %s\n\n", ret, buf ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 192 | return( -1 ); |
| 193 | } |
| 194 | } |
| 195 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 196 | polarssl_printf( " ok\n [ Ciphersuite is %s ]\n", |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 197 | ssl_get_ciphersuite( ssl ) ); |
| 198 | |
| 199 | /* |
| 200 | * 5. Verify the server certificate |
| 201 | */ |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 202 | polarssl_printf( " . Verifying peer X.509 certificate..." ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 203 | |
Manuel Pégourié-Gonnard | fcf2fc2 | 2014-03-11 11:10:27 +0100 | [diff] [blame] | 204 | /* In real life, we may want to bail out when ret != 0 */ |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 205 | if( ( ret = ssl_get_verify_result( ssl ) ) != 0 ) |
| 206 | { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 207 | polarssl_printf( " failed\n" ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 208 | |
| 209 | if( ( ret & BADCERT_EXPIRED ) != 0 ) |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 210 | polarssl_printf( " ! server certificate has expired\n" ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 211 | |
| 212 | if( ( ret & BADCERT_REVOKED ) != 0 ) |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 213 | polarssl_printf( " ! server certificate has been revoked\n" ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 214 | |
| 215 | if( ( ret & BADCERT_CN_MISMATCH ) != 0 ) |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 216 | polarssl_printf( " ! CN mismatch (expected CN=%s)\n", opt->server_name ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 217 | |
| 218 | if( ( ret & BADCERT_NOT_TRUSTED ) != 0 ) |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 219 | polarssl_printf( " ! self-signed or not signed by a trusted CA\n" ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 220 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 221 | polarssl_printf( "\n" ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 222 | } |
| 223 | else |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 224 | polarssl_printf( " ok\n" ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 225 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 226 | polarssl_printf( " . Peer certificate information ...\n" ); |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 227 | x509_crt_info( (char *) buf, sizeof( buf ) - 1, " ", |
| 228 | ssl_get_peer_cert( ssl ) ); |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 229 | polarssl_printf( "%s\n", buf ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 230 | |
| 231 | return( 0 ); |
| 232 | } |
| 233 | |
Paul Bakker | 3c5ef71 | 2013-06-25 16:37:45 +0200 | [diff] [blame] | 234 | static int write_ssl_data( ssl_context *ssl, unsigned char *buf, size_t len ) |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 235 | { |
| 236 | int ret; |
| 237 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 238 | polarssl_printf("\n%s", buf); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 239 | while( len && ( ret = ssl_write( ssl, buf, len ) ) <= 0 ) |
| 240 | { |
| 241 | if( ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE ) |
| 242 | { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 243 | polarssl_printf( " failed\n ! ssl_write returned %d\n\n", ret ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 244 | return -1; |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | return( 0 ); |
| 249 | } |
| 250 | |
Paul Bakker | 3c5ef71 | 2013-06-25 16:37:45 +0200 | [diff] [blame] | 251 | static int write_ssl_and_get_response( ssl_context *ssl, unsigned char *buf, size_t len ) |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 252 | { |
| 253 | int ret; |
| 254 | unsigned char data[128]; |
| 255 | char code[4]; |
| 256 | size_t i, idx = 0; |
| 257 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 258 | polarssl_printf("\n%s", buf); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 259 | while( len && ( ret = ssl_write( ssl, buf, len ) ) <= 0 ) |
| 260 | { |
| 261 | if( ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE ) |
| 262 | { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 263 | polarssl_printf( " failed\n ! ssl_write returned %d\n\n", ret ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 264 | return -1; |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | do |
| 269 | { |
| 270 | len = sizeof( data ) - 1; |
| 271 | memset( data, 0, sizeof( data ) ); |
| 272 | ret = ssl_read( ssl, data, len ); |
| 273 | |
| 274 | if( ret == POLARSSL_ERR_NET_WANT_READ || ret == POLARSSL_ERR_NET_WANT_WRITE ) |
| 275 | continue; |
| 276 | |
| 277 | if( ret == POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY ) |
| 278 | return -1; |
| 279 | |
| 280 | if( ret <= 0 ) |
| 281 | { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 282 | polarssl_printf( "failed\n ! ssl_read returned %d\n\n", ret ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 283 | return -1; |
| 284 | } |
| 285 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 286 | polarssl_printf("\n%s", data); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 287 | len = ret; |
| 288 | for( i = 0; i < len; i++ ) |
| 289 | { |
| 290 | if( data[i] != '\n' ) |
| 291 | { |
| 292 | if( idx < 4 ) |
| 293 | code[ idx++ ] = data[i]; |
| 294 | continue; |
| 295 | } |
| 296 | |
| 297 | if( idx == 4 && code[0] >= '0' && code[0] <= '9' && code[3] == ' ' ) |
| 298 | { |
| 299 | code[3] = '\0'; |
| 300 | return atoi( code ); |
| 301 | } |
Paul Bakker | 3c5ef71 | 2013-06-25 16:37:45 +0200 | [diff] [blame] | 302 | |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 303 | idx = 0; |
| 304 | } |
| 305 | } |
| 306 | while( 1 ); |
| 307 | } |
| 308 | |
Paul Bakker | 3c5ef71 | 2013-06-25 16:37:45 +0200 | [diff] [blame] | 309 | static int write_and_get_response( int sock_fd, unsigned char *buf, size_t len ) |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 310 | { |
| 311 | int ret; |
| 312 | unsigned char data[128]; |
| 313 | char code[4]; |
| 314 | size_t i, idx = 0; |
| 315 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 316 | polarssl_printf("\n%s", buf); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 317 | if( len && ( ret = write( sock_fd, buf, len ) ) <= 0 ) |
| 318 | { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 319 | polarssl_printf( " failed\n ! ssl_write returned %d\n\n", ret ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 320 | return -1; |
| 321 | } |
| 322 | |
| 323 | do |
| 324 | { |
| 325 | len = sizeof( data ) - 1; |
| 326 | memset( data, 0, sizeof( data ) ); |
| 327 | ret = read( sock_fd, data, len ); |
| 328 | |
| 329 | if( ret <= 0 ) |
| 330 | { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 331 | polarssl_printf( "failed\n ! read returned %d\n\n", ret ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 332 | return -1; |
| 333 | } |
| 334 | |
Paul Bakker | df71dd1 | 2014-04-17 16:03:48 +0200 | [diff] [blame] | 335 | data[len] = '\0'; |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 336 | polarssl_printf("\n%s", data); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 337 | len = ret; |
| 338 | for( i = 0; i < len; i++ ) |
| 339 | { |
| 340 | if( data[i] != '\n' ) |
| 341 | { |
| 342 | if( idx < 4 ) |
| 343 | code[ idx++ ] = data[i]; |
| 344 | continue; |
| 345 | } |
| 346 | |
| 347 | if( idx == 4 && code[0] >= '0' && code[0] <= '9' && code[3] == ' ' ) |
| 348 | { |
| 349 | code[3] = '\0'; |
| 350 | return atoi( code ); |
| 351 | } |
Manuel Pégourié-Gonnard | 6c5abfa | 2015-02-13 14:12:07 +0000 | [diff] [blame] | 352 | |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 353 | idx = 0; |
| 354 | } |
| 355 | } |
| 356 | while( 1 ); |
| 357 | } |
| 358 | |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 359 | int main( int argc, char *argv[] ) |
| 360 | { |
| 361 | int ret = 0, len, server_fd; |
Paul Bakker | 09c9dd8 | 2014-08-18 11:06:56 +0200 | [diff] [blame] | 362 | unsigned char buf[1024]; |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 363 | #if defined(POLARSSL_BASE64_C) |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 364 | unsigned char base[1024]; |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 365 | #endif |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 366 | char hostname[32]; |
Paul Bakker | ef3f8c7 | 2013-06-24 13:01:08 +0200 | [diff] [blame] | 367 | const char *pers = "ssl_mail_client"; |
Paul Bakker | 508ad5a | 2011-12-04 17:09:26 +0000 | [diff] [blame] | 368 | |
| 369 | entropy_context entropy; |
| 370 | ctr_drbg_context ctr_drbg; |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 371 | ssl_context ssl; |
Paul Bakker | c559c7a | 2013-09-18 14:13:26 +0200 | [diff] [blame] | 372 | x509_crt cacert; |
| 373 | x509_crt clicert; |
Manuel Pégourié-Gonnard | ac75523 | 2013-08-19 14:10:16 +0200 | [diff] [blame] | 374 | pk_context pkey; |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 375 | int i; |
Paul Bakker | 819370c | 2012-09-28 07:04:41 +0000 | [diff] [blame] | 376 | size_t n; |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 377 | char *p, *q; |
| 378 | const int *list; |
| 379 | |
| 380 | /* |
Manuel Pégourié-Gonnard | 3bd2aae | 2013-09-20 13:10:13 +0200 | [diff] [blame] | 381 | * Make sure memory references are valid in case we exit early. |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 382 | */ |
| 383 | server_fd = 0; |
Manuel Pégourié-Gonnard | 3bd2aae | 2013-09-20 13:10:13 +0200 | [diff] [blame] | 384 | memset( &ssl, 0, sizeof( ssl_context ) ); |
Paul Bakker | 333fdec | 2014-08-04 12:12:09 +0200 | [diff] [blame] | 385 | memset( &buf, 0, sizeof( buf ) ); |
Paul Bakker | 369d2eb | 2013-09-18 11:58:25 +0200 | [diff] [blame] | 386 | x509_crt_init( &cacert ); |
| 387 | x509_crt_init( &clicert ); |
Manuel Pégourié-Gonnard | ac75523 | 2013-08-19 14:10:16 +0200 | [diff] [blame] | 388 | pk_init( &pkey ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 389 | |
| 390 | if( argc == 0 ) |
| 391 | { |
| 392 | usage: |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 393 | polarssl_printf( USAGE ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 394 | |
| 395 | list = ssl_list_ciphersuites(); |
| 396 | while( *list ) |
| 397 | { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 398 | polarssl_printf(" %s\n", ssl_get_ciphersuite_name( *list ) ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 399 | list++; |
| 400 | } |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 401 | polarssl_printf("\n"); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 402 | goto exit; |
| 403 | } |
| 404 | |
| 405 | opt.server_name = DFL_SERVER_NAME; |
| 406 | opt.server_port = DFL_SERVER_PORT; |
| 407 | opt.debug_level = DFL_DEBUG_LEVEL; |
| 408 | opt.authentication = DFL_AUTHENTICATION; |
| 409 | opt.mode = DFL_MODE; |
| 410 | opt.user_name = DFL_USER_NAME; |
| 411 | opt.user_pwd = DFL_USER_PWD; |
| 412 | opt.mail_from = DFL_MAIL_FROM; |
| 413 | opt.mail_to = DFL_MAIL_TO; |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 414 | opt.ca_file = DFL_CA_FILE; |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 415 | opt.crt_file = DFL_CRT_FILE; |
| 416 | opt.key_file = DFL_KEY_FILE; |
| 417 | opt.force_ciphersuite[0]= DFL_FORCE_CIPHER; |
| 418 | |
| 419 | for( i = 1; i < argc; i++ ) |
| 420 | { |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 421 | p = argv[i]; |
| 422 | if( ( q = strchr( p, '=' ) ) == NULL ) |
| 423 | goto usage; |
| 424 | *q++ = '\0'; |
| 425 | |
| 426 | if( strcmp( p, "server_name" ) == 0 ) |
| 427 | opt.server_name = q; |
| 428 | else if( strcmp( p, "server_port" ) == 0 ) |
| 429 | { |
| 430 | opt.server_port = atoi( q ); |
| 431 | if( opt.server_port < 1 || opt.server_port > 65535 ) |
| 432 | goto usage; |
| 433 | } |
| 434 | else if( strcmp( p, "debug_level" ) == 0 ) |
| 435 | { |
| 436 | opt.debug_level = atoi( q ); |
| 437 | if( opt.debug_level < 0 || opt.debug_level > 65535 ) |
| 438 | goto usage; |
| 439 | } |
| 440 | else if( strcmp( p, "authentication" ) == 0 ) |
| 441 | { |
| 442 | opt.authentication = atoi( q ); |
| 443 | if( opt.authentication < 0 || opt.authentication > 1 ) |
| 444 | goto usage; |
| 445 | } |
| 446 | else if( strcmp( p, "mode" ) == 0 ) |
| 447 | { |
| 448 | opt.mode = atoi( q ); |
| 449 | if( opt.mode < 0 || opt.mode > 1 ) |
| 450 | goto usage; |
| 451 | } |
| 452 | else if( strcmp( p, "user_name" ) == 0 ) |
| 453 | opt.user_name = q; |
| 454 | else if( strcmp( p, "user_pwd" ) == 0 ) |
| 455 | opt.user_pwd = q; |
| 456 | else if( strcmp( p, "mail_from" ) == 0 ) |
| 457 | opt.mail_from = q; |
| 458 | else if( strcmp( p, "mail_to" ) == 0 ) |
| 459 | opt.mail_to = q; |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 460 | else if( strcmp( p, "ca_file" ) == 0 ) |
| 461 | opt.ca_file = q; |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 462 | else if( strcmp( p, "crt_file" ) == 0 ) |
| 463 | opt.crt_file = q; |
| 464 | else if( strcmp( p, "key_file" ) == 0 ) |
| 465 | opt.key_file = q; |
| 466 | else if( strcmp( p, "force_ciphersuite" ) == 0 ) |
| 467 | { |
| 468 | opt.force_ciphersuite[0] = -1; |
| 469 | |
| 470 | opt.force_ciphersuite[0] = ssl_get_ciphersuite_id( q ); |
| 471 | |
| 472 | if( opt.force_ciphersuite[0] <= 0 ) |
| 473 | goto usage; |
| 474 | |
| 475 | opt.force_ciphersuite[1] = 0; |
| 476 | } |
| 477 | else |
| 478 | goto usage; |
| 479 | } |
| 480 | |
| 481 | /* |
| 482 | * 0. Initialize the RNG and the session data |
| 483 | */ |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 484 | polarssl_printf( "\n . Seeding the random number generator..." ); |
Paul Bakker | 508ad5a | 2011-12-04 17:09:26 +0000 | [diff] [blame] | 485 | fflush( stdout ); |
| 486 | |
| 487 | entropy_init( &entropy ); |
| 488 | if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy, |
Paul Bakker | ef3f8c7 | 2013-06-24 13:01:08 +0200 | [diff] [blame] | 489 | (const unsigned char *) pers, |
| 490 | strlen( pers ) ) ) != 0 ) |
Paul Bakker | 508ad5a | 2011-12-04 17:09:26 +0000 | [diff] [blame] | 491 | { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 492 | polarssl_printf( " failed\n ! ctr_drbg_init returned %d\n", ret ); |
Paul Bakker | 508ad5a | 2011-12-04 17:09:26 +0000 | [diff] [blame] | 493 | goto exit; |
| 494 | } |
| 495 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 496 | polarssl_printf( " ok\n" ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 497 | |
| 498 | /* |
| 499 | * 1.1. Load the trusted CA |
| 500 | */ |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 501 | polarssl_printf( " . Loading the CA root certificate ..." ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 502 | fflush( stdout ); |
| 503 | |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 504 | #if defined(POLARSSL_FS_IO) |
| 505 | if( strlen( opt.ca_file ) ) |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 506 | ret = x509_crt_parse_file( &cacert, opt.ca_file ); |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 507 | else |
| 508 | #endif |
| 509 | #if defined(POLARSSL_CERTS_C) |
Manuel Pégourié-Gonnard | 641de71 | 2013-09-25 13:23:33 +0200 | [diff] [blame] | 510 | ret = x509_crt_parse( &cacert, (const unsigned char *) test_ca_list, |
| 511 | strlen( test_ca_list ) ); |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 512 | #else |
| 513 | { |
| 514 | ret = 1; |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 515 | polarssl_printf("POLARSSL_CERTS_C not defined."); |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 516 | } |
| 517 | #endif |
Paul Bakker | 4248823 | 2012-05-16 08:21:05 +0000 | [diff] [blame] | 518 | if( ret < 0 ) |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 519 | { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 520 | polarssl_printf( " failed\n ! x509_crt_parse returned %d\n\n", ret ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 521 | goto exit; |
| 522 | } |
| 523 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 524 | polarssl_printf( " ok (%d skipped)\n", ret ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 525 | |
| 526 | /* |
| 527 | * 1.2. Load own certificate and private key |
| 528 | * |
| 529 | * (can be skipped if client authentication is not required) |
| 530 | */ |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 531 | polarssl_printf( " . Loading the client cert. and key..." ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 532 | fflush( stdout ); |
| 533 | |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 534 | #if defined(POLARSSL_FS_IO) |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 535 | if( strlen( opt.crt_file ) ) |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 536 | ret = x509_crt_parse_file( &clicert, opt.crt_file ); |
| 537 | else |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 538 | #endif |
| 539 | #if defined(POLARSSL_CERTS_C) |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 540 | ret = x509_crt_parse( &clicert, (const unsigned char *) test_cli_crt, |
| 541 | strlen( test_cli_crt ) ); |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 542 | #else |
| 543 | { |
Paul Bakker | 69e095c | 2011-12-10 21:55:01 +0000 | [diff] [blame] | 544 | ret = -1; |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 545 | polarssl_printf("POLARSSL_CERTS_C not defined."); |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 546 | } |
| 547 | #endif |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 548 | if( ret != 0 ) |
| 549 | { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 550 | polarssl_printf( " failed\n ! x509_crt_parse returned %d\n\n", ret ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 551 | goto exit; |
| 552 | } |
| 553 | |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 554 | #if defined(POLARSSL_FS_IO) |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 555 | if( strlen( opt.key_file ) ) |
Paul Bakker | 1a7550a | 2013-09-15 13:01:22 +0200 | [diff] [blame] | 556 | ret = pk_parse_keyfile( &pkey, opt.key_file, "" ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 557 | else |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 558 | #endif |
| 559 | #if defined(POLARSSL_CERTS_C) |
Paul Bakker | 1a7550a | 2013-09-15 13:01:22 +0200 | [diff] [blame] | 560 | ret = pk_parse_key( &pkey, (const unsigned char *) test_cli_key, |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 561 | strlen( test_cli_key ), NULL, 0 ); |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 562 | #else |
| 563 | { |
Paul Bakker | 69e095c | 2011-12-10 21:55:01 +0000 | [diff] [blame] | 564 | ret = -1; |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 565 | polarssl_printf("POLARSSL_CERTS_C not defined."); |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 566 | } |
| 567 | #endif |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 568 | if( ret != 0 ) |
| 569 | { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 570 | polarssl_printf( " failed\n ! pk_parse_key returned %d\n\n", ret ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 571 | goto exit; |
| 572 | } |
| 573 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 574 | polarssl_printf( " ok\n" ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 575 | |
| 576 | /* |
| 577 | * 2. Start the connection |
| 578 | */ |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 579 | polarssl_printf( " . Connecting to tcp/%s/%-4d...", opt.server_name, |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 580 | opt.server_port ); |
| 581 | fflush( stdout ); |
| 582 | |
| 583 | if( ( ret = net_connect( &server_fd, opt.server_name, |
| 584 | opt.server_port ) ) != 0 ) |
| 585 | { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 586 | polarssl_printf( " failed\n ! net_connect returned %d\n\n", ret ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 587 | goto exit; |
| 588 | } |
| 589 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 590 | polarssl_printf( " ok\n" ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 591 | |
| 592 | /* |
| 593 | * 3. Setup stuff |
| 594 | */ |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 595 | polarssl_printf( " . Setting up the SSL/TLS structure..." ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 596 | fflush( stdout ); |
| 597 | |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 598 | if( ( ret = ssl_init( &ssl ) ) != 0 ) |
| 599 | { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 600 | polarssl_printf( " failed\n ! ssl_init returned %d\n\n", ret ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 601 | goto exit; |
| 602 | } |
| 603 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 604 | polarssl_printf( " ok\n" ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 605 | |
| 606 | ssl_set_endpoint( &ssl, SSL_IS_CLIENT ); |
Manuel Pégourié-Gonnard | fcf2fc2 | 2014-03-11 11:10:27 +0100 | [diff] [blame] | 607 | /* OPTIONAL is not optimal for security, |
| 608 | * but makes interop easier in this simplified example */ |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 609 | ssl_set_authmode( &ssl, SSL_VERIFY_OPTIONAL ); |
| 610 | |
Manuel Pégourié-Gonnard | 448ea50 | 2015-01-12 11:40:14 +0100 | [diff] [blame] | 611 | /* SSLv3 is deprecated, set minimum to TLS 1.0 */ |
| 612 | ssl_set_min_version( &ssl, SSL_MAJOR_VERSION_3, SSL_MINOR_VERSION_1 ); |
Manuel Pégourié-Gonnard | fa06581 | 2015-01-12 14:05:33 +0100 | [diff] [blame] | 613 | /* RC4 is deprecated, disable it */ |
| 614 | ssl_set_arc4_support( &ssl, SSL_ARC4_DISABLED ); |
Manuel Pégourié-Gonnard | 448ea50 | 2015-01-12 11:40:14 +0100 | [diff] [blame] | 615 | |
Paul Bakker | 508ad5a | 2011-12-04 17:09:26 +0000 | [diff] [blame] | 616 | ssl_set_rng( &ssl, ctr_drbg_random, &ctr_drbg ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 617 | ssl_set_dbg( &ssl, my_debug, stdout ); |
| 618 | ssl_set_bio( &ssl, net_recv, &server_fd, |
| 619 | net_send, &server_fd ); |
| 620 | |
Paul Bakker | 645ce3a | 2012-10-31 12:32:41 +0000 | [diff] [blame] | 621 | if( opt.force_ciphersuite[0] != DFL_FORCE_CIPHER ) |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 622 | ssl_set_ciphersuites( &ssl, opt.force_ciphersuite ); |
| 623 | |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 624 | ssl_set_ca_chain( &ssl, &cacert, NULL, opt.server_name ); |
Manuel Pégourié-Gonnard | c5fd391 | 2014-07-08 14:05:52 +0200 | [diff] [blame] | 625 | if( ( ret = ssl_set_own_cert( &ssl, &clicert, &pkey ) ) != 0 ) |
| 626 | { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 627 | polarssl_printf( " failed\n ! ssl_set_own_cert returned %d\n\n", ret ); |
Manuel Pégourié-Gonnard | c5fd391 | 2014-07-08 14:05:52 +0200 | [diff] [blame] | 628 | goto exit; |
| 629 | } |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 630 | |
Paul Bakker | 0be444a | 2013-08-27 21:55:01 +0200 | [diff] [blame] | 631 | #if defined(POLARSSL_SSL_SERVER_NAME_INDICATION) |
Manuel Pégourié-Gonnard | c5fd391 | 2014-07-08 14:05:52 +0200 | [diff] [blame] | 632 | if( ( ret = ssl_set_hostname( &ssl, opt.server_name ) ) != 0 ) |
| 633 | { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 634 | polarssl_printf( " failed\n ! ssl_set_hostname returned %d\n\n", ret ); |
Manuel Pégourié-Gonnard | c5fd391 | 2014-07-08 14:05:52 +0200 | [diff] [blame] | 635 | goto exit; |
| 636 | } |
Paul Bakker | 0be444a | 2013-08-27 21:55:01 +0200 | [diff] [blame] | 637 | #endif |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 638 | |
| 639 | if( opt.mode == MODE_SSL_TLS ) |
| 640 | { |
| 641 | if( do_handshake( &ssl, &opt ) != 0 ) |
| 642 | goto exit; |
| 643 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 644 | polarssl_printf( " > Get header from server:" ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 645 | fflush( stdout ); |
| 646 | |
| 647 | ret = write_ssl_and_get_response( &ssl, buf, 0 ); |
| 648 | if( ret < 200 || ret > 299 ) |
| 649 | { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 650 | polarssl_printf( " failed\n ! server responded with %d\n\n", ret ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 651 | goto exit; |
| 652 | } |
| 653 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 654 | polarssl_printf(" ok\n" ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 655 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 656 | polarssl_printf( " > Write EHLO to server:" ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 657 | fflush( stdout ); |
| 658 | |
| 659 | gethostname( hostname, 32 ); |
Paul Bakker | d75ba40 | 2014-01-24 16:11:17 +0100 | [diff] [blame] | 660 | len = sprintf( (char *) buf, "EHLO %s\r\n", hostname ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 661 | ret = write_ssl_and_get_response( &ssl, buf, len ); |
| 662 | if( ret < 200 || ret > 299 ) |
| 663 | { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 664 | polarssl_printf( " failed\n ! server responded with %d\n\n", ret ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 665 | goto exit; |
| 666 | } |
| 667 | } |
| 668 | else |
| 669 | { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 670 | polarssl_printf( " > Get header from server:" ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 671 | fflush( stdout ); |
| 672 | |
| 673 | ret = write_and_get_response( server_fd, buf, 0 ); |
| 674 | if( ret < 200 || ret > 299 ) |
| 675 | { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 676 | polarssl_printf( " failed\n ! server responded with %d\n\n", ret ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 677 | goto exit; |
| 678 | } |
| 679 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 680 | polarssl_printf(" ok\n" ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 681 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 682 | polarssl_printf( " > Write EHLO to server:" ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 683 | fflush( stdout ); |
| 684 | |
| 685 | gethostname( hostname, 32 ); |
Paul Bakker | d75ba40 | 2014-01-24 16:11:17 +0100 | [diff] [blame] | 686 | len = sprintf( (char *) buf, "EHLO %s\r\n", hostname ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 687 | ret = write_and_get_response( server_fd, buf, len ); |
| 688 | if( ret < 200 || ret > 299 ) |
| 689 | { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 690 | polarssl_printf( " failed\n ! server responded with %d\n\n", ret ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 691 | goto exit; |
| 692 | } |
| 693 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 694 | polarssl_printf(" ok\n" ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 695 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 696 | polarssl_printf( " > Write STARTTLS to server:" ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 697 | fflush( stdout ); |
| 698 | |
| 699 | gethostname( hostname, 32 ); |
Paul Bakker | d75ba40 | 2014-01-24 16:11:17 +0100 | [diff] [blame] | 700 | len = sprintf( (char *) buf, "STARTTLS\r\n" ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 701 | ret = write_and_get_response( server_fd, buf, len ); |
| 702 | if( ret < 200 || ret > 299 ) |
| 703 | { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 704 | polarssl_printf( " failed\n ! server responded with %d\n\n", ret ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 705 | goto exit; |
| 706 | } |
| 707 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 708 | polarssl_printf(" ok\n" ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 709 | |
| 710 | if( do_handshake( &ssl, &opt ) != 0 ) |
| 711 | goto exit; |
| 712 | } |
| 713 | |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 714 | #if defined(POLARSSL_BASE64_C) |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 715 | if( opt.authentication ) |
| 716 | { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 717 | polarssl_printf( " > Write AUTH LOGIN to server:" ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 718 | fflush( stdout ); |
| 719 | |
Paul Bakker | d75ba40 | 2014-01-24 16:11:17 +0100 | [diff] [blame] | 720 | len = sprintf( (char *) buf, "AUTH LOGIN\r\n" ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 721 | ret = write_ssl_and_get_response( &ssl, buf, len ); |
| 722 | if( ret < 200 || ret > 399 ) |
| 723 | { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 724 | polarssl_printf( " failed\n ! server responded with %d\n\n", ret ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 725 | goto exit; |
| 726 | } |
| 727 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 728 | polarssl_printf(" ok\n" ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 729 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 730 | polarssl_printf( " > Write username to server: %s", opt.user_name ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 731 | fflush( stdout ); |
| 732 | |
| 733 | n = sizeof( buf ); |
Alfred Klomp | 7c03424 | 2014-07-14 22:11:13 +0200 | [diff] [blame] | 734 | ret = base64_encode( base, &n, (const unsigned char *) opt.user_name, |
Paul Bakker | ef3f8c7 | 2013-06-24 13:01:08 +0200 | [diff] [blame] | 735 | strlen( opt.user_name ) ); |
Alfred Klomp | 7c03424 | 2014-07-14 22:11:13 +0200 | [diff] [blame] | 736 | |
| 737 | if( ret != 0 ) { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 738 | polarssl_printf( " failed\n ! base64_encode returned %d\n\n", ret ); |
Alfred Klomp | 7c03424 | 2014-07-14 22:11:13 +0200 | [diff] [blame] | 739 | goto exit; |
| 740 | } |
Paul Bakker | d75ba40 | 2014-01-24 16:11:17 +0100 | [diff] [blame] | 741 | len = sprintf( (char *) buf, "%s\r\n", base ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 742 | ret = write_ssl_and_get_response( &ssl, buf, len ); |
| 743 | if( ret < 300 || ret > 399 ) |
| 744 | { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 745 | polarssl_printf( " failed\n ! server responded with %d\n\n", ret ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 746 | goto exit; |
| 747 | } |
| 748 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 749 | polarssl_printf(" ok\n" ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 750 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 751 | polarssl_printf( " > Write password to server: %s", opt.user_pwd ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 752 | fflush( stdout ); |
| 753 | |
Alfred Klomp | 7c03424 | 2014-07-14 22:11:13 +0200 | [diff] [blame] | 754 | ret = base64_encode( base, &n, (const unsigned char *) opt.user_pwd, |
Paul Bakker | ef3f8c7 | 2013-06-24 13:01:08 +0200 | [diff] [blame] | 755 | strlen( opt.user_pwd ) ); |
Alfred Klomp | 7c03424 | 2014-07-14 22:11:13 +0200 | [diff] [blame] | 756 | |
| 757 | if( ret != 0 ) { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 758 | polarssl_printf( " failed\n ! base64_encode returned %d\n\n", ret ); |
Alfred Klomp | 7c03424 | 2014-07-14 22:11:13 +0200 | [diff] [blame] | 759 | goto exit; |
| 760 | } |
Paul Bakker | d75ba40 | 2014-01-24 16:11:17 +0100 | [diff] [blame] | 761 | len = sprintf( (char *) buf, "%s\r\n", base ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 762 | ret = write_ssl_and_get_response( &ssl, buf, len ); |
| 763 | if( ret < 200 || ret > 399 ) |
| 764 | { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 765 | polarssl_printf( " failed\n ! server responded with %d\n\n", ret ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 766 | goto exit; |
| 767 | } |
| 768 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 769 | polarssl_printf(" ok\n" ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 770 | } |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 771 | #endif |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 772 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 773 | polarssl_printf( " > Write MAIL FROM to server:" ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 774 | fflush( stdout ); |
| 775 | |
Paul Bakker | d75ba40 | 2014-01-24 16:11:17 +0100 | [diff] [blame] | 776 | len = sprintf( (char *) buf, "MAIL FROM:<%s>\r\n", opt.mail_from ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 777 | ret = write_ssl_and_get_response( &ssl, buf, len ); |
| 778 | if( ret < 200 || ret > 299 ) |
| 779 | { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 780 | polarssl_printf( " failed\n ! server responded with %d\n\n", ret ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 781 | goto exit; |
| 782 | } |
| 783 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 784 | polarssl_printf(" ok\n" ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 785 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 786 | polarssl_printf( " > Write RCPT TO to server:" ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 787 | fflush( stdout ); |
| 788 | |
Paul Bakker | d75ba40 | 2014-01-24 16:11:17 +0100 | [diff] [blame] | 789 | len = sprintf( (char *) buf, "RCPT TO:<%s>\r\n", opt.mail_to ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 790 | ret = write_ssl_and_get_response( &ssl, buf, len ); |
| 791 | if( ret < 200 || ret > 299 ) |
| 792 | { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 793 | polarssl_printf( " failed\n ! server responded with %d\n\n", ret ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 794 | goto exit; |
| 795 | } |
| 796 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 797 | polarssl_printf(" ok\n" ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 798 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 799 | polarssl_printf( " > Write DATA to server:" ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 800 | fflush( stdout ); |
| 801 | |
Paul Bakker | d75ba40 | 2014-01-24 16:11:17 +0100 | [diff] [blame] | 802 | len = sprintf( (char *) buf, "DATA\r\n" ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 803 | ret = write_ssl_and_get_response( &ssl, buf, len ); |
| 804 | if( ret < 300 || ret > 399 ) |
| 805 | { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 806 | polarssl_printf( " failed\n ! server responded with %d\n\n", ret ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 807 | goto exit; |
| 808 | } |
| 809 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 810 | polarssl_printf(" ok\n" ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 811 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 812 | polarssl_printf( " > Write content to server:" ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 813 | fflush( stdout ); |
| 814 | |
Manuel Pégourié-Gonnard | 9169921 | 2015-01-22 16:26:39 +0000 | [diff] [blame] | 815 | len = sprintf( (char *) buf, "From: %s\r\nSubject: mbed TLS Test mail\r\n\r\n" |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 816 | "This is a simple test mail from the " |
Manuel Pégourié-Gonnard | 9169921 | 2015-01-22 16:26:39 +0000 | [diff] [blame] | 817 | "mbed TLS mail client example.\r\n" |
Paul Bakker | d75ba40 | 2014-01-24 16:11:17 +0100 | [diff] [blame] | 818 | "\r\n" |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 819 | "Enjoy!", opt.mail_from ); |
| 820 | ret = write_ssl_data( &ssl, buf, len ); |
| 821 | |
| 822 | len = sprintf( (char *) buf, "\r\n.\r\n"); |
| 823 | ret = write_ssl_and_get_response( &ssl, buf, len ); |
| 824 | if( ret < 200 || ret > 299 ) |
| 825 | { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 826 | polarssl_printf( " failed\n ! server responded with %d\n\n", ret ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 827 | goto exit; |
| 828 | } |
| 829 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 830 | polarssl_printf(" ok\n" ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 831 | |
| 832 | ssl_close_notify( &ssl ); |
| 833 | |
| 834 | exit: |
| 835 | |
| 836 | if( server_fd ) |
| 837 | net_close( server_fd ); |
Paul Bakker | 36713e8 | 2013-09-17 13:25:29 +0200 | [diff] [blame] | 838 | x509_crt_free( &clicert ); |
| 839 | x509_crt_free( &cacert ); |
Manuel Pégourié-Gonnard | ac75523 | 2013-08-19 14:10:16 +0200 | [diff] [blame] | 840 | pk_free( &pkey ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 841 | ssl_free( &ssl ); |
Paul Bakker | a317a98 | 2014-06-18 16:44:11 +0200 | [diff] [blame] | 842 | ctr_drbg_free( &ctr_drbg ); |
Paul Bakker | 1ffefac | 2013-09-28 15:23:03 +0200 | [diff] [blame] | 843 | entropy_free( &entropy ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 844 | |
Paul Bakker | cce9d77 | 2011-11-18 14:26:47 +0000 | [diff] [blame] | 845 | #if defined(_WIN32) |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 846 | polarssl_printf( " + Press Enter to exit this program.\n" ); |
Paul Bakker | 1496d38 | 2011-05-23 12:07:29 +0000 | [diff] [blame] | 847 | fflush( stdout ); getchar(); |
| 848 | #endif |
| 849 | |
| 850 | return( ret ); |
| 851 | } |
Paul Bakker | 508ad5a | 2011-12-04 17:09:26 +0000 | [diff] [blame] | 852 | #endif /* POLARSSL_BIGNUM_C && POLARSSL_ENTROPY_C && POLARSSL_SSL_TLS_C && |
| 853 | POLARSSL_SSL_CLI_C && POLARSSL_NET_C && POLARSSL_RSA_C ** |
| 854 | POLARSSL_CTR_DRBG_C */ |