├── CONTRIBUTING.md ├── COPYING ├── README.md ├── auto-generated-man-pages └── sdwdate.8 ├── changelog.upstream ├── config-test.txt ├── debian ├── changelog ├── control ├── copyright ├── rules ├── sdwdate.install ├── sdwdate.maintscript ├── sdwdate.postinst ├── sdwdate.postrm ├── source │ ├── format │ └── lintian-overrides └── watch ├── etc ├── apparmor.d │ ├── abstractions │ │ └── url_to_unixtime │ ├── usr.bin.sdwdate │ └── usr.bin.url_to_unixtime ├── privleap │ └── conf.d │ │ └── sdwdate.conf ├── qubes │ ├── suspend-post.d │ │ └── 30_sdwdate.sh │ └── suspend-pre.d │ │ └── 30_sdwdate.sh ├── rsyslog.d │ └── sdwdate.conf ├── sdwdate.d │ ├── 30_default.conf │ └── qubes-sync-time-disabled-by-sdwdate.marker └── sudoers.d │ └── sdwdate ├── make-helper-overrides.bsh ├── man └── sdwdate.8.ronn └── usr ├── bin ├── sdwdate ├── sdwdate-log-viewer └── url_to_unixtime ├── lib ├── python3 │ └── dist-packages │ │ └── sdwdate │ │ ├── __init__.py │ │ ├── config.py │ │ ├── misc.py │ │ ├── proxy_settings.py │ │ ├── remote_times.py │ │ ├── sdwdate.py │ │ └── timesanitycheck.py ├── qubes-bind-dirs.d │ └── 40_sdwdate.conf ├── systemd │ └── system │ │ ├── qubes-sync-time.service.d │ │ └── 40_sdwdate.conf │ │ ├── sdwdate-pre.service │ │ ├── sdwdate-start-anondate-set-file-watcher.service │ │ ├── sdwdate.service │ │ └── systemd-timesyncd.service.d │ │ └── 40_sdwdate.conf └── tmpfiles.d │ └── sdwdate.conf ├── libexec ├── config-test └── sdwdate │ ├── sdwdate │ ├── sdwdate-pre │ ├── sdwdate-start-anondate-set-file-watcher │ ├── sdwdate-test │ ├── suspend-post │ └── suspend-pre ├── sbin └── sdwdate-clock-jump ├── share ├── sdwdate │ ├── get-time-from-servers-test │ ├── onion-list-all │ ├── onion-test-confirm │ ├── onion-test-https-manual │ ├── onion-tester │ ├── test-clock-fast │ └── test-clock-slow └── translations │ └── sdwdate.yaml └── src └── sdwdate └── sclockadj.c /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Conditions for Contributions to Whonix 2 | 3 | By contributing to Whonix, you acknowledge that you have read, understood and agreed to our Privacy Policy, Cookie Policy, Terms of Service, and E-Sign Consent. 4 | 5 | https://www.whonix.org/wiki/Privacy_Policy 6 | 7 | https://www.whonix.org/wiki/Cookie_Policy 8 | 9 | https://www.whonix.org/wiki/Terms_of_Service 10 | 11 | https://www.whonix.org/wiki/E-Sign_Consent 12 | 13 | Conditions for Contributions to Whonix are not part of Whonix's license. 14 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ 2 | 3 | Files: * 4 | Copyright: 2012 - 2025 ENCRYPTED SUPPORT LLC 5 | License: AGPL-3+ 6 | 7 | License: AGPL-3+ 8 | GNU AFFERO GENERAL PUBLIC LICENSE 9 | Version 3, 19 November 2007 10 | . 11 | Copyright (C) 2007 Free Software Foundation, Inc. 12 | Everyone is permitted to copy and distribute verbatim copies 13 | of this license document, but changing it is not allowed. 14 | . 15 | Preamble 16 | . 17 | The GNU Affero General Public License is a free, copyleft license for 18 | software and other kinds of works, specifically designed to ensure 19 | cooperation with the community in the case of network server software. 20 | . 21 | The licenses for most software and other practical works are designed 22 | to take away your freedom to share and change the works. By contrast, 23 | our General Public Licenses are intended to guarantee your freedom to 24 | share and change all versions of a program--to make sure it remains free 25 | software for all its users. 26 | . 27 | When we speak of free software, we are referring to freedom, not 28 | price. Our General Public Licenses are designed to make sure that you 29 | have the freedom to distribute copies of free software (and charge for 30 | them if you wish), that you receive source code or can get it if you 31 | want it, that you can change the software or use pieces of it in new 32 | free programs, and that you know you can do these things. 33 | . 34 | Developers that use our General Public Licenses protect your rights 35 | with two steps: (1) assert copyright on the software, and (2) offer 36 | you this License which gives you legal permission to copy, distribute 37 | and/or modify the software. 38 | . 39 | A secondary benefit of defending all users' freedom is that 40 | improvements made in alternate versions of the program, if they 41 | receive widespread use, become available for other developers to 42 | incorporate. Many developers of free software are heartened and 43 | encouraged by the resulting cooperation. However, in the case of 44 | software used on network servers, this result may fail to come about. 45 | The GNU General Public License permits making a modified version and 46 | letting the public access it on a server without ever releasing its 47 | source code to the public. 48 | . 49 | The GNU Affero General Public License is designed specifically to 50 | ensure that, in such cases, the modified source code becomes available 51 | to the community. It requires the operator of a network server to 52 | provide the source code of the modified version running there to the 53 | users of that server. Therefore, public use of a modified version, on 54 | a publicly accessible server, gives the public access to the source 55 | code of the modified version. 56 | . 57 | An older license, called the Affero General Public License and 58 | published by Affero, was designed to accomplish similar goals. This is 59 | a different license, not a version of the Affero GPL, but Affero has 60 | released a new version of the Affero GPL which permits relicensing under 61 | this license. 62 | . 63 | The precise terms and conditions for copying, distribution and 64 | modification follow. 65 | . 66 | TERMS AND CONDITIONS 67 | . 68 | 0. Definitions. 69 | . 70 | "This License" refers to version 3 of the GNU Affero General Public License. 71 | . 72 | "Copyright" also means copyright-like laws that apply to other kinds of 73 | works, such as semiconductor masks. 74 | . 75 | "The Program" refers to any copyrightable work licensed under this 76 | License. Each licensee is addressed as "you". "Licensees" and 77 | "recipients" may be individuals or organizations. 78 | . 79 | To "modify" a work means to copy from or adapt all or part of the work 80 | in a fashion requiring copyright permission, other than the making of an 81 | exact copy. The resulting work is called a "modified version" of the 82 | earlier work or a work "based on" the earlier work. 83 | . 84 | A "covered work" means either the unmodified Program or a work based 85 | on the Program. 86 | . 87 | To "propagate" a work means to do anything with it that, without 88 | permission, would make you directly or secondarily liable for 89 | infringement under applicable copyright law, except executing it on a 90 | computer or modifying a private copy. Propagation includes copying, 91 | distribution (with or without modification), making available to the 92 | public, and in some countries other activities as well. 93 | . 94 | To "convey" a work means any kind of propagation that enables other 95 | parties to make or receive copies. Mere interaction with a user through 96 | a computer network, with no transfer of a copy, is not conveying. 97 | . 98 | An interactive user interface displays "Appropriate Legal Notices" 99 | to the extent that it includes a convenient and prominently visible 100 | feature that (1) displays an appropriate copyright notice, and (2) 101 | tells the user that there is no warranty for the work (except to the 102 | extent that warranties are provided), that licensees may convey the 103 | work under this License, and how to view a copy of this License. If 104 | the interface presents a list of user commands or options, such as a 105 | menu, a prominent item in the list meets this criterion. 106 | . 107 | 1. Source Code. 108 | . 109 | The "source code" for a work means the preferred form of the work 110 | for making modifications to it. "Object code" means any non-source 111 | form of a work. 112 | . 113 | A "Standard Interface" means an interface that either is an official 114 | standard defined by a recognized standards body, or, in the case of 115 | interfaces specified for a particular programming language, one that 116 | is widely used among developers working in that language. 117 | . 118 | The "System Libraries" of an executable work include anything, other 119 | than the work as a whole, that (a) is included in the normal form of 120 | packaging a Major Component, but which is not part of that Major 121 | Component, and (b) serves only to enable use of the work with that 122 | Major Component, or to implement a Standard Interface for which an 123 | implementation is available to the public in source code form. A 124 | "Major Component", in this context, means a major essential component 125 | (kernel, window system, and so on) of the specific operating system 126 | (if any) on which the executable work runs, or a compiler used to 127 | produce the work, or an object code interpreter used to run it. 128 | . 129 | The "Corresponding Source" for a work in object code form means all 130 | the source code needed to generate, install, and (for an executable 131 | work) run the object code and to modify the work, including scripts to 132 | control those activities. However, it does not include the work's 133 | System Libraries, or general-purpose tools or generally available free 134 | programs which are used unmodified in performing those activities but 135 | which are not part of the work. For example, Corresponding Source 136 | includes interface definition files associated with source files for 137 | the work, and the source code for shared libraries and dynamically 138 | linked subprograms that the work is specifically designed to require, 139 | such as by intimate data communication or control flow between those 140 | subprograms and other parts of the work. 141 | . 142 | The Corresponding Source need not include anything that users 143 | can regenerate automatically from other parts of the Corresponding 144 | Source. 145 | . 146 | The Corresponding Source for a work in source code form is that 147 | same work. 148 | . 149 | 2. Basic Permissions. 150 | . 151 | All rights granted under this License are granted for the term of 152 | copyright on the Program, and are irrevocable provided the stated 153 | conditions are met. This License explicitly affirms your unlimited 154 | permission to run the unmodified Program. The output from running a 155 | covered work is covered by this License only if the output, given its 156 | content, constitutes a covered work. This License acknowledges your 157 | rights of fair use or other equivalent, as provided by copyright law. 158 | . 159 | You may make, run and propagate covered works that you do not 160 | convey, without conditions so long as your license otherwise remains 161 | in force. You may convey covered works to others for the sole purpose 162 | of having them make modifications exclusively for you, or provide you 163 | with facilities for running those works, provided that you comply with 164 | the terms of this License in conveying all material for which you do 165 | not control copyright. Those thus making or running the covered works 166 | for you must do so exclusively on your behalf, under your direction 167 | and control, on terms that prohibit them from making any copies of 168 | your copyrighted material outside their relationship with you. 169 | . 170 | Conveying under any other circumstances is permitted solely under 171 | the conditions stated below. Sublicensing is not allowed; section 10 172 | makes it unnecessary. 173 | . 174 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 175 | . 176 | No covered work shall be deemed part of an effective technological 177 | measure under any applicable law fulfilling obligations under article 178 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 179 | similar laws prohibiting or restricting circumvention of such 180 | measures. 181 | . 182 | When you convey a covered work, you waive any legal power to forbid 183 | circumvention of technological measures to the extent such circumvention 184 | is effected by exercising rights under this License with respect to 185 | the covered work, and you disclaim any intention to limit operation or 186 | modification of the work as a means of enforcing, against the work's 187 | users, your or third parties' legal rights to forbid circumvention of 188 | technological measures. 189 | . 190 | 4. Conveying Verbatim Copies. 191 | . 192 | You may convey verbatim copies of the Program's source code as you 193 | receive it, in any medium, provided that you conspicuously and 194 | appropriately publish on each copy an appropriate copyright notice; 195 | keep intact all notices stating that this License and any 196 | non-permissive terms added in accord with section 7 apply to the code; 197 | keep intact all notices of the absence of any warranty; and give all 198 | recipients a copy of this License along with the Program. 199 | . 200 | You may charge any price or no price for each copy that you convey, 201 | and you may offer support or warranty protection for a fee. 202 | . 203 | 5. Conveying Modified Source Versions. 204 | . 205 | You may convey a work based on the Program, or the modifications to 206 | produce it from the Program, in the form of source code under the 207 | terms of section 4, provided that you also meet all of these conditions: 208 | . 209 | a) The work must carry prominent notices stating that you modified 210 | it, and giving a relevant date. 211 | . 212 | b) The work must carry prominent notices stating that it is 213 | released under this License and any conditions added under section 214 | 7. This requirement modifies the requirement in section 4 to 215 | "keep intact all notices". 216 | . 217 | c) You must license the entire work, as a whole, under this 218 | License to anyone who comes into possession of a copy. This 219 | License will therefore apply, along with any applicable section 7 220 | additional terms, to the whole of the work, and all its parts, 221 | regardless of how they are packaged. This License gives no 222 | permission to license the work in any other way, but it does not 223 | invalidate such permission if you have separately received it. 224 | . 225 | d) If the work has interactive user interfaces, each must display 226 | Appropriate Legal Notices; however, if the Program has interactive 227 | interfaces that do not display Appropriate Legal Notices, your 228 | work need not make them do so. 229 | . 230 | A compilation of a covered work with other separate and independent 231 | works, which are not by their nature extensions of the covered work, 232 | and which are not combined with it such as to form a larger program, 233 | in or on a volume of a storage or distribution medium, is called an 234 | "aggregate" if the compilation and its resulting copyright are not 235 | used to limit the access or legal rights of the compilation's users 236 | beyond what the individual works permit. Inclusion of a covered work 237 | in an aggregate does not cause this License to apply to the other 238 | parts of the aggregate. 239 | . 240 | 6. Conveying Non-Source Forms. 241 | . 242 | You may convey a covered work in object code form under the terms 243 | of sections 4 and 5, provided that you also convey the 244 | machine-readable Corresponding Source under the terms of this License, 245 | in one of these ways: 246 | . 247 | a) Convey the object code in, or embodied in, a physical product 248 | (including a physical distribution medium), accompanied by the 249 | Corresponding Source fixed on a durable physical medium 250 | customarily used for software interchange. 251 | . 252 | b) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by a 254 | written offer, valid for at least three years and valid for as 255 | long as you offer spare parts or customer support for that product 256 | model, to give anyone who possesses the object code either (1) a 257 | copy of the Corresponding Source for all the software in the 258 | product that is covered by this License, on a durable physical 259 | medium customarily used for software interchange, for a price no 260 | more than your reasonable cost of physically performing this 261 | conveying of source, or (2) access to copy the 262 | Corresponding Source from a network server at no charge. 263 | . 264 | c) Convey individual copies of the object code with a copy of the 265 | written offer to provide the Corresponding Source. This 266 | alternative is allowed only occasionally and noncommercially, and 267 | only if you received the object code with such an offer, in accord 268 | with subsection 6b. 269 | . 270 | d) Convey the object code by offering access from a designated 271 | place (gratis or for a charge), and offer equivalent access to the 272 | Corresponding Source in the same way through the same place at no 273 | further charge. You need not require recipients to copy the 274 | Corresponding Source along with the object code. If the place to 275 | copy the object code is a network server, the Corresponding Source 276 | may be on a different server (operated by you or a third party) 277 | that supports equivalent copying facilities, provided you maintain 278 | clear directions next to the object code saying where to find the 279 | Corresponding Source. Regardless of what server hosts the 280 | Corresponding Source, you remain obligated to ensure that it is 281 | available for as long as needed to satisfy these requirements. 282 | . 283 | e) Convey the object code using peer-to-peer transmission, provided 284 | you inform other peers where the object code and Corresponding 285 | Source of the work are being offered to the general public at no 286 | charge under subsection 6d. 287 | . 288 | A separable portion of the object code, whose source code is excluded 289 | from the Corresponding Source as a System Library, need not be 290 | included in conveying the object code work. 291 | . 292 | A "User Product" is either (1) a "consumer product", which means any 293 | tangible personal property which is normally used for personal, family, 294 | or household purposes, or (2) anything designed or sold for incorporation 295 | into a dwelling. In determining whether a product is a consumer product, 296 | doubtful cases shall be resolved in favor of coverage. For a particular 297 | product received by a particular user, "normally used" refers to a 298 | typical or common use of that class of product, regardless of the status 299 | of the particular user or of the way in which the particular user 300 | actually uses, or expects or is expected to use, the product. A product 301 | is a consumer product regardless of whether the product has substantial 302 | commercial, industrial or non-consumer uses, unless such uses represent 303 | the only significant mode of use of the product. 304 | . 305 | "Installation Information" for a User Product means any methods, 306 | procedures, authorization keys, or other information required to install 307 | and execute modified versions of a covered work in that User Product from 308 | a modified version of its Corresponding Source. The information must 309 | suffice to ensure that the continued functioning of the modified object 310 | code is in no case prevented or interfered with solely because 311 | modification has been made. 312 | . 313 | If you convey an object code work under this section in, or with, or 314 | specifically for use in, a User Product, and the conveying occurs as 315 | part of a transaction in which the right of possession and use of the 316 | User Product is transferred to the recipient in perpetuity or for a 317 | fixed term (regardless of how the transaction is characterized), the 318 | Corresponding Source conveyed under this section must be accompanied 319 | by the Installation Information. But this requirement does not apply 320 | if neither you nor any third party retains the ability to install 321 | modified object code on the User Product (for example, the work has 322 | been installed in ROM). 323 | . 324 | The requirement to provide Installation Information does not include a 325 | requirement to continue to provide support service, warranty, or updates 326 | for a work that has been modified or installed by the recipient, or for 327 | the User Product in which it has been modified or installed. Access to a 328 | network may be denied when the modification itself materially and 329 | adversely affects the operation of the network or violates the rules and 330 | protocols for communication across the network. 331 | . 332 | Corresponding Source conveyed, and Installation Information provided, 333 | in accord with this section must be in a format that is publicly 334 | documented (and with an implementation available to the public in 335 | source code form), and must require no special password or key for 336 | unpacking, reading or copying. 337 | . 338 | 7. Additional Terms. 339 | . 340 | "Additional permissions" are terms that supplement the terms of this 341 | License by making exceptions from one or more of its conditions. 342 | Additional permissions that are applicable to the entire Program shall 343 | be treated as though they were included in this License, to the extent 344 | that they are valid under applicable law. If additional permissions 345 | apply only to part of the Program, that part may be used separately 346 | under those permissions, but the entire Program remains governed by 347 | this License without regard to the additional permissions. 348 | . 349 | When you convey a copy of a covered work, you may at your option 350 | remove any additional permissions from that copy, or from any part of 351 | it. (Additional permissions may be written to require their own 352 | removal in certain cases when you modify the work.) You may place 353 | additional permissions on material, added by you to a covered work, 354 | for which you have or can give appropriate copyright permission. 355 | . 356 | Notwithstanding any other provision of this License, for material you 357 | add to a covered work, you may (if authorized by the copyright holders of 358 | that material) supplement the terms of this License with terms: 359 | . 360 | a) Disclaiming warranty or limiting liability differently from the 361 | terms of sections 15 and 16 of this License; or 362 | . 363 | b) Requiring preservation of specified reasonable legal notices or 364 | author attributions in that material or in the Appropriate Legal 365 | Notices displayed by works containing it; or 366 | . 367 | c) Prohibiting misrepresentation of the origin of that material, or 368 | requiring that modified versions of such material be marked in 369 | reasonable ways as different from the original version; or 370 | . 371 | d) Limiting the use for publicity purposes of names of licensors or 372 | authors of the material; or 373 | . 374 | e) Declining to grant rights under trademark law for use of some 375 | trade names, trademarks, or service marks; or 376 | . 377 | f) Requiring indemnification of licensors and authors of that 378 | material by anyone who conveys the material (or modified versions of 379 | it) with contractual assumptions of liability to the recipient, for 380 | any liability that these contractual assumptions directly impose on 381 | those licensors and authors. 382 | . 383 | All other non-permissive additional terms are considered "further 384 | restrictions" within the meaning of section 10. If the Program as you 385 | received it, or any part of it, contains a notice stating that it is 386 | governed by this License along with a term that is a further 387 | restriction, you may remove that term. If a license document contains 388 | a further restriction but permits relicensing or conveying under this 389 | License, you may add to a covered work material governed by the terms 390 | of that license document, provided that the further restriction does 391 | not survive such relicensing or conveying. 392 | . 393 | If you add terms to a covered work in accord with this section, you 394 | must place, in the relevant source files, a statement of the 395 | additional terms that apply to those files, or a notice indicating 396 | where to find the applicable terms. 397 | . 398 | Additional terms, permissive or non-permissive, may be stated in the 399 | form of a separately written license, or stated as exceptions; 400 | the above requirements apply either way. 401 | . 402 | 8. Termination. 403 | . 404 | You may not propagate or modify a covered work except as expressly 405 | provided under this License. Any attempt otherwise to propagate or 406 | modify it is void, and will automatically terminate your rights under 407 | this License (including any patent licenses granted under the third 408 | paragraph of section 11). 409 | . 410 | However, if you cease all violation of this License, then your 411 | license from a particular copyright holder is reinstated (a) 412 | provisionally, unless and until the copyright holder explicitly and 413 | finally terminates your license, and (b) permanently, if the copyright 414 | holder fails to notify you of the violation by some reasonable means 415 | prior to 60 days after the cessation. 416 | . 417 | Moreover, your license from a particular copyright holder is 418 | reinstated permanently if the copyright holder notifies you of the 419 | violation by some reasonable means, this is the first time you have 420 | received notice of violation of this License (for any work) from that 421 | copyright holder, and you cure the violation prior to 30 days after 422 | your receipt of the notice. 423 | . 424 | Termination of your rights under this section does not terminate the 425 | licenses of parties who have received copies or rights from you under 426 | this License. If your rights have been terminated and not permanently 427 | reinstated, you do not qualify to receive new licenses for the same 428 | material under section 10. 429 | . 430 | 9. Acceptance Not Required for Having Copies. 431 | . 432 | You are not required to accept this License in order to receive or 433 | run a copy of the Program. Ancillary propagation of a covered work 434 | occurring solely as a consequence of using peer-to-peer transmission 435 | to receive a copy likewise does not require acceptance. However, 436 | nothing other than this License grants you permission to propagate or 437 | modify any covered work. These actions infringe copyright if you do 438 | not accept this License. Therefore, by modifying or propagating a 439 | covered work, you indicate your acceptance of this License to do so. 440 | . 441 | 10. Automatic Licensing of Downstream Recipients. 442 | . 443 | Each time you convey a covered work, the recipient automatically 444 | receives a license from the original licensors, to run, modify and 445 | propagate that work, subject to this License. You are not responsible 446 | for enforcing compliance by third parties with this License. 447 | . 448 | An "entity transaction" is a transaction transferring control of an 449 | organization, or substantially all assets of one, or subdividing an 450 | organization, or merging organizations. If propagation of a covered 451 | work results from an entity transaction, each party to that 452 | transaction who receives a copy of the work also receives whatever 453 | licenses to the work the party's predecessor in interest had or could 454 | give under the previous paragraph, plus a right to possession of the 455 | Corresponding Source of the work from the predecessor in interest, if 456 | the predecessor has it or can get it with reasonable efforts. 457 | . 458 | You may not impose any further restrictions on the exercise of the 459 | rights granted or affirmed under this License. For example, you may 460 | not impose a license fee, royalty, or other charge for exercise of 461 | rights granted under this License, and you may not initiate litigation 462 | (including a cross-claim or counterclaim in a lawsuit) alleging that 463 | any patent claim is infringed by making, using, selling, offering for 464 | sale, or importing the Program or any portion of it. 465 | . 466 | 11. Patents. 467 | . 468 | A "contributor" is a copyright holder who authorizes use under this 469 | License of the Program or a work on which the Program is based. The 470 | work thus licensed is called the contributor's "contributor version". 471 | . 472 | A contributor's "essential patent claims" are all patent claims 473 | owned or controlled by the contributor, whether already acquired or 474 | hereafter acquired, that would be infringed by some manner, permitted 475 | by this License, of making, using, or selling its contributor version, 476 | but do not include claims that would be infringed only as a 477 | consequence of further modification of the contributor version. For 478 | purposes of this definition, "control" includes the right to grant 479 | patent sublicenses in a manner consistent with the requirements of 480 | this License. 481 | . 482 | Each contributor grants you a non-exclusive, worldwide, royalty-free 483 | patent license under the contributor's essential patent claims, to 484 | make, use, sell, offer for sale, import and otherwise run, modify and 485 | propagate the contents of its contributor version. 486 | . 487 | In the following three paragraphs, a "patent license" is any express 488 | agreement or commitment, however denominated, not to enforce a patent 489 | (such as an express permission to practice a patent or covenant not to 490 | sue for patent infringement). To "grant" such a patent license to a 491 | party means to make such an agreement or commitment not to enforce a 492 | patent against the party. 493 | . 494 | If you convey a covered work, knowingly relying on a patent license, 495 | and the Corresponding Source of the work is not available for anyone 496 | to copy, free of charge and under the terms of this License, through a 497 | publicly available network server or other readily accessible means, 498 | then you must either (1) cause the Corresponding Source to be so 499 | available, or (2) arrange to deprive yourself of the benefit of the 500 | patent license for this particular work, or (3) arrange, in a manner 501 | consistent with the requirements of this License, to extend the patent 502 | license to downstream recipients. "Knowingly relying" means you have 503 | actual knowledge that, but for the patent license, your conveying the 504 | covered work in a country, or your recipient's use of the covered work 505 | in a country, would infringe one or more identifiable patents in that 506 | country that you have reason to believe are valid. 507 | . 508 | If, pursuant to or in connection with a single transaction or 509 | arrangement, you convey, or propagate by procuring conveyance of, a 510 | covered work, and grant a patent license to some of the parties 511 | receiving the covered work authorizing them to use, propagate, modify 512 | or convey a specific copy of the covered work, then the patent license 513 | you grant is automatically extended to all recipients of the covered 514 | work and works based on it. 515 | . 516 | A patent license is "discriminatory" if it does not include within 517 | the scope of its coverage, prohibits the exercise of, or is 518 | conditioned on the non-exercise of one or more of the rights that are 519 | specifically granted under this License. You may not convey a covered 520 | work if you are a party to an arrangement with a third party that is 521 | in the business of distributing software, under which you make payment 522 | to the third party based on the extent of your activity of conveying 523 | the work, and under which the third party grants, to any of the 524 | parties who would receive the covered work from you, a discriminatory 525 | patent license (a) in connection with copies of the covered work 526 | conveyed by you (or copies made from those copies), or (b) primarily 527 | for and in connection with specific products or compilations that 528 | contain the covered work, unless you entered into that arrangement, 529 | or that patent license was granted, prior to 28 March 2007. 530 | . 531 | Nothing in this License shall be construed as excluding or limiting 532 | any implied license or other defenses to infringement that may 533 | otherwise be available to you under applicable patent law. 534 | . 535 | 12. No Surrender of Others' Freedom. 536 | . 537 | If conditions are imposed on you (whether by court order, agreement or 538 | otherwise) that contradict the conditions of this License, they do not 539 | excuse you from the conditions of this License. If you cannot convey a 540 | covered work so as to satisfy simultaneously your obligations under this 541 | License and any other pertinent obligations, then as a consequence you may 542 | not convey it at all. For example, if you agree to terms that obligate you 543 | to collect a royalty for further conveying from those to whom you convey 544 | the Program, the only way you could satisfy both those terms and this 545 | License would be to refrain entirely from conveying the Program. 546 | . 547 | 13. Remote Network Interaction; Use with the GNU General Public License. 548 | . 549 | Notwithstanding any other provision of this License, if you modify the 550 | Program, your modified version must prominently offer all users 551 | interacting with it remotely through a computer network (if your version 552 | supports such interaction) an opportunity to receive the Corresponding 553 | Source of your version by providing access to the Corresponding Source 554 | from a network server at no charge, through some standard or customary 555 | means of facilitating copying of software. This Corresponding Source 556 | shall include the Corresponding Source for any work covered by version 3 557 | of the GNU General Public License that is incorporated pursuant to the 558 | following paragraph. 559 | . 560 | Notwithstanding any other provision of this License, you have 561 | permission to link or combine any covered work with a work licensed 562 | under version 3 of the GNU General Public License into a single 563 | combined work, and to convey the resulting work. The terms of this 564 | License will continue to apply to the part which is the covered work, 565 | but the work with which it is combined will remain governed by version 566 | 3 of the GNU General Public License. 567 | . 568 | 14. Revised Versions of this License. 569 | . 570 | The Free Software Foundation may publish revised and/or new versions of 571 | the GNU Affero General Public License from time to time. Such new versions 572 | will be similar in spirit to the present version, but may differ in detail to 573 | address new problems or concerns. 574 | . 575 | Each version is given a distinguishing version number. If the 576 | Program specifies that a certain numbered version of the GNU Affero General 577 | Public License "or any later version" applies to it, you have the 578 | option of following the terms and conditions either of that numbered 579 | version or of any later version published by the Free Software 580 | Foundation. If the Program does not specify a version number of the 581 | GNU Affero General Public License, you may choose any version ever published 582 | by the Free Software Foundation. 583 | . 584 | If the Program specifies that a proxy can decide which future 585 | versions of the GNU Affero General Public License can be used, that proxy's 586 | public statement of acceptance of a version permanently authorizes you 587 | to choose that version for the Program. 588 | . 589 | Later license versions may give you additional or different 590 | permissions. However, no additional obligations are imposed on any 591 | author or copyright holder as a result of your choosing to follow a 592 | later version. 593 | . 594 | 15. Disclaimer of Warranty. 595 | . 596 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 597 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 598 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 599 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 600 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 601 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 602 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 603 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 604 | . 605 | 16. Limitation of Liability. 606 | . 607 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 608 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 609 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 610 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 611 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 612 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 613 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 614 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 615 | SUCH DAMAGES. 616 | . 617 | 17. Interpretation of Sections 15 and 16. 618 | . 619 | If the disclaimer of warranty and limitation of liability provided 620 | above cannot be given local legal effect according to their terms, 621 | reviewing courts shall apply local law that most closely approximates 622 | an absolute waiver of all civil liability in connection with the 623 | Program, unless a warranty or assumption of liability accompanies a 624 | copy of the Program in return for a fee. 625 | . 626 | END OF TERMS AND CONDITIONS 627 | . 628 | How to Apply These Terms to Your New Programs 629 | . 630 | If you develop a new program, and you want it to be of the greatest 631 | possible use to the public, the best way to achieve this is to make it 632 | free software which everyone can redistribute and change under these terms. 633 | . 634 | To do so, attach the following notices to the program. It is safest 635 | to attach them to the start of each source file to most effectively 636 | state the exclusion of warranty; and each file should have at least 637 | the "copyright" line and a pointer to where the full notice is found. 638 | . 639 | 640 | Copyright (C) 641 | . 642 | This program is free software: you can redistribute it and/or modify 643 | it under the terms of the GNU Affero General Public License as published by 644 | the Free Software Foundation, either version 3 of the License, or 645 | (at your option) any later version. 646 | . 647 | This program is distributed in the hope that it will be useful, 648 | but WITHOUT ANY WARRANTY; without even the implied warranty of 649 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 650 | GNU Affero General Public License for more details. 651 | . 652 | You should have received a copy of the GNU Affero General Public License 653 | along with this program. If not, see . 654 | . 655 | Also add information on how to contact you by electronic and paper mail. 656 | . 657 | If your software can interact with users remotely through a computer 658 | network, you should also make sure that it provides a way for users to 659 | get its source. For example, if your program is a web application, its 660 | interface could display a "Source" link that leads users to an archive 661 | of the code. There are many ways you could offer source, and different 662 | solutions will be better for different programs; see section 13 for the 663 | specific requirements. 664 | . 665 | You should also get your employer (if you work as a programmer) or school, 666 | if any, to sign a "copyright disclaimer" for the program, if necessary. 667 | For more information on this, and how to apply and follow the GNU AGPL, see 668 | . 669 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Secure Distributed Network Time Synchronization # 2 | 3 | Time keeping is crucial for security, privacy, and anonymity. Sdwdate is a Tor 4 | friendly replacement for rdate and ntpdate that sets the system's clock by 5 | communicating via onion encrypted TCP with Tor onion webservers. 6 | 7 | At randomized intervals, sdwdate connects to a variety of webservers and 8 | extracts the time stamps from http headers (RFC 2616). 9 | Using sclockadj option, time is gradually adjusted preventing bigger clock 10 | jumps that could confuse logs, servers, Tor, i2p, etc. 11 | 12 | This package contains the sdwdate time fetcher and daemon. No 13 | installation on remote servers required. To avoid conflicts, this daemon 14 | should not be enabled together with ntp or tlsdated. 15 | 16 | ## How to install `sdwdate` using apt-get ## 17 | 18 | 1\. Download the APT Signing Key. 19 | 20 | ``` 21 | wget https://www.kicksecure.com/keys/derivative.asc 22 | ``` 23 | 24 | Users can [check the Signing Key](https://www.kicksecure.com/wiki/Signing_Key) for better security. 25 | 26 | 2\. Add the APT Signing Key. 27 | 28 | ``` 29 | sudo cp ~/derivative.asc /usr/share/keyrings/derivative.asc 30 | ``` 31 | 32 | 3\. Add the derivative repository. 33 | 34 | ``` 35 | echo "deb [signed-by=/usr/share/keyrings/derivative.asc] https://deb.kicksecure.com bookworm main contrib non-free" | sudo tee /etc/apt/sources.list.d/derivative.list 36 | ``` 37 | 38 | 4\. Update your package lists. 39 | 40 | ``` 41 | sudo apt-get update 42 | ``` 43 | 44 | 5\. Install `sdwdate`. 45 | 46 | ``` 47 | sudo apt-get install sdwdate 48 | ``` 49 | 50 | ## How to Build deb Package from Source Code ## 51 | 52 | Can be build using standard Debian package build tools such as: 53 | 54 | ``` 55 | dpkg-buildpackage -b 56 | ``` 57 | 58 | See instructions. 59 | 60 | NOTE: Replace `generic-package` with the actual name of this package `sdwdate`. 61 | 62 | * **A)** [easy](https://www.kicksecure.com/wiki/Dev/Build_Documentation/generic-package/easy), _OR_ 63 | * **B)** [including verifying software signatures](https://www.kicksecure.com/wiki/Dev/Build_Documentation/generic-package) 64 | 65 | ## Contact ## 66 | 67 | * [Free Forum Support](https://forums.kicksecure.com) 68 | * [Premium Support](https://www.kicksecure.com/wiki/Premium_Support) 69 | 70 | ## Donate ## 71 | 72 | `sdwdate` requires [donations](https://www.kicksecure.com/wiki/Donate) to stay alive! 73 | -------------------------------------------------------------------------------- /auto-generated-man-pages/sdwdate.8: -------------------------------------------------------------------------------- 1 | .\" generated with Ronn-NG/v0.9.1 2 | .\" http://github.com/apjanke/ronn-ng/tree/0.9.1 3 | .TH "SDWDATE" "8" "January 2020" "sdwdate" "sdwdate Manual" 4 | .SH "NAME" 5 | \fBsdwdate\fR \- Secure Distributed Web Date 6 | .SH "SYNOPSIS" 7 | \fBsdwdate\fR 8 | .SH "DESCRIPTION" 9 | Builds mediate time by asking three onion servers from three different pools\. 10 | .SH "OPTIONS" 11 | None\. 12 | .SH "ENVIRONMENT VARIABLES" 13 | None\. 14 | .SH "CONFIG FILE" 15 | Read the comments in \fB/etc/sdwdate\.d/30_default\.conf\fR\. 16 | .SH "EXIT CODES" 17 | 0 Success\. 18 | .P 19 | 143 Signal sigterm received\. 20 | .P 21 | Other Error\. 22 | .SH "SIGNALS" 23 | .IP "\[ci]" 4 24 | sigterm 25 | .IP 26 | Clean up and exit\. 27 | .IP "" 0 28 | .P 29 | Examples: 30 | .P 31 | \fBsudo kill \-s sigterm "$(cat "/run/sdwdate/pid")"\fR 32 | .SH "EXAMPLES" 33 | If you installed \fBsdwdate\fR from your distribution's repository, it should be already pre\-configured to automatically run as daemon with sane defaults\. 34 | .SH "WWW" 35 | https://www\.whonix\.org/wiki/sdwdate 36 | .SH "CREDITS" 37 | .IP "\[ci]" 4 38 | sdwdate is a rewrite of tails_htp in python 39 | .IP "\[ci]" 4 40 | options and defaults inspired by tails_htp 41 | .IP "\[ci]" 4 42 | log file layout inspired by tails_htp 43 | .IP "" 0 44 | .SH "AUTHOR" 45 | This man page has been written by Patrick Schleizer (adrelanos@whonix\.org)\. 46 | -------------------------------------------------------------------------------- /config-test.txt: -------------------------------------------------------------------------------- 1 | pool: 0 2 | pool_url: [] 3 | pool_comment: [] 4 | pool: 1 5 | pool_url: [] 6 | pool_comment: [] 7 | pool: 2 8 | pool_url: [] 9 | pool_comment: [] 10 | -------------------------------------------------------------------------------- /debian/control: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2012 - 2025 ENCRYPTED SUPPORT LLC 2 | ## See the file COPYING for copying conditions. 3 | 4 | Source: sdwdate 5 | Section: misc 6 | Priority: optional 7 | Maintainer: Patrick Schleizer 8 | Build-Depends: debhelper (>= 13.11.6), debhelper-compat (= 13), 9 | dh-apparmor, dh-python, python3 10 | Homepage: https://www.kicksecure.com/wiki/Sdwdate 11 | Vcs-Browser: https://github.com/Kicksecure/sdwdate 12 | Vcs-Git: https://github.com/Kicksecure/sdwdate.git 13 | Standards-Version: 4.6.2 14 | Rules-Requires-Root: no 15 | 16 | Package: sdwdate 17 | Architecture: all 18 | Depends: sudo, bc, helper-scripts, adduser, gcc, 19 | libc6-dev, privleap, python3-stem, python3-dateutil, 20 | python3-socks, python3-sdnotify, python3-requests, python3, tor, 21 | ${python3:Depends}, ${misc:Depends} 22 | Recommends: timesanitycheck, bootclockrandomization 23 | Provides: time-daemon 24 | Conflicts: time-daemon 25 | Description: Secure Distributed Network Time Synchronization 26 | Time keeping is crucial for security, privacy, and anonymity. Sdwdate is a Tor 27 | friendly replacement for rdate and ntpdate that sets the system's clock by 28 | communicating via onion encrypted TCP with Tor onion webservers. 29 | . 30 | At randomized intervals, sdwdate connects to a variety of webservers and 31 | extracts the time stamps from http headers (RFC 2616). 32 | Using sclockadj option, time is gradually adjusted preventing bigger clock 33 | jumps that could confuse logs, servers, Tor, i2p, etc. 34 | . 35 | This package contains the sdwdate time fetcher and daemon. No 36 | installation on remote servers required. To avoid conflicts, this daemon 37 | should not be enabled together with ntp or tlsdated. 38 | -------------------------------------------------------------------------------- /debian/copyright: -------------------------------------------------------------------------------- 1 | Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ 2 | 3 | Files: * 4 | Copyright: 2012 - 2025 ENCRYPTED SUPPORT LLC 5 | License: AGPL-3+ 6 | 7 | License: AGPL-3+ 8 | GNU AFFERO GENERAL PUBLIC LICENSE 9 | Version 3, 19 November 2007 10 | . 11 | Copyright (C) 2007 Free Software Foundation, Inc. 12 | Everyone is permitted to copy and distribute verbatim copies 13 | of this license document, but changing it is not allowed. 14 | . 15 | Preamble 16 | . 17 | The GNU Affero General Public License is a free, copyleft license for 18 | software and other kinds of works, specifically designed to ensure 19 | cooperation with the community in the case of network server software. 20 | . 21 | The licenses for most software and other practical works are designed 22 | to take away your freedom to share and change the works. By contrast, 23 | our General Public Licenses are intended to guarantee your freedom to 24 | share and change all versions of a program--to make sure it remains free 25 | software for all its users. 26 | . 27 | When we speak of free software, we are referring to freedom, not 28 | price. Our General Public Licenses are designed to make sure that you 29 | have the freedom to distribute copies of free software (and charge for 30 | them if you wish), that you receive source code or can get it if you 31 | want it, that you can change the software or use pieces of it in new 32 | free programs, and that you know you can do these things. 33 | . 34 | Developers that use our General Public Licenses protect your rights 35 | with two steps: (1) assert copyright on the software, and (2) offer 36 | you this License which gives you legal permission to copy, distribute 37 | and/or modify the software. 38 | . 39 | A secondary benefit of defending all users' freedom is that 40 | improvements made in alternate versions of the program, if they 41 | receive widespread use, become available for other developers to 42 | incorporate. Many developers of free software are heartened and 43 | encouraged by the resulting cooperation. However, in the case of 44 | software used on network servers, this result may fail to come about. 45 | The GNU General Public License permits making a modified version and 46 | letting the public access it on a server without ever releasing its 47 | source code to the public. 48 | . 49 | The GNU Affero General Public License is designed specifically to 50 | ensure that, in such cases, the modified source code becomes available 51 | to the community. It requires the operator of a network server to 52 | provide the source code of the modified version running there to the 53 | users of that server. Therefore, public use of a modified version, on 54 | a publicly accessible server, gives the public access to the source 55 | code of the modified version. 56 | . 57 | An older license, called the Affero General Public License and 58 | published by Affero, was designed to accomplish similar goals. This is 59 | a different license, not a version of the Affero GPL, but Affero has 60 | released a new version of the Affero GPL which permits relicensing under 61 | this license. 62 | . 63 | The precise terms and conditions for copying, distribution and 64 | modification follow. 65 | . 66 | TERMS AND CONDITIONS 67 | . 68 | 0. Definitions. 69 | . 70 | "This License" refers to version 3 of the GNU Affero General Public License. 71 | . 72 | "Copyright" also means copyright-like laws that apply to other kinds of 73 | works, such as semiconductor masks. 74 | . 75 | "The Program" refers to any copyrightable work licensed under this 76 | License. Each licensee is addressed as "you". "Licensees" and 77 | "recipients" may be individuals or organizations. 78 | . 79 | To "modify" a work means to copy from or adapt all or part of the work 80 | in a fashion requiring copyright permission, other than the making of an 81 | exact copy. The resulting work is called a "modified version" of the 82 | earlier work or a work "based on" the earlier work. 83 | . 84 | A "covered work" means either the unmodified Program or a work based 85 | on the Program. 86 | . 87 | To "propagate" a work means to do anything with it that, without 88 | permission, would make you directly or secondarily liable for 89 | infringement under applicable copyright law, except executing it on a 90 | computer or modifying a private copy. Propagation includes copying, 91 | distribution (with or without modification), making available to the 92 | public, and in some countries other activities as well. 93 | . 94 | To "convey" a work means any kind of propagation that enables other 95 | parties to make or receive copies. Mere interaction with a user through 96 | a computer network, with no transfer of a copy, is not conveying. 97 | . 98 | An interactive user interface displays "Appropriate Legal Notices" 99 | to the extent that it includes a convenient and prominently visible 100 | feature that (1) displays an appropriate copyright notice, and (2) 101 | tells the user that there is no warranty for the work (except to the 102 | extent that warranties are provided), that licensees may convey the 103 | work under this License, and how to view a copy of this License. If 104 | the interface presents a list of user commands or options, such as a 105 | menu, a prominent item in the list meets this criterion. 106 | . 107 | 1. Source Code. 108 | . 109 | The "source code" for a work means the preferred form of the work 110 | for making modifications to it. "Object code" means any non-source 111 | form of a work. 112 | . 113 | A "Standard Interface" means an interface that either is an official 114 | standard defined by a recognized standards body, or, in the case of 115 | interfaces specified for a particular programming language, one that 116 | is widely used among developers working in that language. 117 | . 118 | The "System Libraries" of an executable work include anything, other 119 | than the work as a whole, that (a) is included in the normal form of 120 | packaging a Major Component, but which is not part of that Major 121 | Component, and (b) serves only to enable use of the work with that 122 | Major Component, or to implement a Standard Interface for which an 123 | implementation is available to the public in source code form. A 124 | "Major Component", in this context, means a major essential component 125 | (kernel, window system, and so on) of the specific operating system 126 | (if any) on which the executable work runs, or a compiler used to 127 | produce the work, or an object code interpreter used to run it. 128 | . 129 | The "Corresponding Source" for a work in object code form means all 130 | the source code needed to generate, install, and (for an executable 131 | work) run the object code and to modify the work, including scripts to 132 | control those activities. However, it does not include the work's 133 | System Libraries, or general-purpose tools or generally available free 134 | programs which are used unmodified in performing those activities but 135 | which are not part of the work. For example, Corresponding Source 136 | includes interface definition files associated with source files for 137 | the work, and the source code for shared libraries and dynamically 138 | linked subprograms that the work is specifically designed to require, 139 | such as by intimate data communication or control flow between those 140 | subprograms and other parts of the work. 141 | . 142 | The Corresponding Source need not include anything that users 143 | can regenerate automatically from other parts of the Corresponding 144 | Source. 145 | . 146 | The Corresponding Source for a work in source code form is that 147 | same work. 148 | . 149 | 2. Basic Permissions. 150 | . 151 | All rights granted under this License are granted for the term of 152 | copyright on the Program, and are irrevocable provided the stated 153 | conditions are met. This License explicitly affirms your unlimited 154 | permission to run the unmodified Program. The output from running a 155 | covered work is covered by this License only if the output, given its 156 | content, constitutes a covered work. This License acknowledges your 157 | rights of fair use or other equivalent, as provided by copyright law. 158 | . 159 | You may make, run and propagate covered works that you do not 160 | convey, without conditions so long as your license otherwise remains 161 | in force. You may convey covered works to others for the sole purpose 162 | of having them make modifications exclusively for you, or provide you 163 | with facilities for running those works, provided that you comply with 164 | the terms of this License in conveying all material for which you do 165 | not control copyright. Those thus making or running the covered works 166 | for you must do so exclusively on your behalf, under your direction 167 | and control, on terms that prohibit them from making any copies of 168 | your copyrighted material outside their relationship with you. 169 | . 170 | Conveying under any other circumstances is permitted solely under 171 | the conditions stated below. Sublicensing is not allowed; section 10 172 | makes it unnecessary. 173 | . 174 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 175 | . 176 | No covered work shall be deemed part of an effective technological 177 | measure under any applicable law fulfilling obligations under article 178 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 179 | similar laws prohibiting or restricting circumvention of such 180 | measures. 181 | . 182 | When you convey a covered work, you waive any legal power to forbid 183 | circumvention of technological measures to the extent such circumvention 184 | is effected by exercising rights under this License with respect to 185 | the covered work, and you disclaim any intention to limit operation or 186 | modification of the work as a means of enforcing, against the work's 187 | users, your or third parties' legal rights to forbid circumvention of 188 | technological measures. 189 | . 190 | 4. Conveying Verbatim Copies. 191 | . 192 | You may convey verbatim copies of the Program's source code as you 193 | receive it, in any medium, provided that you conspicuously and 194 | appropriately publish on each copy an appropriate copyright notice; 195 | keep intact all notices stating that this License and any 196 | non-permissive terms added in accord with section 7 apply to the code; 197 | keep intact all notices of the absence of any warranty; and give all 198 | recipients a copy of this License along with the Program. 199 | . 200 | You may charge any price or no price for each copy that you convey, 201 | and you may offer support or warranty protection for a fee. 202 | . 203 | 5. Conveying Modified Source Versions. 204 | . 205 | You may convey a work based on the Program, or the modifications to 206 | produce it from the Program, in the form of source code under the 207 | terms of section 4, provided that you also meet all of these conditions: 208 | . 209 | a) The work must carry prominent notices stating that you modified 210 | it, and giving a relevant date. 211 | . 212 | b) The work must carry prominent notices stating that it is 213 | released under this License and any conditions added under section 214 | 7. This requirement modifies the requirement in section 4 to 215 | "keep intact all notices". 216 | . 217 | c) You must license the entire work, as a whole, under this 218 | License to anyone who comes into possession of a copy. This 219 | License will therefore apply, along with any applicable section 7 220 | additional terms, to the whole of the work, and all its parts, 221 | regardless of how they are packaged. This License gives no 222 | permission to license the work in any other way, but it does not 223 | invalidate such permission if you have separately received it. 224 | . 225 | d) If the work has interactive user interfaces, each must display 226 | Appropriate Legal Notices; however, if the Program has interactive 227 | interfaces that do not display Appropriate Legal Notices, your 228 | work need not make them do so. 229 | . 230 | A compilation of a covered work with other separate and independent 231 | works, which are not by their nature extensions of the covered work, 232 | and which are not combined with it such as to form a larger program, 233 | in or on a volume of a storage or distribution medium, is called an 234 | "aggregate" if the compilation and its resulting copyright are not 235 | used to limit the access or legal rights of the compilation's users 236 | beyond what the individual works permit. Inclusion of a covered work 237 | in an aggregate does not cause this License to apply to the other 238 | parts of the aggregate. 239 | . 240 | 6. Conveying Non-Source Forms. 241 | . 242 | You may convey a covered work in object code form under the terms 243 | of sections 4 and 5, provided that you also convey the 244 | machine-readable Corresponding Source under the terms of this License, 245 | in one of these ways: 246 | . 247 | a) Convey the object code in, or embodied in, a physical product 248 | (including a physical distribution medium), accompanied by the 249 | Corresponding Source fixed on a durable physical medium 250 | customarily used for software interchange. 251 | . 252 | b) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by a 254 | written offer, valid for at least three years and valid for as 255 | long as you offer spare parts or customer support for that product 256 | model, to give anyone who possesses the object code either (1) a 257 | copy of the Corresponding Source for all the software in the 258 | product that is covered by this License, on a durable physical 259 | medium customarily used for software interchange, for a price no 260 | more than your reasonable cost of physically performing this 261 | conveying of source, or (2) access to copy the 262 | Corresponding Source from a network server at no charge. 263 | . 264 | c) Convey individual copies of the object code with a copy of the 265 | written offer to provide the Corresponding Source. This 266 | alternative is allowed only occasionally and noncommercially, and 267 | only if you received the object code with such an offer, in accord 268 | with subsection 6b. 269 | . 270 | d) Convey the object code by offering access from a designated 271 | place (gratis or for a charge), and offer equivalent access to the 272 | Corresponding Source in the same way through the same place at no 273 | further charge. You need not require recipients to copy the 274 | Corresponding Source along with the object code. If the place to 275 | copy the object code is a network server, the Corresponding Source 276 | may be on a different server (operated by you or a third party) 277 | that supports equivalent copying facilities, provided you maintain 278 | clear directions next to the object code saying where to find the 279 | Corresponding Source. Regardless of what server hosts the 280 | Corresponding Source, you remain obligated to ensure that it is 281 | available for as long as needed to satisfy these requirements. 282 | . 283 | e) Convey the object code using peer-to-peer transmission, provided 284 | you inform other peers where the object code and Corresponding 285 | Source of the work are being offered to the general public at no 286 | charge under subsection 6d. 287 | . 288 | A separable portion of the object code, whose source code is excluded 289 | from the Corresponding Source as a System Library, need not be 290 | included in conveying the object code work. 291 | . 292 | A "User Product" is either (1) a "consumer product", which means any 293 | tangible personal property which is normally used for personal, family, 294 | or household purposes, or (2) anything designed or sold for incorporation 295 | into a dwelling. In determining whether a product is a consumer product, 296 | doubtful cases shall be resolved in favor of coverage. For a particular 297 | product received by a particular user, "normally used" refers to a 298 | typical or common use of that class of product, regardless of the status 299 | of the particular user or of the way in which the particular user 300 | actually uses, or expects or is expected to use, the product. A product 301 | is a consumer product regardless of whether the product has substantial 302 | commercial, industrial or non-consumer uses, unless such uses represent 303 | the only significant mode of use of the product. 304 | . 305 | "Installation Information" for a User Product means any methods, 306 | procedures, authorization keys, or other information required to install 307 | and execute modified versions of a covered work in that User Product from 308 | a modified version of its Corresponding Source. The information must 309 | suffice to ensure that the continued functioning of the modified object 310 | code is in no case prevented or interfered with solely because 311 | modification has been made. 312 | . 313 | If you convey an object code work under this section in, or with, or 314 | specifically for use in, a User Product, and the conveying occurs as 315 | part of a transaction in which the right of possession and use of the 316 | User Product is transferred to the recipient in perpetuity or for a 317 | fixed term (regardless of how the transaction is characterized), the 318 | Corresponding Source conveyed under this section must be accompanied 319 | by the Installation Information. But this requirement does not apply 320 | if neither you nor any third party retains the ability to install 321 | modified object code on the User Product (for example, the work has 322 | been installed in ROM). 323 | . 324 | The requirement to provide Installation Information does not include a 325 | requirement to continue to provide support service, warranty, or updates 326 | for a work that has been modified or installed by the recipient, or for 327 | the User Product in which it has been modified or installed. Access to a 328 | network may be denied when the modification itself materially and 329 | adversely affects the operation of the network or violates the rules and 330 | protocols for communication across the network. 331 | . 332 | Corresponding Source conveyed, and Installation Information provided, 333 | in accord with this section must be in a format that is publicly 334 | documented (and with an implementation available to the public in 335 | source code form), and must require no special password or key for 336 | unpacking, reading or copying. 337 | . 338 | 7. Additional Terms. 339 | . 340 | "Additional permissions" are terms that supplement the terms of this 341 | License by making exceptions from one or more of its conditions. 342 | Additional permissions that are applicable to the entire Program shall 343 | be treated as though they were included in this License, to the extent 344 | that they are valid under applicable law. If additional permissions 345 | apply only to part of the Program, that part may be used separately 346 | under those permissions, but the entire Program remains governed by 347 | this License without regard to the additional permissions. 348 | . 349 | When you convey a copy of a covered work, you may at your option 350 | remove any additional permissions from that copy, or from any part of 351 | it. (Additional permissions may be written to require their own 352 | removal in certain cases when you modify the work.) You may place 353 | additional permissions on material, added by you to a covered work, 354 | for which you have or can give appropriate copyright permission. 355 | . 356 | Notwithstanding any other provision of this License, for material you 357 | add to a covered work, you may (if authorized by the copyright holders of 358 | that material) supplement the terms of this License with terms: 359 | . 360 | a) Disclaiming warranty or limiting liability differently from the 361 | terms of sections 15 and 16 of this License; or 362 | . 363 | b) Requiring preservation of specified reasonable legal notices or 364 | author attributions in that material or in the Appropriate Legal 365 | Notices displayed by works containing it; or 366 | . 367 | c) Prohibiting misrepresentation of the origin of that material, or 368 | requiring that modified versions of such material be marked in 369 | reasonable ways as different from the original version; or 370 | . 371 | d) Limiting the use for publicity purposes of names of licensors or 372 | authors of the material; or 373 | . 374 | e) Declining to grant rights under trademark law for use of some 375 | trade names, trademarks, or service marks; or 376 | . 377 | f) Requiring indemnification of licensors and authors of that 378 | material by anyone who conveys the material (or modified versions of 379 | it) with contractual assumptions of liability to the recipient, for 380 | any liability that these contractual assumptions directly impose on 381 | those licensors and authors. 382 | . 383 | All other non-permissive additional terms are considered "further 384 | restrictions" within the meaning of section 10. If the Program as you 385 | received it, or any part of it, contains a notice stating that it is 386 | governed by this License along with a term that is a further 387 | restriction, you may remove that term. If a license document contains 388 | a further restriction but permits relicensing or conveying under this 389 | License, you may add to a covered work material governed by the terms 390 | of that license document, provided that the further restriction does 391 | not survive such relicensing or conveying. 392 | . 393 | If you add terms to a covered work in accord with this section, you 394 | must place, in the relevant source files, a statement of the 395 | additional terms that apply to those files, or a notice indicating 396 | where to find the applicable terms. 397 | . 398 | Additional terms, permissive or non-permissive, may be stated in the 399 | form of a separately written license, or stated as exceptions; 400 | the above requirements apply either way. 401 | . 402 | 8. Termination. 403 | . 404 | You may not propagate or modify a covered work except as expressly 405 | provided under this License. Any attempt otherwise to propagate or 406 | modify it is void, and will automatically terminate your rights under 407 | this License (including any patent licenses granted under the third 408 | paragraph of section 11). 409 | . 410 | However, if you cease all violation of this License, then your 411 | license from a particular copyright holder is reinstated (a) 412 | provisionally, unless and until the copyright holder explicitly and 413 | finally terminates your license, and (b) permanently, if the copyright 414 | holder fails to notify you of the violation by some reasonable means 415 | prior to 60 days after the cessation. 416 | . 417 | Moreover, your license from a particular copyright holder is 418 | reinstated permanently if the copyright holder notifies you of the 419 | violation by some reasonable means, this is the first time you have 420 | received notice of violation of this License (for any work) from that 421 | copyright holder, and you cure the violation prior to 30 days after 422 | your receipt of the notice. 423 | . 424 | Termination of your rights under this section does not terminate the 425 | licenses of parties who have received copies or rights from you under 426 | this License. If your rights have been terminated and not permanently 427 | reinstated, you do not qualify to receive new licenses for the same 428 | material under section 10. 429 | . 430 | 9. Acceptance Not Required for Having Copies. 431 | . 432 | You are not required to accept this License in order to receive or 433 | run a copy of the Program. Ancillary propagation of a covered work 434 | occurring solely as a consequence of using peer-to-peer transmission 435 | to receive a copy likewise does not require acceptance. However, 436 | nothing other than this License grants you permission to propagate or 437 | modify any covered work. These actions infringe copyright if you do 438 | not accept this License. Therefore, by modifying or propagating a 439 | covered work, you indicate your acceptance of this License to do so. 440 | . 441 | 10. Automatic Licensing of Downstream Recipients. 442 | . 443 | Each time you convey a covered work, the recipient automatically 444 | receives a license from the original licensors, to run, modify and 445 | propagate that work, subject to this License. You are not responsible 446 | for enforcing compliance by third parties with this License. 447 | . 448 | An "entity transaction" is a transaction transferring control of an 449 | organization, or substantially all assets of one, or subdividing an 450 | organization, or merging organizations. If propagation of a covered 451 | work results from an entity transaction, each party to that 452 | transaction who receives a copy of the work also receives whatever 453 | licenses to the work the party's predecessor in interest had or could 454 | give under the previous paragraph, plus a right to possession of the 455 | Corresponding Source of the work from the predecessor in interest, if 456 | the predecessor has it or can get it with reasonable efforts. 457 | . 458 | You may not impose any further restrictions on the exercise of the 459 | rights granted or affirmed under this License. For example, you may 460 | not impose a license fee, royalty, or other charge for exercise of 461 | rights granted under this License, and you may not initiate litigation 462 | (including a cross-claim or counterclaim in a lawsuit) alleging that 463 | any patent claim is infringed by making, using, selling, offering for 464 | sale, or importing the Program or any portion of it. 465 | . 466 | 11. Patents. 467 | . 468 | A "contributor" is a copyright holder who authorizes use under this 469 | License of the Program or a work on which the Program is based. The 470 | work thus licensed is called the contributor's "contributor version". 471 | . 472 | A contributor's "essential patent claims" are all patent claims 473 | owned or controlled by the contributor, whether already acquired or 474 | hereafter acquired, that would be infringed by some manner, permitted 475 | by this License, of making, using, or selling its contributor version, 476 | but do not include claims that would be infringed only as a 477 | consequence of further modification of the contributor version. For 478 | purposes of this definition, "control" includes the right to grant 479 | patent sublicenses in a manner consistent with the requirements of 480 | this License. 481 | . 482 | Each contributor grants you a non-exclusive, worldwide, royalty-free 483 | patent license under the contributor's essential patent claims, to 484 | make, use, sell, offer for sale, import and otherwise run, modify and 485 | propagate the contents of its contributor version. 486 | . 487 | In the following three paragraphs, a "patent license" is any express 488 | agreement or commitment, however denominated, not to enforce a patent 489 | (such as an express permission to practice a patent or covenant not to 490 | sue for patent infringement). To "grant" such a patent license to a 491 | party means to make such an agreement or commitment not to enforce a 492 | patent against the party. 493 | . 494 | If you convey a covered work, knowingly relying on a patent license, 495 | and the Corresponding Source of the work is not available for anyone 496 | to copy, free of charge and under the terms of this License, through a 497 | publicly available network server or other readily accessible means, 498 | then you must either (1) cause the Corresponding Source to be so 499 | available, or (2) arrange to deprive yourself of the benefit of the 500 | patent license for this particular work, or (3) arrange, in a manner 501 | consistent with the requirements of this License, to extend the patent 502 | license to downstream recipients. "Knowingly relying" means you have 503 | actual knowledge that, but for the patent license, your conveying the 504 | covered work in a country, or your recipient's use of the covered work 505 | in a country, would infringe one or more identifiable patents in that 506 | country that you have reason to believe are valid. 507 | . 508 | If, pursuant to or in connection with a single transaction or 509 | arrangement, you convey, or propagate by procuring conveyance of, a 510 | covered work, and grant a patent license to some of the parties 511 | receiving the covered work authorizing them to use, propagate, modify 512 | or convey a specific copy of the covered work, then the patent license 513 | you grant is automatically extended to all recipients of the covered 514 | work and works based on it. 515 | . 516 | A patent license is "discriminatory" if it does not include within 517 | the scope of its coverage, prohibits the exercise of, or is 518 | conditioned on the non-exercise of one or more of the rights that are 519 | specifically granted under this License. You may not convey a covered 520 | work if you are a party to an arrangement with a third party that is 521 | in the business of distributing software, under which you make payment 522 | to the third party based on the extent of your activity of conveying 523 | the work, and under which the third party grants, to any of the 524 | parties who would receive the covered work from you, a discriminatory 525 | patent license (a) in connection with copies of the covered work 526 | conveyed by you (or copies made from those copies), or (b) primarily 527 | for and in connection with specific products or compilations that 528 | contain the covered work, unless you entered into that arrangement, 529 | or that patent license was granted, prior to 28 March 2007. 530 | . 531 | Nothing in this License shall be construed as excluding or limiting 532 | any implied license or other defenses to infringement that may 533 | otherwise be available to you under applicable patent law. 534 | . 535 | 12. No Surrender of Others' Freedom. 536 | . 537 | If conditions are imposed on you (whether by court order, agreement or 538 | otherwise) that contradict the conditions of this License, they do not 539 | excuse you from the conditions of this License. If you cannot convey a 540 | covered work so as to satisfy simultaneously your obligations under this 541 | License and any other pertinent obligations, then as a consequence you may 542 | not convey it at all. For example, if you agree to terms that obligate you 543 | to collect a royalty for further conveying from those to whom you convey 544 | the Program, the only way you could satisfy both those terms and this 545 | License would be to refrain entirely from conveying the Program. 546 | . 547 | 13. Remote Network Interaction; Use with the GNU General Public License. 548 | . 549 | Notwithstanding any other provision of this License, if you modify the 550 | Program, your modified version must prominently offer all users 551 | interacting with it remotely through a computer network (if your version 552 | supports such interaction) an opportunity to receive the Corresponding 553 | Source of your version by providing access to the Corresponding Source 554 | from a network server at no charge, through some standard or customary 555 | means of facilitating copying of software. This Corresponding Source 556 | shall include the Corresponding Source for any work covered by version 3 557 | of the GNU General Public License that is incorporated pursuant to the 558 | following paragraph. 559 | . 560 | Notwithstanding any other provision of this License, you have 561 | permission to link or combine any covered work with a work licensed 562 | under version 3 of the GNU General Public License into a single 563 | combined work, and to convey the resulting work. The terms of this 564 | License will continue to apply to the part which is the covered work, 565 | but the work with which it is combined will remain governed by version 566 | 3 of the GNU General Public License. 567 | . 568 | 14. Revised Versions of this License. 569 | . 570 | The Free Software Foundation may publish revised and/or new versions of 571 | the GNU Affero General Public License from time to time. Such new versions 572 | will be similar in spirit to the present version, but may differ in detail to 573 | address new problems or concerns. 574 | . 575 | Each version is given a distinguishing version number. If the 576 | Program specifies that a certain numbered version of the GNU Affero General 577 | Public License "or any later version" applies to it, you have the 578 | option of following the terms and conditions either of that numbered 579 | version or of any later version published by the Free Software 580 | Foundation. If the Program does not specify a version number of the 581 | GNU Affero General Public License, you may choose any version ever published 582 | by the Free Software Foundation. 583 | . 584 | If the Program specifies that a proxy can decide which future 585 | versions of the GNU Affero General Public License can be used, that proxy's 586 | public statement of acceptance of a version permanently authorizes you 587 | to choose that version for the Program. 588 | . 589 | Later license versions may give you additional or different 590 | permissions. However, no additional obligations are imposed on any 591 | author or copyright holder as a result of your choosing to follow a 592 | later version. 593 | . 594 | 15. Disclaimer of Warranty. 595 | . 596 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 597 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 598 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 599 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 600 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 601 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 602 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 603 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 604 | . 605 | 16. Limitation of Liability. 606 | . 607 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 608 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 609 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 610 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 611 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 612 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 613 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 614 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 615 | SUCH DAMAGES. 616 | . 617 | 17. Interpretation of Sections 15 and 16. 618 | . 619 | If the disclaimer of warranty and limitation of liability provided 620 | above cannot be given local legal effect according to their terms, 621 | reviewing courts shall apply local law that most closely approximates 622 | an absolute waiver of all civil liability in connection with the 623 | Program, unless a warranty or assumption of liability accompanies a 624 | copy of the Program in return for a fee. 625 | . 626 | END OF TERMS AND CONDITIONS 627 | . 628 | How to Apply These Terms to Your New Programs 629 | . 630 | If you develop a new program, and you want it to be of the greatest 631 | possible use to the public, the best way to achieve this is to make it 632 | free software which everyone can redistribute and change under these terms. 633 | . 634 | To do so, attach the following notices to the program. It is safest 635 | to attach them to the start of each source file to most effectively 636 | state the exclusion of warranty; and each file should have at least 637 | the "copyright" line and a pointer to where the full notice is found. 638 | . 639 | 640 | Copyright (C) 641 | . 642 | This program is free software: you can redistribute it and/or modify 643 | it under the terms of the GNU Affero General Public License as published by 644 | the Free Software Foundation, either version 3 of the License, or 645 | (at your option) any later version. 646 | . 647 | This program is distributed in the hope that it will be useful, 648 | but WITHOUT ANY WARRANTY; without even the implied warranty of 649 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 650 | GNU Affero General Public License for more details. 651 | . 652 | You should have received a copy of the GNU Affero General Public License 653 | along with this program. If not, see . 654 | . 655 | Also add information on how to contact you by electronic and paper mail. 656 | . 657 | If your software can interact with users remotely through a computer 658 | network, you should also make sure that it provides a way for users to 659 | get its source. For example, if your program is a web application, its 660 | interface could display a "Source" link that leads users to an archive 661 | of the code. There are many ways you could offer source, and different 662 | solutions will be better for different programs; see section 13 for the 663 | specific requirements. 664 | . 665 | You should also get your employer (if you work as a programmer) or school, 666 | if any, to sign a "copyright disclaimer" for the program, if necessary. 667 | For more information on this, and how to apply and follow the GNU AGPL, see 668 | . 669 | -------------------------------------------------------------------------------- /debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | 3 | ## Copyright (C) 2012 - 2025 ENCRYPTED SUPPORT LLC 4 | ## See the file COPYING for copying conditions. 5 | 6 | #export DH_VERBOSE=1 7 | 8 | %: 9 | dh $@ --with python3 10 | 11 | override_dh_install: 12 | dh_apparmor --profile-name=usr.bin.sdwdate 13 | dh_apparmor --profile-name=usr.bin.url_to_unixtime 14 | dh_install 15 | 16 | override_dh_installman: 17 | dh_installman $(CURDIR)/auto-generated-man-pages/* 18 | 19 | override_dh_installchangelogs: 20 | dh_installchangelogs changelog.upstream upstream 21 | -------------------------------------------------------------------------------- /debian/sdwdate.install: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2020 - 2025 ENCRYPTED SUPPORT LLC 2 | ## See the file COPYING for copying conditions. 3 | 4 | ## This file was generated using genmkfile 'make debinstfile'. 5 | 6 | etc/* 7 | usr/* 8 | -------------------------------------------------------------------------------- /debian/sdwdate.maintscript: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2017 - 2025 ENCRYPTED SUPPORT LLC 2 | ## See the file COPYING for copying conditions. 3 | 4 | ## Was renamed to include file extension .conf. 5 | rm_conffile /etc/sdwdate.d/30_default 6 | rm_conffile /etc/sdwdate.d/30_sdwdate_default 7 | 8 | ## These plugins have been merged into sdwdate. 9 | rm_conffile /etc/sdwdate.d/31_anon_dist_con_check_plugin 10 | rm_conffile /etc/sdwdate.d/31_anon_dist_stream_isolation_plugin 11 | 12 | rm_conffile /etc/apparmor.d/abstractions/sdwdate 13 | 14 | rm_conffile /etc/apparmor.d/usr.lib.sdwdate.url_to_unixtime 15 | -------------------------------------------------------------------------------- /debian/sdwdate.postinst: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ## Copyright (C) 2012 - 2025 ENCRYPTED SUPPORT LLC 4 | ## See the file COPYING for copying conditions. 5 | 6 | if [ -f /usr/libexec/helper-scripts/pre.bsh ]; then 7 | source /usr/libexec/helper-scripts/pre.bsh 8 | fi 9 | 10 | set -e 11 | 12 | true " 13 | ##################################################################### 14 | ## INFO: BEGIN: $DPKG_MAINTSCRIPT_PACKAGE $DPKG_MAINTSCRIPT_NAME $@ 15 | ##################################################################### 16 | " 17 | 18 | if [ -x /usr/libexec/helper-scripts/torsocks-remove-ld-preload ]; then 19 | source /usr/libexec/helper-scripts/torsocks-remove-ld-preload 20 | fi 21 | 22 | case "$1" in 23 | configure) 24 | ## Compatibility with anon-ws-disable-stacked-tor. 25 | addgroup debian-tor 2>/dev/null || true 26 | 27 | adduser --home /run/sdwdate --no-create-home --quiet --system --group sdwdate || true 28 | 29 | ## user `sdwdate` legacy home folder migration 30 | sdwdate_home="$(getent passwd sdwdate | cut -d: -f6)" || true 31 | if [ "$sdwdate_home" = "/nonexistent" ]; then 32 | if [ -d /run/systemd/system ]; then 33 | ## Make /lib/systemd/system/sdwdate.service `RestartSec=10s` take effect. 34 | systemctl --system daemon-reload >/dev/null || true 35 | fi 36 | ## Need to kill sdwdate, otherwise we cannot change user home using `usermod`. 37 | ## `usermod` would complain: 38 | ## usermod: user sdwdate is currently used by process 2491 39 | ## 40 | ## Making sure pgrep will not match this postinst script. 41 | kill -s sigterm $(pgrep -f /usr/bin/sdwdate) 2>/dev/null || true 42 | ## Allow sigterm to actually kill sdwdate. 43 | sleep 5 44 | fi 45 | ## Change user home of user sdwdate to /run/sdwdate. 46 | ## Legacy because previously was created using folder /nonexistent. 47 | ## Folder /run/sdwdate gets created by /usr/lib/tmpfiles.d/sdwdate.conf. 48 | usermod -m -d /run/sdwdate sdwdate || true 49 | 50 | mkdir -p /run/sdwdate || true 51 | ## Fix bug since /run/sdwdate might be owned by onion-grater. 52 | chown sdwdate:sdwdate /run/sdwdate || true 53 | 54 | ## Add sdwdate to group debian-tor so it can read 55 | ## /run/tor/control.authcookie which is required to check if Tor has 56 | ## already successfully established a circuit before fetching time. 57 | adduser sdwdate debian-tor 58 | 59 | ## required for anondate which uses journalctl 60 | ## Not possible here, because 61 | ## group systemd-journal might not exist yet during the build process. 62 | #adduser sdwdate systemd-journal 63 | ;; 64 | 65 | abort-upgrade|abort-remove|abort-deconfigure) 66 | ;; 67 | 68 | *) 69 | echo "$DPKG_MAINTSCRIPT_NAME called with unknown argument \`$1'" >&2 70 | exit 1 71 | ;; 72 | esac 73 | 74 | ## Deletes /etc/systemd/system/sysinit.target.wants/systemd-timesyncd.service. 75 | ## Otherwise timedatectl still thinks systemd-timesyncd is enabled. 76 | timedatectl set-ntp false >/dev/null 2>&1 || true 77 | ## Make sure it gets really deleted even if timedatectl does not work. 78 | rm --force /etc/systemd/system/sysinit.target.wants/systemd-timesyncd.service 79 | 80 | ## Add arch-specific syscalls to the seccomp filter. 81 | if ! [ -d /lib/systemd/system/sdwdate.service.d/ ]; then 82 | mkdir --parents /lib/systemd/system/sdwdate.service.d/ 83 | fi 84 | 85 | ## Legacy 2023. 86 | rm -f /lib/systemd/system/sdwdate.service.d/20_arch_syscall_whitelist.conf 87 | 88 | true "INFO: debhelper beginning here." 89 | 90 | #DEBHELPER# 91 | 92 | true "INFO: Done with debhelper." 93 | 94 | true " 95 | ##################################################################### 96 | ## INFO: END : $DPKG_MAINTSCRIPT_PACKAGE $DPKG_MAINTSCRIPT_NAME $@ 97 | ##################################################################### 98 | " 99 | 100 | ## Explicitly "exit 0", so eventually trapped errors can be ignored. 101 | exit 0 102 | -------------------------------------------------------------------------------- /debian/sdwdate.postrm: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ## Copyright (C) 2012 - 2025 ENCRYPTED SUPPORT LLC 4 | ## See the file COPYING for copying conditions. 5 | 6 | if [ -f /usr/libexec/helper-scripts/pre.bsh ]; then 7 | source /usr/libexec/helper-scripts/pre.bsh 8 | fi 9 | 10 | set -e 11 | 12 | if [ "$1" = "purge" ]; then 13 | ## delete sclockadj only when package is removed using apt-get with purge option 14 | ## otherwise during `release-upgrade` postrm script might run, 15 | ## delete sclockadj while sdwdate is still running 16 | rm --force /usr/libexec/sdwdate/sclockadj 17 | 18 | rm --force "/var/log/sdwdate.log" 19 | rm -r --force "/var/cache/sdwdate" 20 | fi 21 | 22 | #DEBHELPER# 23 | -------------------------------------------------------------------------------- /debian/source/format: -------------------------------------------------------------------------------- 1 | 3.0 (quilt) 2 | -------------------------------------------------------------------------------- /debian/source/lintian-overrides: -------------------------------------------------------------------------------- 1 | ## https://phabricator.whonix.org/T277 2 | debian-watch-does-not-check-openpgp-signature 3 | -------------------------------------------------------------------------------- /debian/watch: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2012 - 2025 ENCRYPTED SUPPORT LLC 2 | ## See the file COPYING for copying conditions. 3 | 4 | version=4 5 | opts=filenamemangle=s/.+\/v?(\d\S+)\.tar\.gz/sdwdate-$1\.tar\.gz/ \ 6 | https://github.com/Whonix/sdwdate/tags .*/v?(\d\S+)\.tar\.gz 7 | -------------------------------------------------------------------------------- /etc/apparmor.d/abstractions/url_to_unixtime: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2017 - 2025 ENCRYPTED SUPPORT LLC 2 | ## See the file COPYING for copying conditions. 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | /usr/bin/ r, 10 | /usr/bin/url_to_unixtime rix, 11 | ## Once no new privs issue is resolved, can downgrade to this: 12 | ## /usr/bin/url_to_unixtime r, 13 | 14 | ## https://forums.whonix.org/t/sdwdate-and-sdwdate-gui-development-thread/1137/372 15 | deny @{HOME}/** rwm, 16 | #deny /home/** rwm, 17 | deny /tmp/** rwm, 18 | deny /var/tmp/** rwm, 19 | #deny /usr/bin/** rwx, 20 | deny /sbin/** rwx, 21 | deny @{PROC}/** r, 22 | deny /usr/bin/python3.9 r, 23 | ## Related to compilation to byte code? 24 | ## AVC apparmor="DENIED" operation="exec" profile="/usr/bin/sdwdate" name="/usr/sbin/ldconfig" comm="sdwdate" requested_mask="x" denied_mask="x" 25 | deny /usr/sbin/ldconfig rx, 26 | 27 | # TCP/UDP network access (to access Tor's SOCKS port) (only needed on Bookworm and later) 28 | network inet stream, 29 | network inet6 stream, 30 | network inet dgram, 31 | network inet6 dgram, 32 | -------------------------------------------------------------------------------- /etc/apparmor.d/usr.bin.sdwdate: -------------------------------------------------------------------------------- 1 | # Last Modified: Thu Sep 23 15:22:11 2021 2 | #include 3 | 4 | ## Copyright (C) 2012 - 2025 ENCRYPTED SUPPORT LLC 5 | ## See the file COPYING for copying conditions. 6 | 7 | 8 | /usr/bin/sdwdate flags=(attach_disconnected) { 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | capability sys_time, 16 | 17 | signal receive set=cont, 18 | signal receive set=term, 19 | signal send set=term peer=/usr/bin/sdwdate//null-/usr/bin/url_to_unixtime, 20 | 21 | deny /usr/sbin/ldconfig rx, 22 | 23 | deny /etc/nsswitch.conf r, 24 | deny /etc/passwd r, 25 | /etc/sdwdate.d/ r, 26 | /etc/sdwdate.d/** r, 27 | /etc/tor/ r, 28 | /etc/tor/** r, 29 | /run/tor/control.authcookie r, 30 | /tmp/* mrw, 31 | /tmp/** mrw, 32 | /usr/lib/python3/dist-packages/sdwdate/timesanitycheck.py rix, 33 | /usr/libexec/helper-scripts/ r, 34 | /usr/libexec/helper-scripts/** r, 35 | /usr/libexec/helper-scripts/onion-time-pre-script rix, 36 | /usr/libexec/helper-scripts/settings_echo mrix, 37 | /usr/libexec/helper-scripts/tor_bootstrap_check.bsh mrix, 38 | /usr/libexec/helper-scripts/tor_bootstrap_check.py mrix, 39 | /usr/libexec/helper-scripts/tor_consensus_valid-after.py mrix, 40 | /usr/libexec/helper-scripts/tor_consensus_valid-until.py mrix, 41 | /usr/libexec/sdwdate/sclockadj rix, 42 | /usr/sbin/anondate-get rUx, 43 | /usr/share/timesanitycheck/minimum_unixtime r, 44 | /usr/share/tor/tor-service-defaults-torrc r, 45 | /usr/share/tor/tor-service-defaults-torrc.anondist r, 46 | /usr/share/translations/sdwdate.yaml r, 47 | /var/lib/sdwdate/ rw, 48 | /var/lib/sdwdate/time-replay-protection-utc-humanreadable rw, 49 | /var/lib/sdwdate/time-replay-protection-utc-unixtime rw, 50 | /{,usr/local/}etc/torrc.d/ r, 51 | /{,usr/local/}etc/torrc.d/** r, 52 | /{,usr/}bin/ r, 53 | /{,usr/}bin/bash ix, 54 | /{,usr/}bin/cat mrix, 55 | /{,usr/}bin/dash mrix, 56 | /{,usr/}bin/date mrix, 57 | /{,usr/}bin/minimum-unixtime-show rix, 58 | /{,usr/}bin/mktemp mrix, 59 | /{,usr/}bin/ps rix, 60 | /{,usr/}bin/python3.9 rix, 61 | /{,usr/}bin/qubesdb-cmd rix, 62 | /{,usr/}bin/qubesdb-read rix, 63 | /{,usr/}bin/rm mrix, 64 | /{,usr/}bin/sdwdate r, 65 | /{,usr/}bin/sleep rix, 66 | /{,usr/}bin/timeout mrix, 67 | /{,usr/}bin/timesanitycheck rix, 68 | /{,usr/}bin/tor-circuit-established-check rix, 69 | /{,usr/}bin/uname rix, 70 | /{,usr/}bin/whoami rix, 71 | /{,usr/}bin/id rix, 72 | /{,usr/}bin/touch mrix, 73 | @{PROC}/ r, 74 | @{PROC}/*/stat r, 75 | @{PROC}/sys/kernel/osrelease r, 76 | @{PROC}/uptime r, 77 | @{PROC}/uptime r, 78 | ## TODO: 'owner' keyword needed? 79 | ## Was breaking 'touch /run/sdwdate/onion-time-script-after-boot'? (As run by onion-time-pre-script.) 80 | ## https://forums.whonix.org/t/sdwdate-broken-on-virtualbox-whonix/12800/2 81 | /run/sdwdate/ rw, 82 | /run/sdwdate/** rw, 83 | /run/anondate/ rw, 84 | /run/anondate/** rw, 85 | deny /var/lib/sdwdate-forbidden-temp/** mrwlk, 86 | owner /usr/lib/python3/dist-packages/sdwdate/__pycache__/ rw, 87 | owner /usr/lib/python3/dist-packages/sdwdate/__pycache__/** rw, 88 | owner @{PROC}/*/fd/ r, 89 | owner @{PROC}/*/mounts r, 90 | owner @{PROC}/*/status r, 91 | 92 | } 93 | -------------------------------------------------------------------------------- /etc/apparmor.d/usr.bin.url_to_unixtime: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2017 - 2025 ENCRYPTED SUPPORT LLC 2 | ## See the file COPYING for copying conditions. 3 | 4 | #include 5 | 6 | /usr/bin/url_to_unixtime flags=(attach_disconnected) { 7 | #include 8 | 9 | # Site-specific additions and overrides. See local/README for details. 10 | #include 11 | } 12 | -------------------------------------------------------------------------------- /etc/privleap/conf.d/sdwdate.conf: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2025 - 2025 ENCRYPTED SUPPORT LLC 2 | ## See the file COPYING for copying conditions. 3 | 4 | [action:sdwdate-clock-jump] 5 | Command=/usr/sbin/sdwdate-clock-jump 6 | AuthorizedGroups=sudo 7 | AuthorizedUsers=user 8 | 9 | [action:sdwdate-libexec] 10 | Command=/usr/libexec/sdwdate/sdwdate 11 | TargetUser=sdwdate 12 | AuthorizedGroups=sudo 13 | AuthorizedUsers=user 14 | 15 | [action:start-sdwdate] 16 | Command=/bin/systemctl --no-pager --no-block start sdwdate 17 | AuthorizedGroups=sudo 18 | AuthorizedUsers=user 19 | 20 | [action:restart-sdwdate] 21 | Command=/bin/systemctl --no-pager --no-block restart sdwdate 22 | AuthorizedGroups=sudo 23 | AuthorizedUsers=user 24 | 25 | [action:stop-sdwdate] 26 | Command=/bin/systemctl --no-pager --no-block stop sdwdate 27 | AuthorizedGroups=sudo 28 | AuthorizedUsers=user 29 | 30 | [action:sdwdate-log-viewer] 31 | Command=/usr/bin/sdwdate-log-viewer 32 | AuthorizedGroups=sudo 33 | AuthorizedUsers=user 34 | 35 | [persistent-users] 36 | User=sdwdate 37 | -------------------------------------------------------------------------------- /etc/qubes/suspend-post.d/30_sdwdate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ## Copyright (C) 2017 - 2025 ENCRYPTED SUPPORT LLC 4 | ## See the file COPYING for copying conditions. 5 | 6 | #### meta start 7 | #### project Whonix 8 | #### category networking and time 9 | #### description 10 | ## hook to run /usr/libexec/sdwdate/suspend-post 11 | ## in Qubes-Whonix. 12 | #### meta end 13 | 14 | set -e 15 | 16 | /usr/libexec/sdwdate/suspend-post 17 | -------------------------------------------------------------------------------- /etc/qubes/suspend-pre.d/30_sdwdate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ## Copyright (C) 2017 - 2025 ENCRYPTED SUPPORT LLC 4 | ## See the file COPYING for copying conditions. 5 | 6 | #### meta start 7 | #### project Whonix 8 | #### category networking and time 9 | #### description 10 | ## hook to run /usr/libexec/sdwdate/suspend-pre 11 | ## in Qubes-Whonix. 12 | #### meta end 13 | 14 | set -e 15 | 16 | /usr/libexec/sdwdate/suspend-pre 17 | -------------------------------------------------------------------------------- /etc/rsyslog.d/sdwdate.conf: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2012 - 2025 ENCRYPTED SUPPORT LLC 2 | ## See the file COPYING for copying conditions. 3 | 4 | ## systemd spams syslog due to time changed by sclockadj 5 | ## https://github.com/Whonix/Whonix/issues/289 6 | 7 | ## Thanks to slm (http://unix.stackexchange.com/users/7453/slm) for the post on 8 | ## http://unix.stackexchange.com/a/151652/49297 9 | 10 | :msg, contains, "Time has been changed" stop 11 | -------------------------------------------------------------------------------- /etc/sdwdate.d/30_default.conf: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2012 - 2025 ENCRYPTED SUPPORT LLC 2 | ## See the file COPYING for copying conditions. 3 | 4 | ## Please use "/etc/sdwdate.d/50_user.conf" for your custom 5 | ## configuration, which will override the defaults found here. 6 | ## When sdwdate is updated, this file may be overwritten. 7 | 8 | ## Proxy settings for non anonymous distributions. 9 | ## Uncomment for standard tor configuration (no stream isolation). 10 | #PROXY_IP=127.0.0.1 11 | #PROXY_PORT=9050 12 | 13 | ## Allowed percentage of url failures common to every pool. 14 | ## If sdwdate frequently stops with "Maximum allowed number of failures" error, 15 | ## create a file "/etc/sdwdate.d/50_user.conf" overriding MAX_FAILURE_RATIO 16 | ## with a higher figure. 17 | MAX_FAILURE_RATIO=0.34 18 | 19 | ## Add or subtract a random amount of nanoseconds (up to 1 second) when setting 20 | ## the time. 21 | ## Whonix enables this by default in package anon-apps-config. 22 | #RANDOMIZE_TIME=true 23 | 24 | ## If the same organization hosts multiple onion services, these must be 25 | ## grouped together as one. 26 | ## See the riseup example. The syntax is is an extra: 27 | ## [ 28 | ## ] 29 | 30 | ## https://www.whonix.org/wiki/Sdwdate#sdwdate_Time_Sources_Criteria 31 | ## https://www.whonix.org/wiki/Sdwdate#Comment_Field_Rules 32 | ## https://forums.whonix.org/t/sdwdate-time-sources-criteria/11035 33 | ## https://forums.whonix.org/t/suggest-trustworthy-tor-hidden-services-as-time-sources-for-sdwdate/856 34 | 35 | ## pool syntax 36 | ## "url.onion[:port] # comment" 37 | ## " 38 | ## url.onion[:port] # comment 39 | ## [url.onion[:port] # comment] 40 | ## [url.onion[:port] # comment] 41 | ## [...] 42 | ## " 43 | ## "url.onion[:port] # comment" 44 | ## ... 45 | 46 | ## 20 47 | SDWDATE_POOL_ZERO=( 48 | "http://p53lf57qovyuvwsc6xnrppyply3vtqm7l6pcobkmyqsiofyeznfu5uqd.onion # https://web.archive.org/web/20200905091808/https://securityheaders.com/?q=https%3A%2F%2Fwww.propublica.org&followRedirects=off" 49 | "https://www.bbcweb3hytmzhn5d532owbu6oqadra5z3ar726vq5kgwwn6aucdccrad.onion # https://web.archive.org/web/20220326121137/https://www.bbc.com/news/technology-50150981" 50 | "https://www.nytimesn7cgmftshazwhfgzm37qxb44r64ytbb2dj3x62d2lljsciiyd.onion # nytimes onion mirror https://archive.ph/750Dh" 51 | "https://dlegal66uj5u2dvcbrev7vv6fjtwnd4moqu7j6jnd42rmbypv3coigyd.onion # https://web.archive.org/web/20210604191414/https://securityheaders.com/?q=https%3A%2F%2Fdecoded.legal%2F&followRedirects=on" 52 | "https://duckduckgogg42xjoc72x3sjasowoarfbgcmvfimaftt6twagswzczad.onion # https://web.archive.org/web/20210604193342/https://securityheaders.com/?q=https%3A%2F%2Fduckduckgo.com%2F&followRedirects=on" 53 | "https://protonmailrmez3lotccipshtkleegetolb73fuirgj7r4o4vfu7ozyd.onion # https://web.archive.org/web/20221025201520/https://proton.me/tor" 54 | "https://ej3kv4ebuugcmuwxctx5ic7zxh73rnxt42soi3tdneu2c2em55thufqd.onion # https://web.archive.org/web/20210604165016/https://securedrop.org/directory/new-york-times/" 55 | "https://vfnmxpa6fo4jdpyq3yneqhglluweax2uclvxkytfpmpkp5rsl75ir5qd.onion # https://web.archive.org/web/20210604171305/https://securedrop.org/directory/washington-post/" 56 | "http://archiveiya74codqgiixo33q62qlrqtkgmcitqx5u2oeqnmn5bpcbiyd.onion # https://web.archive.org/web/20220204131212/https://en.wikipedia.org/wiki/Archive.today" 57 | "http://537ztcntpbmspja4mkpxldpsoc46mqlssnsaklqnfw3gnlpj5glcjgid.onion # https://web.archive.org/web/20210525164508/https://www.nrk.no/varsle/ https://www.nrk.no/varsle/ Varsle NRK" 58 | "http://danielas3rtn54uwmofdo3x2bsdifr47huasnmbgqzfrec5ubupvtpid.onion # https://web.archive.org/web/20201231025809/https://danwin1210.me https://danwin1210.me Danial Services" 59 | "http://wasabiukrxmkdgve5kynjztuovbg43uxcbcxn6y2okcrsg7gb6jdmbad.onion # https://web.archive.org/web/20210604175753/https://wasabiwallet.io/" 60 | "http://blkchairbknpn73cfjhevhla7rkp4ed5gg2knctvv7it4lioy22defid.onion # https://web.archive.org/web/20210604180615/https://blockchair.com/" 61 | [ 62 | "http://g7ejphhubv5idbbu3hb3wawrs5adw7tkx7yjabnf65xtzztgg4hcsqqd.onion # https://web.archive.org/web/20210604184215/https://defcon.org/" 63 | "http://m6rqq6kocsyugo2laitup5nn32bwm3lh677chuodjfmggczoafzwfcad.onion # https://web.archive.org/web/20210604184215/https://defcon.org/" 64 | "https://ezdhgsy2aw7zg54z6dqsutrduhl22moami5zv2zt6urr6vub7gs6wfad.onion # https://web.archive.org/web/20230924182800/https://securityheaders.com/?q=https%3A%2F%2Fforum.defcon.org%2F&followRedirects=on" 65 | ] 66 | "http://offprivqqdxfmssktx3y5h3miqvceq6yy37s5sxkhz4mojvsz74ohqid.onion # https://web.archive.org/web/20210604190115/https://www.offensiveprivacy.com/" 67 | "http://stormwayszuh4juycoy4kwoww5gvcu2c4tdtpkup667pdwe4qenzwayd.onion # https://web.archive.org/web/20210604190703/https://cryptostorm.is/" 68 | "http://monerotoruzizulg5ttgat2emf4d6fbmiea25detrmmy7erypseyteyd.onion # https://web.archive.org/web/20210604192249/https://www.getmonero.org/" 69 | "http://tv54samlti22655ohq3oaswm64cwf7ulp6wzkjcvdla2hagqcu7uokid.onion # https://web.archive.org/web/20210604192729/https://matt.traudt.xyz/" 70 | "http://metagerv65pwclop2rsfzg4jwowpavpwd6grhhlvdgsswvo6ii4akgyd.onion # https://web.archive.org/web/20210604193010/https://metager.org/tor" 71 | ) 72 | 73 | ## 18 74 | SDWDATE_POOL_ONE=( 75 | "http://zkaan2xfbuxia2wpf7ofnkbz6r5zdbbvxbunvp5g2iebopbfc4iqmbad.onion # https://web.archive.org/web/20210607180626/https://keys.openpgp.org/about/faq" 76 | "http://lxjacvxrozjlxd7pqced7dyefnbityrwqjosuuaqponlg3v7esifrzad.onion # https://web.archive.org/web/20210123173459/https://securityheaders.com/?q=securityinabox.org&followRedirects=on https://securityinabox.org/en/" 77 | "http://searxspbitokayvkhzhsnljde7rqmn7rvoga6e4waeub3h7ug3nghoad.onion # https://web.archive.org/web/20210525165705/https://searx.space/ https://searx.space" 78 | "http://lldan5gahapx5k7iafb3s4ikijc4ni7gx5iywdflkba5y2ezyg6sjgyd.onion # https://web.archive.org/web/20210310145458/https://onionshare.org/onion.txt OnionShare onionshare.org" 79 | "http://t3qi4hdmvqo752lhyglhyb5ysoutggsdocmkxhuojfn62ntpcyydwmqd.onion # https://web.archive.org/web/20200904001100/https://torstatus.rueckgr.at/ https://torstatus.rueckgr.at " 80 | [ 81 | "http://7sk2kov2xwx6cbc32phynrifegg6pklmzs7luwcggtzrnlsolxxuyfyd.onion # https://web.archive.org/web/20210111100825/https://www.systemli.org/service/onion/ https://www.systemli.org" 82 | "http://llqiiswupgezsco4ux47cco3bxsaihbss5c3piefv6bhvpgfofyk7kad.onion # https://web.archive.org/web/20200825072459/https://www.systemli.org/en/service/mail.html https://www.systemli.org/en/service/mail.html https://mail.systemli.org" 83 | "http://mjrkrqnlf26etelsi7zpkqc3dzlrzyurvmd3jksmndarzzbugz5xctid.onion # https://web.archive.org/web/20191025120405/https://www.systemli.org/en/service/etherpad.html https://www.systemli.org/en/service/etherpad.html https://pad.systemli.org" 84 | ] 85 | "http://fpfjxcrmw437h6z2xl3w4czl55kvkmxpapg37bbopsafdu7q454byxid.onion # https://web.archive.org/web/20210126151401/https://securityheaders.com/?q=freedom.press&followRedirects=on https://freedom.press" 86 | [ 87 | "http://7fgb4sq435vg7slw3u7m2ayze3imybpe7qm3htdklreoag3l6n2mtkyd.onion # https://web.archive.org/web/20210430195930/https://onion.debian.org/" 88 | "http://iebkxzjscv4jgaucepdbdf4b7bqmcwd5peulm5cbpoavlsnkfhda5gyd.onion # https://web.archive.org/web/20210430195930/https://onion.debian.org/" 89 | "http://r6ogx3w3s6rg3gxm3kprurn77z2oim665yr5pcxhr76yit4g65y76zad.onion # https://web.archive.org/web/20210430195930/https://onion.debian.org/" 90 | ] 91 | "http://xp44cagis447k3lpb4wwhcqukix6cgqokbuys24vmxmbzmaq2gjvc2yd.onion # https://web.archive.org/web/20210524142637/https://www.theguardian.com/securedrop The Guardian(securedrop)" 92 | [ 93 | "http://vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd.onion # https://web.archive.org/web/20200717041213/https://riseup.net/en/security/network-security/tor https://riseup.net/en/security/network-security/tor https://riseup.net" 94 | "http://7sbw6jufrirhyltzkslhcmkik4z7yrsmbpnptyritvz5nhbk35hncsqd.onion # https://web.archive.org/web/20200717041213/https://riseup.net/en/security/network-security/tor https://riseup.net/en/security/network-security/tor https://lists.riseup.net" 95 | "http://5gdvpfoh6kb2iqbizb37lzk2ddzrwa47m6rpdueg2m656fovmbhoptqd.onion # https://web.archive.org/web/20200717041213/https://riseup.net/en/security/network-security/tor https://mail.riseup.net https://riseup.net/en/security/network-security/tor" 96 | "http://kfahv6wfkbezjyg4r6mlhpmieydbebr5vkok5r34ya464gqz6c44bnyd.onion # https://web.archive.org/web/20200717041213/https://riseup.net/en/security/network-security/tor https://pad.riseup.net https://riseup.net/en/security/network-security/tor" 97 | "http://3xeiol2bnhrsqhcsaifwtnlqkylrerdspzua7bcjrh26qlrrrctfobid.onion # https://web.archive.org/web/20200717041213/https://riseup.net/en/security/network-security/tor https://account.riseup.net https://riseup.net/en/security/network-security/tor" 98 | "http://zkdppoahhqu5ihjqd4qqvyfd2bm4wejrhjosim67t6yopl77jitg2nad.onion # https://web.archive.org/web/20200717041213/https://riseup.net/en/security/network-security/tor https://we.riseup.net https://riseup.net/en/security/network-security/tor" 99 | ] 100 | ) 101 | 102 | ## 33 103 | SDWDATE_POOL_TWO=( 104 | "http://sdolvtfhatvsysc6l34d65ymdwxcujausv7k5jk4cy5ttzhjoi6fzvyd.onion # https://web.archive.org/web/20201217013835/https://securedrop.org/ https://securedrop.org" 105 | "http://cy6wj77vryhcyh6go576hxycjz4wxlo4s5vevdinkw3armwzty5jozyd.onion # https://web.archive.org/web/20210604172437/https://securedrop.org/directory/2600-hacker-quarterly/" 106 | "http://dqa4zahticcobfq5rmmmbewbdtyiznbl75hu23k4i37y7yfoosrh7mqd.onion # https://web.archive.org/web/20221010170235/https://securedrop.org/directory/abc/" 107 | "http://tiykfvhb562gheutfnedysnhrxpxoztyszkqyroloyepwzxmxien77id.onion # https://web.archive.org/web/20210604162929/https://securedrop.org/directory/aftenposten-as/" 108 | "http://xm33ge4kupk5o66eqxcd2r4fqcplpqb2sbdduf5z2nw4g2jrxe57luid.onion # https://web.archive.org/web/20210604172805/https://securedrop.org/directory/aftonbladet/" 109 | "http://33buewrpzrfpttl7kerqvtvzyo3ivumilwwmeqjryzajusltibaqc6ad.onion # https://web.archive.org/web/20221010172440/https://securedrop.org/directory/bloomberg-law/" 110 | "http://ogdwaroarq4p6rnfn2hl4crvldyruyc2g24435qtxmd3twhevg7dsqid.onion # https://web.archive.org/web/20210604173144/https://securedrop.org/directory/bloomberg-news/" 111 | "http://qmifwf762qftydprw2adbg7hs2mkunac5xrz3cb5busaflji3rja5lid.onion # https://web.archive.org/web/20221010173040/https://securedrop.org/directory/cnn/" 112 | "http://fg25fqpu2dnxp24xs3jlcley4hp2inshpzek44q3czkhq3zffoqk26id.onion # https://web.archive.org/web/20221010174048/https://securedrop.org/directory/forbidden-stories/" 113 | "http://537ztcntpbmspja4mkpxldpsoc46mqlssnsaklqnfw3gnlpj5glcjgid.onion # https://web.archive.org/web/20210604165129/https://securedrop.org/directory/nrk/" 114 | "http://z4gd5t2g6u6kqeqjeddvmvlhhjtjgslg4elh4ztnct7snskcd7phbiyd.onion # https://web.archive.org/web/20210605192911/https://securedrop.org/directory/public-intelligence/ https://web.archive.org/web/20210501123001/https://publicintelligence.net/contribute/" 115 | "http://4beybcv5e7xya4xu2nzdqkohawm32imugjtatkvmp2xwgfhcoj64slid.onion # https://web.archive.org/web/20221010183334/https://securedrop.org/directory/stavanger-aftenblad/" 116 | "http://jxsb4ovmavjy3r64bak4ha63xwggf3nzf3vikvs23r2avm5rhzmaqtqd.onion # https://web.archive.org/web/20210605193446/https://securedrop.org/directory/stefania-maurizi/" 117 | "http://udhauo3m3fh7v6yfiuornjzxn3fh6vlp4ooo3wogvghcnv5xik6mnayd.onion # https://web.archive.org/web/20210604170717/https://securedrop.org/directory/s%C3%BCddeutsche-zeitung/" 118 | "http://a4zum5ydurvljrohxqp2rjjal5kro4ge2q2qizuonf2jubkhcr627gad.onion # https://web.archive.org/web/20210604171039/https://securedrop.org/directory/globe-and-mail/" 119 | "http://xp44cagis447k3lpb4wwhcqukix6cgqokbuys24vmxmbzmaq2gjvc2yd.onion # https://web.archive.org/web/20221010185044/https://securedrop.org/directory/guardian/" 120 | ) 121 | -------------------------------------------------------------------------------- /etc/sdwdate.d/qubes-sync-time-disabled-by-sdwdate.marker: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2022 - 2025 ENCRYPTED SUPPORT LLC 2 | ## See the file COPYING for copying conditions. 3 | 4 | ## This is just a marker file. 5 | -------------------------------------------------------------------------------- /etc/sudoers.d/sdwdate: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2012 - 2025 ENCRYPTED SUPPORT LLC 2 | ## See the file COPYING for copying conditions. 3 | 4 | user ALL=NOPASSWD: /usr/sbin/sdwdate-clock-jump 5 | %sudo ALL=NOPASSWD: /usr/sbin/sdwdate-clock-jump 6 | -------------------------------------------------------------------------------- /make-helper-overrides.bsh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ## Copyright (C) 2020 - 2025 ENCRYPTED SUPPORT LLC 4 | ## See the file COPYING for copying conditions. 5 | 6 | genmkfile_lintian_post_opts+=" --suppress-tags no-manual-page " 7 | -------------------------------------------------------------------------------- /man/sdwdate.8.ronn: -------------------------------------------------------------------------------- 1 | sdwdate(8) -- Secure Distributed Web Date 2 | ============================================= 3 | 4 | 8 | 9 | ## SYNOPSIS 10 | `sdwdate` 11 | 12 | ## DESCRIPTION 13 | Builds mediate time by asking three onion servers from three different pools. 14 | 15 | ## OPTIONS 16 | None. 17 | 18 | ## ENVIRONMENT VARIABLES 19 | None. 20 | 21 | ## CONFIG FILE 22 | Read the comments in `/etc/sdwdate.d/30_default.conf`. 23 | 24 | ## EXIT CODES 25 | 0 Success. 26 | 27 | 143 Signal sigterm received. 28 | 29 | Other Error. 30 | 31 | ## SIGNALS 32 | 33 | * sigterm 34 | 35 | Clean up and exit. 36 | 37 | Examples: 38 | 39 | `sudo kill -s sigterm "$(cat "/run/sdwdate/pid")"` 40 | 41 | ## EXAMPLES 42 | If you installed `sdwdate` from your distribution's repository, it should be 43 | already pre-configured to automatically run as daemon with sane defaults. 44 | 45 | ## WWW 46 | https://www.whonix.org/wiki/sdwdate 47 | 48 | ## CREDITS 49 | * sdwdate is a rewrite of tails_htp in python 50 | * options and defaults inspired by tails_htp 51 | * log file layout inspired by tails_htp 52 | 53 | ## AUTHOR 54 | This man page has been written by Patrick Schleizer (adrelanos@whonix.org). 55 | -------------------------------------------------------------------------------- /usr/bin/sdwdate: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ## Copyright (C) 2022 - 2025 ENCRYPTED SUPPORT LLC 4 | ## See the file COPYING for copying conditions. 5 | 6 | ## The systemd unit file /lib/systemd/system/sdwdate.service does not use this 7 | ## script. It starts /usr/libexec/sdwdate/sdwdate directly. 8 | 9 | set -x 10 | 11 | set -e 12 | 13 | true "INFO $0: START" 14 | 15 | echo "WARNING: Starting sdwdate from command line by the user is unsupported, for more information, see:" 16 | echo "https://www.kicksecure.com/wiki/Dev/sdwdate#sdwdate_linux_user_account" 17 | 18 | ## Not using exec to be able to see this script in "ps aux". 19 | leaprun sdwdate-libexec 20 | 21 | true "INFO $0: END" 22 | -------------------------------------------------------------------------------- /usr/bin/sdwdate-log-viewer: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ## Copyright (C) 2018 - 2025 ENCRYPTED SUPPORT LLC 4 | ## See the file COPYING for copying conditions. 5 | 6 | set -x 7 | 8 | set -e 9 | 10 | true "INFO $0: START" 11 | 12 | ## goal of this sdwdate log viewer: 13 | ## - show the following systemd units: 14 | ## qubes-sync-time.service 15 | ## qubes-sync-time.timer 16 | ## bootclockrandomization.service 17 | ## sdwdate.service 18 | ## whonix-firewall.service 19 | ## - include seccomp log output for these units 20 | ## - also show the following syslog identifiers 21 | ## suspend-pre 22 | ## suspend-post 23 | ## anondate 24 | 25 | ## Quote journalctl man page: 26 | ## "If two different fields are matched, only entries matching both expressions 27 | ## at the same time are shown:" 28 | 29 | ## Does not work. If combined, systemd is not showing seccomp failures. 30 | ## Only 'journalctl --unit' shows, quote from journalctl man page: 31 | ## "along with additional matches for messages from systemd and messages 32 | ## about coredumps for the specified unit" 33 | ## 34 | ## But using 'journalctl --unit' cannot be combined with 'SYSLOG_IDENTIFIER'. 35 | ## 36 | # /bin/journalctl \ 37 | # --boot \ 38 | # --output cat \ 39 | # -n 10000 \ 40 | # -f \ 41 | # _SYSTEMD_UNIT=qubes-sync-time.service + \ 42 | # _SYSTEMD_UNIT=qubes-sync-time.timer + \ 43 | # _SYSTEMD_UNIT=bootclockrandomization.service + \ 44 | # _SYSTEMD_UNIT=sdwdate.service + \ 45 | # _SYSTEMD_UNIT=whonix-firewall.service + \ 46 | # SYSLOG_IDENTIFIER=suspend-pre + \ 47 | # SYSLOG_IDENTIFIER=suspend-post + \ 48 | # SYSLOG_IDENTIFIER=anondate 49 | 50 | ## Does not work because would only show units that also contain the 51 | ## syslog identifier. 52 | # /bin/journalctl \ 53 | # --boot \ 54 | # --output cat \ 55 | # -n 10000 \ 56 | # -f \ 57 | # --unit=qubes-sync-time.service \ 58 | # --unit=qubes-sync-time.timer \ 59 | # --unit=bootclockrandomization.service \ 60 | # --unit=sdwdate.service \ 61 | # --unit=whonix-firewall.service \ 62 | # --identifier=suspend-pre \ 63 | # --identifier=suspend-post \ 64 | # --identifier=anondate 65 | 66 | ## Launching two different journalctl commands into the background is also not 67 | ## great since these mess up the order of the log output. 68 | 69 | ## Approach using grep: 70 | ## https://forums.whonix.org/t/sdwdate-loop-conclusion-tor-already-reports-circuit-established-seccomp-issue/13260/13 71 | ## This has the disadvantage of catching too many irrelevant messages such as 72 | ## by pam_unix for user sdwdate and more importantly, lacks multi-line messages 73 | ## that do not contain a string being 'grep'ed for. 74 | # /bin/journalctl \ 75 | # --boot \ 76 | # --output cat \ 77 | # -n 10000 \ 78 | # -f \ 79 | # | \ 80 | # grep \ 81 | # --color \ 82 | # "sdwdate\|bootclockrandomization\|anondate\|firewall\|suspend-pre\|suspend-post" 83 | 84 | ## Use '--boot' to avoid confusion from showing previous boot inside Qubes 85 | ## TemplateVM. 86 | ## 87 | ## The following approach has the disadvantage of showing all seccomp related 88 | ## messages not just those related to the units that should be watched here but 89 | ## is better than other approaches from above. 90 | /bin/journalctl \ 91 | --boot \ 92 | --output cat \ 93 | --no-pager \ 94 | -f \ 95 | -n 10000 \ 96 | _SYSTEMD_UNIT=qubes-sync-time.service + \ 97 | _SYSTEMD_UNIT=qubes-sync-time.timer + \ 98 | _SYSTEMD_UNIT=timesanitycheck.service + \ 99 | _SYSTEMD_UNIT=bootclockrandomization.service + \ 100 | _SYSTEMD_UNIT=sdwdate.service + \ 101 | _SYSTEMD_UNIT=whonix-firewall.service + \ 102 | SYSLOG_IDENTIFIER=suspend-pre + \ 103 | SYSLOG_IDENTIFIER=suspend-post + \ 104 | SYSLOG_IDENTIFIER=anondate + \ 105 | _AUDIT_TYPE_NAME=SECCOMP 106 | -------------------------------------------------------------------------------- /usr/bin/url_to_unixtime: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 -su 2 | 3 | ## Copyright (C) 2015 troubadour 4 | ## Copyright (C) 2015 - 2025 ENCRYPTED SUPPORT LLC 5 | ## See the file COPYING for copying conditions. 6 | 7 | ## Syntax: 8 | ## url_to_unixtime socket_ip socket_port url verbosity 9 | 10 | ## Examples: 11 | ## url_to_unixtime 127.0.0.1 9050 http://check.torproject.org 80 true 12 | ## url_to_unixtime 127.0.0.1 9050 https://check.torproject.org 80 true 13 | ## url_to_unixtime 127.0.0.1 9050 http://2gzyxa5ihm7nsggfxnu52rck2vv4rvmdlkiu3zzui5du4xyclen53wid.onion 80 false 14 | ## url_to_unixtime 127.0.0.1 9050 https://p53lf57qovyuvwsc6xnrppyply3vtqm7l6pcobkmyqsiofyeznfu5uqd.onion 80 false 15 | 16 | ## prints debug and errors to stderr 17 | ## prints unixtime to stdout 18 | 19 | # !/bin/bash 20 | # Test. 21 | # timeout --kill-after 1 1 cat /dev/random 22 | # timeout --kill-after 1 1 cat /dev/random >&2 23 | # echo abcdefghij 24 | 25 | import sys 26 | sys.dont_write_bytecode = True 27 | 28 | import os, time, requests 29 | from dateutil.parser import parse 30 | 31 | os.environ['LC_TIME'] = 'C' 32 | os.environ['TZ'] = 'UTC' 33 | time.tzset() 34 | 35 | 36 | def data_to_http_time(data): 37 | http_time = data.headers["Date"] 38 | 39 | ## Test ################### 40 | #http_time = http_time[:28] 41 | ########################### 42 | 43 | http_time_string_length = len(http_time) 44 | 45 | ## min string length = max string length. 46 | if http_time_string_length < 29: 47 | print('HTTP header date string too short.', file=sys.stderr) 48 | print('HTTP header date length: {}'.format(http_time_string_length), file=sys.stderr) 49 | print('HTTP header data:\n{}'.format(data), file=sys.stderr) 50 | print('HTTP header date value: "{}"'.format(http_time), file=sys.stderr) 51 | sys.exit(2) 52 | 53 | if http_time_string_length > 100: 54 | print('HTTP header date string too long.', file=sys.stderr) 55 | print('HTTP header date length: {}'.format(http_time_string_length), file=sys.stderr) 56 | print('HTTP header data:\n{}'.format(data), file=sys.stderr) 57 | print('HTTP header date value: "{}"'.format(http_time), file=sys.stderr) 58 | sys.exit(2) 59 | 60 | return http_time 61 | 62 | def unixtime_sanity_check(data, http_time, parsed_unixtime): 63 | try: 64 | unixtime_digit = int(parsed_unixtime) 65 | 66 | except ValueError: 67 | print('parsed_unixtime conversion failed!', file=sys.stderr) 68 | print('data: {}'.format(data), file=sys.stderr) 69 | print('http_time: {}'.format(http_time), file=sys.stderr) 70 | print('parsed_unixtime: {}'.format(parsed_unixtime), file=sys.stderr) 71 | print('parsed_unixtime not numeric!', file=sys.stderr) 72 | sys.exit(3) 73 | 74 | if unixtime_digit <= 0: 75 | print('parsed_unixtime is negative!', file=sys.stderr) 76 | print('data: {}'.format(data), file=sys.stderr) 77 | print('http_time: {}'.format(http_time), file=sys.stderr) 78 | print('parsed_unixtime: {}'.format(parsed_unixtime), file=sys.stderr) 79 | print('parsed_unixtime not numeric!', file=sys.stderr) 80 | sys.exit(3) 81 | 82 | unixtime_string_length_is = len(parsed_unixtime) 83 | unixtime_string_length_max = 10 84 | 85 | if unixtime_string_length_is > unixtime_string_length_max: 86 | print('parsed_unixtime conversion failed!', file=sys.stderr) 87 | print('data: {}'.format(data), file=sys.stderr) 88 | print('http_time: {}'.format(http_time), file=sys.stderr) 89 | print('parsed_unixtime: {}'.format(parsed_unixtime), file=sys.stderr) 90 | print('unixtime_string_length_is: {}'.format(unixtime_string_length_is), file=sys.stderr) 91 | print('unixtime_string_length_max: {}'.format(unixtime_string_length_max, file=sys.stderr)) 92 | print('parsed_unixtime has excessive string length!', file=sys.stderr) 93 | sys.exit(4) 94 | 95 | return parsed_unixtime 96 | 97 | def request_data_from_remote_server(socket_ip, socket_port, url): 98 | ## https://gist.github.com/jefftriplett/9748036 99 | ## https://github.com/psf/requests/blob/e3f89bf23c53b98593e4248054661472aacac820/requests/packages/urllib3/contrib/socks.py#L158 100 | 101 | proxy = 'socks5h://' + str(socket_ip) + ':' + str(socket_port) 102 | 103 | proxies = { 104 | 'http': proxy, 105 | 'https': proxy 106 | } 107 | 108 | try: 109 | data = requests.get(url, proxies=proxies) 110 | 111 | ## TODO: test 112 | except Exception as e: 113 | print('connect error: {}'.format(e) , file=sys.stderr) 114 | sys.exit(5) 115 | 116 | return data 117 | 118 | def http_time_to_parsed_unixtime(data, http_time): 119 | ## Test ################################## 120 | #http_time = "something" 121 | ########################################## 122 | 123 | try: 124 | ## Thanks to: 125 | ## eumiro 126 | ## http://stackoverflow.com/a/3894047/2605155 127 | parsed_unixtime = parse(http_time).strftime('%s') 128 | 129 | except ValueError as e: 130 | print('Parsing http_time from server failed!', file=sys.stderr) 131 | print('HTTP header data:\n{}'.format(data), file=sys.stderr) 132 | print('http_time: {}'.format(http_time), file=sys.stderr) 133 | print('dateutil ValueError: {}'.format(e), file=sys.stderr) 134 | sys.exit(6) 135 | 136 | ## Test ################################## 137 | #parsed_unixtime = '%sA' % parsed_unixtime 138 | ########################################## 139 | ## Test ################################## 140 | #parsed_unixtime = '%s1' % parsed_unixtime 141 | ########################################## 142 | return parsed_unixtime 143 | 144 | def parse_command_line_parameters(): 145 | try: 146 | socket_ip = sys.argv[1] 147 | socket_port = int(sys.argv[2]) 148 | url = sys.argv[3] 149 | verbosity = sys.argv[4] 150 | 151 | except IndexError as e: 152 | print("Parsing command line parameter failed. | e: {}".format(e), file=sys.stderr) 153 | print("sys.argv:", str(sys.argv), file=sys.stderr) 154 | sys.exit(7) 155 | 156 | return socket_ip, socket_port, url, verbosity 157 | 158 | def output_unixtime(data, http_time, parsed_unixtime, unixtime, verbosity): 159 | if verbosity == "true": 160 | print('data: {}'.format(data), file=sys.stderr) 161 | print('http_time: {}'.format(http_time), file=sys.stderr) 162 | print('parsed_unixtime: {}'.format(parsed_unixtime), file=sys.stderr) 163 | print('{}'.format(unixtime)) 164 | 165 | def main(): 166 | socket_ip, socket_port, url, verbosity = parse_command_line_parameters() 167 | data = request_data_from_remote_server(socket_ip, socket_port, url) 168 | http_time = data_to_http_time(data) 169 | parsed_unixtime = http_time_to_parsed_unixtime(data, http_time) 170 | unixtime = unixtime_sanity_check(data, http_time, parsed_unixtime) 171 | output_unixtime(data, http_time, parsed_unixtime, unixtime, verbosity) 172 | 173 | if __name__ == "__main__": 174 | main() 175 | -------------------------------------------------------------------------------- /usr/lib/python3/dist-packages/sdwdate/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 -su 2 | 3 | import sys 4 | sys.dont_write_bytecode = True 5 | -------------------------------------------------------------------------------- /usr/lib/python3/dist-packages/sdwdate/config.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 -su 2 | 3 | # Copyright (C) 2017 - 2025 ENCRYPTED SUPPORT LLC 4 | # See the file COPYING for copying conditions. 5 | 6 | # python3 /usr/lib/python3/dist-packages/sdwdate/config.py 0 test 7 | # python3 /usr/lib/python3/dist-packages/sdwdate/config.py 1 test 8 | # python3 /usr/lib/python3/dist-packages/sdwdate/config.py 2 test 9 | ## 10 | # python3 /usr/lib/python3/dist-packages/sdwdate/config.py 0 production 11 | # python3 /usr/lib/python3/dist-packages/sdwdate/config.py 1 production 12 | # python3 /usr/lib/python3/dist-packages/sdwdate/config.py 2 production 13 | 14 | import sys 15 | sys.dont_write_bytecode = True 16 | 17 | import os 18 | import sys 19 | import glob 20 | import re 21 | import random 22 | 23 | 24 | def time_human_readable(unixtime): 25 | from datetime import datetime 26 | human_readable_unixtime = datetime.strftime( 27 | datetime.fromtimestamp(unixtime), "%Y-%m-%d %H:%M:%S" 28 | ) 29 | return human_readable_unixtime 30 | 31 | 32 | def time_replay_protection_file_read(): 33 | import subprocess 34 | process = subprocess.Popen( 35 | "/usr/bin/minimum-unixtime-show", 36 | stdout=subprocess.PIPE, 37 | stderr=subprocess.PIPE, 38 | ) 39 | stdout, stderr = process.communicate() 40 | unixtime = int(stdout) 41 | time_human_readable = stderr.decode("utf-8").strip() 42 | # Relay check to avoid false-positives due to sdwdate inaccuracy. 43 | unixtime = unixtime - 100 44 | return unixtime, time_human_readable 45 | 46 | 47 | def randomize_time_config(): 48 | status = False 49 | if not os.path.exists("/etc/sdwdate.d/"): 50 | return status 51 | files = sorted(glob.glob("/etc/sdwdate.d/*.conf")) 52 | for file_item in files: 53 | with open(file_item) as conf: 54 | lines = conf.readlines() 55 | for line in lines: 56 | if line.startswith("RANDOMIZE_TIME=true"): 57 | status = True 58 | if line.startswith("RANDOMIZE_TIME=false"): 59 | status = False 60 | return status 61 | 62 | 63 | def allowed_failures_config(): 64 | failure_ratio = None 65 | if os.path.exists("/etc/sdwdate.d/"): 66 | files = sorted(glob.glob("/etc/sdwdate.d/*.conf")) 67 | for file_item in files: 68 | with open(file_item) as conf: 69 | lines = conf.readlines() 70 | for line in lines: 71 | if line.startswith("MAX_FAILURE_RATIO"): 72 | failure_ratio = re.search(r"=(.*)", line).group(1) 73 | if failure_ratio is None: 74 | failure_ratio = 0.34 75 | return failure_ratio 76 | 77 | 78 | def allowed_failures_calculate( 79 | failure_ratio, 80 | pools_total_number, 81 | number_of_pool_members): 82 | temp = float(number_of_pool_members) * float(failure_ratio) 83 | allowed_failures_value = temp / pools_total_number 84 | allowed_failures_value = int(allowed_failures_value) 85 | return allowed_failures_value 86 | 87 | 88 | def get_comment(pools, remote): 89 | """ For logging the comments, get the index of the url 90 | to get it from pool.comment. 91 | """ 92 | url_comment = "unknown-comment" 93 | for pool_item in pools: 94 | try: 95 | url_index = pool_item.url.index(remote) 96 | url_comment = pool_item.comment[url_index] 97 | break 98 | except BaseException: 99 | pass 100 | return url_comment 101 | 102 | 103 | def get_comment_pool_single(pool, remote): 104 | url_comment = "unknown-comment" 105 | try: 106 | url_index = pool.url.index(remote) 107 | url_comment = pool.comment[url_index] 108 | except BaseException: 109 | pass 110 | return url_comment 111 | 112 | 113 | def sort_pool(pool, mode): 114 | # Check number of multi-line pool. 115 | number_of_pool_multi = 0 116 | for i in range(len(pool)): 117 | if pool[i] == ('['): 118 | number_of_pool_multi += 1 119 | 120 | # Dynamically create multi-line lists. 121 | multi_list_url = [[] for i in range(number_of_pool_multi)] 122 | multi_list_comment = [[] for i in range(number_of_pool_multi)] 123 | 124 | # Sort... 125 | multi_line = False 126 | multi_index = 0 127 | pool_single_url = [] 128 | pool_single_comment = [] 129 | 130 | for i in range(len(pool)): 131 | if multi_line and pool[i] == ']': 132 | multi_line = False 133 | multi_index = multi_index + 1 134 | 135 | elif multi_line and pool[i].startswith('"'): 136 | url = re.search(r'"(.*)#', pool[i]) 137 | if url is not None: 138 | if mode == 'production': 139 | multi_list_url[multi_index].append(url.group(1).strip()) 140 | elif mode == 'test': 141 | pool_single_url.append(url.group(1).strip()) 142 | comment = re.search(r'#(.*)"', pool[i]) 143 | if comment is not None: 144 | if mode == 'production': 145 | multi_list_comment[multi_index].append(comment.group(1).strip()) 146 | elif mode == 'test': 147 | pool_single_comment.append(comment.group(1).strip()) 148 | 149 | elif pool[i] == '[': 150 | multi_line = True 151 | 152 | elif pool[i].startswith('"'): 153 | url = re.search(r'"(.*)#', pool[i]) 154 | if url is not None: 155 | pool_single_url.append(url.group(1).strip()) 156 | comment = re.search(r'#(.*)"', pool[i]) 157 | if comment is not None: 158 | pool_single_comment.append(comment.group(1).strip()) 159 | 160 | # Pick a random url in each multi-line pool, 161 | # append it to single url pool. 162 | for i in range(number_of_pool_multi): 163 | if mode == 'production': 164 | single_ulr_index = random.sample( 165 | range(len(multi_list_url[i])), 1)[0] 166 | single_url = multi_list_url[i][single_ulr_index] 167 | single_comment = multi_list_comment[i][single_ulr_index] 168 | pool_single_url.append(single_url) 169 | pool_single_comment.append(single_comment) 170 | 171 | return(pool_single_url, pool_single_comment) 172 | 173 | 174 | def read_pools(pool, mode): 175 | SDWDATE_POOL_ZERO = False 176 | SDWDATE_POOL_ONE = False 177 | SDWDATE_POOL_TWO = False 178 | 179 | pool_one = [] 180 | pool_two = [] 181 | pool_three = [] 182 | 183 | pool_one_url = [] 184 | pool_two_url = [] 185 | pool_three_url = [] 186 | 187 | if os.path.exists('/etc/sdwdate.d/'): 188 | files = sorted(glob.glob('/etc/sdwdate.d/*.conf')) 189 | 190 | if files: 191 | conf_found = False 192 | for conf in files: 193 | conf_found = True 194 | with open(conf) as c: 195 | for line in c: 196 | line = line.strip() 197 | if line.startswith('SDWDATE_POOL_ZERO'): 198 | SDWDATE_POOL_ZERO = True 199 | 200 | elif line.startswith('SDWDATE_POOL_ONE'): 201 | SDWDATE_POOL_ZERO = False 202 | SDWDATE_POOL_ONE = True 203 | 204 | elif line.startswith('SDWDATE_POOL_TWO'): 205 | SDWDATE_POOL_ZERO = False 206 | SDWDATE_POOL_ONE = False 207 | SDWDATE_POOL_TWO = True 208 | 209 | elif SDWDATE_POOL_ZERO and not line.startswith('##'): 210 | pool_one.append(line) 211 | 212 | elif SDWDATE_POOL_ONE and not line.startswith('##'): 213 | pool_two.append(line) 214 | 215 | elif SDWDATE_POOL_TWO and not line.startswith('##'): 216 | pool_three.append(line) 217 | 218 | if not conf_found: 219 | print( 220 | 'No valid file found in user configuration folder "/etc/sdwdate.d".') 221 | 222 | else: 223 | print('No file found in user configuration folder "/etc/sdwdate.d".') 224 | 225 | else: 226 | print('User configuration folder "/etc/sdwdate.d" does not exist.') 227 | 228 | pool_one_url, pool_one_comment = sort_pool(pool_one, mode) 229 | pool_two_url, pool_two_comment = sort_pool(pool_two, mode) 230 | pool_three_url, pool_three_comment = sort_pool(pool_three, mode) 231 | 232 | pool_url = [pool_one_url, pool_two_url, pool_three_url] 233 | pool_comment = [pool_one_comment, pool_two_comment, pool_three_comment] 234 | 235 | return(pool_url[pool], 236 | pool_comment[pool]) 237 | 238 | 239 | if __name__ == "__main__": 240 | pool = int(sys.argv[1]) 241 | mode = sys.argv[2] 242 | pool_url, pool_comment = read_pools(pool, mode) 243 | print("pool: " + str(pool)) 244 | print("pool_url: " + str(pool_url)) 245 | print("pool_comment: " + str(pool_comment)) 246 | -------------------------------------------------------------------------------- /usr/lib/python3/dist-packages/sdwdate/misc.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 -su 2 | 3 | # Copyright (C) 2017 - 2025 ENCRYPTED SUPPORT LLC 4 | # See the file COPYING for copying conditions. 5 | 6 | import sys 7 | sys.dont_write_bytecode = True 8 | 9 | import re 10 | 11 | 12 | def strip_html(message): 13 | # New line for log. 14 | tmp_message = re.sub("
", "\n", message) 15 | # Strip remaining HTML. 16 | return re.sub("<[^<]+?>", "", tmp_message) 17 | -------------------------------------------------------------------------------- /usr/lib/python3/dist-packages/sdwdate/proxy_settings.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 -su 2 | 3 | # Copyright (C) 2017 - 2025 ENCRYPTED SUPPORT LLC 4 | # See the file COPYING for copying conditions. 5 | 6 | import sys 7 | sys.dont_write_bytecode = True 8 | 9 | import os 10 | import glob 11 | import re 12 | from subprocess import check_output 13 | 14 | 15 | def proxy_settings(): 16 | ip_address = '127.0.0.1' 17 | port_number = '9050' 18 | settings_path = '/usr/libexec/helper-scripts/settings_echo' 19 | 20 | if (os.path.exists('/usr/share/whonix') and 21 | os.access(settings_path, os.X_OK)): 22 | proxy_settings = check_output(settings_path) 23 | ip_address = re.search( 24 | b'GATEWAY_IP="(.*)"', 25 | proxy_settings).group(1).decode() 26 | 27 | if os.path.exists('/usr/share/whonix'): 28 | port_number = '9108' 29 | 30 | if os.path.exists('/etc/sdwdate.d/'): 31 | files = sorted(glob.glob('/etc/sdwdate.d/*.conf')) 32 | for f in files: 33 | with open(f) as conf: 34 | lines = conf.readlines() 35 | for line in lines: 36 | if line.startswith('PROXY_IP'): 37 | ip_address = re.search(r'=(.*)', line).group(1) 38 | if line.startswith('PROXY_PORT'): 39 | port_number = re.search(r'=(.*)', line).group(1) 40 | 41 | return ip_address, port_number 42 | 43 | 44 | if __name__ == "__main__": 45 | ip_address, port_number = proxy_settings() 46 | print(ip_address + " " + port_number) 47 | -------------------------------------------------------------------------------- /usr/lib/python3/dist-packages/sdwdate/remote_times.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 -su 2 | 3 | # Copyright (C) 2015 troubadour 4 | # Copyright (C) 2015 - 2025 ENCRYPTED SUPPORT LLC 5 | # See the file COPYING for copying conditions. 6 | 7 | # Example: 8 | # sudo -u sdwdate python3 /usr/lib/python3/dist-packages/sdwdate/remote_times.py "http://www.dds6qkxpwdeubwucdiaord2xgbbeyds25rbsgr73tbfpqpt4a6vjwsyd.onion/a http://www.dds6qkxpwdeubwucdiaord2xgbbeyds25rbsgr73tbfpqpt4a6vjwsyd.onion/b http://www.dds6qkxpwdeubwucdiaord2xgbbeyds25rbsgr73tbfpqpt4a6vjwsyd.onion/c" "127.0.0.1" "9050" 9 | 10 | import sys 11 | sys.dont_write_bytecode = True 12 | 13 | import os 14 | import signal 15 | import shlex 16 | import time 17 | import subprocess 18 | from subprocess import Popen, PIPE 19 | import concurrent.futures 20 | 21 | from .config import get_comment 22 | from .config import read_pools 23 | from .config import time_human_readable 24 | from .config import time_replay_protection_file_read 25 | from .timesanitycheck import time_consensus_sanity_check 26 | from .timesanitycheck import static_time_sanity_check 27 | 28 | 29 | def run_command(i, url_to_unixtime_command, remote): 30 | timeout_seconds = 120 31 | 32 | # Avoid Popen shell=True. 33 | url_to_unixtime_command = shlex.split(url_to_unixtime_command) 34 | 35 | start_unixtime = time.time() 36 | 37 | process = subprocess.Popen( 38 | url_to_unixtime_command, 39 | stdout=PIPE, 40 | stderr=PIPE 41 | ) 42 | 43 | try: 44 | process.wait(timeout_seconds) 45 | # Process already terminated before timeout. 46 | print("remote_times.py: i: " + str(i) + " | done") 47 | status = "done" 48 | except subprocess.TimeoutExpired: 49 | print("remote_times.py: i: " + str(i) + " | timeout_network") 50 | status = "timeout" 51 | # Timeout hit. Kill process. 52 | process.kill() 53 | except BaseException: 54 | error_message = str(sys.exc_info()[0]) 55 | status = "error" 56 | print( 57 | "remote_times.py: i: " + 58 | str(i) + 59 | " | timeout_network unknown error. sys.exc_info: " + 60 | error_message 61 | ) 62 | process.kill() 63 | 64 | # Do not return from this function until killing of the process is 65 | # complete. 66 | process.wait() 67 | 68 | end_unixtime = time.time() 69 | took_time = end_unixtime - start_unixtime 70 | 71 | # Round took_time to two digits for better readability. 72 | # No other reason for rounding. 73 | took_time = round(took_time, 2) 74 | 75 | temp1 = b"" 76 | temp2 = b"" 77 | 78 | try: 79 | # bytes 80 | temp1, temp2 = process.communicate(timeout=2) 81 | except subprocess.TimeoutExpired: 82 | print("remote_times.py: i: " + str(i) + " | timeout_read") 83 | status = "error" 84 | except BaseException: 85 | error_message = str(sys.exc_info()[0]) 86 | status = "error" 87 | print( 88 | "remote_times.py: i: " + 89 | str(i) + 90 | " | timeout_read unknown error. sys.exc_info: " + 91 | error_message 92 | ) 93 | # No need to use process.kill(). 94 | # Was already terminated by itself or killed above. 95 | 96 | try: 97 | stdout = temp1.decode().strip() 98 | except BaseException: 99 | error_message = str(sys.exc_info()[0]) 100 | print( 101 | "remote_times.py: i: " + 102 | str(i) + 103 | " | stdout decode unknown error. sys.exc_info: " + 104 | error_message 105 | ) 106 | stdout = "" 107 | 108 | try: 109 | stderr = temp2.decode().strip() 110 | except BaseException: 111 | error_message = str(sys.exc_info()[0]) 112 | print( 113 | "remote_times.py: i: " + 114 | str(i) + 115 | " | stderr decode unknown error. sys.exc_info: " + 116 | error_message 117 | ) 118 | stderr = "" 119 | 120 | return process, status, end_unixtime, took_time, stdout, stderr 121 | 122 | 123 | def check_remote(i, pools, remote, process, status, end_unixtime, took_time, stdout, stderr): 124 | message = "remote " + str(i) + ": " + str(remote) 125 | print(message) 126 | 127 | comment = get_comment(pools, remote) 128 | 129 | message = "* comment: " + comment 130 | print(message) 131 | 132 | half_took_time_float = float(took_time) / 2 133 | # Round took_time to two digits for better readability. 134 | # No other reason for rounding. 135 | half_took_time_float = round(half_took_time_float, 2) 136 | 137 | message = "* took_time : " + str(took_time) + " second(s)" 138 | print(message) 139 | message = "* half_took_time: " + str(half_took_time_float) + " second(s)" 140 | print(message) 141 | 142 | unixtime_maybe = stdout 143 | 144 | stdout_string_length_is = len(stdout) 145 | unixtime_string_length_max = 10 146 | 147 | if stdout_string_length_is == 0: 148 | stdout = "empty" 149 | if not status == "timeout": 150 | status = "error" 151 | else: 152 | if not stdout_string_length_is == unixtime_string_length_max: 153 | status = "error" 154 | print("* ERROR: stdout unexpected string length: " + str(stdout_string_length_is)) 155 | 156 | if not status == "timeout": 157 | if not process.returncode == 0: 158 | status = "error" 159 | 160 | stderr_length_is = len(stderr) 161 | stderr_string_length_max = 500 162 | 163 | if stderr_length_is == 0: 164 | stderr = "empty" 165 | 166 | if stderr_length_is > stderr_string_length_max: 167 | status = "error" 168 | print("* ERROR: stderr excessive string length: " + str(stderr_length_is)) 169 | 170 | # Test: 171 | # status = "done" 172 | 173 | if status == "timeout": 174 | cast_success = False 175 | elif status == "error": 176 | cast_success = False 177 | else: 178 | try: 179 | # cast str unixtime_maybe to int remote_unixtime 180 | remote_unixtime = int(unixtime_maybe) 181 | cast_success = True 182 | except BaseException: 183 | cast_success = False 184 | status = "error" 185 | error_message = str(sys.exc_info()[0]) 186 | status = "error" 187 | print("* ERROR: Could not cast to int. error_message: " + error_message) 188 | 189 | # Test: 190 | # remote_unixtime = 99999999999999999999 191 | # remote_unixtime = -1 192 | # remote_unixtime = 1 193 | # status = "done" 194 | 195 | if not status == "error" and not status == "timeout": 196 | # Simple test if above cast str unixtime_maybe to int remote_unixtime 197 | # was a success. Within 1 and 999999999. Just to make sure to not 198 | # continue with excessively larger numbers. A better time sanity test 199 | # is being done later below. 200 | remote_unixtime_max = 9999999999 201 | remote_unixtime_min = 0 202 | if remote_unixtime > remote_unixtime_max: 203 | status = "error" 204 | print("* ERROR: remote_unixtime(int) too large!") 205 | if remote_unixtime <= remote_unixtime_min: 206 | status = "error" 207 | print("* ERROR: remote_unixtime(int) smaller or equal 0!") 208 | 209 | if not status == "done": 210 | message = "* exit_code: " + str(process.returncode) 211 | print(message) 212 | if not stdout_string_length_is > unixtime_string_length_max: 213 | message = "* stdout: " + str(stdout) 214 | print(message) 215 | if not stderr_length_is > stderr_string_length_max: 216 | message = "* stderr: " + stderr 217 | print(message) 218 | message = "* remote_status: " + str(status) 219 | print(message) 220 | remote_unixtime = 0 221 | time_diff_raw_int = 0 222 | time_diff_lag_cleaned_float = 0.0 223 | return status, half_took_time_float, remote_unixtime, time_diff_raw_int, time_diff_lag_cleaned_float 224 | 225 | time_diff_raw_int = int(remote_unixtime) - int(end_unixtime) 226 | remote_time = time_human_readable(remote_unixtime) 227 | 228 | # 1. User's sdwdate sends request to remote time source. 229 | # 2. Server creates reply (HTTP DATE header). 230 | # 3. Server sends reply back to user's sdwdate. 231 | # Therefore assume that half of the time required to get the time 232 | # reply has to be deducted from the raw time diff. 233 | time_diff_lag_cleaned_float = float(time_diff_raw_int) - half_took_time_float 234 | time_diff_lag_cleaned_float = round(time_diff_lag_cleaned_float, 2) 235 | 236 | 237 | time_replay_protection_minium_unixtime_int, \ 238 | time_replay_protection_minium_unixtime_human_readable = ( 239 | time_replay_protection_file_read() 240 | ) 241 | 242 | time_replay_protection_minium_unixtime_human_readable = \ 243 | time_replay_protection_minium_unixtime_human_readable.strip() 244 | 245 | time_replay_protection_minium_unixtime_str = str( 246 | time_replay_protection_minium_unixtime_int 247 | ) 248 | 249 | 250 | timesanitycheck_status_static, \ 251 | timesanitycheck_error_static = \ 252 | static_time_sanity_check(remote_unixtime) 253 | 254 | consensus_status, \ 255 | consensus_error, \ 256 | consensus_valid_after_str, \ 257 | consensus_valid_until_str = \ 258 | time_consensus_sanity_check(remote_unixtime) 259 | 260 | message = ( 261 | "* replay_protection_unixtime: " 262 | + time_replay_protection_minium_unixtime_str 263 | ) 264 | print(message) 265 | message = "* remote_unixtime : " + str(remote_unixtime) 266 | print(message) 267 | 268 | message = "* consensus/valid-after : " + \ 269 | consensus_valid_after_str 270 | print(message) 271 | message = ( 272 | "* replay_protection_time : " 273 | + time_replay_protection_minium_unixtime_human_readable 274 | ) 275 | print(message) 276 | message = "* remote_time : " + remote_time 277 | print(message) 278 | message = "* consensus/valid-until : " + \ 279 | consensus_valid_until_str 280 | print(message) 281 | 282 | message = "* time_diff_raw : " + \ 283 | str(time_diff_raw_int) + " second(s)" 284 | print(message) 285 | message = ( 286 | "* time_diff_lag_cleaned: " 287 | + str(time_diff_lag_cleaned_float) 288 | + " second(s)" 289 | ) 290 | print(message) 291 | 292 | # Fallback. 293 | remote_status = "fallback" 294 | 295 | if timesanitycheck_status_static == "sane": 296 | message = "* Time Replay Protection : sane" 297 | print(message) 298 | elif timesanitycheck_status_static == "slow": 299 | message = "* Time Replay Protection : slow" 300 | print(message) 301 | remote_status = "False" 302 | elif timesanitycheck_status_static == "fast": 303 | message = "* Time Replay Protection : fast" 304 | print(message) 305 | remote_status = "False" 306 | elif timesanitycheck_status_static == "error": 307 | message = ( 308 | "* Static Time Sanity Check : error:" 309 | + timesanitycheck_error_static 310 | ) 311 | print(message) 312 | remote_status = "False" 313 | 314 | if consensus_status == "ok": 315 | message = "* Tor Consensus Time Sanity Check: sane" 316 | print(message) 317 | if not remote_status == "False": 318 | remote_status = "True" 319 | elif consensus_status == "slow": 320 | message = "* Tor Consensus Time Sanity Check: slow" 321 | print(message) 322 | remote_status = "False" 323 | elif consensus_status == "fast": 324 | message = "* Tor Consensus Time Sanity Check: fast" 325 | print(message) 326 | remote_status = "False" 327 | elif consensus_status == "error": 328 | message = "* Tor Consensus Time Sanity Check: error: " + \ 329 | consensus_error 330 | print(message) 331 | remote_status = "False" 332 | 333 | message = "* remote_status: " + remote_status 334 | print(message) 335 | 336 | if remote_status == "True": 337 | status = "ok" 338 | return status, half_took_time_float, remote_unixtime, time_diff_raw_int, time_diff_lag_cleaned_float 339 | 340 | remote_unixtime = 0 341 | time_diff_raw_int = 0 342 | time_diff_lag_cleaned_float = 0.00 343 | return status, half_took_time_float, remote_unixtime, time_diff_raw_int, time_diff_lag_cleaned_float 344 | 345 | 346 | def get_time_from_servers( 347 | pools, 348 | list_of_remote_servers, 349 | proxy_ip_address, 350 | proxy_port_number): 351 | 352 | number_of_remote_servers = len(list_of_remote_servers) 353 | # Example number_of_remote_servers: 354 | # 3 355 | range_of_remote_servers = range(number_of_remote_servers) 356 | # Example range_of_remote_servers: 357 | # range(0, 3) 358 | 359 | url_to_unixtime_debug = "true" 360 | 361 | status = [None] * number_of_remote_servers 362 | status_list = [None] * number_of_remote_servers 363 | urls_list = [None] * number_of_remote_servers 364 | took_time_list = [None] * number_of_remote_servers 365 | half_took_time_list = [None] * number_of_remote_servers 366 | remote_unixtime_list = [None] * number_of_remote_servers 367 | handle_list = [None] * number_of_remote_servers 368 | future_list = [None] * number_of_remote_servers 369 | 370 | end_unixtime = [None] * number_of_remote_servers 371 | took_time = [None] * number_of_remote_servers 372 | stdout = [None] * number_of_remote_servers 373 | stderr = [None] * number_of_remote_servers 374 | 375 | time_diff_raw_int_list = [None] * number_of_remote_servers 376 | time_diff_lag_cleaned_float_list = [None] * number_of_remote_servers 377 | 378 | url_to_unixtime_commands_list = [None] * number_of_remote_servers 379 | 380 | print("remote_times.py: url_to_unixtime_command (s):") 381 | for i in range_of_remote_servers: 382 | url_to_unixtime_commands_list[i] = "url_to_unixtime" + " " + proxy_ip_address + " " + \ 383 | proxy_port_number + " " + list_of_remote_servers[i] + " " + url_to_unixtime_debug 384 | print(url_to_unixtime_commands_list[i]) 385 | 386 | print("") 387 | 388 | with concurrent.futures.ThreadPoolExecutor() as executor: 389 | for i in range_of_remote_servers: 390 | future_list[i] = executor.submit( 391 | run_command, i, url_to_unixtime_commands_list[i], list_of_remote_servers[i] 392 | ) 393 | 394 | for i in range_of_remote_servers: 395 | handle_list[i], status[i], end_unixtime[i], took_time[i], stdout[i], stderr[i] = future_list[i].result() 396 | 397 | for i in range_of_remote_servers: 398 | status_list[i], \ 399 | half_took_time_list[i], \ 400 | remote_unixtime_list[i], \ 401 | time_diff_raw_int_list[i], \ 402 | time_diff_lag_cleaned_float_list[i] \ 403 | = \ 404 | check_remote(i, pools, list_of_remote_servers[i], handle_list[i], status[i], end_unixtime[i], took_time[i], stdout[i], stderr[i]) 405 | 406 | print("") 407 | 408 | urls_list[i] = list_of_remote_servers[i] 409 | took_time_list[i] = took_time[i] 410 | 411 | print("remote_times.py: urls_list:") 412 | print(str(urls_list)) 413 | print("remote_times.py: status_list:") 414 | print(str(status_list)) 415 | print("remote_times.py: took_time_list:") 416 | print(str(took_time_list)) 417 | print("remote_times.py: half_took_time_list:") 418 | print(str(half_took_time_list)) 419 | print("remote_times.py: remote_unixtime_list:") 420 | print(str(remote_unixtime_list)) 421 | print("remote_times.py: time_diff_raw_int_list:") 422 | print(str(time_diff_raw_int_list)) 423 | print("remote_times.py: time_diff_lag_cleaned_float_list:") 424 | print(str(time_diff_lag_cleaned_float_list)) 425 | 426 | return urls_list, status_list, remote_unixtime_list, took_time_list, half_took_time_list, time_diff_raw_int_list, time_diff_lag_cleaned_float_list 427 | 428 | 429 | def remote_times_signal_handler(sig, frame): 430 | print("remote_times_signal_handler: OK") 431 | sys.exit(128 + sig) 432 | 433 | 434 | class TimeSourcePool(object): 435 | def __init__(self, pool): 436 | self.url, self.comment = read_pools(pool, "production") 437 | self.url_random_pool = [] 438 | self.already_picked_index = [] 439 | self.done = False 440 | 441 | 442 | def main(): 443 | os.environ["LC_TIME"] = "C" 444 | os.environ["TZ"] = "UTC" 445 | time.tzset() 446 | 447 | signal.signal(signal.SIGTERM, remote_times_signal_handler) 448 | signal.signal(signal.SIGINT, remote_times_signal_handler) 449 | 450 | pools = [] 451 | number_of_pools = 3 452 | pool_range = range(number_of_pools) 453 | for pool_i in pool_range: 454 | pools.append(TimeSourcePool(pool_i)) 455 | 456 | list_of_remote_servers = sys.argv[1] 457 | list_of_remote_servers = list_of_remote_servers.split() 458 | proxy_ip_address = sys.argv[2] 459 | proxy_port_number = sys.argv[3] 460 | 461 | get_time_from_servers( 462 | pools, 463 | list_of_remote_servers, 464 | proxy_ip_address, 465 | proxy_port_number 466 | ) 467 | 468 | 469 | if __name__ == "__main__": 470 | main() 471 | -------------------------------------------------------------------------------- /usr/lib/python3/dist-packages/sdwdate/timesanitycheck.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 -su 2 | 3 | # Copyright (C) 2017 - 2025 ENCRYPTED SUPPORT LLC 4 | # See the file COPYING for copying conditions. 5 | 6 | # sudo -u sdwdate 7 | # python3 /usr/lib/python3/dist-packages/sdwdate/timesanitycheck.py 1611640486 8 | 9 | import sys 10 | sys.dont_write_bytecode = True 11 | 12 | import os 13 | import time 14 | # from datetime import datetime 15 | from dateutil.parser import parse 16 | from stem.connection import connect 17 | import subprocess 18 | 19 | os.environ["LC_TIME"] = "C" 20 | os.environ["TZ"] = "UTC" 21 | time.tzset() 22 | 23 | def time_consensus_sanity_check(unixtime): 24 | error = "" 25 | status = "ok" 26 | consensus_valid_after_str = "" 27 | consensus_valid_until_str = "" 28 | 29 | try: 30 | controller = connect() 31 | except BaseException: 32 | status = "error" 33 | error = "Could not open Tor control connection. error: " + \ 34 | str(sys.exc_info()[0]) 35 | return status, error, consensus_valid_after_str, consensus_valid_until_str 36 | 37 | try: 38 | consensus_valid_after_str = controller.get_info( 39 | "consensus/valid-after") 40 | consensus_valid_until_str = controller.get_info( 41 | "consensus/valid-until") 42 | except BaseException: 43 | status = "error" 44 | error = "Could not request from Tor control connection. error: " + \ 45 | str(sys.exc_info()[0]) 46 | return status, error, consensus_valid_after_str, consensus_valid_until_str 47 | 48 | try: 49 | controller.close() 50 | except BaseException: 51 | pass 52 | 53 | try: 54 | consensus_valid_after_unixtime = parse( 55 | consensus_valid_after_str).strftime('%s') 56 | consensus_valid_until_unixtime = parse( 57 | consensus_valid_until_str).strftime('%s') 58 | 59 | if int(unixtime) > int(consensus_valid_after_unixtime): 60 | pass 61 | else: 62 | status = "slow" 63 | 64 | if int(unixtime) > int(consensus_valid_until_unixtime): 65 | status = "fast" 66 | else: 67 | pass 68 | except BaseException: 69 | try: 70 | controller.close() 71 | except BaseException: 72 | pass 73 | error = "Unexpected error: " + str(sys.exc_info()[0]) 74 | status = "error" 75 | 76 | return status, error, consensus_valid_after_str, consensus_valid_until_str 77 | 78 | 79 | def static_time_sanity_check(unixtime_to_validate): 80 | # Tue, 17 May 2033 10:00:00 GMT 81 | expiration_unixtime = 1999936800 82 | # expiration_time = datetime.strftime( 83 | # datetime.fromtimestamp(expiration_unixtime), 84 | # '%a %b %d %H:%M:%S UTC %Y') 85 | 86 | try: 87 | # time_to_validate_human_readable = datetime.strftime( 88 | # datetime.fromtimestamp(unixtime_to_validate), '%a %b %d %H:%M:%S UTC 89 | # %Y') 90 | 91 | p = subprocess.Popen( 92 | "/usr/bin/minimum-unixtime-show", 93 | stdout=subprocess.PIPE, 94 | stderr=subprocess.PIPE) 95 | stdout, stderr = p.communicate() 96 | 97 | minimum_unixtime = stdout.decode() 98 | minimum_unixtime = int(minimum_unixtime) 99 | # minimum_time_human_readable = stderr.decode() 100 | 101 | if unixtime_to_validate < minimum_unixtime: 102 | status = 'slow' 103 | elif unixtime_to_validate > expiration_unixtime: 104 | status = 'fast' 105 | else: 106 | status = 'sane' 107 | 108 | error = "none" 109 | 110 | return status, error 111 | except BaseException: 112 | status = "error" 113 | error = str(sys.exc_info()[0]) 114 | return status, error 115 | 116 | 117 | if __name__ == "__main__": 118 | unixtime = int(sys.argv[1]) 119 | time_consensus_sanity_check(unixtime) 120 | status, error = static_time_sanity_check(unixtime) 121 | print("status: " + status) 122 | print("error: " + error) 123 | -------------------------------------------------------------------------------- /usr/lib/qubes-bind-dirs.d/40_sdwdate.conf: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2012 - 2025 ENCRYPTED SUPPORT LLC 2 | ## See the file COPYING for copying conditions. 3 | 4 | ## Time Replay Protection 5 | ## /var/lib/sdwdate/time-replay-protection-utc-unixtime 6 | ## https://www.whonix.org/wiki/Sdwdate#sdwdate_Time_Replay_Protection 7 | binds+=( '/var/lib/sdwdate' ) 8 | -------------------------------------------------------------------------------- /usr/lib/systemd/system/qubes-sync-time.service.d/40_sdwdate.conf: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2022 - 2025 ENCRYPTED SUPPORT LLC 2 | ## See the file COPYING for copying conditions. 3 | 4 | [Unit] 5 | ConditionPathExists=!/etc/sdwdate.d/qubes-sync-time-disabled-by-sdwdate.marker 6 | -------------------------------------------------------------------------------- /usr/lib/systemd/system/sdwdate-pre.service: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2012 - 2025 ENCRYPTED SUPPORT LLC 2 | ## See the file COPYING for copying conditions. 3 | 4 | ## similar file by package apparmor-profile-everything (AAE): 5 | ## /lib/systemd/system/sdwdate-aae.service 6 | 7 | [Unit] 8 | Description=Secure Distributed Web Date - Pre 9 | Documentation=https://www.whonix.org/wiki/sdwdate 10 | #ConditionPathExists=!/run/qubes/this-is-templatevm 11 | ConditionPathExists=!/run/qubes-service/no-sdwdate 12 | 13 | Before=sdwdate.service 14 | 15 | [Service] 16 | Type=notify 17 | ExecStart=/usr/libexec/sdwdate/sdwdate-pre 18 | RemainAfterExit=yes 19 | 20 | [Install] 21 | WantedBy=multi-user.target 22 | -------------------------------------------------------------------------------- /usr/lib/systemd/system/sdwdate-start-anondate-set-file-watcher.service: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2012 - 2025 ENCRYPTED SUPPORT LLC 2 | ## See the file COPYING for copying conditions. 3 | 4 | [Unit] 5 | Description=Secure Distributed Web Date - Tor Restart Request File Watcher 6 | Documentation=https://www.whonix.org/wiki/sdwdate 7 | ConditionPathExists=!/run/qubes/this-is-templatevm 8 | ConditionPathExists=!/run/qubes-service/no-sdwdate 9 | 10 | ## systemd-nspawn does not allow clock to be changed inside the container. 11 | ## Quote https://www.freedesktop.org/software/systemd/man/systemd-nspawn.html 12 | ## The host's network interfaces and the system clock may not be changed from within the container. 13 | ## https://forums.whonix.org/t/bootclockrandomization-always-moving-clock-plus-or-5-seconds/2200/10 14 | ConditionVirtualization=!systemd-nspawn 15 | 16 | After=network.target 17 | Wants=network.target 18 | 19 | After=rinetd.service 20 | After=bootclockrandomization.service 21 | After=tor.service 22 | After=tor@default.service 23 | 24 | Conflicts=systemd-timesyncd.service 25 | 26 | [Service] 27 | User=sdwdate 28 | Group=sdwdate 29 | ExecStart=/usr/libexec/sdwdate/sdwdate-start-anondate-set-file-watcher 30 | #SuccessExitStatus=143 31 | #TimeoutSec=30 32 | #WatchdogSec=200m 33 | Restart=always 34 | 35 | AmbientCapabilities=CAP_SYS_TIME 36 | CapabilityBoundingSet=CAP_SYS_TIME 37 | 38 | [Install] 39 | WantedBy=multi-user.target 40 | -------------------------------------------------------------------------------- /usr/lib/systemd/system/sdwdate.service: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2012 - 2025 ENCRYPTED SUPPORT LLC 2 | ## See the file COPYING for copying conditions. 3 | 4 | ## similar file by package apparmor-profile-everything (AAE): 5 | ## /lib/systemd/system/sdwdate-aae.service 6 | 7 | [Unit] 8 | Description=Secure Distributed Web Date 9 | Documentation=https://www.whonix.org/wiki/sdwdate 10 | ConditionPathExists=!/run/qubes/this-is-templatevm 11 | ConditionPathExists=!/run/qubes-service/no-sdwdate 12 | 13 | ## systemd-nspawn does not allow clock to be changed inside the container. 14 | ## Quote https://www.freedesktop.org/software/systemd/man/systemd-nspawn.html 15 | ## The host's network interfaces and the system clock may not be changed from within the container. 16 | ## https://forums.whonix.org/t/bootclockrandomization-always-moving-clock-plus-or-5-seconds/2200/10 17 | ConditionVirtualization=!systemd-nspawn 18 | 19 | After=network.target 20 | Wants=network.target 21 | 22 | After=rinetd.service 23 | After=bootclockrandomization.service 24 | After=tor.service 25 | After=tor@default.service 26 | 27 | ## TODO: This can be removed if gets improved to start early enough. 28 | After=privleapd.service 29 | 30 | Conflicts=systemd-timesyncd.service 31 | 32 | [Service] 33 | Type=notify 34 | User=sdwdate 35 | Group=sdwdate 36 | ExecStart=/usr/libexec/sdwdate/sdwdate 37 | SuccessExitStatus=143 38 | TimeoutSec=30 39 | WatchdogSec=200m 40 | Restart=always 41 | 42 | ## user `sdwdate` legacy home folder migration 43 | ## Allow time for sdwdate.postinst usermod to change sdwdate home update. 44 | RestartSec=10s 45 | 46 | AmbientCapabilities=CAP_SYS_TIME 47 | CapabilityBoundingSet=CAP_SYS_TIME 48 | 49 | ## Sandboxing. 50 | ## https://forums.whonix.org/t/apply-systemd-sandboxing-by-default-to-some-services/7590/50 51 | ProtectSystem=strict 52 | ReadWriteDirectories=/run/sdwdate/ /var/lib/sdwdate/ 53 | ProtectHome=true 54 | ProtectKernelTunables=true 55 | ProtectKernelModules=true 56 | ProtectControlGroups=true 57 | ProtectKernelLogs=true 58 | ProtectHostname=true 59 | ProtectProc=invisible 60 | ProcSubset=pid 61 | PrivateTmp=true 62 | ## PrivateUsers=true 63 | PrivateDevices=true 64 | NoNewPrivileges=true 65 | LockPersonality=true 66 | RestrictRealtime=true 67 | RestrictSUIDSGID=true 68 | RestrictAddressFamilies=AF_UNIX AF_INET 69 | RestrictNamespaces=true 70 | SystemCallArchitectures=native 71 | 72 | ## Split into multiple lines to fix lintian warning very-long-line-length-in-source-file. 73 | SystemCallFilter=\ 74 | wait4 select futex read stat close openat fstat lseek mmap rt_sigaction \ 75 | getdents64 mprotect ioctl recvfrom munmap brk rt_sigprocmask fcntl \ 76 | getpid write access socket sendto dup2 clone execve getrandom geteuid \ 77 | getgid madvise getuid getegid readlink pipe rt_sigreturn connect pipe2 \ 78 | prlimit64 set_robust_list dup arch_prctl lstat set_tid_address sysinfo \ 79 | sigaltstack rt_sigsuspend shutdown timer_settime mkdir timer_create statfs \ 80 | getcwd setpgid setsockopt uname bind getpgrp getppid getpeername chdir poll \ 81 | getsockname fadvise64 clock_settime kill getsockopt unlink epoll_create1 \ 82 | utimensat mremap prctl sendmsg newfstatat pread64 vfork close_range clone3 \ 83 | get_mempolicy set_mempolicy faccessat readlinkat mkdirat dup3 ppoll pselect6 \ 84 | unlinkat _llseek send waitpid recv _newselect getpriority faccessat2 epoll_wait \ 85 | epoll_ctl tgkill timerfd_create timerfd_settime 86 | 87 | [Install] 88 | WantedBy=multi-user.target 89 | -------------------------------------------------------------------------------- /usr/lib/systemd/system/systemd-timesyncd.service.d/40_sdwdate.conf: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2012 - 2025 ENCRYPTED SUPPORT LLC 2 | ## See the file COPYING for copying conditions. 3 | 4 | [Unit] 5 | ConditionPathExists=!/usr/libexec/sdwdate 6 | -------------------------------------------------------------------------------- /usr/lib/tmpfiles.d/sdwdate.conf: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2012 - 2025 ENCRYPTED SUPPORT LLC 2 | ## See the file COPYING for copying conditions. 3 | 4 | d /run/sdwdate 0755 sdwdate sdwdate - 5 | ## Make sure /run/sdwdate/status always exists so sdwdate-gui can watch it. 6 | f /run/sdwdate/status 0644 sdwdate sdwdate - 7 | Z /run/sdwdate/* 0644 sdwdate sdwdate - 8 | 9 | d /var/lib/sdwdate 0755 sdwdate sdwdate - 10 | Z /var/lib/sdwdate/* 0644 sdwdate sdwdate - 11 | 12 | ## Unfortunately cannot be a sub folder because above 'Z' 13 | ## removed "chmod -x" from the folder. 14 | d /var/lib/sdwdate-forbidden-temp 0755 sdwdate sdwdate - 15 | Z /var/lib/sdwdate-forbidden-temp/* 0644 sdwdate sdwdate - 16 | -------------------------------------------------------------------------------- /usr/libexec/config-test: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ## Copyright (C) 2021 - 2025 ENCRYPTED SUPPORT LLC 4 | ## See the file COPYING for copying conditions. 5 | 6 | ## usage: 7 | ## usr/libexec/config-test > ./config-test.txt 8 | 9 | MYDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 10 | cd "$MYDIR" 11 | 12 | cmd="python3 ../../usr/lib/python3/dist-packages/sdwdate/config.py" 13 | 14 | echo "" 15 | 16 | $cmd "0" "test" 17 | $cmd "1" "test" 18 | $cmd "2" "test" 19 | 20 | # $cmd "0" "production" 21 | # $cmd "1" "production" 22 | # $cmd "2" "production" 23 | -------------------------------------------------------------------------------- /usr/libexec/sdwdate/sdwdate: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 -su 2 | 3 | # Copyright (C) 2021 - 2025 ENCRYPTED SUPPORT LLC 4 | # See the file COPYING for copying conditions. 5 | 6 | import sys 7 | sys.dont_write_bytecode = True 8 | 9 | from sdwdate import sdwdate 10 | sdwdate.main() 11 | -------------------------------------------------------------------------------- /usr/libexec/sdwdate/sdwdate-pre: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ## Copyright (C) 2021 - 2025 ENCRYPTED SUPPORT LLC 4 | ## See the file COPYING for copying conditions. 5 | 6 | set -x 7 | set -e 8 | 9 | ## 'adduser is a debianism' is required for 'anondate' which uses 10 | ## 'journalctl'. Group 'systemd-journal' might not exist yet during the build 11 | ## process, but 'Depends: systemd' would be a too heavy dependency and might 12 | ## cause dependency issues during the build process or distro morphing because 13 | ## package 'systemd' as well as package 'sdwdate' 'Provides: time-daemon'. 14 | ## 'adduser' is a debianism. 15 | adduser sdwdate systemd-journal || true 16 | 17 | gcc /usr/src/sdwdate/sclockadj.c -o /usr/libexec/sdwdate/sclockadj -ldl -D_GNU_SOURCE -Wdate-time -D_FORTIFY_SOURCE=3 -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wl,-z,relro -Wl,-z,now 18 | 19 | systemd-notify --ready 20 | -------------------------------------------------------------------------------- /usr/libexec/sdwdate/sdwdate-start-anondate-set-file-watcher: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ## Copyright (C) 2012 - 2025 ENCRYPTED SUPPORT LLC 4 | ## See the file COPYING for copying conditions. 5 | 6 | #### meta start 7 | #### project Whonix and Kicksecure 8 | #### category time and Tor 9 | #### description 10 | ## start `anondate-set` when `sdwdate` creates file 11 | ## `/run/sdwdate/request_anondate-set`. 12 | ## 13 | ## This script allows `sdwdate` to request restart of Tor through creation of 14 | ## file `/run/sdwdate/request_anondate-set`. 15 | ## 16 | ## This is an alternative to avoid having to weaken `sdwdate` hardening (`systemd`, 17 | ## `apparmor`) while permitting `sdwdate` to restart of Tor. 18 | ## 19 | ## The script `sdwdate` executes the -> `/usr/libexec/helper-scripts/onion-time-pre-script` script, 20 | ## which creates file `/run/sdwdate/request_anondate-set` -> which results in this script running 21 | ## `anondate-set`. 22 | ## 23 | ## This script gets started systemd under user/group sdwdate. 24 | #### meta end 25 | 26 | #set -x 27 | set -e 28 | 29 | true "START: $0" 30 | 31 | ## inotifywait requires the folder to already exist. 32 | mkdir --parents "/run/sdwdate" 33 | chown --recursive "sdwdate:sdwdate" "/run/sdwdate" 34 | 35 | inotifywait_subshell_fifo="$(mktemp)" 36 | rm --force "$inotifywait_subshell_fifo" 37 | mkfifo "$inotifywait_subshell_fifo" 38 | 39 | { 40 | inotifywait --quiet --recursive --monitor --event create --format "%w%f" "/run/sdwdate/" & 41 | wait "$!" 42 | 43 | } > "$inotifywait_subshell_fifo" & 44 | 45 | inotifywait_subshell_pid="$!" 46 | 47 | if [ -f "/run/sdwdate/request_anondate-set" ]; then 48 | anondate-set || true 49 | rm -f "/run/sdwdate/request_anondate-set" 50 | fi 51 | 52 | while read file_name; do 53 | if [ "$file_name" = "/run/sdwdate/request_anondate-set" ] ; then 54 | anondate-set || true 55 | rm -f "/run/sdwdate/request_anondate-set" 56 | fi 57 | done < "$inotifywait_subshell_fifo" 58 | 59 | wait "$inotifywait_subshell_pid" 60 | -------------------------------------------------------------------------------- /usr/libexec/sdwdate/sdwdate-test: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ## Copyright (C) 2021 - 2025 ENCRYPTED SUPPORT LLC 4 | ## See the file COPYING for copying conditions. 5 | 6 | set -x 7 | set -e 8 | 9 | date --set "Fri 24 Sep 2011 06:51:24 PM UTC" 10 | systemctl stop tor 11 | anon-consensus-del 12 | systemctl restart tor 13 | sdwdate-clock-jump 14 | 15 | true "OK" 16 | 17 | -------------------------------------------------------------------------------- /usr/libexec/sdwdate/suspend-post: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ## Copyright (C) 2017 - 2025 ENCRYPTED SUPPORT LLC 4 | ## See the file COPYING for copying conditions. 5 | 6 | #set -x 7 | set -e 8 | 9 | date_cmd(){ 10 | date -u +"%Y-%m-%d %T" 11 | } 12 | 13 | output_cmd_set() { 14 | if [ -o xtrace ]; then 15 | output_cmd=true 16 | else 17 | output_cmd=echo 18 | fi 19 | } 20 | 21 | output_cmd_func() { 22 | msg="$(date_cmd) - $0 - $@" 23 | $output_cmd "$msg" 24 | echo "$msg" | systemd-cat --identifier="suspend-post" || true 25 | } 26 | 27 | output_cmd_set 28 | 29 | output_cmd_func "INFO - START" 30 | 31 | if [ -f /run/qubes/this-is-templatevm ]; then 32 | ## qubes-sync-time is triggered after suspend/resume. 33 | ## https://forums.whonix.org/t/whonix-ws-16-fails-to-update-due-to-timing-issue/12739/10 34 | output_cmd_func "INFO - Skipping, because run in TemplateVM." 35 | exit 0 36 | fi 37 | 38 | if [ ! "$(id -u)" = "0" ]; then 39 | output_cmd_func "ERROR - Must run as root!" 40 | exit 2 41 | fi 42 | 43 | if command -v "qubesdb-read" >/dev/null 2>&1 ; then 44 | true 45 | else 46 | output_cmd_func "INFO - Clock fix after resume not implemented in Non-Qubes-Whonix. See: https://www.whonix.org/wiki/Troubleshooting#Clock_Fix" 47 | exit 3 48 | fi 49 | 50 | ## Defensive measure to not mess up file permissions. 51 | mkdir --parents /run/sdwdate 52 | chown --recursive sdwdate:sdwdate /run/sdwdate 53 | 54 | tor_restart_maybe() { 55 | output_cmd_func "INFO - Checking if file /run/sdwdate/tor_was_running.status exists..." 56 | 57 | if test -f /run/sdwdate/tor_was_running.status ; then 58 | output_cmd_func "INFO - Yes, file /run/sdwdate/tor_was_running.status exists." 59 | 60 | output_cmd_func "INFO - Deleting Tor consensus files, restart Tor (and maybe vanguards)..." 61 | ## Without this, Tor keeps the stale Tor consensus even after restarting Tor. 62 | ## provided by package helper-scripts 63 | anon-consensus-del 64 | output_cmd_func "INFO - Done, deleted Tor consensus files, restarted Tor (and maybe vanguards)." 65 | 66 | output_cmd_func "INFO - Deleting /run/sdwdate/tor_was_running.status..." 67 | rm --force /run/sdwdate/tor_was_running.status 68 | output_cmd_func "INFO - Done, deleted /run/sdwdate/tor_was_running.status." 69 | else 70 | output_cmd_func "INFO - No, file /run/sdwdate/tor_was_running.status did not exist, meaning we previously before suspend/hibernate did not stop Tor, therefore not starting it now." 71 | fi 72 | } 73 | 74 | ## Previously in suspend-pre sdwdate 75 | ## - Tor was stopped. 76 | ## - sdwdate was stopped. 77 | ## - Whonix firewall entered timesync-fail-closed mode. 78 | ## 79 | ## Now in this script: 80 | ## - 1. restart Tor (only if it was previously running) 81 | ## - 2. sdwdate-clock-jump so it sets the time using `date` (instantly setting 82 | ## the time), instead of sclockadj (gradually adjusting the time). 83 | ## - 3. (outside of this script) Once sdwdate succeeded, 84 | ## whonix-firewall-sdwdate-watcher.service should enter Whonix firewall in 85 | ## full mode. 86 | ## 87 | ## For an ISP level observer this should look like a reboot. 88 | 89 | ## Do not interfere with the clock if the sdwdate service was stopped. 90 | output_cmd_func "INFO - Checking if file /run/sdwdate/sdwdate_was_running.status exists..." 91 | if test -f /run/sdwdate/sdwdate_was_running.status ; then 92 | output_cmd_func "INFO - Yes, file /run/sdwdate/sdwdate_was_running.status exists." 93 | 94 | output_cmd_func "INFO - Deleting /run/sdwdate/sdwdate_was_running.status..." 95 | rm --force /run/sdwdate/sdwdate_was_running.status 96 | output_cmd_func "INFO - Done, deleted /run/sdwdate/sdwdate_was_running.status." 97 | 98 | tor_restart_maybe 99 | 100 | output_cmd_func "INFO - Running sdwdate-clock-jump..." 101 | sdwdate-clock-jump 102 | output_cmd_func "INFO - Done, with sdwdate-clock-jump." 103 | 104 | ## Whonix firewall full mode 105 | ## 106 | ## After sdwdate restart, sdwdate will on success recreate the status file 107 | ## '/run/sdwdate/first_success'. 108 | ## 109 | ## ( whonix-[gw|ws]-firewall ) /lib/systemd/system/whonix-firewall-sdwdate-watcher.service / 110 | ## ( helper-scripts ) /usr/libexec/helper-scripts/firewall-restarter 111 | ## will notice this, and restart Whonix firewall in full mode. 112 | 113 | exit 0 114 | else 115 | output_cmd_func "INFO - No, file /run/sdwdate/sdwdate_was_running.status did not exist, meaning we previously before suspend/hilbernate did not stop sdwdate, therefore not starting it now." 116 | fi 117 | 118 | ## Make sure Tor is restarted even if sdwdate was not running during suspend-pre. 119 | tor_restart_maybe 120 | 121 | output_cmd_func "INFO - END" 122 | -------------------------------------------------------------------------------- /usr/libexec/sdwdate/suspend-pre: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ## Copyright (C) 2017 - 2025 ENCRYPTED SUPPORT LLC 4 | ## See the file COPYING for copying conditions. 5 | 6 | #set -x 7 | set -e 8 | 9 | date_cmd(){ 10 | date --utc +"%Y-%m-%d %T" 11 | } 12 | 13 | output_cmd_set() { 14 | if [ -o xtrace ]; then 15 | output_cmd=true 16 | else 17 | output_cmd=echo 18 | fi 19 | } 20 | 21 | output_cmd_func() { 22 | msg="$(date_cmd) - $0 - $@" 23 | echo "$msg" 24 | echo "$msg" | systemd-cat --identifier="suspend-pre" || true 25 | } 26 | 27 | output_cmd_set 28 | 29 | output_cmd_func "INFO - START" 30 | 31 | if [ -f /run/qubes/this-is-templatevm ]; then 32 | output_cmd_func "INFO - Skipping, because run in TemplateVM." 33 | exit 0 34 | fi 35 | 36 | if [ ! "$(id -u)" = "0" ]; then 37 | output_cmd_func "ERROR - Must run as root!" 38 | exit 2 39 | fi 40 | 41 | if command -v "qubesdb-read" >/dev/null 2>&1 ; then 42 | true 43 | else 44 | output_cmd_func "INFO - Clock fix after resume not implemented in Non-Qubes-Whonix. See: https://www.whonix.org/wiki/Troubleshooting#Clock_Fix" 45 | exit 3 46 | fi 47 | 48 | ## Defensive measure to not mess up file permissions. 49 | mkdir --parents /run/sdwdate 50 | chown --recursive sdwdate:sdwdate /run/sdwdate 51 | 52 | ## First stop sdwdate, then stop Tor. 53 | ## Should sdwdate fetch time during run of this script, it would log 54 | ## unnecessary fetching errors. 55 | 56 | output_cmd_func "INFO - Checking if sdwdate systemd unit is running..." 57 | if systemctl --no-pager status sdwdate >/dev/null ; then 58 | output_cmd_func "INFO - Yes, sdwdate is running." 59 | 60 | output_cmd_func "INFO - Creating /run/sdwdate/sdwdate_was_running.status..." 61 | touch /run/sdwdate/sdwdate_was_running.status 62 | output_cmd_func "INFO - Done, created /run/sdwdate/sdwdate_was_running.status." 63 | 64 | output_cmd_func "INFO - Stopping sdwdate..." 65 | systemctl --no-pager stop sdwdate 66 | output_cmd_func "INFO - Done, stopped sdwdate." 67 | 68 | output_cmd_func "INFO - Deleting /run/sdwdate/first_success..." 69 | rm --force /run/sdwdate/first_success 70 | output_cmd_func "INFO - Done, deleted /run/sdwdate/first_success." 71 | 72 | output_cmd_func "INFO - Deleting /run/sdwdate/success..." 73 | rm --force /run/sdwdate/success 74 | output_cmd_func "INFO - Done, deleted /run/sdwdate/success." 75 | 76 | if command -v whonix_firewall >/dev/null 2>&1 ; then 77 | ## Whonix firewall timesync-fail-closed mode 78 | output_cmd_func "INFO - Entering Whonix firewall timesync-fail-closed mode." 79 | firewall_mode="timesync-fail-closed" whonix_firewall 80 | output_cmd_func "INFO - Done, entered Whonix firewall timesync-fail-closed mode." 81 | else 82 | true "$0 INFO: Whonix firewall not installed, probably running outside of Whonix." 83 | fi 84 | else 85 | output_cmd_func "INFO - sdwdate was not running, no need to stop it." 86 | fi 87 | 88 | output_cmd_func "INFO - Checking if tor systemd unit is running..." 89 | if systemctl --no-pager status tor >/dev/null ; then 90 | output_cmd_func "INFO - Yes, tor is running." 91 | 92 | output_cmd_func "INFO - Creating /run/sdwdate/tor_was_running.status..." 93 | touch /run/sdwdate/tor_was_running.status 94 | output_cmd_func "INFO - Done, created /run/sdwdate/tor_was_running.status." 95 | 96 | output_cmd_func "INFO - Stopping Tor..." 97 | systemctl --no-pager stop tor 98 | output_cmd_func "INFO - Done, stopped Tor." 99 | 100 | output_cmd_func "INFO - Stopping vanguards..." 101 | systemctl --no-pager stop vanguards &>/dev/null || true 102 | output_cmd_func "INFO - Done, stopped vanguards." 103 | else 104 | output_cmd_func "INFO - Tor was not running, no need to stop it." 105 | fi 106 | 107 | output_cmd_func "INFO - END" 108 | -------------------------------------------------------------------------------- /usr/sbin/sdwdate-clock-jump: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ## Copyright (C) 2017 - 2025 ENCRYPTED SUPPORT LLC 4 | ## See the file COPYING for copying conditions. 5 | 6 | set -e 7 | 8 | if [ ! "$(id -u)" = "0" ]; then 9 | echo "$0: ERROR: Must be run as root (sudo)!" 10 | exit 1 11 | fi 12 | 13 | ## If this scirpt is run as root. 14 | rm --force /run/anondate/tor_certificate_lifetime_set 15 | ## If this scirpt is run as user sdwdate. 16 | rm --force /run/sdwdate/tor_certificate_lifetime_set 17 | 18 | rm --force /run/sdwdate/first_success 19 | rm --force /run/sdwdate/clock_jump_do_once 20 | 21 | sudo --non-interactive -u sdwdate touch /run/sdwdate/clock_jump_do_once 22 | 23 | leaprun restart-sdwdate 24 | 25 | true "$0: OK" 26 | -------------------------------------------------------------------------------- /usr/share/sdwdate/get-time-from-servers-test: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 -su 2 | 3 | ## Copyright (C) 2017 - 2025 ENCRYPTED SUPPORT LLC 4 | ## See the file COPYING for copying conditions. 5 | 6 | import sys 7 | from sdwdate.remote_times import get_time_from_servers 8 | 9 | list_of_urls_returned, \ 10 | list_of_status, \ 11 | list_of_unixtimes, \ 12 | list_of_took_time, \ 13 | list_of_half_took_time, \ 14 | list_off_time_diff_raw_int, \ 15 | list_off_time_diff_lag_cleaned_float, \ 16 | = get_time_from_servers( 17 | [ 0, 1, 2 ], 18 | [ 19 | "https://p53lf57qovyuvwsc6xnrppyply3vtqm7l6pcobkmyqsiofyeznfu5uqd.onion", 20 | "https://p53lf57qovyuvwsc6xnrppyply3vtqm7l6pcobkmyqsiofyeznfu5uqd.onion", 21 | "https://p53lf57qovyuvwsc6xnrppyply3vtqm7l6pcobkmyqsiofyeznfu5uqd.onion", 22 | ], 23 | "127.0.0.1", "9050" 24 | ) 25 | -------------------------------------------------------------------------------- /usr/share/sdwdate/onion-list-all: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 -su 2 | 3 | ## Copyright (C) 2017 - 2025 ENCRYPTED SUPPORT LLC 4 | ## See the file COPYING for copying conditions. 5 | 6 | import os 7 | import time 8 | import datetime 9 | from sdwdate.remote_times import get_time_from_servers 10 | from sdwdate.config import read_pools 11 | from sdwdate.config import get_comment_pool_single 12 | from sdwdate.proxy_settings import proxy_settings 13 | 14 | # Helpers for a cludge to check only 3 urls at once 15 | def chunks(my_list, n): 16 | """Yield successive n-sized chunks from my_list.""" 17 | for i in range(0, len(my_list), n): 18 | yield my_list[i:i + n] 19 | 20 | class Pool: 21 | def __init__(self, pool): 22 | self.url, self.comment = read_pools(pool, 'test') 23 | 24 | class CheckRemotes: 25 | def __init__(self): 26 | self.number_of_pools = 3 27 | self.pools = [Pool(pool) for pool in range(self.number_of_pools)] 28 | self.proxy_ip, self.proxy_port = proxy_settings() 29 | 30 | def loop(self): 31 | for pool in self.pools: 32 | url_chunk_list = list(chunks(pool.url,1)) 33 | for url_chunk in url_chunk_list: 34 | remote = url_chunk[0] 35 | comment = get_comment_pool_single(pool, remote) 36 | print(remote + " " + comment) 37 | 38 | if __name__ == '__main__': 39 | remotes = CheckRemotes() 40 | remotes.loop() 41 | -------------------------------------------------------------------------------- /usr/share/sdwdate/onion-test-confirm: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ## Copyright (C) 2020 - 2025 ENCRYPTED SUPPORT LLC 4 | ## See the file COPYING for copying conditions. 5 | 6 | while read -r -d $'\n' line ; do 7 | read -r first_word second_word _ <<< "$line" 8 | temp="$first_word" 9 | temp="$(echo "$temp" | str_replace "http://" "")" 10 | plain_url="$(echo "$temp" | str_replace "https://" "")" 11 | ## web.archive.org did not support tlsv1.3 at time of writing. 12 | if scurl --tlsv1.2 --silent --location "$second_word" | grep -q "$plain_url" ; then 13 | continue 14 | fi 15 | echo "Failed!" 16 | echo scurl --tlsv1.2 --silent --location "$second_word" 17 | echo "plain_url: $plain_url" 18 | echo "second_word: $second_word" 19 | echo "" 20 | done < <( /usr/share/sdwdate/onion-list-all ) 21 | -------------------------------------------------------------------------------- /usr/share/sdwdate/onion-test-https-manual: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ## Copyright (C) 2020 - 2025 ENCRYPTED SUPPORT LLC 4 | ## See the file COPYING for copying conditions. 5 | 6 | ## Find out which onions are available over TLS. 7 | 8 | while read -r -d $'\n' line ; do 9 | read -r first_word _ <<< "$line" 10 | url_https="$(echo "$first_word" | str_replace "http://" "https://")" 11 | curl --head "$url_https" 12 | done < <( /usr/share/sdwdate/onion-list-all ) 13 | -------------------------------------------------------------------------------- /usr/share/sdwdate/onion-tester: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 -su 2 | 3 | ## Copyright (C) 2017 - 2025 ENCRYPTED SUPPORT LLC 4 | ## See the file COPYING for copying conditions. 5 | 6 | import os 7 | import time 8 | import datetime 9 | from sdwdate.remote_times import get_time_from_servers 10 | from sdwdate.config import read_pools 11 | from sdwdate.proxy_settings import proxy_settings 12 | 13 | proxy_ip, proxy_port = proxy_settings() 14 | 15 | # Helpers for a cludge to check only 3 urls at once 16 | def chunks(my_list, n): 17 | """Yield successive n-sized chunks from my_list.""" 18 | for i in range(0, len(my_list), n): 19 | yield my_list[i:i + n] 20 | 21 | def exec_curl(c_url): 22 | cmd = 'curl --head '+c_url+'> /dev/null 2>&1' 23 | c_out = os.system(cmd) 24 | if '0' in str(c_out) : 25 | return ' (Curl --head is OK)' 26 | else: 27 | return ' (Curl --head also Not OK)' 28 | 29 | class Pool: 30 | def __init__(self, pool): 31 | self.urls, self.comments = read_pools(pool, 'test') 32 | 33 | class CheckRemotes: 34 | def __init__(self): 35 | self.number_of_pools = 3 36 | self.pools = [Pool(pool) for pool in range(self.number_of_pools)] 37 | self.urls = [] 38 | self.comments = [] 39 | self.returned_values = [] 40 | self.list_of_status = [] 41 | self.list_of_unixtimes = [] 42 | self.list_of_took_time = [] 43 | self.list_of_half_took_time = [] 44 | self.list_off_time_diff_raw_int = [] 45 | self.list_off_time_diff_lag_cleaned_float = [] 46 | 47 | def loop(self): 48 | time_stamp_ts = int(time.time()) 49 | print ('Current Time: '+str(time_stamp_ts)) 50 | 51 | print('Starting remotes check...') 52 | for pool in self.pools: 53 | #orig_list = pool.urls[:] 54 | #print ('Debug:'+str(type(pool.urls))+str(len(pool.urls))) 55 | #print('Debug:'+str(type(orig_list))+str(len(orig_list))) 56 | 57 | ## For avg 58 | tot_diff = 0 59 | 60 | ##print(pool.urls) 61 | ##print(list(chunks(pool.urls,3))) 62 | ##exit() 63 | self.list_of_urls_returned = list(chunks(pool.urls,3)) 64 | for url_chunk in self.list_of_urls_returned: 65 | print("Testing the URL Chunk: ") 66 | print(url_chunk) 67 | 68 | self.list_of_urls_returned, \ 69 | self.list_of_status, \ 70 | self.list_of_unixtimes, \ 71 | self.list_of_took_time, \ 72 | self.list_of_half_took_time, \ 73 | self.list_off_time_diff_raw_int, \ 74 | self.list_off_time_diff_lag_cleaned_float, \ 75 | = get_time_from_servers( 76 | self.pools, 77 | url_chunk, 78 | proxy_ip, 79 | proxy_port 80 | ) 81 | 82 | for url in range(len(self.urls)): 83 | #print('Debug:'+self.returned_values[url]) 84 | if 'Timeout' in str(self.returned_values[url]): 85 | msg = 'pool %s url %s: %s' % (self.pools.index(pool) + 1, self.urls[url], self.returned_values[url]) 86 | msg += exec_curl(self.urls[url]) 87 | elif 'error' in str(self.returned_values[url]): 88 | msg = 'pool %s url %s: %s' % (self.pools.index(pool) + 1, self.urls[url], (self.returned_values[url]).decode()) 89 | msg += exec_curl(self.urls[url]) 90 | elif 'Parsing' in str(self.returned_values[url]): 91 | msg = 'pool %s url %s: %s' % (self.pools.index(pool) + 1, self.urls[url], self.returned_values[url]) 92 | msg += exec_curl(self.urls[url]) 93 | else: 94 | msg = 'pool %s url %s: Time: %s Difference: %d' % (self.pools.index(pool) + 1, self.urls[url], (self.returned_values[url]).decode(), int(time.time()) - int(self.returned_values[url])) 95 | tot_diff += abs(int(time.time()) - int(self.returned_values[url])) 96 | print(msg) 97 | f.write('%s\n' % msg) 98 | ## End For url in self.urls 99 | ## End For each URL Chunk 100 | avg = tot_diff/len(pool.urls) 101 | print("##############################") 102 | print("Avg of Pool :"+str(self.pools.index(pool)+1) +" having URLs #:"+ str(len(pool.urls)) +" is "+str(avg)) 103 | print("##############################") 104 | ## End for each URL Pool (there are 3 such pools) 105 | 106 | if __name__ == '__main__': 107 | remotes = CheckRemotes() 108 | remotes.loop() 109 | -------------------------------------------------------------------------------- /usr/share/sdwdate/test-clock-fast: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ## Copyright (C) 2020 - 2025 ENCRYPTED SUPPORT LLC 4 | ## See the file COPYING for copying conditions. 5 | 6 | set -x 7 | set -e 8 | 9 | if [ ! "$(id -u)" = "0" ]; then 10 | true "$0: ERROR: Must be run as root!" 11 | exit 1 12 | fi 13 | 14 | systemctl stop tor@default 15 | systemctl stop vanguards &>/dev/null || true 16 | 17 | date --set "Sat 09 Jan 2050 02:33:24 AM UTC" 18 | 19 | rm -f /var/lib/tor/cached-certs 20 | rm -f /var/lib/tor/cached-microdesc-consensus 21 | rm -f /var/lib/tor/cached-microdescs.new 22 | rm -f /var/lib/tor/keys 23 | rm -f /var/lib/tor/lock 24 | rm -f /var/lib/tor/state 25 | rm -f /var/lib/tor/vanguards.state 26 | 27 | if systemctl is-enabled vanguards &>/dev/null ; then 28 | systemctl restart vanguards || true 29 | fi 30 | systemctl restart tor@default 31 | 32 | sdwdate-clock-jump 33 | 34 | true "$0: OK" 35 | -------------------------------------------------------------------------------- /usr/share/sdwdate/test-clock-slow: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ## Copyright (C) 2020 - 2025 ENCRYPTED SUPPORT LLC 4 | ## See the file COPYING for copying conditions. 5 | 6 | set -x 7 | set -e 8 | 9 | if [ ! "$(id -u)" = "0" ]; then 10 | true "$0: ERROR: Must be run as root!" 11 | exit 1 12 | fi 13 | 14 | systemctl stop tor@default 15 | systemctl stop vanguards &>/dev/null || true 16 | 17 | date --set "Sat 09 Jan 2000 02:33:24 AM UTC" 18 | 19 | rm -f /var/lib/tor/cached-certs 20 | rm -f /var/lib/tor/cached-microdesc-consensus 21 | rm -f /var/lib/tor/cached-microdescs.new 22 | rm -f /var/lib/tor/keys 23 | rm -f /var/lib/tor/lock 24 | rm -f /var/lib/tor/state 25 | rm -f /var/lib/tor/vanguards.state 26 | 27 | if systemctl is-enabled vanguards &>/dev/null ; then 28 | systemctl restart vanguards || true 29 | fi 30 | systemctl restart tor@default 31 | 32 | sdwdate-clock-jump 33 | 34 | true "$0: OK" 35 | -------------------------------------------------------------------------------- /usr/share/translations/sdwdate.yaml: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2015 troubadour 2 | ## Copyright (C) 2015 - 2025 ENCRYPTED SUPPORT LLC 3 | ## See the file COPYING for copying conditions. 4 | 5 | sdwdate: 6 | en: 7 | fetching: 'Time fetching in progress...' 8 | restricted: 'Initial time fetching in progress...' 9 | sigterm: 'Signal SIGTERM received.' 10 | sleeping: 'Sleeping for ' 11 | minutes: ' minutes, ok.' 12 | success: 'Success.' 13 | 14 | no_valid_time: 'Time is not set: no valid time returned from pool.
15 | Possible causes: 16 |
- internet connection is down 17 |
- Tor is not running' 18 | no_value_returned: 'No values returned from servers.' 19 | list_not_built: 'Something is wrong. sdwdate could not build a list or urls.' 20 | restart: '
Restart sdwdate. If the problem persists, please report this bug.
' 21 | 22 | general_proxy_error: 'General Proxy Error. Is Tor running?' 23 | general_timeout_error: 'General Timeout Error. Internet connection might be down.' 24 | 25 | max_pool_failures_1: 'Maximum allowed number of failures reached in pool ' 26 | max_pool_failures_2: '. Giving up.
If the problem occurs too frequently, please report it.' 27 | -------------------------------------------------------------------------------- /usr/src/sdwdate/sclockadj.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 - 2025 ENCRYPTED SUPPORT LLC 3 | See the file COPYING for copying conditions. 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | /* receive time adjustment, negative or positive, in nanoseconds */ 12 | /* long long 64bit is at least -9,223,372,036,854,775,807 to +9,223,372,036,854,775,807 */ 13 | /* exits program upon failure */ 14 | void change_time_by_nanoseconds(long long add_ns) 15 | { 16 | struct timespec tps; /* tv_sec; tv_nsec */ 17 | if (clock_gettime(CLOCK_REALTIME, &tps) == -1) /* get current time in seconds since epoch + nanoseconds offset */ 18 | { 19 | perror("Failed to get current time!"); 20 | exit(EXIT_FAILURE); 21 | } 22 | /* combine seconds and nanoseconds offset in order to add nanoseconds*/ 23 | long long ns_since_epoch = 24 | (long long)(tps.tv_sec) * 1000000000 + /* convert seconds to nanoseconds */ 25 | (long long)(tps.tv_nsec); /* add offset */ 26 | long long new_ns_since_epoch = ns_since_epoch + add_ns; 27 | /* separate new nanoseconds since epoch into seconds and nanoseconds offset */ 28 | long new_s = new_ns_since_epoch / 1000000000; /* truncates into seconds */ 29 | long new_ns = new_ns_since_epoch % 1000000000; /* nanoseconds remainder */ 30 | /* set old struct with new values */ 31 | tps.tv_sec = new_s; 32 | tps.tv_nsec = new_ns; 33 | /* set time with new values */ 34 | if (clock_settime(CLOCK_REALTIME, &tps) == -1) 35 | { 36 | perror("Failed to change clock!"); 37 | exit(EXIT_FAILURE); 38 | } 39 | } 40 | 41 | /* intended to be used only by sdwdate with sane inputs */ 42 | int main(int argc, char *argv[]) 43 | { 44 | if (argc < 2) { 45 | perror("Too few args!"); 46 | exit(EXIT_FAILURE); 47 | } 48 | if (argc > 2) { 49 | perror("Too many args!"); 50 | exit(EXIT_FAILURE); 51 | } 52 | long long ns_time_change = atoll(argv[1]); /* convert argv string into long long */ 53 | if (ns_time_change == 0) 54 | { 55 | perror("Failed to get nanosecond argument!"); 56 | exit(EXIT_FAILURE); /* exit if atoll fails */ 57 | } 58 | 59 | /* since nanosecond jump is fixed, we can count the number of complete jumps. */ 60 | /* llabs for negative numbers */ 61 | static int const full_jump = 5000000; 62 | long long number_of_full_jumps = llabs(ns_time_change) / full_jump; /* times we'll move clock by 5,000,000 ns at a time */ 63 | long long last_jump_nanoseconds = llabs(ns_time_change) % full_jump; /* then add remaining < 5,000,000 ns */ 64 | 65 | if (ns_time_change > 0) /* positive nanosecond change */ 66 | { 67 | for (unsigned i = 0; i < number_of_full_jumps; ++i) 68 | { 69 | sleep(1); /* a 1 second wait imitates ntpdate */ 70 | change_time_by_nanoseconds(full_jump); /* 5,000,000 ns imitates ntpdate */ 71 | } 72 | sleep(1); 73 | change_time_by_nanoseconds(last_jump_nanoseconds); 74 | } 75 | else /* negative nanosecond change */ 76 | { 77 | for (unsigned i = 0; i < number_of_full_jumps; ++i) 78 | { 79 | sleep(1); 80 | change_time_by_nanoseconds(-full_jump); 81 | } 82 | sleep(1); 83 | change_time_by_nanoseconds(-last_jump_nanoseconds); /* negative of absolute value imitates Euclidean modulo */ 84 | } 85 | return EXIT_SUCCESS; 86 | } 87 | --------------------------------------------------------------------------------