summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2016-12-26 15:31:38 +0000
committerjsing <>2016-12-26 15:31:38 +0000
commit31656117a6540817602e4715e29bda545baa6151 (patch)
tree5f0ac5dd8ad725276ad8d26016b6088b2b1ee08b
parent3f47f43d5cb4924f08a830e3de5523ac054f9213 (diff)
downloadopenbsd-31656117a6540817602e4715e29bda545baa6151.tar.gz
openbsd-31656117a6540817602e4715e29bda545baa6151.tar.bz2
openbsd-31656117a6540817602e4715e29bda545baa6151.zip
Extend regress to include a peer certificate in the session.
-rw-r--r--src/regress/lib/libssl/asn1/asn1test.c192
1 files changed, 134 insertions, 58 deletions
diff --git a/src/regress/lib/libssl/asn1/asn1test.c b/src/regress/lib/libssl/asn1/asn1test.c
index 28cd3d827a..69be086724 100644
--- a/src/regress/lib/libssl/asn1/asn1test.c
+++ b/src/regress/lib/libssl/asn1/asn1test.c
@@ -1,6 +1,6 @@
1/* $OpenBSD: asn1test.c,v 1.5 2016/12/26 15:24:03 jsing Exp $ */ 1/* $OpenBSD: asn1test.c,v 1.6 2016/12/26 15:31:38 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2014, 2016 Joel Sing <jsing@openbsd.org>
4 * 4 *
5 * Permission to use, copy, modify, and distribute this software for any 5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above 6 * purpose with or without fee is hereby granted, provided that the above
@@ -27,9 +27,24 @@ int i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp);
27SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, const unsigned char **pp, 27SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, const unsigned char **pp,
28 long length); 28 long length);
29 29
30X509 *peer_cert;
31
32unsigned char *peer_cert_pem =
33 "-----BEGIN CERTIFICATE-----\n"
34 "MIIBcTCCARugAwIBAgIJAPYhaZJAvUuUMA0GCSqGSIb3DQEBBQUAMBQxEjAQBgNV\n"
35 "BAoMCVRlc3QgUGVlcjAeFw0xNjEyMjYxNDQ3NDdaFw0yNjEyMjQxNDQ3NDdaMBQx\n"
36 "EjAQBgNVBAoMCVRlc3QgUGVlcjBcMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQCyhAdJ\n"
37 "wojHv/uKONh8MbmR2U2+VF1HQusnLfSfHPqkJfvDzLWJ41TG7QcXkx2rIJVtAFrO\n"
38 "U9yNdFYJLA/hsrbjAgMBAAGjUDBOMB0GA1UdDgQWBBS3bZOw7fvaortdsdE2TPMq\n"
39 "IRXFRzAfBgNVHSMEGDAWgBS3bZOw7fvaortdsdE2TPMqIRXFRzAMBgNVHRMEBTAD\n"
40 "AQH/MA0GCSqGSIb3DQEBBQUAA0EAHsxNS+rNUZbopeDMhVIviOfUmelDjJrT56Rc\n"
41 "VJoFN3Gc1cV8nQAHm9aJs71uksC+MN04Pzh0WqmYX9XXrnYPcg==\n"
42 "-----END CERTIFICATE-----\n";
43
30struct ssl_asn1_test { 44struct ssl_asn1_test {
31 SSL_SESSION session; 45 SSL_SESSION session;
32 const unsigned char asn1[512]; 46 int peer_cert;
47 const unsigned char asn1[1024];
33 int asn1_len; 48 int asn1_len;
34}; 49};
35 50
@@ -64,19 +79,19 @@ unsigned char tlsext_tick[] = {
64 79
65struct ssl_asn1_test ssl_asn1_tests[] = { 80struct ssl_asn1_test ssl_asn1_tests[] = {
66 { 81 {
67 { 82 .session = {
68 .cipher_id = 0x03000000L | 1, 83 .cipher_id = 0x03000000L | 1,
69 .ssl_version = TLS1_2_VERSION, 84 .ssl_version = TLS1_2_VERSION,
70 }, 85 },
71 { 86 .asn1 = {
72 0x30, 0x13, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, 87 0x30, 0x13, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03,
73 0x03, 0x04, 0x02, 0x00, 0x01, 0x04, 0x00, 0x04, 88 0x03, 0x04, 0x02, 0x00, 0x01, 0x04, 0x00, 0x04,
74 0x00, 0xa4, 0x02, 0x04, 0x00, 89 0x00, 0xa4, 0x02, 0x04, 0x00,
75 }, 90 },
76 21, 91 .asn1_len = 21,
77 }, 92 },
78 { 93 {
79 { 94 .session = {
80 .cipher_id = 0x03000000L | 1, 95 .cipher_id = 0x03000000L | 1,
81 .ssl_version = TLS1_2_VERSION, 96 .ssl_version = TLS1_2_VERSION,
82 .master_key_length = 26, 97 .master_key_length = 26,
@@ -85,7 +100,7 @@ struct ssl_asn1_test ssl_asn1_tests[] = {
85 .sid_ctx = "abcdefghijklmnopqrstuvwxyz", 100 .sid_ctx = "abcdefghijklmnopqrstuvwxyz",
86 .sid_ctx_length = 26, 101 .sid_ctx_length = 26,
87 }, 102 },
88 { 103 .asn1 = {
89 0x30, 0x51, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, 104 0x30, 0x51, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03,
90 0x03, 0x04, 0x02, 0x00, 0x01, 0x04, 0x0a, 0x30, 105 0x03, 0x04, 0x02, 0x00, 0x01, 0x04, 0x0a, 0x30,
91 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 106 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
@@ -98,10 +113,10 @@ struct ssl_asn1_test ssl_asn1_tests[] = {
98 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 113 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
99 0x78, 0x79, 0x7a, 114 0x78, 0x79, 0x7a,
100 }, 115 },
101 83, 116 .asn1_len = 83,
102 }, 117 },
103 { 118 {
104 { 119 .session = {
105 .cipher_id = 0x03000000L | 1, 120 .cipher_id = 0x03000000L | 1,
106 .ssl_version = TLS1_2_VERSION, 121 .ssl_version = TLS1_2_VERSION,
107 .master_key_length = 26, 122 .master_key_length = 26,
@@ -115,10 +130,11 @@ struct ssl_asn1_test ssl_asn1_tests[] = {
115 .tlsext_hostname = "libressl.openbsd.org", 130 .tlsext_hostname = "libressl.openbsd.org",
116 .tlsext_tick_lifetime_hint = 0x7abbccdd, 131 .tlsext_tick_lifetime_hint = 0x7abbccdd,
117 .tlsext_tick = tlsext_tick, 132 .tlsext_tick = tlsext_tick,
118 .tlsext_ticklen = 207, 133 .tlsext_ticklen = sizeof(tlsext_tick),
119 }, 134 },
120 { 135 .peer_cert = 1,
121 0x30, 0x82, 0x01, 0x58, 0x02, 0x01, 0x01, 0x02, 136 .asn1 = {
137 0x30, 0x82, 0x02, 0xd1, 0x02, 0x01, 0x01, 0x02,
122 0x02, 0x03, 0x03, 0x04, 0x02, 0x00, 0x01, 0x04, 138 0x02, 0x03, 0x03, 0x04, 0x02, 0x00, 0x01, 0x04,
123 0x0a, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 139 0x0a, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,
124 0x37, 0x38, 0x39, 0x04, 0x1a, 0x00, 0x00, 0x00, 140 0x37, 0x38, 0x39, 0x04, 0x1a, 0x00, 0x00, 0x00,
@@ -126,66 +142,113 @@ struct ssl_asn1_test ssl_asn1_tests[] = {
126 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 142 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
127 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa1, 143 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa1,
128 0x06, 0x02, 0x04, 0x53, 0xc2, 0xa8, 0x95, 0xa2, 144 0x06, 0x02, 0x04, 0x53, 0xc2, 0xa8, 0x95, 0xa2,
129 0x03, 0x02, 0x01, 0x05, 0xa4, 0x1c, 0x04, 0x1a, 145 0x03, 0x02, 0x01, 0x05, 0xa3, 0x82, 0x01, 0x75,
130 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 146 0x30, 0x82, 0x01, 0x71, 0x30, 0x82, 0x01, 0x1b,
131 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 147 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x09, 0x00,
132 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 148 0xf6, 0x21, 0x69, 0x92, 0x40, 0xbd, 0x4b, 0x94,
133 0x79, 0x7a, 0xa5, 0x03, 0x02, 0x01, 0x2a, 0xa6, 149 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
134 0x16, 0x04, 0x14, 0x6c, 0x69, 0x62, 0x72, 0x65, 150 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30,
135 0x73, 0x73, 0x6c, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 151 0x14, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55,
136 0x62, 0x73, 0x64, 0x2e, 0x6f, 0x72, 0x67, 0xa9, 152 0x04, 0x0a, 0x0c, 0x09, 0x54, 0x65, 0x73, 0x74,
137 0x06, 0x02, 0x04, 0x7a, 0xbb, 0xcc, 0xdd, 0xaa, 153 0x20, 0x50, 0x65, 0x65, 0x72, 0x30, 0x1e, 0x17,
138 0x81, 0xd2, 0x04, 0x81, 0xcf, 0x43, 0x56, 0x45, 154 0x0d, 0x31, 0x36, 0x31, 0x32, 0x32, 0x36, 0x31,
139 0x2d, 0x32, 0x30, 0x31, 0x34, 0x2d, 0x30, 0x31, 155 0x34, 0x34, 0x37, 0x34, 0x37, 0x5a, 0x17, 0x0d,
140 0x36, 0x30, 0x3a, 0x20, 0x37, 0x74, 0x68, 0x20, 156 0x32, 0x36, 0x31, 0x32, 0x32, 0x34, 0x31, 0x34,
141 0x41, 0x70, 0x72, 0x69, 0x6c, 0x20, 0x32, 0x30, 157 0x34, 0x37, 0x34, 0x37, 0x5a, 0x30, 0x14, 0x31,
142 0x31, 0x34, 0x0a, 0x43, 0x56, 0x45, 0x2d, 0x32, 158 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x0a,
143 0x30, 0x31, 0x30, 0x2d, 0x35, 0x32, 0x39, 0x38, 159 0x0c, 0x09, 0x54, 0x65, 0x73, 0x74, 0x20, 0x50,
144 0x3a, 0x20, 0x38, 0x74, 0x68, 0x20, 0x41, 0x70, 160 0x65, 0x65, 0x72, 0x30, 0x5c, 0x30, 0x0d, 0x06,
161 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01,
162 0x01, 0x01, 0x05, 0x00, 0x03, 0x4b, 0x00, 0x30,
163 0x48, 0x02, 0x41, 0x00, 0xb2, 0x84, 0x07, 0x49,
164 0xc2, 0x88, 0xc7, 0xbf, 0xfb, 0x8a, 0x38, 0xd8,
165 0x7c, 0x31, 0xb9, 0x91, 0xd9, 0x4d, 0xbe, 0x54,
166 0x5d, 0x47, 0x42, 0xeb, 0x27, 0x2d, 0xf4, 0x9f,
167 0x1c, 0xfa, 0xa4, 0x25, 0xfb, 0xc3, 0xcc, 0xb5,
168 0x89, 0xe3, 0x54, 0xc6, 0xed, 0x07, 0x17, 0x93,
169 0x1d, 0xab, 0x20, 0x95, 0x6d, 0x00, 0x5a, 0xce,
170 0x53, 0xdc, 0x8d, 0x74, 0x56, 0x09, 0x2c, 0x0f,
171 0xe1, 0xb2, 0xb6, 0xe3, 0x02, 0x03, 0x01, 0x00,
172 0x01, 0xa3, 0x50, 0x30, 0x4e, 0x30, 0x1d, 0x06,
173 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14,
174 0xb7, 0x6d, 0x93, 0xb0, 0xed, 0xfb, 0xda, 0xa2,
175 0xbb, 0x5d, 0xb1, 0xd1, 0x36, 0x4c, 0xf3, 0x2a,
176 0x21, 0x15, 0xc5, 0x47, 0x30, 0x1f, 0x06, 0x03,
177 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80,
178 0x14, 0xb7, 0x6d, 0x93, 0xb0, 0xed, 0xfb, 0xda,
179 0xa2, 0xbb, 0x5d, 0xb1, 0xd1, 0x36, 0x4c, 0xf3,
180 0x2a, 0x21, 0x15, 0xc5, 0x47, 0x30, 0x0c, 0x06,
181 0x03, 0x55, 0x1d, 0x13, 0x04, 0x05, 0x30, 0x03,
182 0x01, 0x01, 0xff, 0x30, 0x0d, 0x06, 0x09, 0x2a,
183 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05,
184 0x05, 0x00, 0x03, 0x41, 0x00, 0x1e, 0xcc, 0x4d,
185 0x4b, 0xea, 0xcd, 0x51, 0x96, 0xe8, 0xa5, 0xe0,
186 0xcc, 0x85, 0x52, 0x2f, 0x88, 0xe7, 0xd4, 0x99,
187 0xe9, 0x43, 0x8c, 0x9a, 0xd3, 0xe7, 0xa4, 0x5c,
188 0x54, 0x9a, 0x05, 0x37, 0x71, 0x9c, 0xd5, 0xc5,
189 0x7c, 0x9d, 0x00, 0x07, 0x9b, 0xd6, 0x89, 0xb3,
190 0xbd, 0x6e, 0x92, 0xc0, 0xbe, 0x30, 0xdd, 0x38,
191 0x3f, 0x38, 0x74, 0x5a, 0xa9, 0x98, 0x5f, 0xd5,
192 0xd7, 0xae, 0x76, 0x0f, 0x72, 0xa4, 0x1c, 0x04,
193 0x1a, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
194 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
195 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
196 0x78, 0x79, 0x7a, 0xa5, 0x03, 0x02, 0x01, 0x2a,
197 0xa6, 0x16, 0x04, 0x14, 0x6c, 0x69, 0x62, 0x72,
198 0x65, 0x73, 0x73, 0x6c, 0x2e, 0x6f, 0x70, 0x65,
199 0x6e, 0x62, 0x73, 0x64, 0x2e, 0x6f, 0x72, 0x67,
200 0xa9, 0x06, 0x02, 0x04, 0x7a, 0xbb, 0xcc, 0xdd,
201 0xaa, 0x81, 0xd2, 0x04, 0x81, 0xcf, 0x43, 0x56,
202 0x45, 0x2d, 0x32, 0x30, 0x31, 0x34, 0x2d, 0x30,
203 0x31, 0x36, 0x30, 0x3a, 0x20, 0x37, 0x74, 0x68,
204 0x20, 0x41, 0x70, 0x72, 0x69, 0x6c, 0x20, 0x32,
205 0x30, 0x31, 0x34, 0x0a, 0x43, 0x56, 0x45, 0x2d,
206 0x32, 0x30, 0x31, 0x30, 0x2d, 0x35, 0x32, 0x39,
207 0x38, 0x3a, 0x20, 0x38, 0x74, 0x68, 0x20, 0x41,
208 0x70, 0x72, 0x69, 0x6c, 0x20, 0x32, 0x30, 0x31,
209 0x34, 0x0a, 0x43, 0x56, 0x45, 0x2d, 0x32, 0x30,
210 0x31, 0x34, 0x2d, 0x30, 0x31, 0x39, 0x38, 0x3a,
211 0x20, 0x32, 0x31, 0x73, 0x74, 0x20, 0x41, 0x70,
145 0x72, 0x69, 0x6c, 0x20, 0x32, 0x30, 0x31, 0x34, 212 0x72, 0x69, 0x6c, 0x20, 0x32, 0x30, 0x31, 0x34,
146 0x0a, 0x43, 0x56, 0x45, 0x2d, 0x32, 0x30, 0x31, 213 0x0a, 0x43, 0x56, 0x45, 0x2d, 0x32, 0x30, 0x31,
147 0x34, 0x2d, 0x30, 0x31, 0x39, 0x38, 0x3a, 0x20, 214 0x34, 0x2d, 0x33, 0x34, 0x37, 0x30, 0x3a, 0x20,
148 0x32, 0x31, 0x73, 0x74, 0x20, 0x41, 0x70, 0x72, 215 0x33, 0x30, 0x74, 0x68, 0x20, 0x4d, 0x61, 0x79,
149 0x69, 0x6c, 0x20, 0x32, 0x30, 0x31, 0x34, 0x0a, 216 0x20, 0x32, 0x30, 0x31, 0x34, 0x0a, 0x43, 0x56,
217 0x45, 0x2d, 0x32, 0x30, 0x31, 0x34, 0x2d, 0x30,
218 0x31, 0x39, 0x35, 0x3a, 0x20, 0x35, 0x74, 0x68,
219 0x20, 0x4a, 0x75, 0x6e, 0x65, 0x20, 0x32, 0x30,
220 0x31, 0x34, 0x0a, 0x43, 0x56, 0x45, 0x2d, 0x32,
221 0x30, 0x31, 0x34, 0x2d, 0x30, 0x32, 0x32, 0x31,
222 0x3a, 0x20, 0x35, 0x74, 0x68, 0x20, 0x4a, 0x75,
223 0x6e, 0x65, 0x20, 0x32, 0x30, 0x31, 0x34, 0x0a,
150 0x43, 0x56, 0x45, 0x2d, 0x32, 0x30, 0x31, 0x34, 224 0x43, 0x56, 0x45, 0x2d, 0x32, 0x30, 0x31, 0x34,
151 0x2d, 0x33, 0x34, 0x37, 0x30, 0x3a, 0x20, 0x33, 225 0x2d, 0x30, 0x32, 0x32, 0x34, 0x3a, 0x20, 0x35,
152 0x30, 0x74, 0x68, 0x20, 0x4d, 0x61, 0x79, 0x20, 226 0x74, 0x68, 0x20, 0x4a, 0x75, 0x6e, 0x65, 0x20,
153 0x32, 0x30, 0x31, 0x34, 0x0a, 0x43, 0x56, 0x45, 227 0x32, 0x30, 0x31, 0x34, 0x0a,
154 0x2d, 0x32, 0x30, 0x31, 0x34, 0x2d, 0x30, 0x31,
155 0x39, 0x35, 0x3a, 0x20, 0x35, 0x74, 0x68, 0x20,
156 0x4a, 0x75, 0x6e, 0x65, 0x20, 0x32, 0x30, 0x31,
157 0x34, 0x0a, 0x43, 0x56, 0x45, 0x2d, 0x32, 0x30,
158 0x31, 0x34, 0x2d, 0x30, 0x32, 0x32, 0x31, 0x3a,
159 0x20, 0x35, 0x74, 0x68, 0x20, 0x4a, 0x75, 0x6e,
160 0x65, 0x20, 0x32, 0x30, 0x31, 0x34, 0x0a, 0x43,
161 0x56, 0x45, 0x2d, 0x32, 0x30, 0x31, 0x34, 0x2d,
162 0x30, 0x32, 0x32, 0x34, 0x3a, 0x20, 0x35, 0x74,
163 0x68, 0x20, 0x4a, 0x75, 0x6e, 0x65, 0x20, 0x32,
164 0x30, 0x31, 0x34, 0x0a,
165 }, 228 },
166 348, 229 .asn1_len = 725,
167 }, 230 },
168 { 231 {
169 { 232 .session = {
170 .cipher_id = 0x03000000L | 1, 233 .cipher_id = 0x03000000L | 1,
171 .ssl_version = TLS1_2_VERSION, 234 .ssl_version = TLS1_2_VERSION,
172 .timeout = -1, 235 .timeout = -1,
173 }, 236 },
174 { 237 .asn1 = {
175 0x0, 238 0x0,
176 }, 239 },
177 -1, 240 .asn1_len = -1,
178 }, 241 },
179 { 242 {
180 { 243 .session = {
181 .cipher_id = 0x03000000L | 1, 244 .cipher_id = 0x03000000L | 1,
182 .ssl_version = TLS1_2_VERSION, 245 .ssl_version = TLS1_2_VERSION,
183 .time = -1, 246 .time = -1,
184 }, 247 },
185 { 248 .asn1 = {
186 0x0, 249 0x0,
187 }, 250 },
188 -1, 251 .asn1_len = -1,
189 }, 252 },
190}; 253};
191 254
@@ -266,7 +329,8 @@ session_cmp(SSL_SESSION *s1, SSL_SESSION *s2)
266 329
267 /* Ensure that a certificate is or is not present in both. */ 330 /* Ensure that a certificate is or is not present in both. */
268 if ((s1->peer != NULL || s2->peer != NULL) && 331 if ((s1->peer != NULL || s2->peer != NULL) &&
269 (s1->peer == NULL || s2->peer == NULL)) { 332 (s1->peer == NULL || s2->peer == NULL ||
333 X509_cmp(s1->peer, s2->peer) != 0)) {
270 fprintf(stderr, "peer differs\n"); 334 fprintf(stderr, "peer differs\n");
271 return (1); 335 return (1);
272 } 336 }
@@ -310,6 +374,9 @@ do_ssl_asn1_test(int test_no, struct ssl_asn1_test *sat)
310 const unsigned char *pp; 374 const unsigned char *pp;
311 int i, len, rv = 1; 375 int i, len, rv = 1;
312 376
377 if (sat->peer_cert)
378 sat->session.peer = peer_cert;
379
313 len = i2d_SSL_SESSION(&sat->session, NULL); 380 len = i2d_SSL_SESSION(&sat->session, NULL);
314 if (len != sat->asn1_len) { 381 if (len != sat->asn1_len) {
315 fprintf(stderr, "FAIL: test %i returned ASN1 length %i, " 382 fprintf(stderr, "FAIL: test %i returned ASN1 length %i, "
@@ -327,10 +394,7 @@ do_ssl_asn1_test(int test_no, struct ssl_asn1_test *sat)
327 ap = asn1; 394 ap = asn1;
328 len = i2d_SSL_SESSION(&sat->session, &ap); 395 len = i2d_SSL_SESSION(&sat->session, &ap);
329 396
330 /* 397 /* Check the length again since the code path is different. */
331 * Length *should* be the same, but check it again since the code
332 * path is different.
333 */
334 if (len != sat->asn1_len) { 398 if (len != sat->asn1_len) {
335 fprintf(stderr, "FAIL: test %i returned ASN1 length %i, " 399 fprintf(stderr, "FAIL: test %i returned ASN1 length %i, "
336 "want %i\n", test_no, len, sat->asn1_len); 400 "want %i\n", test_no, len, sat->asn1_len);
@@ -389,14 +453,26 @@ failed:
389int 453int
390main(int argc, char **argv) 454main(int argc, char **argv)
391{ 455{
456 BIO *bio = NULL;
392 int failed = 0; 457 int failed = 0;
393 size_t i; 458 size_t i;
394 459
395 SSL_library_init(); 460 SSL_library_init();
396 SSL_load_error_strings(); 461 SSL_load_error_strings();
397 462
463 bio = BIO_new_mem_buf(peer_cert_pem, -1);
464 if (bio == NULL)
465 errx(1, "failed to create bio");
466
467 peer_cert = PEM_read_bio_X509(bio, NULL, NULL, NULL);
468 if (peer_cert == NULL)
469 errx(1, "failed to read peer cert");
470
398 for (i = 0; i < N_SSL_ASN1_TESTS; i++) 471 for (i = 0; i < N_SSL_ASN1_TESTS; i++)
399 failed += do_ssl_asn1_test(i, &ssl_asn1_tests[i]); 472 failed += do_ssl_asn1_test(i, &ssl_asn1_tests[i]);
400 473
474 X509_free(peer_cert);
475 BIO_free(bio);
476
401 return (failed); 477 return (failed);
402} 478}