|
|
dccbab |
From b3bb13e18a74e9ece825b7de1b81db97ebb107a0 Mon Sep 17 00:00:00 2001
|
|
|
dccbab |
From: Iker Pedrosa <ipedrosa@redhat.com>
|
|
|
dccbab |
Date: Thu, 25 Mar 2021 09:43:30 +0100
|
|
|
dccbab |
Subject: [PATCH] pam_timestamp: replace hmac implementation
|
|
|
dccbab |
|
|
|
dccbab |
sha1 is no longer recommended as a cryptographic algorithm for
|
|
|
dccbab |
authentication. Thus, the idea of this change is to replace the
|
|
|
dccbab |
implementation provided by hmacsha1 included in pam_timestamp module by
|
|
|
dccbab |
the one in the openssl library. This way, there's no need to maintain
|
|
|
dccbab |
the cryptographic algorithm implementation and it can be easily changed
|
|
|
dccbab |
with a single configuration change.
|
|
|
dccbab |
|
|
|
dccbab |
modules/pam_timestamp/hmac_openssl_wrapper.c: implement wrapper
|
|
|
dccbab |
functions around openssl's hmac implementation. Moreover, manage the key
|
|
|
dccbab |
generation and its read and write in a file. Include an option to
|
|
|
dccbab |
configure the cryptographic algorithm in login.defs file.
|
|
|
dccbab |
modules/pam_timestamp/hmac_openssl_wrapper.h: likewise.
|
|
|
dccbab |
modules/pam_timestamp/pam_timestamp.c: replace calls to functions
|
|
|
dccbab |
provided by hmacsha1 by functions provided by openssl's wrapper.
|
|
|
dccbab |
configure.ac: include openssl dependecy if it is enabled.
|
|
|
dccbab |
modules/pam_timestamp/Makefile.am: include new files and openssl library
|
|
|
dccbab |
to compilation.
|
|
|
dccbab |
ci/install-dependencies.sh: include openssl library to dependencies.
|
|
|
dccbab |
NEWS: add new item to next release.
|
|
|
dccbab |
Make.xml.rules.in: add stringparam profiling for hmac
|
|
|
dccbab |
doc/custom-man.xsl: change import docbook to one with profiling
|
|
|
dccbab |
modules/pam_timestamp/pam_timestamp.8.xml: add conditional paragraph to
|
|
|
dccbab |
indicate the value in /etc/login.defs that holds the value for the
|
|
|
dccbab |
encryption algorithm
|
|
|
dccbab |
|
|
|
dccbab |
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1947294
|
|
|
dccbab |
---
|
|
|
dccbab |
Make.xml.rules.in | 2 +-
|
|
|
dccbab |
NEWS | 5 +
|
|
|
dccbab |
configure.ac | 16 +
|
|
|
dccbab |
doc/custom-man.xsl | 2 +-
|
|
|
dccbab |
modules/pam_timestamp/Makefile.am | 15 +-
|
|
|
dccbab |
modules/pam_timestamp/hmac_openssl_wrapper.c | 381 +++++++++++++++++++
|
|
|
dccbab |
modules/pam_timestamp/hmac_openssl_wrapper.h | 57 +++
|
|
|
dccbab |
modules/pam_timestamp/pam_timestamp.8.xml | 5 +
|
|
|
dccbab |
modules/pam_timestamp/pam_timestamp.c | 53 ++-
|
|
|
dccbab |
10 files changed, 524 insertions(+), 13 deletions(-)
|
|
|
dccbab |
create mode 100644 modules/pam_timestamp/hmac_openssl_wrapper.c
|
|
|
dccbab |
create mode 100644 modules/pam_timestamp/hmac_openssl_wrapper.h
|
|
|
dccbab |
|
|
|
dccbab |
diff --git a/Make.xml.rules.in b/Make.xml.rules.in
|
|
|
dccbab |
index daa1b97b..27bb510e 100644
|
|
|
dccbab |
--- a/Make.xml.rules.in
|
|
|
dccbab |
+++ b/Make.xml.rules.in
|
|
|
dccbab |
@@ -21,6 +21,6 @@ README: README.xml
|
|
|
dccbab |
|
|
|
dccbab |
%.8: %.8.xml
|
|
|
dccbab |
$(XMLLINT) --nonet --xinclude --postvalid --noout $<
|
|
|
dccbab |
- $(XSLTPROC) -o $(srcdir)/$@ --path $(srcdir) --xinclude @STRINGPARAM_VENDORDIR@ --nonet $(top_srcdir)/doc/custom-man.xsl $<
|
|
|
dccbab |
+ $(XSLTPROC) -o $(srcdir)/$@ --path $(srcdir) --xinclude @STRINGPARAM_VENDORDIR@ @STRINGPARAM_HMAC@ --nonet $(top_srcdir)/doc/custom-man.xsl $<
|
|
|
dccbab |
|
|
|
dccbab |
#CLEANFILES += $(man_MANS) README
|
|
|
dccbab |
diff --git a/NEWS b/NEWS
|
|
|
dccbab |
index 2d49ec39..f4d11303 100644
|
|
|
dccbab |
--- a/NEWS
|
|
|
dccbab |
+++ b/NEWS
|
|
|
dccbab |
@@ -1,5 +1,10 @@
|
|
|
dccbab |
Linux-PAM NEWS -- history of user-visible changes.
|
|
|
dccbab |
|
|
|
dccbab |
+Release next
|
|
|
dccbab |
+* pam_timestamp: change hmac algorithm to call openssl instead of the bundled
|
|
|
dccbab |
+ sha1 implementation if selected. Add option to select the hash
|
|
|
dccbab |
+ algorithm to use with HMAC.
|
|
|
dccbab |
+
|
|
|
dccbab |
Release 1.5.1
|
|
|
dccbab |
* pam_unix: fixed CVE-2020-27780 - authentication bypass when a user
|
|
|
dccbab |
doesn't exist and root password is blank
|
|
|
dccbab |
diff --git a/configure.ac b/configure.ac
|
|
|
dccbab |
index bd806473..9c92d0de 100644
|
|
|
dccbab |
--- a/configure.ac
|
|
|
dccbab |
+++ b/configure.ac
|
|
|
dccbab |
@@ -504,6 +504,22 @@ else
|
|
|
dccbab |
fi
|
|
|
dccbab |
AC_SUBST([STRINGPARAM_VENDORDIR])
|
|
|
dccbab |
|
|
|
dccbab |
+AC_ARG_ENABLE([openssl],
|
|
|
dccbab |
+ AS_HELP_STRING([--enable-openssl],[use OpenSSL crypto libraries]),
|
|
|
dccbab |
+ [OPENSSL_ENABLED=$enableval], OPENSSL_ENABLED=no)
|
|
|
dccbab |
+if test "$OPENSSL_ENABLED" = "yes" ; then
|
|
|
dccbab |
+ AC_CHECK_LIB([crypto], [EVP_MAC_CTX_new],
|
|
|
dccbab |
+ [CRYPTO_LIBS="-lcrypto"
|
|
|
dccbab |
+ use_openssl=yes
|
|
|
dccbab |
+ AC_DEFINE([WITH_OPENSSL], 1, [OpenSSL provides crypto algorithm for hmac])
|
|
|
dccbab |
+ STRINGPARAM_HMAC="--stringparam profile.condition 'openssl_hmac'"],
|
|
|
dccbab |
+ [CRYPTO_LIBS=""
|
|
|
dccbab |
+ STRINGPARAM_HMAC="--stringparam profile.condition 'no_openssl_hmac'"])
|
|
|
dccbab |
+fi
|
|
|
dccbab |
+AC_SUBST([CRYPTO_LIBS])
|
|
|
dccbab |
+AC_SUBST([STRINGPARAM_HMAC])
|
|
|
dccbab |
+AM_CONDITIONAL([COND_USE_OPENSSL], [test "x$use_openssl" = "xyes"])
|
|
|
dccbab |
+
|
|
|
dccbab |
dnl Checks for header files.
|
|
|
dccbab |
AC_HEADER_DIRENT
|
|
|
dccbab |
AC_HEADER_STDC
|
|
|
dccbab |
diff --git a/doc/custom-man.xsl b/doc/custom-man.xsl
|
|
|
dccbab |
index 4c35e839..a3408e6c 100644
|
|
|
dccbab |
--- a/doc/custom-man.xsl
|
|
|
dccbab |
+++ b/doc/custom-man.xsl
|
|
|
dccbab |
@@ -1,6 +1,6 @@
|
|
|
dccbab |
|
|
|
dccbab |
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ss="http://docbook.sf.net/xmlns/string.subst/1.0" version="1.0">
|
|
|
dccbab |
- <xsl:import href="http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl"/>
|
|
|
dccbab |
+ <xsl:import href="http://docbook.sourceforge.net/release/xsl/current/manpages/profile-docbook.xsl"/>
|
|
|
dccbab |
<xsl:param name="vendordir"/>
|
|
|
dccbab |
|
|
|
dccbab |
<xsl:param name="man.string.subst.map.local.pre">
|
|
|
dccbab |
diff --git a/modules/pam_timestamp/Makefile.am b/modules/pam_timestamp/Makefile.am
|
|
|
dccbab |
index 1faa324a..d290b85f 100644
|
|
|
dccbab |
--- a/modules/pam_timestamp/Makefile.am
|
|
|
dccbab |
+++ b/modules/pam_timestamp/Makefile.am
|
|
|
dccbab |
@@ -18,12 +18,12 @@ TESTS = $(dist_check_SCRIPTS) $(check_PROGRAMS)
|
|
|
dccbab |
securelibdir = $(SECUREDIR)
|
|
|
dccbab |
secureconfdir = $(SCONFIGDIR)
|
|
|
dccbab |
|
|
|
dccbab |
-noinst_HEADERS = hmacsha1.h sha1.h
|
|
|
dccbab |
+noinst_HEADERS = hmacsha1.h sha1.h hmac_openssl_wrapper.h
|
|
|
dccbab |
|
|
|
dccbab |
AM_CFLAGS = -I$(top_srcdir)/libpam/include -I$(top_srcdir)/libpamc/include \
|
|
|
dccbab |
$(WARN_CFLAGS)
|
|
|
dccbab |
|
|
|
dccbab |
-pam_timestamp_la_LDFLAGS = -no-undefined -avoid-version -module $(AM_LDFLAGS)
|
|
|
dccbab |
+pam_timestamp_la_LDFLAGS = -no-undefined -avoid-version -module $(AM_LDFLAGS) $(CRYPTO_LIBS)
|
|
|
dccbab |
pam_timestamp_la_LIBADD = $(top_builddir)/libpam/libpam.la
|
|
|
dccbab |
if HAVE_VERSIONING
|
|
|
dccbab |
pam_timestamp_la_LDFLAGS += -Wl,--version-script=$(srcdir)/../modules.map
|
|
|
dccbab |
@@ -32,7 +32,12 @@ endif
|
|
|
dccbab |
securelib_LTLIBRARIES = pam_timestamp.la
|
|
|
dccbab |
sbin_PROGRAMS = pam_timestamp_check
|
|
|
dccbab |
|
|
|
dccbab |
-pam_timestamp_la_SOURCES = pam_timestamp.c hmacsha1.c sha1.c
|
|
|
dccbab |
+pam_timestamp_la_SOURCES = pam_timestamp.c
|
|
|
dccbab |
+if COND_USE_OPENSSL
|
|
|
dccbab |
+pam_timestamp_la_SOURCES += hmac_openssl_wrapper.c
|
|
|
dccbab |
+else
|
|
|
dccbab |
+pam_timestamp_la_SOURCES += hmacsha1.c sha1.c
|
|
|
dccbab |
+endif
|
|
|
dccbab |
pam_timestamp_la_CFLAGS = $(AM_CFLAGS)
|
|
|
dccbab |
|
|
|
dccbab |
pam_timestamp_check_SOURCES = pam_timestamp_check.c
|
|
|
dccbab |
@@ -40,7 +45,11 @@ pam_timestamp_check_CFLAGS = $(AM_CFLAGS) @EXE_CFLAGS@
|
|
|
dccbab |
pam_timestamp_check_LDADD = $(top_builddir)/libpam/libpam.la
|
|
|
dccbab |
pam_timestamp_check_LDFLAGS = @EXE_LDFLAGS@
|
|
|
dccbab |
|
|
|
dccbab |
+if COND_USE_OPENSSL
|
|
|
dccbab |
+hmacfile_SOURCES = hmac_openssl_wrapper.c
|
|
|
dccbab |
+else
|
|
|
dccbab |
hmacfile_SOURCES = hmacfile.c hmacsha1.c sha1.c
|
|
|
dccbab |
+endif
|
|
|
dccbab |
hmacfile_LDADD = $(top_builddir)/libpam/libpam.la
|
|
|
dccbab |
|
|
|
dccbab |
check_PROGRAMS = hmacfile
|
|
|
dccbab |
diff --git a/modules/pam_timestamp/hmac_openssl_wrapper.c b/modules/pam_timestamp/hmac_openssl_wrapper.c
|
|
|
dccbab |
new file mode 100644
|
|
|
dccbab |
index 00000000..926c2fb9
|
|
|
dccbab |
--- /dev/null
|
|
|
dccbab |
+++ b/modules/pam_timestamp/hmac_openssl_wrapper.c
|
|
|
dccbab |
@@ -0,0 +1,381 @@
|
|
|
dccbab |
+/* Wrapper for hmac openssl implementation.
|
|
|
dccbab |
+ *
|
|
|
dccbab |
+ * Copyright (c) 2021 Red Hat, Inc.
|
|
|
dccbab |
+ * Written by Iker Pedrosa <ipedrosa@redhat.com>
|
|
|
dccbab |
+ *
|
|
|
dccbab |
+ * Redistribution and use in source and binary forms, with or without
|
|
|
dccbab |
+ * modification, are permitted provided that the following conditions
|
|
|
dccbab |
+ * are met:
|
|
|
dccbab |
+ * 1. Redistributions of source code must retain the above copyright
|
|
|
dccbab |
+ * notice, and the entire permission notice in its entirety,
|
|
|
dccbab |
+ * including the disclaimer of warranties.
|
|
|
dccbab |
+ * 2. Redistributions in binary form must reproduce the above copyright
|
|
|
dccbab |
+ * notice, this list of conditions and the following disclaimer in the
|
|
|
dccbab |
+ * documentation and/or other materials provided with the distribution.
|
|
|
dccbab |
+ * 3. The name of the author may not be used to endorse or promote
|
|
|
dccbab |
+ * products derived from this software without specific prior
|
|
|
dccbab |
+ * written permission.
|
|
|
dccbab |
+ *
|
|
|
dccbab |
+ * ALTERNATIVELY, this product may be distributed under the terms of
|
|
|
dccbab |
+ * the GNU Public License, in which case the provisions of the GPL are
|
|
|
dccbab |
+ * required INSTEAD OF the above restrictions. (This clause is
|
|
|
dccbab |
+ * necessary due to a potential bad interaction between the GPL and
|
|
|
dccbab |
+ * the restrictions contained in a BSD-style copyright.)
|
|
|
dccbab |
+ *
|
|
|
dccbab |
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
|
|
dccbab |
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
dccbab |
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
dccbab |
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
|
|
dccbab |
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
dccbab |
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
dccbab |
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
dccbab |
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
dccbab |
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
dccbab |
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
|
|
dccbab |
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
dccbab |
+ *
|
|
|
dccbab |
+ */
|
|
|
dccbab |
+
|
|
|
dccbab |
+#include "config.h"
|
|
|
dccbab |
+
|
|
|
dccbab |
+#ifdef WITH_OPENSSL
|
|
|
dccbab |
+
|
|
|
dccbab |
+#include <sys/stat.h>
|
|
|
dccbab |
+#include <fcntl.h>
|
|
|
dccbab |
+#include <syslog.h>
|
|
|
dccbab |
+#include <unistd.h>
|
|
|
dccbab |
+#include <string.h>
|
|
|
dccbab |
+#include <errno.h>
|
|
|
dccbab |
+#include <openssl/evp.h>
|
|
|
dccbab |
+#include <openssl/params.h>
|
|
|
dccbab |
+#include <openssl/core_names.h>
|
|
|
dccbab |
+
|
|
|
dccbab |
+#include <security/pam_ext.h>
|
|
|
dccbab |
+#include <security/pam_modutil.h>
|
|
|
dccbab |
+
|
|
|
dccbab |
+#include "hmac_openssl_wrapper.h"
|
|
|
dccbab |
+
|
|
|
dccbab |
+#define LOGIN_DEFS "/etc/login.defs"
|
|
|
dccbab |
+#define CRYPTO_KEY "HMAC_CRYPTO_ALGO"
|
|
|
dccbab |
+#define DEFAULT_ALGORITHM "SHA512"
|
|
|
dccbab |
+#define MAX_HMAC_LENGTH 512
|
|
|
dccbab |
+#define MAX_KEY_LENGTH EVP_MAX_KEY_LENGTH
|
|
|
dccbab |
+
|
|
|
dccbab |
+static char *
|
|
|
dccbab |
+get_crypto_algorithm(pam_handle_t *pamh, int debug){
|
|
|
dccbab |
+ char *config_value = NULL;
|
|
|
dccbab |
+
|
|
|
dccbab |
+ config_value = pam_modutil_search_key(pamh, LOGIN_DEFS, CRYPTO_KEY);
|
|
|
dccbab |
+
|
|
|
dccbab |
+ if (config_value == NULL) {
|
|
|
dccbab |
+ config_value = strdup(DEFAULT_ALGORITHM);
|
|
|
dccbab |
+ if (debug) {
|
|
|
dccbab |
+ pam_syslog(pamh, LOG_DEBUG,
|
|
|
dccbab |
+ "Key [%s] not found, falling back to default algorithm [%s]\n",
|
|
|
dccbab |
+ CRYPTO_KEY, DEFAULT_ALGORITHM);
|
|
|
dccbab |
+ }
|
|
|
dccbab |
+ }
|
|
|
dccbab |
+
|
|
|
dccbab |
+ return config_value;
|
|
|
dccbab |
+}
|
|
|
dccbab |
+
|
|
|
dccbab |
+static int
|
|
|
dccbab |
+generate_key(pam_handle_t *pamh, char **key, size_t key_size)
|
|
|
dccbab |
+{
|
|
|
dccbab |
+ int fd = 0;
|
|
|
dccbab |
+ size_t bytes_read = 0;
|
|
|
dccbab |
+ char * tmp = NULL;
|
|
|
dccbab |
+
|
|
|
dccbab |
+ fd = open("/dev/urandom", O_RDONLY);
|
|
|
dccbab |
+ if (fd == -1) {
|
|
|
dccbab |
+ pam_syslog(pamh, LOG_ERR, "Cannot open /dev/urandom: %m");
|
|
|
dccbab |
+ return PAM_AUTH_ERR;
|
|
|
dccbab |
+ }
|
|
|
dccbab |
+
|
|
|
dccbab |
+ tmp = malloc(key_size);
|
|
|
dccbab |
+ if (!tmp) {
|
|
|
dccbab |
+ pam_syslog(pamh, LOG_CRIT, "Not enough memory");
|
|
|
dccbab |
+ close(fd);
|
|
|
dccbab |
+ return PAM_AUTH_ERR;
|
|
|
dccbab |
+ }
|
|
|
dccbab |
+
|
|
|
dccbab |
+ bytes_read = pam_modutil_read(fd, tmp, key_size);
|
|
|
dccbab |
+ close(fd);
|
|
|
dccbab |
+
|
|
|
dccbab |
+ if (bytes_read < key_size) {
|
|
|
dccbab |
+ pam_syslog(pamh, LOG_ERR, "Short read on random device");
|
|
|
dccbab |
+ free(tmp);
|
|
|
dccbab |
+ return PAM_AUTH_ERR;
|
|
|
dccbab |
+ }
|
|
|
dccbab |
+
|
|
|
dccbab |
+ *key = tmp;
|
|
|
dccbab |
+
|
|
|
dccbab |
+ return PAM_SUCCESS;
|
|
|
dccbab |
+}
|
|
|
dccbab |
+
|
|
|
dccbab |
+static int
|
|
|
dccbab |
+read_file(pam_handle_t *pamh, int fd, char **text, size_t *text_length)
|
|
|
dccbab |
+{
|
|
|
dccbab |
+ struct stat st;
|
|
|
dccbab |
+ size_t bytes_read = 0;
|
|
|
dccbab |
+ char *tmp = NULL;
|
|
|
dccbab |
+
|
|
|
dccbab |
+ if (fstat(fd, &st) == -1) {
|
|
|
dccbab |
+ pam_syslog(pamh, LOG_ERR, "Unable to stat file: %m");
|
|
|
dccbab |
+ close(fd);
|
|
|
dccbab |
+ return PAM_AUTH_ERR;
|
|
|
dccbab |
+ }
|
|
|
dccbab |
+
|
|
|
dccbab |
+ if (st.st_size == 0) {
|
|
|
dccbab |
+ pam_syslog(pamh, LOG_ERR, "Key file size cannot be 0");
|
|
|
dccbab |
+ close(fd);
|
|
|
dccbab |
+ return PAM_AUTH_ERR;
|
|
|
dccbab |
+ }
|
|
|
dccbab |
+
|
|
|
dccbab |
+ tmp = malloc(st.st_size);
|
|
|
dccbab |
+ if (!tmp) {
|
|
|
dccbab |
+ pam_syslog(pamh, LOG_CRIT, "Not enough memory");
|
|
|
dccbab |
+ close(fd);
|
|
|
dccbab |
+ return PAM_AUTH_ERR;
|
|
|
dccbab |
+ }
|
|
|
dccbab |
+
|
|
|
dccbab |
+ bytes_read = pam_modutil_read(fd, tmp, st.st_size);
|
|
|
dccbab |
+ close(fd);
|
|
|
dccbab |
+
|
|
|
dccbab |
+ if (bytes_read < (size_t)st.st_size) {
|
|
|
dccbab |
+ pam_syslog(pamh, LOG_ERR, "Short read on key file");
|
|
|
dccbab |
+ memset(tmp, 0, st.st_size);
|
|
|
dccbab |
+ free(tmp);
|
|
|
dccbab |
+ return PAM_AUTH_ERR;
|
|
|
dccbab |
+ }
|
|
|
dccbab |
+
|
|
|
dccbab |
+ *text = tmp;
|
|
|
dccbab |
+ *text_length = st.st_size;
|
|
|
dccbab |
+
|
|
|
dccbab |
+ return PAM_SUCCESS;
|
|
|
dccbab |
+}
|
|
|
dccbab |
+
|
|
|
dccbab |
+static int
|
|
|
dccbab |
+write_file(pam_handle_t *pamh, const char *file_name, char *text,
|
|
|
dccbab |
+ size_t text_length, uid_t owner, gid_t group)
|
|
|
dccbab |
+{
|
|
|
dccbab |
+ int fd = 0;
|
|
|
dccbab |
+ size_t bytes_written = 0;
|
|
|
dccbab |
+
|
|
|
dccbab |
+ fd = open(file_name,
|
|
|
dccbab |
+ O_WRONLY | O_CREAT | O_TRUNC,
|
|
|
dccbab |
+ S_IRUSR | S_IWUSR);
|
|
|
dccbab |
+ if (fd == -1) {
|
|
|
dccbab |
+ pam_syslog(pamh, LOG_ERR, "Unable to open [%s]: %m", file_name);
|
|
|
dccbab |
+ memset(text, 0, text_length);
|
|
|
dccbab |
+ free(text);
|
|
|
dccbab |
+ return PAM_AUTH_ERR;
|
|
|
dccbab |
+ }
|
|
|
dccbab |
+
|
|
|
dccbab |
+ if (fchown(fd, owner, group) == -1) {
|
|
|
dccbab |
+ pam_syslog(pamh, LOG_ERR, "Unable to change ownership [%s]: %m", file_name);
|
|
|
dccbab |
+ memset(text, 0, text_length);
|
|
|
dccbab |
+ free(text);
|
|
|
dccbab |
+ close(fd);
|
|
|
dccbab |
+ return PAM_AUTH_ERR;
|
|
|
dccbab |
+ }
|
|
|
dccbab |
+
|
|
|
dccbab |
+ bytes_written = pam_modutil_write(fd, text, text_length);
|
|
|
dccbab |
+ close(fd);
|
|
|
dccbab |
+
|
|
|
dccbab |
+ if (bytes_written < text_length) {
|
|
|
dccbab |
+ pam_syslog(pamh, LOG_ERR, "Short write on %s", file_name);
|
|
|
dccbab |
+ free(text);
|
|
|
dccbab |
+ return PAM_AUTH_ERR;
|
|
|
dccbab |
+ }
|
|
|
dccbab |
+
|
|
|
dccbab |
+ return PAM_SUCCESS;
|
|
|
dccbab |
+}
|
|
|
dccbab |
+
|
|
|
dccbab |
+static int
|
|
|
dccbab |
+key_management(pam_handle_t *pamh, const char *file_name, char **text,
|
|
|
dccbab |
+ size_t text_length, uid_t owner, gid_t group)
|
|
|
dccbab |
+{
|
|
|
dccbab |
+ int fd = 0;
|
|
|
dccbab |
+
|
|
|
dccbab |
+ fd = open(file_name, O_RDONLY | O_NOFOLLOW);
|
|
|
dccbab |
+ if (fd == -1) {
|
|
|
dccbab |
+ if (errno == ENOENT) {
|
|
|
dccbab |
+ if (generate_key(pamh, text, text_length)) {
|
|
|
dccbab |
+ pam_syslog(pamh, LOG_ERR, "Unable to generate key");
|
|
|
dccbab |
+ return PAM_AUTH_ERR;
|
|
|
dccbab |
+ }
|
|
|
dccbab |
+
|
|
|
dccbab |
+ if (write_file(pamh, file_name, *text, text_length, owner, group)) {
|
|
|
dccbab |
+ pam_syslog(pamh, LOG_ERR, "Unable to write key");
|
|
|
dccbab |
+ return PAM_AUTH_ERR;
|
|
|
dccbab |
+ }
|
|
|
dccbab |
+ } else {
|
|
|
dccbab |
+ pam_syslog(pamh, LOG_ERR, "Unable to open %s: %m", file_name);
|
|
|
dccbab |
+ return PAM_AUTH_ERR;
|
|
|
dccbab |
+ }
|
|
|
dccbab |
+ } else {
|
|
|
dccbab |
+ if (read_file(pamh, fd, text, &text_length)) {
|
|
|
dccbab |
+ pam_syslog(pamh, LOG_ERR, "Error reading key file %s\n", file_name);
|
|
|
dccbab |
+ return PAM_AUTH_ERR;
|
|
|
dccbab |
+ }
|
|
|
dccbab |
+ }
|
|
|
dccbab |
+
|
|
|
dccbab |
+ return PAM_SUCCESS;
|
|
|
dccbab |
+}
|
|
|
dccbab |
+
|
|
|
dccbab |
+static int
|
|
|
dccbab |
+hmac_management(pam_handle_t *pamh, int debug, void **out, size_t *out_length,
|
|
|
dccbab |
+ char *key, size_t key_length,
|
|
|
dccbab |
+ const void *text, size_t text_length)
|
|
|
dccbab |
+{
|
|
|
dccbab |
+ int ret = PAM_AUTH_ERR;
|
|
|
dccbab |
+ EVP_MAC *evp_mac = NULL;
|
|
|
dccbab |
+ EVP_MAC_CTX *ctx = NULL;
|
|
|
dccbab |
+ unsigned char *hmac_message = NULL;
|
|
|
dccbab |
+ size_t hmac_length;
|
|
|
dccbab |
+ char *algo = NULL;
|
|
|
dccbab |
+ OSSL_PARAM subalg_param[] = { OSSL_PARAM_END, OSSL_PARAM_END };
|
|
|
dccbab |
+
|
|
|
dccbab |
+ algo = get_crypto_algorithm(pamh, debug);
|
|
|
dccbab |
+
|
|
|
dccbab |
+ subalg_param[0] = OSSL_PARAM_construct_utf8_string(OSSL_MAC_PARAM_DIGEST,
|
|
|
dccbab |
+ algo,
|
|
|
dccbab |
+ 0);
|
|
|
dccbab |
+
|
|
|
dccbab |
+ evp_mac = EVP_MAC_fetch(NULL, "HMAC", NULL);
|
|
|
dccbab |
+ if (evp_mac == NULL) {
|
|
|
dccbab |
+ pam_syslog(pamh, LOG_ERR, "Unable to create hmac implementation");
|
|
|
dccbab |
+ goto done;
|
|
|
dccbab |
+ }
|
|
|
dccbab |
+
|
|
|
dccbab |
+ ctx = EVP_MAC_CTX_new(evp_mac);
|
|
|
dccbab |
+ if (ctx == NULL) {
|
|
|
dccbab |
+ pam_syslog(pamh, LOG_ERR, "Unable to create hmac context");
|
|
|
dccbab |
+ goto done;
|
|
|
dccbab |
+ }
|
|
|
dccbab |
+
|
|
|
dccbab |
+ ret = EVP_MAC_init(ctx, (const unsigned char *)key, key_length, subalg_param);
|
|
|
dccbab |
+ if (ret == 0) {
|
|
|
dccbab |
+ pam_syslog(pamh, LOG_ERR, "Unable to initialize hmac context");
|
|
|
dccbab |
+ goto done;
|
|
|
dccbab |
+ }
|
|
|
dccbab |
+
|
|
|
dccbab |
+ ret = EVP_MAC_update(ctx, (const unsigned char *)text, text_length);
|
|
|
dccbab |
+ if (ret == 0) {
|
|
|
dccbab |
+ pam_syslog(pamh, LOG_ERR, "Unable to update hmac context");
|
|
|
dccbab |
+ goto done;
|
|
|
dccbab |
+ }
|
|
|
dccbab |
+
|
|
|
dccbab |
+ hmac_message = (unsigned char*)malloc(sizeof(unsigned char) * MAX_HMAC_LENGTH);
|
|
|
dccbab |
+ if (!hmac_message) {
|
|
|
dccbab |
+ pam_syslog(pamh, LOG_CRIT, "Not enough memory");
|
|
|
dccbab |
+ goto done;
|
|
|
dccbab |
+ }
|
|
|
dccbab |
+
|
|
|
dccbab |
+ ret = EVP_MAC_final(ctx, hmac_message, &hmac_length, MAX_HMAC_LENGTH);
|
|
|
dccbab |
+ if (ret == 0) {
|
|
|
dccbab |
+ pam_syslog(pamh, LOG_ERR, "Unable to calculate hmac message");
|
|
|
dccbab |
+ goto done;
|
|
|
dccbab |
+ }
|
|
|
dccbab |
+
|
|
|
dccbab |
+ *out_length = hmac_length;
|
|
|
dccbab |
+ *out = malloc(*out_length);
|
|
|
dccbab |
+ if (*out == NULL) {
|
|
|
dccbab |
+ pam_syslog(pamh, LOG_CRIT, "Not enough memory");
|
|
|
dccbab |
+ goto done;
|
|
|
dccbab |
+ }
|
|
|
dccbab |
+
|
|
|
dccbab |
+ memcpy(*out, hmac_message, *out_length);
|
|
|
dccbab |
+ ret = PAM_SUCCESS;
|
|
|
dccbab |
+
|
|
|
dccbab |
+done:
|
|
|
dccbab |
+ if (hmac_message != NULL) {
|
|
|
dccbab |
+ free(hmac_message);
|
|
|
dccbab |
+ }
|
|
|
dccbab |
+ if (key != NULL) {
|
|
|
dccbab |
+ memset(key, 0, key_length);
|
|
|
dccbab |
+ free(key);
|
|
|
dccbab |
+ }
|
|
|
dccbab |
+ if (ctx != NULL) {
|
|
|
dccbab |
+ EVP_MAC_CTX_free(ctx);
|
|
|
dccbab |
+ }
|
|
|
dccbab |
+ if (evp_mac != NULL) {
|
|
|
dccbab |
+ EVP_MAC_free(evp_mac);
|
|
|
dccbab |
+ }
|
|
|
dccbab |
+ free(algo);
|
|
|
dccbab |
+
|
|
|
dccbab |
+ return ret;
|
|
|
dccbab |
+}
|
|
|
dccbab |
+
|
|
|
dccbab |
+int
|
|
|
dccbab |
+hmac_size(pam_handle_t *pamh, int debug, size_t *hmac_length)
|
|
|
dccbab |
+{
|
|
|
dccbab |
+ int ret = PAM_AUTH_ERR;
|
|
|
dccbab |
+ EVP_MAC *evp_mac = NULL;
|
|
|
dccbab |
+ EVP_MAC_CTX *ctx = NULL;
|
|
|
dccbab |
+ const unsigned char key[] = "ThisIsJustAKey";
|
|
|
dccbab |
+ size_t key_length = MAX_KEY_LENGTH;
|
|
|
dccbab |
+ char *algo = NULL;
|
|
|
dccbab |
+ OSSL_PARAM subalg_param[] = { OSSL_PARAM_END, OSSL_PARAM_END };
|
|
|
dccbab |
+
|
|
|
dccbab |
+ algo = get_crypto_algorithm(pamh, debug);
|
|
|
dccbab |
+
|
|
|
dccbab |
+ subalg_param[0] = OSSL_PARAM_construct_utf8_string(OSSL_MAC_PARAM_DIGEST,
|
|
|
dccbab |
+ algo,
|
|
|
dccbab |
+ 0);
|
|
|
dccbab |
+
|
|
|
dccbab |
+ evp_mac = EVP_MAC_fetch(NULL, "HMAC", NULL);
|
|
|
dccbab |
+ if (evp_mac == NULL) {
|
|
|
dccbab |
+ pam_syslog(pamh, LOG_ERR, "Unable to create hmac implementation");
|
|
|
dccbab |
+ goto done;
|
|
|
dccbab |
+ }
|
|
|
dccbab |
+
|
|
|
dccbab |
+ ctx = EVP_MAC_CTX_new(evp_mac);
|
|
|
dccbab |
+ if (ctx == NULL) {
|
|
|
dccbab |
+ pam_syslog(pamh, LOG_ERR, "Unable to create hmac context");
|
|
|
dccbab |
+ goto done;
|
|
|
dccbab |
+ }
|
|
|
dccbab |
+
|
|
|
dccbab |
+ ret = EVP_MAC_init(ctx, key, key_length, subalg_param);
|
|
|
dccbab |
+ if (ret == 0) {
|
|
|
dccbab |
+ pam_syslog(pamh, LOG_ERR, "Unable to initialize hmac context");
|
|
|
dccbab |
+ goto done;
|
|
|
dccbab |
+ }
|
|
|
dccbab |
+
|
|
|
dccbab |
+ *hmac_length = EVP_MAC_CTX_get_mac_size(ctx);
|
|
|
dccbab |
+ ret = PAM_SUCCESS;
|
|
|
dccbab |
+
|
|
|
dccbab |
+done:
|
|
|
dccbab |
+ if (ctx != NULL) {
|
|
|
dccbab |
+ EVP_MAC_CTX_free(ctx);
|
|
|
dccbab |
+ }
|
|
|
dccbab |
+ if (evp_mac != NULL) {
|
|
|
dccbab |
+ EVP_MAC_free(evp_mac);
|
|
|
dccbab |
+ }
|
|
|
dccbab |
+ free(algo);
|
|
|
dccbab |
+
|
|
|
dccbab |
+ return ret;
|
|
|
dccbab |
+}
|
|
|
dccbab |
+
|
|
|
dccbab |
+int
|
|
|
dccbab |
+hmac_generate(pam_handle_t *pamh, int debug, void **mac, size_t *mac_length,
|
|
|
dccbab |
+ const char *key_file, uid_t owner, gid_t group,
|
|
|
dccbab |
+ const void *text, size_t text_length)
|
|
|
dccbab |
+{
|
|
|
dccbab |
+ char *key = NULL;
|
|
|
dccbab |
+ size_t key_length = MAX_KEY_LENGTH;
|
|
|
dccbab |
+
|
|
|
dccbab |
+ if (key_management(pamh, key_file, &key, key_length, owner, group)) {
|
|
|
dccbab |
+ return PAM_AUTH_ERR;
|
|
|
dccbab |
+ }
|
|
|
dccbab |
+
|
|
|
dccbab |
+ if (hmac_management(pamh, debug, mac, mac_length, key, key_length,
|
|
|
dccbab |
+ text, text_length)) {
|
|
|
dccbab |
+ return PAM_AUTH_ERR;
|
|
|
dccbab |
+ }
|
|
|
dccbab |
+
|
|
|
dccbab |
+ return PAM_SUCCESS;
|
|
|
dccbab |
+}
|
|
|
dccbab |
+
|
|
|
dccbab |
+#endif /* WITH_OPENSSL */
|
|
|
dccbab |
diff --git a/modules/pam_timestamp/hmac_openssl_wrapper.h b/modules/pam_timestamp/hmac_openssl_wrapper.h
|
|
|
dccbab |
new file mode 100644
|
|
|
dccbab |
index 00000000..cc27c811
|
|
|
dccbab |
--- /dev/null
|
|
|
dccbab |
+++ b/modules/pam_timestamp/hmac_openssl_wrapper.h
|
|
|
dccbab |
@@ -0,0 +1,57 @@
|
|
|
dccbab |
+/* Wrapper for hmac openssl implementation.
|
|
|
dccbab |
+ *
|
|
|
dccbab |
+ * Copyright (c) 2021 Red Hat, Inc.
|
|
|
dccbab |
+ * Written by Iker Pedrosa <ipedrosa@redhat.com>
|
|
|
dccbab |
+ *
|
|
|
dccbab |
+ * Redistribution and use in source and binary forms, with or without
|
|
|
dccbab |
+ * modification, are permitted provided that the following conditions
|
|
|
dccbab |
+ * are met:
|
|
|
dccbab |
+ * 1. Redistributions of source code must retain the above copyright
|
|
|
dccbab |
+ * notice, and the entire permission notice in its entirety,
|
|
|
dccbab |
+ * including the disclaimer of warranties.
|
|
|
dccbab |
+ * 2. Redistributions in binary form must reproduce the above copyright
|
|
|
dccbab |
+ * notice, this list of conditions and the following disclaimer in the
|
|
|
dccbab |
+ * documentation and/or other materials provided with the distribution.
|
|
|
dccbab |
+ * 3. The name of the author may not be used to endorse or promote
|
|
|
dccbab |
+ * products derived from this software without specific prior
|
|
|
dccbab |
+ * written permission.
|
|
|
dccbab |
+ *
|
|
|
dccbab |
+ * ALTERNATIVELY, this product may be distributed under the terms of
|
|
|
dccbab |
+ * the GNU Public License, in which case the provisions of the GPL are
|
|
|
dccbab |
+ * required INSTEAD OF the above restrictions. (This clause is
|
|
|
dccbab |
+ * necessary due to a potential bad interaction between the GPL and
|
|
|
dccbab |
+ * the restrictions contained in a BSD-style copyright.)
|
|
|
dccbab |
+ *
|
|
|
dccbab |
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
|
|
dccbab |
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
dccbab |
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
dccbab |
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
|
|
dccbab |
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
dccbab |
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
dccbab |
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
dccbab |
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
dccbab |
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
dccbab |
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
|
|
dccbab |
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
dccbab |
+ *
|
|
|
dccbab |
+ */
|
|
|
dccbab |
+#ifndef PAM_TIMESTAMP_HMAC_OPENSSL_WRAPPER_H
|
|
|
dccbab |
+#define PAM_TIMESTAMP_HMAC_OPENSSL_WRAPPER_H
|
|
|
dccbab |
+
|
|
|
dccbab |
+#include "config.h"
|
|
|
dccbab |
+
|
|
|
dccbab |
+#ifdef WITH_OPENSSL
|
|
|
dccbab |
+
|
|
|
dccbab |
+#include <openssl/hmac.h>
|
|
|
dccbab |
+#include <security/pam_modules.h>
|
|
|
dccbab |
+
|
|
|
dccbab |
+int
|
|
|
dccbab |
+hmac_size(pam_handle_t *pamh, int debug, size_t *hmac_length);
|
|
|
dccbab |
+
|
|
|
dccbab |
+int
|
|
|
dccbab |
+hmac_generate(pam_handle_t *pamh, int debug, void **mac, size_t *mac_length,
|
|
|
dccbab |
+ const char *key_file, uid_t owner, gid_t group,
|
|
|
dccbab |
+ const void *text, size_t text_length);
|
|
|
dccbab |
+
|
|
|
dccbab |
+#endif /* WITH_OPENSSL */
|
|
|
dccbab |
+#endif /* PAM_TIMESTAMP_HMAC_OPENSSL_WRAPPER_H */
|
|
|
dccbab |
diff --git a/modules/pam_timestamp/pam_timestamp.8.xml b/modules/pam_timestamp/pam_timestamp.8.xml
|
|
|
dccbab |
index e19a0bcf..83e5aea8 100644
|
|
|
dccbab |
--- a/modules/pam_timestamp/pam_timestamp.8.xml
|
|
|
dccbab |
+++ b/modules/pam_timestamp/pam_timestamp.8.xml
|
|
|
dccbab |
@@ -50,6 +50,11 @@ for the user. When an application attempts to authenticate the user, a
|
|
|
dccbab |
<emphasis>pam_timestamp</emphasis> will treat a sufficiently recent timestamp
|
|
|
dccbab |
file as grounds for succeeding.
|
|
|
dccbab |
</para>
|
|
|
dccbab |
+ <para condition="openssl_hmac">
|
|
|
dccbab |
+ The default encryption hash is taken from the
|
|
|
dccbab |
+ <emphasis remap='B'>HMAC_CRYPTO_ALGO</emphasis> variable from
|
|
|
dccbab |
+ <emphasis>/etc/login.defs</emphasis>.
|
|
|
dccbab |
+ </para>
|
|
|
dccbab |
</refsect1>
|
|
|
dccbab |
|
|
|
dccbab |
<refsect1 id="pam_timestamp-options">
|
|
|
dccbab |
diff --git a/modules/pam_timestamp/pam_timestamp.c b/modules/pam_timestamp/pam_timestamp.c
|
|
|
dccbab |
index 30be883c..01dd1385 100644
|
|
|
dccbab |
--- a/modules/pam_timestamp/pam_timestamp.c
|
|
|
dccbab |
+++ b/modules/pam_timestamp/pam_timestamp.c
|
|
|
dccbab |
@@ -56,7 +56,11 @@
|
|
|
dccbab |
#include <utmp.h>
|
|
|
dccbab |
#include <syslog.h>
|
|
|
dccbab |
#include <paths.h>
|
|
|
dccbab |
+#ifdef WITH_OPENSSL
|
|
|
dccbab |
+#include "hmac_openssl_wrapper.h"
|
|
|
dccbab |
+#else
|
|
|
dccbab |
#include "hmacsha1.h"
|
|
|
dccbab |
+#endif /* WITH_OPENSSL */
|
|
|
dccbab |
|
|
|
dccbab |
#include <security/pam_modules.h>
|
|
|
dccbab |
#include <security/_pam_macros.h>
|
|
|
dccbab |
@@ -79,6 +83,9 @@
|
|
|
dccbab |
#define BUFLEN PATH_MAX
|
|
|
dccbab |
#endif
|
|
|
dccbab |
|
|
|
dccbab |
+#define ROOT_USER 0
|
|
|
dccbab |
+#define ROOT_GROUP 0
|
|
|
dccbab |
+
|
|
|
dccbab |
/* Return PAM_SUCCESS if the given directory looks "safe". */
|
|
|
dccbab |
static int
|
|
|
dccbab |
check_dir_perms(pam_handle_t *pamh, const char *tdir)
|
|
|
dccbab |
@@ -449,6 +456,13 @@ pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc, const char **argv)
|
|
|
dccbab |
return PAM_AUTH_ERR;
|
|
|
dccbab |
}
|
|
|
dccbab |
|
|
|
dccbab |
+#ifdef WITH_OPENSSL
|
|
|
dccbab |
+ if (hmac_size(pamh, debug, &maclen)) {
|
|
|
dccbab |
+ return PAM_AUTH_ERR;
|
|
|
dccbab |
+ }
|
|
|
dccbab |
+#else
|
|
|
dccbab |
+ maclen = hmac_sha1_size();
|
|
|
dccbab |
+#endif /* WITH_OPENSSL */
|
|
|
dccbab |
/* Check that the file is the expected size. */
|
|
|
dccbab |
if (st.st_size == 0) {
|
|
|
dccbab |
/* Invalid, but may have been created by sudo. */
|
|
|
dccbab |
@@ -456,7 +470,7 @@ pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc, const char **argv)
|
|
|
dccbab |
return PAM_AUTH_ERR;
|
|
|
dccbab |
}
|
|
|
dccbab |
if (st.st_size !=
|
|
|
dccbab |
- (off_t)(strlen(path) + 1 + sizeof(then) + hmac_sha1_size())) {
|
|
|
dccbab |
+ (off_t)(strlen(path) + 1 + sizeof(then) + maclen)) {
|
|
|
dccbab |
pam_syslog(pamh, LOG_NOTICE, "timestamp file `%s' "
|
|
|
dccbab |
"appears to be corrupted", path);
|
|
|
dccbab |
close(fd);
|
|
|
dccbab |
@@ -487,8 +501,17 @@ pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc, const char **argv)
|
|
|
dccbab |
message_end = message + strlen(path) + 1 + sizeof(then);
|
|
|
dccbab |
|
|
|
dccbab |
/* Regenerate the MAC. */
|
|
|
dccbab |
- hmac_sha1_generate_file(pamh, &mac, &maclen, TIMESTAMPKEY, 0, 0,
|
|
|
dccbab |
- message, message_end - message);
|
|
|
dccbab |
+#ifdef WITH_OPENSSL
|
|
|
dccbab |
+ if (hmac_generate(pamh, debug, &mac, &maclen, TIMESTAMPKEY,
|
|
|
dccbab |
+ ROOT_USER, ROOT_GROUP, message, message_end - message)) {
|
|
|
dccbab |
+ close(fd);
|
|
|
dccbab |
+ free(message);
|
|
|
dccbab |
+ return PAM_AUTH_ERR;
|
|
|
dccbab |
+ }
|
|
|
dccbab |
+#else
|
|
|
dccbab |
+ hmac_sha1_generate_file(pamh, &mac, &maclen, TIMESTAMPKEY,
|
|
|
dccbab |
+ ROOT_USER, ROOT_GROUP, message, message_end - message);
|
|
|
dccbab |
+#endif /* WITH_OPENSSL */
|
|
|
dccbab |
if ((mac == NULL) ||
|
|
|
dccbab |
(memcmp(path, message, strlen(path)) != 0) ||
|
|
|
dccbab |
(memcmp(mac, message_end, maclen) != 0)) {
|
|
|
dccbab |
@@ -605,8 +628,16 @@ pam_sm_open_session(pam_handle_t *pamh, int flags UNUSED, int argc, const char *
|
|
|
dccbab |
}
|
|
|
dccbab |
}
|
|
|
dccbab |
|
|
|
dccbab |
+#ifdef WITH_OPENSSL
|
|
|
dccbab |
+ if (hmac_size(pamh, debug, &maclen)) {
|
|
|
dccbab |
+ return PAM_SESSION_ERR;
|
|
|
dccbab |
+ }
|
|
|
dccbab |
+#else
|
|
|
dccbab |
+ maclen = hmac_sha1_size();
|
|
|
dccbab |
+#endif /* WITH_OPENSSL */
|
|
|
dccbab |
+
|
|
|
dccbab |
/* Generate the message. */
|
|
|
dccbab |
- text = malloc(strlen(path) + 1 + sizeof(now) + hmac_sha1_size());
|
|
|
dccbab |
+ text = malloc(strlen(path) + 1 + sizeof(now) + maclen);
|
|
|
dccbab |
if (text == NULL) {
|
|
|
dccbab |
pam_syslog(pamh, LOG_CRIT, "unable to allocate memory: %m");
|
|
|
dccbab |
return PAM_SESSION_ERR;
|
|
|
dccbab |
@@ -621,15 +652,21 @@ pam_sm_open_session(pam_handle_t *pamh, int flags UNUSED, int argc, const char *
|
|
|
dccbab |
p += sizeof(now);
|
|
|
dccbab |
|
|
|
dccbab |
/* Generate the MAC and append it to the plaintext. */
|
|
|
dccbab |
- hmac_sha1_generate_file(pamh, &mac, &maclen,
|
|
|
dccbab |
- TIMESTAMPKEY,
|
|
|
dccbab |
- 0, 0,
|
|
|
dccbab |
- text, p - text);
|
|
|
dccbab |
+#ifdef WITH_OPENSSL
|
|
|
dccbab |
+ if (hmac_generate(pamh, debug, &mac, &maclen, TIMESTAMPKEY,
|
|
|
dccbab |
+ ROOT_USER, ROOT_GROUP, text, p - text)) {
|
|
|
dccbab |
+ free(text);
|
|
|
dccbab |
+ return PAM_SESSION_ERR;
|
|
|
dccbab |
+ }
|
|
|
dccbab |
+#else
|
|
|
dccbab |
+ hmac_sha1_generate_file(pamh, &mac, &maclen, TIMESTAMPKEY,
|
|
|
dccbab |
+ ROOT_USER, ROOT_GROUP, text, p - text);
|
|
|
dccbab |
if (mac == NULL) {
|
|
|
dccbab |
pam_syslog(pamh, LOG_ERR, "failure generating MAC: %m");
|
|
|
dccbab |
free(text);
|
|
|
dccbab |
return PAM_SESSION_ERR;
|
|
|
dccbab |
}
|
|
|
dccbab |
+#endif /* WITH_OPENSSL */
|
|
|
dccbab |
memmove(p, mac, maclen);
|
|
|
dccbab |
p += maclen;
|
|
|
dccbab |
free(mac);
|
|
|
dccbab |
--
|
|
|
dccbab |
2.31.1
|
|
|
dccbab |
|