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

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: Compile error. 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
« no previous file with comments | « ipc/brokerable_attachment.h ('k') | ipc/handle_attachment_win.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #if USE_ATTACHMENT_BROKER
16 BrokerableAttachment::AttachmentId::AttachmentId() {
17 // In order to prevent mutually untrusted processes from stealing resources
18 // from one another, the nonce must be secret. This generates a 128-bit,
19 // cryptographicaly-strong random number.
20 crypto::RandBytes(nonce, BrokerableAttachment::kNonceSize);
21 }
22 #else
23 BrokerableAttachment::AttachmentId::AttachmentId() {
24 CHECK(false) << "Not allowed to construct an attachment id if the platform "
25 "does not support attachment brokering.";
26 }
27 #endif
12 28
13 // In order to prevent mutually untrusted processes from stealing resources from 29 BrokerableAttachment::AttachmentId::AttachmentId(const char* start_address,
14 // one another, the nonce must be secret. This generates a 128-bit, 30 size_t size) {
15 // cryptographicaly-strong random number. 31 DCHECK(size == BrokerableAttachment::kNonceSize);
16 BrokerableAttachment::AttachmentId GetRandomId() { 32 for (size_t i = 0; i < BrokerableAttachment::kNonceSize; ++i)
17 BrokerableAttachment::AttachmentId id; 33 nonce[i] = start_address[i];
18 crypto::RandBytes(id.nonce, BrokerableAttachment::kNonceSize);
19 return id;
20 } 34 }
21 35
22 } // namespace 36 void BrokerableAttachment::AttachmentId::SerializeToBuffer(char* start_address,
37 size_t size) {
38 DCHECK(size == BrokerableAttachment::kNonceSize);
39 for (size_t i = 0; i < BrokerableAttachment::kNonceSize; ++i)
40 start_address[i] = nonce[i];
41 }
23 42
24 BrokerableAttachment::BrokerableAttachment() 43 BrokerableAttachment::BrokerableAttachment() {}
25 : id_(GetRandomId()), needs_brokering_(false) {}
26 44
27 BrokerableAttachment::BrokerableAttachment(const AttachmentId& id, 45 BrokerableAttachment::BrokerableAttachment(const AttachmentId& id) : id_(id) {}
28 bool needs_brokering)
29 : id_(id), needs_brokering_(needs_brokering) {}
30 46
31 BrokerableAttachment::~BrokerableAttachment() { 47 BrokerableAttachment::~BrokerableAttachment() {}
32 }
33 48
34 BrokerableAttachment::AttachmentId BrokerableAttachment::GetIdentifier() const { 49 BrokerableAttachment::AttachmentId BrokerableAttachment::GetIdentifier() const {
35 return id_; 50 return id_;
36 } 51 }
37 52
38 bool BrokerableAttachment::NeedsBrokering() const { 53 bool BrokerableAttachment::NeedsBrokering() const {
39 return needs_brokering_; 54 return GetBrokerableType() == PLACEHOLDER;
40 }
41
42 void BrokerableAttachment::SetNeedsBrokering(bool needs_brokering) {
43 needs_brokering_ = needs_brokering;
44 } 55 }
45 56
46 BrokerableAttachment::Type BrokerableAttachment::GetType() const { 57 BrokerableAttachment::Type BrokerableAttachment::GetType() const {
47 return TYPE_BROKERABLE_ATTACHMENT; 58 return TYPE_BROKERABLE_ATTACHMENT;
48 } 59 }
49 60
61 #if defined(OS_POSIX)
62 base::PlatformFile BrokerableAttachment::TakePlatformFile() {
63 NOTREACHED();
64 return base::PlatformFile();
65 }
66 #endif // OS_POSIX
67
50 } // namespace IPC 68 } // namespace IPC
OLDNEW
« no previous file with comments | « ipc/brokerable_attachment.h ('k') | ipc/handle_attachment_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698