Пример #1
0
 def get(self, id):
     if request.args.get("rescan", None):
         certificates.get_authorities()
     certs = certificates.get_authorities(id)
     if id and not certs:
         abort(404)
     if id and request.args.get("download", None):
         with open(certs.cert_path, "r") as f:
             data = f.read()
         resp = Response(data, mimetype="application/octet-stream")
         resp.headers["Content-Length"] = str(len(data.encode('utf-8')))
         resp.headers["Content-Disposition"] = "attachment; filename=%s.pem" % id
         return resp
     if type(certs) == list:
         return jsonify(certauths=[x.as_dict() for x in certs])
     else:
         return jsonify(certauth=certs.as_dict())
Пример #2
0
 def get(self, id):
     if request.args.get("rescan", None):
         certificates.get_authorities()
     certs = certificates.get_authorities(id)
     if id and not certs:
         abort(404)
     if id and request.args.get("download", None):
         with open(certs.cert_path, "r") as f:
             data = f.read()
         resp = Response(data, mimetype="application/octet-stream")
         resp.headers["Content-Length"] = str(len(data.encode('utf-8')))
         aname = "attachment; filename={0}.pem".format(id)
         resp.headers["Content-Disposition"] = aname
         return resp
     if isinstance(certs, certificates.CertificateAuthority):
         return jsonify(authority=certs.serialized)
     else:
         return jsonify(authorities=[x.serialized for x in certs])
Пример #3
0
def list_authorities():
    """List all certificate authorities (CAs)."""
    try:
        certs = certificates.get_authorities()
        if not certs:
            logger.info('ctl:cert:authorities',
                        'No certificate authorities found')
            return
        llen = len(sorted(certs, key=lambda x: len(x.id))[-1].id)
        for x in sorted(certs, key=lambda x: x.id):
            click.echo(
                click.style('{name: <{fill}}'.format(name=x.id, fill=llen + 3),
                            fg="white",
                            bold=True) + "Expires " +
                click.style(x.expiry.strftime("%c"), fg="yellow"))
    except Exception as e:
        raise CLIException(str(e))
Пример #4
0
 def _generate(self, job, data):
     nthread = NotificationThread(id=job.id)
     try:
         cert = certificates.generate_certificate(
             data["id"], data["domain"], data["country"], data["state"],
             data["locale"], data["email"], data["keytype"],
             data["keylength"], nthread=nthread)
     except:
         remove_record("certificate", data["id"])
         raise
     else:
         push_record("certificate", cert.serialized)
     try:
         basehost = ".".join(data["domain"].split(".")[-2:])
         ca = certificates.get_authorities(basehost)
     except:
         pass
     else:
         push_record("authority", ca.serialized)
Пример #5
0
 def delete(self, id):
     cert = certificates.get_authorities(id)
     if not id or not cert:
         abort(404)
     cert.remove()
     return Response(status=204)
Пример #6
0
 def delete(self, id):
     cert = certificates.get_authorities(id)
     if not id or not cert:
         abort(404)
     cert.remove()
     return Response(status=204)