diff options
Diffstat (limited to 'ipscrambling')
-rw-r--r-- | ipscrambling/.gitignore | 1 | ||||
-rw-r--r-- | ipscrambling/Orbot_LICENSE | 206 | ||||
-rw-r--r-- | ipscrambling/README.md | 42 | ||||
-rw-r--r-- | ipscrambling/build.gradle | 55 | ||||
-rw-r--r-- | ipscrambling/commons.gradle | 12 | ||||
-rw-r--r-- | ipscrambling/consumer-rules.pro | 0 | ||||
-rw-r--r-- | ipscrambling/dependencies.gradle | 61 | ||||
-rw-r--r-- | ipscrambling/exportdependencies/pom.xml | 24 | ||||
-rw-r--r-- | ipscrambling/exportdependencies/publish.gradle | 52 | ||||
-rw-r--r-- | ipscrambling/exportdependencies/update_dependencies.md | 43 | ||||
m--------- | ipscrambling/orbotservice | 0 | ||||
-rw-r--r-- | ipscrambling/proguard-rules.pro | 21 | ||||
-rw-r--r-- | ipscrambling/src/main/AndroidManifest.xml | 26 | ||||
-rw-r--r-- | ipscrambling/src/main/java/foundation/e/privacymodules/ipscrambler/IIpScramblerModule.kt | 54 | ||||
-rw-r--r-- | ipscrambling/src/main/java/foundation/e/privacymodules/ipscrambler/IpScramblerModule.kt | 301 |
15 files changed, 898 insertions, 0 deletions
diff --git a/ipscrambling/.gitignore b/ipscrambling/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/ipscrambling/.gitignore @@ -0,0 +1 @@ +/build
\ No newline at end of file diff --git a/ipscrambling/Orbot_LICENSE b/ipscrambling/Orbot_LICENSE new file mode 100644 index 0000000..194b99d --- /dev/null +++ b/ipscrambling/Orbot_LICENSE @@ -0,0 +1,206 @@ +This file contains the license for Orbot, a free software project to +provide anonymity on the Internet from a Google Android smartphone. + +It also lists the licenses for other components used by Orbot, including +Tor, and iptables. + +For more information about Orbot, see https://guardianproject.info/apps/org.torproject.android/ + +If you got this file as a part of a larger bundle, there may be other +license terms that you should be aware of. +=============================================================================== +Orbot is distributed under this license (aka the 3-clause BSD license) + +Copyright (c) 2009-2010, Nathan Freitas, The Guardian Project + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + + * Neither the names of the copyright owners nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +***** + +=============================================================================== +Orbot includes the Obfs4 pluggable transport: +https://gitweb.torproject.org/pluggable-transports/obfs4.git + +Copyright (c) 2014, Yawning Angel <yawning at torproject dot org> +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +=============================================================================== + + +***** +Orbot contains a binary distribution of Tor: + + This file contains the license for Tor, + a free software project to provide anonymity on the Internet. + + It also lists the licenses for other components used by Tor. + + For more information about Tor, see https://www.torproject.org/. + + If you got this file as a part of a larger bundle, + there may be other license terms that you should be aware of. + +=============================================================================== +Tor is distributed under this license: + +Copyright (c) 2001-2004, Roger Dingledine +Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson +Copyright (c) 2007-2009, The Tor Project, Inc. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + + * Neither the names of the copyright owners nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +=============================================================================== + +src/common/strlcat.c and src/common/strlcpy.c by Todd C. Miller are licensed +under the following license: + + * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +=============================================================================== +If you got Tor as a static binary with OpenSSL included, then you should know: + "This product includes software developed by the OpenSSL Project + for use in the OpenSSL Toolkit (http://www.openssl.org/)" +=============================================================================== + +=============================================================================== +"This program uses the IP-to-Country Database provided by +WebHosting.Info (http://www.webhosting.info), available from +http://ip-to-country.webhosting.info." +See the src/config/geoip file in particular. +=============================================================================== + +=============================================================================== +Orbot also uses iptables from the Netfilter.org project + +netfilter/iptables is - like all of the Linux Kernel - Free Software (sometimes +referred to as Open Source Software), distributed under the terms of the GNU GPLv2 +only. Please, note that some source code files might differ, and in that case it +is explicitely stated in the header of every file. + +The GPL also contains some obligations. If you distribute netfilter/iptables code +in binary form, you have to offer the source code, too. +=============================================================================== + +=============================================================================== +Orbot also includes BadVPN tun2socks: https://github.com/ambrop72/badvpn + +Copyright (c) 2009, Ambroz Bizjak <ambrop7@gmail.com> +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the author nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +=============================================================================== diff --git a/ipscrambling/README.md b/ipscrambling/README.md new file mode 100644 index 0000000..777b6a1 --- /dev/null +++ b/ipscrambling/README.md @@ -0,0 +1,42 @@ +# Ipscrambling module + +This Module implements IpScramblerModule functionnalities with Tor, reliying on a fork of OrbotService. + +# Build + +Ipscrambling includes a git repo submodules of OrbotService, the module used by Orbot to run Tor + +Be sure that you have all of the git submodules up-to-date: + + git submodule update --init --recursive + +You can build the AAR modules : + + ./gradlew :ipscrambling:orbotservice:assembleRelease + +To deploy localy during development + + ./gradlew --console=verbose publishToMavenLocal + +This will put compiled AAR and pom file exposing their dependencies in the local maven +repository (usually in ~/.m2/repository). + + +To push release on gitlab + + ./gradlew --console=verbose publish + +# Update orbotservice to an upper Orbot version + +1. Upgrade the code: follow the steps in [orbotservice/README.md](orbotservice/README.md) +2. Prepare the orbotservice the dependencies : follow the steps in [exportdependencies/update_dependencies.md](exportdependencies/update_dependencies.md), first using the mvn install:install-file command +3. build and deploy orbotservice locally: + + ./gradlew :ipscrambling:orbotservice:assembleRelease + ./gradlew --console=verbose :ipscrambling:orbotservice:publishToMavenLocal + +5. Test this new version with advanced privacy, and merge the orbotservice. +6. deploy the orbotservice dependencies to gitlab registry see [exportdependencies/update_dependencies.md](exportdependencies/update_dependencies.md), using mvn deploy:deploy-file command +7. deploy orbotservice in gitlab registry + ./gradlew --console=verbose :orbotservice:publish +8. Create MR in AdvancedPrivacy. diff --git a/ipscrambling/build.gradle b/ipscrambling/build.gradle new file mode 100644 index 0000000..0e293df --- /dev/null +++ b/ipscrambling/build.gradle @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2021 E FOUNDATION + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +plugins { + id 'com.android.library' + id 'kotlin-android' +} + +android { + compileSdkVersion buildConfig.compileSdk + + defaultConfig { + minSdkVersion buildConfig.minSdk + targetSdkVersion buildConfig.targetSdk + + consumerProguardFiles "consumer-rules.pro" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } +} + +dependencies { + implementation( + libs.bundles.kotlin.android.coroutines, + libs.androidx.localbroadcast, + ) + implementation libs.e.orbotservice + //implementation project(':ipscrambling:orbotservice') +} diff --git a/ipscrambling/commons.gradle b/ipscrambling/commons.gradle new file mode 100644 index 0000000..3be1be4 --- /dev/null +++ b/ipscrambling/commons.gradle @@ -0,0 +1,12 @@ + +/* + Applies across all modules + */ +android { + compileSdkVersion 30 + buildToolsVersion '30.0.3' + compileOptions { + sourceCompatibility JavaVersion.VERSION_11 + targetCompatibility JavaVersion.VERSION_11 + } +} diff --git a/ipscrambling/consumer-rules.pro b/ipscrambling/consumer-rules.pro new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/ipscrambling/consumer-rules.pro diff --git a/ipscrambling/dependencies.gradle b/ipscrambling/dependencies.gradle new file mode 100644 index 0000000..412bf9a --- /dev/null +++ b/ipscrambling/dependencies.gradle @@ -0,0 +1,61 @@ +ext { + versions = [ + android_material : "1.4.0", + android_shell : "1.0.0", + android_snowfall : "1.2.1", + android_volley : "1.2.0", + androidx_appcompat : "1.3.1", + androidx_constraint : "2.1.0", + androidx_coordinator : "1.1.0", + androidx_core : "1.6.0", + androidx_leanback : "1.2.0-alpha01", + androidx_leanback_paging : "1.1.0-alpha08", + androidx_leanback_tab : "1.1.0-beta01", + androidx_localbroadcast : "1.0.0", + androidx_multidex : "2.0.1", + androidx_palette : "1.0.0", + androidx_recyclerview : "1.2.1", + apl_appintro : "v4.2.3", + bclogic_pulsator : "1.0.3", + fastlane_screengrab : "1.2.0", + guardian_geoip : "20191217", + guardian_jsocks : "1.0.4", + guardian_jtorctl : "0.4.5.7", + ipt_proxy : "1.8.1", + portmapper : "2.0.5", + tor_android : "0.4.7.10", + pcap_core : "1.8.2", + pcap_factory : "1.8.2", + orbot_service : libs.versions.orbotservice, + ] + + libs = [ + android_material : "com.google.android.material:material:$versions.android_material", + android_shell : "com.jaredrummler:android-shell:$versions.android_shell", + android_snowfall : "com.github.jetradarmobile:android-snowfall:$versions.android_snowfall", + android_volley : "com.android.volley:volley:$versions.android_volley", + androidx_appcompat : "androidx.appcompat:appcompat:$versions.androidx_appcompat", + androidx_constraint : "androidx.constraintlayout:constraintlayout:$versions.androidx_constraint", + androidx_coordinator : "androidx.coordinatorlayout:coordinatorlayout:$versions.androidx_coordinator", + androidx_core : "androidx.core:core:$versions.androidx_core", + androidx_leanback_core : "androidx.leanback:leanback:$versions.androidx_leanback", + androidx_leanback_paging : "androidx.leanback:leanback-paging:$versions.androidx_leanback_paging", + androidx_leanback_preferences : "androidx.leanback:leanback-preference:$versions.androidx_leanback", + androidx_leanback_tab : "androidx.leanback:leanback-tab:$versions.androidx_leanback_tab", + androidx_localbroadcast : "androidx.localbroadcastmanager:localbroadcastmanager:$versions.androidx_localbroadcast", + androidx_multidex : "androidx.multidex:multidex:$versions.androidx_multidex", + androidx_palette : "androidx.palette:palette:$versions.androidx_palette", + androidx_recyclerview : "androidx.recyclerview:recyclerview:$versions.androidx_recyclerview", + apl_appintro : "com.github.apl-devs:appintro:$versions.apl_appintro", + bclogic_pulsator : "pl.bclogic:pulsator4droid:$versions.bclogic_pulsator", + fastlane_screengrab : "tools.fastlane:screengrab:$versions.fastlane_screengrab", + guardian_geoip : "foundation.e:geoip:$versions.orbot_service", + guardian_jsocks : "com.gitlab.guardianproject:jsocksandroid:$versions.guardian_jsocks", + guardian_jtorctl : "info.guardianproject:jtorctl:$versions.guardian_jtorctl", + ipt_proxy : "foundation.e:OrbotIPtProxy:$versions.orbot_service", + portmapper : "com.offbynull.portmapper:portmapper:$versions.portmapper", + tor_android : "foundation.e:tor-android:$versions.orbot_service", + pcap_core : "org.pcap4j:pcap4j-core:$versions.pcap_core", + pcap_factory : "org.pcap4j:pcap4j-packetfactory-static:$versions.pcap_factory" + ] +} diff --git a/ipscrambling/exportdependencies/pom.xml b/ipscrambling/exportdependencies/pom.xml new file mode 100644 index 0000000..be28747 --- /dev/null +++ b/ipscrambling/exportdependencies/pom.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project> + <modelVersion>4.0.0</modelVersion> + <groupId>foundation.e</groupId> + <artifactId>orbotservice</artifactId> + <version>orbot-16.6.3-1</version> + + <description></description> + + <properties> + <groupId>${project.groupId}</groupId> + <artifactId>${project.artifactId}</artifactId> + <version>${project.version}</version> + <packaging>aar</packaging> + <file>OrbotLib.aar</file> + </properties> + + <repositories> + <repository> + <id>gitlab-e-maven</id> + <url>https://gitlab.e.foundation/api/v4/projects/1063/packages/maven</url> + </repository> + </repositories> +</project> diff --git a/ipscrambling/exportdependencies/publish.gradle b/ipscrambling/exportdependencies/publish.gradle new file mode 100644 index 0000000..657ce22 --- /dev/null +++ b/ipscrambling/exportdependencies/publish.gradle @@ -0,0 +1,52 @@ +apply plugin: 'maven-publish' + +publishing { + publications { + maven(MavenPublication) { + groupId 'foundation.e' + artifactId 'orbotservice' + version versions.orbot_service + artifact "$buildDir/outputs/aar/orbotservice-release.aar" + + pom.withXml { + def dependenciesNode = asNode().appendNode('dependencies') + configurations.implementation.allDependencies.each { dependency -> + if (dependency.name != 'unspecified') { + def dependencyNode = dependenciesNode.appendNode('dependency') + dependencyNode.appendNode('groupId', dependency.group) + dependencyNode.appendNode('artifactId', dependency.name) + dependencyNode.appendNode('version', dependency.version) + } + } + } + + repositories { + def ciJobToken = System.getenv("CI_JOB_TOKEN") + def ciApiV4Url = System.getenv("CI_API_V4_URL") + if (ciJobToken != null) { + maven { + url "${ciApiV4Url}/projects/1063/packages/maven" + credentials(HttpHeaderCredentials) { + name = 'Job-Token' + value = ciJobToken + } + authentication { + header(HttpHeaderAuthentication) + } + } + } else { + maven { + url "https://gitlab.e.foundation/api/v4/projects/1063/packages/maven" + credentials(HttpHeaderCredentials) { + name = "Private-Token" + value = gitLabPrivateToken + } + authentication { + header(HttpHeaderAuthentication) + } + } + } + } + } + } +}
\ No newline at end of file diff --git a/ipscrambling/exportdependencies/update_dependencies.md b/ipscrambling/exportdependencies/update_dependencies.md new file mode 100644 index 0000000..32ef58d --- /dev/null +++ b/ipscrambling/exportdependencies/update_dependencies.md @@ -0,0 +1,43 @@ +A few orbot dependencies are added directly through the /libs directory, because remotely available version are outdated. We can't embed .aar or .jar into the orbotservice.aar (as any aar), so we have to expose this dependencies in the gitlab repository. + +To do that we use the mn deploy:deploy-file command ; and also the mvn install:install-file command to deploy in local maven repository for development. + +1. Update the orbot_service version in + * exportdependencies/pom.xml file + * dependencies.gradle +2. For each dependencies in orbot/libs, update or prepare an entry in dependecies.gradle, using groupId=foundation.e ; version orbot_service, and an approprioate artifactId . +3. For each dependencies in orbot/libs, run with appropriate PATH and ARTIFACTID : + +mvn install:install-file \ +-DartifactId=[ARTIFACTID] \ +-Dpackaging=aar \ +-Dfile=[PATH] + +4. Later, when isvalidated, deploy to gitlab repository: + +mvn deploy:deploy-file \ +-DrepositoryId=gitlab-e-maven \ +-Durl=https://gitlab.e.foundation/api/v4/projects/1063/packages/maven \ +-DartifactId=[ARTIFACTID] \ +-Dpackaging=aar \ +-Dfile=[PATH] + +example, for tor-android-binary +step 2: +"info.guardianproject:tor-android:$versions.tor_android" -> "foundation.e:tor-android:$versions.orbot_service", + +step 3: + +mvn install:install-file \ +-DartifactId=tor-android \ +-Dpackaging=aar \ +-Dfile="../../orbot/libs/tor-android-binary-release.aar + +step 4 : + +mvn deploy:deploy-file \ +-DrepositoryId=gitlab-e-maven \ +-Durl=https://gitlab.e.foundation/api/v4/projects/1063/packages/maven \ +-DartifactId=tor-android \ +-Dpackaging=aar \ +-Dfile="../../orbot/libs/tor-android-binary-release.aar diff --git a/ipscrambling/orbotservice b/ipscrambling/orbotservice new file mode 160000 +Subproject 1930a046eff2dd37d23ffd83f0064f60334468a diff --git a/ipscrambling/proguard-rules.pro b/ipscrambling/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/ipscrambling/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile
\ No newline at end of file diff --git a/ipscrambling/src/main/AndroidManifest.xml b/ipscrambling/src/main/AndroidManifest.xml new file mode 100644 index 0000000..e948147 --- /dev/null +++ b/ipscrambling/src/main/AndroidManifest.xml @@ -0,0 +1,26 @@ +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="foundation.e.privacymodules.tor" + android:installLocation="internalOnly" + > + + <uses-permission android:name="android.permission.INTERNET" /> + <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> + <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> + <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> + <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" /> + + <application + android:allowBackup="true" + > + <service + android:name="org.torproject.android.service.OrbotService" + android:enabled="true" + android:exported="false" + android:permission="android.permission.BIND_VPN_SERVICE" + android:stopWithTask="false"> + <intent-filter> + <action android:name="android.net.VpnService" /> + </intent-filter> + </service> + </application> +</manifest> diff --git a/ipscrambling/src/main/java/foundation/e/privacymodules/ipscrambler/IIpScramblerModule.kt b/ipscrambling/src/main/java/foundation/e/privacymodules/ipscrambler/IIpScramblerModule.kt new file mode 100644 index 0000000..859319a --- /dev/null +++ b/ipscrambling/src/main/java/foundation/e/privacymodules/ipscrambler/IIpScramblerModule.kt @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2021 E FOUNDATION + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package foundation.e.privacymodules.ipscrambler + +import android.content.Intent + +interface IIpScramblerModule { + fun prepareAndroidVpn(): Intent? + + fun start(enableNotification: Boolean = true) + + fun stop() + + fun requestStatus() + + var appList: Set<String> + + var exitCountry: String + fun getAvailablesLocations(): Set<String> + + val httpProxyPort: Int + val socksProxyPort: Int + + fun addListener(listener: Listener) + fun removeListener(listener: Listener) + fun clearListeners() + + fun onCleared() + + interface Listener { + fun onStatusChanged(newStatus: Status) + fun log(message: String) + fun onTrafficUpdate(upload: Long, download: Long, read: Long, write: Long) + } + + enum class Status { + OFF, ON, STARTING, STOPPING, START_DISABLED + } +} diff --git a/ipscrambling/src/main/java/foundation/e/privacymodules/ipscrambler/IpScramblerModule.kt b/ipscrambling/src/main/java/foundation/e/privacymodules/ipscrambler/IpScramblerModule.kt new file mode 100644 index 0000000..1c39330 --- /dev/null +++ b/ipscrambling/src/main/java/foundation/e/privacymodules/ipscrambler/IpScramblerModule.kt @@ -0,0 +1,301 @@ +/* + * Copyright (C) 2021 E FOUNDATION + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package foundation.e.privacymodules.ipscrambler + +import android.annotation.SuppressLint +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent +import android.content.IntentFilter +import android.net.VpnService +import android.os.Bundle +import android.os.Handler +import android.os.Looper +import android.os.Message +import android.util.Log +import androidx.localbroadcastmanager.content.LocalBroadcastManager +import foundation.e.privacymodules.ipscrambler.IIpScramblerModule.Listener +import foundation.e.privacymodules.ipscrambler.IIpScramblerModule.Status +import org.torproject.android.service.OrbotConstants +import org.torproject.android.service.OrbotConstants.ACTION_STOP_FOREGROUND_TASK +import org.torproject.android.service.OrbotService +import org.torproject.android.service.util.Prefs +import java.security.InvalidParameterException + +@SuppressLint("CommitPrefEdits") +class IpScramblerModule(private val context: Context) : IIpScramblerModule { + companion object { + const val TAG = "IpScramblerModule" + + private val EXIT_COUNTRY_CODES = setOf("DE", "AT", "SE", "CH", "IS", "CA", "US", "ES", "FR", "BG", "PL", "AU", "BR", "CZ", "DK", "FI", "GB", "HU", "NL", "JP", "RO", "RU", "SG", "SK") + + // Key where exit country is stored by orbot service. + private const val PREFS_KEY_EXIT_NODES = "pref_exit_nodes" + // Copy of the package private OrbotService.NOTIFY_ID value. + // const val ORBOT_SERVICE_NOTIFY_ID_COPY = 1 + } + + private var currentStatus: Status? = null + private val listeners = mutableSetOf<Listener>() + + private val localBroadcastReceiver: BroadcastReceiver = object : BroadcastReceiver() { + override fun onReceive(context: Context, intent: Intent) { + val action = intent.action ?: return + if (action == OrbotConstants.ACTION_RUNNING_SYNC) { + try { + intent.getStringExtra(OrbotConstants.EXTRA_STATUS)?.let { + val newStatus = Status.valueOf(it) + currentStatus = newStatus + } + } catch (e: Exception) { + Log.e(TAG, "Can't parse Orbot service status.") + } + return + } + + val msg = messageHandler.obtainMessage() + msg.obj = action + msg.data = intent.extras + messageHandler.sendMessage(msg) + } + } + + private val messageHandler: Handler = object : Handler(Looper.getMainLooper()) { + override fun handleMessage(msg: Message) { + val action = msg.obj as? String ?: return + val data = msg.data + when (action) { + OrbotConstants.LOCAL_ACTION_LOG -> + data.getString(OrbotConstants.LOCAL_EXTRA_LOG)?.let { newLog(it) } + + OrbotConstants.LOCAL_ACTION_BANDWIDTH -> { + trafficUpdate( + data.getLong("up", 0), + data.getLong("down", 0), + data.getLong("written", 0), + data.getLong("read", 0) + ) + } + + OrbotConstants.LOCAL_ACTION_PORTS -> { + httpProxyPort = data.getInt(OrbotService.EXTRA_HTTP_PROXY_PORT, -1) + socksProxyPort = data.getInt(OrbotService.EXTRA_SOCKS_PROXY_PORT, -1) + } + + OrbotConstants.LOCAL_ACTION_STATUS -> + data.getString(OrbotConstants.EXTRA_STATUS)?.let { + try { + val newStatus = Status.valueOf(it) + updateStatus(newStatus, force = true) + } catch (e: Exception) { + Log.e(TAG, "Can't parse Orbot service status.") + } + } + } + super.handleMessage(msg) + } + } + + init { + Prefs.setContext(context) + + val lbm = LocalBroadcastManager.getInstance(context) + lbm.registerReceiver( + localBroadcastReceiver, + IntentFilter(OrbotConstants.LOCAL_ACTION_STATUS) + ) + lbm.registerReceiver( + localBroadcastReceiver, + IntentFilter(OrbotConstants.LOCAL_ACTION_BANDWIDTH) + ) + lbm.registerReceiver( + localBroadcastReceiver, + IntentFilter(OrbotConstants.LOCAL_ACTION_LOG) + ) + lbm.registerReceiver( + localBroadcastReceiver, + IntentFilter(OrbotConstants.LOCAL_ACTION_PORTS) + ) + lbm.registerReceiver( + localBroadcastReceiver, + IntentFilter(OrbotConstants.ACTION_RUNNING_SYNC) + ) + + Prefs.getSharedPrefs(context).edit() + .putInt(OrbotConstants.PREFS_DNS_PORT, OrbotConstants.TOR_DNS_PORT_DEFAULT) + .apply() + } + + private fun updateStatus(status: Status, force: Boolean = false) { + if (force || status != currentStatus) { + currentStatus = status + listeners.forEach { + it.onStatusChanged(status) + } + } + } + + private fun isServiceRunning(): Boolean { + // Reset status, and then ask to refresh it synchronously. + currentStatus = Status.OFF + LocalBroadcastManager.getInstance(context) + .sendBroadcastSync(Intent(OrbotConstants.ACTION_CHECK_RUNNING_SYNC)) + return currentStatus != Status.OFF + } + + private fun newLog(message: String) { + listeners.forEach { it.log(message) } + } + + private fun trafficUpdate(upload: Long, download: Long, read: Long, write: Long) { + listeners.forEach { it.onTrafficUpdate(upload, download, read, write) } + } + + private fun sendIntentToService(action: String, extra: Bundle? = null) { + val intent = Intent(context, OrbotService::class.java) + intent.action = action + extra?.let { intent.putExtras(it) } + context.startService(intent) + } + + @SuppressLint("ApplySharedPref") + private fun saveTorifiedApps(packageNames: Collection<String>) { + packageNames.joinToString("|") + Prefs.getSharedPrefs(context).edit().putString( + OrbotConstants.PREFS_KEY_TORIFIED, packageNames.joinToString("|") + ).commit() + + if (isServiceRunning()) { + sendIntentToService(OrbotConstants.ACTION_RESTART_VPN) + } + } + + private fun getTorifiedApps(): Set<String> { + val list = Prefs.getSharedPrefs(context).getString(OrbotConstants.PREFS_KEY_TORIFIED, "") + ?.split("|") + return if (list == null || list == listOf("")) { + emptySet() + } else { + list.toSet() + } + } + + @SuppressLint("ApplySharedPref") + private fun setExitCountryCode(countryCode: String) { + val countryParam = when { + countryCode.isEmpty() -> "" + countryCode in EXIT_COUNTRY_CODES -> "{$countryCode}" + else -> throw InvalidParameterException( + "Only these countries are available: ${EXIT_COUNTRY_CODES.joinToString { ", " } }" + ) + } + + if (isServiceRunning()) { + val extra = Bundle() + extra.putString("exit", countryParam) + sendIntentToService(OrbotConstants.CMD_SET_EXIT, extra) + } else { + Prefs.getSharedPrefs(context) + .edit().putString(PREFS_KEY_EXIT_NODES, countryParam) + .commit() + } + } + + private fun getExitCountryCode(): String { + val raw = Prefs.getExitNodes() + return if (raw.isEmpty()) raw else raw.slice(1..2) + } + + override fun prepareAndroidVpn(): Intent? { + return VpnService.prepare(context) + } + + override fun start(enableNotification: Boolean) { + Prefs.enableNotification(enableNotification) + Prefs.putUseVpn(true) + Prefs.putStartOnBoot(true) + + sendIntentToService(OrbotConstants.ACTION_START) + sendIntentToService(OrbotConstants.ACTION_START_VPN) + } + + override fun stop() { + updateStatus(Status.STOPPING) + + Prefs.putUseVpn(false) + Prefs.putStartOnBoot(false) + + sendIntentToService(OrbotConstants.ACTION_STOP_VPN) + sendIntentToService( + action = OrbotConstants.ACTION_STOP, + extra = Bundle().apply { putBoolean(ACTION_STOP_FOREGROUND_TASK, true) } + ) + stoppingWatchdog(5) + } + + private fun stoppingWatchdog(countDown: Int) { + Handler(Looper.getMainLooper()).postDelayed( + { + if (isServiceRunning() && countDown > 0) { + stoppingWatchdog(countDown - 1) + } else { + updateStatus(Status.OFF, force = true) + } + }, + 500 + ) + } + + override fun requestStatus() { + if (isServiceRunning()) { + sendIntentToService(OrbotConstants.ACTION_STATUS) + } else { + updateStatus(Status.OFF, force = true) + } + } + + override var appList: Set<String> + get() = getTorifiedApps() + set(value) = saveTorifiedApps(value) + + override var exitCountry: String + get() = getExitCountryCode() + set(value) = setExitCountryCode(value) + + override fun getAvailablesLocations(): Set<String> = EXIT_COUNTRY_CODES + + override var httpProxyPort: Int = -1 + private set + + override var socksProxyPort: Int = -1 + private set + + override fun addListener(listener: Listener) { + listeners.add(listener) + } + override fun removeListener(listener: Listener) { + listeners.remove(listener) + } + override fun clearListeners() { + listeners.clear() + } + + override fun onCleared() { + LocalBroadcastManager.getInstance(context).unregisterReceiver(localBroadcastReceiver) + } +} |