BACKPORT: tlsdated: support command-line proxy override

This makes a proxy passed on the command line with -x supplant proxies for
configured sources, and makes the 'proxy' stanza in sources optional (in which
case we supply no proxy argument for them).

BUG=chromium-os:38801
TEST=unit

Signed-off-by: Elly Fong-Jones <ellyjones@chromium.org>
(cherry picked from commit 254dc20bbaa68f955b1de8c7da6a02d52c786fd0)

Change-Id: I537037bd15d7c873f87e820a5291fc7a7e0ffca1
Reviewed-on: https://gerrit.chromium.org/gerrit/44075
Reviewed-by: Will Drewry <wad@chromium.org>
Commit-Queue: Elly Jones <ellyjones@chromium.org>
Tested-by: Elly Jones <ellyjones@chromium.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
BACKPORT: tlsdate-helper: fix SAN checking

Right now, SAN checking checks against the host we're opening a socket to
instead of the host we're actually trying to talk to, which is fine... as long
as we don't have a proxy. Note that this problem only manifests for hosts whose
CN is not equal to their hostname (so the default host of www.ptb.de is fine).

To observe the problem:
$ ssh -D 127.0.0.1:30000 somehost
$ tlsdate -H clients3.google.com -x socks5://127.0.0.1:30000
hostname verification failed for host 127.0.0.1!
child process failed in SSL handshake

With this fix, you instead see no output.

BUG=chromium-os:38801
TEST=adhoc
Test steps given above.

Signed-off-by: Elly Fong-Jones <ellyjones@chromium.org>
(cherry picked from commit ceb1fe26c3136fc206101b757bdae298e729acf9)

Change-Id: If57d7cc6a8c12bbbcefa95bb8414a37445434eb4
Reviewed-on: https://gerrit.chromium.org/gerrit/44277
Reviewed-by: Elly Jones <ellyjones@chromium.org>
Tested-by: Elly Jones <ellyjones@chromium.org>
Commit-Queue: Elly Jones <ellyjones@chromium.org>
BACKPORT: tlsdate-dbus-announce: use name and flush connection

Have tlsdate-dbus-announce grab a well-known bus name before it sends its
signal, and have it wait for the signal to actually be sent over the bus before
exiting.

Signed-off-by: Elly Fong-Jones <ellyjones@chromium.org>
(cherry picked from commit f258f78782e362bf26c6cf606f11293d68632780)

Change-Id: Ica80f47d7f2317c9c31e0d34ccbc23873f087c50
Reviewed-on: https://gerrit.chromium.org/gerrit/44534
Reviewed-by: Kees Cook <keescook@chromium.org>
Commit-Queue: Elly Jones <ellyjones@chromium.org>
Tested-by: Elly Jones <ellyjones@chromium.org>
Fix subprocess watching.

Currently, the subprocess watching code polls with a delay between attempts.
Instead, introduce wait_with_timeout() and use it, simplifying this code.

Signed-off-by: Elly Fong-Jones <elly@leptoquark.net>
Merge pull request #114 from elly/refactor

Fix subprocess watching.
David Hill noticed that we sometimes leave &warp_time uninitalized
add verbosity for privilege dropping attempt
Merge branch 'master' of github.com:ioerror/tlsdate
Add integration testing.

These new integration tests mostly focus on tlsdated's subprocess code.

Signed-off-by: Elly Fong-Jones <elly@leptoquark.net>
Merge pull request #116 from elly/integration

Add integration testing.
Update CHANGELOG for integration tests.
Merge pull request #117 from elly/integration-changelog

Update CHANGELOG for integration tests.
Refactor event loop.

Refactor the event loop to be modular and testable. Also, add support for
detecting corruption of the realtime clock, as can be caused by suspend/resume
cycles without an rtc battery. The event loop is now driven by a tree of events,
which are either sources (currently suspend/resume events, periodic events, and
network route events) or composite events.

Signed-off-by: Elly Fong-Jones <elly@leptoquark.net>
tlsdate: add optional --showtime support for "raw"

Add support for optional arguments to --showtime, "raw" and "human".

Human readable output is what --showtime and -V do already.  Passing
in --showtime=raw will tell tlsdate-helper to write the raw
unix time directly to stdout in host byte order.

The purpose of this change is to provide easier integration of
privilege isolation for time setting.  If tlsdate is called from
a wrapper, like tlsdated, it should be possible to pass the time back
to a privileged time-setter with the minimum of needed parsing.
tlsdate, docs: make -V taken an optional arg to simplify showtime

Update the man pages and simplify the processing of -V
and --showtime to share the optional argument path.
Merge pull request #118 from elly/event-loop

Refactor event loop.
Merge pull request #119 from redpig/showtime=raw

tlsdate: add optional --showtime support for "raw"
Rudimentary support for HTTP Date headers

Since I'm going on a personal crusade to kill off gmt_unix_time, I
should provide an alternative.  That alternative can be the Date
header from HTTP -- unlike gmt_unix_time, the Date header is required
by the RFC to actually be an accurate clock-like clock, and nobody is
trying to get rid of it.

This code is pretty hack-ish and does some nonportable stuff, like
using memmem() and timegm().  It's not super-tolerant of
non-standards-compliant HTTP servers.  I hope I didn't make any
pointer mistakes.
BACKPORT: tlsdate: add optional --showtime support for "raw"

Add support for optional arguments to --showtime, "raw" and "human".

Human readable output is what --showtime and -V do already.  Passing
in --showtime=raw will tell tlsdate-helper to write the raw
unix time directly to stdout in host byte order.

The purpose of this change is to provide easier integration of
privilege isolation for time setting.  If tlsdate is called from
a wrapper, like tlsdated, it should be possible to pass the time back
to a privileged time-setter with the minimum of needed parsing.

TEST=manual
BUG=chromium:262137

Change-Id: I94bde171688fc84f9962d90ddf9ef28e6652eec0
Reviewed-on: https://chromium-review.googlesource.com/169970
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Will Drewry <wad@chromium.org>
Commit-Queue: Will Drewry <wad@chromium.org>
Tested-by: Will Drewry <wad@chromium.org>
BACKPORT: tlsdate, docs: make -V taken an optional arg to simplify showtime

Update the man pages and simplify the processing of -V
and --showtime to share the optional argument path.

TEST=manual
BUG=chromium:262137

Change-Id: I42eac2d27c0c2b23ff50b4a3d4b52d376d28e450
Reviewed-on: https://chromium-review.googlesource.com/169980
Reviewed-by: Kees Cook <keescook@chromium.org>
Commit-Queue: Will Drewry <wad@chromium.org>
Tested-by: Will Drewry <wad@chromium.org>