Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
michael@0 | 2 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 3 | // found in the LICENSE file. |
michael@0 | 4 | |
michael@0 | 5 | #include <windows.h> |
michael@0 | 6 | #include <atlsecurity.h> |
michael@0 | 7 | |
michael@0 | 8 | #include "base/win/windows_version.h" |
michael@0 | 9 | #include "testing/gtest/include/gtest/gtest.h" |
michael@0 | 10 | #include "sandbox/win/src/sandbox.h" |
michael@0 | 11 | #include "sandbox/win/src/sandbox_policy.h" |
michael@0 | 12 | #include "sandbox/win/src/sandbox_factory.h" |
michael@0 | 13 | #include "sandbox/win/tests/common/controller.h" |
michael@0 | 14 | |
michael@0 | 15 | namespace sandbox { |
michael@0 | 16 | |
michael@0 | 17 | |
michael@0 | 18 | SBOX_TESTS_COMMAND int CheckIntegrityLevel(int argc, wchar_t **argv) { |
michael@0 | 19 | ATL::CAccessToken token; |
michael@0 | 20 | if (!token.GetEffectiveToken(TOKEN_READ)) |
michael@0 | 21 | return SBOX_TEST_FAILED; |
michael@0 | 22 | |
michael@0 | 23 | char* buffer[100]; |
michael@0 | 24 | DWORD buf_size = 100; |
michael@0 | 25 | if (!::GetTokenInformation(token.GetHandle(), TokenIntegrityLevel, |
michael@0 | 26 | reinterpret_cast<void*>(buffer), buf_size, |
michael@0 | 27 | &buf_size)) |
michael@0 | 28 | return SBOX_TEST_FAILED; |
michael@0 | 29 | |
michael@0 | 30 | TOKEN_MANDATORY_LABEL* label = |
michael@0 | 31 | reinterpret_cast<TOKEN_MANDATORY_LABEL*>(buffer); |
michael@0 | 32 | |
michael@0 | 33 | PSID sid_low = NULL; |
michael@0 | 34 | if (!::ConvertStringSidToSid(L"S-1-16-4096", &sid_low)) |
michael@0 | 35 | return SBOX_TEST_FAILED; |
michael@0 | 36 | |
michael@0 | 37 | BOOL is_low_sid = ::EqualSid(label->Label.Sid, sid_low); |
michael@0 | 38 | |
michael@0 | 39 | ::LocalFree(sid_low); |
michael@0 | 40 | |
michael@0 | 41 | if (is_low_sid) |
michael@0 | 42 | return SBOX_TEST_SUCCEEDED; |
michael@0 | 43 | |
michael@0 | 44 | return SBOX_TEST_DENIED; |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | TEST(IntegrityLevelTest, TestLowILReal) { |
michael@0 | 48 | if (base::win::GetVersion() != base::win::VERSION_VISTA) |
michael@0 | 49 | return; |
michael@0 | 50 | |
michael@0 | 51 | TestRunner runner(JOB_LOCKDOWN, USER_INTERACTIVE, USER_INTERACTIVE); |
michael@0 | 52 | |
michael@0 | 53 | runner.SetTimeout(INFINITE); |
michael@0 | 54 | |
michael@0 | 55 | runner.GetPolicy()->SetIntegrityLevel(INTEGRITY_LEVEL_LOW); |
michael@0 | 56 | |
michael@0 | 57 | EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckIntegrityLevel")); |
michael@0 | 58 | |
michael@0 | 59 | runner.SetTestState(BEFORE_REVERT); |
michael@0 | 60 | EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckIntegrityLevel")); |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | TEST(DelayedIntegrityLevelTest, TestLowILDelayed) { |
michael@0 | 64 | if (base::win::GetVersion() != base::win::VERSION_VISTA) |
michael@0 | 65 | return; |
michael@0 | 66 | |
michael@0 | 67 | TestRunner runner(JOB_LOCKDOWN, USER_INTERACTIVE, USER_INTERACTIVE); |
michael@0 | 68 | |
michael@0 | 69 | runner.SetTimeout(INFINITE); |
michael@0 | 70 | |
michael@0 | 71 | runner.GetPolicy()->SetDelayedIntegrityLevel(INTEGRITY_LEVEL_LOW); |
michael@0 | 72 | |
michael@0 | 73 | EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckIntegrityLevel")); |
michael@0 | 74 | |
michael@0 | 75 | runner.SetTestState(BEFORE_REVERT); |
michael@0 | 76 | EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"CheckIntegrityLevel")); |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | TEST(IntegrityLevelTest, TestNoILChange) { |
michael@0 | 80 | if (base::win::GetVersion() != base::win::VERSION_VISTA) |
michael@0 | 81 | return; |
michael@0 | 82 | |
michael@0 | 83 | TestRunner runner(JOB_LOCKDOWN, USER_INTERACTIVE, USER_INTERACTIVE); |
michael@0 | 84 | |
michael@0 | 85 | runner.SetTimeout(INFINITE); |
michael@0 | 86 | |
michael@0 | 87 | EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"CheckIntegrityLevel")); |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | } // namespace sandbox |