File gsi-openssh-SLE_15.spec of Package gsi-openssh

#
# spec file for package gsi-openssh
#
# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany.
# Copyright (c) 2019, 2020 Frank Scheiner, HLRS, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#


#Compat macro for new _fillupdir macro introduced in Nov 2017
%if ! %{defined _fillupdir}
  %define _fillupdir /var/adm/fillup-templates
%endif

%if 0%{suse_version} >= 1100
%define has_fw_dir 1
%else
%define has_fw_dir 0
%endif

%if 0%{suse_version} >= 1110
%define has_libselinux 1
%else
%define has_libselinux 0
%endif

%if 0%{?suse_version} >= 1130
%define needs_all_dirs 1
%else
%define needs_all_dirs 0
%endif

%if 0%{?suse_version} >= 1140
%define needs_libedit 1
%else
%define needs_libedit 0
%endif

%if 0%{?suse_version} > 1140
%define has_krb_mini 1
%else
%define has_krb_mini 0
%endif

%if 0%{?suse_version} > 1220
%define uses_systemd 1
%else
%define uses_systemd 0
%endif

%define sandbox_seccomp 0
%if 0%{?suse_version} > 1220
%define sandbox_seccomp 1
%endif

%if 0%{?suse_version} >= 1500
%define use_tirpc 1
%endif

%define DIST     SLE_15
%define _fwdir   %{_sysconfdir}/sysconfig/SuSEfirewall2.d
%define _fwdefdir   %{_fwdir}/services
%define _appdefdir  %( grep "configdirspec=" $( which xmkmf ) | sed -r 's,^[^=]+=.*-I(.*)/config.*$,\\1/app-defaults,' )
%{!?_initddir:%global _initddir %{_initrddir}}

Name:           gsi-openssh
BuildRequires:  audit-devel
BuildRequires:  autoconf
BuildRequires:  groff
#%if %{has_krb_mini}
#BuildRequires:  krb5-mini-devel
#%else
#BuildRequires:  krb5-devel
#%endif
%if %{needs_libedit}
BuildRequires:  libedit-devel
%endif
%if %{has_libselinux}
BuildRequires:  libselinux-devel
%endif
BuildRequires:  openldap2-devel
BuildRequires:  openssl-devel
BuildRequires:  pam-devel
%if 0%{?use_tirpc}
BuildRequires:  libtirpc-devel
%endif
%if %{uses_systemd}
BuildRequires:  pkgconfig(libsystemd)
BuildRequires:  pkgconfig(systemd)
%{?systemd_requires}
%endif
BuildRequires:  globus-gss-assist-devel >= 8
BuildRequires:  globus-gssapi-gsi-devel >= 12.12
BuildRequires:  globus-common-devel >= 14
PreReq:         pwdutils %{fillup_prereq} coreutils
%if ! %{uses_systemd}
PreReq:         %{insserv_prereq}
%endif
Version:        7.6p1
Release:        1
#Summary:        GSI and HPN enabled Secure Shell Client and Server (Remote Login Program)
Summary:        GSI enabled Secure Shell Client and Server (Remote Login Program)
License:        BSD-2-Clause AND MIT
Group:          Productivity/Networking/SSH
Url:            http://www.openssh.com/
Source:         https://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-%{version}.tar.gz
Source42:       https://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-%{version}.tar.gz.asc
Source1:        gsisshd-%{DIST}.init
Source2:        gsisshd-%{DIST}.pamd
Source3:        README-%{DIST}.SUSE
#Source4:        README.kerberos
Source5:        gsissh-%{DIST}.reg
Source6:        ssh-askpass-%{DIST}
Source7:        gsisshd-%{DIST}.fw
Source8:        sysconfig-%{DIST}.gsissh
Source9:        gsisshd-gen-keys-start-%{DIST}
Source10:       gsisshd-%{DIST}.service
Source11:       README-%{DIST}.FIPS
Source12:       cavs_driver-ssh-%{DIST}.pl
Patch0:         openssh-7.6p1-allow_root_password_login-%{DIST}.patch
Patch1:         openssh-7.6p1-X11_trusted_forwarding-%{DIST}.patch
Patch2:         openssh-7.6p1-lastlog-%{DIST}.patch
Patch3:         openssh-7.6p1-enable_PAM_by_default-%{DIST}.patch
Patch4:         openssh-7.6p1-eal3-%{DIST}.patch
Patch5:         openssh-7.6p1-blocksigalrm-%{DIST}.patch
Patch6:         openssh-7.6p1-send_locale-%{DIST}.patch
Patch7:         openssh-7.6p1-hostname_changes_when_forwarding_X-%{DIST}.patch
Patch8:         openssh-7.6p1-remove_xauth_cookies_on_exit-%{DIST}.patch
Patch9:         openssh-7.6p1-pts_names_formatting-%{DIST}.patch
Patch10:        openssh-7.6p1-pam_check_locks-%{DIST}.patch
Patch12:        openssh-7.6p1-seccomp_getuid-%{DIST}.patch
Patch13:        openssh-7.6p1-seccomp_geteuid-%{DIST}.patch
Patch14:        openssh-7.6p1-seccomp_stat-%{DIST}.patch
Patch15:        openssh-7.6p1-seccomp_ipc_flock-%{DIST}.patch
Patch16:        openssh-7.6p1-seccomp_ioctl_s390_EP11-%{DIST}.patch
Patch17:        openssh-7.6p1-fips-%{DIST}.patch
Patch18:        openssh-7.6p1-cavstest-ctr-%{DIST}.patch
Patch19:        openssh-7.6p1-cavstest-kdf-%{DIST}.patch
Patch20:        openssh-7.6p1-fips_checks-%{DIST}.patch
Patch21:        openssh-7.6p1-missing_headers-%{DIST}.patch
Patch22:        openssh-7.6p1-seed-prng-%{DIST}.patch
Patch23:        openssh-7.6p1-systemd-notify-%{DIST}.patch
Patch24:        openssh-7.6p1-gssapi_key_exchange-%{DIST}.patch
Patch25:        openssh-7.6p1-audit-%{DIST}.patch
Patch26:        openssh-7.6p1-openssl_1.1.0-%{DIST}.patch
Patch27:        openssh-7.6p1-disable_openssl_abi_check-%{DIST}.patch
Patch28:        openssh-7.6p1-no_fork-no_pid_file-%{DIST}.patch
Patch29:        openssh-7.6p1-host_ident-%{DIST}.patch
Patch30:        openssh-7.6p1-sftp_force_permissions-%{DIST}.patch
Patch31:        openssh-7.6p1-X_forward_with_disabled_ipv6-%{DIST}.patch
Patch32:        openssh-7.6p1-ldap-%{DIST}.patch
Patch33:        openssh-7.6p1-IPv6_X_forwarding-%{DIST}.patch
Patch34:        openssh-7.6p1-sftp_print_diagnostic_messages-%{DIST}.patch
Patch35:        openssh-7.6p1-CVE-2018-15473-%{DIST}.patch
Patch36:        openssh-7.6p1-sftp-client-return-code-%{DIST}.patch
Patch37:        openssh-7.9p1-CVE-2018-20685-%{DIST}.patch
Patch38:        openssh-CVE-2019-6109-sanitize-scp-filenames-%{DIST}.patch
Patch39:        openssh-CVE-2019-6109-force-progressmeter-update-%{DIST}.patch
Patch40:        openssh-CVE-2019-6111-scp-client-wildcard-%{DIST}.patch
Patch41:        openssh-7.9p1-brace-expansion-%{DIST}.patch
Patch42:        0001-upstream-Fix-two-race-conditions-in-sshd-relating-to-%{DIST}.patch
Patch43:        openssh-7.6p1-audit_race_condition-%{DIST}.patch
Patch44:        openssh-7.6p1-gsissh--from-fedora-27-gsi-openssh-package-modified-%{DIST}.patch
#Patch45:        openssh-7.6p1-hpn-14.15-modified-%{DIST}.patch
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
Conflicts:      nonfreessh
Recommends:     audit
Recommends:     xauth
Recommends:     %{name}-helpers = %{version}-%{release}
Conflicts:      %{name}-fips < %{version}-%{release} , %{name}-fips > %{version}-%{release}
%define CHECKSUM_SUFFIX .hmac
%define CHECKSUM_HMAC_KEY "HMAC_KEY:OpenSSH-FIPS@SLE"

%description
SSH (Secure Shell) is a program for logging into and executing commands
on a remote machine. It is intended to replace rsh (rlogin and rsh) and
provides openssl (secure encrypted communication) between two untrusted
hosts over an insecure network.

xorg-x11 (X Window System) connections and arbitrary TCP/IP ports can
also be forwarded over the secure channel.

This version of OpenSSH has been modified to support GSI authentication and High Performance Networking.

%package fips
Summary:        OpenSSH FIPS cryptomodule HMACs
Group:          Productivity/Networking/SSH
Requires:       %{name} = %{version}-%{release}
Conflicts:      %{name} < %{version}-%{release} , %{name} > %{version}-%{release}
Obsoletes:      %{name}-hmac

%description fips
Hashes that together with the main package form the FIPS certifiable
cryptomodule.


%package cavs
Summary:        OpenSSH FIPS cryptomodule CAVS tests
Group:          Productivity/Networking/SSH
Requires:       %{name} = %{version}-%{release}

%description cavs
FIPS140 CAVS tests related parts of the GSI-OpenSSH package


%prep
%setup -q -n openssh-%{version}
cp %{SOURCE3} ./README.SUSE
cp %{SOURCE11} ./README.FIPS
%autopatch -p1

# set libexec dir in the LDAP patch
sed -i.libexec 's,@LIBEXECDIR@,%{_libexecdir}/gsissh,' \
    $( grep -Rl @LIBEXECDIR@ \
        $( grep "^+++" $PATCH_DIR/openssh-7.6p1-ldap.patch | sed -r 's@^.+/([^/\t ]+).*$@\1@' )
    )

%build
autoreconf -fiv
%ifarch s390 s390x %sparc
PIEFLAGS="-fPIE"
%else
PIEFLAGS="-fpie"
%endif
CFLAGS="%{optflags} $PIEFLAGS -fstack-protector"
CXXFLAGS="%{optflags} $PIEFLAGS -fstack-protector"
LDFLAGS="-pie -Wl,--as-needed"
#CPPFLAGS="%{optflags} -DUSE_INTERNAL_B64"
export LDFLAGS CFLAGS CXXFLAGS CPPFLAGS
%configure \
    --prefix=%{_prefix} \
    --mandir=%{_mandir} \
    --infodir=%{_infodir} \
    --sysconfdir=%{_sysconfdir}/gsissh \
    --libexecdir=%{_libexecdir}/gsissh \
    --with-tcp-wrappers \
%if %{has_libselinux}
    --with-selinux \
%endif
%if %{uses_systemd}
    --with-pid-dir=/run \
    --with-systemd \
%endif
    --with-ssl-engine \
    --with-pam \
    --with-gsi \
    --with-privsep-path=/var/lib/empty \
%if %{sandbox_seccomp}
    --with-sandbox=seccomp_filter \
%else
    --with-sandbox=rlimit \
%endif
%ifnarch s390 s390x
    --with-opensc \
%endif
    --disable-strip \
    --with-audit=linux \
    --with-ldap \
    --with-xauth=%{_bindir}/xauth \
%if %{needs_libedit}
    --with-libedit \
%endif
    --with-ssh1 \
    --target=%{_target_cpu}-suse-linux \

### configure end
make %{?_smp_mflags} SSH_PROGRAM=%{_bindir}/gsissh \
     ASKPASS_PROGRAM=%{_libexecdir}/openssh/ssh-askpass

#make %{?_smp_mflags} -C converter

%install
make install DESTDIR=%{buildroot}
#make install DESTDIR=%{buildroot} -C converter

install -d -m 755 %{buildroot}%{_sysconfdir}/pam.d
install -d -m 755 %{buildroot}/var/lib/gsisshd
install -m 644 %{SOURCE2} %{buildroot}%{_sysconfdir}/pam.d/gsisshd
install -d -m 755 %{buildroot}%{_sysconfdir}/slp.reg.d/
install -m 644 %{SOURCE5} %{buildroot}%{_sysconfdir}/slp.reg.d/gsissh.reg
install -d -m 755 %{buildroot}%{_initddir}
%if %{uses_systemd}
install -m 0755 %{SOURCE1} gsisshd.init
install -D -m 0644 %{SOURCE10} %{buildroot}%{_unitdir}/gsisshd.service
ln -s /sbin/service %{buildroot}%{_sbindir}/rcgsisshd
%else
install -D -m 0755 %{SOURCE1} %{buildroot}%{_initddir}/gsisshd
install -m 0644 %{SOURCE10} gsisshd.service
ln -s ../..%{_initddir}/gsisshd %{buildroot}%{_sbindir}/rcgsisshd
%endif
install -d -m 755 %{buildroot}%{_fillupdir}
install -m 644 %{SOURCE8} %{buildroot}%{_fillupdir}/sysconfig.gsissh
sed -i -e s@/usr/libexec@%{_libexecdir}@g %{buildroot}%{_sysconfdir}/gsissh/sshd_config

%if %{has_fw_dir}
#install firewall definitions format is described here:
#%{_datadir}/SuSEfirewall2/services/TEMPLATE
mkdir -p %{buildroot}%{_fwdefdir}
install -m 644 %{SOURCE7} %{buildroot}%{_fwdefdir}/gsisshd
%endif

# askpass wrapper
sed -e "s,@LIBEXECDIR@,%{_libexecdir},g" < %{SOURCE6} > %{buildroot}%{_libexecdir}/gsissh/ssh-askpass
sed -e "s,@LIBEXECDIR@,%{_libexecdir},g" < %{SOURCE12} > %{buildroot}%{_libexecdir}/gsissh/cavs_driver-ssh.pl
rm -f %{buildroot}%{_datadir}/Ssh.bin
# sshd keys generator wrapper
install -D -m 0755 %{SOURCE9} %{buildroot}%{_sbindir}/gsisshd-gen-keys-start

# the hmac hashes - taken from openssl
#
# re-define the __os_install_post macro: the macro strips
# the binaries and thereby invalidates any hashes created earlier.
#
# this shows up earlier because otherwise the %expand of
# the macro is too late.
%{expand:%%global __os_install_post {%__os_install_post
for b in \
        %{_bindir}/gsissh \
        %{_sbindir}/gsisshd \
        %{_libexecdir}/gsissh/sftp-server \
        ; do
    openssl dgst -sha256 -binary -hmac %{CHECKSUM_HMAC_KEY} < %{buildroot}$b > %{buildroot}$b%{CHECKSUM_SUFFIX}
done

}}

rm $RPM_BUILD_ROOT%{_bindir}/ssh-add
rm $RPM_BUILD_ROOT%{_bindir}/ssh-agent
rm $RPM_BUILD_ROOT%{_bindir}/ssh-keyscan
rm $RPM_BUILD_ROOT%{_sysconfdir}/gsissh/ldap.conf
rm $RPM_BUILD_ROOT%{_libexecdir}/gsissh/ssh-ldap-helper
rm $RPM_BUILD_ROOT%{_libexecdir}/gsissh/ssh-ldap-wrapper
rm $RPM_BUILD_ROOT%{_libexecdir}/gsissh/ssh-pkcs11-helper
rm $RPM_BUILD_ROOT%{_mandir}/man1/ssh-add.1*
rm $RPM_BUILD_ROOT%{_mandir}/man1/ssh-agent.1*
rm $RPM_BUILD_ROOT%{_mandir}/man1/ssh-keyscan.1*
rm $RPM_BUILD_ROOT%{_mandir}/man5/ssh-ldap.conf.5*
rm $RPM_BUILD_ROOT%{_mandir}/man8/ssh-ldap-helper.8*
rm $RPM_BUILD_ROOT%{_mandir}/man8/ssh-pkcs11-helper.8*

for f in $RPM_BUILD_ROOT%{_bindir}/* \
	 $RPM_BUILD_ROOT%{_sbindir}/* \
	 $RPM_BUILD_ROOT%{_mandir}/man*/* ; do
    if [ "`basename $f`" = "gsisshd-gen-keys-start" ]; then
        continue
    fi
    if [ "`basename $f`" = "rcgsisshd" ]; then
        continue
    fi
        mv $f `dirname $f`/gsi`basename $f`
done

perl -pi -e "s|$RPM_BUILD_ROOT||g" $RPM_BUILD_ROOT%{_mandir}/man*/*

%pre
getent group gsisshd >/dev/null || %{_sbindir}/groupadd -r gsisshd
getent passwd gsisshd >/dev/null || %{_sbindir}/useradd -r -g gsisshd -d /var/lib/gsisshd -s /bin/false -c "GSISSH daemon" gsisshd
%if %{uses_systemd}
%service_add_pre gsisshd.service
%endif

%post
%if %{uses_systemd}
%{fillup_only -n gsissh gsisshd}
%service_add_post gsisshd.service
%else
%{fillup_and_insserv -n gsissh gsisshd}
%endif
%set_permissions /etc/gsissh/sshd_config

%preun
%if %{uses_systemd}
%service_del_preun gsisshd.service
%else
%stop_on_removal gsisshd
%endif

%postun
# The openssh-fips trigger script for openssh will normally restart sshd once
# it gets installed, so only restart the service here if openssh-fips is not
# present
rpm -q gsi-openssh-fips >& /dev/null && DISABLE_RESTART_ON_UPDATE=yes
%if %{uses_systemd}
%service_del_postun gsisshd.service
%else
%restart_on_update gsisshd
%{insserv_cleanup}
%endif

%triggerin -n gsi-openssh-fips -- %{name} = %{version}-%{release}
%restart_on_update gsisshd

%verifyscript
%verify_permissions -e /etc/gsissh/sshd_config

%files
%defattr(-,root,root)
%exclude %{_bindir}/gsissh%{CHECKSUM_SUFFIX}
%exclude %{_sbindir}/gsisshd%{CHECKSUM_SUFFIX}
%exclude %{_libexecdir}/gsissh/sftp-server%{CHECKSUM_SUFFIX}
%exclude %{_libexecdir}/gsissh/cavs*
%dir %attr(755,root,root) /var/lib/gsisshd
%license LICENCE
#%doc README.SUSE HPN-README README.FIPS ChangeLog OVERVIEW README TODO CREDITS
%doc README.SUSE README.FIPS ChangeLog OVERVIEW README TODO CREDITS
%attr(0755,root,root) %dir %{_sysconfdir}/gsissh
%attr(0600,root,root) %config(noreplace) %{_sysconfdir}/gsissh/moduli
%attr(0644,root,root) %config(noreplace) %{_sysconfdir}/gsissh/ssh_config
%attr(0600,root,root) %config(noreplace) %{_sysconfdir}/gsissh/sshd_config
%attr(0644,root,root) %config(noreplace) %{_sysconfdir}/pam.d/gsisshd
%if %{uses_systemd}
%doc gsisshd.init
%attr(0644,root,root) %config %{_unitdir}/gsisshd.service
%else
%attr(0755,root,root) %config %{_initddir}/gsisshd
%doc gsisshd.service
%endif
%attr(0755,root,root) %{_bindir}/*
%attr(0755,root,root) %{_sbindir}/gsisshd
%attr(0755,root,root) %{_sbindir}/gsisshd-gen-keys-start
%{_sbindir}/rcgsisshd
%attr(0755,root,root) %dir %{_libexecdir}/gsissh
%attr(0755,root,root) %{_libexecdir}/gsissh/*
%attr(0444,root,root) %doc %{_mandir}/man1/*
%attr(0444,root,root) %doc %{_mandir}/man5/*
%attr(0444,root,root) %doc %{_mandir}/man8/*
%dir %{_sysconfdir}/slp.reg.d
%config %{_sysconfdir}/slp.reg.d/gsissh.reg
%{_fillupdir}/sysconfig.gsissh
%if %{has_fw_dir}
%if %{needs_all_dirs}
%dir %{_fwdir}
%dir %{_fwdefdir}
%endif
%config %{_fwdefdir}/gsisshd
%endif

%files fips
%defattr(-,root,root)
%attr(0444,root,root) %{_bindir}/gsissh%{CHECKSUM_SUFFIX}
%attr(0444,root,root) %{_sbindir}/gsisshd%{CHECKSUM_SUFFIX}
%attr(0444,root,root) %{_libexecdir}/gsissh/sftp-server%{CHECKSUM_SUFFIX}

%files cavs
%defattr(-,root,root)
%attr(0755,root,root) %{_libexecdir}/gsissh/cavs*

%changelog
openSUSE Build Service is sponsored by