Handling of OpenSSL encryption. More...
#include "config.h"
#include <errno.h>
#include <openssl/asn1.h>
#include <openssl/bio.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/obj_mac.h>
#include <openssl/opensslv.h>
#include <openssl/ossl_typ.h>
#include <openssl/pem.h>
#include <openssl/rand.h>
#include <openssl/safestack.h>
#include <openssl/ssl.h>
#include <openssl/x509.h>
#include <openssl/x509v3.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <sys/stat.h>
#include <unistd.h>
#include "private.h"
#include "mutt/lib.h"
#include "address/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "connaccount.h"
#include "connection.h"
#include "globals.h"
#include "mutt_logging.h"
#include "ssl.h"
Go to the source code of this file.
Functions | |
static | STACK_OF (X509) |
Keep a handle on accepted certificates in case we want to open up another connection to the same server in this session. | |
static bool | ssl_load_certificates (SSL_CTX *ctx) |
Load certificates and filter out the expired ones. | |
static bool | ssl_set_verify_partial (SSL_CTX *ctx) |
Allow verification using partial chains (with no root) | |
static int | add_entropy (const char *file) |
Add a source of random numbers. | |
static void | ssl_err (struct SslSockData *data, int err) |
Display an SSL error message. | |
static void | ssl_dprint_err_stack (void) |
Dump the SSL error stack. | |
static int | ssl_passwd_cb (char *buf, int buflen, int rwflag, void *userdata) |
Callback to get a password. | |
static int | ssl_socket_open_err (struct Connection *conn) |
Error callback for opening an SSL connection - Implements Connection::open() -. | |
static char * | x509_get_part (X509_NAME *name, int nid) |
Retrieve from X509 data. | |
static void | x509_fingerprint (struct Buffer *buf, X509 *cert, const EVP_MD *(*hashfunc)(void)) |
Generate a fingerprint for an X509 certificate. | |
static char * | asn1time_to_string (ASN1_UTCTIME *tm) |
Convert a time to a string. | |
static bool | certificates_equal (X509 *cert, X509 *peercert, unsigned char *peermd, unsigned int peermdlen) |
Compare two X509 certificated. | |
static bool | check_certificate_expiration (X509 *peercert, bool silent) |
Check if a certificate has expired. | |
static bool | hostname_match (const char *hostname, const char *certname) |
Does the hostname match the certificate. | |
static int | ssl_init (void) |
Initialise the SSL library. | |
static void | ssl_get_client_cert (struct SslSockData *ssldata, struct Connection *conn) |
Get the client certificate for an SSL connection. | |
static int | ssl_socket_close_and_restore (struct Connection *conn) |
Close an SSL Connection and restore Connection callbacks - Implements Connection::close() -. | |
static bool | check_certificate_cache (X509 *peercert) |
Is the X509 Certificate in the cache? | |
static bool | check_certificate_file (X509 *peercert) |
Read and check a certificate file. | |
static int | check_host (X509 *x509cert, const char *hostname, char *err, size_t errlen) |
Check the host on the certificate. | |
static bool | check_certificate_by_digest (X509 *peercert) |
Validate a certificate by its digest. | |
static int | ssl_cache_trusted_cert (X509 *c) |
Cache a trusted certificate. | |
static void | add_cert (const char *title, X509 *cert, bool issuer, struct CertArray *carr) |
Look up certificate info and save it to a list. | |
static bool | interactive_check_cert (X509 *cert, int idx, size_t len, SSL *ssl, bool allow_always) |
Ask the user if a certificate is valid. | |
static int | ssl_verify_callback (int preverify_ok, X509_STORE_CTX *ctx) |
Certificate verification callback. | |
static int | ssl_negotiate (struct Connection *conn, struct SslSockData *ssldata) |
Attempt to negotiate SSL over the wire. | |
static struct SslSockData * | sockdata (struct Connection *conn) |
Get a Connection's socket data. | |
static int | ssl_setup (struct Connection *conn) |
Set up SSL on the Connection. | |
static int | ssl_socket_poll (struct Connection *conn, time_t wait_secs) |
Check if any data is waiting on a socket - Implements Connection::poll() -. | |
static int | ssl_socket_open (struct Connection *conn) |
Open an SSL socket - Implements Connection::open() -. | |
static int | ssl_socket_read (struct Connection *conn, char *buf, size_t count) |
Read data from an SSL socket - Implements Connection::read() -. | |
static int | ssl_socket_write (struct Connection *conn, const char *buf, size_t count) |
Write data to an SSL socket - Implements Connection::write() -. | |
static int | ssl_socket_close (struct Connection *conn) |
Close an SSL connection - Implements Connection::close() -. | |
int | mutt_ssl_starttls (struct Connection *conn) |
Negotiate TLS over an already opened connection. | |
int | mutt_ssl_socket_setup (struct Connection *conn) |
Set up SSL socket mulitplexor. | |
Variables | |
static int | HostExDataIndex = -1 |
index for storing hostname as application specific data in SSL structure | |
static int | SkipModeExDataIndex = -1 |
Index for storing the "skip mode" state in SSL structure. | |
Handling of OpenSSL encryption.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Definition in file openssl.c.
|
static |
|
static |
Load certificates and filter out the expired ones.
ctx | SSL context |
1 | Success |
0 | Error |
ssl certificate verification can behave strangely if there are expired certs loaded into the trusted store. This function filters out expired certs.
Previously the code used this form: SSL_CTX_load_verify_locations (ssldata->ctx, $certificate_file
, NULL);
Definition at line 119 of file openssl.c.
|
static |
Allow verification using partial chains (with no root)
ctx | SSL context |
true | Success |
false | Error |
Definition at line 168 of file openssl.c.
|
static |
Add a source of random numbers.
file | Random device |
>0 | Success, number of bytes read from the source |
-1 | Error |
Definition at line 204 of file openssl.c.
|
static |
Display an SSL error message.
data | SSL socket data |
err | SSL error code |
Definition at line 239 of file openssl.c.
|
static |
Dump the SSL error stack.
Definition at line 308 of file openssl.c.
|
static |
Callback to get a password.
buf | Buffer for the password |
buflen | Length of the buffer |
rwflag | 0 if writing, 1 if reading (UNUSED) |
userdata | ConnAccount whose password is requested |
>0 | Success, number of chars written to buf |
0 | Error |
Definition at line 337 of file openssl.c.
|
static |
Retrieve from X509 data.
name | Name of data to retrieve |
nid | ID of the item to retrieve |
ptr | Retrieved data |
The returned pointer is to a static buffer, so it must not be free()'d.
Definition at line 370 of file openssl.c.
|
static |
Generate a fingerprint for an X509 certificate.
buf | Buffer for fingerprint |
cert | Certificate |
hashfunc | Hashing function |
Definition at line 386 of file openssl.c.
|
static |
Convert a time to a string.
tm | Time to convert |
ptr | Time string |
The returned pointer is to a static buffer, so it must not be free()'d.
Definition at line 414 of file openssl.c.
|
static |
Compare two X509 certificated.
cert | Certificate |
peercert | Peer certificate |
peermd | Peer certificate message digest |
peermdlen | Length of peer certificate message digest |
true | Certificates match |
false | Certificates differ |
Definition at line 441 of file openssl.c.
|
static |
Check if a certificate has expired.
peercert | Certificate to check |
silent | If true, don't notify the user if the certificate has expired |
true | Certificate is valid |
false | Certificate has expired (or hasn't yet become valid) |
Definition at line 471 of file openssl.c.
|
static |
Does the hostname match the certificate.
hostname | Hostname |
certname | Certificate |
true | Hostname matches the certificate |
Definition at line 506 of file openssl.c.
|
static |
Initialise the SSL library.
0 | Success |
-1 | Error |
OpenSSL library needs to be fed with sufficient entropy. On systems with /dev/urandom, this is done transparently by the library itself, on other systems we need to fill the entropy pool ourselves.
Even though only OpenSSL 0.9.5 and later will complain about the lack of entropy, we try to our best and fill the pool with older versions also. (That's the reason for the ugly ifdefs and macros, otherwise I could have simply ifdef'd the whole ssl_init function)
Definition at line 552 of file openssl.c.
|
static |
Get the client certificate for an SSL connection.
ssldata | SSL socket data |
conn | Connection to a server |
Definition at line 605 of file openssl.c.
|
static |
Is the X509 Certificate in the cache?
peercert | Certificate |
true | Certificate is in the cache |
Definition at line 637 of file openssl.c.
|
static |
Read and check a certificate file.
peercert | Certificate |
true | Certificate is valid |
false | Error, or certificate is invalid |
Definition at line 666 of file openssl.c.
|
static |
Check the host on the certificate.
x509cert | Certificate |
hostname | Hostname |
err | Buffer for error message |
errlen | Length of buffer |
1 | Hostname matches the certificate |
0 | Error |
Definition at line 712 of file openssl.c.
|
static |
Validate a certificate by its digest.
peercert | Certificate |
true | Certificate is valid |
false | Error |
Definition at line 821 of file openssl.c.
|
static |
Cache a trusted certificate.
c | Certificate |
>0 | Number of elements in the cache |
0 | Error |
Definition at line 832 of file openssl.c.
|
static |
Look up certificate info and save it to a list.
title | Title for this block of certificate info |
cert | Certificate |
issuer | If true, look up the issuer rather than owner details |
carr | Array to save info to |
Definition at line 847 of file openssl.c.
|
static |
Ask the user if a certificate is valid.
cert | Certificate |
idx | Place of certificate in the chain |
len | Length of the certificate chain |
ssl | SSL state |
allow_always | If certificate may be always allowed |
true | User selected 'skip' |
false | Otherwise |
Definition at line 891 of file openssl.c.
|
static |
Certificate verification callback.
preverify_ok | If true, don't question the user if they skipped verification |
ctx | X509 store context |
true | Certificate is valid |
false | Error, or Certificate is invalid |
Called for each certificate in the chain sent by the peer, starting from the root; returning true means that the given certificate is trusted, returning false immediately aborts the SSL connection
Definition at line 1001 of file openssl.c.
|
static |
Attempt to negotiate SSL over the wire.
conn | Connection to a server |
ssldata | SSL socket data |
0 | Success |
-1 | Error |
After SSL state has been initialized, attempt to negotiate SSL over the wire, including certificate checks.
Definition at line 1117 of file openssl.c.
|
inlinestatic |
Get a Connection's socket data.
conn | Connection |
ptr | Socket data |
Definition at line 1194 of file openssl.c.
|
static |
Set up SSL on the Connection.
conn | Connection |
0 | Success |
-1 | Failure |
Definition at line 1205 of file openssl.c.
int mutt_ssl_starttls | ( | struct Connection * | conn | ) |
Negotiate TLS over an already opened connection.
conn | Connection to a server |
0 | Success |
-1 | Error |
Definition at line 1422 of file openssl.c.
int mutt_ssl_socket_setup | ( | struct Connection * | conn | ) |
Set up SSL socket mulitplexor.
conn | Connection to a server |
0 | Success |
-1 | Error |
Definition at line 1444 of file openssl.c.
|
static |