mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-27 23:57:38 -04:00
Merge pull request #2011 from G10h4ck/createLocationV2
Improve API to create locations
This commit is contained in:
commit
b49dfaead0
4 changed files with 194 additions and 22 deletions
|
@ -114,6 +114,8 @@ RsLoginHelper* rsLoginHelper = nullptr;
|
|||
|
||||
RsAccounts* rsAccounts = nullptr;
|
||||
|
||||
const RsInitErrorCategory RsInitErrorCategory::instance;
|
||||
|
||||
RsConfigOptions::RsConfigOptions()
|
||||
:
|
||||
autoLogin(false),
|
||||
|
@ -1950,6 +1952,47 @@ void RsLoginHelper::getLocations(std::vector<RsLoginHelper::Location>& store)
|
|||
}
|
||||
}
|
||||
|
||||
std::error_condition RsLoginHelper::createLocationV2(
|
||||
RsPeerId& locationId, RsPgpId& pgpId,
|
||||
const std::string& locationName, const std::string& pgpName,
|
||||
const std::string& password )
|
||||
{
|
||||
if(isLoggedIn()) return RsInitErrorNum::ALREADY_LOGGED_IN;
|
||||
if(locationName.empty()) return RsInitErrorNum::INVALID_LOCATION_NAME;
|
||||
if(pgpId.isNull() && pgpName.empty())
|
||||
return RsInitErrorNum::PGP_NAME_OR_ID_NEEDED;
|
||||
|
||||
std::string errorMessage;
|
||||
if(pgpId.isNull() && !RsAccounts::GeneratePGPCertificate(
|
||||
pgpName, "", password, pgpId, 4096, errorMessage ) )
|
||||
{
|
||||
RS_ERR("Failure creating PGP key: ", errorMessage);
|
||||
return RsInitErrorNum::PGP_KEY_CREATION_FAILED;
|
||||
}
|
||||
|
||||
std::string sslPassword =
|
||||
RsRandom::random_alphaNumericString(RsInit::getSslPwdLen());
|
||||
|
||||
rsNotify->cachePgpPassphrase(password);
|
||||
rsNotify->setDisableAskPassword(true);
|
||||
|
||||
bool ret = RsAccounts::createNewAccount(
|
||||
pgpId, "", locationName, "", false, false, sslPassword,
|
||||
locationId, errorMessage );
|
||||
if(!ret)
|
||||
{
|
||||
RS_ERR("Failure creating SSL key: ", errorMessage);
|
||||
return RsInitErrorNum::SSL_KEY_CREATION_FAILED;
|
||||
}
|
||||
|
||||
RsInit::LoadPassword(sslPassword);
|
||||
ret = (RsInit::OK == attemptLogin(locationId, password));
|
||||
rsNotify->setDisableAskPassword(false);
|
||||
|
||||
return (ret ? std::error_condition() : RsInitErrorNum::LOGIN_FAILED);
|
||||
}
|
||||
|
||||
#if !RS_VERSION_AT_LEAST(0,6,6)
|
||||
bool RsLoginHelper::createLocation(
|
||||
RsLoginHelper::Location& l, const std::string& password,
|
||||
std::string& errorMessage, bool makeHidden, bool makeAutoTor )
|
||||
|
@ -1991,6 +2034,7 @@ bool RsLoginHelper::createLocation(
|
|||
rsNotify->setDisableAskPassword(false);
|
||||
return ret;
|
||||
}
|
||||
#endif // !RS_VERSION_AT_LEAST(0,6,6)
|
||||
|
||||
bool RsLoginHelper::isLoggedIn()
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue