Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Unified Diff: third_party/libjingle_xmpp/xmpp/xmppauth.cc

Issue 2443903004: Add xmllite and xmpp sources to third_party/ (Closed)
Patch Set: Fix GN and sort includes Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/libjingle_xmpp/xmpp/xmppauth.cc
diff --git a/third_party/libjingle_xmpp/xmpp/xmppauth.cc b/third_party/libjingle_xmpp/xmpp/xmppauth.cc
new file mode 100644
index 0000000000000000000000000000000000000000..48f94eb583dc64ccc1aa061b5cac8938ec713189
--- /dev/null
+++ b/third_party/libjingle_xmpp/xmpp/xmppauth.cc
@@ -0,0 +1,82 @@
+// Copyright 2004 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "third_party/libjingle_xmpp/xmpp/xmppauth.h"
+
+#include <algorithm>
+
+#include "third_party/libjingle_xmpp/xmpp/constants.h"
+#include "third_party/libjingle_xmpp/xmpp/saslcookiemechanism.h"
+#include "third_party/libjingle_xmpp/xmpp/saslplainmechanism.h"
+
+XmppAuth::XmppAuth() : done_(false) {
+}
+
+XmppAuth::~XmppAuth() {
+}
+
+void XmppAuth::StartPreXmppAuth(const buzz::Jid& jid,
+ const rtc::SocketAddress& server,
+ const rtc::CryptString& pass,
+ const std::string& auth_mechanism,
+ const std::string& auth_token) {
+ jid_ = jid;
+ passwd_ = pass;
+ auth_mechanism_ = auth_mechanism;
+ auth_token_ = auth_token;
+ done_ = true;
+
+ SignalAuthDone();
+}
+
+static bool contains(const std::vector<std::string>& strings,
+ const std::string& string) {
+ return std::find(strings.begin(), strings.end(), string) != strings.end();
+}
+
+std::string XmppAuth::ChooseBestSaslMechanism(
+ const std::vector<std::string>& mechanisms,
+ bool encrypted) {
+ // First try Oauth2.
+ if (GetAuthMechanism() == buzz::AUTH_MECHANISM_OAUTH2 &&
+ contains(mechanisms, buzz::AUTH_MECHANISM_OAUTH2)) {
+ return buzz::AUTH_MECHANISM_OAUTH2;
+ }
+
+ // A token is the weakest auth - 15s, service-limited, so prefer it.
+ if (GetAuthMechanism() == buzz::AUTH_MECHANISM_GOOGLE_TOKEN &&
+ contains(mechanisms, buzz::AUTH_MECHANISM_GOOGLE_TOKEN)) {
+ return buzz::AUTH_MECHANISM_GOOGLE_TOKEN;
+ }
+
+ // A cookie is the next weakest - 14 days.
+ if (GetAuthMechanism() == buzz::AUTH_MECHANISM_GOOGLE_COOKIE &&
+ contains(mechanisms, buzz::AUTH_MECHANISM_GOOGLE_COOKIE)) {
+ return buzz::AUTH_MECHANISM_GOOGLE_COOKIE;
+ }
+
+ // As a last resort, use plain authentication.
+ if (contains(mechanisms, buzz::AUTH_MECHANISM_PLAIN)) {
+ return buzz::AUTH_MECHANISM_PLAIN;
+ }
+
+ // No good mechanism found
+ return "";
+}
+
+buzz::SaslMechanism* XmppAuth::CreateSaslMechanism(
+ const std::string& mechanism) {
+ if (mechanism == buzz::AUTH_MECHANISM_OAUTH2) {
+ return new buzz::SaslCookieMechanism(
+ mechanism, jid_.Str(), auth_token_, "oauth2");
+ } else if (mechanism == buzz::AUTH_MECHANISM_GOOGLE_TOKEN) {
+ return new buzz::SaslCookieMechanism(mechanism, jid_.Str(), auth_token_);
+ // } else if (mechanism == buzz::AUTH_MECHANISM_GOOGLE_COOKIE) {
+ // return new buzz::SaslCookieMechanism(mechanism, jid.Str(), sid_);
+ } else if (mechanism == buzz::AUTH_MECHANISM_PLAIN) {
+ return new buzz::SaslPlainMechanism(jid_, passwd_);
+ } else {
+ return NULL;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698