View | Details | Raw Unified | Return to bug 26572 | Differences between
and this patch

Collapse All | Expand All

(-)a/branches/ucs-3.0/ucs/base/univention-ssl/conffiles/etc/cron.daily/univention-ssl-validity (-1 / +1 lines)
 Lines 1-7    Link Here 
1
#!/bin/sh
1
#!/bin/sh
2
@%@UCRWARNING=# @%@
2
@%@UCRWARNING=# @%@
3
3
4
# Copyright 2004-2011 Univention GmbH
4
# Copyright 2004-2012 Univention GmbH
5
#
5
#
6
# http://www.univention.de/
6
# http://www.univention.de/
7
#
7
#
(-)a/branches/ucs-3.0/ucs/base/univention-ssl/debian/copyright (-3 / +1 lines)
 Lines 1-4    Link Here 
1
Copyright 2002-2011 Univention GmbH
1
Copyright 2002-2012 Univention GmbH
2
2
3
http://www.univention.de/
3
http://www.univention.de/
4
4
 Lines 25-29   You should have received a copy of the GNU Affero General Public Link Here 
25
License with the Debian GNU/Linux or Univention distribution in file
25
License with the Debian GNU/Linux or Univention distribution in file
26
/usr/share/common-licenses/AGPL-3; if not, see
26
/usr/share/common-licenses/AGPL-3; if not, see
27
<http://www.gnu.org/licenses/>.
27
<http://www.gnu.org/licenses/>.
28
29
(-)a/branches/ucs-3.0/ucs/base/univention-ssl/debian/rules (-2 / +1 lines)
 Lines 3-9    Link Here 
3
# Univention SSL
3
# Univention SSL
4
#  rules file for the debian package
4
#  rules file for the debian package
5
#
5
#
6
# Copyright 2004-2011 Univention GmbH
6
# Copyright 2004-2012 Univention GmbH
7
#
7
#
8
# http://www.univention.de/
8
# http://www.univention.de/
9
#
9
#
 Lines 44-47   override_dh_auto_test: Link Here 
44
44
45
%:
45
%:
46
	dh $@
46
	dh $@
47
(-)a/branches/ucs-3.0/ucs/base/univention-ssl/debian/univention-ssl.postinst (-8 / +8 lines)
 Lines 3-9    Link Here 
3
# Univention SSL
3
# Univention SSL
4
#  postinst script
4
#  postinst script
5
#
5
#
6
# Copyright 2004-2011 Univention GmbH
6
# Copyright 2004-2012 Univention GmbH
7
#
7
#
8
# http://www.univention.de/
8
# http://www.univention.de/
9
#
9
#
 Lines 76-87   if [ "$server_role" = "domaincontroller_master" ] || [ -z "$server_role" ] || [ Link Here 
76
		# Bug #13549
76
		# Bug #13549
77
		rdate time.fu-berlin.de || rdate 130.133.1.10 || true
77
		rdate time.fu-berlin.de || rdate 130.133.1.10 || true
78
78
79
		. /usr/share/univention-ssl/make-certificates.sh;
79
		. /usr/share/univention-ssl/make-certificates.sh
80
		init;
80
		init
81
		univention-certificate new -name $hostname.$domainname
81
		univention-certificate new -name "$hostname.$domainname"
82
		ln -sf /etc/univention/ssl/$hostname.$domainname /etc/univention/ssl/$hostname
82
		ln -sf "/etc/univention/ssl/$hostname.$domainname" "/etc/univention/ssl/$hostname"
83
	else
83
	else
84
		echo "skipped. SSL Certificate found in $CERTPATH ";
84
		echo "skipped. SSL Certificate found in $CERTPATH"
85
	fi
85
	fi
86
fi
86
fi
87
87
 Lines 93-99   if [ "$1" = configure -a -n "$2" ] && dpkg --compare-versions "$2" lt 1.3; then Link Here 
93
fi
93
fi
94
94
95
if [ "$1" = configure -a -n "$2" ] && dpkg --compare-versions "$2" lt 3.0.3-1; then
95
if [ "$1" = configure -a -n "$2" ] && dpkg --compare-versions "$2" lt 3.0.3-1; then
96
	ln -sf /etc/univention/ssl/$hostname.$domainname /etc/univention/ssl/$hostname
96
	ln -sf "/etc/univention/ssl/$hostname.$domainname" "/etc/univention/ssl/$hostname"
97
fi
97
fi
98
98
99
if [ "$1" = "$configure" -a -z "$2" ]; then
99
if [ "$1" = "$configure" -a -z "$2" ]; then
 Lines 105-111   fi Link Here 
105
105
106
if [ "$1" = "configure" ]; then
106
if [ "$1" = "configure" ]; then
107
	if test -f /etc/init.d/univention-directory-listener
107
	if test -f /etc/init.d/univention-directory-listener
108
		then
108
	then
109
		/etc/init.d/univention-directory-listener crestart || true
109
		/etc/init.d/univention-directory-listener crestart || true
110
	fi
110
	fi
111
fi
111
fi
(-)a/branches/ucs-3.0/ucs/base/univention-ssl/debian/univention-ssl.postrm (-2 / +2 lines)
 Lines 3-9    Link Here 
3
# Univention SSL
3
# Univention SSL
4
#  postrm script
4
#  postrm script
5
#
5
#
6
# Copyright 2004-2011 Univention GmbH
6
# Copyright 2004-2012 Univention GmbH
7
#
7
#
8
# http://www.univention.de/
8
# http://www.univention.de/
9
#
9
#
 Lines 32-38    Link Here 
32
# postrm script for univention-ssl
32
# postrm script for univention-ssl
33
33
34
if [ "$1" = "purge" ]; then
34
if [ "$1" = "purge" ]; then
35
	rm -rf /etc/univention/ssl;
35
	rm -rf /etc/univention/ssl
36
fi
36
fi
37
37
38
#DEBHELPER#
38
#DEBHELPER#
(-)a/branches/ucs-3.0/ucs/base/univention-ssl/debian/univention-ssl.univention-config-registry-variables (-3 / +3 lines)
 Lines 43-49   Categories=system-ssl Link Here 
43
[ssl/default/days]
43
[ssl/default/days]
44
Description[de]=Standard Lebensdauer für neue SSL-Zertifikate
44
Description[de]=Standard Lebensdauer für neue SSL-Zertifikate
45
Description[en]=Default lifetime of new SSL certificates
45
Description[en]=Default lifetime of new SSL certificates
46
Type=str
46
Type=int
47
Categories=system-ssl
47
Categories=system-ssl
48
48
49
[ssl/default/hashfunction]
49
[ssl/default/hashfunction]
 Lines 55-67   Categories=system-ssl Link Here 
55
[ssl/validity/check]
55
[ssl/validity/check]
56
Description[de]=Aktiviere/Deaktiviere die regelmäßige Gültigkeitsprüfung für Zertifikate
56
Description[de]=Aktiviere/Deaktiviere die regelmäßige Gültigkeitsprüfung für Zertifikate
57
Description[en]=Enable/Disable regular checks for certificate validity
57
Description[en]=Enable/Disable regular checks for certificate validity
58
Type=str
58
Type=bool
59
Categories=system-ssl
59
Categories=system-ssl
60
60
61
[ssl/validity/days]
61
[ssl/validity/days]
62
Description[de]=Anzahl an Tagen die das Root SSL-Zertifikat gültig ist
62
Description[de]=Anzahl an Tagen die das Root SSL-Zertifikat gültig ist
63
Description[en]=Number of days which the root certificate is valid
63
Description[en]=Number of days which the root certificate is valid
64
Type=str
64
Type=int
65
Categories=system-ssl
65
Categories=system-ssl
66
66
67
[ssl/validity/warning]
67
[ssl/validity/warning]
(-)a/branches/ucs-3.0/ucs/base/univention-ssl/extensions-example.sh (-8 / +5 lines)
 Lines 1-11    Link Here 
1
function createHostExtensionsFile () {
1
createHostExtensionsFile () {
2
2
	local fqdn="$1"
3
        local fqdn="$1"
3
	local hostname=${fqdn/.*/}
4
        local hostname=${fqdn/.*/}
4
	local extFile=$(mktemp)
5
        local extFile=$(mktemp)
6
7
        cat <<EOF >>"$extFile"
8
5
6
	cat <<EOF >>"$extFile"
9
extensions = myx509v3
7
extensions = myx509v3
10
[ myx509v3 ]
8
[ myx509v3 ]
11
9
 Lines 16-22   authorityKeyIdentifier = keyid,issuer:always Link Here 
16
14
17
# alternative name
15
# alternative name
18
subjectAltName = DNS:$fqdn, DNS:$hostname
16
subjectAltName = DNS:$fqdn, DNS:$hostname
19
20
EOF
17
EOF
21
18
22
        echo "$extFile"
19
        echo "$extFile"
(-)a/branches/ucs-3.0/ucs/base/univention-ssl/gencertificate.py (-49 / +46 lines)
 Lines 3-9    Link Here 
3
# Univention SSL
3
# Univention SSL
4
#  listener ssl module
4
#  listener ssl module
5
#
5
#
6
# Copyright 2004-2011 Univention GmbH
6
# Copyright 2004-2012 Univention GmbH
7
#
7
#
8
# http://www.univention.de/
8
# http://www.univention.de/
9
#
9
#
 Lines 30-41    Link Here 
30
# /usr/share/common-licenses/AGPL-3; if not, see
30
# /usr/share/common-licenses/AGPL-3; if not, see
31
# <http://www.gnu.org/licenses/>.
31
# <http://www.gnu.org/licenses/>.
32
32
33
__package__='' 	# workaround for PEP 366
33
__package__=''	# workaround for PEP 366
34
from listener import *
34
from listener import *
35
import grp
35
import grp
36
36
37
import univention.debug
37
import univention.debug
38
import univention.misc
38
import univention.misc
39
import subprocess
39
40
40
name='gencertificate'
41
name='gencertificate'
41
description='Generate new Certificates'
42
description='Generate new Certificates'
 Lines 46-51   attributes=[] Link Here 
46
uidNumber = 0
47
uidNumber = 0
47
gidNumber = 0
48
gidNumber = 0
48
saved_uid = 65545
49
saved_uid = 65545
50
SSLDIR = '/etc/univention/ssl'
49
51
50
def set_privileges_cert(root=0):
52
def set_privileges_cert(root=0):
51
	global saved_uid
53
	global saved_uid
 Lines 56-63   def set_privileges_cert(root=0): Link Here 
56
		os.seteuid(saved_uid)
58
		os.seteuid(saved_uid)
57
59
58
def initialize():
60
def initialize():
59
	univention.debug.debug(univention.debug.LISTENER, univention.debug.INFO, 'CERTIFICATE: Initialize' )
61
	univention.debug.debug(univention.debug.LISTENER, univention.debug.INFO, 'CERTIFICATE: Initialize')
60
	return
61
62
62
def handler(dn, new, old):
63
def handler(dn, new, old):
63
	global uidNumber
64
	global uidNumber
 Lines 71-86   def handler(dn, new, old): Link Here 
71
	try:
72
	try:
72
		try:
73
		try:
73
			uidNumber = int(new.get('uidNumber', ['0'])[0])
74
			uidNumber = int(new.get('uidNumber', ['0'])[0])
74
		except:
75
		except (LookupError, TypeError, ValueError):
75
			uidNumber = 0
76
			uidNumber = 0
76
77
77
		try:
78
		try:
78
			gidNumber = int(grp.getgrnam('DC Backup Hosts')[2])
79
			gidNumber = int(grp.getgrnam('DC Backup Hosts')[2])
79
		except:
80
		except (LookupError, TypeError, ValueError):
80
			univention.debug.debug(univention.debug.LISTENER, univention.debug.WARN, 'CERTIFICATE: Failed to get groupID for "%s"' % name)
81
			univention.debug.debug(univention.debug.LISTENER, univention.debug.WARN, 'CERTIFICATE: Failed to get groupID for "%s"' % name)
81
			gidNumber = 0
82
			gidNumber = 0
82
83
83
		if new and not old:			
84
		if new and not old:
84
			if new.has_key('associatedDomain'):
85
			if new.has_key('associatedDomain'):
85
				domain=new['associatedDomain'][0]
86
				domain=new['associatedDomain'][0]
86
			else:
87
			else:
 Lines 108-137   def handler(dn, new, old): Link Here 
108
				create_certificate(new['cn'][0], int(new['uidNumber'][0]), domainname=new_domain)
109
				create_certificate(new['cn'][0], int(new['uidNumber'][0]), domainname=new_domain)
109
			else:
110
			else:
110
				# Reset permissions
111
				# Reset permissions
111
				ssldir='/etc/univention/ssl'
112
				fqdn = "%s.%s" % (new['cn'][0], new_domain)
112
				certpath=os.path.join(ssldir,"%s.%s" % (new['cn'][0],new_domain))
113
				certpath = os.path.join(SSLDIR, fqdn)
113
				a=os.path.walk(certpath,set_permissions, None)
114
				a = os.path.walk(certpath, set_permissions, None)
114
	finally:
115
	finally:
115
		set_privileges_cert(root=0)
116
		set_privileges_cert(root=0)
116
	return
117
117
118
def set_permissions(tmp1, directory, filename):
118
def set_permissions(tmp1, directory, filename):
119
	global uidNumber
119
	global uidNumber
120
	global gidNumber
120
	global gidNumber
121
	
121
122
	univention.debug.debug(univention.debug.LISTENER, univention.debug.PROCESS, 'CERTIFICATE: Set permissons for = %s with owner/group %s/%s' % (directory, gidNumber, uidNumber))
122
	univention.debug.debug(univention.debug.LISTENER, univention.debug.PROCESS, 'CERTIFICATE: Set permissons for = %s with owner/group %s/%s' % (directory, gidNumber, uidNumber))
123
	os.chown(directory, uidNumber, gidNumber)
123
	os.chown(directory, uidNumber, gidNumber)
124
	os.chmod(directory, 0750)
124
	os.chmod(directory, 0750)
125
125
126
	for f in filename:
126
	for f in filename:
127
		file=os.path.join(directory,f)
127
		file = os.path.join(directory, f)
128
		univention.debug.debug(univention.debug.LISTENER, univention.debug.PROCESS, 'CERTIFICATE: Set permissons for = %s with owner/group %s/%s' % (file, gidNumber, uidNumber))
128
		univention.debug.debug(univention.debug.LISTENER, univention.debug.PROCESS, 'CERTIFICATE: Set permissons for = %s with owner/group %s/%s' % (file, gidNumber, uidNumber))
129
		os.chown(file, uidNumber, gidNumber)
129
		os.chown(file, uidNumber, gidNumber)
130
		os.chmod(file, 0750)
130
		os.chmod(file, 0640)
131
131
132
def remove_dir(tmp1, directory, filename):
132
def remove_dir(tmp1, directory, filename):
133
	"""Remove directory and all files within."""
133
	for f in filename:
134
	for f in filename:
134
		file=os.path.join(directory,f)
135
		file = os.path.join(directory, f)
135
		os.remove(file)
136
		os.remove(file)
136
	os.rmdir(directory)
137
	os.rmdir(directory)
137
138
 Lines 139-193   def create_certificate(name, serverUidNumber, domainname): Link Here 
139
	global uidNumber
140
	global uidNumber
140
	global gidNumber
141
	global gidNumber
141
	uidNumber = serverUidNumber
142
	uidNumber = serverUidNumber
142
	
143
	ssldir='/etc/univention/ssl'
144
	univention.debug.debug(univention.debug.LISTENER, univention.debug.PROCESS, 'CERTIFICATE: Creating certificate %s' % name)
145
143
146
	certpath=os.path.join(ssldir,name+'.'+domainname)
144
	fqdn = '%s.%s' % (name, domainname)
147
	if os.path.exists(certpath):
145
	certpath = os.path.join(SSLDIR, fqdn)
148
		univention.debug.debug(univention.debug.LISTENER, univention.debug.WARN, 'CERTIFICATE: Certificate for host %s.%s already exists' % (name,domainname))
146
	link_path = os.path.join(SSLDIR, name)
149
		if not os.path.islink("%s/%s" % (ssldir,name)):
150
			p = os.popen('ln -sf %s/%s.%s %s/%s' % (ssldir,name,domainname,ssldir,name) )
151
			p.close
152
		a=os.path.walk(certpath,set_permissions, None)
153
		return
154
147
148
	if os.path.exists(certpath):
149
		univention.debug.debug(univention.debug.LISTENER, univention.debug.WARN, 'CERTIFICATE: Certificate for host %s already exists' % (fqdn,))
150
		if os.path.islink(link_path):
151
			return
152
	else:
153
		if len(fqdn) > 64:
154
			univention.debug.debug(univention.debug.LISTENER, univention.debug.ERROR, 'CERTIFICATE: can\'t create certificate, Common Name too long: %s' % (fqdn,))
155
			return
155
156
156
	if len("%s.%s" % (name,domainname)) > 64:
157
		univention.debug.debug(univention.debug.LISTENER, univention.debug.PROCESS, 'CERTIFICATE: Creating certificate %s' % name)
157
		univention.debug.debug(univention.debug.LISTENER, univention.debug.ERROR, 'CERTIFICATE: can\'t create certificate, Common Name too long: %s.%s' % (name,domainname))
158
		return
159
160
	p = os.popen('. /usr/share/univention-ssl/make-certificates.sh; gencert %s.%s %s.%s' % (name,domainname,name,domainname) )
161
	p.close()
162
	p = os.popen('ln -sf %s/%s.%s %s/%s' % (ssldir,name,domainname,ssldir,name) )
163
	p.close()
164
158
165
	
159
		subprocess.call('. /usr/share/univention-ssl/make-certificates.sh; gencert %s %s' % (fqdn, fqdn), shell=True)
166
	a=os.path.walk(certpath,set_permissions, None)
167
160
168
	return
161
	# Create symlink
162
	try:
163
		os.remove(link_path)
164
	except OSError, e:
165
		pass
166
	try:
167
		os.symlink(certpath, link_path)
168
	except OSError, e:
169
		pass
170
	# Fix permissions
171
	a = os.path.walk(certpath, set_permissions, None)
169
172
170
def remove_certificate(name, domainname):
173
def remove_certificate(name, domainname):
174
	fqdn = '%s.%s' % (name, domainname)
175
	univention.debug.debug(univention.debug.LISTENER, univention.debug.INFO, 'CERTIFICATE: Revoke certificate %s' % (fqdn,))
176
	subprocess.call(('/usr/sbin/univention-certificate', 'revoke', '-name', fqdn))
171
177
172
	ssldir='/etc/univention/ssl'
178
	link_path = os.path.join(SSLDIR, name)
173
174
	univention.debug.debug(univention.debug.LISTENER, univention.debug.INFO, 'CERTIFICATE: Revoke certificate %s.%s' % (name,domainname))
175
	p = os.popen('/usr/sbin/univention-certificate revoke -name %s.%s' % (name,domainname) )
176
	p.close()
177
178
	link_path=os.path.join(ssldir,name)
179
	if os.path.exists(link_path):
179
	if os.path.exists(link_path):
180
		os.remove(link_path)
180
		os.remove(link_path)
181
181
182
	certpath=os.path.join(ssldir,"%s.%s" % (name,domainname))
182
	certpath = os.path.join(SSLDIR, fqdn)
183
	if os.path.exists(certpath):
183
	if os.path.exists(certpath):
184
		a=os.path.walk(certpath,remove_dir, None)
184
		a = os.path.walk(certpath, remove_dir, None)
185
186
	return
187
185
188
def clean():
186
def clean():
189
	return
187
	return
190
188
191
def postrun():
189
def postrun():
192
	return
190
	return
193
(-)a/branches/ucs-3.0/ucs/base/univention-ssl/make-certificates.sh (-120 / +114 lines)
 Lines 3-9    Link Here 
3
# Univention SSL
3
# Univention SSL
4
#  gencertificate script
4
#  gencertificate script
5
#
5
#
6
# Copyright 2004-2011 Univention GmbH
6
# Copyright 2004-2012 Univention GmbH
7
#
7
#
8
# http://www.univention.de/
8
# http://www.univention.de/
9
#
9
#
 Lines 35-43    Link Here 
35
# http://www.pca.dfn.de/dfnpca/certify/ssl/handbuch/ossl092/
35
# http://www.pca.dfn.de/dfnpca/certify/ssl/handbuch/ossl092/
36
36
37
if [ -n "$sslbase" ]; then
37
if [ -n "$sslbase" ]; then
38
        SSLBASE="$sslbase"
38
	SSLBASE="$sslbase"
39
else
39
else
40
        SSLBASE=/etc/univention/ssl
40
	SSLBASE=/etc/univention/ssl
41
fi
41
fi
42
42
43
CA=ucsCA
43
CA=ucsCA
 Lines 57-79   else Link Here 
57
fi
57
fi
58
58
59
mk_config () {
59
mk_config () {
60
60
    local outfile=$1
61
    local outfile=$1;
61
    local password=$2
62
    local password=$2;
63
    local days=$3
62
    local days=$3
64
    local name=$4
63
    local name=$4
65
64
66
	if test -e $outfile; then
65
	if test -e "$outfile"; then
67
        rm $outfile;
66
		rm -f "$outfile"
68
	fi
67
	fi
69
    touch $outfile;
68
	touch "$outfile"
70
    chmod 0600 $outfile;
69
	chmod 0600 "$outfile"
71
70
72
	eval "$(univention-config-registry shell ssl/country ssl/state ssl/locality ssl/organization ssl/organizationalunit ssl/email)"
71
	eval "$(univention-config-registry shell ssl/country ssl/state ssl/locality ssl/organization ssl/organizationalunit ssl/email)"
73
72
74
73
    cat >"$outfile" <<EOF
75
    cat <<EOF >>$outfile
76
77
# HOME			= .
74
# HOME			= .
78
# RANDFILE		= \$ENV::HOME/.rnd
75
# RANDFILE		= \$ENV::HOME/.rnd
79
# oid_section		= new_oids
76
# oid_section		= new_oids
 Lines 136-152   default_keyfile = privkey.pem Link Here 
136
distinguished_name	= req_distinguished_name
133
distinguished_name	= req_distinguished_name
137
attributes		= req_attributes
134
attributes		= req_attributes
138
x509_extensions		= v3_ca
135
x509_extensions		= v3_ca
139
140
EOF
136
EOF
141
137
142
if [ "$password" ]; then
138
	if [ -n "$password" ]; then
143
cat <<EOF >>$outfile
139
		cat >>"$outfile" <<EOF
144
input_password = $password
140
input_password = $password
145
output_password = $password
141
output_password = $password
146
EOF
142
EOF
147
fi;
143
	fi
148
144
149
cat <<EOF >>$outfile
145
	cat >>"$outfile" <<EOF
150
146
151
string_mask = nombstr
147
string_mask = nombstr
152
req_extensions = v3_req
148
req_extensions = v3_req
 Lines 219-256   nsComment = This certificate is a Root CA Certificate Link Here 
219
215
220
issuerAltName           = issuer:copy
216
issuerAltName           = issuer:copy
221
authorityKeyIdentifier  = keyid:always,issuer:always
217
authorityKeyIdentifier  = keyid:always,issuer:always
222
223
EOF
218
EOF
224
chmod 0600 $outfile
219
	chmod 0600 "$outfile"
225
226
}
220
}
227
221
228
move_cert () {
222
move_cert () {
229
    local new;
223
    local count=0
230
    local count=0;
224
	local OPWD=$(pwd)
231
    local linkname;
225
    cd "$SSLBASE"
232
    local hash;
226
233
    local OPWD=`pwd`;
227
    local i
234
    cd "$SSLBASE";
228
    for i in "$@"; do
235
229
		if [ -f "$i" ]
236
    for i; do
230
		then
237
	if [ -f "$i" ]; then
231
			local new="${SSLBASE}/${CA}/certs/$(basename "$i")"
238
	    new="${SSLBASE}/${CA}/certs/"`basename $i`;
232
			mv "$i" "$new"
239
	    mv "$i" "$new";
233
			local hash=$(openssl x509 -hash -noout -in "$new")
240
	    hash=`openssl x509 -hash -noout -in "$new"`;
234
			while :
241
	    while :; do
235
			do
242
		linkname="${CA}/certs/""$hash"".""$count";
236
				local linkname="${CA}/certs/${hash}.${count}"
243
		if [ -h "$linkname" ]; then
237
				if [ -h "$linkname" ]
244
		    count=$((count + 1));
238
				then
245
		    continue;
239
					count=$((count + 1))
246
		else
240
					continue
247
		    ln -s "$new" "$linkname";
241
				else
248
		    break;
242
					ln -s "$new" "$linkname"
249
		fi;
243
					break
250
	    done;
244
				fi
251
	fi;
245
			done
252
    done;
246
		fi
253
    cd "$OPWD"
247
	done
248
	cd "$OPWD"
254
}
249
}
255
250
256
init () {
251
init () {
 Lines 266-316   init () { Link Here 
266
		chmod 600 "$SSLBASE/password"
261
		chmod 600 "$SSLBASE/password"
267
		makepasswd > "$SSLBASE/password"
262
		makepasswd > "$SSLBASE/password"
268
	fi
263
	fi
269
	PASSWD=`cat "$SSLBASE/password"`
264
	local PASSWD=`cat "$SSLBASE/password"`
270
265
271
	local OPWD=`pwd`;
266
	local OPWD=$(pwd)
272
267
273
	# create directory infrastructure
268
	# create directory infrastructure
274
	cd "$SSLBASE"
269
	cd "$SSLBASE"
275
	mkdir -m 700 -p ${CA};
270
	mkdir -m 700 -p "${CA}"
276
	mkdir -p ${CA}/{certs,crl,newcerts,private};
271
	mkdir -p "${CA}/"{certs,crl,newcerts,private}
277
	echo "01" > ${CA}/serial;
272
	echo "01" >"${CA}/serial"
278
	touch ${CA}/index.txt;
273
	touch "${CA}/index.txt"
279
274
280
	eval "$(ucr shell ssl/common)"
275
	eval "$(ucr shell ssl/common)"
281
276
282
	# make the root-CA configuration file
277
	# make the root-CA configuration file
283
	mk_config openssl.cnf $PASSWD $DEFAULT_DAYS "$ssl_common"
278
	mk_config openssl.cnf "$PASSWD" "$DEFAULT_DAYS" "$ssl_common"
284
279
285
280
	openssl genrsa -des3 -passout pass:"$PASSWD" -out "${CA}/private/CAkey.pem" 2048
286
	openssl genrsa -des3 -passout pass:"$PASSWD" -out ${CA}/private/CAkey.pem 2048
281
	yes '' | openssl req -config openssl.cnf -new -x509 -days "$DEFAULT_DAYS" -key "${CA}/private/CAkey.pem" -out "${CA}/CAcert.pem"
287
	yes '' | openssl req -config openssl.cnf -new -x509 -days $DEFAULT_DAYS -key ${CA}/private/CAkey.pem -out ${CA}/CAcert.pem
288
282
289
	# copy the public key to a place, from where browsers can access it
283
	# copy the public key to a place, from where browsers can access it
290
	openssl x509 -in ${CA}/CAcert.pem -out /var/www/ucs-root-ca.crt
284
	openssl x509 -in "${CA}/CAcert.pem" -out /var/www/ucs-root-ca.crt
291
285
292
	# mv the certificate to the certs dir and link it to its hash value
286
	# mv the certificate to the certs dir and link it to its hash value
293
	cp ${CA}/CAcert.pem ${CA}/newcerts/00.pem
287
	cp "${CA}/CAcert.pem" "${CA}/newcerts/00.pem"
294
	move_cert ${CA}/newcerts/00.pem
288
	move_cert "${CA}/newcerts/00.pem"
295
289
296
	# generate root ca request
290
	# generate root ca request
297
	openssl x509 -x509toreq -in ${CA}/CAcert.pem -signkey ${CA}/private/CAkey.pem -out ${CA}/CAreq.pem -passin pass:$PASSWD
291
	openssl x509 -x509toreq -in "${CA}/CAcert.pem" -signkey "${CA}/private/CAkey.pem" -out "${CA}/CAreq.pem" -passin pass:"$PASSWD"
298
292
299
	find ${CA} -type f | xargs chmod 600
293
	find "${CA}" -type f -exec chmod 600 {} +
300
	find ${CA} -type d | xargs chmod 700
294
	find "${CA}" -type d -exec chmod 700 {} +
301
295
302
	chmod 755 ${CA}
296
	chmod 755 "${CA}"
303
	chmod 644 ${CA}/CAcert.pem
297
	chmod 644 "${CA}/CAcert.pem"
304
	#generate empty crl at installation time	
298
	#generate empty crl at installation time
305
	openssl ca -config openssl.cnf -gencrl -out ${CA}/crl/crl.pem -passin pass:"$PASSWD"
299
	openssl ca -config openssl.cnf -gencrl -out "${CA}/crl/crl.pem" -passin pass:"$PASSWD"
306
	openssl crl -in ${CA}/crl/crl.pem -out /var/www/${CA}.crl -inform pem -outform der
300
	openssl crl -in "${CA}/crl/crl.pem" -out "/var/www/${CA}.crl" -inform pem -outform der
307
301
308
	cd "$OPWD"
302
	cd "$OPWD"
309
}
303
}
310
304
311
305
312
list_cert_names () {
306
list_cert_names () {
313
   local OPWD=`pwd`
307
	local OPWD=$(pwd)
314
   cd "$SSLBASE"
308
   cd "$SSLBASE"
315
   awk 'BEGIN { FS="\t"; }
309
   awk 'BEGIN { FS="\t"; }
316
    { if ( $1 == "V" )
310
    { if ( $1 == "V" )
 Lines 323-402   list_cert_names () { Link Here 
323
		}
317
		}
324
	    }
318
	    }
325
	}
319
	}
326
    }'< ${CA}/index.txt
320
    }' <"${CA}/index.txt"
327
    cd "$OPWD"
321
    cd "$OPWD"
328
}
322
}
329
323
330
324
331
has_valid_cert () {
325
has_valid_cert () {
332
    list_cert_names | egrep -q "$1$";
326
    list_cert_names | egrep -q "$1$"
333
}
327
}
334
328
335
renew_cert () {
329
renew_cert () {
336
	local OPWD=`pwd`;
330
	local OPWD=$(pwd)
337
	cd "$SSLBASE";
331
	cd "$SSLBASE"
338
	
332
339
	if [ -z "$1" ]; then
333
	if [ -z "$1" ]; then
340
		echo "missing certificate name" 1>&2;
334
		echo "missing certificate name" 1>&2
341
		return 1;
335
		return 1
342
	fi
336
	fi
343
	
337
344
	local NUM=`list_cert_names | grep "$1" | sed -e 's/^\([0-9A-Fa-f]*\).*/\1/1'`;
338
	local NUM=`list_cert_names | grep "$1" | sed -e 's/^\([0-9A-Fa-f]*\).*/\1/1'`
345
	if [ -z "$NUM" ]; then
339
	if [ -z "$NUM" ]; then
346
		echo "no certificate for $1 registered" 1>&2;
340
		echo "no certificate for $1 registered" >&2
347
		return 1;
341
		return 1
348
	fi;
342
	fi
349
	
343
350
	if [ -z "$2" ]; then
344
	if [ -z "$2" ]; then
351
		days=$DEFAULT_DAYS
345
		days=$DEFAULT_DAYS
352
	fi
346
	fi
353
	
347
354
	# revoke cert
348
	# revoke cert
355
	revoke_cert $1
349
	revoke_cert "$1"
356
350
357
	# get host extension file
351
	# get host extension file
358
	hostExt=$(ucr get ssl/host/extensions)
352
	hostExt=$(ucr get ssl/host/extensions)
359
	if [ -s "$hostExt" ]; then
353
	if [ -s "$hostExt" ]; then
360
		source $hostExt
354
		. "$hostExt"
361
		extFile=$(createHostExtensionsFile "$1")
355
		extFile=$(createHostExtensionsFile "$1")
362
	fi	
356
	fi
363
	
357
364
	# sign the request
358
	# sign the request
365
	if [ -s "$extFile" ]; then
359
	if [ -s "$extFile" ]; then
366
		openssl ca -batch -config openssl.cnf -days $days -in "$1/req.pem" \
360
		openssl ca -batch -config openssl.cnf -days "$days" -in "$1/req.pem" \
367
		-out "$1/cert.pem" -passin pass:"$PASSWD" -extfile "$extFile"
361
			-out "$1/cert.pem" -passin pass:"$PASSWD" -extfile "$extFile"
368
		rm -f "$extFile"
362
		rm -f "$extFile"
369
	else
363
	else
370
		openssl ca -batch -config openssl.cnf -days $days -in "$1/req.pem" \
364
		openssl ca -batch -config openssl.cnf -days "$days" -in "$1/req.pem" \
371
		-out "$1/cert.pem" -passin pass:"$PASSWD"
365
			-out "$1/cert.pem" -passin pass:"$PASSWD"
372
	fi
366
	fi
373
	
367
374
	# move the new certificate to its place
368
	# move the new certificate to its place
375
	move_cert ${CA}/newcerts/*;
369
	move_cert "${CA}/newcerts/"*
376
	cd "$OPWD";
370
	cd "$OPWD"
377
}
371
}
378
372
379
# Parameter 1: Name des CN dessen Zertifikat wiederufen werden soll
373
# Parameter 1: Name des CN dessen Zertifikat wiederufen werden soll
380
374
381
revoke_cert () {
375
revoke_cert () {
382
	local OPWD=`pwd`;
376
	local OPWD=`pwd`
383
	cd "$SSLBASE";
377
	cd "$SSLBASE"
384
378
385
	if [ -z "$1" ]; then
379
	if [ -z "$1" ]; then
386
		echo "missing certificate name" 1>&2;
380
		echo "missing certificate name" >&2
387
		return 1;
381
		return 1
388
	fi
382
	fi
389
383
390
	local NUM=`list_cert_names | grep "$1" | sed -e 's/^\([0-9A-Fa-f]*\).*/\1/1'`;
384
	local NUM=`list_cert_names | grep "$1" | sed -e 's/^\([0-9A-Fa-f]*\).*/\1/1'`
391
	if [ -z "$NUM" ]; then
385
	if [ -z "$NUM" ]; then
392
		echo "no certificate for $1 registered" 1>&2;
386
		echo "no certificate for $1 registered" >&2
393
		return 1;
387
		return 1
394
	fi;
388
	fi
395
	openssl ca -config openssl.cnf -revoke ${CA}/certs/${NUM}.pem -passin pass:"$PASSWD"
389
	openssl ca -config openssl.cnf -revoke "${CA}/certs/${NUM}.pem" -passin pass:"$PASSWD"
396
	openssl ca -config openssl.cnf -gencrl -out ${CA}/crl/crl.pem -passin pass:"$PASSWD"
390
	openssl ca -config openssl.cnf -gencrl -out "${CA}/crl/crl.pem" -passin pass:"$PASSWD"
397
	openssl crl -in ${CA}/crl/crl.pem -out /var/www/${CA}.crl -inform pem -outform der
391
	openssl crl -in "${CA}/crl/crl.pem" -out "/var/www/${CA}.crl" -inform pem -outform der
398
392
399
	cd "$OPWD";
393
	cd "$OPWD"
400
}
394
}
401
395
402
396
 Lines 410-449   gencert () { Link Here 
410
	local OPWD=`pwd`
404
	local OPWD=`pwd`
411
	cd "$SSLBASE"
405
	cd "$SSLBASE"
412
	if has_valid_cert "$2"; then
406
	if has_valid_cert "$2"; then
413
	    revoke_cert "$2";
407
		revoke_cert "$2"
414
	fi;
408
	fi
415
409
416
	days=$(/usr/sbin/univention-config-registry get ssl/default/days)
410
	local days=$(/usr/sbin/univention-config-registry get ssl/default/days)
417
	if [ -z "$days" ]; then
411
	if [ -z "$days" ]; then
418
		days=$DEFAULT_DAYS
412
		days=$DEFAULT_DAYS
419
	fi
413
	fi
420
	# generate a key pair
414
	# generate a key pair
421
	mkdir -pm 700 $name
415
	mkdir -pm 700 "$name"
422
	mk_config "$name/openssl.cnf" "" $days "$cn"
416
	mk_config "$name/openssl.cnf" "" "$days" "$cn"
423
	openssl genrsa -out "$name/private.key" 1024
417
	openssl genrsa -out "$name/private.key" 1024
424
	yes '' | openssl req -config "$name/openssl.cnf" -new -key "$name/private.key" -out "$name/req.pem"
418
	yes '' | openssl req -config "$name/openssl.cnf" -new -key "$name/private.key" -out "$name/req.pem"
425
419
426
	# get host extension file
420
	# get host extension file
427
	hostExt=$(ucr get ssl/host/extensions)
421
	local hostExt=$(ucr get ssl/host/extensions)
428
	if [ -s "$hostExt" ]; then
422
	if [ -s "$hostExt" ]; then
429
		source $hostExt
423
		. "$hostExt"
430
		extFile=$(createHostExtensionsFile "$cn")
424
		local extFile=$(createHostExtensionsFile "$cn")
431
	fi	
425
	fi
432
426
433
	# sign the key
427
	# sign the key
434
	if [ -s "$extFile" ]; then
428
	if [ -s "$extFile" ]; then
435
		openssl ca -batch -config openssl.cnf -days $days -in "$name/req.pem" \
429
		openssl ca -batch -config openssl.cnf -days $days -in "$name/req.pem" \
436
		-out "$name/cert.pem" -passin pass:"$PASSWD" -extfile "$extFile"
430
			-out "$name/cert.pem" -passin pass:"$PASSWD" -extfile "$extFile"
437
		rm -f "$extFile"
431
		rm -f "$extFile"
438
	else
432
	else
439
		openssl ca -batch -config openssl.cnf -days $days -in "$name/req.pem" \
433
		openssl ca -batch -config openssl.cnf -days $days -in "$name/req.pem" \
440
		-out "$name/cert.pem" -passin pass:"$PASSWD"
434
			-out "$name/cert.pem" -passin pass:"$PASSWD"
441
	fi
435
	fi
442
436
443
	# move the new certificate to its place
437
	# move the new certificate to its place
444
	move_cert ${CA}/newcerts/*;
438
	move_cert "${CA}/newcerts/"*
445
439
446
	find $name -type f | xargs chmod 600
440
	find "$name" -type f -exec chmod 600 {} +
447
	find $name -type d | xargs chmod 700
441
	find "$name" -type d -exec chmod 700 {} +
448
	cd "$OPWD"
442
	cd "$OPWD"
449
}
443
}
(-)a/branches/ucs-3.0/ucs/base/univention-ssl/ssl-sync (-1 / +1 lines)
 Lines 3-9    Link Here 
3
# Univention SSL
3
# Univention SSL
4
#  ssl sync script
4
#  ssl sync script
5
#
5
#
6
# Copyright 2004-2011 Univention GmbH
6
# Copyright 2004-2012 Univention GmbH
7
#
7
#
8
# http://www.univention.de/
8
# http://www.univention.de/
9
#
9
#
(-)a/branches/ucs-3.0/ucs/base/univention-ssl/univention-certificate (-26 / +23 lines)
 Lines 3-9    Link Here 
3
# Univention SSL
3
# Univention SSL
4
#  openssl wrapper
4
#  openssl wrapper
5
#
5
#
6
# Copyright 2004-2011 Univention GmbH
6
# Copyright 2004-2012 Univention GmbH
7
#
7
#
8
# http://www.univention.de/
8
# http://www.univention.de/
9
#
9
#
 Lines 29-35    Link Here 
29
# License with the Debian GNU/Linux or Univention distribution in file
29
# License with the Debian GNU/Linux or Univention distribution in file
30
# /usr/share/common-licenses/AGPL-3; if not, see
30
# /usr/share/common-licenses/AGPL-3; if not, see
31
# <http://www.gnu.org/licenses/>.
31
# <http://www.gnu.org/licenses/>.
32
32
set -o errfail
33
33
34
usage ()
34
usage ()
35
{
35
{
 Lines 50-61   usage () Link Here 
50
	echo "        dump"
50
	echo "        dump"
51
	echo "        list"
51
	echo "        list"
52
	echo ""
52
	echo ""
53
	echo "Options"
53
	echo "Options:"
54
	echo "        -name <name>"
54
	echo "        -name <name>"
55
	echo "        -days <days>"
55
	echo "        -days <days>"
56
	echo ""
56
	echo ""
57
57
58
	exit
58
	exit 2
59
}
59
}
60
60
61
command="$1"
61
command="$1"
 Lines 63-100   shift Link Here 
63
63
64
if [ "$command" != "new" -a "$command" != "revoke" -a "$command" != "renew" -a "$command" != "check" -a "$command" != "list" -a "$command" != "dump" ]; then
64
if [ "$command" != "new" -a "$command" != "revoke" -a "$command" != "renew" -a "$command" != "check" -a "$command" != "list" -a "$command" != "dump" ]; then
65
	if [ -n "$command" ]; then
65
	if [ -n "$command" ]; then
66
		usage "unknown command: $command"
66
		usage "unknown command: $command" >&2
67
	else
67
	else
68
		usage
68
		usage >&2
69
	fi
69
	fi
70
fi
70
fi
71
71
72
while [ $# -gt 0 ]; do
72
while [ $# -gt 0 ]; do
73
	case "$1" in
73
	case "$1" in
74
	"-path")
74
	"-path")
75
		shift
75
		path="$2"
76
		path="$1"
76
		shift 2 || usage "Missing argument to -path" >&2
77
		shift
78
		;;
77
		;;
79
	"-name")
78
	"-name")
80
		shift
79
		name="$2"
81
		name="$1"
80
		shift 2 || usage "Missing argument to -name" >&2
82
		shift
83
		;;
81
		;;
84
	"-days")
82
	"-days")
85
		shift
83
		days="$2" || usage "Missing argument to -days" >&2
86
		days="$1"
84
		shift 2
87
		shift
88
		;;
85
		;;
89
	*)
86
	*)
90
		usage "unknown option $1"
87
		usage "unknown option $1" >&2
91
		shift
92
		;;
88
		;;
93
	esac
89
	esac
94
done
90
done
95
91
96
if [ "$command" != "list" -a -z "$name" ]; then
92
if [ "$command" != "list" -a -z "$name" ]; then
97
	usage "missing -name"
93
	usage "missing -name" >&2
98
fi
94
fi
99
95
100
cd /etc/univention/ssl
96
cd /etc/univention/ssl
 Lines 105-114   case "$command" in Link Here 
105
	"new")
101
	"new")
106
		echo "Creating certificate: $name"
102
		echo "Creating certificate: $name"
107
		gencert "/etc/univention/ssl/$name" "$name"
103
		gencert "/etc/univention/ssl/$name" "$name"
108
		getent group "DC Backup Hosts" 2>&1 >/dev/null
104
		if getent group "DC Backup Hosts" 2>&1 >/dev/null
109
		if [ $? = 0 ]; then
105
		then
110
			chgrp -R "DC Backup Hosts" "/etc/univention/ssl/$name"
106
			chgrp -R "DC Backup Hosts" "/etc/univention/ssl/$name"
111
			chmod -R g+rx "/etc/univention/ssl/$name"
107
			chmod g+rx "/etc/univention/ssl/$name"
112
		fi
108
		fi
113
		;;
109
		;;
114
	"revoke")
110
	"revoke")
 Lines 117-134   case "$command" in Link Here 
117
		;;
113
		;;
118
	"renew")
114
	"renew")
119
		if [ -z "$days" ]; then
115
		if [ -z "$days" ]; then
120
			usage "missing -days"
116
			usage "missing -days" >&2
121
		fi
117
		fi
122
		echo "Renew certificate: $name"
118
		echo "Renew certificate: $name"
123
		renew_cert "$name" "$days"
119
		renew_cert "$name" "$days"
124
		;;
120
		;;
125
	"check")
121
	"check")
126
		echo -n "Certificate \"$name\" is "
122
		echo -n "Certificate \"$name\" is "
127
		has_valid_cert $name
123
		if has_valid_cert "$name"
128
		if [ $? = 0 ]; then
124
		then
129
			echo "valid"
125
			echo "valid"
126
			exit 0
130
		else
127
		else
131
			echo "invalid"
128
			echo "invalid"
129
			exit 1
132
		fi
130
		fi
133
		;;
131
		;;
134
	"list")
132
	"list")
 Lines 137-143   case "$command" in Link Here 
137
		;;
135
		;;
138
	"dump")
136
	"dump")
139
		echo "Dump certificate: $name"
137
		echo "Dump certificate: $name"
140
		openssl x509 -in /etc/univention/ssl/$name/cert.pem -noout -text
138
		openssl x509 -in "/etc/univention/ssl/$name/cert.pem" -noout -text
141
		;;
139
		;;
142
esac
140
esac
143
(-)a/branches/ucs-3.0/ucs/base/univention-ssl/univention-certificate-check-validity (-3 / +3 lines)
 Lines 4-10    Link Here 
4
# Univention SSL
4
# Univention SSL
5
#  checks validity of the local SSL certificate
5
#  checks validity of the local SSL certificate
6
#
6
#
7
# Copyright 2006-2011 Univention GmbH
7
# Copyright 2006-2012 Univention GmbH
8
#
8
#
9
# http://www.univention.de/
9
# http://www.univention.de/
10
#
10
#
 Lines 37-45   import calendar Link Here 
37
37
38
from M2Crypto import X509
38
from M2Crypto import X509
39
39
40
import univention_baseconfig
40
from univention.config_registry import ConfigRegistry
41
41
42
_bc = univention_baseconfig.baseConfig()
42
_bc = ConfigRegistry()
43
_bc.load()
43
_bc.load()
44
44
45
def get_validity_date(certFile):
45
def get_validity_date(certFile):

Return to bug 26572