~ubuntu-branches/ubuntu/trusty/freeipa/trusty-proposed

« back to all changes in this revision

Viewing changes to ipaserver/install/plugins/upload_cacrt.py

  • Committer: Package Import Robot
  • Author(s): Timo Aaltonen
  • Date: 2013-09-03 17:13:27 UTC
  • Revision ID: package-import@ubuntu.com-20130903171327-s3f56x6vxz0o1jq5
Tags: upstream-3.3.4
ImportĀ upstreamĀ versionĀ 3.3.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Authors:
 
2
#   Alexander Bokovoy <abokovoy@redhat.com>
 
3
#
 
4
# Copyright (C) 2012  Red Hat
 
5
# see file 'COPYING' for use and warranty information
 
6
#
 
7
# This program is free software; you can redistribute it and/or modify
 
8
# it under the terms of the GNU General Public License as published by
 
9
# the Free Software Foundation, either version 3 of the License, or
 
10
# (at your option) any later version.
 
11
#
 
12
# This program is distributed in the hope that it will be useful,
 
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
# GNU General Public License for more details.
 
16
#
 
17
# You should have received a copy of the GNU General Public License
 
18
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
 
 
20
from ipaserver.install.plugins import MIDDLE
 
21
from ipaserver.install.plugins.baseupdate import PostUpdate
 
22
from ipaserver.install.dsinstance import realm_to_serverid, config_dirname
 
23
from ipaserver.install import certs
 
24
from ipalib import api
 
25
from ipapython.dn import DN
 
26
import base64
 
27
 
 
28
class update_upload_cacrt(PostUpdate):
 
29
    """
 
30
    Upload public CA certificate to LDAP
 
31
    """
 
32
    order=MIDDLE
 
33
 
 
34
    def execute(self, **options):
 
35
        ldap = self.obj.backend
 
36
        (cdn, ipa_config) = ldap.get_ipa_config()
 
37
        subject_base = ipa_config.get('ipacertificatesubjectbase', [None])[0]
 
38
        dirname = config_dirname(realm_to_serverid(api.env.realm))
 
39
        certdb = certs.CertDB(api.env.realm, nssdir=dirname, subject_base=subject_base)
 
40
 
 
41
        dercert = certdb.get_cert_from_db(certdb.cacert_name, pem=False)
 
42
 
 
43
        updates = {}
 
44
        dn = DN(('cn', 'CACert'), ('cn', 'ipa'), ('cn','etc'), api.env.basedn)
 
45
 
 
46
        cacrt_entry = ['objectclass:nsContainer',
 
47
                       'objectclass:pkiCA',
 
48
                       'cn:CAcert',
 
49
                       'cACertificate;binary:%s' % dercert,
 
50
                      ]
 
51
        updates[dn] = {'dn': dn, 'default': cacrt_entry}
 
52
 
 
53
        return (False, True, [updates])
 
54
 
 
55
api.register(update_upload_cacrt)