Skip to content

Commit 7d782c9

Browse files
committed
Initial commit
0 parents  commit 7d782c9

8 files changed

Lines changed: 315 additions & 0 deletions

File tree

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
#!/sbin/sh
2+
##########################################################################################
3+
#
4+
# Magisk Module Template Install Script
5+
# by topjohnwu
6+
#
7+
##########################################################################################
8+
9+
# Detect whether in boot mode
10+
ps | grep zygote | grep -v grep >/dev/null && BOOTMODE=true || BOOTMODE=false
11+
$BOOTMODE || ps -A 2>/dev/null | grep zygote | grep -v grep >/dev/null && BOOTMODE=true
12+
13+
# This path should work in any cases
14+
TMPDIR=/dev/tmp
15+
MOUNTPATH=/magisk
16+
IMG=/data/magisk.img
17+
if $BOOTMODE; then
18+
MOUNTPATH=/dev/magisk_merge
19+
IMG=/data/magisk_merge.img
20+
fi
21+
INSTALLER=$TMPDIR/install
22+
MAGISKBIN=/data/magisk
23+
24+
# Default permissions
25+
umask 022
26+
27+
# Initial cleanup
28+
rm -rf $TMPDIR 2>/dev/null
29+
mkdir -p $INSTALLER
30+
31+
##########################################################################################
32+
# Environment
33+
##########################################################################################
34+
35+
OUTFD=$2
36+
ZIP=$3
37+
38+
ui_print() {
39+
if $BOOTMODE; then
40+
echo "$1"
41+
else
42+
echo -n -e "ui_print $1\n" >> /proc/self/fd/$OUTFD
43+
echo -n -e "ui_print\n" >> /proc/self/fd/$OUTFD
44+
fi
45+
}
46+
47+
require_new_magisk() {
48+
ui_print "***********************************"
49+
ui_print "! $MAGISKBIN isn't setup properly!"
50+
ui_print "! Please install Magisk v14.0+!"
51+
ui_print "***********************************"
52+
exit 1
53+
}
54+
55+
ui_print "- Mounting /system, /vendor, /data, /cache"
56+
mount -o ro /system 2>/dev/null
57+
mount -o ro /vendor 2>/dev/null
58+
mount /data 2>/dev/null
59+
mount /cache 2>/dev/null
60+
61+
# Utility functions must exist
62+
[ -f $MAGISKBIN/util_functions.sh ] || require_new_magisk
63+
# Load utility fuctions
64+
. $MAGISKBIN/util_functions.sh
65+
get_outfd
66+
67+
$BOOTMODE && ! is_mounted /magisk && abort "! Magisk is not activated!"
68+
[ ! -f /system/build.prop ] && abort "! /system could not be mounted!"
69+
70+
# Detect version and architecture
71+
api_level_arch_detect
72+
73+
# You can get the Android API version from $API, the CPU architecture from $ARCH
74+
# Useful if you are creating Android version / platform dependent mods
75+
76+
# We need busybox/binaries to be setup
77+
$BOOTMODE && boot_actions || recovery_actions
78+
79+
##########################################################################################
80+
# Preparation
81+
##########################################################################################
82+
83+
# Extract common files
84+
unzip -o "$ZIP" module.prop config.sh 'common/*' -d $INSTALLER 2>/dev/null
85+
86+
[ ! -f $INSTALLER/config.sh ] && abort "! Unable to extract zip file!"
87+
# Load configurations
88+
. $INSTALLER/config.sh
89+
90+
# Check the min magisk version
91+
MIN_VER=`grep_prop template $INSTALLER/module.prop`
92+
[ ! -z $MAGISK_VER_CODE -a $MAGISK_VER_CODE -ge $MIN_VER ] || require_new_magisk
93+
MODID=`grep_prop id $INSTALLER/module.prop`
94+
MODPATH=$MOUNTPATH/$MODID
95+
96+
# Print mod name
97+
print_modname
98+
99+
# Please leave this message in your flashable zip for credits :)
100+
ui_print "******************************"
101+
ui_print "Powered by Magisk (@topjohnwu)"
102+
ui_print "******************************"
103+
104+
##########################################################################################
105+
# Install
106+
##########################################################################################
107+
108+
request_zip_size_check "$ZIP"
109+
110+
if [ -f "$IMG" ]; then
111+
ui_print "- Found $IMG"
112+
image_size_check $IMG
113+
if [ "$reqSizeM" -gt "$curFreeM" ]; then
114+
newSizeM=$(((reqSizeM + curUsedM) / 32 * 32 + 64))
115+
ui_print "- Resizing $IMG to ${newSizeM}M"
116+
$MAGISKBIN/magisk --resizeimg $IMG $newSizeM
117+
fi
118+
else
119+
newSizeM=$((reqSizeM / 32 * 32 + 64));
120+
ui_print "- Creating $IMG with size ${newSizeM}M"
121+
$MAGISKBIN/magisk --createimg $IMG $newSizeM
122+
fi
123+
124+
ui_print "- Mounting $IMG to $MOUNTPATH"
125+
MAGISKLOOP=`$MAGISKBIN/magisk --mountimg $IMG $MOUNTPATH`
126+
is_mounted $MOUNTPATH || abort "! $IMG mount failed..."
127+
128+
# Create mod paths
129+
rm -rf $MODPATH 2>/dev/null
130+
mkdir -p $MODPATH
131+
132+
ui_print "- Extracting module files"
133+
unzip -o "$ZIP" 'system/*' -d $MODPATH 2>/dev/null
134+
135+
# Handle replace folders
136+
for TARGET in $REPLACE; do
137+
mktouch $MODPATH$TARGET/.replace
138+
done
139+
140+
# Auto Mount
141+
$AUTOMOUNT && touch $MODPATH/auto_mount
142+
143+
# prop files
144+
$PROPFILE && cp -af $INSTALLER/common/system.prop $MODPATH/system.prop
145+
146+
# Module info
147+
cp -af $INSTALLER/module.prop $MODPATH/module.prop
148+
if $BOOTMODE; then
149+
# Update info for Magisk Manager
150+
mktouch /magisk/$MODID/update
151+
cp -af $INSTALLER/module.prop /magisk/$MODID/module.prop
152+
fi
153+
154+
# post-fs-data mode scripts
155+
$POSTFSDATA && cp -af $INSTALLER/common/post-fs-data.sh $MODPATH/post-fs-data.sh
156+
157+
# service mode scripts
158+
$LATESTARTSERVICE && cp -af $INSTALLER/common/service.sh $MODPATH/service.sh
159+
160+
ui_print "- Setting permissions"
161+
set_permissions
162+
163+
##########################################################################################
164+
# Finalizing
165+
##########################################################################################
166+
167+
$MAGISKBIN/magisk --umountimg $MOUNTPATH $MAGISKLOOP
168+
rmdir $MOUNTPATH
169+
170+
# Shrink the image if possible
171+
image_size_check $IMG
172+
newSizeM=$((curUsedM / 32 * 32 + 64))
173+
if [ $curSizeM -gt $newSizeM ]; then
174+
ui_print "- Shrinking $IMG to ${newSizeM}M"
175+
$MAGISKBIN/magisk --resizeimg $IMG $newSizeM
176+
fi
177+
178+
$BOOTMODE || recovery_cleanup
179+
rm -rf $TMPDIR
180+
181+
ui_print "- Done"
182+
exit 0
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#MAGISK

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Magisk Trust User Certs
2+
This module makes all installed user certificates part of the system certificate store, so that they will automatically be used when building the trust chain. This module makes it unnecessary to add the network_security_config property to an application's manifest.
3+
4+
### Installation
5+
1. Install [Magisk](https://forum.xda-developers.com/apps/magisk/official-magisk-v7-universal-systemless-t3473445)
6+
2. Zip files `zip -r AlwaysTrustUserCerts.zip ./*` or download zip from releases
7+
3. Install in Magisk
8+
4. Install client certificates through [normal flow](https://support.portswigger.net/customer/portal/articles/1841102-installing-burp-s-ca-certificate-in-an-android-device)
9+
5. Reboot
10+
11+
### Changelog
12+
#### v0.1
13+
* Initial release
14+
15+
Template used from [Magisk's module template](https://github.com/topjohnwu/magisk-module-template)

common/post-fs-data.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/system/bin/sh
2+
# Please don't hardcode /magisk/modname/... ; instead, please use $MODDIR/...
3+
# This will make your scripts compatible even if Magisk change its mount point in the future
4+
MODDIR=${0%/*}
5+
6+
cp -f /data/misc/user/0/cacerts-added/* $MODDIR/system/etc/security/cacerts/
7+
8+
# This script will be executed in post-fs-data mode
9+
# More info in the main Magisk thread

common/service.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/system/bin/sh
2+
# Please don't hardcode /magisk/modname/... ; instead, please use $MODDIR/...
3+
# This will make your scripts compatible even if Magisk change its mount point in the future
4+
MODDIR=${0%/*}
5+
6+
# This script will be executed in late_start service mode
7+
# More info in the main Magisk thread

common/system.prop

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# This file will be read by resetprop
2+
# Example: Change dpi
3+
# ro.sf.lcd_density=320

config.sh

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
##########################################################################################
2+
#
3+
# Magisk Module Template Config Script
4+
# by topjohnwu
5+
#
6+
##########################################################################################
7+
##########################################################################################
8+
#
9+
# Instructions:
10+
#
11+
# 1. Place your files into system folder (delete the placeholder file)
12+
# 2. Fill in your module's info into module.prop
13+
# 3. Configure the settings in this file (common/config.sh)
14+
# 4. For advanced features, add shell commands into the script files under common:
15+
# post-fs-data.sh, service.sh
16+
# 5. For changing props, add your additional/modified props into common/system.prop
17+
#
18+
##########################################################################################
19+
20+
##########################################################################################
21+
# Configs
22+
##########################################################################################
23+
24+
# Set to true if you need to enable Magic Mount
25+
# Most mods would like it to be enabled
26+
AUTOMOUNT=true
27+
28+
# Set to true if you need to load system.prop
29+
PROPFILE=false
30+
31+
# Set to true if you need post-fs-data script
32+
POSTFSDATA=true
33+
34+
# Set to true if you need late_start service script
35+
LATESTARTSERVICE=false
36+
37+
##########################################################################################
38+
# Installation Message
39+
##########################################################################################
40+
41+
# Set what you want to show when installing your mod
42+
43+
print_modname() {
44+
ui_print "****************************************"
45+
ui_print "Adding user certificates to system store "
46+
ui_print "****************************************"
47+
}
48+
49+
##########################################################################################
50+
# Replace list
51+
##########################################################################################
52+
53+
# List all directories you want to directly replace in the system
54+
# By default Magisk will merge your files with the original system
55+
# Directories listed here however, will be directly mounted to the correspond directory in the system
56+
57+
# You don't need to remove the example below, these values will be overwritten by your own list
58+
# This is an example
59+
REPLACE="
60+
/system/app/Youtube
61+
/system/priv-app/SystemUI
62+
/system/priv-app/Settings
63+
/system/framework
64+
"
65+
66+
# Construct your own list here, it will overwrite the example
67+
# !DO NOT! remove this if you don't need to replace anything, leave it empty as it is now
68+
REPLACE="
69+
"
70+
71+
##########################################################################################
72+
# Permissions
73+
##########################################################################################
74+
75+
set_permissions() {
76+
# Only some special files require specific permissions
77+
# The default permissions should be good enough for most cases
78+
79+
# Here are some examples for the set_perm functions:
80+
81+
# set_perm_recursive <dirname> <owner> <group> <dirpermission> <filepermission> <contexts> (default: u:object_r:system_file:s0)
82+
# set_perm_recursive $MODPATH/system/lib 0 0 0755 0644
83+
84+
# set_perm <filename> <owner> <group> <permission> <contexts> (default: u:object_r:system_file:s0)
85+
# set_perm $MODPATH/system/bin/app_process32 0 2000 0755 u:object_r:zygote_exec:s0
86+
# set_perm $MODPATH/system/bin/dex2oat 0 2000 0755 u:object_r:dex2oat_exec:s0
87+
# set_perm $MODPATH/system/lib/libart.so 0 0 0644
88+
89+
# The following is default permissions, DO NOT remove
90+
set_perm_recursive $MODPATH 0 0 0755 0644
91+
}

module.prop

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
id=trustusercerts
2+
name=Always Trust User Certificates
3+
version=v0.1
4+
versionCode=1
5+
author=Jeroen Beckers (NVISO.be)
6+
description=This module adds all installed user certificates to the system trust store.
7+
template=1400

0 commit comments

Comments
 (0)