Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Side by Side Diff: crypto_pkcs11.cc

Issue 6338003: Explicitly logging out the token to avoid leaving it in a non-stable state. (Closed) Base URL: http://git.chromium.org/git/entd.git@master
Patch Set: Adding helper method 'logoutAndClose'. Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« base_policy/policy-utils.js ('K') | « crypto_pkcs11.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 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 #include "entd/crypto_pkcs11.h" 5 #include "entd/crypto_pkcs11.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include <chromeos/utility.h> 10 #include <chromeos/utility.h>
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 BindMethod(instance_t, &Pkcs11::Session::CallRefresh, "refresh"); 492 BindMethod(instance_t, &Pkcs11::Session::CallRefresh, "refresh");
493 BindMethod(instance_t, &Pkcs11::Session::Close, "close"); 493 BindMethod(instance_t, &Pkcs11::Session::Close, "close");
494 BindMethod(instance_t, &Pkcs11::Session::Login, "login"); 494 BindMethod(instance_t, &Pkcs11::Session::Login, "login");
495 BindMethod(instance_t, &Pkcs11::Session::Logout, "logout"); 495 BindMethod(instance_t, &Pkcs11::Session::Logout, "logout");
496 BindMethod(instance_t, &Pkcs11::Session::InitPin, "initPin"); 496 BindMethod(instance_t, &Pkcs11::Session::InitPin, "initPin");
497 BindMethod(instance_t, &Pkcs11::Session::SetPin, "setPin"); 497 BindMethod(instance_t, &Pkcs11::Session::SetPin, "setPin");
498 BindMethod(instance_t, &Pkcs11::Session::GenerateKeyPair, "generateKeyPair"); 498 BindMethod(instance_t, &Pkcs11::Session::GenerateKeyPair, "generateKeyPair");
499 BindMethod(instance_t, &Pkcs11::Session::FindObjects, "findObjects"); 499 BindMethod(instance_t, &Pkcs11::Session::FindObjects, "findObjects");
500 BindMethod(instance_t, &Pkcs11::Session::CreateObject, "createObject"); 500 BindMethod(instance_t, &Pkcs11::Session::CreateObject, "createObject");
501 501
502 BindMethod(instance_t, &Pkcs11::Session::LogoutAndClose, "logoutAndClose");
503
502 return true; 504 return true;
503 } 505 }
504 506
505 bool Pkcs11::Session::Refresh() { 507 bool Pkcs11::Session::Refresh() {
506 CK_SESSION_INFO session_info; 508 CK_SESSION_INFO session_info;
507 CK_RV rv = C_GetSessionInfo(session_handle_, &session_info); 509 CK_RV rv = C_GetSessionInfo(session_handle_, &session_info);
508 if (!OkOrWarn(rv)) 510 if (!OkOrWarn(rv))
509 return false; 511 return false;
510 512
511 v8::Handle<v8::Object> self = js_object(); 513 v8::Handle<v8::Object> self = js_object();
(...skipping 24 matching lines...) Expand all
536 reinterpret_cast<CK_CHAR_PTR>(*ascii_pin), 538 reinterpret_cast<CK_CHAR_PTR>(*ascii_pin),
537 ascii_pin.length())); 539 ascii_pin.length()));
538 540
539 return v8::Undefined(); 541 return v8::Undefined();
540 } 542 }
541 543
542 v8::Handle<v8::Value> Pkcs11::Session::Close(const v8::Arguments& args) { 544 v8::Handle<v8::Value> Pkcs11::Session::Close(const v8::Arguments& args) {
543 if (!session_handle_) 545 if (!session_handle_)
544 return ThrowException("Not open"); 546 return ThrowException("Not open");
545 547
548 if (logged_in_) {
549 OkOrThrow(C_Logout(session_handle_));
rginda 2011/01/18 22:10:19 You should return early if this throws.
Nelson Araujo 2011/01/18 22:50:19 Done.
550 logged_in_ = false;
551 }
552
546 OkOrThrow(C_CloseSession(session_handle_)); 553 OkOrThrow(C_CloseSession(session_handle_));
547 session_handle_ = 0; 554 session_handle_ = 0;
548 return v8::Undefined(); 555 return v8::Undefined();
549 } 556 }
550 557
551 v8::Handle<v8::Value> Pkcs11::Session::Login(const v8::Arguments& args) { 558 v8::Handle<v8::Value> Pkcs11::Session::Login(const v8::Arguments& args) {
552 if (args.Length() < 1) 559 if (args.Length() < 1)
553 return ThrowException("Missing required parameter: userType"); 560 return ThrowException("Missing required parameter: userType");
554 561
555 uint32_t user_type = args[0]->Uint32Value(); 562 uint32_t user_type = args[0]->Uint32Value();
556 if (user_type != CKU_USER && user_type != CKU_SO) 563 if (user_type != CKU_USER && user_type != CKU_SO)
557 return ThrowException("Invalid value for parameter: userType"); 564 return ThrowException("Invalid value for parameter: userType");
558 565
559 if (args.Length() < 2) 566 if (args.Length() < 2)
560 return ThrowException("Missing required parameter: pin"); 567 return ThrowException("Missing required parameter: pin");
561 568
562 v8::String::AsciiValue ascii_pin(args[1]); 569 v8::String::AsciiValue ascii_pin(args[1]);
563 570
571 logged_in_ = false;
572
564 CK_RV rv = C_Login(session_handle_, user_type, 573 CK_RV rv = C_Login(session_handle_, user_type,
565 reinterpret_cast<CK_CHAR_PTR>(*ascii_pin), 574 reinterpret_cast<CK_CHAR_PTR>(*ascii_pin),
566 ascii_pin.length()); 575 ascii_pin.length());
567 576
568 if (rv == CKR_PIN_INCORRECT) 577 if (rv == CKR_PIN_INCORRECT)
569 return v8::False(); 578 return v8::False();
570 579
571 if (!OkOrThrow(rv)) 580 if (!OkOrThrow(rv))
572 return v8::Undefined(); 581 return v8::Undefined();
573 582
583 logged_in_ = true;
574 return v8::True(); 584 return v8::True();
575 } 585 }
576 586
577 v8::Handle<v8::Value> Pkcs11::Session::Logout(const v8::Arguments& args) { 587 v8::Handle<v8::Value> Pkcs11::Session::Logout(const v8::Arguments& args) {
578 OkOrThrow(C_Logout(session_handle_)); 588 OkOrThrow(C_Logout(session_handle_));
589 logged_in_ = false;
579 return v8::Undefined(); 590 return v8::Undefined();
580 } 591 }
581 592
593 v8::Handle<v8::Value> Pkcs11::Session::LogoutAndClose(
594 const v8::Arguments& args) {
595 Logout(args);
596 Close(args);
597 return v8::Undefined();
598 }
599
582 v8::Handle<v8::Value> Pkcs11::Session::SetPin(const v8::Arguments& args) { 600 v8::Handle<v8::Value> Pkcs11::Session::SetPin(const v8::Arguments& args) {
583 if (args.Length() < 1) 601 if (args.Length() < 1)
584 return ThrowException("Missing required parameter: oldPin"); 602 return ThrowException("Missing required parameter: oldPin");
585 603
586 v8::String::AsciiValue old_pin(args[0]); 604 v8::String::AsciiValue old_pin(args[0]);
587 605
588 if (args.Length() < 2) 606 if (args.Length() < 2)
589 return ThrowException("Missing required parameter: newPin"); 607 return ThrowException("Missing required parameter: newPin");
590 608
591 v8::String::AsciiValue new_pin(args[1]); 609 v8::String::AsciiValue new_pin(args[1]);
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after
1294 SET_CK_CONST(ctor_t, CKR_MUTEX_BAD); 1312 SET_CK_CONST(ctor_t, CKR_MUTEX_BAD);
1295 SET_CK_CONST(ctor_t, CKR_MUTEX_NOT_LOCKED); 1313 SET_CK_CONST(ctor_t, CKR_MUTEX_NOT_LOCKED);
1296 SET_CK_CONST(ctor_t, CKR_VENDOR_DEFINED); 1314 SET_CK_CONST(ctor_t, CKR_VENDOR_DEFINED);
1297 1315
1298 return true; 1316 return true;
1299 } 1317 }
1300 1318
1301 } // namespace crypto 1319 } // namespace crypto
1302 1320
1303 } // namespace entd 1321 } // namespace entd
OLDNEW
« base_policy/policy-utils.js ('K') | « crypto_pkcs11.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698