mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 13:18:38 +02:00
don't update the AM keypair until uploaded
This commit is contained in:
parent
e2f02347dd
commit
bfdf74367e
2 changed files with 82 additions and 40 deletions
|
@ -107,7 +107,7 @@ void AccountManager::logout() {
|
||||||
connect(&_accountInfo, &DataServerAccountInfo::balanceChanged, this, &AccountManager::accountInfoBalanceChanged);
|
connect(&_accountInfo, &DataServerAccountInfo::balanceChanged, this, &AccountManager::accountInfoBalanceChanged);
|
||||||
|
|
||||||
// remove this account from the account settings file
|
// remove this account from the account settings file
|
||||||
removeAccountFromSettings();
|
removeAccountFromFile();
|
||||||
|
|
||||||
emit logoutComplete();
|
emit logoutComplete();
|
||||||
// the username has changed to blank
|
// the username has changed to blank
|
||||||
|
@ -199,7 +199,7 @@ void AccountManager::setAuthURL(const QUrl& authURL) {
|
||||||
qCWarning(networking) << "Unable to load account file. No existing account settings will be loaded.";
|
qCWarning(networking) << "Unable to load account file. No existing account settings will be loaded.";
|
||||||
} else {
|
} else {
|
||||||
// persist the migrated settings to file
|
// persist the migrated settings to file
|
||||||
persistAccountToSettings();
|
persistAccountToFile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -399,7 +399,7 @@ bool writeAccountMapToFile(const QVariantMap& accountMap) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AccountManager::persistAccountToSettings() {
|
void AccountManager::persistAccountToFile() {
|
||||||
|
|
||||||
qCDebug(networking) << "Persisting AccountManager accounts to" << accountFilePath();
|
qCDebug(networking) << "Persisting AccountManager accounts to" << accountFilePath();
|
||||||
|
|
||||||
|
@ -419,7 +419,7 @@ void AccountManager::persistAccountToSettings() {
|
||||||
qCWarning(networking) << "Could not load accounts file - unable to persist account information to file.";
|
qCWarning(networking) << "Could not load accounts file - unable to persist account information to file.";
|
||||||
}
|
}
|
||||||
|
|
||||||
void AccountManager::removeAccountFromSettings() {
|
void AccountManager::removeAccountFromFile() {
|
||||||
bool wasLoaded = false;
|
bool wasLoaded = false;
|
||||||
auto accountMap = accountMapFromFile(wasLoaded);
|
auto accountMap = accountMapFromFile(wasLoaded);
|
||||||
|
|
||||||
|
@ -469,7 +469,7 @@ void AccountManager::setAccessTokenForCurrentAuthURL(const QString& accessToken)
|
||||||
|
|
||||||
_accountInfo.setAccessToken(newOAuthToken);
|
_accountInfo.setAccessToken(newOAuthToken);
|
||||||
|
|
||||||
persistAccountToSettings();
|
persistAccountToFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AccountManager::requestAccessToken(const QString& login, const QString& password) {
|
void AccountManager::requestAccessToken(const QString& login, const QString& password) {
|
||||||
|
@ -524,7 +524,7 @@ void AccountManager::requestAccessTokenFinished() {
|
||||||
|
|
||||||
emit loginComplete(rootURL);
|
emit loginComplete(rootURL);
|
||||||
|
|
||||||
persistAccountToSettings();
|
persistAccountToFile();
|
||||||
|
|
||||||
requestProfile();
|
requestProfile();
|
||||||
}
|
}
|
||||||
|
@ -570,7 +570,7 @@ void AccountManager::requestProfileFinished() {
|
||||||
emit usernameChanged(_accountInfo.getUsername());
|
emit usernameChanged(_accountInfo.getUsername());
|
||||||
|
|
||||||
// store the whole profile into the local settings
|
// store the whole profile into the local settings
|
||||||
persistAccountToSettings();
|
persistAccountToFile();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// TODO: error handling
|
// TODO: error handling
|
||||||
|
@ -589,6 +589,10 @@ void AccountManager::generateNewKeypair(bool isUserKeypair, const QUuid& domainI
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// make sure we don't already have an outbound keypair generation request
|
||||||
|
if (!_isWaitingForKeypairResponse) {
|
||||||
|
_isWaitingForKeypairResponse = true;
|
||||||
|
|
||||||
// clear the current private key
|
// clear the current private key
|
||||||
qDebug() << "Clearing current private key in DataServerAccountInfo";
|
qDebug() << "Clearing current private key in DataServerAccountInfo";
|
||||||
_accountInfo.setPrivateKey(QByteArray());
|
_accountInfo.setPrivateKey(QByteArray());
|
||||||
|
@ -621,6 +625,7 @@ void AccountManager::generateNewKeypair(bool isUserKeypair, const QUuid& domainI
|
||||||
|
|
||||||
qCDebug(networking) << "Starting worker thread to generate 2048-bit RSA keypair.";
|
qCDebug(networking) << "Starting worker thread to generate 2048-bit RSA keypair.";
|
||||||
generateThread->start();
|
generateThread->start();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AccountManager::processGeneratedKeypair() {
|
void AccountManager::processGeneratedKeypair() {
|
||||||
|
@ -631,8 +636,7 @@ void AccountManager::processGeneratedKeypair() {
|
||||||
|
|
||||||
if (keypairGenerator) {
|
if (keypairGenerator) {
|
||||||
// set the private key on our metaverse API account info
|
// set the private key on our metaverse API account info
|
||||||
_accountInfo.setPrivateKey(keypairGenerator->getPrivateKey());
|
_pendingPrivateKey = keypairGenerator->getPrivateKey();
|
||||||
persistAccountToSettings();
|
|
||||||
|
|
||||||
// upload the public key so data-web has an up-to-date key
|
// upload the public key so data-web has an up-to-date key
|
||||||
const QString USER_PUBLIC_KEY_UPDATE_PATH = "api/v1/user/public_key";
|
const QString USER_PUBLIC_KEY_UPDATE_PATH = "api/v1/user/public_key";
|
||||||
|
@ -656,8 +660,15 @@ void AccountManager::processGeneratedKeypair() {
|
||||||
|
|
||||||
requestMultiPart->append(keyPart);
|
requestMultiPart->append(keyPart);
|
||||||
|
|
||||||
|
// setup callback parameters so we know once the keypair upload has succeeded or failed
|
||||||
|
JSONCallbackParameters callbackParameters;
|
||||||
|
callbackParameters.jsonCallbackReceiver = this;
|
||||||
|
callbackParameters.jsonCallbackMethod = "publicKeyUploadSucceeded";
|
||||||
|
callbackParameters.errorCallbackReceiver = this;
|
||||||
|
callbackParameters.errorCallbackMethod = "publicKeyUploadFailed";
|
||||||
|
|
||||||
sendRequest(uploadPath, AccountManagerAuth::Required, QNetworkAccessManager::PutOperation,
|
sendRequest(uploadPath, AccountManagerAuth::Required, QNetworkAccessManager::PutOperation,
|
||||||
JSONCallbackParameters(), QByteArray(), requestMultiPart);
|
callbackParameters, QByteArray(), requestMultiPart);
|
||||||
|
|
||||||
keypairGenerator->deleteLater();
|
keypairGenerator->deleteLater();
|
||||||
} else {
|
} else {
|
||||||
|
@ -666,8 +677,33 @@ void AccountManager::processGeneratedKeypair() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AccountManager::publicKeyUploadSuceeded() {
|
||||||
|
// public key upload complete - store the matching private key and persist the account to settings
|
||||||
|
_accountInfo.setPrivateKey(_pendingPrivateKey);
|
||||||
|
_pendingPrivateKey.clear();
|
||||||
|
persistAccountToFile();
|
||||||
|
|
||||||
|
// clear our waiting state
|
||||||
|
_isWaitingForKeypairResponse = false;
|
||||||
|
|
||||||
|
emit newKeypair();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AccountManager::publicKeyUploadFailed() {
|
||||||
|
// the public key upload has failed
|
||||||
|
|
||||||
|
// we aren't waiting for a response any longer
|
||||||
|
_isWaitingForKeypairResponse = false;
|
||||||
|
|
||||||
|
// clear our pending private key
|
||||||
|
_pendingPrivateKey.clear();
|
||||||
|
}
|
||||||
|
|
||||||
void AccountManager::handleKeypairGenerationError() {
|
void AccountManager::handleKeypairGenerationError() {
|
||||||
qCritical() << "Error generating keypair - this is likely to cause authentication issues.";
|
qCritical() << "Error generating keypair - this is likely to cause authentication issues.";
|
||||||
|
|
||||||
|
// reset our waiting state for keypair response
|
||||||
|
_isWaitingForKeypairResponse = false;
|
||||||
|
|
||||||
sender()->deleteLater();
|
sender()->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,19 +99,22 @@ signals:
|
||||||
void loginFailed();
|
void loginFailed();
|
||||||
void logoutComplete();
|
void logoutComplete();
|
||||||
void balanceChanged(qint64 newBalance);
|
void balanceChanged(qint64 newBalance);
|
||||||
|
void newKeypair();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void processReply();
|
void processReply();
|
||||||
void handleKeypairGenerationError();
|
void handleKeypairGenerationError();
|
||||||
void processGeneratedKeypair();
|
void processGeneratedKeypair();
|
||||||
|
void publicKeyUploadSuceeded();
|
||||||
|
void publicKeyUploadFailed();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AccountManager();
|
AccountManager();
|
||||||
AccountManager(AccountManager const& other) = delete;
|
AccountManager(AccountManager const& other) = delete;
|
||||||
void operator=(AccountManager const& other) = delete;
|
void operator=(AccountManager const& other) = delete;
|
||||||
|
|
||||||
void persistAccountToSettings();
|
void persistAccountToFile();
|
||||||
void removeAccountFromSettings();
|
void removeAccountFromFile();
|
||||||
|
|
||||||
void passSuccessToCallback(QNetworkReply* reply);
|
void passSuccessToCallback(QNetworkReply* reply);
|
||||||
void passErrorToCallback(QNetworkReply* reply);
|
void passErrorToCallback(QNetworkReply* reply);
|
||||||
|
@ -123,6 +126,9 @@ private:
|
||||||
|
|
||||||
DataServerAccountInfo _accountInfo;
|
DataServerAccountInfo _accountInfo;
|
||||||
bool _isAgent { false };
|
bool _isAgent { false };
|
||||||
|
|
||||||
|
bool _isWaitingForKeypairResponse { false };
|
||||||
|
QByteArray _pendingPrivateKey;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_AccountManager_h
|
#endif // hifi_AccountManager_h
|
||||||
|
|
Loading…
Reference in a new issue