OLD | NEW |
1 // Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2009-2010 The Chromium OS 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 // Contains the implementation of class Tpm | 5 // Contains the implementation of class Tpm |
6 | 6 |
7 #include "tpm.h" | 7 #include "tpm.h" |
8 | 8 |
9 #include <base/file_util.h> | 9 #include <base/file_util.h> |
10 #include <base/platform_thread.h> | 10 #include <base/platform_thread.h> |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 if (password_sync_lock_.Try()) { | 489 if (password_sync_lock_.Try()) { |
490 if (owner_password_.size() != 0) { | 490 if (owner_password_.size() != 0) { |
491 owner_password->assign(owner_password_.begin(), owner_password_.end()); | 491 owner_password->assign(owner_password_.begin(), owner_password_.end()); |
492 result = true; | 492 result = true; |
493 } | 493 } |
494 password_sync_lock_.Release(); | 494 password_sync_lock_.Release(); |
495 } | 495 } |
496 return result; | 496 return result; |
497 } | 497 } |
498 | 498 |
499 bool Tpm::InitializeTpm() { | 499 bool Tpm::InitializeTpm(bool* OUT_took_ownership) { |
| 500 if (OUT_took_ownership) { |
| 501 *OUT_took_ownership = false; |
| 502 } |
| 503 |
500 if (!IsConnected()) { | 504 if (!IsConnected()) { |
501 Connect(); | 505 Connect(); |
502 } | 506 } |
503 | 507 |
504 if (!IsConnected()) { | 508 if (!IsConnected()) { |
505 LOG(ERROR) << "Failed to connect to TPM"; | 509 LOG(ERROR) << "Failed to connect to TPM"; |
506 return false; | 510 return false; |
507 } | 511 } |
508 | 512 |
509 if (is_disabled_) { | 513 if (is_disabled_) { |
(...skipping 28 matching lines...) Expand all Loading... |
538 default_owner_password)) { | 542 default_owner_password)) { |
539 LOG(ERROR) << "Take Ownership failed"; | 543 LOG(ERROR) << "Take Ownership failed"; |
540 is_being_owned_ = false; | 544 is_being_owned_ = false; |
541 return false; | 545 return false; |
542 } | 546 } |
543 | 547 |
544 is_owned_ = true; | 548 is_owned_ = true; |
545 took_ownership = true; | 549 took_ownership = true; |
546 } | 550 } |
547 | 551 |
| 552 if (OUT_took_ownership) { |
| 553 *OUT_took_ownership = took_ownership; |
| 554 } |
| 555 |
548 // Ensure the SRK is available | 556 // Ensure the SRK is available |
549 TSS_RESULT result; | 557 TSS_RESULT result; |
550 TSS_HKEY srk_handle; | 558 TSS_HKEY srk_handle; |
551 TSS_UUID SRK_UUID = TSS_UUID_SRK; | 559 TSS_UUID SRK_UUID = TSS_UUID_SRK; |
552 if ((result = Tspi_Context_LoadKeyByUUID(context_handle_, TSS_PS_TYPE_SYSTEM, | 560 if ((result = Tspi_Context_LoadKeyByUUID(context_handle_, TSS_PS_TYPE_SYSTEM, |
553 SRK_UUID, &srk_handle))) { | 561 SRK_UUID, &srk_handle))) { |
554 is_srk_available_ = false; | 562 is_srk_available_ = false; |
555 } else { | 563 } else { |
556 Tspi_Context_CloseObject(context_handle_, srk_handle); | 564 Tspi_Context_CloseObject(context_handle_, srk_handle); |
557 is_srk_available_ = true; | 565 is_srk_available_ = true; |
(...skipping 27 matching lines...) Expand all Loading... |
585 | 593 |
586 password_sync_lock_.Acquire(); | 594 password_sync_lock_.Acquire(); |
587 owner_password_.assign(owner_password.begin(), owner_password.end()); | 595 owner_password_.assign(owner_password.begin(), owner_password.end()); |
588 password_sync_lock_.Release(); | 596 password_sync_lock_.Release(); |
589 | 597 |
590 file_util::WriteFile(FilePath(kTpmOwnedFile), NULL, 0); | 598 file_util::WriteFile(FilePath(kTpmOwnedFile), NULL, 0); |
591 } | 599 } |
592 | 600 |
593 is_being_owned_ = false; | 601 is_being_owned_ = false; |
594 | 602 |
595 return took_ownership; | 603 return true; |
596 } | 604 } |
597 | 605 |
598 bool Tpm::GetRandomData(size_t length, chromeos::Blob* data) { | 606 bool Tpm::GetRandomData(size_t length, chromeos::Blob* data) { |
599 TSS_HCONTEXT context_handle; | 607 TSS_HCONTEXT context_handle; |
600 if (!OpenAndConnectTpm(&context_handle)) { | 608 if (!OpenAndConnectTpm(&context_handle)) { |
601 LOG(ERROR) << "Could not open the TPM"; | 609 LOG(ERROR) << "Could not open the TPM"; |
602 return false; | 610 return false; |
603 } | 611 } |
604 | 612 |
605 TSS_HTPM tpm_handle; | 613 TSS_HTPM tpm_handle; |
(...skipping 13 matching lines...) Expand all Loading... |
619 } | 627 } |
620 memcpy(random.data(), tpm_data, random.size()); | 628 memcpy(random.data(), tpm_data, random.size()); |
621 Tspi_Context_FreeMemory(context_handle, tpm_data); | 629 Tspi_Context_FreeMemory(context_handle, tpm_data); |
622 chromeos::SecureMemset(tpm_data, 0, random.size()); | 630 chromeos::SecureMemset(tpm_data, 0, random.size()); |
623 Tspi_Context_Close(context_handle); | 631 Tspi_Context_Close(context_handle); |
624 data->swap(random); | 632 data->swap(random); |
625 return true; | 633 return true; |
626 } | 634 } |
627 | 635 |
628 } // namespace tpm_init | 636 } // namespace tpm_init |
OLD | NEW |