def certificate_export_certificate_and_privatekey(request, id): c = models.Certificate.objects.get(pk=id) export_certificate(c.cert_certificate) export_privatekey(c.cert_privatekey) response = StreamingHttpResponse(buf_generator(combined), content_type='application/octet-stream') response['Content-Length'] = len(combined) response['Content-Disposition'] = 'attachment; filename=%s.p12' % c return response
def certificate_export_certificate_and_privatekey(request, id): c = models.Certificate.objects.get(pk=id) export_certificate(c.cert_certificate) export_privatekey(c.cert_privatekey) response = StreamingHttpResponse( buf_generator(combined), content_type='application/octet-stream' ) response['Content-Length'] = len(combined) response['Content-Disposition'] = 'attachment; filename=%s.p12' % c return response
def CA_export_privatekey(request, id): ca = models.CertificateAuthority.objects.get(pk=id) key = export_privatekey(ca.cert_privatekey) response = StreamingHttpResponse(buf_generator(key), content_type='application/octet-stream') response['Content-Length'] = len(key) response['Content-Disposition'] = 'attachment; filename=%s.key' % ca return response
def CA_export_privatekey(request, id): ca = models.CertificateAuthority.objects.get(pk=id) key = export_privatekey(ca.cert_privatekey) response = StreamingHttpResponse( buf_generator(key), content_type='application/octet-stream' ) response['Content-Length'] = len(key) response['Content-Disposition'] = 'attachment; filename=%s.key' % ca return response
def main(certfile, keyfile): """ This function reads the certificates that were ported form pre-certmanager to 9.3 post-certmanager in the update and tries to parse, import and save them into the new Cert UI model db. Once it has done so successfully,it then goes ahead to set the webui setting's certfile to the above created cert object""" # Try to read the certfile and private keyfile and parse them # into respective vars, throw appropriate errors if files notice # found and then exit with return status 1. try: with open(certfile, "r") as f: crt = f.read() except IOError: print("Cannot read certfile specified at %s" % certfile) sys.exit(1) try: with open(keyfile, "r") as f: key = f.read() except IOError: print("Cannot read keyfile specified at %s" % keyfile) sys.exit(1) # Now for the actual parsing to meet the new cert ui reqs # as well as the creation of the new cert object in the django db cert_info = load_certificate(crt) created_cert = Certificate.objects.create( cert_name="freenas-pre-certui", cert_type=CERT_TYPE_EXISTING, cert_certificate=crt, cert_privatekey=export_privatekey(key), cert_country=cert_info['country'], cert_state=cert_info['state'], cert_city=cert_info['city'], cert_organization=cert_info['organization'], cert_common=cert_info['common'], cert_email=cert_info['email'], cert_digest_algorithm=cert_info['digest_algorithm'] ) # Now to set this cert as the webui cert in the system settings model fnassettings = Settings.objects.all()[0] fnassettings.stg_guicertificate = created_cert fnassettings.save()
def main(certfile, keyfile): """ This function reads the certificates that were ported form pre-certmanager to 9.3 post-certmanager in the update and tries to parse, import and save them into the new Cert UI model db. Once it has done so successfully,it then goes ahead to set the webui setting's certfile to the above created cert object""" # Try to read the certfile and private keyfile and parse them # into respective vars, throw appropriate errors if files notice # found and then exit with return status 1. try: with open(certfile, "r") as f: crt = f.read() except IOError: print "Cannot read certfile specified at %s" % certfile sys.exit(1) try: with open(keyfile, "r") as f: key = f.read() except IOError: print "Cannot read keyfile specified at %s" % keyfile sys.exit(1) # Now for the actual parsing to meet the new cert ui reqs # as well as the creation of the new cert object in the django db cert_info = load_certificate(crt) created_cert = Certificate.objects.create( cert_name="freenas-pre-certui", cert_type=CERT_TYPE_EXISTING, cert_certificate=crt, cert_privatekey=export_privatekey(key), cert_country=cert_info['country'], cert_state=cert_info['state'], cert_city=cert_info['city'], cert_organization=cert_info['organization'], cert_common=cert_info['common'], cert_email=cert_info['email'], cert_digest_algorithm=cert_info['digest_algorithm'] ) # Now to set this cert as the webui cert in the system settings model fnassettings = Settings.objects.all()[0] fnassettings.stg_guicertificate = created_cert fnassettings.save()