Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
PublicAndroidApps
Nebulo
Commits
70668ca6
Commit
70668ca6
authored
Jun 24, 2019
by
Daniel Wolf
Browse files
The service now uses the defined dns rules
parent
db814652
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/com/frostnerd/smokescreen/database/dao/DnsRuleDao.kt
View file @
70668ca6
...
...
@@ -3,7 +3,10 @@ package com.frostnerd.smokescreen.database.dao
import
androidx.room.Dao
import
androidx.room.Insert
import
androidx.room.Query
import
androidx.room.TypeConverters
import
com.frostnerd.smokescreen.database.converters.DnsTypeConverter
import
com.frostnerd.smokescreen.database.entities.DnsRule
import
org.minidns.record.Record
/*
* Copyright (C) 2019 Daniel Wolf (Ch4t4r)
...
...
@@ -24,6 +27,7 @@ import com.frostnerd.smokescreen.database.entities.DnsRule
* You can contact the developer at daniel.wolf@frostnerd.com.
*/
@Dao
@TypeConverters
(
DnsTypeConverter
::
class
)
interface
DnsRuleDao
{
@Query
(
"DELETE FROM DnsRule"
)
...
...
@@ -46,4 +50,7 @@ interface DnsRuleDao {
@Query
(
"SELECT COUNT(*) FROM DnsRule"
)
fun
getCount
():
Long
@Query
(
"SELECT target FROM DnsRule WHERE host=:host AND type = :type LIMIT 1"
)
fun
findRuleTarget
(
host
:
String
,
type
:
Record
.
TYPE
):
String
?
}
\ No newline at end of file
app/src/main/java/com/frostnerd/smokescreen/service/DnsVpnService.kt
View file @
70668ca6
...
...
@@ -40,10 +40,13 @@ import kotlinx.coroutines.*
import
org.minidns.dnsmessage.DnsMessage
import
org.minidns.dnsmessage.Question
import
org.minidns.dnsname.DnsName
import
org.minidns.record.A
import
org.minidns.record.AAAA
import
org.minidns.record.Record
import
java.io.ByteArrayInputStream
import
java.io.DataInputStream
import
java.io.Serializable
import
java.lang.IllegalStateException
import
java.net.Inet4Address
import
java.net.Inet6Address
import
java.net.InetAddress
...
...
@@ -213,7 +216,8 @@ class DnsVpnService : VpnService(), Runnable {
"allow_ipv4_traffic"
,
"dns_server_config"
,
"notification_allow_stop"
,
"notification_allow_pause"
"notification_allow_pause"
,
"dns_rules_enabled"
)
settingsSubscription
=
getPreferences
().
listenForChanges
(
relevantSettings
,
getPreferences
().
preferenceChangeListener
{
changes
->
...
...
@@ -752,7 +756,7 @@ class DnsVpnService : VpnService(), Runnable {
handle
.
ipv4Enabled
=
!
handle
.
ipv6Enabled
||
(
getPreferences
().
enableIpv4
&&
(
getPreferences
().
forceIpv4
||
hasDeviceIpv4Address
()))
dnsProxy
=
SmokeProxy
(
handle
,
createProxyBypassHandlers
(),
createDnsCache
(),
createQueryLogger
())
dnsProxy
=
SmokeProxy
(
handle
,
createProxyBypassHandlers
(),
createDnsCache
(),
createQueryLogger
()
,
createLocalResolver
()
)
log
(
"DnsProxy created, creating VPN proxy"
)
vpnProxy
=
VPNTunnelProxy
(
dnsProxy
!!
,
vpnService
=
this
,
coroutineScope
=
CoroutineScope
(
newFixedThreadPoolContext
(
1
,
"proxy-pool"
)),
logger
=
object
:
com
.
frostnerd
.
vpntunnelproxy
.
Logger
{
...
...
@@ -912,6 +916,44 @@ class DnsVpnService : VpnService(), Runnable {
return
dnsCache
}
private
fun
createLocalResolver
():
LocalResolver
?
{
if
(
getPreferences
().
dnsRulesEnabled
)
{
return
object
:
LocalResolver
(
false
)
{
private
val
dao
=
getDatabase
().
dnsRuleDao
()
private
val
resolveResults
=
mutableMapOf
<
Question
,
String
>()
override
suspend
fun
canResolve
(
question
:
Question
):
Boolean
{
return
if
(
question
.
type
!=
Record
.
TYPE
.
A
&&
question
.
type
!=
Record
.
TYPE
.
AAAA
)
{
false
}
else
{
val
resolveResult
=
dao
.
findRuleTarget
(
question
.
name
.
toString
(),
question
.
type
)
if
(
resolveResult
!=
null
)
{
resolveResults
[
question
]
=
resolveResult
true
}
else
false
}
}
override
suspend
fun
resolve
(
question
:
Question
):
List
<
Record
<
*
>>
{
val
result
=
resolveResults
.
remove
(
question
)
return
result
?.
let
{
val
data
=
if
(
question
.
type
==
Record
.
TYPE
.
A
)
{
A
(
it
)
}
else
{
AAAA
(
it
)
}
listOf
(
Record
(
question
.
name
.
toString
(),
question
.
type
,
question
.
clazz
.
value
,
9999
,
data
))
}
?:
throw
IllegalStateException
()
}
override
fun
cleanup
()
{}
}
}
else
{
return
null
}
}
private
fun
createPersistedCacheEntry
(
dnsName
:
String
,
type
:
Record
.
TYPE
,
...
...
app/src/main/java/com/frostnerd/smokescreen/util/proxy/SmokeProxy.kt
View file @
70668ca6
package
com.frostnerd.smokescreen.util.proxy
import
com.frostnerd.dnstunnelproxy.DnsHandle
import
com.frostnerd.dnstunnelproxy.DnsPacketProxy
import
com.frostnerd.dnstunnelproxy.*
import
com.frostnerd.dnstunnelproxy.QueryListener
import
com.frostnerd.dnstunnelproxy.SimpleDnsCache
import
com.frostnerd.smokescreen.service.DnsVpnService
import
org.minidns.dnsmessage.DnsMessage
import
org.minidns.record.A
...
...
@@ -36,7 +34,8 @@ class SmokeProxy(
dnsHandle
:
DnsHandle
,
proxyBypassHandles
:
List
<
DnsHandle
>,
val
cache
:
SimpleDnsCache
?,
queryListener
:
QueryListener
?
queryListener
:
QueryListener
?,
localResolver
:
LocalResolver
?
)
:
DnsPacketProxy
(
proxyBypassHandles
.
toMutableList
().
let
{
...
...
@@ -45,7 +44,8 @@ class SmokeProxy(
}.
toList
(),
null
,
cache
,
queryListener
=
queryListener
queryListener
=
queryListener
,
localResolver
=
localResolver
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment