| Paul Bakker | 4593aea | 2009-02-09 22:32:35 +0000 | [diff] [blame] | 1 | /* | 
|  | 2 | *  SSL certificate functionality tests | 
|  | 3 | * | 
| Manuel Pégourié-Gonnard | a658a40 | 2015-01-23 09:45:19 +0000 | [diff] [blame] | 4 | *  Copyright (C) 2006-2011, ARM Limited, All Rights Reserved | 
| Paul Bakker | b96f154 | 2010-07-18 20:36:00 +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 | b96f154 | 2010-07-18 20:36:00 +0000 | [diff] [blame] | 7 | * | 
| Paul Bakker | 4593aea | 2009-02-09 22:32:35 +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 | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 23 | #if !defined(MBEDTLS_CONFIG_FILE) | 
| Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 24 | #include "mbedtls/config.h" | 
| Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 25 | #else | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 26 | #include MBEDTLS_CONFIG_FILE | 
| Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 27 | #endif | 
| Paul Bakker | 4593aea | 2009-02-09 22:32:35 +0000 | [diff] [blame] | 28 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 29 | #if defined(MBEDTLS_PLATFORM_C) | 
| Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 30 | #include "mbedtls/platform.h" | 
| Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 31 | #else | 
| Rich Evans | 18b78c7 | 2015-02-11 14:06:19 +0000 | [diff] [blame] | 32 | #include <stdio.h> | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 33 | #define mbedtls_snprintf   snprintf | 
|  | 34 | #define mbedtls_printf     printf | 
|  | 35 | #define mbedtls_snprintf   snprintf | 
| Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 36 | #endif | 
|  | 37 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 38 | #if defined(MBEDTLS_RSA_C) && defined(MBEDTLS_X509_CRT_PARSE_C) && \ | 
|  | 39 | defined(MBEDTLS_FS_IO) && defined(MBEDTLS_X509_CRL_PARSE_C) | 
| Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 40 | #include "mbedtls/certs.h" | 
|  | 41 | #include "mbedtls/x509_crt.h" | 
| Rich Evans | 18b78c7 | 2015-02-11 14:06:19 +0000 | [diff] [blame] | 42 |  | 
| Paul Bakker | 4593aea | 2009-02-09 22:32:35 +0000 | [diff] [blame] | 43 | #include <stdio.h> | 
| Rich Evans | 18b78c7 | 2015-02-11 14:06:19 +0000 | [diff] [blame] | 44 | #include <string.h> | 
|  | 45 | #endif | 
|  | 46 |  | 
|  | 47 | #if defined _MSC_VER && !defined snprintf | 
|  | 48 | #define snprintf _snprintf | 
|  | 49 | #endif | 
|  | 50 |  | 
|  | 51 | #define MAX_CLIENT_CERTS    8 | 
| Paul Bakker | 4593aea | 2009-02-09 22:32:35 +0000 | [diff] [blame] | 52 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 53 | #if !defined(MBEDTLS_RSA_C) || !defined(MBEDTLS_X509_CRT_PARSE_C) || \ | 
|  | 54 | !defined(MBEDTLS_FS_IO) || !defined(MBEDTLS_X509_CRL_PARSE_C) | 
| Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 55 | int main( void ) | 
| Manuel Pégourié-Gonnard | 7831b0c | 2013-09-20 12:29:56 +0200 | [diff] [blame] | 56 | { | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 57 | mbedtls_printf("MBEDTLS_RSA_C and/or MBEDTLS_X509_CRT_PARSE_C " | 
|  | 58 | "MBEDTLS_FS_IO and/or MBEDTLS_X509_CRL_PARSE_C " | 
| Manuel Pégourié-Gonnard | 7831b0c | 2013-09-20 12:29:56 +0200 | [diff] [blame] | 59 | "not defined.\n"); | 
|  | 60 | return( 0 ); | 
|  | 61 | } | 
|  | 62 | #else | 
| Paul Bakker | ef3f8c7 | 2013-06-24 13:01:08 +0200 | [diff] [blame] | 63 | const char *client_certificates[MAX_CLIENT_CERTS] = | 
| Paul Bakker | 4593aea | 2009-02-09 22:32:35 +0000 | [diff] [blame] | 64 | { | 
| Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 65 | "client1.crt", | 
|  | 66 | "client2.crt", | 
| Paul Bakker | 40ea7de | 2009-05-03 10:18:48 +0000 | [diff] [blame] | 67 | "server1.crt", | 
|  | 68 | "server2.crt", | 
| Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 69 | "cert_sha224.crt", | 
|  | 70 | "cert_sha256.crt", | 
|  | 71 | "cert_sha384.crt", | 
|  | 72 | "cert_sha512.crt" | 
| Paul Bakker | 4593aea | 2009-02-09 22:32:35 +0000 | [diff] [blame] | 73 | }; | 
|  | 74 |  | 
| Paul Bakker | ef3f8c7 | 2013-06-24 13:01:08 +0200 | [diff] [blame] | 75 | const char *client_private_keys[MAX_CLIENT_CERTS] = | 
| Paul Bakker | a1d3e5f | 2009-03-28 17:30:26 +0000 | [diff] [blame] | 76 | { | 
| Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 77 | "client1.key", | 
|  | 78 | "client2.key", | 
| Paul Bakker | 40ea7de | 2009-05-03 10:18:48 +0000 | [diff] [blame] | 79 | "server1.key", | 
|  | 80 | "server2.key", | 
| Paul Bakker | f17ed28 | 2011-02-09 17:10:48 +0000 | [diff] [blame] | 81 | "cert_digest.key", | 
|  | 82 | "cert_digest.key", | 
|  | 83 | "cert_digest.key", | 
|  | 84 | "cert_digest.key" | 
| Paul Bakker | a1d3e5f | 2009-03-28 17:30:26 +0000 | [diff] [blame] | 85 | }; | 
|  | 86 |  | 
| Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 87 | int main( void ) | 
| Paul Bakker | 4593aea | 2009-02-09 22:32:35 +0000 | [diff] [blame] | 88 | { | 
|  | 89 | int ret, i; | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 90 | mbedtls_x509_crt cacert; | 
|  | 91 | mbedtls_x509_crl crl; | 
| Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 92 | char buf[10240]; | 
|  | 93 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 94 | mbedtls_x509_crt_init( &cacert ); | 
|  | 95 | mbedtls_x509_crl_init( &crl ); | 
| Paul Bakker | 4593aea | 2009-02-09 22:32:35 +0000 | [diff] [blame] | 96 |  | 
|  | 97 | /* | 
|  | 98 | * 1.1. Load the trusted CA | 
|  | 99 | */ | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 100 | mbedtls_printf( "\n  . Loading the CA root certificate ..." ); | 
| Paul Bakker | 4593aea | 2009-02-09 22:32:35 +0000 | [diff] [blame] | 101 | fflush( stdout ); | 
|  | 102 |  | 
| Paul Bakker | 4593aea | 2009-02-09 22:32:35 +0000 | [diff] [blame] | 103 | /* | 
|  | 104 | * Alternatively, you may load the CA certificates from a .pem or | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 105 | * .crt file by calling mbedtls_x509_crt_parse_file( &cacert, "myca.crt" ). | 
| Paul Bakker | 4593aea | 2009-02-09 22:32:35 +0000 | [diff] [blame] | 106 | */ | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 107 | ret = mbedtls_x509_crt_parse_file( &cacert, "ssl/test-ca/test-ca.crt" ); | 
| Paul Bakker | 4593aea | 2009-02-09 22:32:35 +0000 | [diff] [blame] | 108 | if( ret != 0 ) | 
|  | 109 | { | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 110 | mbedtls_printf( " failed\n  !  mbedtls_x509_crt_parse_file returned %d\n\n", ret ); | 
| Paul Bakker | 4593aea | 2009-02-09 22:32:35 +0000 | [diff] [blame] | 111 | goto exit; | 
|  | 112 | } | 
|  | 113 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 114 | mbedtls_printf( " ok\n" ); | 
| Paul Bakker | 4593aea | 2009-02-09 22:32:35 +0000 | [diff] [blame] | 115 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 116 | mbedtls_x509_crt_info( buf, 1024, "CRT: ", &cacert ); | 
|  | 117 | mbedtls_printf("%s\n", buf ); | 
| Paul Bakker | 40ea7de | 2009-05-03 10:18:48 +0000 | [diff] [blame] | 118 |  | 
| Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 119 | /* | 
|  | 120 | * 1.2. Load the CRL | 
|  | 121 | */ | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 122 | mbedtls_printf( "  . Loading the CRL ..." ); | 
| Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 123 | fflush( stdout ); | 
|  | 124 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 125 | ret = mbedtls_x509_crl_parse_file( &crl, "ssl/test-ca/crl.pem" ); | 
| Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 126 | if( ret != 0 ) | 
|  | 127 | { | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 128 | mbedtls_printf( " failed\n  !  mbedtls_x509_crl_parse_file returned %d\n\n", ret ); | 
| Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 129 | goto exit; | 
|  | 130 | } | 
|  | 131 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 132 | mbedtls_printf( " ok\n" ); | 
| Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 133 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 134 | mbedtls_x509_crl_info( buf, 1024, "CRL: ", &crl ); | 
|  | 135 | mbedtls_printf("%s\n", buf ); | 
| Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 136 |  | 
| Paul Bakker | 4593aea | 2009-02-09 22:32:35 +0000 | [diff] [blame] | 137 | for( i = 0; i < MAX_CLIENT_CERTS; i++ ) | 
|  | 138 | { | 
|  | 139 | /* | 
| Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 140 | * 1.3. Load own certificate | 
| Paul Bakker | 4593aea | 2009-02-09 22:32:35 +0000 | [diff] [blame] | 141 | */ | 
| Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 142 | char    name[512]; | 
|  | 143 | int flags; | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 144 | mbedtls_x509_crt clicert; | 
|  | 145 | mbedtls_pk_context pk; | 
| Paul Bakker | 4593aea | 2009-02-09 22:32:35 +0000 | [diff] [blame] | 146 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 147 | mbedtls_x509_crt_init( &clicert ); | 
|  | 148 | mbedtls_pk_init( &pk ); | 
| Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 149 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 150 | mbedtls_snprintf(name, 512, "ssl/test-ca/%s", client_certificates[i]); | 
| Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 151 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 152 | mbedtls_printf( "  . Loading the client certificate %s...", name ); | 
| Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 153 | fflush( stdout ); | 
| Paul Bakker | 4593aea | 2009-02-09 22:32:35 +0000 | [diff] [blame] | 154 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 155 | ret = mbedtls_x509_crt_parse_file( &clicert, name ); | 
| Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 156 | if( ret != 0 ) | 
|  | 157 | { | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 158 | mbedtls_printf( " failed\n  !  mbedtls_x509_crt_parse_file returned %d\n\n", ret ); | 
| Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 159 | goto exit; | 
|  | 160 | } | 
| Paul Bakker | 4593aea | 2009-02-09 22:32:35 +0000 | [diff] [blame] | 161 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 162 | mbedtls_printf( " ok\n" ); | 
| Paul Bakker | a1d3e5f | 2009-03-28 17:30:26 +0000 | [diff] [blame] | 163 |  | 
|  | 164 | /* | 
| Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 165 | * 1.4. Verify certificate validity with CA certificate | 
| Paul Bakker | a1d3e5f | 2009-03-28 17:30:26 +0000 | [diff] [blame] | 166 | */ | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 167 | mbedtls_printf( "  . Verify the client certificate with CA certificate..." ); | 
| Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 168 | fflush( stdout ); | 
|  | 169 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 170 | ret = mbedtls_x509_crt_verify( &clicert, &cacert, &crl, NULL, &flags, NULL, | 
| Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 171 | NULL ); | 
| Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 172 | if( ret != 0 ) | 
|  | 173 | { | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 174 | if( ret == MBEDTLS_ERR_X509_CERT_VERIFY_FAILED ) | 
| Paul Bakker | 40ea7de | 2009-05-03 10:18:48 +0000 | [diff] [blame] | 175 | { | 
| Manuel Pégourié-Gonnard | 89addc4 | 2015-04-20 10:56:18 +0100 | [diff] [blame] | 176 | char vrfy_buf[512]; | 
|  | 177 |  | 
|  | 178 | mbedtls_printf( " failed\n" ); | 
| Manuel Pégourié-Gonnard | da61ed3 | 2015-04-30 10:28:51 +0200 | [diff] [blame] | 179 | mbedtls_x509_crt_verify_info( vrfy_buf, sizeof( vrfy_buf ), "  ! ", flags ); | 
| Manuel Pégourié-Gonnard | 89addc4 | 2015-04-20 10:56:18 +0100 | [diff] [blame] | 180 | mbedtls_printf( "%s\n", vrfy_buf ); | 
|  | 181 | } | 
|  | 182 | else | 
|  | 183 | { | 
| Manuel Pégourié-Gonnard | da61ed3 | 2015-04-30 10:28:51 +0200 | [diff] [blame] | 184 | mbedtls_printf( " failed\n  !  mbedtls_x509_crt_verify returned %d\n\n", ret ); | 
| Paul Bakker | 40ea7de | 2009-05-03 10:18:48 +0000 | [diff] [blame] | 185 | goto exit; | 
|  | 186 | } | 
| Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 187 | } | 
|  | 188 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 189 | mbedtls_printf( " ok\n" ); | 
| Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 190 |  | 
|  | 191 | /* | 
|  | 192 | * 1.5. Load own private key | 
|  | 193 | */ | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 194 | mbedtls_snprintf(name, 512, "ssl/test-ca/%s", client_private_keys[i]); | 
| Paul Bakker | a1d3e5f | 2009-03-28 17:30:26 +0000 | [diff] [blame] | 195 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 196 | mbedtls_printf( "  . Loading the client private key %s...", name ); | 
| Paul Bakker | a1d3e5f | 2009-03-28 17:30:26 +0000 | [diff] [blame] | 197 | fflush( stdout ); | 
|  | 198 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 199 | ret = mbedtls_pk_parse_keyfile( &pk, name, NULL ); | 
| Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 200 | if( ret != 0 ) | 
|  | 201 | { | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 202 | mbedtls_printf( " failed\n  !  mbedtls_pk_parse_keyfile returned %d\n\n", ret ); | 
| Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 203 | goto exit; | 
|  | 204 | } | 
| Paul Bakker | a1d3e5f | 2009-03-28 17:30:26 +0000 | [diff] [blame] | 205 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 206 | mbedtls_printf( " ok\n" ); | 
| Paul Bakker | a1d3e5f | 2009-03-28 17:30:26 +0000 | [diff] [blame] | 207 |  | 
| Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 208 | /* | 
| Manuel Pégourié-Gonnard | be50680 | 2013-07-11 13:17:21 +0200 | [diff] [blame] | 209 | * 1.6. Verify certificate validity with private key | 
| Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 210 | */ | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 211 | mbedtls_printf( "  . Verify the client certificate with private key..." ); | 
| Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 212 | fflush( stdout ); | 
| Paul Bakker | a1d3e5f | 2009-03-28 17:30:26 +0000 | [diff] [blame] | 213 |  | 
| Manuel Pégourié-Gonnard | be50680 | 2013-07-11 13:17:21 +0200 | [diff] [blame] | 214 |  | 
|  | 215 | /* EC NOT IMPLEMENTED YET */ | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 216 | if( ! mbedtls_pk_can_do( &clicert.pk, MBEDTLS_PK_RSA ) ) | 
| Manuel Pégourié-Gonnard | be50680 | 2013-07-11 13:17:21 +0200 | [diff] [blame] | 217 | { | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 218 | mbedtls_printf( " failed\n  !  certificate's key is not RSA\n\n" ); | 
|  | 219 | ret = MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE; | 
| Manuel Pégourié-Gonnard | be50680 | 2013-07-11 13:17:21 +0200 | [diff] [blame] | 220 | goto exit; | 
|  | 221 | } | 
|  | 222 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 223 | ret = mbedtls_mpi_cmp_mpi(&mbedtls_pk_rsa( pk )->N, &mbedtls_pk_rsa( clicert.pk )->N); | 
| Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 224 | if( ret != 0 ) | 
|  | 225 | { | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 226 | mbedtls_printf( " failed\n  !  mbedtls_mpi_cmp_mpi for N returned %d\n\n", ret ); | 
| Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 227 | goto exit; | 
|  | 228 | } | 
| Paul Bakker | a1d3e5f | 2009-03-28 17:30:26 +0000 | [diff] [blame] | 229 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 230 | ret = mbedtls_mpi_cmp_mpi(&mbedtls_pk_rsa( pk )->E, &mbedtls_pk_rsa( clicert.pk )->E); | 
| Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 231 | if( ret != 0 ) | 
|  | 232 | { | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 233 | mbedtls_printf( " failed\n  !  mbedtls_mpi_cmp_mpi for E returned %d\n\n", ret ); | 
| Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 234 | goto exit; | 
|  | 235 | } | 
| Paul Bakker | a1d3e5f | 2009-03-28 17:30:26 +0000 | [diff] [blame] | 236 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 237 | ret = mbedtls_rsa_check_privkey( mbedtls_pk_rsa( pk ) ); | 
| Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 238 | if( ret != 0 ) | 
|  | 239 | { | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 240 | mbedtls_printf( " failed\n  !  mbedtls_rsa_check_privkey returned %d\n\n", ret ); | 
| Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 241 | goto exit; | 
|  | 242 | } | 
| Paul Bakker | a1d3e5f | 2009-03-28 17:30:26 +0000 | [diff] [blame] | 243 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 244 | mbedtls_printf( " ok\n" ); | 
| Paul Bakker | a1d3e5f | 2009-03-28 17:30:26 +0000 | [diff] [blame] | 245 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 246 | mbedtls_x509_crt_free( &clicert ); | 
|  | 247 | mbedtls_pk_free( &pk ); | 
| Paul Bakker | 4593aea | 2009-02-09 22:32:35 +0000 | [diff] [blame] | 248 | } | 
|  | 249 |  | 
|  | 250 | exit: | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 251 | mbedtls_x509_crt_free( &cacert ); | 
|  | 252 | mbedtls_x509_crl_free( &crl ); | 
| Paul Bakker | 4593aea | 2009-02-09 22:32:35 +0000 | [diff] [blame] | 253 |  | 
| Paul Bakker | cce9d77 | 2011-11-18 14:26:47 +0000 | [diff] [blame] | 254 | #if defined(_WIN32) | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 255 | mbedtls_printf( "  + Press Enter to exit this program.\n" ); | 
| Paul Bakker | 4593aea | 2009-02-09 22:32:35 +0000 | [diff] [blame] | 256 | fflush( stdout ); getchar(); | 
|  | 257 | #endif | 
|  | 258 |  | 
|  | 259 | return( ret ); | 
|  | 260 | } | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 261 | #endif /* MBEDTLS_RSA_C && MBEDTLS_X509_CRT_PARSE_C && MBEDTLS_FS_IO && | 
|  | 262 | MBEDTLS_X509_CRL_PARSE_C */ |