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

Side by Side Diff: ipc/brokerable_attachment.cc

Issue 1286253002: IPC: Add attachment brokering support to the message header. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix more #ifs Created 5 years, 4 months 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/brokerable_attachment.h" 5 #include "ipc/brokerable_attachment.h"
6 6
7 #include "ipc/attachment_broker.h"
8
9 #if USE_ATTACHMENT_BROKER
7 #include "crypto/random.h" 10 #include "crypto/random.h"
11 #endif
8 12
9 namespace IPC { 13 namespace IPC {
10 14
11 namespace { 15 namespace {
12 16
13 // In order to prevent mutually untrusted processes from stealing resources from 17 // In order to prevent mutually untrusted processes from stealing resources from
14 // one another, the nonce must be secret. This generates a 128-bit, 18 // one another, the nonce must be secret. This generates a 128-bit,
15 // cryptographicaly-strong random number. 19 // cryptographicaly-strong random number.
16 BrokerableAttachment::AttachmentId GetRandomId() { 20 BrokerableAttachment::AttachmentId GetRandomId() {
17 BrokerableAttachment::AttachmentId id; 21 BrokerableAttachment::AttachmentId id;
22 #if USE_ATTACHMENT_BROKER
18 crypto::RandBytes(id.nonce, BrokerableAttachment::kNonceSize); 23 crypto::RandBytes(id.nonce, BrokerableAttachment::kNonceSize);
24 #endif
19 return id; 25 return id;
Tom Sepez 2015/08/17 18:29:39 nit: feels wrong to allow this to return a known k
erikchen 2015/08/18 05:59:46 I agree. I've changed the no-parameter constructor
20 } 26 }
21 27
22 } // namespace 28 } // namespace
23 29
24 BrokerableAttachment::BrokerableAttachment() 30 // The size of the nonce array in AttachmentId must match kNonceSize.
25 : id_(GetRandomId()), needs_brokering_(false) {} 31 const size_t BrokerableAttachment::kNonceSize = 16;
26 32
27 BrokerableAttachment::BrokerableAttachment(const AttachmentId& id, 33 BrokerableAttachment::AttachmentId::AttachmentId(const char* start_address,
28 bool needs_brokering) 34 size_t size) {
29 : id_(id), needs_brokering_(needs_brokering) {} 35 DCHECK_EQ(size, BrokerableAttachment::kNonceSize);
36 for (size_t i = 0; i < BrokerableAttachment::kNonceSize; ++i)
37 nonce[i] = start_address[i];
38 }
30 39
31 BrokerableAttachment::~BrokerableAttachment() { 40 void BrokerableAttachment::AttachmentId::SerializeToBuffer(char* start_address,
41 size_t size) {
42 DCHECK_EQ(size, BrokerableAttachment::kNonceSize);
43 for (size_t i = 0; i < BrokerableAttachment::kNonceSize; ++i)
44 start_address[i] = nonce[i];
32 } 45 }
33 46
47 bool BrokerableAttachment::AttachmentId::operator==(
48 const AttachmentId& rhs) const {
49 for (size_t i = 0; i < kNonceSize; ++i) {
50 if (nonce[i] != rhs.nonce[i])
51 return false;
52 }
53 return true;
54 }
55
56 bool BrokerableAttachment::AttachmentId::operator<(
57 const AttachmentId& rhs) const {
58 for (size_t i = 0; i < kNonceSize; ++i) {
59 if (nonce[i] < rhs.nonce[i])
60 return true;
61 if (nonce[i] > rhs.nonce[i])
62 return false;
63 }
64 return false;
65 }
66
67 BrokerableAttachment::BrokerableAttachment() : id_(GetRandomId()) {}
68
69 BrokerableAttachment::BrokerableAttachment(const AttachmentId& id) : id_(id) {}
70
71 BrokerableAttachment::~BrokerableAttachment() {}
72
34 BrokerableAttachment::AttachmentId BrokerableAttachment::GetIdentifier() const { 73 BrokerableAttachment::AttachmentId BrokerableAttachment::GetIdentifier() const {
35 return id_; 74 return id_;
36 } 75 }
37 76
38 bool BrokerableAttachment::NeedsBrokering() const { 77 bool BrokerableAttachment::NeedsBrokering() const {
39 return needs_brokering_; 78 return GetBrokerableType() == PLACEHOLDER;
40 }
41
42 void BrokerableAttachment::SetNeedsBrokering(bool needs_brokering) {
43 needs_brokering_ = needs_brokering;
44 } 79 }
45 80
46 BrokerableAttachment::Type BrokerableAttachment::GetType() const { 81 BrokerableAttachment::Type BrokerableAttachment::GetType() const {
47 return TYPE_BROKERABLE_ATTACHMENT; 82 return TYPE_BROKERABLE_ATTACHMENT;
48 } 83 }
49 84
85 #if defined(OS_POSIX)
86 base::PlatformFile BrokerableAttachment::TakePlatformFile() {
87 NOTREACHED();
88 return base::PlatformFile();
89 }
90 #endif // OS_POSIX
91
50 } // namespace IPC 92 } // namespace IPC
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698