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
3 // found in the LICENSE file.
5 #include "ipc/brokerable_attachment.h"
7 #include "ipc/attachment_broker.h"
9 #if USE_ATTACHMENT_BROKER
10 #include "crypto/random.h"
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
);
23 BrokerableAttachment::AttachmentId::AttachmentId() {
24 CHECK(false) << "Not allowed to construct an attachment id if the platform "
25 "does not support attachment brokering.";
29 BrokerableAttachment::AttachmentId::AttachmentId(const char* start_address
,
31 DCHECK(size
== BrokerableAttachment::kNonceSize
);
32 for (size_t i
= 0; i
< BrokerableAttachment::kNonceSize
; ++i
)
33 nonce
[i
] = start_address
[i
];
36 void BrokerableAttachment::AttachmentId::SerializeToBuffer(char* start_address
,
38 DCHECK(size
== BrokerableAttachment::kNonceSize
);
39 for (size_t i
= 0; i
< BrokerableAttachment::kNonceSize
; ++i
)
40 start_address
[i
] = nonce
[i
];
43 BrokerableAttachment::BrokerableAttachment() {}
45 BrokerableAttachment::BrokerableAttachment(const AttachmentId
& id
) : id_(id
) {}
47 BrokerableAttachment::~BrokerableAttachment() {}
49 BrokerableAttachment::AttachmentId
BrokerableAttachment::GetIdentifier() const {
53 bool BrokerableAttachment::NeedsBrokering() const {
54 return GetBrokerableType() == PLACEHOLDER
;
57 BrokerableAttachment::Type
BrokerableAttachment::GetType() const {
58 return TYPE_BROKERABLE_ATTACHMENT
;
62 base::PlatformFile
BrokerableAttachment::TakePlatformFile() {
64 return base::PlatformFile();