Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #138: Set correct file and SE Linux permissions on CA certificates #139

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ An ID of a known permission on Android.

#### Defined in

[android.ts:1102](https://github.com/tweaselORG/appstraction/blob/main/src/android.ts#L1102)
[android.ts:1108](https://github.com/tweaselORG/appstraction/blob/main/src/android.ts#L1108)

___

Expand Down Expand Up @@ -394,7 +394,7 @@ The IDs of known permissions on Android.

#### Defined in

[android.ts:971](https://github.com/tweaselORG/appstraction/blob/main/src/android.ts#L971)
[android.ts:977](https://github.com/tweaselORG/appstraction/blob/main/src/android.ts#L977)

___

Expand Down
12 changes: 9 additions & 3 deletions src/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { fileTypeFromFile } from 'file-type';
import frida from 'frida';
import { open, readFile, rm, writeFile } from 'fs/promises';
import pRetry from 'p-retry';
import { basename, dirname } from 'path';
import { basename, dirname, join } from 'path';
import { major as semverMajor, minVersion as semverMinVersion } from 'semver';
import { temporaryFile } from 'tempy';
import type {
Expand Down Expand Up @@ -786,15 +786,21 @@ export const androidApi = <RunTarget extends SupportedRunTarget<'android'>>(

if (await this._internal.hasCertificateAuthority(certFilename)) return;

const { adbRootPush } = await this._internal.requireRoot('installCertificateAuthority');
const { adbRootShell, adbRootPush } = await this._internal.requireRoot('installCertificateAuthority');

// Since Android 10, we cannot write to `/system` anymore, even if we are root, see:
// https://github.com/tweaselORG/meta/issues/18#issuecomment-1437057934
// Thanks to HTTP Toolkit for the idea to use a tmpfs as a workaround:
// https://github.com/httptoolkit/httptoolkit-server/blob/9658bef164fb5cfce13b2c4b1bedacc158767f57/src/interceptors/android/adb-commands.ts#L228-L230
await this._internal.overlayTmpfs('/system/etc/security/cacerts');
const systemCertPath = '/system/etc/security/cacerts';
await this._internal.overlayTmpfs(systemCertPath);

await adbRootPush(path, `/system/etc/security/cacerts/${certFilename}`);

await adbRootShell([`chown root:root ${join(systemCertPath, '*')}`]);
await adbRootShell([`chmod 655 ${join(systemCertPath, '*')}`]);
await adbRootShell([`chcon u:object_r:system_file:s0 ${join(systemCertPath, '*')}`]);
await adbRootShell([`chcon u:object_r:system_file:s0 ${systemCertPath}`]);
},
async removeCertificateAuthority(path) {
const certFilename = `${await this._internal.getCertificateSubjectHashOld(path)}.0`;
Expand Down