{{Header}}
{{Title|title=
TimeSync: {{project_name_long}} Time Synchronization Mechanism
}}
{{#seo:
|description=Design Documentation of {{project_name_short}} Time Synchronization Mechanism
}}
{{time_mininav}}
{{intro|
Design Documentation of {{project_name_short}} Time Synchronization Mechanism
}}
= Basic Knowledge =
== Introduction ==
The Post Install Advice is part of this design, therefore read [[Post Install Advice#Network Time Syncing|Network Time Syncing]] first. Also read [[Network Time Synchronization|Network Time Synchronization]] as well.
== Local Clock Leaks ==
* TCP Sequence Numbers → [https://github.com/Kicksecure/tirdad tirdad
]
* [https://web.archive.org/web/20160624053221/https://mailman.boum.org/pipermail/tails-dev/2014-September/007062.html Tails-dev - TCP Sequence Numbers leak System Clock]
* [https://gitlab.torproject.org/legacy/trac/-/issues/16659 Linux TCP Initial Sequence Numbers may aid correlation]
* ICMP timestamps → blocked by {{project_name_short}} firewall for {{project_name_short}} VMs. Host: [[Disable_TCP_and_ICMP_Timestamps#Disable_ICMP_Timestamps|Recommendation]] to disable on the host.
* TCP timestamps → blocked in {{project_name_short}} VMs by [https://github.com/Kicksecure/security-misc security-misc].; [[Computer_Security_Education#Disable_TCP_Timestamps|Recommendation]] to disable on the host.
* NTP → Not installed by default in {{project_name_short}}. Host: TODO
* Automatic updaters and other network using cron jobs that run at non-random, canned
By distribution defaults.
times.
* Javascript.
Was [https://gitlab.torproject.org/legacy/trac/-/issues/3059 fixed] in Tor Browser, but remains open for other applications such as browsers like Mozilla Firefox.
See https://ip-check.info/ for demonstration.
* E-mail clients such as Mozilla Thunderbird and others.
As of June 2016, Iceweasel has been replaced by Firefox-ESR in Debian, see https://wiki.debian.org/Iceweasel
[https://gitlab.torproject.org/legacy/trac/-/issues/6314 prevent leak via Date header field (local timestamp disclosure)]
[https://gitlab.torproject.org/legacy/trac/-/issues/6315 prevent leak via Message-ID header field (local timestamp disclosure) ]
[https://blog.torproject.org/torbirdy-013-our-fourth-beta-release Quote, on October 24th, 2014 sukhbir said]:
"The timestamp disclosures are via the date and the message-ID headers (relevant tickets: [https://gitlab.torproject.org/legacy/trac/-/issues/6314 #6314], [https://gitlab.torproject.org/legacy/trac/-/issues/6315 #6315]). We have submitted patches to Mozilla ([https://bugzilla.mozilla.org/show_bug.cgi?id=902573 902573], [https://bugzilla.mozilla.org/show_bug.cgi?id=902580 902580]) that have not yet been merged. The patches probably need more work and we are looking for volunteers to work on them and help us to get them merged. We will be doing a blog post about this soon and put out a call for help."
* https / ssl, older versions of openssl, TLS HELLO gmt_unix_time
https://gitlab.torproject.org/legacy/trac/-/issues/8751
What about other implementations of SSL / TLS, other than openssl?
* older For example the one shipped by Debian wheezy.
versions of Tor (NETINFO)
See [https://gitlab.torproject.org/legacy/trac/-/issues/4852 torproject.org #4852: Clients send NETINFO with time]. The ticket says fixed. However, [https://packages.debian.org/de/wheezy/tor Debian wheezy (which {{project_name_short}} 10 was based on) was using Tor 0.2.3] but Nick's [https://gitlab.torproject.org/legacy/trac/-/issues/4852#comment:20 patch appeared first in 0.2.4]. It was solved in {{project_name_short}} 11, because it was based on Debian jessie, that contained [https://packages.debian.org/de/jessie/tor a more recent version of Tor].
* web servers (time stamps from http headers (RFC 2616))
For demonstration, you could use.
curl -silent --head torproject.org | grep -i date:
== Virtualizers Time Synchronization Features ==
=== VirtualBox Time Synchronization Features ===
{{Anchor|VirtualBox's Time Synchronization Features}}
For understanding {{project_name_short}} Time Synchronization Mechanism, it is required to know VirtualBox's time synchronization features:
* VirtualBox uses the host's time if it needs to correct the time for guests.
* (Some of VirtualBox's time synchronization features depend on guest additions.)
* By default VirtualBox corrects Virtual Machine guests' virtual hardware system clock,
** when they get powered on,
** when they resume from suspension and
** when their clock is more than X minutes off.
=== KVM's Time Synchronization Features ===
* KVM attempts (in vain) to use:
** ntpd
** If offline or manually selected (with a compatible CPU), Time Stamp Counters (TSC) from the CPU.docs.redhat.com/en/documentation/red_hat_enterprise_linux/7/html/virtualization_deployment_and_administration_guide/chap-kvm_guest_timing_management
It is possible to check what exact method of synchronization the guest is trying to use by typing cat /sys/devices/system/clocksource/clocksource0/current_clocksource
https://www.linux-kvm.org/page/KVMClock
As of 2024, on Whonix, this is TSC (KVM does not control the process as kvm-clock
is not included within the output). sdwdate
and bootclockrandomization
fix any timing attacks that could be introduced.
=== Qubes Time Synchronization Features ===
TODO: document
Xen DomU’s get their initial time from Xen (Qubes dom0) at VM start.
* qvm-sync-clock.service
* qvm-sync-clock.timer
qvm-sync-clock gets time from Qubes ClockVM.
It is used because otherwise Xen DomU’s would start to clock drift more and more. This [https://forums.whonix.org/t/whonix-ws-16-fails-to-update-due-to-timing-issue/12739/10 this answer by marmarek].
qvm-sync-clock is unwanted in {{project_name_gateway_vm}} and {{project_name_workstation_vm}} because sdwdate runs there.
qvm-sync-clock is disabled in {{q_project_name_long}} Templates until version {{q_project_name_long}} 16.0.3.7
. To be re-considered for later versions. {{q_project_name_long}} get their time from dom0 at VM startup, which is then randomized using [[Boot Clock Randomization]].
Future: qvm-sync-clock should be equally safe to run inside {{q_project_name_short}} Templates, if passed though clock-random-manual-cli
.
When is /etc/qubes-rpc/qubes.SetDateTime
run?
== sdwdate Time Sources Criteria ==
See [[Sdwdate#sdwdate_Time_Sources_Criteria|sdwdate Time Sources Criteria]].
== Facts ==
People have been using:
* Tor Browser and Mozilla Firefox in parallel
* Tails inside VMs and Firefox on the host
* Tor Browser inside {{project_name_workstation_long}} and Mozilla Firefox on the host
== Other Facts ==
* Almost no one and no operating system is using Secure Network Time Synchronization or External Clocks by default. Most systems synchronize the system clock using unauthenticated NTP. An adversary tampering with NTP replies or malicious NTP server makes things even worse. Even if there was authenticated NTP, there is a requirement for a distributed trust model.
* A system not using NTP or using authenticated NTP stands out from most other users.
* clock jumps are bad: [https://www.wired.com/2012/07/leap-second-glitch-explained/ wired: The Inside Story of the Extra Second That Crashed the Web]
== Definitions ==
* Time Sanity Check in context of Whonix: Is an init.d script, which checks if the system clock is between build timestamp and expiration date (17 MAY 2033 10:00:00).
= Attacks =
A correct system clock is crucial for many reasons (see footnotes for more):
* '''Attack 1:''' Replay attacks Replay old Tor consensus, see [https://tails.boum.org/contribute/design/Time_syncing/ Tails: Time syncing] for detailed explanation.
* '''Attack 2:''' Feeding old/outdated/known vulnerable updates and (https) certificates Cryptographic verification depends on system clock, i.e. a clock two years in past will accept certificates/updates, which have been expired/revoked for two years.
* '''Attack 3:''' Deanonymizing [[#Local Clock Leaks]] are an issue. Imagine the user connects to an adversary controlled web-server with Mozilla Firefox and connects to another web-server controlled by the same adversary with Thunderbird. The adversary can link the anonymous and non-anonymous session, thus deanonymizing.
* '''Attack 4:''' Linking all sessions to the same pseudonym If the clock is too much off, it is also easy for an adversary's web-server to detect "Oh, that's the Tor Browser user who's clock is X in past/future.", thus allowing the adversary to link all sessions to the same pseudonym. See Tor Browser upstream bug #3059: [https://gitlab.torproject.org/legacy/trac/-/issues/3059 Find some way to deal with time-based fingerprints].
* '''Attack 5:''' Locating onion services.
For onion services a correct clock is crucial, see:
* [https://murdoch.is/papers/ccs06hotornot.pdf Hot or Not: Revealing Hidden Services by their Clock Skew]
* [https://web.archive.org/web/20220324134410/https://caia.swin.edu.au/talks/CAIA-TALK-080728A.pdf An improved clock-skew measurement technique for revealing hidden services]
* [https://web.archive.org/web/20120522143952/http://people.cs.umass.edu/~elisha/Papers/SkewMask%20-%20final%20version.pdf SkewMask: Frustrating Clock Skew Fingerprinting Attempts]
* [https://catalog.caida.org/details/paper/2005_fingerprinting Remote physical device fingerprinting]
= Goals =
== Completely Isolated Virtual Time ==
Quote https://www.kernel.org/doc/Documentation/virtual/kvm/timekeeping.txt
4.8) Covert channels and leaks In addition to the above problems, time information will inevitably leak to the guest about the host in anything but a perfect implementation of virtualized time. This may allow the guest to infer the presence of a hypervisor (as in a red-pill type detection), and it may allow information to leak between guest by using CPU utilization itself as a signalling channel. Preventing such problems would require completely isolated virtual time which may not track real time any longer. This may be useful in certain security or QA contexts, but in general is not recommended for real-world deployment scenarios.Therefore we want a completely isolated virtual time. = {{project_name_short}} Time Synchronization Mechanism = == Overview == * {{project_name_short}} leaves the host's system clock or time synchronization mechanism untouched. * {{project_name_gateway_long}} and {{project_name_workstation_short}} are commonly used inside virtualizers and therefore have their own virtual hardware system clocks. * Virtualizers time synchronization get disabled by {{project_name_short}}. ** Most VirtualBox time synchronization features get disabled by {{project_name_short}}. *** Guest additions time synchronization gets disabled in by [https://github.com/{{project_name_short}}/vm-config-dist vm-config-dist] at run time. See VirtualBox bug report [https://www.virtualbox.org/ticket/10828 VBoxService --disable-timesync broken]. They say it is actually not a bug. It is a missing feature, that running instances of VBoxService can not be modified in their settings. *** built in time synchronization features get disabled by ''VBoxManage setextradata "$VMNAME" "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" "1"'' at build time. ** Qubes: TODO *** https://phabricator.whonix.org/T389 *** https://phabricator.whonix.org/T440 *** https://phabricator.whonix.org/T389 * VM Settings, Hardware Clock: set to UTC. * When get powered on, they still get their time from the host. The user is advised to modify the biossystemtimeoffset in Advanced Security Guide, chapter [[Advanced Security Guide#Network Time Synchronization|Network Time Synchronization]]. Developer information: If we needed or wanted to render the hardware clock unusable, we could set VirtualBox ''--biossystemtimeoffset'' several decades in past or future. * Time Sanity Check before [[sdwdate]] will be executed, this ensures, that the host clock is sane and not slow in 1980. User gets advised to fix its host clock in such cases. * After they are connected to the Tor network, they use sdwdate (inspired by [https://tails.boum.org/contribute/design/Time_syncing/ tails_htp]) to set the system clock. Stream isolation has been added, for {{project_name_short}} sdwdate implementation i.e. people using Tor Browser prevent notifying their exit relay, that they are sdwdate or {{project_name_short}} users. * Time Sanity Check after sdwdate was executed. This should catch eventual bigger bugs and attacks. User gets informed if it fails. * Using [https://github.com/{{project_name_short}}/bootclockrandomization Boot Clock Randomization], i.e. after boot, the clock is set randomly between 0 and 180 seconds into the past or future. This is useful to enforce the design goal, that the host clock and {{project_name_workstation_short}} clock should always slightly differ. It is also useful to obfuscate the clock when sdwdate itself is running, because naturally at this time, sdwdate hasn't finished. * sdwdate runs after booting. * {{project_name_gateway_short}}: Using sdwdate is better against Attack (1) when using a bridge. * Every hour, at a random time, sdwdate will set the clock again. This is useful for machines running for long time periods without reboot. * sdwdate runs at non-predictable times to prevent the ISP or Tor guard/bridge node to guess, that the user is running {{project_name_short}}. * sdwdate adds or subtracts a random amount of seconds in range of 0.000000001 and 0.999999999. Check.
grep -i "Made up" /var/log/sdwdate.logThis is supposed to prevent time servers tracking individual users. * That will reach the design goal, that all clocks, the host's, {{project_name_gateway_short}} and {{project_name_workstation_short}} slightly differ. == Block Networking until sdwdate Finishes == TODO: expand '''This is not yet enabled by default.''' Network access will be limited to Tor and sdwdate until network time synchronization is done to prevent accidental traffic before that is done. {{project_name_short}} firewall runs in two different modes. After boot it runs in
timesync-fail-closed mode
.
OK: First run during current boot, therefore running in timesync-fail-closed mode. OK: (Only local Tor control port connections and torified sdwdate allowed.)Otherwise after sdwdate succeeded or after manually reloading {{project_name_short}} firewall it runs in
full mode
.
OK: Consecutive run during current boot, therefore running in full mode. OK: (Full torified network access allowed.)Users are encouraged to test so we can enable it by default in the future. https://forums.whonix.org/t/testers-wanted-blocking-networking-until-sdwdate-finished-status-of-sdwdate-gui/5372/6 Instructions: [[Network_Time_Synchronization#Block_Networking_until_sdwdate_Finishes]] == boot clock randomization == {{Boot_Clock_Randomization}} == Conclusions == * '''Attack 1''' is a general Tor problem. It is impossible to solve for {{project_name_short}}. It is unsolved in other projects as well. * '''Attack 2''' gets partially defeated. ** {{project_name_gateway_short}} and {{project_name_workstation_short}} are immune. ** This problem is unsolved in other projects as well. *** This is a general problem with all operating systems. *** The host is still at risk. *** [https://web.archive.org/web/20120905134544/http://brainstorm.ubuntu.com/idea/30050/ Ubuntu Brainstorm Idea #30050: Secure Network Time Synchronization] *** [https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%23687166 Debian Bug Report ntp: NTP security vulnerability because not using authentication by default] *** [https://bugs.launchpad.net/ubuntu/+source/ntp/+bug/1039420 Ubuntu Bug Report NTP security vulnerability because not using authentication by default] ** Manual workaround: Check your clock manually and read [[Other Operating Systems#About_Ubuntu|About Ubuntu]] (stale mirror attack). ([https://bugs.launchpad.net/launchpad/+bug/716535 Bug #716535: Please support Valid-Until in release files for security.ubuntu.com]) * '''Attack 3''' gets defeated, {{project_name_short}} adds additional security. * '''Attack 4''' gets defeated, {{project_name_short}} adds additional security. * '''Attack 5''' is a general Tor problem, which can not be solved by {{project_name_short}} and which is unsolved in other projects as well. Since host, {{project_name_gateway_short}} and {{project_name_workstation_short}} time all differ, at least this attack becomes harder against {{project_name_short}}. When the user powers on {{project_name_gateway_short}} and the host time is too much off, it will not be able to connect to the Tor network. It is advised, when powering on {{project_name_gateway_short}}, to check that the host time is no more than 1 hour in past or more than 3 hour in future, otherwise Tor will be unable to establish circuits. https://lists.torproject.org/pipermail/tor-talk/2012-February/023264.html An adversary tampering with the user's clock, while the user doesn't recognize that, can't do any more damage to {{project_name_short}} than he could do to Tor Browser. Worst case is a denial of service for Tor. On the other hand, an adversary capable of actively tampering with the traffic between the user and its entry guard or bridge poses much bigger risks to Tor in general. General Tor problems, Tor is known to be broken against many active attacks. This can not be solved by {{project_name_short}}. When an adversary is capable of running active attacks, tampering with the time leading into a denial of service is the least of the worries. The adversary could also disrupt the service easier. And as for active attacking in general, there are other attacks which are easier to deploy and which pose a greater danger. Not a {{project_name_short}} specific problem. The reason for running TimeSync on {{project_name_gateway_short}}, is that onion services can only be accessed if the clock is no more than 30 minutes slow or fast. https://gitlab.torproject.org/legacy/trac/-/issues/3582#comment:3 Running TimeSync ensures, that {{project_name_gateway_short}} clock is reasonably accurate. {{Anchor|sclockadj2}} = External Clock = This topic is still under research. Help is welcome. It might make sense to add an external clock, such as a GPS, or even better an atomic clock. (Can we get an atomic USB clock?) This clock should be added to the host and/or {{project_name_gateway_short}} and/or {{project_name_workstation_short}}? Open question: would the GPS/atomic clock be too accurate and would that make {{project_name_short}} more fingerprintable? = Discarded Options = == NTP == {{Anchor|NTP authentication (autokey) is insecure}} * unauthenticated by default * NTP insecure ** https://web.archive.org/web/20200209084816/https://gist.github.com/CHEF-KOCH/12976cf15012d64b8fd2 ** https://blog.hboeck.de/archives/863-Dont-update-NTP-stop-using-it.html * NTP authentication (autokey): ** info: https://datatracker.ietf.org/doc/html/draft-ietf-ntp-network-time-security-00 ** insecure:
Origin Timestamp (org): Time at the client when the request departed for the server, in NTP timestamp format.Credits: Thanks to [https://security.stackexchange.com/users/4564/dfc dfc] for [https://security.stackexchange.com/a/67142/54240 the answer on security.se]. * does not work over Tor, because NTP uses UDP, while the Tor network does not support UDP * [https://www.ntp.org/ntpfaq/NTP-s-algo.htm Quote]:
For example standard Linux adjusts the time with a rate of 0.5ms per second.** 500000 ns = 0.5 ms = 0.0005 s ** 1 day = 86400 s 60 s * 60 m * 24 h ** NTP can adjust the clock 43.2 s per 1 day. ** Or 1296 s (= 21.6 m) per 30 days. ** Or 15768 s (= 262.8 m) (=4.38 h) per 365 days. (4.38 h per year) == tlsdate == https://github.com/ioerror/tlsdate Pros: * uses seccomp *
valid-after=2014-07-31 21:00:00 valid-until=2014-08-01 00:00:00This is simply {{Code2|/bin/date}}.
Current time is 2014-07-31 22:44:02Less magic.
Current time is in valid Tor rangeLess magic, but maybe useful.
Current time is not in valid Tor range, setting to middle of this range: [2014-07-31 22:30:00]{{Code2|anondate}} can do this by parsing Tor's verified consensus file {{Code2|/var/lib/cached-microdesc-consensus}} or by parsing {{Code2|/var/lib/tor/unverified-microdesc-consensus}}. ===== Tor Consensus Download and Verification Conditions ===== Under which conditions Tor is not able to verify the Tor consensus file? 1) If it has been tampered with by a man-in-the-middle. 2) For clocks that are more than 30 days in the past or 2 days in the future, Tor will not even be able to download a consensus. In this case anondate can parse Tor's log and report the authority's cert's valid-after date. Source, source code comment in tordate: https://gitlab.tails.boum.org/tails/tails/-/blob/master/config/chroot_local-includes/etc/NetworkManager/dispatcher.d/20-time.sh
# Since Tor 0.2.3.x Tor doesn't download a consensus for # clocks that are more than 30 days in the past or 2 days in # the future. For such clock skews we set the time to the # authority's cert's valid-after date.
anondate --tor-cert-valid-after
Jun 16 00:00:00 2014 GMT===== Open Questions ===== * Is the authority's cert's valid-after date signed/verified/built-into-Tor or can it be tampered with by a man-in-the-middle attack? * When clock is more than 1 hour in past or more than 3 hour in future, Tor will be unable to establish circuits? https://lists.torproject.org/pipermail/tor-talk/2012-February/023264.html ===== Required Clock Accuracy for Onion Services Accessibility ===== ====== Gateway ====== Generally, computer running Tor ({{project_name_gateway_short}}):
live consensus
definition, quote [https://github.com/torproject/torspec/blob/master/dir-spec.txt Tor Tor directory protocol]:
A network-status document is "live" if the time in its valid-after field has passed, and the time in its valid-until field has not passed.
reasonably live consensus
definition, quote Tor Tor directory protocol:
A reasonably live consensus is one that expired less than 24 hours ago.How accurate has the clock to be so onion services can be accessed? https://gitlab.torproject.org/legacy/trac/-/issues/3460 Due to issue [https://forums.whonix.org/t/most-onions-down-due-to-a-denial-of-service-attack-on-the-tor-network/10979 Most Onions Down due to a Denial of Service Attack on the Tor Network] this question received attention. Previously a
live consensus
was required. From Tor 0.4.5.3
and above only a reasonably live consensus
will be required.
====== Workstation ======
Generally, computer running applications (such as curl or sdwdate) connection to onions ({{project_name_workstation_short}}):
Applications running on a separate computer/VM ({{project_name_workstation_short}}) can establish onion connections irrespective of ultra slow or ultra fast system clock on that computer. That is as Tor on a separate computer/VM is functional, which however requires a correct clock as described above.
====== Summary ======
* {{project_name_gateway_short}}: Clock need to be correct enough to be able to reach onions.
* {{project_name_workstation_short}}: No clock correctness requirements for ability of reaching onions.
===== Reasons for relying solely on anondate for time setting =====
* Does not require [armadev: oh. i think that would be horrible. hundreds of thousands of users doing that could overwhelm the directory authorities.===== Reasons against relying solely on anondate for time setting ===== * Provides only rough time. ** [[Fingerprint#For_the_websites_that_you_are_visiting|web fingerprint]] would differ from most other Tor users. ** Would cause lots of support requests complaining about skewed clocks. ** Might trouble onion services (such as hidden web servers) that need to show time to clients? ** Might trouble people attempting to [[I2P|tunnel I2P through Tor]]? ** Might cause other (gpg) verification issues? *** Debian updater APT refuses to use sources which are not yet valid. I.e. source with a signed valid-until field later than the local system clock. * Fingerprinting issues at ISP level: ** In situation, where the clock is that much off, that Tor cannot establish circuits, setting time using anondate required, restart of Tor required: *** As per [[Comparison with Others#Fingerprint]], quoted from the [https://tails.boum.org/contribute/design/Time_syncing/#index5h1 Tails Design about Time syncing]: "Our initial time guess based on the Tor consensus is probably easier to fingerprint, though: a fresh Tor is started, and restarted again right after the consensus has been downloaded." ** Might not matter. See also [[Fingerprint#ISP_or_Local_Network_Administrators|Network Fingerprint]]. *** Related: [[Comparison with Others#Network Time related]] *
Currently we use tordate to set the initial clock. It is very messy and error prone, so we desperately need a robust replacement.* Vulnerable to ISP level man-in-the-middle attacks: ** [https://tails.boum.org/contribute/design/Time_syncing/ Tails Design: Time Syncing] Quote:
First, replaying a consensus older than one week or so results in preventing access to the Tor network, and that's all, because onion keys will be wrong.*** In a situation where an adversary is replaying a more than ~7 days old consensus: **** anondate could report a clock that is more than ~7 days slow. With a system clock that is that slow, Tor would no longer be able to establish circuits. But there are multiple reasons why Tor may not be able to establish circuits. So anondate could only guess, that the clock reported in Tor consensus is more than ~7 days slow, but not know with certainty. *** In a situation where an adversary is replaying an up to ~7 days old consensus: **** anondate could report a clock that is up to ~7 days slow and Tor would still be able to create circuits. **** With Tor as is at the moment, anondate cannot even in principle provide a more accurate time guess than a clock that is up to ~7 days slow. **** Using an up to ~7 days old consensus, is most likely something we really should avoid? ** Therefore vulnerable to Attack 3 as per [[#Attacks]]. ===== Conclusions ===== * Relying solely on anondate for time setting is probably a bad idea. * Tor consensus time is used as a [[Sdwdate#Tor_Consensus_Time_Sanity_Check|sdwdate Tor Consensus Time Sanity Check]]. * Rough time fix. ** If clock is too much off so sdwdate cannot fix it, use anondate to get a rough time fix, then let sdwdate do the rest. ===== Why not use tordate by Tails instead of reinventing the wheel with anondate? ===== * Because Tails code is highly Tails specific. ** Depending on non-persistent Tor data dir. ** Entangled with Tails specific gui notifications. ** Entangled into the Tails specific boot process with other scripts. ** Not a clean abstraction of "tell me what Tor's log / Tor's consensus thinks about date/time". ** Quote: "Currently we use tordate to set the initial clock. It is very messy and error prone, so we desperately need a robust replacement." https://gitlab.tails.boum.org/tails/tails/-/issues/5774 ===== Random Stuff ===== * [https://web.archive.org/web/20160629091629/https://mailman.boum.org/pipermail/tails-dev/2012-January/000822.html tails-dev mailing list: tordate: why is it safe to set time from unverified-consensus?] ** String parsing a unverified consensus using anondate is more risky [hitting hypothetical vulnerabilities in grep] than string parsing a verified Tor consensus. * Tor consensus is in some cases downloaded from Tor directory authorities and in some cases from Tor directory mirrors. The latter should not be trusted as much as the former. * https://github.com/torproject/torspec/blob/main/proposals/149-using-netinfo-data.txt {{Anchor|Status of this idea}} ===== Tor Certificate Lifetime =====
certificate lifetime
Certificate not yet valid. Either their clock is set wrong, or your clock is wrong. (certificate lifetime runs from Aug 27 00:00:00 2020 GMT through Aug 27 00:00:00 2021 GMT. Your time is Jan 09 07:33:33 2000 UTC.){{CodeSelect|code= sudo anondate --tor-cert-valid-after }}
Aug 27 00:00:00 2020 GMTMight be related to the following. Quote [https://github.com/torproject/torspec/blob/master/dir-spec.txt Tor Tor directory protocol]:
Every authority has a very-secret, long-term "Authority Identity Key". This is stored encrypted and/or offline, and is used to sign "key certificate" documents. Every key certificate contains a medium-term (3-12 months) "authority signing key", that is used by the authority to sign other directory information. (Note that the authority identity key is distinct from the router identity key that the authority uses in its role as an ordinary router.)While Authority Identity Key might be hardcoded in Tor, the certificate lifetime is likely not. Otherwise Debian (old)stable would have to ship yearly upgrades to upgrade the "Tor directory authority certificate start date" which never happens. Therefore
certificate lifetime
should not be trusted since it could be stale.
Tor Certificate Lifetime likely has a digital software signature which gets verified by Tor. It's however not a trustworthy source of time. Vulnerable to replay attacks. Could be one year or older. That's because to verify its freshness, Tor requires a correct clock. For time synchronization purposes however the clock is assumed to be incorrect. What however could be trusted that at least that time has already come. It's not a far future date because then Tor directory authorities wouldn't have signed a Tor certificate with that lifetime yet.
Related source code: https://src-ref.docs.torproject.org/tor/x509__openssl_8c.html#adcb9e22c87cb9ba135f6edf3e13386b4
Related ticket: https://gitlab.torproject.org/legacy/trac/-/issues/4370
===== Tor Consensus Issues =====
[https://lists.torproject.org/pipermail/tor-talk/2011-January/008551.html Quote] Roger Dingledine:
Whether this is a good idea depends on where you got the consensus. If you connect to a Tor directory mirror and it hands you a consensus from last month, and you set your clock based on it, then you've opened yourself up to exactly the attack that Tor is trying to defend against.Problem is, nowadays Tor in most cases doesn't download from Tor directory authorities anymore. And we ought to not download the Tor consensus exclusively from Tor directory authorities. Source: https://forums.whonix.org/t/tor-dev-mailinglist-proposal/489/10
https://forums.whonix.org/t/tor-dev-mailinglist-proposal/489/print ===== Fixing Time based on Tor Consensus ===== Future Implementation consideration. This could be how time syncing is performed when {{project_name_short}} starts: Credits: This is a rewrite of [https://tails.boum.org/contribute/design/Time_syncing/ Tails Time Syncing Design] # Start Tor. If Tor is already working, skip to the following anondate steps. # Let Tor fetch the Tor consensus. # (anondate related step) If the time is too badly off, the Tor directory authority certificate may not be valid, so we set the system time to the Tor directory authority certificate start date. (oh. i think that would be horrible. hundreds of thousands of users doing that could overwhelm the directory authorities.
sudo anondate --tor-cert-valid-after
) For example, see above. Which will guarantee that the Tor directory authority certificate will be valid and the Tor consensus (which includes Tor valid-until
date/time) can be downloaded.
# (anondate related step) Wait until Tor can tell us the Tor valid-until
date/time.
# (anondate related step) Set system time to Tor consensus time valid-until
- 1:30
. (In other words: minus 1
and 30
or minus 90
minutes.) (sudo anondate --show-middle-range
)
{{CodeSelect|code=
anondate --show-valid-after
}}
2021-01-09 13:00:00{{CodeSelect|code= sudo anondate --show-valid-until }}
2021-01-09 16:00:00{{CodeSelect|code= anondate --show-middle-range }}
2021-01-09 14:30:00# Wait until the Tor bootstrap process has been completed. # Use sdwdate (which exclusively uses onions as time sources) though Tor to get a more correct system time. A notification in form of [[sdwdate-gui]] shown while the whole process is running. Non-issues: * Use of unverified Tor consensus is not required. * The hardware clock is not affected. Security discussion: sdwdate's approach essentially removes Tor's time skew check, which is used to prevent replay of consensus data. Let's discuss this class of attacks. First, replaying a consensus older than four weeks or so results in preventing access to the Tor network, and that's all, because onion keys will be wrong. An attacker who is in a position to replay a consensus to the user could anyway do this, unrelated to time, so the issue at hand boils down to replaying a consensus not older than four weeks or so. Second, the same type of attacker as above could also try to forge a completely new consensus, which would be unverifiable since the attacker doesn't have access to the authorities' keys. An attacker in that position could do denial-of-service attacks in many other ways, so this doesn't make the situation any worse. Third, things are different depending on if the user is using a bridge or not. If not using a bridge, first boot: * Tor starts without a cached consensus. * The Tor client starts by connecting directly to a [https://gitlab.torproject.org/legacy/trac/-/wikis/doc/FallbackDirectoryMirrors fallback directory mirror] to download the Tor consensus. * Feeding a stale consensus requires the attacker either to break SSL or to control the fallback directory mirror the user's Tor client connects to. * Under these conditions the adversary could feed an up to four weeks stale Tor consensus, which is used until sdwdate has fixed the time. * Not good, but probably a compromise we can make. If using a bridge, first boot: * Tor starts without a cached consensus. * Tor fetches Tor consensus from the bridge. * Feeding a stale consensus requires the attacker either to break SSL or to control the user's bridge. * Under these conditions the adversary could feed an up to four weeks stale Tor consensus, which is used until sdwdate has fixed the time. * Not good, but probably a compromise we can make. If your ISP, Tor entry guard or Tor bridge, can also: * A) set up an onion MitM attack against the sdwdate onion connections, and/or * B) controls onions used by sdwdate as time sources, it can trick you into keep using this old consensus for max. four weeks, which is much worse. A) should be extremely unlikely. A successful MitM against a Tor onion connection have never been reported. While Tor onions servers might be vulnerable to various de-anonymization attacks, this is a different topic, this affects only the anonymity of the onion server. The client, visitor (here user's machine using sdwdate) does not have to worry about this. Also does not affect the encryption/authentication of the connection. No reports of breaking onion encryption/authentication where known at time of writing. If this was possible, this would be catastrophic anyhow. This wouldn't make the situation any worse. B) should also be very unlikely. Onion servers targeting specific users seems very unlikely since users connect anonymously using Tor to an onion server. An attack against all users is also very unlikely since sdwdate is distributed (uses median of 3 onion time sources), randomly chosen from sdwdate time sources list and such an attack would be easy to notice, probably reported by users and in response developers would remove these sdwdate time sources. In any case it should be better than using unauthenticated NTP. ===== Tor Consensus Time Setting Method Security Considerations ===== User local system clock being much skewed is a big issue because: *
a)
Stands out in javascript snooping scripts (Even if Tor Browser fixed that, other applications could leak it.)
* b)
Prevents Tor consensus from being downloaded leading to broken Tor connectivity.
* c)
Other issues discussed on top of this page, [[Time Attacks]].
It depends on the start conditions. Seems really complex. The user's clock is either:
* [C]
: correct
* [D]
: incorrect
The Tor directory mirror (just normal relays) is either sending the user a Tor consensus that is:
* [E]
: fresh
* [D]
: legitimate (bug) stale
* [F]
: malicious (targeted attack) stale
* [G]
: invalid
Now these are quite a few cases to combine and consider. [G]
we can ignore. [D]
and [F]
can be regarded as approximately the same issue.
user clock slow [D]
+ stale Tor consensus [F]
: user would remain on fake Tor network
user clock correct [C]
+ stale Tor consensus [F]
: anondate would introduce a time skew. Not fix one. The user's system clock would be set to the past because the stale Tor consensus told anondate so. The worst could be prevented with a hardcoded minimum date as a safeguard but it's still a security compromise to make.
user clock slow [D]
+ fresh Tor consensus [E]
: In this case anondate would fix the connectivity/usability issue, fix a) and b).
Then it also depends on how slow the user's clock is.
* [H]
Less than 24 hours slow clock or
* [I]
More than 24 hours slow clock.
Therefore:
* [H]
+ a)
: issue
* [I]
+ a)
: no issue since no connection
===== Issues =====
The issue with looking at Tor consensus time is that after power off for a few hours (>= ~3
hours) Tor starts necessarily with a stale Tor consensus. When querying Tor consensus time (using anondate-get
or otherwise), from the perspective of anondate-get
the clock is fast, because Tor consensus is stale because Tor hasn't downloaded a newer Tor consensus yet.
This happened up to {{project_name_short}} 16.0.3.1 after the gateway VM was offline for a few hours:
sudo anondate-get /usr/sbin/anondate-get: INFO: 100% Tor bootstrap, ok. /usr/sbin/anondate-get: INFO: tor_circuit_established_check.py, ok. /usr/sbin/anondate-get: INFO: Tor circuit already established, ok. /usr/sbin/anondate-get: WARNING: local system time is NOT with valid time range. (valid_after: 2021-05-25 11:00:00 | middle_range: 2021-05-25 12:30:00 | valid_until: 2021-05-25 14:00:00) /usr/sbin/anondate-get: INFO: middle_range: '2021-05-25 12:30:00' /usr/sbin/anondate-get: INFO: time_result later than minimum-unixtime-show, ok. 2021-05-25 12:30:00 /usr/sbin/anondate-get: END: Exiting with exit_code '0' indicating 'Showed Tor consensus time middle range.'.
/usr/lib/helper-scripts/onion-time-pre-script: Start. Static Time Sanity Check: Within minimum time 'Sun Jan 17 00:00:00 UTC 2021' and expiration timestamp 'Tue May 17 10:00:00 UTC 2033', ok. Tor reports: NOTICE BOOTSTRAP PROGRESS=95 TAG=circuit_create SUMMARY="Establishing a Tor circuit" Tor circuit: not established. Tor Consensus Time Sanity Check: The clock might be too fast. Clock is faster than consensus/valid-until 2021-05-25 14:00:00. /usr/lib/helper-scripts/onion-time-pre-script: END: Exiting with exit_code '2' indicating 'wait, show busy icon and retry.'.
The clock might be too fast.
is because while the hardware clock was reasonable correct, Tor consensus time was still stale since Tor didn't download a new Tor consensus yet.
After approximately two minutes after VM start (Tor finished downloading a newer Tor consensus):
sudo anondate-get /usr/sbin/anondate-get: INFO: 100% Tor bootstrap, ok. /usr/sbin/anondate-get: INFO: tor_circuit_established_check.py, ok. /usr/sbin/anondate-get: INFO: Tor circuit already established, ok. /usr/sbin/anondate-get: INFO: local system time is already within valid range, ok. (valid_after: 2021-05-25 18:00:00 | middle_range: 2021-05-25 19:30:00 | valid_until: 2021-05-25 21:00:00) /usr/sbin/anondate-get: INFO: time_result later than minimum-unixtime-show, ok. /usr/sbin/anondate-get: INFO: Tor certificate lifetime valid, ok. /usr/sbin/anondate-get: END: Exiting with exit_code '4' indicating 'Setting time using anondate either not possible or not required.'.
Static Time Sanity Check: Within minimum time 'Sun Jan 17 00:00:00 UTC 2021' and expiration timestamp 'Tue May 17 10:00:00 UTC 2033', ok. Tor reports: NOTICE BOOTSTRAP PROGRESS=100 TAG=done SUMMARY="Done" Tor circuit: established. Tor Consensus Time Sanity Check: Clock within consensus parameters consensus/valid-after 2021-05-25 18:00:00 and consensus/valid-until 2021-05-25 21:00:00. Tor already reports circuit established. /usr/lib/helper-scripts/onion-time-pre-script: END: Exiting with exit_code '0' indicating 'success'.Comparison:
valid_after: 2021-05-25 11:00:00 | middle_range: 2021-05-25 12:30:00 | valid_until: 2021-05-25 14:00:00 valid_after: 2021-05-25 18:00:00 | middle_range: 2021-05-25 19:30:00 | valid_until: 2021-05-25 21:00:00Actual time when this happened was:
2021-05-25 18:40:00If sdwdate had set the time to
anondate-get
's initial guess 2021-05-25 12:30:00
(using anondate-set
), Tor connectivity would have been broken. (This issue was experienced indeed in past during experimentation using anondate-set
.)
Tor control protocol has no feature to query "attempting to download a newer Tor consensus done yet?"
Idea:
If hardware clock is faster than valid_until
, delete Tor consensus before Tor starts.
(Easily implemented thanks to systemd units.) Tor would re-download the Tor consensus anyhow. But this might be fingerprintable but then again, being a user of {{project_name_short}} might be fingerprintable anyhow ([https://github.com/Kicksecure/tirdad random ISN] / [[security-misc]] network hardening). Instead of Tor starting with a stale consensus, figuring out it's stale and re-downloading one, it would go straight ahead and download a new one which it has to do anyhow.
Maybe using anondate-set
to fix the clock on Whonix-Gateway only. That might mitigate introducing new fingerprinting issues inside
Whonix-Workstation. And sdwdate in Whonix-Workstation should be functional anyhow as soon as Tor in Whonix-Gateway is functional.
Maybe most issues with broken hardware clocks are these being too slow, and not too fast? Perhaps by only ever using anondate-set
to move the clock into the future but never to the past most if not all security issues can be prevented.
If Tor relays send us a too new Tor consensus, they are in position for denial of service anyhow. Too new is unlikely since for that Tor directory authorities would need to be malicious/compromised. Even if that happens, it would just DOS Tor. Any TLS certificate (debian APT) would be refused if clock is too far in future. Security issues with wrong system time seems to be only with too slow clocks but not with too fast clocks. The latter is at worst a DOS issue.
= Clock Fixing =
Since a few Whonix 16 point releases now.
If Tor is running on the same machine / VM (such as Kicksecure or Whonix-Gateway):
* very slow clocks can be fixed
* very fast clocks cannot be fixed
If Tor is running on another machine / VM (such as Whonix-Workstation):
* very slow clocks can be fixed
* very fast clocks can be fixed
That is because Tor is not running on these machines. Once Tor is functional on Whonix-Gateway, it is easy for sdwdate in Whonix-Workstation to connect to onion time sources despite how far skews the time is.
= Notes =
= Adjusting time slowly using adjtimex/ntp_adjtime =
Under [https://github.com/{{project_name_short}}/sdwdate/pull/4 consideration] is changing the time with sclockadj2. The initial drive for this was that calling clock_settime() in the original sclockadj can result in several thousand entries in systemd's journal per invocation (can be seen with journalctrl -f) on Debian.
sclockadj2 uses adjtimex call in libc (als called ntp_adjtime) which translates to Linux' kernel system call 124. This is a modal interface that is used by `ntpd` to change the system clock. adjtimex supports a mode with "hard" changes to the time, but those generate entries in systemd journal, just like with clock_settime.
The offset mode for adjtimex allows a change of 0.5 seconds per call (used to be ~130 milisec until the 2.6 kernel). The documentation of this call is incomplete, partly resulting from the limited number of clients (ntpd, chronyd) using this interface, but by tracing the kernel internals (linux/kernel/time/ntp.c and /linux/kernel/time/timekeeping.c) one can get a more complete picture, including that modern kernels support a NANO mode easier implementation of smaller adjustments than the older μsecond based interface, without the need to do clock tick adjustment calculations.
Based on this interface and mode bit definitions taken from /usr/include/linux/timex.h (more complete than the counterparts you typically find online) to form a Python based interface via ctypes. Primarily first setting the kernel internals to handle nanoseconds specifications and run in PLL mode. Then using OFFSET to adjust the time.
With this call the kernel is instructed to change the time gradually. You can observe this change by making further calls to adjtimex, this time without setting any values (specified by 0 in the modes bitfield of the structure handed to adjtimex). To handle changes of more than the maximum allowed (±0.5 seconds), you need to invoke a 0.5 second change and observe if the offset has been reduced to 0, then invoke again. Writing a new offset using adjtimex will overwrite any running adjustment process, therefore you have to wait.
By default the kernel uses a decreasing stepsize as the (remaining) offset to handle approaches 0. This can be influenced by the TIMECONST to start with bigger steps, or even reset the stepsize on a regular basis while the kernel is changing the clock according to the remaining offset.
The ntpd can use this offset changing possibility as is but also has a more sophisticated approach, by instructing the kernel about the drift compared to the internal clock.
The sclockadj2 directly uses a nanosecond offset (positive or negative) that instructs the kernel to adjust (looping multiple invocations if the absolute value of the offset > 0.5 seconds. The program has to be run as root in order to tell the kernel to make these changes (querying the status doesn't require this). At the start of this process a PID file is written, which is checked during loops (if running longer than 0.5 s) and will kill any previous invocation of the program. The syntax for the offset invocation is:
sclockadj2 offset [-h] [--constant CONSTANT] [--verbose] [--quiet][--wait] nanoseconds
for changes > 0.5s --wait has to be specified. Increased verbosity can be used to watch the progress of what the kernel is doing with the offset.
This progress can also be seen by invoking the program with the status option. To do so has some instructional value for observing normal `ntpd` behaviour as well. The full options for status:
usage: sclockadj2 status [-h] [--follow] [--set] [--verbose] [--quiet]
[--debug] [--wait]
adjtimex status (--quiet → only offset, --verbose → detail)
optional arguments:
-h, --help show this help message and exit
--follow, -f follow status indefinitely
--set set status explicitly to PLL and NANO
--verbose, -v increase verbosity level
--quiet, -q decrease verbosity level
--debug, -D Debug messages. Don't change date
--wait wait for offset to return to 0
Stopping a previous invocation of sclockadj2 (which might be looping on values > 0.5s), including stopping the internal offset can easily be achieved by calling sclockadj2 offset 0
== Blockchain Time ==
* https://bitcoinmagazine.com/articles/bip-the-end-to-end-encryption-bitcoin-never-had-but-soon-will-1465401187
* https://github.com/bitcoin/bips/blob/master/bip-0150.mediawiki
* https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2019-March/016806.html
* https://en.bitcoin.it/wiki/Block_timestamp
* https://web.archive.org/web/20140213190023/http://james.lab6.com/2012/01/12/bitcoin-285-bytes-that-changed-the-world/
* https://en.bitcoin.it/wiki/API_reference_(JSON-RPC)
* https://twitter.com/_jonasschnelli_/status/1119137870592102400
** A BIP158 based wallet rescans takes less then 5 minutes (back from genesis) on powerful consumer computer.* https://electrum.readthedocs.io/en/latest/faq.html#does-electrum-trust-servers * https://electrum.readthedocs.io/en/latest/faq.html#i-might-run-my-own-server-are-client-server-connections-authenticated * [https://ieeexplore.ieee.org/document/8482304 Blockchain-Based Secure Time Protection Scheme in IoT] * [https://hal.univ-grenoble-alpes.fr/hal-01865259/document Secure Time Synchronization Protocol] == NTS - Network Time Security - Secure NTP == * https://fedoramagazine.org/secure-ntp-with-nts/ * https://weberblog.net/network-time-security-strengths-weaknesses/ * https://weberblog.net/setting-up-nts-secured-ntp-with-ntpsec/ * https://weberblog.net/network-time-security-new-ntp-authentication-mechanism/ **
the time data is not encrypted by NTS – but authenticated.* https://chrony.tuxfamily.org/comparison.html * https://blog.apnic.net/2019/11/08/network-time-security-new-ntp-authentication-mechanism/ * https://www.cloudflare.com/time/ * https://blog.cloudflare.com/secure-time/ * https://blog.cloudflare.com/nts-is-now-rfc/ * https://blog.cloudflare.com/announcing-cfnts/ == roughtime == === roughtime information === * https://datatracker.ietf.org/doc/draft-ietf-ntp-roughtime/ * https://datatracker.ietf.org/doc/draft-ietf-ntp-roughtime/?include_text=1 * https://roughtime.googlesource.com/roughtime * https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=838416 * https://salsa.debian.org/lamby/pkg-roughtime * UDP * independent of TLS CAs (hardcoded keys) * server list: https://github.com/cloudflare/roughtime/blob/master/ecosystem.json * https://int08h.com/post/to-catch-a-lying-timeserver/ * https://int08h.com/post/roughtime-message-anatomy/ * https://roughtime.googlesource.com/roughtime/+/HEAD/ECOSYSTEM.md * https://roughtime.googlesource.com/roughtime/+/HEAD/PROTOCOL.md === roughtime client list === * https://roughtime.googlesource.com/roughtime * https://github.com/cloudflare/roughtime * https://github.com/int08h/roughenough * https://github.com/int08h/roughenough-fuzz * https://github.com/ffledgling/python-roughtime * https://github.com/dansarie/pyroughtime ** https://github.com/dansarie/pyroughtime/issues/3 * https://github.com/Merovius/notary/tree/master/roughtime * https://github.com/nahojkap/craggy * https://github.com/tajchert/securetime * https://github.com/systemd/systemd/issues/12751 * https://github.com/topics/roughtime * https://github.com/bnoordhuis/node-roughtime = Debugging = Useful to run in Qubes dom0.
qvm-run --pass-io {{project_name_gateway_vm}} "date -u" ; date -u= See Also = == Other == * [https://curl.se/docs/security.html List to keep track of curl advisories from the official website. Their descriptions are non-cryptic.] * [[Time Attacks]] * [[sdwdate|sdwdate - Secure Distribiuted Web Date - Homepage]] * [[Dev/sdwdate]] == Previous Discussion == * [https://lists.torproject.org/pipermail/tor-talk/2011-January/008551.html System time in anonymity oriented LiveCDs] * [https://web.archive.org/web/20160629151935/https://mailman.boum.org/pipermail/tails-dev/2014-August/006821.html Tails-dev mailing list - Tails htpdate - why use time information from neutral and foe pools?] * [https://web.archive.org/web/20160629152125/https://mailman.boum.org/pipermail/tails-dev/2013-February/002635.html Tails-dev Endless Data Attack and Defense] == Other Projects == * [https://tails.boum.org/contribute/design/Time_syncing/ Tails Design: Time syncing] * https://docs.google.com/a/chromium.org/document/d/1ylaCHabUIHoKRJQWhBxqQ5Vck270fX7XCWBdiJofHbU/edit == Comparison with Others == [[Comparison with Others#Network Time related|Network Time related]] == Tickets == === Qubes === ==== high priority ==== * [https://phabricator.whonix.org/T389 make sure {{q_project_name_short}} has no access to clocksource=xen] * [https://phabricator.whonix.org/T397 prevent dom0 telling {{q_project_name_short}} VMs the time] ==== normal priority ==== * document [[Advanced_Security_Guide#Spoof_the_Initial_Virtual_Hardware_Clock_Offset|Spoof the Initial Virtual Hardware Clock Offset]] for [[Advanced_Security_Guide#Qubes|Qubes]] * [https://phabricator.whonix.org/T387 {{q_project_name_short}} {{project_name_gateway_short}} as ClockVM] === others === * [https://gitlab.torproject.org/legacy/trac/-/issues/6894 torproject.org #6894 answer network time requests] * [https://tails.boum.org/todo/robust_time_syncing/ Tails Todo: robust time syncing] * https://tails.boum.org/blueprint/robust_time_syncing/ * [https://tails.boum.org/todo/safer_tordate_parameters/ Tails Todo: safer tordate parameters (always use tordate)] * [https://tails.boum.org/todo/bridge_mode_vs_tordate_timeouts/ Tails Todo: bridge mode vs tordate timeouts] * [https://tails.boum.org/todo/when_htp_fails_the_user_should_be_prompted/ Tails Todo: when htp fails the user should be prompted] * [https://github.com/QubesOS/qubes-issues/issues/2342 Qubes: secure time synchronization] * [https://gitlab.torproject.org/legacy/trac/-/issues/16659 Linux TCP Initial Sequence Numbers may aid correlation] * [https://gitlab.torproject.org/legacy/trac/-/issues/8170 get independent from host clock time / insecure NTP] == Clock Correlation Attack == === Attack === prerequisite knowledge: * {{project_name_gateway_short}} [Proxy]VMs and {{project_name_workstation_short}} [App]VM's system time cannot not be obtained by watching traffic at ISP level. * This chapter is not about tracking a single VM across its different Tor exit relays. * The context is anonymity. The significance is deanonymization. * In anonymity we don't just care about about correlations. Also about estimations. Anonymity set reduction. Partitioning users is already a success. Because it may be combined with other guesses. No direct proof is required. From some countries, there are just a few 100 users or less. If there is already a lead by country, then combined with these time related issues, things begin to really matter. * clocksource 'xen' / 'kvmclock' doesn't prevent {{project_name_short}} from using sdwdate. * clocksource 'xen' / 'kvmclock' doesn't prevent each VM having slightly different system time (used by all the applications), so no direct leaks here. * [host | dom0] host time and VM times a very, very similar. At most one second difference. Or less. In [host | dom0], see:
date ; qvm-run --pass-io sys-net dateAttack: * 1) requires a) compromise a {{project_name_workstation_short}} VM and b) observing the ISP network the user is using * 2) read [host | dom0] time using clocksource 'xen' / 'kvmclock' or possibly the wall clock interface * 3) [host | dom0] time will be very similar to NetVM's time (the system where external network connections are made) * 4) correlate {{project_name_workstation_short}} VM with NetVM's time * 5) anonymity set reduction done Notes: No need to compromise multiple VMs. Only one VM, a {{project_name_workstation_short}} VM needs to be compromised. NetVM does not have to be compromised, it leaks in most cases - hard to avoid all cases - any passive ISP level adversary watching traffic can read the clients local clock. It is leaked on many levels, see [[#Local Clock Leaks]]. Threat Model: * {{project_name_workstation_short}} AppVM gets compromised up to local root code execution. Then the attacker uses the local exploit, reads clocksource 'xen' / 'kvmclock'. === Defense === We need to make sure that all of {{project_name_gateway_short}}, {{project_name_workstation_short}}, and NetVM uses slightly different time. Even if {{project_name_workstation_short}} would be compromised, and the attacker gets knowledge of the time of [host | dom0] and sniffs NetVM's time, it would hinder correlation. [host | dom0] and non-anonymous VM's clocks should be as synced, correct and secure as those can be. But those should differ from the clocks within {{project_name_short}} VMs. We need completely isolated virtual time within {{project_name_short}} VMs. https://security.stackexchange.com/questions/106406/how-to-get-a-completely-isolated-virtual-time-using-xen https://lists.xen.org/archives/html/xen-users/2015-11/msg00114.html === wallclock === > The other interface ("wallclock interface") would provide such time, though. And it is not configurable. But not sure if it is used anywhere in Linux by default (probably besides initial system time set). Yes. Must be so. Otherwise with "ticks" alone the VM had no chance to figure out the current time. And this is a roblem, because we don't want the VM to know [host | dom0]'s time. We might be able to solve the wallclock [not pvclock] issue by [[Advanced_Security_Guide#Spoof_the_Initial_Virtual_Hardware_Clock_Offset|Spoofing the Initial Virtual Hardware Clock Offset]]. === Development === Rather than modifying [host | dom0]'s clock, we could perhaps spoof the initial virtual hardware clock offset. It is possible for KVM, as per: https://libvirt.org/formatdomain.html#time-keeping Something like this:
Reading clocksource xen as a [root] user is not easily possible. source: https://lists.xen.org/archives/html/xen-users/2015-08/msg00020.html Would probably require writing a kernel module. * [https://phabricator.whonix.org/T440 set random clock offset for {{q_project_name_short}} VMs using mgmt to prevent clock correlation attacks] * [https://phabricator.whonix.org/T389 make sure {{q_project_name_short}} has no access to clocksource=xen] * https://groups.google.com/g/qubes-devel/c/aN3IOv6JmKw === Sources === * https://groups.google.com/g/qubes-devel/c/aN3IOv6JmKw * Document with general information on various clock interfaces. ** Not very specific to kvm. ** PIT, RTC, APIC, HPET, Offboard Timers, TSC ** https://www.kernel.org/doc/Documentation/virtual/kvm/timekeeping.txt == TSC == Needs more research. Why we should avoid leaking TSC from the host go the VM. Leaking anything related to time from the host into the VM [or from VM to VM] risks cryptographic side channel attacks and should therefore be avoided. Search term: