Index: ipc/brokerable_attachment.cc |
diff --git a/ipc/brokerable_attachment.cc b/ipc/brokerable_attachment.cc |
index be5d51b2069451e25eb1ff987fb48bfd32e9b166..5caed2842a48ae666829e54dbd4c5a88491fdc1a 100644 |
--- a/ipc/brokerable_attachment.cc |
+++ b/ipc/brokerable_attachment.cc |
@@ -4,9 +4,24 @@ |
#include "ipc/brokerable_attachment.h" |
+#include "crypto/random.h" |
+ |
namespace IPC { |
-BrokerableAttachment::BrokerableAttachment() { |
+namespace { |
+ |
+// In order to prevent mutually untrusted processes from stealing resources from |
+// one another, the nonce must be secret. This generates a 128-bit, |
+// cryptographicaly-strong random number. |
+BrokerableAttachment::AttachmentId GetRandomId() { |
+ BrokerableAttachment::AttachmentId id; |
+ crypto::RandBytes(id.nonce, BrokerableAttachment::kNonceSize); |
+ return id; |
+} |
+ |
+} // namespace |
+ |
+BrokerableAttachment::BrokerableAttachment() : id_(GetRandomId()) { |
} |
BrokerableAttachment::~BrokerableAttachment() { |
@@ -16,4 +31,8 @@ BrokerableAttachment::AttachmentId BrokerableAttachment::GetIdentifier() const { |
return id_; |
} |
+BrokerableAttachment::Type BrokerableAttachment::GetType() const { |
+ return TYPE_BROKERABLE_ATTACHMENT; |
+} |
+ |
} // namespace IPC |