| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/cert/x509_certificate.h" | 5 #include "net/cert/x509_certificate.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 } | 332 } |
| 333 | 333 |
| 334 // Legacy / Migration code. This should eventually be removed once | 334 // Legacy / Migration code. This should eventually be removed once |
| 335 // sufficient time has passed that all pickles serialized prior to | 335 // sufficient time has passed that all pickles serialized prior to |
| 336 // PICKLETYPE_CERTIFICATE_CHAIN_V3 have been removed. | 336 // PICKLETYPE_CERTIFICATE_CHAIN_V3 have been removed. |
| 337 OSCertHandle cert_handle = ReadOSCertHandleFromPickle(pickle_iter); | 337 OSCertHandle cert_handle = ReadOSCertHandleFromPickle(pickle_iter); |
| 338 if (!cert_handle) | 338 if (!cert_handle) |
| 339 return NULL; | 339 return NULL; |
| 340 | 340 |
| 341 OSCertHandles intermediates; | 341 OSCertHandles intermediates; |
| 342 uint32 num_intermediates = 0; | 342 uint32_t num_intermediates = 0; |
| 343 if (type != PICKLETYPE_SINGLE_CERTIFICATE) { | 343 if (type != PICKLETYPE_SINGLE_CERTIFICATE) { |
| 344 if (!pickle_iter->ReadUInt32(&num_intermediates)) { | 344 if (!pickle_iter->ReadUInt32(&num_intermediates)) { |
| 345 FreeOSCertHandle(cert_handle); | 345 FreeOSCertHandle(cert_handle); |
| 346 return NULL; | 346 return NULL; |
| 347 } | 347 } |
| 348 | 348 |
| 349 #if defined(OS_POSIX) && !defined(OS_MACOSX) && defined(__x86_64__) | 349 #if defined(OS_POSIX) && !defined(OS_MACOSX) && defined(__x86_64__) |
| 350 // On 64-bit Linux (and any other 64-bit platforms), the intermediate count | 350 // On 64-bit Linux (and any other 64-bit platforms), the intermediate count |
| 351 // might really be a 64-bit field since we used to use Pickle::WriteSize(), | 351 // might really be a 64-bit field since we used to use Pickle::WriteSize(), |
| 352 // which writes either 32 or 64 bits depending on the architecture. Since | 352 // which writes either 32 or 64 bits depending on the architecture. Since |
| 353 // x86-64 is little-endian, if that happens, the next 32 bits will be all | 353 // x86-64 is little-endian, if that happens, the next 32 bits will be all |
| 354 // zeroes (the high bits) and the 32 bits we already read above are the | 354 // zeroes (the high bits) and the 32 bits we already read above are the |
| 355 // correct value (we assume there are never more than 2^32 - 1 intermediate | 355 // correct value (we assume there are never more than 2^32 - 1 intermediate |
| 356 // certificates in a chain; in practice, more than a dozen or so is | 356 // certificates in a chain; in practice, more than a dozen or so is |
| 357 // basically unheard of). Since it's invalid for a certificate to start with | 357 // basically unheard of). Since it's invalid for a certificate to start with |
| 358 // 32 bits of zeroes, we check for that here and skip it if we find it. We | 358 // 32 bits of zeroes, we check for that here and skip it if we find it. We |
| 359 // save a copy of the pickle iterator to restore in case we don't get 32 | 359 // save a copy of the pickle iterator to restore in case we don't get 32 |
| 360 // bits of zeroes. Now we always write 32 bits, so after a while, these old | 360 // bits of zeroes. Now we always write 32 bits, so after a while, these old |
| 361 // cached pickles will all get replaced. | 361 // cached pickles will all get replaced. |
| 362 // TODO(mdm): remove this compatibility code in April 2013 or so. | 362 // TODO(mdm): remove this compatibility code in April 2013 or so. |
| 363 base::PickleIterator saved_iter = *pickle_iter; | 363 base::PickleIterator saved_iter = *pickle_iter; |
| 364 uint32 zero_check = 0; | 364 uint32_t zero_check = 0; |
| 365 if (!pickle_iter->ReadUInt32(&zero_check)) { | 365 if (!pickle_iter->ReadUInt32(&zero_check)) { |
| 366 // This may not be an error. If there are no intermediates, and we're | 366 // This may not be an error. If there are no intermediates, and we're |
| 367 // reading an old 32-bit pickle, and there's nothing else after this in | 367 // reading an old 32-bit pickle, and there's nothing else after this in |
| 368 // the pickle, we should report success. Note that it is technically | 368 // the pickle, we should report success. Note that it is technically |
| 369 // possible for us to skip over zeroes that should have occurred after | 369 // possible for us to skip over zeroes that should have occurred after |
| 370 // an empty certificate list; to avoid this going forward, only do this | 370 // an empty certificate list; to avoid this going forward, only do this |
| 371 // backward-compatibility stuff for PICKLETYPE_CERTIFICATE_CHAIN_V1 | 371 // backward-compatibility stuff for PICKLETYPE_CERTIFICATE_CHAIN_V1 |
| 372 // which comes from the pickle version number in http_response_info.cc. | 372 // which comes from the pickle version number in http_response_info.cc. |
| 373 if (num_intermediates) { | 373 if (num_intermediates) { |
| 374 FreeOSCertHandle(cert_handle); | 374 FreeOSCertHandle(cert_handle); |
| 375 return NULL; | 375 return NULL; |
| 376 } | 376 } |
| 377 } | 377 } |
| 378 if (zero_check) | 378 if (zero_check) |
| 379 *pickle_iter = saved_iter; | 379 *pickle_iter = saved_iter; |
| 380 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) && defined(__x86_64__) | 380 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) && defined(__x86_64__) |
| 381 | 381 |
| 382 for (uint32 i = 0; i < num_intermediates; ++i) { | 382 for (uint32_t i = 0; i < num_intermediates; ++i) { |
| 383 OSCertHandle intermediate = ReadOSCertHandleFromPickle(pickle_iter); | 383 OSCertHandle intermediate = ReadOSCertHandleFromPickle(pickle_iter); |
| 384 if (!intermediate) | 384 if (!intermediate) |
| 385 break; | 385 break; |
| 386 intermediates.push_back(intermediate); | 386 intermediates.push_back(intermediate); |
| 387 } | 387 } |
| 388 } | 388 } |
| 389 | 389 |
| 390 X509Certificate* cert = NULL; | 390 X509Certificate* cert = NULL; |
| 391 if (intermediates.size() == num_intermediates) | 391 if (intermediates.size() == num_intermediates) |
| 392 cert = CreateFromHandle(cert_handle, intermediates); | 392 cert = CreateFromHandle(cert_handle, intermediates); |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 RemoveFromCache(cert_handle_); | 757 RemoveFromCache(cert_handle_); |
| 758 FreeOSCertHandle(cert_handle_); | 758 FreeOSCertHandle(cert_handle_); |
| 759 } | 759 } |
| 760 for (size_t i = 0; i < intermediate_ca_certs_.size(); ++i) { | 760 for (size_t i = 0; i < intermediate_ca_certs_.size(); ++i) { |
| 761 RemoveFromCache(intermediate_ca_certs_[i]); | 761 RemoveFromCache(intermediate_ca_certs_[i]); |
| 762 FreeOSCertHandle(intermediate_ca_certs_[i]); | 762 FreeOSCertHandle(intermediate_ca_certs_[i]); |
| 763 } | 763 } |
| 764 } | 764 } |
| 765 | 765 |
| 766 } // namespace net | 766 } // namespace net |
| OLD | NEW |