• Stars
    star
    989
  • Rank 46,300 (Top 1.0 %)
  • Language
    C
  • License
    Other
  • Created almost 8 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🛡 Make safest code in Android. (基于libsodium实现chacha20算法,key在native中,防止被二次打包){长期维护,请star,勿fork}

English

中文

Reach high security with libsodium on Android

I have no longer supported AES algorithms. Still need it, you can check out tag: v2.2.

  • Use CHACHA20 instead of AES. I have to mention that TLS1.3 use CHACHA20 on mobile devices too. It is high-performance for the ARM architecture.

  • Hide native function in JniOnload

  • Use signature verification to avoid second-packaged. (It prevents hackers call your JNI method directly.)

  • key exists in the symbol table, and hides the character table. This approach has been deprecated due to discard reason issues5

  • Obtain the key from a complex function, to hide the key, currently, the function is a simple solution. (Complex solution: divide the Key into several pieces, store them in different C files, and finally splice them together. This function should be complicated to write and increase the decompiling difficulty.)

  • Use "obfuscator" to confuse C code, how to deobfuscate it?

  • Supporting x86 of obfuscation. A link at the bottom is a tutorial for configuring obfuscation.

  • Anti-debugging. Currently, I put a simple solution into code, but there are complicated and sophisticated solutions. I recommend determining whether it is traced in every encryption and decryption. You can add other complicated algorithms to your fork.

  • Detecting device is an emulator during runtime. This feature comes from my another repo Check_Emulator_In_NDK

  • TODO: Prevent SO file injecting from hackers.

build & run it.

click to expand.
  1. preparation:

run the shell : ./build_libsodium_for_all_android_abi.sh When you run the shell, some error you may got some error like this: env: python: No such file or directory , `See "config.log" for more details or others.

Please, take time to solve them.

If the shell runs well, many files, such as .a & .so, will be copied into aesjni/src/main/jni/sodium_include/. Also, you would see All of static libs has been moved into ...... at terminal.

  1. click run app from ADB to look at logcat, some result of execution will be there

how to integrate it into my project?

click to expand. a. generating a chacha20 key:

run test_in_exexutaing.sh, and look at logcat. It will generate key and nonce. You can paste it into JNIEntry.c.

b. Set ndk.dir in local.properties. Some NDK versions have not been tested you may encounter build errors from them.

c. As you integrate it into the project, please modify class names and method names, don't expose the name of the encryption algorithm, modify the C function of key storage from my code.

d. Generate and modify signatures.

d.1. Generate Keystore file(You should jump this step in case you already have Keystore.)

# my generate record:
mkdir keystore
cd keystore/
keytool -genkey -alias client1 -keypass 123456 -keyalg RSA -keysize 1024 -validity 365 -storetype PKCS12 -keystore ./androidyuan.keystore

d.2. Modify hash of your keystore and pkg-name in check_signature.h.

As you obtain the hash, you should use this method: getSignature(), to get.

Please copy the keystore hashcode and package name into check_signature.h.

Remind: SO file will become bigger

unconfused so confused so

The size of the confused SO file may be three times the size of the original SO file. If the size bothers you, you can disable obfuscator-lvvm. It is unnecessary.

In addition, what I have to tell you:

Because you need to do signature verification, I can't provide jcenter dependencies, pls forgive me!

Even though this code is very safe, I am still against storing keys in code. The key that shouldn't be constant should be temporary and generated. If you know how SSL works, you may think that asymmetric encryption transferring the key is the safest in the world. If you don’t know how SSL works, I recommend a blog from Cloudflare: what-is-asymmetric-encryption

To confuse native code, you need to modify the externalNativeBuild in the aesjni/build.gradle and configure the Obfuscator-LLVM under the NDK.

This is my NDK configuration obfuscator tutorial: Obfuscator-LLVM-4.0-BUILD-NDK.

In another way, you can build it on docker. Maybe you think configuring Obfuscator-LLVM is really difficult. I recommend using docker : github.com/nickdiego/docker-ollvm.

How do other languages ​​work together with encryption and decryption?

If you got a crash, you can look into FigureOutJNICrash.md to find where this code crashed at.


Legal

If you live in China, you should take care of checking apk signature. In this code, I use PackageManger which may be misunderstood to collect a list of apps installed. You should look at 工信部整治八项违规.

Contributing

In case you would like to add information to this repository or suggest some ideas, please use one of the following options:

Contributor

https://github.com/larry19840909

https://github.com/zxp0505

https://github.com/baoyongzhang

Thanks

Libsodium Algorithm from: https://github.com/jedisct1/libsodium

Native code obfuscator: obfuscation-o-llvm-ndk

More Repositories

1

AndroidScreenShot_SysApi

To take screenshots easily with Android 5.0 API.{优雅地实现屏幕截图,用android 5.0之后的录屏API实现}
Java
677
star
2

Image-Anti-OCR

HTML
71
star
3

OperatingImageBypassJavaHeap

Bypassing java heap to operate images,will 100% avoid OOM (Maintenance stopped)绕过java heap操作图片,100%避开OOM
C
42
star
4

Obfuscator-LLVM-4.0-BUILD-NDK

Obfuscator-LLVM 4.0 build & setup into NDK
Shell
35
star
5

GcoreCDNIPSelector

🔍 to choose the best Gcore‘IPs for connection 📶 with lowest latency.(gcore优选ip)
JavaScript
24
star
6

passwordopen_wordpress

wordpress的漏洞,可以通过暴力破解获得管理员密码。
Python
14
star
7

CloudFrontIPSelector

🔍To choose the best CloudFront IPs for achieving fast and low-latency connections
JavaScript
13
star
8

SoftCodec

📀 Encoding YUV into H.246 & transmit it to rtmp server.
C
11
star
9

AndroidRemoteBuilder

🛳️ A docker image for building large project on remote&powerful server to save your time. (远程编译Android Project)
Shell
10
star
10

Juao

🚄 fast cache much more than JVM heap memory in Android.(在安卓上利用更多的物理RAM,快速地存取巨量的Java对象)
Java
8
star
11

CryptoPPInNDK

A repo for hiding encrypt algorithm working with CryptoPP.
C++
7
star
12

GuetzliAndroid

Guetzli on android.
C
6
star
13

EncryptJni

用NDK实现的Base64和MD5算法。
C
6
star
14

Fireworks

view爆炸的烟花效果,已开发完毕。
Java
5
star
15

TodayGasInWechat

今日油价,微信小程序
JavaScript
4
star
16

fear-and-greed-index-alarm

A notification reminder for indicating when the CNN Fear and Greed Index is out of range.
JavaScript
4
star
17

GeneratorX

generate class in java.
Java
3
star
18

auto_send_weather2qqzone

自动把天气信息或者AQI指数通过qq空间发出去。
JavaScript
3
star
19

Text2QrCodeWithAndroid

Generate qr code with least java code.(用最少的代码生成二维码)
Java
3
star
20

ExamVocabulary

Several lists of words aren't only for exams, but also for immigration.
Python
2
star
21

auto_build_lastest_x264

Automatically clone x264 the latest source code, and then build the .a file of the android arm platform.
Shell
2
star
22

show_video_fps

Show vps which player decoded.(显示播放端真正拉到的FPS的值)
Java
2
star
23

JarHook

An example about hooking a method in jar.
Java
2
star
24

BaotaPanelShells

There are shells about Baota panel. And then those shells are used to manage my ubuntu pc.
Shell
1
star
25

wordpress-multiple-services-in-one

🛳️ Manage multiple WordPress instances on a single computer with flexible multi-port configuration.
1
star
26

JNI_CCallJava

一个c调用java的 demo
Java
1
star
27

MUIHybridScaffhold

A hybrid app Scaffhold established with MUI and ReactJS.
TypeScript
1
star
28

RxBroadcaster

使用RxJava实现Broadcaster
Java
1
star
29

rxpermissions

rxpermissions
Java
1
star
30

RustPractice

Rust
1
star
31

asciio_docker

Run asciio with docker on MacOS.
Dockerfile
1
star
32

LibjpegBuild

build libjpeg..
Shell
1
star
33

remind_someting_on_startup

Remind me to take sign in in company.(ubuntu的一个提醒的脚本,解决每天到公司早上忘记打卡的问题)
Python
1
star
34

TFNodeJsExamples

An example for recognizing porn by loading Tensorflow model
JavaScript
1
star
35

CompressImagesInAndroid

to automaticly compress large imgs on CI/Actions.
Shell
1
star
36

BruceWind

1
star
37

Java_code_clean_lib_demo

集合了今年 比较新的几个,来缩减java代码的仓库。(今天,12.30号。)
Java
1
star
38

BruceWind.github.io

JavaScript
1
star
39

MyRNExercise

Excecising React Native.
Java
1
star
40

my_refind

It is a customisation for me to config rEFInd which is used to lead either Ubuntu and MAC os on macbook startup.
Shell
1
star
41

CPSensor

A cross-platform sensor app, like a 🦮 , which just settle in a system tray to oversee battery, CPU, memory and others.
JavaScript
1
star