summaryrefslogtreecommitdiffstats
path: root/src/db
ModeNameSize
-rw-r--r--sysdb.c50937logstatsplain
-rw-r--r--sysdb.h34465logstatsplain
-rw-r--r--sysdb_autofs.c12176logstatsplain
-rw-r--r--sysdb_autofs.h3207logstatsplain
-rw-r--r--sysdb_idmap.c9502logstatsplain
-rw-r--r--sysdb_ops.c86957logstatsplain
-rw-r--r--sysdb_private.h3886logstatsplain
-rw-r--r--sysdb_search.c25223logstatsplain
-rw-r--r--sysdb_selinux.c13191logstatsplain
-rw-r--r--sysdb_selinux.h2553logstatsplain
-rw-r--r--sysdb_services.c22414logstatsplain
-rw-r--r--sysdb_services.h2957logstatsplain
-rw-r--r--sysdb_ssh.c5179logstatsplain
-rw-r--r--sysdb_ssh.h1442logstatsplain
-rw-r--r--sysdb_subdomains.c13638logstatsplain
-rw-r--r--sysdb_sudo.c22082logstatsplain
-rw-r--r--sysdb_sudo.h4355logstatsplain
-rw-r--r--sysdb_upgrade.c33804logstatsplain
pan class="hl opt">.in_tree: dbdir = api.env.dot_ipa + os.sep + 'alias' else: dbdir = "/etc/httpd/alias" nss.nss_init(dbdir) return nss.Certificate(buffer(data)) def get_subject(certificate, datatype=PEM): """ Load an X509.3 certificate and get the subject. """ nsscert = load_certificate(certificate, datatype) return nsscert.subject def get_serial_number(certificate, datatype=PEM): """ Return the decimal value of the serial number. """ nsscert = load_certificate(certificate, datatype) return nsscert.serial_number def make_pem(data): """ Convert a raw base64-encoded blob into something that looks like a PE file with lines split to 64 characters and proper headers. """ pemcert = '\n'.join([data[x:x+64] for x in range(0, len(data), 64)]) return '-----BEGIN CERTIFICATE-----\n' + \ pemcert + \ '\n-----END CERTIFICATE-----' def normalize_certificate(rawcert): """ Incoming certificates should be DER-encoded. If not it is converted to DER-format. Note that this can't be a normalizer on a Param because only unicode variables are normalized. """ if not rawcert: return None rawcert = strip_header(rawcert) if util.isvalid_base64(rawcert): try: dercert = base64.b64decode(rawcert) except Exception, e: raise errors.Base64DecodeError(reason=str(e)) else: dercert = rawcert # At this point we should have a certificate, either because the data # was base64-encoded and now its not or it came in as DER format. # Let's decode it and see. Fetching the serial number will pass the # certificate through the NSS DER parser. try: serial = unicode(get_serial_number(dercert, DER)) except NSPRError, nsprerr: if nsprerr.errno == -8183: # SEC_ERROR_BAD_DER raise errors.CertificateFormatError(error='improperly formatted DER-encoded certificate') else: raise errors.CertificateFormatError(error=str(nsprerr)) return dercert def write_certificate(rawcert, filename): """ Write the certificate to a file in PEM format. The cert value can be either DER or PEM-encoded, it will be normalized to DER regardless, then back out to PEM. """ dercert = normalize_certificate(rawcert) try: fp = open(filename, 'w') fp.write(make_pem(base64.b64encode(dercert))) fp.close() except (IOError, OSError), e: raise errors.FileError(reason=str(e)) def verify_cert_subject(ldap, hostname, dercert): """ Verify that the certificate issuer we're adding matches the issuer base of our installation. This assumes the certificate has already been normalized. This raises an exception on errors and returns nothing otherwise. """ nsscert = load_certificate(dercert, datatype=DER) subject = str(nsscert.subject) issuer = str(nsscert.issuer) # Handle both supported forms of issuer, from selfsign and dogtag. if ((issuer != 'CN=%s Certificate Authority' % api.env.realm) and (issuer != 'CN=Certificate Authority,O=%s' % api.env.realm)): raise errors.CertificateOperationError(error=_('Issuer "%(issuer)s" does not match the expected issuer') % \ {'issuer' : issuer}) if __name__ == '__main__': # this can be run with: # python ipalib/x509.py < /etc/ipa/ca.crt from ipalib import api api.bootstrap() api.finalize() nss.nss_init_nodb() # Read PEM certs from stdin and print out its components certlines = sys.stdin.readlines() cert = ''.join(certlines) nsscert = load_certificate(cert) print nsscert