From 893879adbd7d00939b2dbb7d31060d9196aab821 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Thu, 11 Jul 2013 10:31:57 +0200 Subject: [PATCH] Adapt debug_print_crt() for EC keys --- library/debug.c | 24 ++++++++++++++++++++---- tests/data_files/test-ca2.crt | Bin 0 -> 238 bytes tests/data_files/test-ca2.key | 8 ++++++++ tests/suites/test_suite_debug.data | 6 +++++- 4 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 tests/data_files/test-ca2.crt create mode 100644 tests/data_files/test-ca2.key diff --git a/library/debug.c b/library/debug.c index 23b901996..b6babe6fc 100644 --- a/library/debug.c +++ b/library/debug.c @@ -250,11 +250,27 @@ void debug_print_crt( const ssl_context *ssl, int level, str[maxlen] = '\0'; ssl->f_dbg( ssl->p_dbg, level, str ); - debug_print_mpi( ssl, level, file, line, - "crt->rsa.N", &crt->rsa.N ); + switch( crt->pk.type ) + { + case POLARSSL_PK_NONE: + case POLARSSL_PK_ECDSA: + debug_print_msg( ssl, level, file, line, + "crt->pk.type is not valid" ); + break; - debug_print_mpi( ssl, level, file, line, - "crt->rsa.E", &crt->rsa.E ); + case POLARSSL_PK_RSA: + debug_print_mpi( ssl, level, file, line, + "crt->rsa.N", &pk_rsa( crt->pk )->N ); + debug_print_mpi( ssl, level, file, line, + "crt->rsa.E", &pk_rsa( crt->pk )->E ); + break; + + case POLARSSL_PK_ECKEY: + case POLARSSL_PK_ECKEY_DH: + debug_print_ecp( ssl, level, file, line, + "crt->eckey.Q", &pk_ec( crt->pk )->Q ); + break; + } crt = crt->next; } diff --git a/tests/data_files/test-ca2.crt b/tests/data_files/test-ca2.crt new file mode 100644 index 0000000000000000000000000000000000000000..c47c496bffeb66fdd4df15a927c5090af5d72ef2 GIT binary patch literal 238 zcmXqLd~MLUn2D3&i>OJO-tm`02Api{T5TTZY*`o$_zigtxY?LPS(t@cLQ;!M4CKUl z4UG-V4Gjz|O$-bzqr`cQfLsF$C>K+Mr-3lkI3`9m4zRh*jEu}i3@nP~)8?rsa.N' (2048 bits) is\:\nMyFile(0999)\: a9 02 1f 3d 40 6a d5 55 53 8b fd 36 ee 82 65 2e\nMyFile(0999)\: 15 61 5e 89 bf b8 e8 45 90 db ee 88 16 52 d3 f1\nMyFile(0999)\: 43 50 47 96 12 59 64 87 6b fd 2b e0 46 f9 73 be\nMyFile(0999)\: dd cf 92 e1 91 5b ed 66 a0 6f 89 29 79 45 80 d0\nMyFile(0999)\: 83 6a d5 41 43 77 5f 39 7c 09 04 47 82 b0 57 39\nMyFile(0999)\: 70 ed a3 ec 15 19 1e a8 33 08 47 c1 05 42 a9 fd\nMyFile(0999)\: 4c c3 b4 df dd 06 1f 4d 10 51 40 67 73 13 0f 40\nMyFile(0999)\: f8 6d 81 25 5f 0a b1 53 c6 30 7e 15 39 ac f9 5a\nMyFile(0999)\: ee 7f 92 9e a6 05 5b e7 13 97 85 b5 23 92 d9 d4\nMyFile(0999)\: 24 06 d5 09 25 89 75 07 dd a6 1a 8f 3f 09 19 be\nMyFile(0999)\: ad 65 2c 64 eb 95 9b dc fe 41 5e 17 a6 da 6c 5b\nMyFile(0999)\: 69 cc 02 ba 14 2c 16 24 9c 4a dc cd d0 f7 52 67\nMyFile(0999)\: 73 f1 2d a0 23 fd 7e f4 31 ca 2d 70 ca 89 0b 04\nMyFile(0999)\: db 2e a6 4f 70 6e 9e ce bd 58 89 e2 53 59 9e 6e\nMyFile(0999)\: 5a 92 65 e2 88 3f 0c 94 19 a3 dd e5 e8 9d 95 13\nMyFile(0999)\: ed 29 db ab 70 12 dc 5a ca 6b 17 ab 52 82 54 b1\nMyFile(0999)\: value of 'crt->rsa.E' (17 bits) is\:\nMyFile(0999)\: 01 00 01\n" +Debug print certificate #2 (EC) +depends_on:POLARSSL_FS_IO:POLARSSL_PEM_C:POLARSSL_BASE64_C +debug_print_crt:"data_files/test-ca2.crt":"MyFile":999:"PREFIX_":"MyFile(0999)\: PREFIX_ #1\:\nMyFile(0999)\: cert. version \: 1\nMyFile(0999)\: serial number \: F4\:15\:34\:66\:2E\:C7\:E9\:12\nMyFile(0999)\: issuer name \: CN=Test\nMyFile(0999)\: subject name \: CN=Test\nMyFile(0999)\: issued on \: 2013-07-10 09\:40\:19\nMyFile(0999)\: expires on \: 2023-07-08 09\:40\:19\nMyFile(0999)\: signed using \: ECDSA with SHA1\nMyFile(0999)\: EC key size \: 192 bits\nMyFile(0999)\: value of 'crt->eckey.Q(X)' (190 bits) is\:\nMyFile(0999)\: 21 37 96 9f ab d4 e3 70 62 4a 0e 1a 33 e3 79 ca\nMyFile(0999)\: b9 50 cc e0 0e f8 c3 c3\nMyFile(0999)\: value of 'crt->eckey.Q(Y)' (192 bits) is\:\nMyFile(0999)\: e2 ad ae b7 27 1c 8f 07 65 9d 65 d3 d7 77 dc f2\nMyFile(0999)\: 16 14 36 3a e4 b6 e6 17\nMyFile(0999)\: value of 'crt->eckey.Q(Z)' (1 bits) is\:\nMyFile(0999)\: 01\n" + Debug print mpi #1 debug_print_mpi:16:"01020304050607":"MyFile":999:"VALUE":"MyFile(0999)\: value of 'VALUE' (49 bits) is\:\nMyFile(0999)\: 01 02 03 04 05 06 07\n"