summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsergeyu <sergeyu@chromium.org>2015-05-06 16:00:16 -0700
committerCommit bot <commit-bot@chromium.org>2015-05-06 23:00:52 +0000
commit8916cd0a41e708d4c00e96dae7960cb9e634794e (patch)
tree69436885a4195f849143207634e2076b4925ea79
parent51bf98859f09d62152a3662839f93b9efad826c5 (diff)
downloadchromium_src-8916cd0a41e708d4c00e96dae7960cb9e634794e.zip
chromium_src-8916cd0a41e708d4c00e96dae7960cb9e634794e.tar.gz
chromium_src-8916cd0a41e708d4c00e96dae7960cb9e634794e.tar.bz2
Normalize JIDs when generating signatures for messages sent to CRD bot.
When generating signatures for the messages sent to the bot the JID must be normalized, i.e. node and domain parts must be in lower-case. XmppSignalStrategy::GetLocalJid() was previously returning normalized value, but it was changed recently, which broke hosts that use account with upper-case characters in the name. BUG=485134 Review URL: https://codereview.chromium.org/1131653002 Cr-Commit-Position: refs/heads/master@{#328646}
-rw-r--r--remoting/host/heartbeat_sender.cc5
-rw-r--r--remoting/host/heartbeat_sender_unittest.cc7
-rw-r--r--remoting/host/register_support_host_request.cc3
-rw-r--r--remoting/host/register_support_host_request_unittest.cc5
-rw-r--r--remoting/remoting_srcs.gypi2
-rw-r--r--remoting/remoting_test.gypi1
-rw-r--r--remoting/signaling/jid_util.cc23
-rw-r--r--remoting/signaling/jid_util.h18
-rw-r--r--remoting/signaling/jid_util_unittest.cc19
9 files changed, 75 insertions, 8 deletions
diff --git a/remoting/host/heartbeat_sender.cc b/remoting/host/heartbeat_sender.cc
index 1d1a77d..d244f1e 100644
--- a/remoting/host/heartbeat_sender.cc
+++ b/remoting/host/heartbeat_sender.cc
@@ -17,6 +17,7 @@
#include "remoting/base/logging.h"
#include "remoting/host/server_log_entry_host.h"
#include "remoting/signaling/iq_sender.h"
+#include "remoting/signaling/jid_util.h"
#include "remoting/signaling/server_log_entry.h"
#include "remoting/signaling/signal_strategy.h"
#include "third_party/webrtc/libjingle/xmllite/xmlelement.h"
@@ -331,8 +332,8 @@ scoped_ptr<XmlElement> HeartbeatSender::CreateSignature() {
scoped_ptr<XmlElement> signature_tag(new XmlElement(
QName(kChromotingXmlNamespace, kHeartbeatSignatureTag)));
- std::string message = signal_strategy_->GetLocalJid() + ' ' +
- base::IntToString(sequence_id_);
+ std::string message = NormalizeJid(signal_strategy_->GetLocalJid()) + ' ' +
+ base::IntToString(sequence_id_);
std::string signature(host_key_pair_->SignMessage(message));
signature_tag->AddText(signature);
diff --git a/remoting/host/heartbeat_sender_unittest.cc b/remoting/host/heartbeat_sender_unittest.cc
index 38fee24..dd9411c 100644
--- a/remoting/host/heartbeat_sender_unittest.cc
+++ b/remoting/host/heartbeat_sender_unittest.cc
@@ -38,7 +38,8 @@ namespace {
const char kTestBotJid[] = "remotingunittest@bot.talk.google.com";
const char kHostId[] = "0";
-const char kTestJid[] = "user@gmail.com/chromoting123";
+const char kTestJid[] = "User@gmail.com/chromotingABC123";
+const char kTestJidNormalized[] = "user@gmail.com/chromotingABC123";
const char kStanzaId[] = "123";
const int kTestInterval = 123;
const base::TimeDelta kTestTimeout = base::TimeDelta::FromSeconds(123);
@@ -362,8 +363,8 @@ void HeartbeatSenderTest::ValidateHeartbeatStanza(
scoped_refptr<RsaKeyPair> key_pair = RsaKeyPair::FromString(kTestRsaKeyPair);
ASSERT_TRUE(key_pair.get());
- std::string expected_signature =
- key_pair->SignMessage(std::string(kTestJid) + ' ' + expected_sequence_id);
+ std::string expected_signature = key_pair->SignMessage(
+ std::string(kTestJidNormalized) + ' ' + expected_sequence_id);
EXPECT_EQ(expected_signature, signature->BodyText());
}
diff --git a/remoting/host/register_support_host_request.cc b/remoting/host/register_support_host_request.cc
index b1bdd41..6d39873 100644
--- a/remoting/host/register_support_host_request.cc
+++ b/remoting/host/register_support_host_request.cc
@@ -13,6 +13,7 @@
#include "remoting/base/constants.h"
#include "remoting/host/host_config.h"
#include "remoting/signaling/iq_sender.h"
+#include "remoting/signaling/jid_util.h"
#include "remoting/signaling/signal_strategy.h"
#include "third_party/webrtc/libjingle/xmllite/xmlelement.h"
#include "third_party/webrtc/libjingle/xmpp/constants.h"
@@ -98,7 +99,7 @@ scoped_ptr<XmlElement> RegisterSupportHostRequest::CreateSignature(
signature_tag->AddAttr(
QName(kChromotingXmlNamespace, kSignatureTimeAttr), time_str);
- std::string message = jid + ' ' + time_str;
+ std::string message = NormalizeJid(jid) + ' ' + time_str;
std::string signature(key_pair_->SignMessage(message));
signature_tag->AddText(signature);
diff --git a/remoting/host/register_support_host_request_unittest.cc b/remoting/host/register_support_host_request_unittest.cc
index 36e927c..c848bf2 100644
--- a/remoting/host/register_support_host_request_unittest.cc
+++ b/remoting/host/register_support_host_request_unittest.cc
@@ -33,7 +33,8 @@ namespace remoting {
namespace {
const char kTestBotJid[] = "remotingunittest@bot.talk.google.com";
-const char kTestJid[] = "user@gmail.com/chromoting123";
+const char kTestJid[] = "User@gmail.com/chromotingABC123";
+const char kTestJidNormalized[] = "user@gmail.com/chromotingABC123";
const char kSupportId[] = "AB4RF3";
const char kSupportIdLifetime[] = "300";
const char kStanzaId[] = "123";
@@ -122,7 +123,7 @@ TEST_F(RegisterSupportHostRequestTest, Send) {
ASSERT_TRUE(key_pair.get());
std::string expected_signature =
- key_pair->SignMessage(std::string(kTestJid) + ' ' + time_str);
+ key_pair->SignMessage(std::string(kTestJidNormalized) + ' ' + time_str);
EXPECT_EQ(expected_signature, signature->BodyText());
// Generate response and verify that callback is called.
diff --git a/remoting/remoting_srcs.gypi b/remoting/remoting_srcs.gypi
index 68994c0..b5cd4b0 100644
--- a/remoting/remoting_srcs.gypi
+++ b/remoting/remoting_srcs.gypi
@@ -195,6 +195,8 @@
'protocol/video_stub.h',
'signaling/iq_sender.cc',
'signaling/iq_sender.h',
+ 'signaling/jid_util.cc',
+ 'signaling/jid_util.h',
'signaling/jingle_info_request.cc',
'signaling/jingle_info_request.h',
'signaling/log_to_server.cc',
diff --git a/remoting/remoting_test.gypi b/remoting/remoting_test.gypi
index 29d36ce..124c2c6 100644
--- a/remoting/remoting_test.gypi
+++ b/remoting/remoting_test.gypi
@@ -252,6 +252,7 @@
'protocol/third_party_authenticator_unittest.cc',
'protocol/v2_authenticator_unittest.cc',
'signaling/iq_sender_unittest.cc',
+ 'signaling/jid_util_unittest.cc',
'signaling/log_to_server_unittest.cc',
'signaling/server_log_entry_unittest.cc',
'signaling/server_log_entry_unittest.h',
diff --git a/remoting/signaling/jid_util.cc b/remoting/signaling/jid_util.cc
new file mode 100644
index 0000000..8e8e12b
--- /dev/null
+++ b/remoting/signaling/jid_util.cc
@@ -0,0 +1,23 @@
+// Copyright 2015 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 "remoting/signaling/jid_util.h"
+
+#include "base/strings/string_util.h"
+
+namespace remoting {
+
+std::string NormalizeJid(const std::string& jid) {
+ size_t slash_pos = jid.find('/');
+
+ // In case there the jid doesn't have resource id covert the whole value to
+ // lower-case.
+ if (slash_pos == std::string::npos)
+ return base::StringToLowerASCII(jid);
+
+ return base::StringToLowerASCII(jid.substr(0, slash_pos)) +
+ jid.substr(slash_pos);
+}
+
+} // namespace remoting
diff --git a/remoting/signaling/jid_util.h b/remoting/signaling/jid_util.h
new file mode 100644
index 0000000..e7bd7bc
--- /dev/null
+++ b/remoting/signaling/jid_util.h
@@ -0,0 +1,18 @@
+// Copyright 2015 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.
+
+#ifndef REMOTING_SIGNALING_JID_UTIL_H_
+#define REMOTING_SIGNALING_JID_UTIL_H_
+
+#include <string>
+
+namespace remoting {
+
+// Normalizes the |jid| by converting case-insensitive parts (node and domain)
+// to lower-case.
+std::string NormalizeJid(const std::string& jid);
+
+} // namespace remoting
+
+#endif // REMOTING_SIGNALING_JID_UTIL_H_
diff --git a/remoting/signaling/jid_util_unittest.cc b/remoting/signaling/jid_util_unittest.cc
new file mode 100644
index 0000000..c4e307d
--- /dev/null
+++ b/remoting/signaling/jid_util_unittest.cc
@@ -0,0 +1,19 @@
+// Copyright 2015 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 "remoting/signaling/jid_util.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace remoting {
+
+TEST(JidUtil, NormalizeJid) {
+ EXPECT_EQ(NormalizeJid("USER@DOMAIN.com"), "user@domain.com");
+ EXPECT_EQ(NormalizeJid("user@domain.com"), "user@domain.com");
+ EXPECT_EQ(NormalizeJid("USER@DOMAIN.com/RESOURCE"),
+ "user@domain.com/RESOURCE");
+ EXPECT_EQ(NormalizeJid("USER@DOMAIN.com/"), "user@domain.com/");
+}
+
+} // namespace remoting