Skip to content

Commit

Permalink
Inline NSC XML template
Browse files Browse the repository at this point in the history
This makes it possible to include apk-mitm in a project built with
webpack (like APK Lab).
  • Loading branch information
niklashigi committed Jan 18, 2021
1 parent 0c1d87d commit ae998f9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
"bin": "bin/apk-mitm",
"files": [
"bin",
"dist",
"res"
"dist"
],
"engines": {
"node": ">=10"
Expand Down
11 changes: 0 additions & 11 deletions res/nsc_mitm.xml

This file was deleted.

14 changes: 12 additions & 2 deletions src/tasks/create-netsec-config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import * as fs from '../utils/fs'
import * as pathUtils from 'path'

const TEMPLATE_PATH = pathUtils.join(__dirname, '../../res/nsc_mitm.xml')
const TEMPLATE = `<?xml version="1.0" encoding="utf-8"?>
<!-- Intentionally lax Network Security Configuration (generated by apk-mitm) -->
<network-security-config>
<!-- Allow cleartext traffic -->
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<!-- Allow user-added (proxy) certificates -->
<certificates src="user" />
</trust-anchors>
</base-config>
</network-security-config>`

export default async function createNetworkSecurityConfig(path: string) {
await fs.mkdir(pathUtils.dirname(path), { recursive: true })
await fs.copyFile(TEMPLATE_PATH, path)
await fs.writeFile(path, TEMPLATE, 'utf-8')
}

0 comments on commit ae998f9

Please sign in to comment.