repair for persisting of Account to file after keypair generation

This commit is contained in:
Stephen Birarda 2014-10-14 14:21:18 -07:00
parent bac6961235
commit 22b599b8cc
6 changed files with 28 additions and 24 deletions

View file

@ -138,8 +138,7 @@ void DatagramProcessor::processDatagrams() {
case PacketTypeDomainUsernameRequest: {
// flag the domain handler so it knows to send a username signature on next check-in
// and then make it send that next check in
nodeList->getDomainHandler().setRequiresUsernameSignature(true);
nodeList->sendDomainServerCheckIn();
qDebug() << "domain-server is requesting a connection with a username signature";
break;
}
case PacketTypeMuteEnvironment: {

View file

@ -321,6 +321,16 @@ void AccountManager::passErrorToCallback(QNetworkReply* requestReply) {
}
}
void AccountManager::persistAccountToSettings() {
if (_shouldPersistToSettingsFile) {
// store this access token into the local settings
QSettings localSettings;
localSettings.beginGroup(ACCOUNTS_GROUP);
localSettings.setValue(_authURL.toString().replace("//", DOUBLE_SLASH_SUBSTITUTE),
QVariant::fromValue(_accountInfo));
}
}
bool AccountManager::hasValidAccessToken() {
if (_accountInfo.getAccessToken().token.isEmpty() || _accountInfo.getAccessToken().isExpired()) {
@ -410,13 +420,7 @@ void AccountManager::requestAccessTokenFinished() {
emit loginComplete(rootURL);
if (_shouldPersistToSettingsFile) {
// store this access token into the local settings
QSettings localSettings;
localSettings.beginGroup(ACCOUNTS_GROUP);
localSettings.setValue(rootURL.toString().replace("//", DOUBLE_SLASH_SUBSTITUTE),
QVariant::fromValue(_accountInfo));
}
persistAccountToSettings();
requestProfile();
generateNewKeypair();
@ -461,15 +465,8 @@ void AccountManager::requestProfileFinished() {
// the username has changed to whatever came back
emit usernameChanged(_accountInfo.getUsername());
if (_shouldPersistToSettingsFile) {
// store the whole profile into the local settings
QUrl rootURL = profileReply->url();
rootURL.setPath("");
QSettings localSettings;
localSettings.beginGroup(ACCOUNTS_GROUP);
localSettings.setValue(rootURL.toString().replace("//", DOUBLE_SLASH_SUBSTITUTE),
QVariant::fromValue(_accountInfo));
}
// store the whole profile into the local settings
persistAccountToSettings();
} else {
// TODO: error handling
@ -508,6 +505,7 @@ void AccountManager::processGeneratedKeypair(const QByteArray& publicKey, const
// set the private key on our data-server account info
_accountInfo.setPrivateKey(privateKey);
persistAccountToSettings();
// upload the public key so data-web has an up-to-date key
const QString PUBLIC_KEY_UPDATE_PATH = "api/v1/user/public_key";

View file

@ -97,6 +97,8 @@ private:
AccountManager();
AccountManager(AccountManager const& other); // not implemented
void operator=(AccountManager const& other); // not implemented
void persistAccountToSettings();
void passSuccessToCallback(QNetworkReply* reply);
void passErrorToCallback(QNetworkReply* reply);

View file

@ -30,7 +30,6 @@ DomainHandler::DomainHandler(QObject* parent) :
_iceServerSockAddr(),
_icePeer(),
_isConnected(false),
_requiresUsernameSignature(false),
_handshakeTimer(NULL),
_settingsObject(),
_failedSettingsRequests(0)
@ -49,7 +48,6 @@ void DomainHandler::clearConnectionInfo() {
}
_isConnected = false;
_requiresUsernameSignature = false;
emit disconnectedFromDomain();

View file

@ -68,9 +68,6 @@ public:
bool isConnected() const { return _isConnected; }
void setIsConnected(bool isConnected);
bool requiresUsernameSignature() const { return _requiresUsernameSignature; }
void setRequiresUsernameSignature(bool requiresUsernameSignature) { _requiresUsernameSignature = requiresUsernameSignature; }
bool hasSettings() const { return !_settingsObject.isEmpty(); }
void requestDomainSettings();
const QJsonObject& getSettingsObject() const { return _settingsObject; }
@ -107,7 +104,6 @@ private:
HifiSockAddr _iceServerSockAddr;
NetworkPeer _icePeer;
bool _isConnected;
bool _requiresUsernameSignature;
QTimer* _handshakeTimer;
QJsonObject _settingsObject;
int _failedSettingsRequests;

View file

@ -309,6 +309,17 @@ void NodeList::sendDomainServerCheckIn() {
packetStream << nodeTypeOfInterest;
}
// if this is a connect request, and we can present a username signature, send it along
AccountManager& accountManager = AccountManager::getInstance();
const QByteArray& privateKey = accountManager.getAccountInfo().getPrivateKey();
if (!_domainHandler.isConnected()) {
if (!privateKey.isEmpty()) {
qDebug() << "Including username signature in domain connect request.";
} else {
qDebug() << "Private key not present - domain connect request cannot include username signature";
}
}
if (!isUsingDTLS) {
writeDatagram(domainServerPacket, _domainHandler.getSockAddr(), QUuid());
}