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

Side by Side Diff: ipc/brokerable_attachment.cc

Issue 1321093003: ipc: Add methods for AttachmentBroker nonce serialization. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments from tsepez. Created 5 years, 3 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') | no next file » | 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 {
12 15
16 #if USE_ATTACHMENT_BROKER
17 BrokerableAttachment::AttachmentId::AttachmentId() {
13 // In order to prevent mutually untrusted processes from stealing resources from 18 // In order to prevent mutually untrusted processes from stealing resources from
14 // one another, the nonce must be secret. This generates a 128-bit, 19 // one another, the nonce must be secret. This generates a 128-bit,
15 // cryptographicaly-strong random number. 20 // cryptographicaly-strong random number.
16 BrokerableAttachment::AttachmentId GetRandomId() { 21 crypto::RandBytes(nonce, BrokerableAttachment::kNonceSize);
17 BrokerableAttachment::AttachmentId id; 22 }
18 crypto::RandBytes(id.nonce, BrokerableAttachment::kNonceSize); 23 #else
19 return id; 24 BrokerableAttachment::AttachmentId::AttachmentId() {
25 CHECK(false) << "Not allowed to construct an attachment id if the platform "
26 "does not support attachment brokering.";
27 }
28 #endif
29
30 BrokerableAttachment::AttachmentId::AttachmentId(const char* start_address,
31 size_t size) {
32 DCHECK(size == BrokerableAttachment::kNonceSize);
33 for (size_t i = 0; i < BrokerableAttachment::kNonceSize; ++i)
34 nonce[i] = start_address[i];
20 } 35 }
21 36
22 } // namespace 37 void BrokerableAttachment::AttachmentId::SerializeToBuffer(char* start_address,
38 size_t size) {
39 DCHECK(size == BrokerableAttachment::kNonceSize);
40 for (size_t i = 0; i < BrokerableAttachment::kNonceSize; ++i)
41 start_address[i] = nonce[i];
42 }
23 43
24 BrokerableAttachment::BrokerableAttachment() 44 BrokerableAttachment::BrokerableAttachment()
25 : id_(GetRandomId()), needs_brokering_(false) {} 45 : needs_brokering_(false) {}
26 46
27 BrokerableAttachment::BrokerableAttachment(const AttachmentId& id, 47 BrokerableAttachment::BrokerableAttachment(const AttachmentId& id,
28 bool needs_brokering) 48 bool needs_brokering)
29 : id_(id), needs_brokering_(needs_brokering) {} 49 : id_(id), needs_brokering_(needs_brokering) {}
30 50
31 BrokerableAttachment::~BrokerableAttachment() { 51 BrokerableAttachment::~BrokerableAttachment() {
32 } 52 }
33 53
34 BrokerableAttachment::AttachmentId BrokerableAttachment::GetIdentifier() const { 54 BrokerableAttachment::AttachmentId BrokerableAttachment::GetIdentifier() const {
35 return id_; 55 return id_;
36 } 56 }
37 57
38 bool BrokerableAttachment::NeedsBrokering() const { 58 bool BrokerableAttachment::NeedsBrokering() const {
39 return needs_brokering_; 59 return needs_brokering_;
40 } 60 }
41 61
42 void BrokerableAttachment::SetNeedsBrokering(bool needs_brokering) { 62 void BrokerableAttachment::SetNeedsBrokering(bool needs_brokering) {
43 needs_brokering_ = needs_brokering; 63 needs_brokering_ = needs_brokering;
44 } 64 }
45 65
46 BrokerableAttachment::Type BrokerableAttachment::GetType() const { 66 BrokerableAttachment::Type BrokerableAttachment::GetType() const {
47 return TYPE_BROKERABLE_ATTACHMENT; 67 return TYPE_BROKERABLE_ATTACHMENT;
48 } 68 }
49 69
50 } // namespace IPC 70 } // namespace IPC
OLDNEW
« no previous file with comments | « ipc/brokerable_attachment.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698