xref: /aosp_15_r20/external/libchrome/ipc/ipc_security_test_util.h (revision 635a864187cb8b6c713ff48b7e790a6b21769273)
1*635a8641SAndroid Build Coastguard Worker // Copyright 2014 The Chromium Authors. All rights reserved.
2*635a8641SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*635a8641SAndroid Build Coastguard Worker // found in the LICENSE file.
4*635a8641SAndroid Build Coastguard Worker 
5*635a8641SAndroid Build Coastguard Worker #ifndef IPC_IPC_SECURITY_TEST_UTIL_H_
6*635a8641SAndroid Build Coastguard Worker #define IPC_IPC_SECURITY_TEST_UTIL_H_
7*635a8641SAndroid Build Coastguard Worker 
8*635a8641SAndroid Build Coastguard Worker #include "base/macros.h"
9*635a8641SAndroid Build Coastguard Worker 
10*635a8641SAndroid Build Coastguard Worker namespace IPC {
11*635a8641SAndroid Build Coastguard Worker 
12*635a8641SAndroid Build Coastguard Worker class ChannelProxy;
13*635a8641SAndroid Build Coastguard Worker class Message;
14*635a8641SAndroid Build Coastguard Worker 
15*635a8641SAndroid Build Coastguard Worker class IpcSecurityTestUtil {
16*635a8641SAndroid Build Coastguard Worker  public:
17*635a8641SAndroid Build Coastguard Worker   // Enables testing of security exploit scenarios where a compromised child
18*635a8641SAndroid Build Coastguard Worker   // process can send a malicious message of an arbitrary type.
19*635a8641SAndroid Build Coastguard Worker   //
20*635a8641SAndroid Build Coastguard Worker   // This function will post the message to the IPC channel's thread, where it
21*635a8641SAndroid Build Coastguard Worker   // is offered to the channel's listeners. Afterwards, a reply task is posted
22*635a8641SAndroid Build Coastguard Worker   // back to the current thread. This function blocks until the reply task is
23*635a8641SAndroid Build Coastguard Worker   // received. For messages forwarded back to the current thread, we won't
24*635a8641SAndroid Build Coastguard Worker   // return until after the message has been handled here.
25*635a8641SAndroid Build Coastguard Worker   //
26*635a8641SAndroid Build Coastguard Worker   // Use this only for testing security bugs in a browsertest; other uses are
27*635a8641SAndroid Build Coastguard Worker   // likely perilous. Unit tests should be using IPC::TestSink which has an
28*635a8641SAndroid Build Coastguard Worker   // OnMessageReceived method you can call directly. Non-security browsertests
29*635a8641SAndroid Build Coastguard Worker   // should just exercise the child process's normal codepaths to send messages.
30*635a8641SAndroid Build Coastguard Worker   static void PwnMessageReceived(ChannelProxy* channel, const Message& message);
31*635a8641SAndroid Build Coastguard Worker 
32*635a8641SAndroid Build Coastguard Worker  private:
33*635a8641SAndroid Build Coastguard Worker   IpcSecurityTestUtil();  // Not instantiable.
34*635a8641SAndroid Build Coastguard Worker 
35*635a8641SAndroid Build Coastguard Worker   DISALLOW_COPY_AND_ASSIGN(IpcSecurityTestUtil);
36*635a8641SAndroid Build Coastguard Worker };
37*635a8641SAndroid Build Coastguard Worker 
38*635a8641SAndroid Build Coastguard Worker }  // namespace IPC
39*635a8641SAndroid Build Coastguard Worker 
40*635a8641SAndroid Build Coastguard Worker #endif  // IPC_IPC_SECURITY_TEST_UTIL_H_
41