summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjooseong lee <jooseong.lee@samsung.com>2016-08-24 20:39:21 +0900
committerjooseong lee <jooseong.lee@samsung.com>2016-08-25 10:36:24 +0900
commitfab6e67ea43cb76dd818c5e9b7eab6aa5b20274f (patch)
treec5794a9ea429e355889657382757585e4eb0c499
parent0e3e87f1c1575ec776df45b31583bdbee86eb068 (diff)
downloadauth-fw-accepted/tizen/ivi/20160830.060812.tar.gz
auth-fw-accepted/tizen/ivi/20160830.060812.tar.bz2
auth-fw-accepted/tizen/ivi/20160830.060812.zip
We should load old format password file after Tizen platform upgrade. (2.4->3.0) Refer to: https://review.tizen.org/gerrit/#/c/85383/ Change-Id: Ied40ac768f6b083f1670393a3f9221571aa6f5b6 Signed-off-by: jooseong lee <jooseong.lee@samsung.com>
-rw-r--r--src/server/service/password-file.cpp66
1 files changed, 16 insertions, 50 deletions
diff --git a/src/server/service/password-file.cpp b/src/server/service/password-file.cpp
index 2b015b2..af823c5 100644
--- a/src/server/service/password-file.cpp
+++ b/src/server/service/password-file.cpp
@@ -54,7 +54,7 @@ const std::string OLD_VERSION_PASSWORD_FILE = "/password.old";
const std::string ATTEMPT_FILE = "/attempt";
const double RETRY_TIMEOUT = 0.5;
const mode_t FILE_MODE = S_IRUSR | S_IWUSR;
-const unsigned int CURRENT_FILE_VERSION = 1;
+const unsigned int CURRENT_FILE_VERSION = 4;
} // namespace anonymous
namespace AuthPasswd {
@@ -330,64 +330,30 @@ bool PasswordFile::tryLoadMemoryFromOldFormatFile()
if (stat(oldVersionPwdFile.c_str(), &oldFileStat) != 0)
return false;
- static const int ELEMENT_SIZE = sizeof(unsigned) + SHA256_DIGEST_LENGTH;
- static const int VERSION_1_REMAINING = sizeof(unsigned) * 4;
- static const int VERSION_2_REMAINING = VERSION_1_REMAINING + sizeof(bool);
- int remaining = oldFileStat.st_size % ELEMENT_SIZE;
-
- if (remaining != VERSION_1_REMAINING && remaining != VERSION_2_REMAINING)
- return false;
+ PasswordFileBuffer pwdBuffer;
+ pwdBuffer.Load(oldVersionPwdFile);
+ unsigned int fileVersion = 0;
+ Deserialization::Deserialize(pwdBuffer, fileVersion);
- try {
- PasswordFileBuffer pwdBuffer;
- pwdBuffer.Load(oldVersionPwdFile);
+ switch (fileVersion) {
+ case 1:
+ case 2:
+ case 3:
Deserialization::Deserialize(pwdBuffer, m_maxAttempt);
Deserialization::Deserialize(pwdBuffer, m_maxHistorySize);
Deserialization::Deserialize(pwdBuffer, m_expireTimeLeft);
-
- if (m_expireTimeLeft == 0)
- m_expireTimeLeft = PASSWORD_INFINITE_EXPIRATION_TIME;
-
- if (remaining == VERSION_2_REMAINING)
- Deserialization::Deserialize(pwdBuffer, m_passwordActive);
- else
- m_passwordActive = true;
-
- // deserialize passwords in old format
- struct OldPassword {
- OldPassword() {}
- OldPassword(IStream &stream) {
- Deserialization::Deserialize(stream, m_hash);
- }
- IPassword::RawHash m_hash;
- };
- std::list<OldPassword> oldFormatPasswords;
- Deserialization::Deserialize(pwdBuffer, oldFormatPasswords);
- // convert passwords to new format
- m_passwordHistory.clear();
-
- if (oldFormatPasswords.empty()) {
- m_passwordCurrent.reset(new NoPassword());
- m_passwordActive = false;
- } else {
- m_passwordCurrent.reset(new SHA256Password(oldFormatPasswords.front().m_hash));
- std::for_each(
- ++oldFormatPasswords.begin(),
- oldFormatPasswords.end(),
- [&](const OldPassword & pwd) {
- m_passwordHistory.push_back(IPasswordPtr(new SHA256Password(pwd.m_hash)));
- });
- }
+ Deserialization::Deserialize(pwdBuffer, m_passwordActive);
+ Deserialization::Deserialize(pwdBuffer, m_passwordCurrent);
+ Deserialization::Deserialize(pwdBuffer, m_passwordHistory);
m_expireTime = PASSWORD_INFINITE_EXPIRATION_DAYS;
m_passwordRcvActive = false;
m_passwordRecovery.reset(new NoPassword());
- } catch (...) {
- LogWarning("Invalid " << oldVersionPwdFile << " file format");
- resetState();
- return false;
+ break;
+ default:
+ LogError("Invaild password version: " << fileVersion);
+ Throw(PasswordException::FStreamReadError);
}
-
return true;
}