summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/Base/Algorithm.h1
-rw-r--r--Swiften/Client/ClientOptions.h12
-rw-r--r--Swiften/Client/CoreClient.cpp24
-rw-r--r--Swiften/Client/CoreClient.h1
-rw-r--r--Swiften/SASL/ClientAuthenticator.cpp5
5 files changed, 38 insertions, 5 deletions
diff --git a/Swiften/Base/Algorithm.h b/Swiften/Base/Algorithm.h
index cd6f9dc..b7459ed 100644
--- a/Swiften/Base/Algorithm.h
+++ b/Swiften/Base/Algorithm.h
@@ -12,6 +12,7 @@
#include <algorithm>
namespace Swift {
+
/*
* Generic erase()
*/
diff --git a/Swiften/Client/ClientOptions.h b/Swiften/Client/ClientOptions.h
index 1155b46..cc80dc2 100644
--- a/Swiften/Client/ClientOptions.h
+++ b/Swiften/Client/ClientOptions.h
@@ -12,7 +12,7 @@ struct ClientOptions {
UseTLSWhenAvailable
};
- ClientOptions() : useStreamCompression(true), useTLS(UseTLSWhenAvailable), useStreamResumption(false) {
+ ClientOptions() : useStreamCompression(true), useTLS(UseTLSWhenAvailable), useStreamResumption(false), forgetPassword(false) {
}
/**
@@ -35,5 +35,15 @@ struct ClientOptions {
* Default: false
*/
bool useStreamResumption;
+
+ /**
+ * Forget the password once it's used.
+ * This makes the Client useless after the first login attempt.
+ *
+ * FIXME: This is a temporary workaround.
+ *
+ * Default: false
+ */
+ bool forgetPassword;
};
diff --git a/Swiften/Client/CoreClient.cpp b/Swiften/Client/CoreClient.cpp
index 9521bd9..8684de2 100644
--- a/Swiften/Client/CoreClient.cpp
+++ b/Swiften/Client/CoreClient.cpp
@@ -9,6 +9,10 @@
#include <boost/bind.hpp>
#include <boost/smart_ptr/make_shared.hpp>
+#include <Swiften/Base/IDGenerator.h>
+#include <Swiften/Base/Log.h>
+#include <Swiften/Base/foreach.h>
+#include <Swiften/Base/Algorithm.h>
#include <Swiften/Client/ClientSession.h>
#include <Swiften/TLS/PlatformTLSFactories.h>
#include <Swiften/TLS/CertificateVerificationError.h>
@@ -17,10 +21,7 @@
#include <Swiften/TLS/PKCS12Certificate.h>
#include <Swiften/Session/BasicSessionStream.h>
#include <Swiften/Queries/IQRouter.h>
-#include <Swiften/Base/IDGenerator.h>
#include <Swiften/Client/ClientSessionStanzaChannel.h>
-#include <Swiften/Base/Log.h>
-#include <Swiften/Base/foreach.h>
#include <Swiften/Network/PlatformProxyProvider.h>
#include <Swiften/Network/SOCKS5ProxiedConnectionFactory.h>
#include <Swiften/Network/HTTPConnectProxiedConnectionFactory.h>
@@ -50,6 +51,7 @@ CoreClient::~CoreClient() {
stanzaChannel_->onPresenceReceived.disconnect(boost::bind(&CoreClient::handlePresenceReceived, this, _1));
stanzaChannel_->onStanzaAcked.disconnect(boost::bind(&CoreClient::handleStanzaAcked, this, _1));
delete stanzaChannel_;
+ purgePassword();
}
void CoreClient::connect(const ClientOptions& o) {
@@ -88,6 +90,9 @@ void CoreClient::handleConnectorFinished(boost::shared_ptr<Connection> connectio
}
if (!connection) {
+ if (options.forgetPassword) {
+ purgePassword();
+ }
onDisconnected(disconnectRequested_ ? boost::optional<ClientError>() : boost::optional<ClientError>(ClientError::ConnectionError));
}
else {
@@ -121,6 +126,9 @@ void CoreClient::handleConnectorFinished(boost::shared_ptr<Connection> connectio
}
void CoreClient::disconnect() {
+ if (options.forgetPassword) {
+ purgePassword();
+ }
// FIXME: We should be able to do without this boolean. We just have to make sure we can tell the difference between
// connector finishing without a connection due to an error or because of a disconnect.
disconnectRequested_ = true;
@@ -137,6 +145,9 @@ void CoreClient::setCertificate(const std::string& certificate) {
}
void CoreClient::handleSessionFinished(boost::shared_ptr<Error> error) {
+ if (options.forgetPassword) {
+ purgePassword();
+ }
session_->onFinished.disconnect(boost::bind(&CoreClient::handleSessionFinished, this, _1));
session_->onNeedCredentials.disconnect(boost::bind(&CoreClient::handleNeedCredentials, this));
@@ -248,6 +259,9 @@ void CoreClient::handleSessionFinished(boost::shared_ptr<Error> error) {
void CoreClient::handleNeedCredentials() {
assert(session_);
session_->sendCredentials(password_);
+ if (options.forgetPassword) {
+ purgePassword();
+ }
}
void CoreClient::handleDataRead(const std::string& data) {
@@ -318,4 +332,8 @@ const JID& CoreClient::getJID() const {
}
}
+void CoreClient::purgePassword() {
+ safeClear(password_);
+}
+
}
diff --git a/Swiften/Client/CoreClient.h b/Swiften/Client/CoreClient.h
index 6dc8392..9806d35 100644
--- a/Swiften/Client/CoreClient.h
+++ b/Swiften/Client/CoreClient.h
@@ -199,6 +199,7 @@ namespace Swift {
void handlePresenceReceived(boost::shared_ptr<Presence>);
void handleMessageReceived(boost::shared_ptr<Message>);
void handleStanzaAcked(boost::shared_ptr<Stanza>);
+ void purgePassword();
private:
JID jid_;
diff --git a/Swiften/SASL/ClientAuthenticator.cpp b/Swiften/SASL/ClientAuthenticator.cpp
index b882d04..12636e2 100644
--- a/Swiften/SASL/ClientAuthenticator.cpp
+++ b/Swiften/SASL/ClientAuthenticator.cpp
@@ -1,17 +1,20 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2011 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#include <Swiften/SASL/ClientAuthenticator.h>
+#include <Swiften/Base/Algorithm.h>
+
namespace Swift {
ClientAuthenticator::ClientAuthenticator(const std::string& name) : name(name) {
}
ClientAuthenticator::~ClientAuthenticator() {
+ safeClear(password);
}
}