2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-29 05:18:13 +00:00

17 Commits

Author SHA1 Message Date
Ben Pfaff
3d47699cdf stream-ssl: Flush OpenSSL error queue after calling SSL_shutdown().
The OpenSSL manpage for SSL_get_error() says this:

   In addition to ssl and ret, SSL_get_error() inspects the current
   thread's OpenSSL error queue.  Thus, SSL_get_error() must be used in
   the same thread that performed the TLS/SSL I/O operation, and no other
   OpenSSL function calls should appear in between.  The current thread's
   error queue must be empty before the TLS/SSL I/O operation is
   attempted, or SSL_get_error() will not work reliably.

We weren't taking this advice literally enough, which meant that this
would happen:

   1. Call SSL_shutdown() on one connection.
   2. Call SSL_read() on another connection, returning 0 bytes.  (This is
      normal.  It just means that no more data has arrived yet.)
   3. Call SSL_get_error() for that second connection to check whether
      the 0-byte return value was a real error.  (This should return
      SSL_ERROR_WANT_READ to indicate that more data is needed.)
   4. Actually get some other error indicating that the SSL_shutdown()
      call returned an error.

This commit fixes the problem by flushing the OpenSSL error queue after
calling SSL_shutdown().

Without this commit, starting an ovsdb-server with two active SSL remotes,
running two ovsdb-clients listening for connections from the ovsdb-server
remotes, then killing one of the ovsdb-clients (with e.g. Control+C), will
cause ovsdb-server to drop the other ovsdb-client connnection the next time
that SSL_read() is called on it.  With this commit, this scenario works
correctly (e.g. ovsdb-server keeps the remaining connection up).

CC: Jeremy Stribling <strib@nicira.com>
2010-05-13 16:08:14 -07:00
Ben Pfaff
1e3c004749 Diagnose attempts to connect the wrong protocol to a network port.
Sometimes, when a user asks me to help debug a problem, it turns out that
an SSL connection was being made on a TCP port, or vice versa, or that an
OpenFlow connection was being made on a JSON-RPC port, or vice versa, and
so on.  This commit adds log messages that diagnose this kind of problem,
e.g. "tcp:127.0.0.1:6633: received JSON-RPC data on OpenFlow channel".
2010-05-11 11:50:45 -07:00
Ben Pfaff
26efd2563b socket-util: Move get_mtime() here from stream-ssl.
An upcoming commit will add a new user for this function in another file,
so export it and move it to a common library file.
2010-04-26 11:29:32 -07:00
Ben Pfaff
2b1a27a1f8 stream-ssl: Avoid access-after-free error in update_ssl_config().
Commit b84f503d "stream-ssl: Read existing CA certificate more eagerly
during bootstrap" inadvertently introduced an access-after-free error:

  do_ca_cert_bootstrap() calls
    stream_ssl_set_ca_cert_file(ca_cert.file_name, true), which calls
      update_ssl_config(&ca_cert, file_name), which calls
        free(ca_cert.file_name) then xstrdup(ca_cert.file_name).

Fix the problem.

Reported-by: Cedric Hobbs <cedric@nicira.com>
Reported-by: Peter Balland <peter@nicira.com>
2010-04-14 16:02:45 -07:00
Ben Pfaff
ba104a1e39 stream-ssl: Make it possible to avoid checking peer SSL certificate.
In Citrix XenServer, the hosts have SSL private keys and certificates, but
those certificates are not signed by any certificate authority.  So we
must provide a way to avoid checking certificates against a CA if we want
other OVS tools to be able to talk to XenServer hosts over SSL.  This
commit makes that possible.
2010-04-12 11:03:32 -07:00
Ben Pfaff
b84f503d84 stream-ssl: Read existing CA certificate more eagerly during bootstrap.
When do_ca_cert_bootstrap() attempts to bootstrap a CA certificate from a
remote host, it gives up if the CA certificate file already exists.  It
knows that this file did not exist some time earlier (because it checked),
so it logged a warning and just returns.  The next time that
stream_ssl_set_ca_cert_file() gets called, it will read the new CA
certificate file and all will be well.

That works OK in ovsdb-server, which calls stream_ssl_set_ca_cert_file()
every time through its main loop.  It does not work well for ovs-vswitchd,
which only calls that function when it needs to reconfigure.  But it
should work fine to call it directly from do_ca_cert_bootstrap(), so this
commit changes it to do that.

Bug #2635.
2010-04-12 10:49:16 -07:00
Ben Pfaff
9cb0788702 stream-ssl: Only re-read certificates and keys if they change.
Commit 415f6c0b1 "stream-ssl: Make no-op reconfiguration cheap" caused
ovsdb-server to re-read its certificates and keys every 60 seconds just
in case they changed.  However, doing this causes OpenSSL to drop its
connections.  This commit solves the problem by making stream-ssl re-read
certificates and keys only if the files changed.

Bug #2535.
Reported-by: Ram Jothikumar <rjothikumar@nicira.com>
2010-03-24 16:52:07 -07:00
Ben Pfaff
415f6c0b1c stream-ssl: Make no-op reconfiguration cheap.
Until now, the stream_ssl functions for configuring private keys,
certificates, and CA certificates have always called into OpenSSL to read
a file.  This commit instead makes them do that only if the file name
changed (or it has been 60 seconds since we last tried, in case someone
installed the file behind our backs).

This allows us to factor some code out of vswitchd.  In an upcoming commit
we will want to do essentially the same thing from ovsdb-server, so this
avoid code redundancy.
2010-03-19 15:18:37 -07:00
Ben Pfaff
deb1f4336c stream-ssl: Permit race in bootstrapping CA certificate.
If two processes were both configured to bootstrap the CA certificate, then
one of them would succeed in writing it to a file and use it, and the other
one would fail to use it because the file was created behind its back.
This commit fixes the problem by making the bootstrap code accept a CA
certificate file that exists at the time that bootstrapping tries to create
it.
2010-03-19 15:18:37 -07:00
Ben Pfaff
c69ee87c10 Merge "master" into "next".
The main change here is the need to update all of the uses of UNUSED in
the next branch to OVS_UNUSED as it is now spelled on "master".
2010-02-11 11:11:23 -08:00
Ben Pfaff
f6b60e026e stream-ssl: Fix unimportant memory leak.
This function is generally called only once per program execution, so
leaking a little bit of memory does not matter that much.

Found with valgrind.
2010-02-02 15:21:09 -08:00
Ben Pfaff
1504c76330 stream-ssl: Fix bug that crept in during rebasing. 2010-01-08 09:40:45 -08:00
Ben Pfaff
2b494771fd stream-ssl: Fix ssl_recv() and ssl_send() return value semantics.
These functions' return value semantics did not match those documented
in stream-provider.h.
2010-01-07 15:00:51 -08:00
Ben Pfaff
5e4641a147 stream-ssl: Try to shut SSL connections down gracefully.
It's nice to shut down SSL connections gracefully when we can.
2010-01-07 15:00:51 -08:00
Ben Pfaff
42967038cb stream: Make passive SSL and TCP streams report bound addresses as names.
The names of passive SSL and TCP streams were being poorly reported: TCP
always simply reported "ptcp", and SSL reported whatever was passed in.
This commit makes them report the addresses that were actually bound by
the TCP/IP stack, which is more useful for testing, debugging, and logging.
2010-01-07 15:00:51 -08:00
Ben Pfaff
36775dad35 socket-util: Make inet_open_passive() pass back the bound address.
This feature is useful in an upcoming commit.
2010-01-07 15:00:47 -08:00
Ben Pfaff
9467fe6246 Add SSL support to "stream" library and OVSDB. 2010-01-06 14:30:29 -08:00