OLD | NEW |
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 "crypto/random.h" |
| 8 |
7 namespace IPC { | 9 namespace IPC { |
8 | 10 |
9 BrokerableAttachment::BrokerableAttachment() { | 11 namespace { |
| 12 |
| 13 // In order to prevent mutually untrusted processes from stealing resources from |
| 14 // one another, the nonce must be secret. This generates a 128-bit, |
| 15 // cryptographicaly-strong random number. |
| 16 BrokerableAttachment::AttachmentId GetRandomId() { |
| 17 BrokerableAttachment::AttachmentId id; |
| 18 crypto::RandBytes(id.nonce, BrokerableAttachment::kNonceSize); |
| 19 return id; |
| 20 } |
| 21 |
| 22 } // namespace |
| 23 |
| 24 BrokerableAttachment::BrokerableAttachment() : id_(GetRandomId()) { |
10 } | 25 } |
11 | 26 |
12 BrokerableAttachment::~BrokerableAttachment() { | 27 BrokerableAttachment::~BrokerableAttachment() { |
13 } | 28 } |
14 | 29 |
15 BrokerableAttachment::AttachmentId BrokerableAttachment::GetIdentifier() const { | 30 BrokerableAttachment::AttachmentId BrokerableAttachment::GetIdentifier() const { |
16 return id_; | 31 return id_; |
17 } | 32 } |
18 | 33 |
| 34 BrokerableAttachment::Type BrokerableAttachment::GetType() const { |
| 35 return TYPE_BROKERABLE_ATTACHMENT; |
| 36 } |
| 37 |
19 } // namespace IPC | 38 } // namespace IPC |
OLD | NEW |