Browse Source

pfMacPasswordStore implementation.

Conflicts:
	Sources/Plasma/FeatureLib/pfPasswordStore/pfPasswordStore_impl.h
Darryl Pogue 10 years ago committed by Joseph Davies
parent
commit
1554546bdb
  1. 5
      Sources/Plasma/FeatureLib/pfPasswordStore/CMakeLists.txt
  2. 53
      Sources/Plasma/FeatureLib/pfPasswordStore/pfPasswordStore.cpp
  3. 12
      Sources/Plasma/FeatureLib/pfPasswordStore/pfPasswordStore_impl.h

5
Sources/Plasma/FeatureLib/pfPasswordStore/CMakeLists.txt

@ -15,6 +15,11 @@ set(pfPasswordStore_SOURCES
add_library(pfPasswordStore STATIC ${pfPasswordStore_HEADERS} ${pfPasswordStore_SOURCES})
target_link_libraries(pfPasswordStore CoreLib plFile)
if(APPLE)
find_library(SECURITY_LIBRARY Security)
target_link_libraries(pfPasswordStore ${SECURITY_LIBRARY})
endif(APPLE)
source_group("Header Files" FILES ${pfPasswordStore_HEADERS})
source_group("Source Files" FILES ${pfPasswordStore_SOURCES})

53
Sources/Plasma/FeatureLib/pfPasswordStore/pfPasswordStore.cpp

@ -54,8 +54,12 @@ pfPasswordStore* pfPasswordStore::Instance()
if (store == nullptr) {
#ifdef HS_BUILD_FOR_WIN32
store = new pfWin32PasswordStore();
#else
#ifdef HS_BUILD_FOR_OSX
store = new pfMacPasswordStore();
#else
store = new pfFilePasswordStore();
#endif
#endif
}
@ -198,3 +202,52 @@ bool pfWin32PasswordStore::SetPassword(const plString& username, const plString&
return true;
}
#endif
#ifdef HS_BUILD_FOR_OSX
#include <Security/Security.h>
/*****************************************************************************
** pfMacPasswordStore **
*****************************************************************************/
const plString pfMacPasswordStore::GetPassword(const plString& username)
{
plString service = plProduct::UUID();
void* passwd = nullptr;
uint32_t passwd_len = 0;
if (SecKeychainFindGenericPassword(nullptr,
service.GetSize(),
service.c_str(),
username.GetSize(),
username.c_str(),
&passwd_len,
&passwd,
nullptr) != errSecSuccess)
{
return plString::Null;
}
plString ret(reinterpret_cast<const char*>(passwd), size_t(passwd_len));
SecKeychainItemFreeContent(nullptr, passwd);
return ret;
}
bool pfMacPasswordStore::SetPassword(const plString& username, const plString& password)
{
plString service = plProduct::UUID();
return SecKeychainAddGenericPassword(nullptr,
service.GetSize(),
service.c_str(),
username.GetSize(),
username.c_str(),
password.GetSize(),
password.c_str(),
nullptr) == errSecSuccess;
}
#endif

12
Sources/Plasma/FeatureLib/pfPasswordStore/pfPasswordStore_impl.h

@ -80,8 +80,18 @@ public:
* @todo A Linux libsecret-based storage mechanism.
*/
#ifdef HS_BUILD_FOR_OSX
/**
* @todo An OSX KeyChain-based storage mechanism.
* An OSX Keychain password storage mechanism.
*/
class pfMacPasswordStore : public pfPasswordStore
{
public:
pfMacPasswordStore() { }
virtual const plString GetPassword(const plString& username);
virtual bool SetPassword(const plString& username, const plString& password);
};
#endif //HS_BUILD_FOR_OSX
#endif //pfPasswordStore_impl_inc

Loading…
Cancel
Save