Merge branch 'master' into master

This commit is contained in:
Vadym Vikulin 2021-06-19 17:36:16 +03:00 committed by GitHub
commit e170d0705d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 114 additions and 76 deletions

View File

@ -1,6 +1,5 @@
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
apply plugin: 'kotlin-android' apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android { android {
compileSdkVersion 29 compileSdkVersion 29
@ -8,8 +7,8 @@ android {
applicationId "io.github.chronosx88.yggdrasil" applicationId "io.github.chronosx88.yggdrasil"
minSdkVersion 15 minSdkVersion 15
targetSdkVersion 29 targetSdkVersion 29
versionCode 18 versionCode 23
versionName "1.7" versionName "2.0.3"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
setProperty("archivesBaseName", project.getParent().name+"-"+versionName) setProperty("archivesBaseName", project.getParent().name+"-"+versionName)
} }
@ -46,6 +45,10 @@ android {
exclude 'META-INF/LICENSE' exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE' exclude 'META-INF/NOTICE'
} }
buildFeatures {
viewBinding true
}
} }
task ndkBuild(type: Exec) { task ndkBuild(type: Exec) {
@ -59,16 +62,19 @@ gradle.projectsEvaluated {
} }
dependencies { dependencies {
implementation 'ch.acra:acra-http:5.8.3'
implementation 'ch.acra:acra-dialog:5.8.3'
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(path: ':yggdrasil') implementation project(path: ':yggdrasil')
implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4' implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation "androidx.preference:preference-ktx:1.1.1" implementation 'androidx.preference:preference-ktx:1.1.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.7' implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.8'
implementation 'com.google.android.material:material:1.3.0-alpha04' implementation 'com.google.android.material:material:1.4.0-rc01'
implementation 'com.google.code.gson:gson:2.8.6' implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.hbb20:ccp:2.4.0' implementation 'com.hbb20:ccp:2.4.0'
implementation 'com.vincentbrison.openlibraries.android:dualcache:3.1.1' implementation 'com.vincentbrison.openlibraries.android:dualcache:3.1.1'

View File

@ -8,6 +8,7 @@
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<application <application
android:name=".YggApplication"
android:allowBackup="true" android:allowBackup="true"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"

View File

@ -17,15 +17,15 @@ class CopyLocalNodeInfoActivity: AppCompatActivity() {
val preferences = val preferences =
PreferenceManager.getDefaultSharedPreferences(this.baseContext) PreferenceManager.getDefaultSharedPreferences(this.baseContext)
val ipv6Address = intent.extras!!.getString(MainActivity.IPv6, "") val ipv6Address = intent.extras!!.getString(MainActivity.IPv6, "")
val signingPublicKey = preferences.getString(MainActivity.signingPublicKey, "***") val publicKey = preferences.getString(MainActivity.publicKey, "")
val encryptionPublicKey = preferences.getString(MainActivity.encryptionPublicKey, "***") var nodeInfoListView = findViewById<ListView>(R.id.nodeInfoList)
var nodeInfoListView = findViewById<RecyclerView>(R.id.node_info_list) val nodeInfoList = listOf<NodeInfo>(NodeInfo("IP address", ipv6Address!!), NodeInfo("Public Key", publicKey!!));
val nodeInfoList = listOf<Pair<String, String>>(Pair("IP address", ipv6Address!!), Pair("Encryption Public Key", encryptionPublicKey!!), Pair("Signing Public Key", signingPublicKey!!));
val adapter = val adapter =
NodeInfoListAdapter( NodeInfoListAdapter(
this, this,
nodeInfoList.toTypedArray() nodeInfoList.toTypedArray()
) )
nodeInfoListView.adapter = adapter nodeInfoListView.adapter = adapter
nodeInfoListView.layoutManager = LinearLayoutManager(this) nodeInfoListView.layoutManager = LinearLayoutManager(this)

View File

@ -34,10 +34,8 @@ class MainActivity : AppCompatActivity() {
const val STATUS_PEERS_UPDATE = 12 const val STATUS_PEERS_UPDATE = 12
const val MESH_PEERS = "MESH_PEERS" const val MESH_PEERS = "MESH_PEERS"
const val STATIC_IP = "STATIC_IP_FLAG" const val STATIC_IP = "STATIC_IP_FLAG"
const val signingPrivateKey = "signingPrivateKey" const val privateKey = "privateKey"
const val signingPublicKey = "signingPublicKey" const val publicKey = "publicKey"
const val encryptionPrivateKey = "encryptionPrivateKey"
const val encryptionPublicKey = "encryptionPublicKey"
const val COMMAND = "COMMAND" const val COMMAND = "COMMAND"
const val STOP = "STOP" const val STOP = "STOP"
const val START = "START" const val START = "START"

View File

@ -11,14 +11,12 @@ val gson = Gson()
fun createNativeYggConfig(config: Config): NodeConfig { fun createNativeYggConfig(config: Config): NodeConfig {
val nativeConfig = NodeConfig() val nativeConfig = NodeConfig()
nativeConfig.adminListen = config.adminListen nativeConfig.adminListen = config.adminListen
nativeConfig.encryptionPrivateKey = config.encryptionPrivateKey nativeConfig.privateKey = config.privateKey
nativeConfig.encryptionPublicKey = config.encryptionPublicKey nativeConfig.publicKey = config.publicKey
//nativeConfig.ifMTU = config.ifMTU //nativeConfig.ifMTU = config.ifMTU
nativeConfig.ifName = config.ifName nativeConfig.ifName = config.ifName
//nativeConfig.ifTAPMode = config.ifTAPMode //nativeConfig.ifTAPMode = config.ifTAPMode
nativeConfig.nodeInfoPrivacy = config.nodeInfoPrivacy nativeConfig.nodeInfoPrivacy = config.nodeInfoPrivacy
nativeConfig.signingPrivateKey = config.signingPrivateKey
nativeConfig.signingPublicKey = config.signingPublicKey
return nativeConfig return nativeConfig
} }

View File

@ -0,0 +1,46 @@
package io.github.chronosx88.yggdrasil
import android.app.Application
import android.content.Context
import org.acra.config.dialog
import org.acra.config.httpSender
import org.acra.data.StringFormat
import org.acra.ktx.initAcra
import org.acra.sender.HttpSender
class YggApplication : Application() {
override fun attachBaseContext(base: Context) {
super.attachBaseContext(base)
initAcra {
//core configuration:
buildConfigClass = BuildConfig::class.java
reportFormat = StringFormat.JSON
//each plugin you chose above can be configured in a block like this:
httpSender {
uri = "http://<host>/report"
basicAuthLogin="***"
basicAuthPassword = "***"
httpMethod = HttpSender.Method.POST
}
dialog {
//required
text = getString(R.string.report_dialog_text)
//optional, enables the dialog title
title = getString(R.string.app_name)
//defaults to android.R.string.ok
positiveButtonText = getString(android.R.string.ok)
//defaults to android.R.string.cancel
negativeButtonText = getString(android.R.string.cancel)
//optional, enables the comment input
commentPrompt = getString(R.string.report_dialog_comment)
//optional, enables the email input
//emailPrompt = getString(R.string.report_dialog_email)
//defaults to android.R.drawable.ic_dialog_alert
resIcon = android.R.drawable.ic_dialog_alert
//optional, defaults to @android:style/Theme.Dialog
resTheme = R.style.Theme_AppCompat_Dialog
}
}
}
}

View File

@ -14,7 +14,6 @@ import androidx.core.app.NotificationCompat
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import com.google.gson.Gson import com.google.gson.Gson
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import dummy.ConduitEndpoint
import io.github.chronosx88.yggdrasil.models.DNSInfo import io.github.chronosx88.yggdrasil.models.DNSInfo
import io.github.chronosx88.yggdrasil.models.PeerInfo import io.github.chronosx88.yggdrasil.models.PeerInfo
import io.github.chronosx88.yggdrasil.models.config.Peer import io.github.chronosx88.yggdrasil.models.config.Peer
@ -22,7 +21,6 @@ import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.convertPeer2
import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.convertPeerInfoSet2PeerIdSet import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.convertPeerInfoSet2PeerIdSet
import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.deserializeStringList2DNSInfoSet import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.deserializeStringList2DNSInfoSet
import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.deserializeStringList2PeerInfoSet import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.deserializeStringList2PeerInfoSet
import kotlinx.coroutines.*
import mobile.Mobile import mobile.Mobile
import mobile.Yggdrasil import mobile.Yggdrasil
import java.io.* import java.io.*
@ -119,19 +117,19 @@ class YggdrasilTunService : VpnService() {
configJson = gson.toJson(config).toByteArray() configJson = gson.toJson(config).toByteArray()
var yggConduitEndpoint = ygg.startJSON(configJson) ygg.startJSON(configJson)
setupIOStreams(dns) setupIOStreams(dns)
thread(start = true) { thread(start = true) {
val buffer = ByteArray(MAX_PACKET_SIZE) val buffer = ByteArray(MAX_PACKET_SIZE)
while (!isClosed) { while (!isClosed) {
readPacketsFromTun(yggConduitEndpoint, buffer) readPacketsFromTun(buffer)
} }
} }
thread(start = true) { thread(start = true) {
while (!isClosed) { while (!isClosed) {
writePacketsToTun(yggConduitEndpoint) writePacketsToTun()
} }
} }
val intent: Intent = Intent().putExtra(MainActivity.IPv6, address) val intent: Intent = Intent().putExtra(MainActivity.IPv6, address)
@ -147,7 +145,6 @@ class YggdrasilTunService : VpnService() {
convertPeer2PeerStringList(meshPeers) convertPeer2PeerStringList(meshPeers)
); );
pi?.send(this, MainActivity.STATUS_PEERS_UPDATE, intent) pi?.send(this, MainActivity.STATUS_PEERS_UPDATE, intent)
} }
private fun fixConfig( private fun fixConfig(
@ -168,37 +165,27 @@ class YggdrasilTunService : VpnService() {
val preferences = val preferences =
PreferenceManager.getDefaultSharedPreferences(this.baseContext) PreferenceManager.getDefaultSharedPreferences(this.baseContext)
if(preferences.getString(MainActivity.STATIC_IP, null)==null) { if(preferences.getString(MainActivity.STATIC_IP, null)==null) {
val encryptionPublicKey = config["EncryptionPublicKey"].toString() val publicKey = config["PublicKey"].toString()
val encryptionPrivateKey = config["EncryptionPrivateKey"].toString() val privateKey = config["PrivateKey"].toString()
val signingPublicKey = config["SigningPublicKey"].toString()
val signingPrivateKey = config["SigningPrivateKey"].toString()
preferences.edit() preferences.edit()
.putString(MainActivity.signingPrivateKey, signingPrivateKey) .putString(MainActivity.privateKey, privateKey)
.putString(MainActivity.signingPublicKey, signingPublicKey) .putString(MainActivity.publicKey, publicKey)
.putString(MainActivity.encryptionPrivateKey, encryptionPrivateKey)
.putString(MainActivity.encryptionPublicKey, encryptionPublicKey)
.putString(MainActivity.STATIC_IP, MainActivity.STATIC_IP).apply() .putString(MainActivity.STATIC_IP, MainActivity.STATIC_IP).apply()
} else { } else {
val signingPrivateKey = preferences.getString(MainActivity.signingPrivateKey, null) val privateKey = preferences.getString(MainActivity.privateKey, null)
val signingPublicKey = preferences.getString(MainActivity.signingPublicKey, null) val publicKey = preferences.getString(MainActivity.publicKey, null)
val encryptionPrivateKey = preferences.getString(MainActivity.encryptionPrivateKey, null)
val encryptionPublicKey = preferences.getString(MainActivity.encryptionPublicKey, null)
config["SigningPrivateKey"] = signingPrivateKey config["PrivateKey"] = privateKey
config["SigningPublicKey"] = signingPublicKey config["PublicKey"] = publicKey
config["EncryptionPrivateKey"] = encryptionPrivateKey
config["EncryptionPublicKey"] = encryptionPublicKey
} }
} }
(config["SessionFirewall"] as MutableMap<Any, Any>)["Enable"] = false
//(config["SessionFirewall"] as MutableMap<Any, Any>)["AllowFromDirect"] = true //(config["SessionFirewall"] as MutableMap<Any, Any>)["AllowFromDirect"] = true
//(config["SessionFirewall"] as MutableMap<Any, Any>)["AllowFromRemote"] = true //(config["SessionFirewall"] as MutableMap<Any, Any>)["AllowFromRemote"] = true
//(config["SessionFirewall"] as MutableMap<Any, Any>)["AlwaysAllowOutbound"] = true //(config["SessionFirewall"] as MutableMap<Any, Any>)["AlwaysAllowOutbound"] = true
//(config["SessionFirewall"] as MutableMap<Any, Any>)["WhitelistEncryptionPublicKeys"] = whiteList //(config["SessionFirewall"] as MutableMap<Any, Any>)["WhitelistEncryptionPublicKeys"] = whiteList
//(config["SessionFirewall"] as MutableMap<Any, Any>)["BlacklistEncryptionPublicKeys"] = blackList //(config["SessionFirewall"] as MutableMap<Any, Any>)["BlacklistEncryptionPublicKeys"] = blackList
(config["SwitchOptions"] as MutableMap<Any, Any>)["MaxTotalQueueSize"] = 4194304 //(config["SwitchOptions"] as MutableMap<Any, Any>)["MaxTotalQueueSize"] = 4194304
if (config["AutoStart"] == null) { if (config["AutoStart"] == null) {
val tmpMap = emptyMap<String, Boolean>().toMutableMap() val tmpMap = emptyMap<String, Boolean>().toMutableMap()
tmpMap["WiFi"] = false tmpMap["WiFi"] = false
@ -208,18 +195,18 @@ class YggdrasilTunService : VpnService() {
return config return config
} }
private fun readPacketsFromTun(yggConduitEndpoint: ConduitEndpoint, buffer: ByteArray) { private fun readPacketsFromTun(buffer: ByteArray) {
try { try {
// Read the outgoing packet from the input stream. // Read the outgoing packet from the input stream.
val length = tunInputStream.read(buffer) val length = tunInputStream.read(buffer)
yggConduitEndpoint.send(buffer.sliceArray(IntRange(0, length - 1))) ygg.send(buffer.sliceArray(IntRange(0, length - 1)))
} catch (e: IOException) { } catch (e: IOException) {
e.printStackTrace() e.printStackTrace()
} }
} }
private fun writePacketsToTun(yggConduitEndpoint: ConduitEndpoint) { private fun writePacketsToTun() {
val buffer = yggConduitEndpoint.recv() val buffer = ygg.recv()
if(buffer!=null) { if(buffer!=null) {
try { try {
tunOutputStream.write(buffer) tunOutputStream.write(buffer)

View File

@ -4,23 +4,21 @@ import com.google.gson.annotations.SerializedName
// FIXME This is old config scheme // FIXME This is old config scheme
data class Config ( data class Config (
@SerializedName("peers") var peers : List<String>, @SerializedName("peers") var peers : List<String>,
@SerializedName("interfacePeers") var interfacePeers : Map<String, List<String>>, @SerializedName("interfacePeers") var interfacePeers : Map<String, List<String>>,
@SerializedName("listen") var listen : List<String>, @SerializedName("listen") var listen : List<String>,
@SerializedName("adminListen") var adminListen : String, @SerializedName("adminListen") var adminListen : String,
@SerializedName("multicastInterfaces") var multicastInterfaces : List<String>, @SerializedName("multicastInterfaces") var multicastInterfaces : List<String>,
@SerializedName("allowedEncryptionPublicKeys") var allowedEncryptionPublicKeys : List<String>, @SerializedName("allowedEncryptionPublicKeys") var allowedEncryptionPublicKeys : List<String>,
@SerializedName("encryptionPublicKey") var encryptionPublicKey : String, @SerializedName("publicKey") var publicKey : String,
@SerializedName("encryptionPrivateKey") var encryptionPrivateKey : String, @SerializedName("privateKey") var privateKey : String,
@SerializedName("signingPublicKey") var signingPublicKey : String, @SerializedName("linkLocalTCPPort") var linkLocalTCPPort : Int,
@SerializedName("signingPrivateKey") var signingPrivateKey : String, @SerializedName("ifName") var ifName : String,
@SerializedName("linkLocalTCPPort") var linkLocalTCPPort : Int, @SerializedName("ifTAPMode") var ifTAPMode : Boolean,
@SerializedName("ifName") var ifName : String, @SerializedName("ifMTU") var ifMTU : Long,
@SerializedName("ifTAPMode") var ifTAPMode : Boolean, @SerializedName("sessionFirewall") var sessionFirewall : SessionFirewall,
@SerializedName("ifMTU") var ifMTU : Long, @SerializedName("tunnelRouting") var tunnelRouting : TunnelRouting,
@SerializedName("sessionFirewall") var sessionFirewall : SessionFirewall, @SerializedName("switchOptions") var switchOptions : SwitchOptions,
@SerializedName("tunnelRouting") var tunnelRouting : TunnelRouting, @SerializedName("nodeInfoPrivacy") var nodeInfoPrivacy : Boolean,
@SerializedName("switchOptions") var switchOptions : SwitchOptions, @SerializedName("nodeInfo") var nodeInfo : Map<String, Any>
@SerializedName("nodeInfoPrivacy") var nodeInfoPrivacy : Boolean,
@SerializedName("nodeInfo") var nodeInfo : Map<String, Any>
) )

View File

@ -3,6 +3,7 @@ package io.github.chronosx88.yggdrasil.models.config
import com.google.gson.Gson import com.google.gson.Gson
import io.github.chronosx88.yggdrasil.models.DNSInfo import io.github.chronosx88.yggdrasil.models.DNSInfo
import io.github.chronosx88.yggdrasil.models.PeerInfo import io.github.chronosx88.yggdrasil.models.PeerInfo
import org.acra.ACRA
import java.net.InetAddress import java.net.InetAddress
import java.net.InetSocketAddress import java.net.InetSocketAddress
import java.net.Socket import java.net.Socket
@ -113,6 +114,7 @@ class Utils {
@JvmStatic @JvmStatic
fun deserializePeerStringList2PeerInfoSet(list: List<String>?): MutableSet<PeerInfo> { fun deserializePeerStringList2PeerInfoSet(list: List<String>?): MutableSet<PeerInfo> {
var gson = Gson() var gson = Gson()
ACRA.errorReporter.putCustomData("Peer list", gson.toJson(list))
var out = mutableSetOf<PeerInfo>() var out = mutableSetOf<PeerInfo>()
if (list != null) { if (list != null) {
for(s in list) { for(s in list) {

View File

@ -9,4 +9,6 @@
<string name="schema">Schema</string> <string name="schema">Schema</string>
<string name="title_activity_about">Yggdrasil</string> <string name="title_activity_about">Yggdrasil</string>
<string name="title_activity_copy_local_node_info">Node info</string> <string name="title_activity_copy_local_node_info">Node info</string>
<string name="report_dialog_text">Sorry, the application crashed.</string>
<string name="report_dialog_comment">Please describe what were you doing when the app crashed:</string>
</resources> </resources>

View File

@ -1,15 +1,14 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules. // Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript { buildscript {
ext.kotlin_version = '1.4.10' ext.kotlin_version = "1.5.10"
repositories { repositories {
google() google()
mavenCentral() mavenCentral()
jcenter()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:4.1.3' classpath "com.android.tools.build:gradle:4.2.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files
} }
@ -18,10 +17,11 @@ buildscript {
allprojects { allprojects {
repositories { repositories {
google() google()
jcenter() mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
} }
} }
task clean(type: Delete) { task clean(type: Delete) {
delete rootProject.buildDir delete rootProject.buildDir
} }

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip distributionUrl=https://services.gradle.org/distributions/gradle-6.7.1-all.zip

View File

@ -1,10 +1,10 @@
GOPATH=$(shell go env GOPATH) GOPATH=$(shell go env GOPATH)
export GO111MODULE=off
all: all:
-go get -u github.com/yggdrasil-network/yggdrasil-go; -go get -u github.com/yggdrasil-network/yggdrasil-go;
-cd $(GOPATH)/src/github.com/yggdrasil-network/yggdrasil-go; \ -cd $(GOPATH)/src/github.com/yggdrasil-network/yggdrasil-go; \
go get -v -d ./...; \ go get -v -d ./...; \
go get -u github.com/yggdrasil-network/yggdrasil-extras@005d79c; \ go get -u github.com/yggdrasil-network/yggdrasil-extras; \
ANDROID=true ./build; ANDROID=true ./build;
mv -f $(GOPATH)/src/github.com/yggdrasil-network/yggdrasil-go/yggdrasil.aar yggdrasil.aar; mv -f $(GOPATH)/src/github.com/yggdrasil-network/yggdrasil-go/yggdrasil.aar yggdrasil.aar;
mv -f $(GOPATH)/src/github.com/yggdrasil-network/yggdrasil-go/yggdrasil-sources.jar yggdrasil-sources.jar; mv -f $(GOPATH)/src/github.com/yggdrasil-network/yggdrasil-go/yggdrasil-sources.jar yggdrasil-sources.jar;