Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1 | /* |
| 2 | * X.509 Certificate Signing Request (CSR) parsing |
| 3 | * |
Paul Bakker | 7dc4c44 | 2014-02-01 22:50:26 +0100 | [diff] [blame] | 4 | * Copyright (C) 2006-2014, Brainspark B.V. |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 5 | * |
| 6 | * This file is part of PolarSSL (http://www.polarssl.org) |
| 7 | * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> |
| 8 | * |
| 9 | * All rights reserved. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License along |
| 22 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 23 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 24 | */ |
| 25 | /* |
| 26 | * The ITU-T X.509 standard defines a certificate format for PKI. |
| 27 | * |
| 28 | * http://www.ietf.org/rfc/rfc3279.txt |
| 29 | * http://www.ietf.org/rfc/rfc3280.txt |
| 30 | * |
| 31 | * ftp://ftp.rsasecurity.com/pub/pkcs/ascii/pkcs-1v2.asc |
| 32 | * |
| 33 | * http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf |
| 34 | * http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf |
| 35 | */ |
| 36 | |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 37 | #if !defined(POLARSSL_CONFIG_FILE) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 38 | #include "polarssl/config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 39 | #else |
| 40 | #include POLARSSL_CONFIG_FILE |
| 41 | #endif |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 42 | |
| 43 | #if defined(POLARSSL_X509_CSR_PARSE_C) |
| 44 | |
| 45 | #include "polarssl/x509_csr.h" |
| 46 | #include "polarssl/oid.h" |
| 47 | #if defined(POLARSSL_PEM_PARSE_C) |
| 48 | #include "polarssl/pem.h" |
| 49 | #endif |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 50 | |
Paul Bakker | 7dc4c44 | 2014-02-01 22:50:26 +0100 | [diff] [blame] | 51 | #if defined(POLARSSL_PLATFORM_C) |
| 52 | #include "polarssl/platform.h" |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 53 | #else |
| 54 | #define polarssl_malloc malloc |
| 55 | #define polarssl_free free |
| 56 | #endif |
| 57 | |
| 58 | #include <string.h> |
| 59 | #include <stdlib.h> |
| 60 | |
Paul Bakker | fa6a620 | 2013-10-28 18:48:30 +0100 | [diff] [blame] | 61 | #if defined(POLARSSL_FS_IO) || defined(EFIX64) || defined(EFI32) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 62 | #include <stdio.h> |
| 63 | #endif |
| 64 | |
| 65 | /* |
| 66 | * Version ::= INTEGER { v1(0) } |
| 67 | */ |
| 68 | static int x509_csr_get_version( unsigned char **p, |
| 69 | const unsigned char *end, |
| 70 | int *ver ) |
| 71 | { |
| 72 | int ret; |
| 73 | |
| 74 | if( ( ret = asn1_get_int( p, end, ver ) ) != 0 ) |
| 75 | { |
| 76 | if( ret == POLARSSL_ERR_ASN1_UNEXPECTED_TAG ) |
| 77 | { |
| 78 | *ver = 0; |
| 79 | return( 0 ); |
| 80 | } |
| 81 | |
Paul Bakker | 5187656 | 2013-09-17 14:36:05 +0200 | [diff] [blame] | 82 | return( POLARSSL_ERR_X509_INVALID_VERSION + ret ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | return( 0 ); |
| 86 | } |
| 87 | |
| 88 | /* |
| 89 | * Parse a CSR |
| 90 | */ |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 91 | int x509_csr_parse( x509_csr *csr, const unsigned char *buf, size_t buflen ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 92 | { |
| 93 | int ret; |
| 94 | size_t len; |
| 95 | unsigned char *p, *end; |
| 96 | #if defined(POLARSSL_PEM_PARSE_C) |
| 97 | size_t use_len; |
| 98 | pem_context pem; |
| 99 | #endif |
| 100 | |
| 101 | /* |
| 102 | * Check for valid input |
| 103 | */ |
| 104 | if( csr == NULL || buf == NULL ) |
Paul Bakker | 5187656 | 2013-09-17 14:36:05 +0200 | [diff] [blame] | 105 | return( POLARSSL_ERR_X509_BAD_INPUT_DATA ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 106 | |
Paul Bakker | 369d2eb | 2013-09-18 11:58:25 +0200 | [diff] [blame] | 107 | x509_csr_init( csr ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 108 | |
| 109 | #if defined(POLARSSL_PEM_PARSE_C) |
| 110 | pem_init( &pem ); |
| 111 | ret = pem_read_buffer( &pem, |
| 112 | "-----BEGIN CERTIFICATE REQUEST-----", |
| 113 | "-----END CERTIFICATE REQUEST-----", |
| 114 | buf, NULL, 0, &use_len ); |
| 115 | |
| 116 | if( ret == 0 ) |
| 117 | { |
| 118 | /* |
Manuel Pégourié-Gonnard | 7c59363 | 2014-01-20 10:27:13 +0100 | [diff] [blame] | 119 | * Was PEM encoded, steal PEM buffer |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 120 | */ |
| 121 | p = pem.buf; |
| 122 | pem.buf = NULL; |
| 123 | len = pem.buflen; |
| 124 | pem_free( &pem ); |
| 125 | } |
| 126 | else if( ret != POLARSSL_ERR_PEM_NO_HEADER_FOOTER_PRESENT ) |
| 127 | { |
| 128 | pem_free( &pem ); |
| 129 | return( ret ); |
| 130 | } |
| 131 | else |
Paul Bakker | 9af723c | 2014-05-01 13:03:14 +0200 | [diff] [blame^] | 132 | #endif /* POLARSSL_PEM_PARSE_C */ |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 133 | { |
| 134 | /* |
| 135 | * nope, copy the raw DER data |
| 136 | */ |
| 137 | p = (unsigned char *) polarssl_malloc( len = buflen ); |
| 138 | |
| 139 | if( p == NULL ) |
| 140 | return( POLARSSL_ERR_X509_MALLOC_FAILED ); |
| 141 | |
| 142 | memcpy( p, buf, buflen ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | csr->raw.p = p; |
| 146 | csr->raw.len = len; |
| 147 | end = p + len; |
| 148 | |
| 149 | /* |
| 150 | * CertificationRequest ::= SEQUENCE { |
| 151 | * certificationRequestInfo CertificationRequestInfo, |
| 152 | * signatureAlgorithm AlgorithmIdentifier, |
| 153 | * signature BIT STRING |
| 154 | * } |
| 155 | */ |
| 156 | if( ( ret = asn1_get_tag( &p, end, &len, |
| 157 | ASN1_CONSTRUCTED | ASN1_SEQUENCE ) ) != 0 ) |
| 158 | { |
| 159 | x509_csr_free( csr ); |
Paul Bakker | 5187656 | 2013-09-17 14:36:05 +0200 | [diff] [blame] | 160 | return( POLARSSL_ERR_X509_INVALID_FORMAT ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | if( len != (size_t) ( end - p ) ) |
| 164 | { |
| 165 | x509_csr_free( csr ); |
Paul Bakker | 5187656 | 2013-09-17 14:36:05 +0200 | [diff] [blame] | 166 | return( POLARSSL_ERR_X509_INVALID_FORMAT + |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 167 | POLARSSL_ERR_ASN1_LENGTH_MISMATCH ); |
| 168 | } |
| 169 | |
| 170 | /* |
| 171 | * CertificationRequestInfo ::= SEQUENCE { |
| 172 | */ |
| 173 | csr->cri.p = p; |
| 174 | |
| 175 | if( ( ret = asn1_get_tag( &p, end, &len, |
| 176 | ASN1_CONSTRUCTED | ASN1_SEQUENCE ) ) != 0 ) |
| 177 | { |
| 178 | x509_csr_free( csr ); |
Paul Bakker | 5187656 | 2013-09-17 14:36:05 +0200 | [diff] [blame] | 179 | return( POLARSSL_ERR_X509_INVALID_FORMAT + ret ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | end = p + len; |
| 183 | csr->cri.len = end - csr->cri.p; |
| 184 | |
| 185 | /* |
| 186 | * Version ::= INTEGER { v1(0) } |
| 187 | */ |
| 188 | if( ( ret = x509_csr_get_version( &p, end, &csr->version ) ) != 0 ) |
| 189 | { |
| 190 | x509_csr_free( csr ); |
| 191 | return( ret ); |
| 192 | } |
| 193 | |
| 194 | csr->version++; |
| 195 | |
| 196 | if( csr->version != 1 ) |
| 197 | { |
| 198 | x509_csr_free( csr ); |
Paul Bakker | 5187656 | 2013-09-17 14:36:05 +0200 | [diff] [blame] | 199 | return( POLARSSL_ERR_X509_UNKNOWN_VERSION ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | /* |
| 203 | * subject Name |
| 204 | */ |
| 205 | csr->subject_raw.p = p; |
| 206 | |
| 207 | if( ( ret = asn1_get_tag( &p, end, &len, |
| 208 | ASN1_CONSTRUCTED | ASN1_SEQUENCE ) ) != 0 ) |
| 209 | { |
| 210 | x509_csr_free( csr ); |
Paul Bakker | 5187656 | 2013-09-17 14:36:05 +0200 | [diff] [blame] | 211 | return( POLARSSL_ERR_X509_INVALID_FORMAT + ret ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | if( ( ret = x509_get_name( &p, p + len, &csr->subject ) ) != 0 ) |
| 215 | { |
| 216 | x509_csr_free( csr ); |
| 217 | return( ret ); |
| 218 | } |
| 219 | |
| 220 | csr->subject_raw.len = p - csr->subject_raw.p; |
| 221 | |
| 222 | /* |
| 223 | * subjectPKInfo SubjectPublicKeyInfo |
| 224 | */ |
Paul Bakker | da77115 | 2013-09-16 22:45:03 +0200 | [diff] [blame] | 225 | if( ( ret = pk_parse_subpubkey( &p, end, &csr->pk ) ) != 0 ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 226 | { |
| 227 | x509_csr_free( csr ); |
| 228 | return( ret ); |
| 229 | } |
| 230 | |
| 231 | /* |
| 232 | * attributes [0] Attributes |
| 233 | */ |
| 234 | if( ( ret = asn1_get_tag( &p, end, &len, |
| 235 | ASN1_CONSTRUCTED | ASN1_CONTEXT_SPECIFIC ) ) != 0 ) |
| 236 | { |
| 237 | x509_csr_free( csr ); |
Paul Bakker | 5187656 | 2013-09-17 14:36:05 +0200 | [diff] [blame] | 238 | return( POLARSSL_ERR_X509_INVALID_FORMAT + ret ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 239 | } |
| 240 | // TODO Parse Attributes / extension requests |
| 241 | |
| 242 | p += len; |
| 243 | |
| 244 | end = csr->raw.p + csr->raw.len; |
| 245 | |
| 246 | /* |
| 247 | * signatureAlgorithm AlgorithmIdentifier, |
| 248 | * signature BIT STRING |
| 249 | */ |
Manuel Pégourié-Gonnard | c909308 | 2014-02-12 09:39:59 +0100 | [diff] [blame] | 250 | if( ( ret = x509_get_alg_null( &p, end, &csr->sig_oid ) ) != 0 ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 251 | { |
| 252 | x509_csr_free( csr ); |
| 253 | return( ret ); |
| 254 | } |
| 255 | |
Manuel Pégourié-Gonnard | c909308 | 2014-02-12 09:39:59 +0100 | [diff] [blame] | 256 | if( ( ret = x509_get_sig_alg( &csr->sig_oid, &csr->sig_md, |
| 257 | &csr->sig_pk ) ) != 0 ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 258 | { |
| 259 | x509_csr_free( csr ); |
Paul Bakker | 5187656 | 2013-09-17 14:36:05 +0200 | [diff] [blame] | 260 | return( POLARSSL_ERR_X509_UNKNOWN_SIG_ALG ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | if( ( ret = x509_get_sig( &p, end, &csr->sig ) ) != 0 ) |
| 264 | { |
| 265 | x509_csr_free( csr ); |
| 266 | return( ret ); |
| 267 | } |
| 268 | |
| 269 | if( p != end ) |
| 270 | { |
| 271 | x509_csr_free( csr ); |
Paul Bakker | 5187656 | 2013-09-17 14:36:05 +0200 | [diff] [blame] | 272 | return( POLARSSL_ERR_X509_INVALID_FORMAT + |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 273 | POLARSSL_ERR_ASN1_LENGTH_MISMATCH ); |
| 274 | } |
| 275 | |
| 276 | return( 0 ); |
| 277 | } |
| 278 | |
| 279 | #if defined(POLARSSL_FS_IO) |
| 280 | /* |
| 281 | * Load a CSR into the structure |
| 282 | */ |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 283 | int x509_csr_parse_file( x509_csr *csr, const char *path ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 284 | { |
| 285 | int ret; |
| 286 | size_t n; |
| 287 | unsigned char *buf; |
| 288 | |
| 289 | if ( ( ret = x509_load_file( path, &buf, &n ) ) != 0 ) |
| 290 | return( ret ); |
| 291 | |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 292 | ret = x509_csr_parse( csr, buf, n ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 293 | |
| 294 | memset( buf, 0, n + 1 ); |
| 295 | polarssl_free( buf ); |
| 296 | |
| 297 | return( ret ); |
| 298 | } |
| 299 | #endif /* POLARSSL_FS_IO */ |
| 300 | |
Paul Bakker | 6edcd41 | 2013-10-29 15:22:54 +0100 | [diff] [blame] | 301 | #if defined(_MSC_VER) && !defined snprintf && !defined(EFIX64) && \ |
| 302 | !defined(EFI32) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 303 | #include <stdarg.h> |
| 304 | |
| 305 | #if !defined vsnprintf |
| 306 | #define vsnprintf _vsnprintf |
| 307 | #endif // vsnprintf |
| 308 | |
| 309 | /* |
| 310 | * Windows _snprintf and _vsnprintf are not compatible to linux versions. |
| 311 | * Result value is not size of buffer needed, but -1 if no fit is possible. |
| 312 | * |
| 313 | * This fuction tries to 'fix' this by at least suggesting enlarging the |
| 314 | * size by 20. |
| 315 | */ |
| 316 | static int compat_snprintf(char *str, size_t size, const char *format, ...) |
| 317 | { |
| 318 | va_list ap; |
| 319 | int res = -1; |
| 320 | |
| 321 | va_start( ap, format ); |
| 322 | |
| 323 | res = vsnprintf( str, size, format, ap ); |
| 324 | |
| 325 | va_end( ap ); |
| 326 | |
| 327 | // No quick fix possible |
| 328 | if ( res < 0 ) |
| 329 | return( (int) size + 20 ); |
| 330 | |
| 331 | return res; |
| 332 | } |
| 333 | |
| 334 | #define snprintf compat_snprintf |
Paul Bakker | 9af723c | 2014-05-01 13:03:14 +0200 | [diff] [blame^] | 335 | #endif /* _MSC_VER && !snprintf && !EFIX64 && !EFI32 */ |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 336 | |
| 337 | #define POLARSSL_ERR_DEBUG_BUF_TOO_SMALL -2 |
| 338 | |
| 339 | #define SAFE_SNPRINTF() \ |
| 340 | { \ |
| 341 | if( ret == -1 ) \ |
| 342 | return( -1 ); \ |
| 343 | \ |
| 344 | if ( (unsigned int) ret > n ) { \ |
| 345 | p[n - 1] = '\0'; \ |
| 346 | return POLARSSL_ERR_DEBUG_BUF_TOO_SMALL;\ |
| 347 | } \ |
| 348 | \ |
| 349 | n -= (unsigned int) ret; \ |
| 350 | p += (unsigned int) ret; \ |
| 351 | } |
| 352 | |
| 353 | #define BEFORE_COLON 14 |
| 354 | #define BC "14" |
| 355 | /* |
| 356 | * Return an informational string about the CSR. |
| 357 | */ |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 358 | int x509_csr_info( char *buf, size_t size, const char *prefix, |
| 359 | const x509_csr *csr ) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 360 | { |
| 361 | int ret; |
| 362 | size_t n; |
| 363 | char *p; |
Manuel Pégourié-Gonnard | c909308 | 2014-02-12 09:39:59 +0100 | [diff] [blame] | 364 | const char *desc; |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 365 | char key_size_str[BEFORE_COLON]; |
| 366 | |
| 367 | p = buf; |
| 368 | n = size; |
| 369 | |
| 370 | ret = snprintf( p, n, "%sCSR version : %d", |
| 371 | prefix, csr->version ); |
| 372 | SAFE_SNPRINTF(); |
| 373 | |
| 374 | ret = snprintf( p, n, "\n%ssubject name : ", prefix ); |
| 375 | SAFE_SNPRINTF(); |
Paul Bakker | 86d0c19 | 2013-09-18 11:11:02 +0200 | [diff] [blame] | 376 | ret = x509_dn_gets( p, n, &csr->subject ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 377 | SAFE_SNPRINTF(); |
| 378 | |
| 379 | ret = snprintf( p, n, "\n%ssigned using : ", prefix ); |
| 380 | SAFE_SNPRINTF(); |
| 381 | |
Manuel Pégourié-Gonnard | c909308 | 2014-02-12 09:39:59 +0100 | [diff] [blame] | 382 | ret = oid_get_sig_alg_desc( &csr->sig_oid, &desc ); |
| 383 | if( ret != 0 ) |
| 384 | ret = snprintf( p, n, "???" ); |
| 385 | else |
| 386 | ret = snprintf( p, n, "%s", desc ); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 387 | SAFE_SNPRINTF(); |
| 388 | |
| 389 | if( ( ret = x509_key_size_helper( key_size_str, BEFORE_COLON, |
| 390 | pk_get_name( &csr->pk ) ) ) != 0 ) |
| 391 | { |
| 392 | return( ret ); |
| 393 | } |
| 394 | |
| 395 | ret = snprintf( p, n, "\n%s%-" BC "s: %d bits\n", prefix, key_size_str, |
| 396 | (int) pk_get_size( &csr->pk ) ); |
| 397 | SAFE_SNPRINTF(); |
| 398 | |
| 399 | return( (int) ( size - n ) ); |
| 400 | } |
| 401 | |
| 402 | /* |
Paul Bakker | 369d2eb | 2013-09-18 11:58:25 +0200 | [diff] [blame] | 403 | * Initialize a CSR |
| 404 | */ |
| 405 | void x509_csr_init( x509_csr *csr ) |
| 406 | { |
| 407 | memset( csr, 0, sizeof(x509_csr) ); |
| 408 | } |
| 409 | |
| 410 | /* |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 411 | * Unallocate all CSR data |
| 412 | */ |
| 413 | void x509_csr_free( x509_csr *csr ) |
| 414 | { |
| 415 | x509_name *name_cur; |
| 416 | x509_name *name_prv; |
| 417 | |
| 418 | if( csr == NULL ) |
| 419 | return; |
| 420 | |
| 421 | pk_free( &csr->pk ); |
| 422 | |
| 423 | name_cur = csr->subject.next; |
| 424 | while( name_cur != NULL ) |
| 425 | { |
| 426 | name_prv = name_cur; |
| 427 | name_cur = name_cur->next; |
| 428 | memset( name_prv, 0, sizeof( x509_name ) ); |
| 429 | polarssl_free( name_prv ); |
| 430 | } |
| 431 | |
| 432 | if( csr->raw.p != NULL ) |
| 433 | { |
| 434 | memset( csr->raw.p, 0, csr->raw.len ); |
| 435 | polarssl_free( csr->raw.p ); |
| 436 | } |
| 437 | |
| 438 | memset( csr, 0, sizeof( x509_csr ) ); |
| 439 | } |
| 440 | |
| 441 | #endif /* POLARSSL_X509_CSR_PARSE_C */ |