| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/common/net/x509_certificate_model.h" | 5 #include "chrome/common/net/x509_certificate_model.h" |
| 6 | 6 |
| 7 #include <cert.h> | 7 #include <cert.h> |
| 8 #include <cms.h> | 8 #include <cms.h> |
| 9 #include <hasht.h> | 9 #include <hasht.h> |
| 10 #include <keyhi.h> // SECKEY_DestroyPrivateKey | 10 #include <keyhi.h> // SECKEY_DestroyPrivateKey |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 } | 325 } |
| 326 | 326 |
| 327 string GetDerString(X509Certificate::OSCertHandle cert_handle) { | 327 string GetDerString(X509Certificate::OSCertHandle cert_handle) { |
| 328 return string(reinterpret_cast<const char*>(cert_handle->derCert.data), | 328 return string(reinterpret_cast<const char*>(cert_handle->derCert.data), |
| 329 cert_handle->derCert.len); | 329 cert_handle->derCert.len); |
| 330 } | 330 } |
| 331 | 331 |
| 332 string GetCMSString(const X509Certificate::OSCertHandles& cert_chain, | 332 string GetCMSString(const X509Certificate::OSCertHandles& cert_chain, |
| 333 size_t start, size_t end) { | 333 size_t start, size_t end) { |
| 334 ScopedPRArenaPool arena(PORT_NewArena(1024)); | 334 ScopedPRArenaPool arena(PORT_NewArena(1024)); |
| 335 CHECK(arena.get()); | 335 DCHECK(arena.get()); |
| 336 | 336 |
| 337 ScopedNSSCMSMessage message(NSS_CMSMessage_Create(arena.get())); | 337 ScopedNSSCMSMessage message(NSS_CMSMessage_Create(arena.get())); |
| 338 CHECK(message.get()); | 338 DCHECK(message.get()); |
| 339 | 339 |
| 340 // First, create SignedData with the certificate only (no chain). | 340 // First, create SignedData with the certificate only (no chain). |
| 341 ScopedNSSCMSSignedData signed_data(NSS_CMSSignedData_CreateCertsOnly( | 341 ScopedNSSCMSSignedData signed_data(NSS_CMSSignedData_CreateCertsOnly( |
| 342 message.get(), cert_chain[start], PR_FALSE)); | 342 message.get(), cert_chain[start], PR_FALSE)); |
| 343 if (!signed_data.get()) { | 343 if (!signed_data.get()) { |
| 344 LOG(ERROR) << "NSS_CMSSignedData_Create failed"; | 344 DLOG(ERROR) << "NSS_CMSSignedData_Create failed"; |
| 345 return ""; | 345 return ""; |
| 346 } | 346 } |
| 347 // Add the rest of the chain (if any). | 347 // Add the rest of the chain (if any). |
| 348 for (size_t i = start + 1; i < end; ++i) { | 348 for (size_t i = start + 1; i < end; ++i) { |
| 349 if (NSS_CMSSignedData_AddCertificate(signed_data.get(), cert_chain[i]) != | 349 if (NSS_CMSSignedData_AddCertificate(signed_data.get(), cert_chain[i]) != |
| 350 SECSuccess) { | 350 SECSuccess) { |
| 351 LOG(ERROR) << "NSS_CMSSignedData_AddCertificate failed on " << i; | 351 DLOG(ERROR) << "NSS_CMSSignedData_AddCertificate failed on " << i; |
| 352 return ""; | 352 return ""; |
| 353 } | 353 } |
| 354 } | 354 } |
| 355 | 355 |
| 356 NSSCMSContentInfo *cinfo = NSS_CMSMessage_GetContentInfo(message.get()); | 356 NSSCMSContentInfo *cinfo = NSS_CMSMessage_GetContentInfo(message.get()); |
| 357 if (NSS_CMSContentInfo_SetContent_SignedData( | 357 if (NSS_CMSContentInfo_SetContent_SignedData( |
| 358 message.get(), cinfo, signed_data.get()) == SECSuccess) { | 358 message.get(), cinfo, signed_data.get()) == SECSuccess) { |
| 359 ignore_result(signed_data.release()); | 359 ignore_result(signed_data.release()); |
| 360 } else { | 360 } else { |
| 361 LOG(ERROR) << "NSS_CMSMessage_GetContentInfo failed"; | 361 DLOG(ERROR) << "NSS_CMSMessage_GetContentInfo failed"; |
| 362 return ""; | 362 return ""; |
| 363 } | 363 } |
| 364 | 364 |
| 365 SECItem cert_p7 = { siBuffer, NULL, 0 }; | 365 SECItem cert_p7 = { siBuffer, NULL, 0 }; |
| 366 NSSCMSEncoderContext *ecx = NSS_CMSEncoder_Start(message.get(), NULL, NULL, | 366 NSSCMSEncoderContext *ecx = NSS_CMSEncoder_Start(message.get(), NULL, NULL, |
| 367 &cert_p7, arena.get(), NULL, | 367 &cert_p7, arena.get(), NULL, |
| 368 NULL, NULL, NULL, NULL, | 368 NULL, NULL, NULL, NULL, |
| 369 NULL); | 369 NULL); |
| 370 if (!ecx) { | 370 if (!ecx) { |
| 371 LOG(ERROR) << "NSS_CMSEncoder_Start failed"; | 371 DLOG(ERROR) << "NSS_CMSEncoder_Start failed"; |
| 372 return ""; | 372 return ""; |
| 373 } | 373 } |
| 374 | 374 |
| 375 if (NSS_CMSEncoder_Finish(ecx) != SECSuccess) { | 375 if (NSS_CMSEncoder_Finish(ecx) != SECSuccess) { |
| 376 LOG(ERROR) << "NSS_CMSEncoder_Finish failed"; | 376 DLOG(ERROR) << "NSS_CMSEncoder_Finish failed"; |
| 377 return ""; | 377 return ""; |
| 378 } | 378 } |
| 379 | 379 |
| 380 return string(reinterpret_cast<const char*>(cert_p7.data), cert_p7.len); | 380 return string(reinterpret_cast<const char*>(cert_p7.data), cert_p7.len); |
| 381 } | 381 } |
| 382 | 382 |
| 383 string ProcessSecAlgorithmSignature(X509Certificate::OSCertHandle cert_handle) { | 383 string ProcessSecAlgorithmSignature(X509Certificate::OSCertHandle cert_handle) { |
| 384 return ProcessSecAlgorithmInternal(&cert_handle->signature); | 384 return ProcessSecAlgorithmInternal(&cert_handle->signature); |
| 385 } | 385 } |
| 386 | 386 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 403 string ProcessRawBitsSignatureWrap(X509Certificate::OSCertHandle cert_handle) { | 403 string ProcessRawBitsSignatureWrap(X509Certificate::OSCertHandle cert_handle) { |
| 404 return ProcessRawBits(cert_handle->signatureWrap.signature.data, | 404 return ProcessRawBits(cert_handle->signatureWrap.signature.data, |
| 405 cert_handle->signatureWrap.signature.len); | 405 cert_handle->signatureWrap.signature.len); |
| 406 } | 406 } |
| 407 | 407 |
| 408 void RegisterDynamicOids() { | 408 void RegisterDynamicOids() { |
| 409 psm::RegisterDynamicOids(); | 409 psm::RegisterDynamicOids(); |
| 410 } | 410 } |
| 411 | 411 |
| 412 } // namespace x509_certificate_model | 412 } // namespace x509_certificate_model |
| OLD | NEW |