| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ipc/ipc_channel_win.h" | 5 #include "ipc/ipc_channel_win.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 } | 564 } |
| 565 } | 565 } |
| 566 | 566 |
| 567 //------------------------------------------------------------------------------ | 567 //------------------------------------------------------------------------------ |
| 568 // Channel's methods | 568 // Channel's methods |
| 569 | 569 |
| 570 // static | 570 // static |
| 571 scoped_ptr<Channel> Channel::Create(const IPC::ChannelHandle& channel_handle, | 571 scoped_ptr<Channel> Channel::Create(const IPC::ChannelHandle& channel_handle, |
| 572 Mode mode, | 572 Mode mode, |
| 573 Listener* listener) { | 573 Listener* listener) { |
| 574 return scoped_ptr<Channel>( | 574 return scoped_ptr<Channel>(new ChannelWin(channel_handle, mode, listener)); |
| 575 new ChannelWin(channel_handle, mode, listener)); | |
| 576 } | 575 } |
| 577 | 576 |
| 578 // static | 577 // static |
| 579 bool Channel::IsNamedServerInitialized(const std::string& channel_id) { | 578 bool Channel::IsNamedServerInitialized(const std::string& channel_id) { |
| 580 return ChannelWin::IsNamedServerInitialized(channel_id); | 579 return ChannelWin::IsNamedServerInitialized(channel_id); |
| 581 } | 580 } |
| 582 | 581 |
| 583 // static | 582 // static |
| 584 std::string Channel::GenerateVerifiedChannelID(const std::string& prefix) { | 583 std::string Channel::GenerateVerifiedChannelID(const std::string& prefix) { |
| 585 // Windows pipes can be enumerated by low-privileged processes. So, we | 584 // Windows pipes can be enumerated by low-privileged processes. So, we |
| 586 // append a strong random value after the \ character. This value is not | 585 // append a strong random value after the \ character. This value is not |
| 587 // included in the pipe name, but sent as part of the client hello, to | 586 // included in the pipe name, but sent as part of the client hello, to |
| 588 // hijacking the pipe name to spoof the client. | 587 // hijacking the pipe name to spoof the client. |
| 589 | 588 |
| 590 std::string id = prefix; | 589 std::string id = prefix; |
| 591 if (!id.empty()) | 590 if (!id.empty()) |
| 592 id.append("."); | 591 id.append("."); |
| 593 | 592 |
| 594 int secret; | 593 int secret; |
| 595 do { // Guarantee we get a non-zero value. | 594 do { // Guarantee we get a non-zero value. |
| 596 secret = base::RandInt(0, std::numeric_limits<int>::max()); | 595 secret = base::RandInt(0, std::numeric_limits<int>::max()); |
| 597 } while (secret == 0); | 596 } while (secret == 0); |
| 598 | 597 |
| 599 id.append(GenerateUniqueRandomChannelID()); | 598 id.append(GenerateUniqueRandomChannelID()); |
| 600 return id.append(base::StringPrintf("\\%d", secret)); | 599 return id.append(base::StringPrintf("\\%d", secret)); |
| 601 } | 600 } |
| 602 | 601 |
| 603 } // namespace IPC | 602 } // namespace IPC |
| OLD | NEW |