Skip to content

Commit

Permalink
Remove crypto::GetTPMTokenInfo which is no longer necessary.
Browse files Browse the repository at this point in the history
BUG=none

Review URL: https://codereview.chromium.org/83833003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@237150 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
mattm@chromium.org committed Nov 25, 2013
1 parent e703dfe commit bee9b54
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 87 deletions.
8 changes: 0 additions & 8 deletions chrome/browser/resources/chromeos/cryptohome.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,6 @@ <h3>crypto:</h3>
<td>IsTPMTokenReady</td>
<td id="is-tpm-token-ready"></td>
</tr>
<tr>
<td>token_name</td>
<td id="token-name"></td>
</tr>
<tr>
<td>user_pin</td>
<td id="user-pin"></td>
</tr>
</table>
</body>
</html>
39 changes: 5 additions & 34 deletions chrome/browser/ui/webui/chromeos/cryptohome_web_ui_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,6 @@

using content::BrowserThread;

namespace {
void GetNSSUtilInfoOnIOThread(const base::Callback<
void(bool, const std::string&, const std::string&)>& ui_callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));

bool is_tpm_ready = crypto::IsTPMTokenReady();
std::string token_name;
std::string user_pin;
if (is_tpm_ready)
crypto::GetTPMTokenInfo(&token_name, &user_pin);

BrowserThread::PostTask(
BrowserThread::UI,
FROM_HERE,
base::Bind(ui_callback, is_tpm_ready, token_name, user_pin));
}
} // namespace

namespace chromeos {

CryptohomeWebUIHandler::CryptohomeWebUIHandler() : weak_ptr_factory_(this) {}
Expand All @@ -58,31 +40,20 @@ void CryptohomeWebUIHandler::OnPageLoaded(const base::ListValue* args) {
cryptohome_client->Pkcs11IsTpmTokenReady(
GetCryptohomeBoolCallback("pkcs11-is-tpm-token-ready"));

BrowserThread::PostTask(
BrowserThread::PostTaskAndReplyWithResult(
BrowserThread::IO,
FROM_HERE,
base::Bind(
&GetNSSUtilInfoOnIOThread,
base::Bind(&CryptohomeWebUIHandler::DidGetNSSUtilInfoOnUIThread,
weak_ptr_factory_.GetWeakPtr())));
base::Bind(&crypto::IsTPMTokenReady),
base::Bind(&CryptohomeWebUIHandler::DidGetNSSUtilInfoOnUIThread,
weak_ptr_factory_.GetWeakPtr()));
}

void CryptohomeWebUIHandler::DidGetNSSUtilInfoOnUIThread(
bool is_tpm_token_ready,
const std::string& token_name,
const std::string& user_pin) {
bool is_tpm_token_ready) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));

base::FundamentalValue is_tpm_token_ready_value(is_tpm_token_ready);
SetCryptohomeProperty("is-tpm-token-ready", is_tpm_token_ready_value);

if (is_tpm_token_ready) {
base::StringValue token_name_value(token_name);
SetCryptohomeProperty("token-name", token_name_value);
// Hide user_pin.
base::StringValue user_pin_value(std::string(user_pin.length(), '*'));
SetCryptohomeProperty("user-pin", user_pin_value);
}
}

BoolDBusMethodCallback CryptohomeWebUIHandler::GetCryptohomeBoolCallback(
Expand Down
4 changes: 1 addition & 3 deletions chrome/browser/ui/webui/chromeos/cryptohome_web_ui_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ class CryptohomeWebUIHandler : public content::WebUIMessageHandler {
// This method is called from JavaScript.
void OnPageLoaded(const base::ListValue* args);

void DidGetNSSUtilInfoOnUIThread(bool is_tpm_token_ready,
const std::string& token_name,
const std::string& user_pin);
void DidGetNSSUtilInfoOnUIThread(bool is_tpm_token_ready);

// Returns a callback to handle Cryptohome property values.
BoolDBusMethodCallback GetCryptohomeBoolCallback(
Expand Down
5 changes: 1 addition & 4 deletions chromeos/cert_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,7 @@ void CertLoader::InitializeTokenAndLoadCertificates() {
base::PostTaskAndReplyWithResult(
crypto_task_runner_.get(),
FROM_HERE,
base::Bind(&crypto::InitializeTPMToken,
tpm_token_name_,
tpm_token_slot_id_,
tpm_user_pin_),
base::Bind(&crypto::InitializeTPMToken, tpm_token_slot_id_),
base::Bind(&CertLoader::OnTPMTokenInitialized,
initialize_token_factory_.GetWeakPtr()));
return;
Expand Down
32 changes: 3 additions & 29 deletions crypto/nss_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,7 @@ class NSSInitSingleton {
tpm_token_enabled_for_nss_ = true;
}

bool InitializeTPMToken(const std::string& token_name,
int token_slot_id,
const std::string& user_pin) {
bool InitializeTPMToken(int token_slot_id) {
DCHECK(thread_checker_.CalledOnValidThread());

// If EnableTPMTokenForNSS hasn't been called, return false.
Expand All @@ -247,9 +245,6 @@ class NSSInitSingleton {
if (chaps_module_ && tpm_slot_)
return true;

tpm_token_name_ = token_name;
tpm_user_pin_ = user_pin;

// This tries to load the Chaps module so NSS can talk to the hardware
// TPM.
if (!chaps_module_) {
Expand Down Expand Up @@ -277,18 +272,6 @@ class NSSInitSingleton {
return false;
}

void GetTPMTokenInfo(std::string* token_name, std::string* user_pin) {
DCHECK(thread_checker_.CalledOnValidThread());
if (!tpm_token_enabled_for_nss_) {
LOG(ERROR) << "GetTPMTokenInfo called before TPM Token is ready.";
return;
}
if (token_name)
*token_name = tpm_token_name_;
if (user_pin)
*user_pin = tpm_user_pin_;
}

bool IsTPMTokenReady() {
// TODO(mattm): Change to DCHECK when callers have been fixed.
if (!thread_checker_.CalledOnValidThread()) {
Expand Down Expand Up @@ -629,8 +612,6 @@ class NSSInitSingleton {
static bool force_nodb_init_;

bool tpm_token_enabled_for_nss_;
std::string tpm_token_name_;
std::string tpm_user_pin_;
SECMODModule* chaps_module_;
PK11SlotInfo* software_slot_;
PK11SlotInfo* test_slot_;
Expand Down Expand Up @@ -800,19 +781,12 @@ void EnableTPMTokenForNSS() {
g_nss_singleton.Get().EnableTPMTokenForNSS();
}

void GetTPMTokenInfo(std::string* token_name, std::string* user_pin) {
g_nss_singleton.Get().GetTPMTokenInfo(token_name, user_pin);
}

bool IsTPMTokenReady() {
return g_nss_singleton.Get().IsTPMTokenReady();
}

bool InitializeTPMToken(const std::string& token_name,
int token_slot_id,
const std::string& user_pin) {
return g_nss_singleton.Get().InitializeTPMToken(
token_name, token_slot_id, user_pin);
bool InitializeTPMToken(int token_slot_id) {
return g_nss_singleton.Get().InitializeTPMToken(token_slot_id);
}
#endif // defined(OS_CHROMEOS)

Expand Down
10 changes: 1 addition & 9 deletions crypto/nss_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,14 @@ CRYPTO_EXPORT void OpenPersistentNSSDB();
// GetPrivateNSSKeySlot() will return the TPM slot if one was found.
CRYPTO_EXPORT void EnableTPMTokenForNSS();

// Get name and user PIN for the built-in TPM token on ChromeOS.
// Either one can safely be NULL. Should only be called after
// EnableTPMTokenForNSS has been called with a non-null delegate.
CRYPTO_EXPORT void GetTPMTokenInfo(std::string* token_name,
std::string* user_pin);

// Returns true if the TPM is owned and PKCS#11 initialized with the
// user and security officer PINs, and has been enabled in NSS by
// calling EnableTPMForNSS, and Chaps has been successfully
// loaded into NSS.
CRYPTO_EXPORT bool IsTPMTokenReady();

// Initialize the TPM token. Does nothing if it is already initialized.
CRYPTO_EXPORT bool InitializeTPMToken(const std::string& token_name,
int token_slot_id,
const std::string& user_pin);
CRYPTO_EXPORT bool InitializeTPMToken(int token_slot_id);
#endif

// Convert a NSS PRTime value into a base::Time object.
Expand Down

0 comments on commit bee9b54

Please sign in to comment.