Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 1102083

Summary: generate-server-cert.sh leaves security relevant tmp files behind
Product: Red Hat Enterprise Linux 6 Reporter: Ralph Angenendt <ralph>
Component: openldapAssignee: Jan Synacek <jsynacek>
Status: CLOSED ERRATA QA Contact: David Spurek <dspurek>
Severity: medium Docs Contact:
Priority: medium    
Version: 6.5CC: dspurek, ebenes, jsynacek, ksrot
Target Milestone: rcKeywords: EasyFix, Patch
Target Release: ---   
Hardware: Unspecified   
OS: Linux   
Whiteboard:
Fixed In Version: openldap-2.4.39-7.el6 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 1103101 (view as bug list) Environment:
Last Closed: 2014-10-14 04:58:28 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Ralph Angenendt 2014-05-28 13:04:06 UTC
This has come up in the CentOS bug tracker: http://bugs.centos.org/view.php?id=7139

At least the following package is affected -  openldap-servers-2.4.23-34.el6_5.1.x86_64

After a short discussion with the reporter I decided to open this bug here. 

Short description (taken from the bug report):

When running /usr/libexec/openldap-generate-server-cert.sh, a tmp file with a random name is being generated, and should be deleted after use. A wrong variable is used in deletion, leaving security relevant material lying around in an insecure fashion.

In the trace below you can see the CERT_RANDOM file being generated, but it is attempted to delete $RANDOM_DATA after use.

This is wrong. It should have been "rm -rf $CERT_RANDOM".

After completion of the script, the file is left behind in /tmp, containing random bytes used to generate the cert. This is a security issue, even if the permissions of the file are restrictive.

How to reproduce:

[root@cloud01 ~]# cd /etc/openldap/certs
[root@cloud01 certs]# \rm -rf *
[root@cloud01 certs]# echo keks > password
[root@cloud01 certs]# certutil -d $(pwd) -N -f password
[root@cloud01 certs]# bash -xv /usr/libexec/openldap/generate-server-cert.sh
...
CERT_RANDOM=$(mktemp)
mktemp)
mktemp
++ mktemp
+ CERT_RANDOM=/tmp/tmp.toBUDh50mG
dd if=$RANDOM_SOURCE bs=$CERT_RANDOM_BYTES count=1 of=$CERT_RANDOM &>/dev/null
+ dd if=/dev/urandom bs=256 count=1 of=/tmp/tmp.toBUDh50mG

certutil -d "$CERTDB_DIR" -f "$PASSWORD_FILE" -z "$CERT_RANDOM" \
        -S -x -n "$CERT_NAME" \
        -s "CN=$HOSTNAME_FQDN" \
        -t TC,, \
        -k $CERT_KEY_TYPE -g $CERT_KEY_SIZE \
        -v $CERT_VALID_MONTHS \
        -8 "$ALT_NAMES" \
        &>/dev/null
+ certutil -d /etc/openldap/certs -f /etc/openldap/certs/password -z /tmp/tmp.toBUDh50mG -S -x -n 'OpenLDAP Server' -s CN=cloud01.bki1.syseleven.de -t TC,, -k rsa -g 1024 -v 12 -8 cloud01.bki1.syseleven.de,localhost,localhost.localdomain

rm -f $RANDOM_DATA
+ rm -f
...

[root@cloud01 certs]# ls -l /tmp/tmp.toBUDh50mG
-rw------- 1 root root 256 May 27 15:24 /tmp/tmp.toBUDh50mG

Comment 1 Jan Synacek 2014-05-30 09:00:52 UTC
Thanks for the report.

Trivial patch:
-rm -f $RANDOM_DATA
+rm -f $CERT_RANDOM

Comment 6 errata-xmlrpc 2014-10-14 04:58:28 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

http://rhn.redhat.com/errata/RHBA-2014-1426.html