-
Notifications
You must be signed in to change notification settings - Fork 934
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
Ensure successful registration before key refresh #3736
Conversation
Current dependencies on/for this PR: This comment was auto-generated by Graphite. |
...l-compiler/src/main/java/com/duckduckgo/anvil/compiler/ContributesServiceApiCodeGenerator.kt
Show resolved
Hide resolved
3c4ec73
to
4514bee
Compare
.../src/main/java/com/duckduckgo/networkprotection/impl/configuration/WgVpnControllerService.kt
Outdated
Show resolved
Hide resolved
fb31b77
to
6967b32
Compare
...tection-impl/src/main/java/com/duckduckgo/networkprotection/impl/rekey/NetPRekeyScheduler.kt
Show resolved
Hide resolved
suspend fun forceRekey() { | ||
if (appBuildConfig.isInternalBuild()) { | ||
forceRekey.set(true) | ||
doRekey() | ||
} else { | ||
logcat(LogPriority.ERROR) { "Force re-key not allowed in production builds" } | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to keep the force rekey
internal build functionality
@@ -52,7 +53,7 @@ interface NetPWaitlistManager { | |||
@SingleInstanceIn(AppScope::class) | |||
@ContributesBinding(AppScope::class) | |||
class RealNetPWaitlistManager @Inject constructor( | |||
private val service: WgVpnControllerService, | |||
@ProtectedVpnControllerService private val service: WgVpnControllerService, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto, ie. this probably can also rather be @UnprotectedVpnControllerService
at which point we delete the @ProtectedVpnControllerService
altogether
@@ -215,7 +213,7 @@ class NetPInternalSettingsActivity : DuckDuckGoActivity() { | |||
|
|||
binding.forceRekey.setClickListener { | |||
lifecycleScope.launch { | |||
netPRekeyer.doRekey() | |||
sendBroadcast(Intent(DebugRekeyReceiver.ACTION_FORCE_REKEY)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use a broadcast as an IPC mechanism, as rekeying needs to be received/executed by the :vpn
process
@@ -32,7 +33,7 @@ import javax.inject.Inject | |||
) | |||
class WgServerInternalProvider @Inject constructor( | |||
private val netPServerRepository: NetPServerRepository, | |||
private val controllerService: WgVpnControllerService, | |||
@ProtectedVpnControllerService private val controllerService: WgVpnControllerService, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
class DebugRekeyReceiver @Inject constructor( | ||
private val context: Context, | ||
private val rekeyer: RealNetPRekeyer, | ||
@ProcessName private val processName: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just for logging
728ba37
to
1e99303
Compare
0ed4fd1
to
57c48bd
Compare
1e99303
to
573f67e
Compare
.../src/main/java/com/duckduckgo/networkprotection/impl/configuration/WgVpnControllerService.kt
Show resolved
Hide resolved
...ork-protection-impl/src/main/java/com/duckduckgo/networkprotection/impl/rekey/NetPRekeyer.kt
Outdated
Show resolved
Hide resolved
...ork-protection-impl/src/main/java/com/duckduckgo/networkprotection/impl/rekey/NetPRekeyer.kt
Outdated
Show resolved
Hide resolved
573f67e
to
605400c
Compare
c3ca5af
to
c897c06
Compare
a2ffe89
to
cde8bfa
Compare
cde8bfa
to
8027aaa
Compare
8027aaa
to
771b666
Compare
Task/Issue URL: https://app.asana.com/0/0/1205631225739207/f ### Description Improve re-key so that: * it happens once a day * just re-key when the screen is off * avoids re-keying attempts when device is idle ### Steps to test this PR _Test force re-key_ - [x] build internal from this branch - [x] use force rekey in the netp dev settings - [x] new private key should be registered _Test rekey_ - apply the following patch ```diff Index: network-protection/network-protection-impl/src/main/java/com/duckduckgo/networkprotection/impl/rekey/NetPRekeyer.kt IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/network-protection/network-protection-impl/src/main/java/com/duckduckgo/networkprotection/impl/rekey/NetPRekeyer.kt b/network-protection/network-protection-impl/src/main/java/com/duckduckgo/networkprotection/impl/rekey/NetPRekeyer.kt --- a/network-protection/network-protection-impl/src/main/java/com/duckduckgo/networkprotection/impl/rekey/NetPRekeyer.kt (revision e44ddfce33069ae2ee2227bddffb24cc89049381) +++ b/network-protection/network-protection-impl/src/main/java/com/duckduckgo/networkprotection/impl/rekey/NetPRekeyer.kt (date 1698157737720) @@ -68,7 +68,7 @@ val forceOrFalseInProductionBuilds = forceRekey.getAndResetValue() val millisSinceLastKeyUpdate = System.currentTimeMillis() - networkProtectionRepository.lastPrivateKeyUpdateTimeInMillis - if (!forceOrFalseInProductionBuilds && millisSinceLastKeyUpdate < TimeUnit.DAYS.toMillis(1)) { + if (!forceOrFalseInProductionBuilds && millisSinceLastKeyUpdate < TimeUnit.SECONDS.toMillis(5)) { logcat { "Less than 24h passed, skip re-keying" } return } Index: network-protection/network-protection-impl/src/main/java/com/duckduckgo/networkprotection/impl/rekey/NetPRekeyScheduler.kt IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/network-protection/network-protection-impl/src/main/java/com/duckduckgo/networkprotection/impl/rekey/NetPRekeyScheduler.kt b/network-protection/network-protection-impl/src/main/java/com/duckduckgo/networkprotection/impl/rekey/NetPRekeyScheduler.kt --- a/network-protection/network-protection-impl/src/main/java/com/duckduckgo/networkprotection/impl/rekey/NetPRekeyScheduler.kt (revision e44ddfce33069ae2ee2227bddffb24cc89049381) +++ b/network-protection/network-protection-impl/src/main/java/com/duckduckgo/networkprotection/impl/rekey/NetPRekeyScheduler.kt (date 1698157737723) @@ -42,7 +42,7 @@ job += coroutineScope.launch(dispatcherProvider.io()) { while (isActive && vpnFeaturesRegistry.isFeatureRegistered(NetPVpnFeature.NETP_VPN)) { logcat { "Start periodic re-keying attempts" } - delay(TimeUnit.HOURS.toMillis(1)) // try to re-key every 1h + delay(TimeUnit.SECONDS.toMillis(10)) // try to re-key every 1h netPRekeyer.doRekey() } ``` - build internal build - launch app and enable NetP - [x] with mobile device screen ON, see `Device not locked, skip re-keying` logcat appear every 10 seconds or so - [x] with mobile device screen OFF, see `Restarting VPN after clearing client keys` logcat appear every 10 seconds or so
Task/Issue URL: https://app.asana.com/0/0/1205631225739207/f
Description
Improve re-key so that:
Steps to test this PR
Test force re-key
Test rekey
Device not locked, skip re-keying
logcat appear every 10 seconds or soRestarting VPN after clearing client keys
logcat appear every 10 seconds or so