Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
applicationId = "net.pangolin.Pangolin"
minSdk = 24
targetSdk = 36
versionCode = 27
versionName = "0.8.0"
versionCode = 28
versionName = "0.8.1"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
23 changes: 2 additions & 21 deletions app/src/main/java/net/pangolin/Pangolin/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ import android.os.Build
import android.os.Bundle
import android.os.PowerManager
import android.provider.Settings
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.style.ForegroundColorSpan
import android.text.style.RelativeSizeSpan
import android.util.Log
import android.view.View
import android.widget.Toast
Expand Down Expand Up @@ -867,23 +863,8 @@ class MainActivity : BaseNavigationActivity() {
return
}

// "None" first, then each exit node with the sites it routes through beneath its name
val secondaryColor = MaterialColors.getColor(
this, com.google.android.material.R.attr.colorOnSurfaceVariant, android.graphics.Color.GRAY
)
val names = (listOf<CharSequence>("None") + nodes.map { node ->
val siteNames = node.siteNames.orEmpty()
if (siteNames.isEmpty()) {
node.name
} else {
SpannableStringBuilder(node.name).append('\n').apply {
val start = length
append(siteNames.joinToString(", "))
setSpan(RelativeSizeSpan(0.85f), start, length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
setSpan(ForegroundColorSpan(secondaryColor), start, length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
}
}
}).toTypedArray()
// "None" first, then each exit node by name
val names = (listOf<CharSequence>("None") + nodes.map { it.name }).toTypedArray()
val activeIndex = nodes.indexOfFirst { it.siteResourceId == state.activeId }
val checkedItem = if (activeIndex >= 0) activeIndex + 1 else 0

Expand Down
28 changes: 13 additions & 15 deletions app/src/main/java/net/pangolin/Pangolin/SettingsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.content.ContextCompat
import android.view.ViewGroup
import android.text.method.DigitsKeyListener
import android.util.Patterns
import androidx.lifecycle.lifecycleScope
import androidx.preference.EditTextPreference
import androidx.preference.Preference
Expand All @@ -21,6 +20,7 @@ import com.google.android.material.textfield.TextInputLayout
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import net.pangolin.Pangolin.databinding.SettingsActivityBinding
import net.pangolin.Pangolin.util.DnsServerAddress
import net.pangolin.Pangolin.util.TunnelManager

class SettingsActivity : BaseNavigationActivity() {
Expand Down Expand Up @@ -233,11 +233,15 @@ class SettingsActivity : BaseNavigationActivity() {
setText(preference.text)
}

// If DNS fields, restrict to numeric + decimal input (to allow dots) and validate
// If DNS fields, restrict to the characters of an IPv4/IPv6 address and validate
val isDnsField = preference.key == "primaryDNSServer" || preference.key == "secondaryDNSServer"
val isMtuField = preference.key == "mtu"
if (isDnsField) {
editText.keyListener = DigitsKeyListener.getInstance("0123456789.:")
editText.keyListener = DigitsKeyListener.getInstance("0123456789abcdefABCDEF.:")
// DigitsKeyListener asks for the number pad, which has no ':' or hex letters for IPv6
editText.setRawInputType(
android.text.InputType.TYPE_CLASS_TEXT or android.text.InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
)
textInputLayout.placeholderText = "System DNS"
} else if (isMtuField) {
editText.keyListener = DigitsKeyListener.getInstance("0123456789")
Expand Down Expand Up @@ -268,7 +272,7 @@ class SettingsActivity : BaseNavigationActivity() {
if (newValue.isEmpty()) {
true
} else {
Patterns.IP_ADDRESS.matcher(newValue).matches()
DnsServerAddress.isValid(newValue)
}
}
isMtuField -> {
Expand All @@ -279,19 +283,14 @@ class SettingsActivity : BaseNavigationActivity() {
}

if (!isValid) {
when {
isMtuField -> {
textInputLayout.error = "Please enter a valid MTU value"
textInputLayout.helperText = "Must be between 576 and 65535"
}
else -> {
textInputLayout.error = "Please enter a valid IP address"
textInputLayout.helperText = "Examples: 1.1.1.1, 8.8.4.4, or IPv6 like 2001:4860:4860::8888"
}
// Only the error is set: setting helperText afterwards replaces
// the error caption, so it would flash and disappear
textInputLayout.error = when {
isMtuField -> "Please enter a valid MTU value between 576 and 65535"
else -> "Please enter a valid IP address, like 1.1.1.1 or 2001:4860:4860::8888"
}
} else {
textInputLayout.error = null
textInputLayout.helperText = null
if (preference.callChangeListener(newValue)) {
preference.text = newValue
dialog.dismiss()
Expand All @@ -304,7 +303,6 @@ class SettingsActivity : BaseNavigationActivity() {
neutralButton?.setOnClickListener {
editText.setText("")
textInputLayout.error = null
textInputLayout.helperText = null
if (preference.callChangeListener("")) {
preference.text = ""
}
Expand Down
65 changes: 65 additions & 0 deletions app/src/main/java/net/pangolin/Pangolin/util/DnsServerAddress.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package net.pangolin.Pangolin.util

/**
* Validation and formatting for the user-entered upstream DNS server addresses.
*
* Parsed by hand rather than with InetAddress.getByName (which falls back to a
* DNS lookup for anything that isn't a literal) or InetAddresses.isNumericAddress
* (API 29+, minSdk is 24).
*/
object DnsServerAddress {
/** Whether [address] is a literal IPv4 or IPv6 address. */
fun isValid(address: String): Boolean = isIPv4(address) || isIPv6(address)

/**
* Formats [address] as the "host:port" olm expects, wrapping IPv6 addresses
* in brackets ("[2606:4700:4700::1111]:53") so the port stays unambiguous.
*/
fun toHostPort(address: String, port: Int = 53): String =
if (address.contains(':')) "[$address]:$port" else "$address:$port"

private fun isIPv4(address: String): Boolean {
val parts = address.split('.')
if (parts.size != 4) return false
return parts.all { part ->
// No leading zeros - olm's Go parser rejects them as ambiguous with octal
part.length in 1..3 &&
part.all { it in '0'..'9' } &&
(part.length == 1 || part[0] != '0') &&
part.toInt() <= 255
}
}

private fun isIPv6(address: String): Boolean {
val compression = address.indexOf("::")
if (compression != address.lastIndexOf("::")) return false // at most one "::"

val groups = if (compression >= 0) {
splitGroups(address.substring(0, compression)) + splitGroups(address.substring(compression + 2))
} else {
address.split(':')
}

var count = 0
for ((index, group) in groups.withIndex()) {
if (index == groups.lastIndex && group.contains('.')) {
// Embedded IPv4 tail, e.g. ::ffff:192.0.2.1, takes the place of two groups
// and has to end the address (so not "1.2.3.4::")
if (address.endsWith("::") || !isIPv4(group)) return false
count += 2
} else {
if (group.length !in 1..4 || !group.all { it.isHexDigit() }) return false
count++
}
}

// "::" stands in for at least one group of zeros
return if (compression >= 0) count <= 7 else count == 8
}

private fun splitGroups(part: String): List<String> =
if (part.isEmpty()) emptyList() else part.split(':')

private fun Char.isHexDigit(): Boolean =
this in '0'..'9' || this in 'a'..'f' || this in 'A'..'F'
}
4 changes: 2 additions & 2 deletions app/src/main/java/net/pangolin/Pangolin/util/TunnelManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,10 @@ class TunnelManager private constructor(
// explicit user override and would stop it from being auto-updated.
val upstreamDns = mutableListOf<String>()
if (!primaryDNS.isNullOrBlank()) {
upstreamDns.add("$primaryDNS:53")
upstreamDns.add(DnsServerAddress.toHostPort(primaryDNS.trim()))
}
if (!secondaryDNS.isNullOrBlank()) {
upstreamDns.add("$secondaryDNS:53")
upstreamDns.add(DnsServerAddress.toHostPort(secondaryDNS.trim()))
}

val tunnelConfig = TunnelConfig.Builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package net.pangolin.Pangolin.util

import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test

class DnsServerAddressTest {
@Test
fun acceptsIPv4() {
listOf("1.1.1.1", "8.8.4.4", "192.168.1.254", "0.0.0.0", "255.255.255.255").forEach {
assertTrue(it, DnsServerAddress.isValid(it))
}
}

@Test
fun acceptsIPv6() {
listOf(
"2606:4700:4700::1111",
"2606:4700:4700:0000:0000:0000:0000:1111",
"2001:4860:4860::8888",
"2001:db8::1",
"2001:DB8::ABCD",
"fd00::53",
"::1",
"::",
"1::",
"1:2:3:4:5:6:7::",
"::ffff:192.0.2.1",
"64:ff9b::8.8.8.8",
"1:2:3:4:5:6:1.2.3.4",
).forEach {
assertTrue(it, DnsServerAddress.isValid(it))
}
}

@Test
fun rejectsInvalidAddresses() {
listOf(
"",
"1.1.1",
"1.1.1.1.1",
"256.1.1.1",
"01.1.1.1",
"1.1.1.",
"1..1.1",
"1.1.1.1:53",
":",
":::",
"1:::2",
"1::2::3",
":1::2",
"1::2:",
"1:2:3:4:5:6:7",
"1:2:3:4:5:6:7:8:9",
"1:2:3:4:5:6:7:8::",
"12345::1",
"2001:db8::g",
"::1.2.3",
"1:2:3:4:5:6:7:1.2.3.4",
"1.2.3.4::",
"[2606:4700:4700::1111]",
"2606:4700:4700::1111%wlan0",
"dns.example.com",
).forEach {
assertFalse(it, DnsServerAddress.isValid(it))
}
}

@Test
fun formatsHostPort() {
assertEquals("1.1.1.1:53", DnsServerAddress.toHostPort("1.1.1.1"))
assertEquals("[2606:4700:4700::1111]:53", DnsServerAddress.toHostPort("2606:4700:4700::1111"))
}
}
12 changes: 5 additions & 7 deletions tunnel/tools/libpangolin-go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/fosrl/android
go 1.26.0

require (
github.com/fosrl/newt v1.18.0
github.com/fosrl/olm v1.10.0
github.com/fosrl/newt v1.18.1
github.com/fosrl/olm v1.10.1
golang.org/x/sys v0.48.0
)

Expand All @@ -17,20 +17,18 @@ require (
github.com/gorilla/websocket v1.5.3 // indirect
github.com/mdlayher/netlink v1.7.3-0.20250113171957-fbb4dce95f42 // indirect
github.com/mdlayher/socket v0.5.1 // indirect
github.com/miekg/dns v1.1.70 // indirect
github.com/miekg/dns v1.1.73 // indirect
github.com/vishvananda/netlink v1.3.1 // indirect
github.com/vishvananda/netns v0.0.5 // indirect
golang.org/x/crypto v0.57.0 // indirect
golang.org/x/exp v0.0.0-20251113190631-e25ba8c21ef6 // indirect
golang.org/x/mod v0.34.0 // indirect
golang.org/x/net v0.59.0 // indirect
golang.org/x/sync v0.20.0 // indirect
golang.org/x/sync v0.22.0 // indirect
golang.org/x/time v0.12.0 // indirect
golang.org/x/tools v0.43.0 // indirect
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 // indirect
golang.zx2c4.com/wireguard v0.0.0-20250521234502-f333402bd9cb // indirect
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20241231184526-a9ab2273dd10 // indirect
golang.zx2c4.com/wireguard/windows v1.0.1 // indirect
golang.zx2c4.com/wireguard/windows v1.1.1 // indirect
gvisor.dev/gvisor v0.0.0-20250503011706-39ed1f5ac29c // indirect
software.sslmate.com/src/go-pkcs12 v0.7.3 // indirect
)
Expand Down
24 changes: 10 additions & 14 deletions tunnel/tools/libpangolin-go/go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/fosrl/newt v1.18.0 h1:fFBksIV6BoI+BGmv6fwo87tXBk1WlxbVoruvupeD6hk=
github.com/fosrl/newt v1.18.0/go.mod h1:CwcuQtifgDQeSWSEB3yfqOgheFv9yltVBYQNgDB/DoM=
github.com/fosrl/olm v1.10.0 h1:2YS6Kirab1yg+MZSM8y9/Ja5IpwQBFY6d7ZMsPuYGM0=
github.com/fosrl/olm v1.10.0/go.mod h1:c/ECpzDjwnkcLrXxNpFDpFViE7+NC8yRuuLCOhGj7OA=
github.com/fosrl/newt v1.18.1 h1:gKWBDKSqQLSgD6z0jPzZB86U19a2xNfOTV0S1KdYSx0=
github.com/fosrl/newt v1.18.1/go.mod h1:gTr7YDmLqjVrqZJ3SQU0MR9wKfqbUZOJF8hSFIi/M+I=
github.com/fosrl/olm v1.10.1 h1:9q6sMuWpT8MzTj7UX4q5VYzPc8CJmW+9eBqZVIUkNZU=
github.com/fosrl/olm v1.10.1/go.mod h1:WqvwXlFtE5WjDFZj35VTdMYIhIRh4Nb65NDSNpmYE1U=
github.com/godbus/dbus/v5 v5.2.2 h1:TUR3TgtSVDmjiXOgAAyaZbYmIeP3DPkld3jgKGV8mXQ=
github.com/godbus/dbus/v5 v5.2.2/go.mod h1:3AAv2+hPq5rdnr5txxxRwiGjPXamgoIHgz9FPBfOp3c=
github.com/google/btree v1.1.3 h1:CVpQJjYgC4VbzxeGVHfvZrv1ctoYCAI8vbl07Fcxlyg=
Expand All @@ -18,8 +18,8 @@ github.com/mdlayher/netlink v1.7.3-0.20250113171957-fbb4dce95f42 h1:A1Cq6Ysb0GM0
github.com/mdlayher/netlink v1.7.3-0.20250113171957-fbb4dce95f42/go.mod h1:BB4YCPDOzfy7FniQ/lxuYQ3dgmM2cZumHbK8RpTjN2o=
github.com/mdlayher/socket v0.5.1 h1:VZaqt6RkGkt2OE9l3GcC6nZkqD3xKeQLyfleW/uBcos=
github.com/mdlayher/socket v0.5.1/go.mod h1:TjPLHI1UgwEv5J1B5q0zTZq12A/6H7nKmtTanQE37IQ=
github.com/miekg/dns v1.1.70 h1:DZ4u2AV35VJxdD9Fo9fIWm119BsQL5cZU1cQ9s0LkqA=
github.com/miekg/dns v1.1.70/go.mod h1:+EuEPhdHOsfk6Wk5TT2CzssZdqkmFhf8r+aVyDEToIs=
github.com/miekg/dns v1.1.73 h1:uhT8nJxmTrPJYClxVxTCX+CVn6qnzSiybRk72Z6DgrE=
github.com/miekg/dns v1.1.73/go.mod h1:RW2Obtfd5NZHvOFe3zYG0W8koWOQtAzyHaLo8vASBuQ=
github.com/vishvananda/netlink v1.3.1 h1:3AEMt62VKqz90r0tmNhog0r/PpWKmrEShJU0wJW6bV0=
github.com/vishvananda/netlink v1.3.1/go.mod h1:ARtKouGSTGchR8aMwmkzC0qiNPrrWO5JS/XMVl45+b4=
github.com/vishvananda/netns v0.0.5 h1:DfiHV+j8bA32MFM7bfEunvT8IAqQ/NzSJHtcmW5zdEY=
Expand All @@ -28,28 +28,24 @@ golang.org/x/crypto v0.57.0 h1:3ZVCjf8Ggz7zneR/EHRVx68Ctf+2pmIMP2UFhh9cC6M=
golang.org/x/crypto v0.57.0/go.mod h1:Fdz0i5U6CoizGwLda9DttjSk6qlZo25zYNtR+ycvuZA=
golang.org/x/exp v0.0.0-20251113190631-e25ba8c21ef6 h1:zfMcR1Cs4KNuomFFgGefv5N0czO2XZpUbxGUy8i8ug0=
golang.org/x/exp v0.0.0-20251113190631-e25ba8c21ef6/go.mod h1:46edojNIoXTNOhySWIWdix628clX9ODXwPsQuG6hsK0=
golang.org/x/mod v0.34.0 h1:xIHgNUUnW6sYkcM5Jleh05DvLOtwc6RitGHbDk4akRI=
golang.org/x/mod v0.34.0/go.mod h1:ykgH52iCZe79kzLLMhyCUzhMci+nQj+0XkbXpNYtVjY=
golang.org/x/net v0.59.0 h1:5zfYln+w5XCxwrnMMJPufRgNoXEaGxl0wo5GqPXyues=
golang.org/x/net v0.59.0/go.mod h1:2DA/G1UfVbCpQPeWTmMPGY7Cs2PkBkwu743bVX5PIVg=
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
golang.org/x/sync v0.22.0 h1:SZjpbeLmrCk4xhRSZFNZW5gFUeCeFgjekvI/+gfScek=
golang.org/x/sync v0.22.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.48.0 h1:bbX/i/6MgT9BVLM9RT1thmxL04yeTAhbEz4SyadbXoo=
golang.org/x/sys v0.48.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE=
golang.org/x/time v0.12.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
golang.org/x/tools v0.43.0 h1:12BdW9CeB3Z+J/I/wj34VMl8X+fEXBxVR90JeMX5E7s=
golang.org/x/tools v0.43.0/go.mod h1:uHkMso649BX2cZK6+RpuIPXS3ho2hZo4FVwfoy1vIk0=
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 h1:B82qJJgjvYKsXS9jeunTOisW56dUokqW/FOteYJJ/yg=
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2/go.mod h1:deeaetjYA+DHMHg+sMSMI58GrEteJUUzzw7en6TJQcI=
golang.zx2c4.com/wireguard v0.0.0-20250521234502-f333402bd9cb h1:whnFRlWMcXI9d+ZbWg+4sHnLp52d5yiIPUxMBSt4X9A=
golang.zx2c4.com/wireguard v0.0.0-20250521234502-f333402bd9cb/go.mod h1:rpwXGsirqLqN2L0JDJQlwOboGHmptD5ZD6T2VmcqhTw=
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20241231184526-a9ab2273dd10 h1:3GDAcqdIg1ozBNLgPy4SLT84nfcBjr6rhGtXYtrkWLU=
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20241231184526-a9ab2273dd10/go.mod h1:T97yPqesLiNrOYxkwmhMI0ZIlJDm+p0PMR8eRVeR5tQ=
golang.zx2c4.com/wireguard/windows v1.0.1 h1:eOxiDVbywPC+ZQqvdCK7x+ZwWXKbYv50TtH8ysFIbw8=
golang.zx2c4.com/wireguard/windows v1.0.1/go.mod h1:+fbT3FFdX4zzYDLwJh5+HPEcNN/3HyNdzhNSVsQM+zs=
golang.zx2c4.com/wireguard/windows v1.1.1 h1:8/H97U1v1PNDNcBsMZgU3KFuND9MQdTsU2NOwmCXArE=
golang.zx2c4.com/wireguard/windows v1.1.1/go.mod h1:+fbT3FFdX4zzYDLwJh5+HPEcNN/3HyNdzhNSVsQM+zs=
gvisor.dev/gvisor v0.0.0-20250503011706-39ed1f5ac29c h1:m/r7OM+Y2Ty1sgBQ7Qb27VgIMBW8ZZhT4gLnUyDIhzI=
gvisor.dev/gvisor v0.0.0-20250503011706-39ed1f5ac29c/go.mod h1:3r5CMtNQMKIvBlrmM9xWUNamjKBYPOWyXOjmg5Kts3g=
software.sslmate.com/src/go-pkcs12 v0.7.3 h1:JBQD3FDqYjTeyDAeZQklj2ar88ykBLtALloPJHyAauU=
Expand Down