5a1f25
 configure.in             |   34 +++++++++++++++++++++++++++++++++-
5a1f25
 src/network/ssl/socket.c |   28 ++++++++++++++++++++++------
5a1f25
 src/network/ssl/ssl.c    |   32 ++++++++++++++++++++++++++------
5a1f25
 src/network/ssl/ssl.h    |    2 +-
5a1f25
 4 files changed, 82 insertions(+), 14 deletions(-)
5a1f25
5a1f25
diff --git a/configure.in b/configure.in
5a1f25
index 0e534db..972a305 100644
5a1f25
--- a/configure.in
5a1f25
+++ b/configure.in
5a1f25
@@ -970,6 +970,37 @@ AC_ARG_WITH(openssl, [[  --with-openssl[=DIR]    enable OpenSSL support (default
5a1f25
 		*)	chosen_ssl_library="OpenSSL" ;;
5a1f25
 	     esac])
5a1f25
 
5a1f25
+AC_ARG_WITH(nss_compat_ossl, [[  --with-nss_compat_ossl[=DIR]
5a1f25
+                          NSS compatibility SSL libraries/include files]])
5a1f25
+
5a1f25
+# nss_compat_ossl
5a1f25
+if test -n "$with_nss_compat_ossl" && test "$with_nss_compat_ossl" != "no"; then
5a1f25
+	EL_SAVE_FLAGS
5a1f25
+	if test "$with_nss_compat_ossl" = yes; then
5a1f25
+		if pkg-config nss; then
5a1f25
+			CFLAGS="$CFLAGS_X `pkg-config --cflags nss`"
5a1f25
+			LIBS="$LIBS_X `pkg-config --libs nss`"
5a1f25
+		else
5a1f25
+			with_nss_compat_ossl=no
5a1f25
+		fi
5a1f25
+	else
5a1f25
+		# Without pkg-config, we'll kludge in some defaults
5a1f25
+		CFLAGS="$CFLAGS_X -I$with_nss_compat_ossl/include -I/usr/include/nss3 -I/usr/include/nspr4"
5a1f25
+		LIBS="$LIBS_X -L$with_nss_compat_ossl/lib -lssl3 -lsmime3 -lnss3 -lplds4 -lplc4 -lnspr4 -lpthread -ldl"
5a1f25
+	fi
5a1f25
+	AC_CHECK_HEADERS(nss_compat_ossl/nss_compat_ossl.h,, [with_nss_compat_ossl=no], [#define NSS_COMPAT_OSSL_H])
5a1f25
+	AC_CHECK_LIB(nss_compat_ossl, X509_free,, [with_nss_compat_ossl=no])
5a1f25
+
5a1f25
+	if test "$with_nss_compat_ossl" = "no"; then
5a1f25
+		EL_RESTORE_FLAGS
5a1f25
+	else
5a1f25
+		LIBS="$LIBS -lnss_compat_ossl"
5a1f25
+		EL_CONFIG(CONFIG_NSS_COMPAT_OSSL, [nss_compat_ossl])
5a1f25
+		disable_openssl="yes"
5a1f25
+		disable_gnutls="yes"
5a1f25
+	fi
5a1f25
+fi
5a1f25
+
5a1f25
 # ---- OpenSSL
5a1f25
 
5a1f25
 AC_MSG_CHECKING([for OpenSSL])
5a1f25
@@ -1092,10 +1123,11 @@ fi
5a1f25
 
5a1f25
 # Final SSL setup
5a1f25
 
5a1f25
-EL_CONFIG_DEPENDS(CONFIG_SSL, [CONFIG_OPENSSL CONFIG_GNUTLS], [SSL])
5a1f25
+EL_CONFIG_DEPENDS(CONFIG_SSL, [CONFIG_OPENSSL CONFIG_GNUTLS CONFIG_NSS_COMPAT_OSSL], [SSL])
5a1f25
 AC_SUBST(CONFIG_GNUTLS_OPENSSL_COMPAT)
5a1f25
 AC_SUBST(CONFIG_OPENSSL)
5a1f25
 AC_SUBST(CONFIG_GNUTLS)
5a1f25
+AC_SUBST(CONFIG_NSS_COMPAT_OSSL)
5a1f25
 
5a1f25
 #endif
5a1f25
 
5a1f25
diff --git a/src/network/ssl/socket.c b/src/network/ssl/socket.c
5a1f25
index 45b4b4a..3265107 100644
5a1f25
--- a/src/network/ssl/socket.c
5a1f25
+++ b/src/network/ssl/socket.c
5a1f25
@@ -6,6 +6,10 @@
5a1f25
 
5a1f25
 #ifdef CONFIG_OPENSSL
5a1f25
 #include <openssl/ssl.h>
5a1f25
+#define USE_OPENSSL
5a1f25
+#elif defined(CONFIG_NSS_COMPAT_OSSL)
5a1f25
+#include <nss_compat_ossl/nss_compat_ossl.h>
5a1f25
+#define USE_OPENSSL
5a1f25
 #elif defined(CONFIG_GNUTLS)
5a1f25
 #include <gnutls/gnutls.h>
5a1f25
 #else
5a1f25
@@ -26,7 +30,7 @@
5a1f25
 
5a1f25
 
5a1f25
 /* SSL errors */
5a1f25
-#ifdef CONFIG_OPENSSL
5a1f25
+#ifdef USE_OPENSSL
5a1f25
 #define	SSL_ERROR_WANT_READ2	9999 /* XXX */
5a1f25
 #define	SSL_ERROR_WANT_WRITE2	SSL_ERROR_WANT_WRITE
5a1f25
 #define	SSL_ERROR_SYSCALL2	SSL_ERROR_SYSCALL
5a1f25
@@ -40,7 +44,7 @@
5a1f25
 #define	SSL_ERROR_SYSCALL2	GNUTLS_E_PULL_ERROR
5a1f25
 #endif
5a1f25
 
5a1f25
-#ifdef CONFIG_OPENSSL
5a1f25
+#ifdef USE_OPENSSL
5a1f25
 
5a1f25
 #define ssl_do_connect(socket)		SSL_get_error(socket->ssl, SSL_connect(socket->ssl))
5a1f25
 #define ssl_do_write(socket, data, len)	SSL_write(socket->ssl, data, len)
5a1f25
@@ -126,7 +130,7 @@ ssl_connect(struct socket *socket)
5a1f25
 	if (socket->no_tls)
5a1f25
 		ssl_set_no_tls(socket);
5a1f25
 
5a1f25
-#ifdef CONFIG_OPENSSL
5a1f25
+#ifdef USE_OPENSSL
5a1f25
 	SSL_set_fd(socket->ssl, socket->fd);
5a1f25
 
5a1f25
 	if (get_opt_bool("connection.ssl.cert_verify"))
5a1f25
@@ -137,7 +141,13 @@ ssl_connect(struct socket *socket)
5a1f25
 	if (get_opt_bool("connection.ssl.client_cert.enable")) {
5a1f25
 		unsigned char *client_cert;
5a1f25
 
5a1f25
-		client_cert = get_opt_str("connection.ssl.client_cert.file");
5a1f25
+#ifdef CONFIG_NSS_COMPAT_OSSL
5a1f25
+		client_cert = get_opt_str(
5a1f25
+				"connection.ssl.client_cert.nickname");
5a1f25
+#else
5a1f25
+		client_cert = get_opt_str(
5a1f25
+				"connection.ssl.client_cert.file");
5a1f25
+#endif
5a1f25
 		if (!*client_cert) {
5a1f25
 			client_cert = getenv("X509_CLIENT_CERT");
5a1f25
 			if (client_cert && !*client_cert)
5a1f25
@@ -145,11 +155,17 @@ ssl_connect(struct socket *socket)
5a1f25
 		}
5a1f25
 
5a1f25
 		if (client_cert) {
5a1f25
+#ifdef CONFIG_NSS_COMPAT_OSSL
5a1f25
+			SSL_CTX_use_certificate_chain_file(
5a1f25
+					(SSL *) socket->ssl,
5a1f25
+					client_cert);
5a1f25
+#else
5a1f25
 			SSL_CTX *ctx = ((SSL *) socket->ssl)->ctx;
5a1f25
 
5a1f25
 			SSL_CTX_use_certificate_chain_file(ctx, client_cert);
5a1f25
 			SSL_CTX_use_PrivateKey_file(ctx, client_cert,
5a1f25
 						    SSL_FILETYPE_PEM);
5a1f25
+#endif
5a1f25
 		}
5a1f25
 	}
5a1f25
 
5a1f25
@@ -206,7 +222,7 @@ ssl_write(struct socket *socket, unsigned char *data, int len)
5a1f25
 	ssize_t wr = ssl_do_write(socket, data, len);
5a1f25
 
5a1f25
 	if (wr <= 0) {
5a1f25
-#ifdef CONFIG_OPENSSL
5a1f25
+#ifdef USE_OPENSSL
5a1f25
 		int err = SSL_get_error(socket->ssl, wr);
5a1f25
 #elif defined(CONFIG_GNUTLS)
5a1f25
 		int err = wr;
5a1f25
@@ -235,7 +251,7 @@ ssl_read(struct socket *socket, unsigned char *data, int len)
5a1f25
 	ssize_t rd = ssl_do_read(socket, data, len);
5a1f25
 
5a1f25
 	if (rd <= 0) {
5a1f25
-#ifdef CONFIG_OPENSSL
5a1f25
+#ifdef USE_OPENSSL
5a1f25
 		int err = SSL_get_error(socket->ssl, rd);
5a1f25
 #elif defined(CONFIG_GNUTLS)
5a1f25
 		int err = rd;
5a1f25
diff --git a/src/network/ssl/ssl.c b/src/network/ssl/ssl.c
5a1f25
index 685c31e..73446b5 100644
5a1f25
--- a/src/network/ssl/ssl.c
5a1f25
+++ b/src/network/ssl/ssl.c
5a1f25
@@ -7,6 +7,10 @@
5a1f25
 #ifdef CONFIG_OPENSSL
5a1f25
 #include <openssl/ssl.h>
5a1f25
 #include <openssl/rand.h>
5a1f25
+#define USE_OPENSSL
5a1f25
+#elif defined(CONFIG_NSS_COMPAT_OSSL)
5a1f25
+#include <nss_compat_ossl/nss_compat_ossl.h>
5a1f25
+#define USE_OPENSSL
5a1f25
 #elif defined(CONFIG_GNUTLS)
5a1f25
 #include <gnutls/gnutls.h>
5a1f25
 #include <gnutls/x509.h>
5a1f25
@@ -33,7 +37,7 @@
5a1f25
 /* FIXME: As you can see, SSL is currently implemented in very, erm,
5a1f25
  * decentralized manner. */
5a1f25
 
5a1f25
-#ifdef CONFIG_OPENSSL
5a1f25
+#ifdef USE_OPENSSL
5a1f25
 
5a1f25
 #ifndef PATH_MAX
5a1f25
 #define	PATH_MAX	256 /* according to my /usr/include/bits/posix1_lim.h */
5a1f25
@@ -71,12 +75,28 @@ static union option_info openssl_options[] = {
5a1f25
 		N_("Enable or not the sending of X509 client certificates "
5a1f25
 		"to servers which request them.")),
5a1f25
 
5a1f25
+#ifdef CONFIG_NSS_COMPAT_OSSL
5a1f25
+	INIT_OPT_STRING("connection.ssl.client_cert", N_("Certificate nickname"),
5a1f25
+		"nickname", 0, "",
5a1f25
+		N_("The nickname of the client certificate stored in NSS "
5a1f25
+		"database. If this value is unset, the nickname from "
5a1f25
+		"the X509_CLIENT_CERT variable is used instead. If you "
5a1f25
+		"have a PKCS#12 file containing client certificate, you "
5a1f25
+		"can import it into your NSS database with:\n"
5a1f25
+		"\n"
5a1f25
+		"$ pk12util -i mycert.p12 -d /path/to/database\n"
5a1f25
+		"\n"
5a1f25
+		"The NSS database location can be changed by SSL_DIR "
5a1f25
+		"environment variable. The database can be also shared "
5a1f25
+		"with Mozilla browsers.")),
5a1f25
+#else
5a1f25
 	INIT_OPT_STRING("connection.ssl.client_cert", N_("Certificate File"),
5a1f25
 		"file", 0, "",
5a1f25
 		N_("The location of a file containing the client certificate "
5a1f25
 		"and unencrypted private key in PEM format. If unset, the "
5a1f25
 		"file pointed to by the X509_CLIENT_CERT variable is used "
5a1f25
 		"instead.")),
5a1f25
+#endif
5a1f25
 
5a1f25
 	NULL_OPTION_INFO,
5a1f25
 };
5a1f25
@@ -182,7 +202,7 @@ static struct module gnutls_module = struct_module(
5a1f25
 	/* done: */		done_gnutls
5a1f25
 );
5a1f25
 
5a1f25
-#endif /* CONFIG_OPENSSL or CONFIG_GNUTLS */
5a1f25
+#endif /* USE_OPENSSL or CONFIG_GNUTLS */
5a1f25
 
5a1f25
 static union option_info ssl_options[] = {
5a1f25
 	INIT_OPT_TREE("connection", N_("SSL"),
5a1f25
@@ -193,7 +213,7 @@ static union option_info ssl_options[] = {
5a1f25
 };
5a1f25
 
5a1f25
 static struct module *ssl_modules[] = {
5a1f25
-#ifdef CONFIG_OPENSSL
5a1f25
+#ifdef USE_OPENSSL
5a1f25
 	&openssl_module,
5a1f25
 #elif defined(CONFIG_GNUTLS)
5a1f25
 	&gnutls_module,
5a1f25
@@ -214,7 +234,7 @@ struct module ssl_module = struct_module(
5a1f25
 int
5a1f25
 init_ssl_connection(struct socket *socket)
5a1f25
 {
5a1f25
-#ifdef CONFIG_OPENSSL
5a1f25
+#ifdef USE_OPENSSL
5a1f25
 	socket->ssl = SSL_new(context);
5a1f25
 	if (!socket->ssl) return S_SSL_ERROR;
5a1f25
 #elif defined(CONFIG_GNUTLS)
5a1f25
@@ -271,7 +291,7 @@ done_ssl_connection(struct socket *socket)
5a1f25
 	ssl_t *ssl = socket->ssl;
5a1f25
 
5a1f25
 	if (!ssl) return;
5a1f25
-#ifdef CONFIG_OPENSSL
5a1f25
+#ifdef USE_OPENSSL
5a1f25
 	SSL_free(ssl);
5a1f25
 #elif defined(CONFIG_GNUTLS)
5a1f25
 	gnutls_deinit(*ssl);
5a1f25
@@ -288,7 +308,7 @@ get_ssl_connection_cipher(struct socket *socket)
5a1f25
 
5a1f25
 	if (!init_string(&str)) return NULL;
5a1f25
 
5a1f25
-#ifdef CONFIG_OPENSSL
5a1f25
+#ifdef USE_OPENSSL
5a1f25
 	add_format_to_string(&str, "%ld-bit %s %s",
5a1f25
 		SSL_get_cipher_bits(ssl, NULL),
5a1f25
 		SSL_get_cipher_version(ssl),
5a1f25
diff --git a/src/network/ssl/ssl.h b/src/network/ssl/ssl.h
5a1f25
index 7c54a7a..21ca142 100644
5a1f25
--- a/src/network/ssl/ssl.h
5a1f25
+++ b/src/network/ssl/ssl.h
5a1f25
@@ -22,7 +22,7 @@ unsigned char *get_ssl_connection_cipher(struct socket *socket);
5a1f25
 
5a1f25
 /* Internal type used in ssl module. */
5a1f25
 
5a1f25
-#ifdef CONFIG_OPENSSL
5a1f25
+#if defined(CONFIG_OPENSSL) || defined(CONFIG_NSS_COMPAT_OSSL)
5a1f25
 #define	ssl_t	SSL
5a1f25
 #elif defined(CONFIG_GNUTLS)
5a1f25
 #define	ssl_t	gnutls_session_t