)
SET(SW_BACKEND_SOURCES
+ generic-backend/ipassword.cpp
generic-backend/password-file-buffer.cpp
sw-backend/password-file.cpp
)
)
SET(TZ_BACKEND_SOURCES
+ generic-backend/ipassword.cpp
+ generic-backend/password-file-buffer.cpp
tz-backend/password-file.cpp
)
#ifndef _IPASSWORD_FILE_H_
#define _IPASSWORD_FILE_H_
+#include <generic-backend/ipassword.h>
+
#include <string>
-#include <memory>
#include <time.h>
-#include <limits>
-
namespace AuthPasswd {
-constexpr time_t PASSWORD_INFINITE_EXPIRATION_TIME = std::numeric_limits<time_t>::max();
-
struct IPasswordFile {
IPasswordFile() = default;
virtual ~IPasswordFile() = default;
virtual void setPassword(unsigned int passwdType, const std::string &password) = 0;
virtual bool checkPassword(unsigned int passwdType,
- const std::string &password) const = 0;
+ const std::string &password) = 0;
virtual bool isPasswordActive(unsigned int passwdType) const = 0;
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+#include <generic-backend/ipassword.h>
+#include <generic-backend/password-file-buffer.h>
+
+#include <error-description.h>
+#include <password-exception.h>
+
+#include <dpl/fstream_accessors.h>
+
+#include <openssl/sha.h>
+
+namespace AuthPasswd {
+
+NoPassword::NoPassword(IStream&)
+{
+}
+
+void NoPassword::Serialize(IStream &stream) const
+{
+ Serialization::Serialize(stream, static_cast<unsigned int>(PasswordType::NONE));
+}
+
+bool NoPassword::match(const std::string &pass) const
+{
+ return pass.empty();
+}
+
+SHA256Password::SHA256Password(IStream &stream)
+{
+ Deserialization::Deserialize(stream, m_hash);
+}
+
+SHA256Password::SHA256Password(const std::string &password) : m_hash(hash(password))
+{
+}
+
+SHA256Password::SHA256Password(const RawHash ¶mHash) : m_hash(paramHash)
+{
+}
+
+void SHA256Password::Serialize(IStream &stream) const
+{
+ Serialization::Serialize(stream, static_cast<unsigned int>(PasswordType::SHA256));
+ Serialization::Serialize(stream, m_hash);
+}
+
+bool SHA256Password::match(const std::string &password) const
+{
+ return m_hash == hash(password);
+}
+
+RawHash SHA256Password::hash(const std::string &password)
+{
+ RawHash result(SHA256_DIGEST_LENGTH);
+ SHA256_CTX context;
+ SHA256_Init(&context);
+ SHA256_Update(&context, reinterpret_cast<const unsigned char *>(password.c_str()),
+ password.size());
+ SHA256_Final(result.data(), &context);
+ return result;
+}
+
+template <>
+void Deserialization::Deserialize(IStream &stream, IPasswordPtr &ptr)
+{
+ unsigned int algorithm;
+ Deserialization::Deserialize(stream, algorithm);
+
+ switch (algorithm) {
+ case (unsigned int)IPassword::PasswordType::NONE:
+ ptr.reset(new NoPassword());
+ break;
+
+ case (unsigned int)IPassword::PasswordType::SHA256:
+ ptr.reset(new SHA256Password(stream));
+ break;
+
+ default:
+ Throw(PasswordException::FStreamReadError);
+ }
+}
+
+} //namespace AuthPasswd
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+#ifndef _IPASSWORD_H_
+#define _IPASSWORD_H_
+
+#include <string>
+#include <memory>
+#include <limits>
+
+#include <time.h>
+
+#include <dpl/serialization.h>
+
+namespace AuthPasswd {
+
+constexpr time_t PASSWORD_INFINITE_EXPIRATION_TIME = std::numeric_limits<time_t>::max();
+
+struct IPassword;
+using RawHash = std::vector<unsigned char>;
+using IPasswordPtr = std::shared_ptr<IPassword>;
+using PasswordList = std::list<IPasswordPtr>;
+
+struct IPassword: public ISerializable {
+
+ enum class PasswordType : unsigned int {
+ NONE = 0,
+ SHA256 = 1,
+ };
+
+ virtual bool match(const std::string &password) const = 0;
+};
+
+class NoPassword: public IPassword {
+public:
+ NoPassword() = default;
+ NoPassword(IStream &);
+
+ void Serialize(IStream &stream) const;
+ bool match(const std::string &pass) const;
+};
+
+class SHA256Password: public IPassword {
+public:
+ SHA256Password(IStream &stream);
+ SHA256Password(const std::string &password);
+ SHA256Password(const RawHash ¶mHash);
+
+ void Serialize(IStream &stream) const;
+ bool match(const std::string &password) const;
+
+private:
+ static RawHash hash(const std::string &password);
+
+ RawHash m_hash;
+};
+
+template <>
+void Deserialization::Deserialize(IStream &stream, IPasswordPtr &ptr);
+
+} //namespace AuthPasswd
+
+#endif
#include <sys/stat.h>
#include <unistd.h>
-#include <openssl/sha.h>
-
#include <dpl/log/log.h>
#include <dpl/fstream_accessors.h>
} // namespace anonymous
namespace AuthPasswd {
-
-class NoPassword: public IPassword {
-public:
- NoPassword(IStream &) {}
- NoPassword() {}
-
- void Serialize(IStream &stream) const {
- Serialization::Serialize(stream, static_cast<unsigned int>(PasswordType::NONE));
- }
-
- bool match(const std::string &pass) const {
- return pass.empty();
- }
-};
-
-class SHA256Password: public IPassword {
-public:
- SHA256Password(IStream &stream) {
- Deserialization::Deserialize(stream, m_hash);
- }
-
- SHA256Password(const std::string &password) : m_hash(hash(password)) {}
-
- SHA256Password(const RawHash ¶mHash) : m_hash(paramHash) {}
-
- void Serialize(IStream &stream) const {
- Serialization::Serialize(stream, static_cast<unsigned int>(PasswordType::SHA256));
- Serialization::Serialize(stream, m_hash);
- }
-
- bool match(const std::string &password) const {
- return m_hash == hash(password);
- }
-
-private:
- RawHash m_hash;
-
- static RawHash hash(const std::string &password) {
- RawHash result(SHA256_DIGEST_LENGTH);
- SHA256_CTX context;
- SHA256_Init(&context);
- SHA256_Update(&context, reinterpret_cast<const unsigned char *>(password.c_str()),
- password.size());
- SHA256_Final(result.data(), &context);
- return result;
- }
-};
-
-template <>
-void Deserialization::Deserialize(IStream &stream, IPasswordPtr &ptr)
-{
- unsigned int algorithm;
- Deserialization::Deserialize(stream, algorithm);
-
- switch (algorithm) {
- case (unsigned int)IPassword::PasswordType::NONE:
- ptr.reset(new NoPassword());
- break;
-
- case (unsigned int)IPassword::PasswordType::SHA256:
- ptr.reset(new SHA256Password(stream));
- break;
-
- default:
- Throw(PasswordException::FStreamReadError);
- }
-}
-
namespace SWBackend {
PasswordFile::PasswordFile(unsigned int user) :
}
}
-bool PasswordFile::checkPassword(unsigned int passwdType, const std::string &password) const
+bool PasswordFile::checkPassword(unsigned int passwdType, const std::string &password)
{
if (passwdType != AUTH_PWD_NORMAL)
return false;
#include <generic-backend/ipassword-file.h>
namespace AuthPasswd {
-
-struct IPassword: public ISerializable {
- typedef std::vector<unsigned char> RawHash;
-
- enum class PasswordType : unsigned int {
- NONE = 0,
- SHA256 = 1,
- };
-
- virtual bool match(const std::string &password) const = 0;
-};
-
-using IPasswordPtr = std::shared_ptr<IPassword>;
-using PasswordList = std::list<IPasswordPtr>;
-
namespace SWBackend {
class PasswordFile : public IPasswordFile {
void setPassword(unsigned int passwdType, const std::string &password) override;
bool checkPassword(unsigned int passwdType,
- const std::string &password) const override;
+ const std::string &password) override;
bool isPasswordActive(unsigned int passwdType) const override;
}
bool PasswordFile::checkPassword(unsigned int,
- const std::string &) const
+ const std::string &)
{
std::runtime_error("TZ-Backend is not implemented.");
return false;
void setPassword(unsigned int passwdType, const std::string &password) override;
bool checkPassword(unsigned int passwdType,
- const std::string &password) const override;
+ const std::string &password) override;
void setMaxHistorySize(unsigned int history) override;
unsigned int getMaxHistorySize() const override;
INCLUDE_DIRECTORIES(SYSTEM ${${TARGET_TEST}_DEP_INCLUDE_DIRS}
${INCLUDE_PATH}
+ ${COMMON_PATH}/include
${SERVER_PATH}/service/include
${DPL_PATH}/core/include
${DPL_PATH}/log/include
SET_TARGET_PROPERTIES(${TARGET_TEST} PROPERTIES LINK_FLAGS "-pie")
INSTALL(TARGETS ${TARGET_TEST}
- DESTINATION bin
+ DESTINATION ${BIN_DIR}
PERMISSIONS OWNER_READ
OWNER_WRITE
OWNER_EXECUTE