| OLD | NEW |
| 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 #ifndef ENTD_CRYPTO_PKCS11_H_ | 5 #ifndef ENTD_CRYPTO_PKCS11_H_ |
| 6 #define ENTD_CRYPTO_PKCS11_H_ | 6 #define ENTD_CRYPTO_PKCS11_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 private: | 118 private: |
| 119 SlotMap slot_map_; | 119 SlotMap slot_map_; |
| 120 }; | 120 }; |
| 121 | 121 |
| 122 class Session : public Scriptable<Session> { | 122 class Session : public Scriptable<Session> { |
| 123 public: | 123 public: |
| 124 static const std::string class_name() { | 124 static const std::string class_name() { |
| 125 return "entd.crypto.Pkcs11.Session"; | 125 return "entd.crypto.Pkcs11.Session"; |
| 126 }; | 126 }; |
| 127 | 127 |
| 128 Session() : session_handle_(0) {} | 128 Session() : session_handle_(0), logged_in_(false) {} |
| 129 ~Session() { | 129 ~Session() { |
| 130 if (logged_in_) |
| 131 C_Logout(session_handle_); |
| 130 if (session_handle_) | 132 if (session_handle_) |
| 131 C_CloseSession(session_handle_); | 133 C_CloseSession(session_handle_); |
| 132 } | 134 } |
| 133 | 135 |
| 134 bool Initialize(const CK_SLOT_ID slot_id, | 136 bool Initialize(const CK_SLOT_ID slot_id, |
| 135 const CK_SESSION_HANDLE& session_handle); | 137 const CK_SESSION_HANDLE& session_handle); |
| 136 static bool InitializeTemplate(v8::Handle<v8::FunctionTemplate> ctor_t); | 138 static bool InitializeTemplate(v8::Handle<v8::FunctionTemplate> ctor_t); |
| 137 | 139 |
| 138 v8::Handle<v8::Value> Construct(const v8::Arguments& args) { | 140 v8::Handle<v8::Value> Construct(const v8::Arguments& args) { |
| 139 return ThrowNoScriptableConstructor(); | 141 return ThrowNoScriptableConstructor(); |
| 140 } | 142 } |
| 141 | 143 |
| 142 // Call C_GetSessionInfo(), and copy the results to the js_object(). | 144 // Call C_GetSessionInfo(), and copy the results to the js_object(). |
| 143 bool Refresh(); | 145 bool Refresh(); |
| 144 | 146 |
| 145 // Stubs for PKCS#11 C_* functions of the same name. | 147 // Stubs for PKCS#11 C_* functions of the same name. |
| 146 v8::Handle<v8::Value> Close(const v8::Arguments& args); | 148 v8::Handle<v8::Value> Close(const v8::Arguments& args); |
| 147 v8::Handle<v8::Value> Login(const v8::Arguments& args); | 149 v8::Handle<v8::Value> Login(const v8::Arguments& args); |
| 148 v8::Handle<v8::Value> Logout(const v8::Arguments& args); | 150 v8::Handle<v8::Value> Logout(const v8::Arguments& args); |
| 149 v8::Handle<v8::Value> InitPin(const v8::Arguments& args); | 151 v8::Handle<v8::Value> InitPin(const v8::Arguments& args); |
| 150 v8::Handle<v8::Value> SetPin(const v8::Arguments& args); | 152 v8::Handle<v8::Value> SetPin(const v8::Arguments& args); |
| 151 v8::Handle<v8::Value> FindObjects(const v8::Arguments& args); | 153 v8::Handle<v8::Value> FindObjects(const v8::Arguments& args); |
| 152 v8::Handle<v8::Value> CreateObject(const v8::Arguments& args); | 154 v8::Handle<v8::Value> CreateObject(const v8::Arguments& args); |
| 153 v8::Handle<v8::Value> GenerateKeyPair(const v8::Arguments& args); | 155 v8::Handle<v8::Value> GenerateKeyPair(const v8::Arguments& args); |
| 154 | 156 |
| 157 // Helper functions. |
| 158 v8::Handle<v8::Value> LogoutAndClose(const v8::Arguments& args); |
| 159 |
| 155 // Invoke the 'bool Refresh()' method from script. | 160 // Invoke the 'bool Refresh()' method from script. |
| 156 v8::Handle<v8::Value> CallRefresh(const v8::Arguments& args); | 161 v8::Handle<v8::Value> CallRefresh(const v8::Arguments& args); |
| 157 | 162 |
| 158 private: | 163 private: |
| 159 CK_SLOT_ID slot_id_; | 164 CK_SLOT_ID slot_id_; |
| 160 CK_SESSION_HANDLE session_handle_; | 165 CK_SESSION_HANDLE session_handle_; |
| 166 bool logged_in_; |
| 161 }; | 167 }; |
| 162 | 168 |
| 163 class Object : public Scriptable<Object> { | 169 class Object : public Scriptable<Object> { |
| 164 public: | 170 public: |
| 165 static const std::string class_name() { | 171 static const std::string class_name() { |
| 166 return "entd.crypto.Pkcs11.Object"; | 172 return "entd.crypto.Pkcs11.Object"; |
| 167 }; | 173 }; |
| 168 | 174 |
| 169 Object() : session_handle_(0), object_handle_(0) {} | 175 Object() : session_handle_(0), object_handle_(0) {} |
| 170 ~Object() {} | 176 ~Object() {} |
| (...skipping 25 matching lines...) Expand all Loading... |
| 196 // This can be called multiple times. It will keep trying to initialize the | 202 // This can be called multiple times. It will keep trying to initialize the |
| 197 // library until it succeeds, then it will become a no-op. | 203 // library until it succeeds, then it will become a no-op. |
| 198 static CK_RV InitializeLibrary(); | 204 static CK_RV InitializeLibrary(); |
| 199 }; | 205 }; |
| 200 | 206 |
| 201 } // namespace crypto | 207 } // namespace crypto |
| 202 | 208 |
| 203 } // namespace entd | 209 } // namespace entd |
| 204 | 210 |
| 205 #endif // ENTD_CRYPTO_PKCS11_H_ | 211 #endif // ENTD_CRYPTO_PKCS11_H_ |
| OLD | NEW |