Title: [123694] trunk/Source/WebCore
Revision
123694
Author
[email protected]
Date
2012-07-25 19:16:56 -0700 (Wed, 25 Jul 2012)

Log Message

[BlackBerry] Integrate certmgr with CredentialBackingStore
https://bugs.webkit.org/show_bug.cgi?id=92183

Patch by Jonathan Dong <[email protected]> on 2012-07-25
Reviewed by George Staikos.

Integrated BlackBerry::Platform::CertMgrWrapper with
CredentialBackingStore, when certmgr is ready we save
the password in certmgr and retrieve it from certmgr.

RIM PR: 171991
Internally reviewed by Joe Mason <[email protected]>.

No new tests since there's no functional change.

* platform/network/blackberry/CredentialBackingStore.cpp:
(WebCore::hashCredentialInfo):
(WebCore):
(WebCore::CredentialBackingStore::CredentialBackingStore):
(WebCore::CredentialBackingStore::open):
(WebCore::CredentialBackingStore::addLogin):
(WebCore::CredentialBackingStore::updateLogin):
(WebCore::CredentialBackingStore::getLogin):
* platform/network/blackberry/CredentialBackingStore.h:
(CredentialBackingStore):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (123693 => 123694)


--- trunk/Source/WebCore/ChangeLog	2012-07-26 02:14:27 UTC (rev 123693)
+++ trunk/Source/WebCore/ChangeLog	2012-07-26 02:16:56 UTC (rev 123694)
@@ -1,3 +1,30 @@
+2012-07-25  Jonathan Dong  <[email protected]>
+
+        [BlackBerry] Integrate certmgr with CredentialBackingStore
+        https://bugs.webkit.org/show_bug.cgi?id=92183
+
+        Reviewed by George Staikos.
+
+        Integrated BlackBerry::Platform::CertMgrWrapper with
+        CredentialBackingStore, when certmgr is ready we save
+        the password in certmgr and retrieve it from certmgr.
+
+        RIM PR: 171991
+        Internally reviewed by Joe Mason <[email protected]>.
+
+        No new tests since there's no functional change.
+
+        * platform/network/blackberry/CredentialBackingStore.cpp:
+        (WebCore::hashCredentialInfo):
+        (WebCore):
+        (WebCore::CredentialBackingStore::CredentialBackingStore):
+        (WebCore::CredentialBackingStore::open):
+        (WebCore::CredentialBackingStore::addLogin):
+        (WebCore::CredentialBackingStore::updateLogin):
+        (WebCore::CredentialBackingStore::getLogin):
+        * platform/network/blackberry/CredentialBackingStore.h:
+        (CredentialBackingStore):
+
 2012-07-25  Kent Tamura  <[email protected]>
 
         REGRESSION(r121420): Performance regression of form state saving for pages with multiple forms

Modified: trunk/Source/WebCore/platform/network/blackberry/CredentialBackingStore.cpp (123693 => 123694)


--- trunk/Source/WebCore/platform/network/blackberry/CredentialBackingStore.cpp	2012-07-26 02:14:27 UTC (rev 123693)
+++ trunk/Source/WebCore/platform/network/blackberry/CredentialBackingStore.cpp	2012-07-26 02:16:56 UTC (rev 123694)
@@ -29,6 +29,7 @@
 #include "SQLiteStatement.h"
 #include <BlackBerryPlatformClient.h>
 #include <BlackBerryPlatformEncryptor.h>
+#include <CertMgrWrapper.h>
 
 #define HANDLE_SQL_EXEC_FAILURE(statement, returnValue, ...) \
     if (statement) { \
@@ -38,6 +39,17 @@
 
 namespace WebCore {
 
+static unsigned hashCredentialInfo(const String& url, const ProtectionSpace& space, const String& username)
+{
+    String hashString = String::format("%s@%s@%s@%d@%d@%s@%d",
+                                       username.utf8().data(), url.utf8().data(),
+                                       space.host().utf8().data(), space.port(),
+                                       static_cast<int>(space.serverType()),
+                                       space.realm().utf8().data(),
+                                       static_cast<int>(space.authenticationScheme()));
+    return StringHasher::computeHash(hashString.characters(), hashString.length());
+}
+
 CredentialBackingStore& credentialBackingStore()
 {
     DEFINE_STATIC_LOCAL(CredentialBackingStore, backingStore, ());
@@ -57,6 +69,7 @@
     , m_hasNeverRememberStatement(0)
     , m_getNeverRememberStatement(0)
     , m_removeNeverRememberStatement(0)
+    , m_usingCertManager(BlackBerry::Platform::CertMgrWrapper::instance()->isReady())
 {
 }
 
@@ -125,11 +138,11 @@
     HANDLE_SQL_EXEC_FAILURE(m_hasLoginStatement->prepare() != SQLResultOk,
         false, "Failed to prepare hasLogin statement");
 
-    m_getLoginStatement = new SQLiteStatement(m_database, "SELECT username, password FROM logins WHERE host = ? AND port = ? AND service_type = ? AND realm = ? AND auth_scheme = ?");
+    m_getLoginStatement = new SQLiteStatement(m_database, "SELECT username, password, origin_url FROM logins WHERE host = ? AND port = ? AND service_type = ? AND realm = ? AND auth_scheme = ?");
     HANDLE_SQL_EXEC_FAILURE(m_getLoginStatement->prepare() != SQLResultOk,
         false, "Failed to prepare getLogin statement");
 
-    m_getLoginByURLStatement = new SQLiteStatement(m_database, "SELECT username, password FROM logins WHERE origin_url = ?");
+    m_getLoginByURLStatement = new SQLiteStatement(m_database, "SELECT username, password, host, port, service_type, realm, auth_scheme FROM logins WHERE origin_url = ?");
     HANDLE_SQL_EXEC_FAILURE(m_getLoginByURLStatement->prepare() != SQLResultOk,
         false, "Failed to prepare getLoginByURL statement");
 
@@ -171,14 +184,17 @@
     m_addLoginStatement->bindText(5, protectionSpace.realm());
     m_addLoginStatement->bindInt(6, static_cast<int>(protectionSpace.authenticationScheme()));
     m_addLoginStatement->bindText(7, credential.user());
-    m_addLoginStatement->bindBlob(8, encryptedString(credential.password()));
+    m_addLoginStatement->bindBlob(8, m_usingCertManager ? "" : encryptedString(credential.password()));
 
     int result = m_addLoginStatement->step();
     m_addLoginStatement->reset();
     HANDLE_SQL_EXEC_FAILURE(result != SQLResultDone, false,
         "Failed to add login info into table logins - %i", result);
 
-    return true;
+    if (!m_usingCertManager)
+        return true;
+    unsigned hash = hashCredentialInfo(url.string(), protectionSpace, credential.user());
+    return BlackBerry::Platform::CertMgrWrapper::instance()->savePassword(hash, encryptedString(credential.password()).latin1().data());
 }
 
 bool CredentialBackingStore::updateLogin(const KURL& url, const ProtectionSpace& protectionSpace, const Credential& credential)
@@ -190,7 +206,7 @@
         return false;
 
     m_updateLoginStatement->bindText(1, credential.user());
-    m_updateLoginStatement->bindBlob(2, encryptedString(credential.password()));
+    m_updateLoginStatement->bindBlob(2, m_usingCertManager ? "" : encryptedString(credential.password()));
     m_updateLoginStatement->bindText(3, url.string());
     m_updateLoginStatement->bindText(4, protectionSpace.host());
     m_updateLoginStatement->bindInt(5, protectionSpace.port());
@@ -203,7 +219,10 @@
     HANDLE_SQL_EXEC_FAILURE(result != SQLResultDone, false,
         "Failed to update login info in table logins - %i", result);
 
-    return true;
+    if (!m_usingCertManager)
+        return true;
+    unsigned hash = hashCredentialInfo(url.string(), protectionSpace, credential.user());
+    return BlackBerry::Platform::CertMgrWrapper::instance()->savePassword(hash, encryptedString(credential.password()).latin1().data());
 }
 
 bool CredentialBackingStore::hasLogin(const KURL& url, const ProtectionSpace& protectionSpace)
@@ -248,12 +267,20 @@
 
     int result = m_getLoginStatement->step();
     String username = m_getLoginStatement->getColumnText(0);
-    String password = m_getLoginStatement->getColumnBlobAsString(1);
+    String password = m_usingCertManager ? "" : m_getLoginStatement->getColumnBlobAsString(1);
+    String url = ""
     m_getLoginStatement->reset();
     HANDLE_SQL_EXEC_FAILURE(result != SQLResultRow, Credential(),
         "Failed to execute select login info from table logins in getLogin - %i", result);
 
-    return Credential(username, decryptedString(password), CredentialPersistencePermanent);
+    if (!m_usingCertManager)
+        return Credential(username, decryptedString(password), CredentialPersistencePermanent);
+
+    unsigned hash = hashCredentialInfo(url, protectionSpace, username);
+    std::string passwordBlob;
+    if (!BlackBerry::Platform::CertMgrWrapper::instance()->getPassword(hash, passwordBlob))
+        return Credential();
+    return Credential(username, decryptedString(passwordBlob.c_str()), CredentialPersistencePermanent);
 }
 
 Credential CredentialBackingStore::getLogin(const KURL& url)
@@ -268,12 +295,26 @@
 
     int result = m_getLoginByURLStatement->step();
     String username = m_getLoginByURLStatement->getColumnText(0);
-    String password = m_getLoginByURLStatement->getColumnBlobAsString(1);
+    String password = m_usingCertManager ? "" : m_getLoginByURLStatement->getColumnBlobAsString(1);
+    String host = m_getLoginByURLStatement->getColumnText(2);
+    int port = m_getLoginByURLStatement->getColumnInt(3);
+    int serviceType = m_getLoginByURLStatement->getColumnInt(4);
+    String realm = m_getLoginByURLStatement->getColumnText(5);
+    int authenticationScheme = m_getLoginByURLStatement->getColumnInt(6);
     m_getLoginByURLStatement->reset();
     HANDLE_SQL_EXEC_FAILURE(result != SQLResultRow, Credential(),
-        "Failed to execute select login info from table logins in getLogin - %i", result);
+        "Failed to execute select login info from table logins in getLoginByURL - %i", result);
 
-    return Credential(username, decryptedString(password), CredentialPersistencePermanent);
+    if (!m_usingCertManager)
+        return Credential(username, decryptedString(password), CredentialPersistencePermanent);
+
+    ProtectionSpace protectionSpace(host, port, static_cast<ProtectionSpaceServerType>(serviceType),
+                                    realm, static_cast<ProtectionSpaceAuthenticationScheme>(authenticationScheme));
+    unsigned hash = hashCredentialInfo(url, protectionSpace, username);
+    std::string passwordBlob;
+    if (!BlackBerry::Platform::CertMgrWrapper::instance()->getPassword(hash, passwordBlob))
+        return Credential();
+    return Credential(username, decryptedString(passwordBlob.c_str()), CredentialPersistencePermanent);
 }
 
 bool CredentialBackingStore::removeLogin(const KURL& url, const ProtectionSpace& protectionSpace)

Modified: trunk/Source/WebCore/platform/network/blackberry/CredentialBackingStore.h (123693 => 123694)


--- trunk/Source/WebCore/platform/network/blackberry/CredentialBackingStore.h	2012-07-26 02:14:27 UTC (rev 123693)
+++ trunk/Source/WebCore/platform/network/blackberry/CredentialBackingStore.h	2012-07-26 02:16:56 UTC (rev 123694)
@@ -64,6 +64,8 @@
     SQLiteStatement* m_hasNeverRememberStatement;
     SQLiteStatement* m_getNeverRememberStatement;
     SQLiteStatement* m_removeNeverRememberStatement;
+
+    bool m_usingCertManager;
 };
 
 CredentialBackingStore& credentialBackingStore();
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to