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

Obfuscation with V2Ray #296

Open
wants to merge 33 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
6bc76cc
feat: create config.json
jurajhilje Nov 3, 2023
d468e62
feat: create V2RayConfig.kt
jurajhilje Nov 3, 2023
758be62
refactor: clean up V2RayConfig.kt
jurajhilje Nov 3, 2023
e4fc62e
feat: create V2RayCore.kt
jurajhilje Nov 4, 2023
66c4fa4
feat: create V2RaySettings.kt
jurajhilje Nov 4, 2023
595da2c
feat: update V2RaySettings.kt
jurajhilje Nov 4, 2023
fe62631
feat: update Mapper.kt
jurajhilje Nov 5, 2023
df47202
feat: update Settings.kt
jurajhilje Nov 5, 2023
ed96b63
feat: update ServersRepository.kt
jurajhilje Nov 5, 2023
16267b8
feat: update Settings.kt
jurajhilje Nov 5, 2023
7c48ee8
feat: update ServersRepository.kt
jurajhilje Nov 8, 2023
4b681a2
refactor: clean up V2RaySettings.kt
jurajhilje Nov 8, 2023
3dabd5b
Merge branch 'task/upgrade-wireguard-kotlin1.8.0-agp8.0.2-tools' into…
jurajhilje Nov 8, 2023
fd8a7bc
feat: update Settings.kt
jurajhilje Nov 9, 2023
d863741
feat: add setV2ray method in ConfigManager.kt
jurajhilje Nov 9, 2023
9287fe3
feat: update Host model
jurajhilje Nov 9, 2023
369ee70
feat: V2RayCore.kt
jurajhilje Nov 9, 2023
aca89f2
feat: create v2ray-config.json
jurajhilje Nov 9, 2023
d6787af
feat: update ConfigManager.kt
jurajhilje Nov 9, 2023
cadaa27
refactor: clean up Config.java
jurajhilje Nov 9, 2023
36f1e4f
refactor: update ConfigManager.kt
jurajhilje Nov 9, 2023
fe9b7fc
feat: update core/build.gradle
jurajhilje Nov 10, 2023
4076017
feat: update V2RayCore.kt
jurajhilje Nov 10, 2023
e2702e2
feat: create build-v2ray.sh
jurajhilje Nov 10, 2023
bd5a378
feat: create v2ray module
jurajhilje Nov 11, 2023
66a9529
feat: update core/build.gradle
jurajhilje Nov 12, 2023
d4ff316
feat: update core/build.gradle
jurajhilje Nov 12, 2023
63a225c
ci: update build.yml and codeql.yml
jurajhilje Nov 13, 2023
1a5b454
ci: update core/build.gradle
jurajhilje Nov 13, 2023
7e76913
Merge branch 'develop' into feature/v2ray
jurajhilje Dec 3, 2023
01665f7
Merge branch 'develop' into feature/v2ray
jurajhilje Dec 12, 2023
a11c1f9
Merge branch 'develop' into feature/v2ray
jurajhilje Dec 13, 2023
92900dd
Merge branch 'develop' into feature/v2ray
jurajhilje Jun 3, 2024
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
14 changes: 14 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ jobs:

- name: Install liboqs dependencies
run: sudo apt-get update && sudo apt-get install -y astyle cmake gcc ninja-build libssl-dev python3-pytest python3-pytest-xdist unzip xsltproc doxygen graphviz python3-yaml valgrind

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19

- name: Install Gomobile
run: |
go install golang.org/x/mobile/cmd/gomobile@latest
go install golang.org/x/mobile/cmd/gobind@latest
gomobile init

- name: Build V2Ray
run: ./v2ray/build.sh

- name: Set up JDK 17
uses: actions/setup-java@v3
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ jobs:

- name: Checkout submodules
run: git submodule update --init --recursive

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19

- name: Install Gomobile
run: |
go install golang.org/x/mobile/cmd/gomobile@latest
go install golang.org/x/mobile/cmd/gobind@latest
gomobile init

- name: Build V2Ray
run: ./v2ray/build.sh

- name: Set up JDK 17
uses: actions/setup-java@v3
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ keystore.properties
/.idea/
/core/.cxx/
core/.cxx/
v2ray/libs/
/store/production/
/production/
liboqs-android/**/*.so
13 changes: 12 additions & 1 deletion core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def File registerGenTask(variantName, variantDirName) {
def kemScript = "./../liboqs-android/jni/liboqs/scripts/build-android.sh"
def kemPlatform = "android-21"
def kemMechanisms = "KEM_kyber_1024;"
def v2rayScript = "./../v2ray/build.sh"

tasks.register("buildLiboqsARM64", Exec) {
commandLine kemScript, android.ndkDirectory, "-a", "arm64-v8a", "-p", kemPlatform, "-m", kemMechanisms
Expand All @@ -157,26 +158,33 @@ tasks.register("buildLiboqsX86", Exec) {
commandLine kemScript, android.ndkDirectory, "-a", "x86", "-p", kemPlatform, "-m", kemMechanisms
}

tasks.register("buildV2ray", Exec) {
commandLine v2rayScript
}

android.libraryVariants.all { variant ->
def sourceDir = registerGenTask(variant.name, variant.baseName.replace("-", "/"))
def generateOpenVPN3Swig = tasks.named("generateOpenVPN3Swig${variant.name}").get()
def buildLiboqsARM64 = tasks.named("buildLiboqsARM64").get()
def buildLiboqsARM = tasks.named("buildLiboqsARM").get()
def buildLiboqsX8664 = tasks.named("buildLiboqsX8664").get()
def buildLiboqsX86 = tasks.named("buildLiboqsX86").get()
def buildV2ray = tasks.named("buildV2ray").get()
variant.registerJavaGeneratingTask(generateOpenVPN3Swig, sourceDir)
variant.registerJavaGeneratingTask(buildLiboqsARM64, sourceDir)
variant.registerJavaGeneratingTask(buildLiboqsARM, sourceDir)
variant.registerJavaGeneratingTask(buildLiboqsX8664, sourceDir)
variant.registerJavaGeneratingTask(buildLiboqsX86, sourceDir)
variant.registerJavaGeneratingTask(buildV2ray, sourceDir)
}

project.afterEvaluate {
preBuild.dependsOn(
tasks.named("buildLiboqsARM64").get(),
tasks.named("buildLiboqsARM").get(),
tasks.named("buildLiboqsX8664").get(),
tasks.named("buildLiboqsX86").get()
tasks.named("buildLiboqsX86").get(),
tasks.named("buildV2ray").get()
)
}

Expand Down Expand Up @@ -278,6 +286,9 @@ dependencies {
// liboqs
implementation project(path: ':liboqs-android')

// V2Ray
implementation project(path: ':v2ray')

// For crash logging.
implementation 'io.sentry:sentry-android:4.3.0'
implementation "androidx.multidex:multidex:2.0.1"
Expand Down
70 changes: 70 additions & 0 deletions core/src/main/assets/v2ray-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"log":{
"loglevel":"debug"
},
"inbounds":[
{
"tag":"vpn",
"port":"16661",
"listen":"127.0.0.1",
"protocol":"dokodemo-door",
"settings":{
"address":"",
"port":0,
"network":"udp"
}
}
],
"outbounds":[
{
"tag":"proxy",
"protocol":"vmess",
"settings":{
"vnext":[
{
"address":"",
"port":0,
"users":[
{
"id":"",
"alterId":0,
"security":"none"
}
]
}
]
},
"streamSettings":{
"network":"quic",
"security":"tls",
"quicSettings":{
"security":"",
"key":"",
"header":{
"type":"srtp"
}
},
"tlsSettings":{
"serverName":"xb1.gw.inet-telecom.com"
},
"tcpSettings":{
"header":{
"type":"http",
"request":{
"version":"1.1",
"method":"GET",
"path":["/"],
"headers":{
"Host":["www.inet-telecom.com"],
"User-Agent":["Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.75 Safari/537.36", "Mozilla/5.0 (iPhone; CPU iPhone OS 10_0_2 like Mac OS X) AppleWebKit/601.1 (KHTML, like Gecko) CriOS/53.0.2785.109 Mobile/14A456 Safari/601.1.46"],
"Accept-Encoding":["gzip, deflate"],
"Connection":["keep-alive"],
"Pragma":"no-cache"
}
}
}
}
}
}
]
}
10 changes: 10 additions & 0 deletions core/src/main/java/net/ivpn/core/common/Mapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ package net.ivpn.core.common
import com.google.gson.Gson
import com.google.gson.JsonSyntaxException
import com.google.gson.reflect.TypeToken
import net.ivpn.core.common.v2ray.V2RaySettings
import net.ivpn.core.rest.data.ServersListResponse
import net.ivpn.core.rest.data.model.AntiTracker
import net.ivpn.core.rest.data.model.Port
Expand Down Expand Up @@ -91,6 +92,15 @@ object Mapper {
return Gson().toJson(dns)
}

fun v2raySettingsFrom(json: String?): V2RaySettings {
val type = object : TypeToken<V2RaySettings>() {}.type
return Gson().fromJson(json, type)
}

fun stringFromV2raySettings(settings: V2RaySettings?): String {
return Gson().toJson(settings)
}

fun stringFromIps(ips: List<String>?): String? {
if (ips == null) return null
return Gson().toJson(ips)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class EncryptedSettingsPreference @Inject constructor(val preference: Preference
private const val SETTINGS_MOCK_LOCATION = "SETTINGS_MOCK_LOCATION"
private const val SETTINGS_BYPASS_LOCAL = "SETTINGS_BYPASS_LOCAL"
private const val SETTINGS_IPV6 = "SETTINGS_IPV6"
private const val SETTINGS_V2RAY = "SETTINGS_V2RAY"
private const val SETTINGS_V2RAY_PROTOCOL = "SETTINGS_V2RAY_PROTOCOL"
private const val IPV6_SHOW_ALL_SERVERS = "IPV6_SHOW_ALL_SERVERS"

private const val OV_PORT = "OV_PORT"
Expand All @@ -75,6 +77,7 @@ class EncryptedSettingsPreference @Inject constructor(val preference: Preference
private const val LAST_USED_IP = "LAST_USED_IP"
private const val ANTITRACKER_LIST = "ANTITRACKER_LIST"
private const val ANTITRACKER_DNS = "ANTITRACKER_DNS"
private const val V2RAY_SETTINGS = "V2RAY_SETTINGS"
}

private val sharedPreferences: SharedPreferences = preference.settingsPreference
Expand Down Expand Up @@ -109,6 +112,26 @@ class EncryptedSettingsPreference @Inject constructor(val preference: Preference
.apply()
}

var v2ray: Boolean
get() {
return sharedPreferences.getBoolean(SETTINGS_V2RAY, false)
}
set(value) {
sharedPreferences.edit()
.putBoolean(SETTINGS_V2RAY, value)
.apply()
}

var v2rayProtocol: String?
get() {
return sharedPreferences.getString(SETTINGS_V2RAY_PROTOCOL, "")
}
set(value) {
sharedPreferences.edit()
.putString(SETTINGS_V2RAY_PROTOCOL, value)
.apply()
}

var killSwitch: Boolean
get() {
return sharedPreferences.getBoolean(SETTINGS_KILL_SWITCH, false)
Expand Down Expand Up @@ -492,6 +515,16 @@ class EncryptedSettingsPreference @Inject constructor(val preference: Preference
return sharedPreferences.getString(ANTITRACKER_DNS, "")
}

fun setV2raySettings(json: String?) {
sharedPreferences.edit()
.putString(V2RAY_SETTINGS, json)
.apply()
}

fun getV2raySettings(): String? {
return sharedPreferences.getString(V2RAY_SETTINGS, "")
}

private fun putIsMigrated(isMigrated: Boolean) {
sharedPreferences.edit()
.putBoolean(IS_MIGRATED, isMigrated)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ class ServersRepository @Inject constructor(
settings.wireGuardPortRanges = response.config.ports.wireguard.filter { it.range != null }
settings.openVpnPortRanges = response.config.ports.openvpn.filter { it.range != null }
settings.antiTrackerList = response.config.antiTrackerPlus.list
settings.v2raySettings = response.config.ports.v2ray

if (settings.antiTracker == null) {
val defaultDns = AntiTracker()
settings.antiTracker = defaultDns.getDefaultList(settings.antiTrackerList, settings, userPreference)
Expand Down Expand Up @@ -270,6 +272,7 @@ class ServersRepository @Inject constructor(
settings.wireGuardPortRanges = response.config.ports.wireguard.filter { it.range != null }
settings.openVpnPortRanges = response.config.ports.openvpn.filter { it.range != null }
settings.antiTrackerList = response.config.antiTrackerPlus.list
settings.v2raySettings = response.config.ports.v2ray
if (settings.antiTracker == null) {
val defaultDns = AntiTracker()
settings.antiTracker = defaultDns.getDefaultList(settings.antiTrackerList, settings, userPreference)
Expand All @@ -289,6 +292,7 @@ class ServersRepository @Inject constructor(
settings.wireGuardPortRanges = response.config.ports.wireguard.filter { it.range != null }
settings.openVpnPortRanges = response.config.ports.openvpn.filter { it.range != null }
settings.antiTrackerList = response.config.antiTrackerPlus.list
settings.v2raySettings = response.config.ports.v2ray
if (settings.antiTracker == null) {
val defaultDns = AntiTracker()
settings.antiTracker = defaultDns.getDefaultList(settings.antiTrackerList, settings, userPreference)
Expand Down
22 changes: 22 additions & 0 deletions core/src/main/java/net/ivpn/core/common/prefs/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import net.ivpn.core.common.BuildController
import net.ivpn.core.common.Mapper
import net.ivpn.core.common.dagger.ApplicationScope
import net.ivpn.core.common.nightmode.NightMode
import net.ivpn.core.common.v2ray.V2RaySettings
import net.ivpn.core.rest.data.model.AntiTracker
import net.ivpn.core.rest.data.model.Port
import net.ivpn.core.v2.serverlist.dialog.Filters
Expand Down Expand Up @@ -310,6 +311,27 @@ class Settings @Inject constructor(
settingsPreference.setAntiTracker(Mapper.stringFromAntiTracker(dns))
}

var v2ray: Boolean
get() = settingsPreference.v2ray
set(v2ray) {
settingsPreference.v2ray = v2ray
}

var v2rayProtocol: String
get() = settingsPreference.v2rayProtocol ?: "udp"
set(v2rayProtocol) {
settingsPreference.v2rayProtocol = v2rayProtocol
}

var v2raySettings: V2RaySettings?
get() {
val json = settingsPreference.getV2raySettings()
return if (json!!.isEmpty()) null else Mapper.v2raySettingsFrom(json)
}
set(settings) {
settingsPreference.setV2raySettings(Mapper.stringFromV2raySettings(settings))
}

fun nextPort() {
val protocol = stickyPreference.currentProtocol
if (protocol == Protocol.OPENVPN) {
Expand Down
Loading
Loading