+ # Download delegated_user_cred
+ elif 'dl_user_cred' in request.POST:
+ if 'delegated_user_credential' in account_config:
+ user_cred = account_config['delegated_user_credential']
+ response = HttpResponse(user_cred, content_type='text/plain')
+ response['Content-Disposition'] = 'attachment; filename="user_cred.txt"'
+ return response
+ else:
+ messages.error(request, 'Download error: User credential is not stored in the server')
+ return HttpResponseRedirect("/portal/account/")
+
+ # Download user_cert
+ elif 'dl_user_cert' in request.POST:
+ if 'user_credential' in account_config:
+ user_cred = account_config['user_credential']
+ obj_cred = Credential(string=user_cred)
+ obj_gid = obj_cred.get_gid_object()
+ str_cert = obj_gid.save_to_string()
+ response = HttpResponse(str_cert, content_type='text/plain')
+ response['Content-Disposition'] = 'attachment; filename="user_certificate.pem"'
+ return response
+
+ elif 'delegated_user_credential' in account_config:
+ user_cred = account_config['delegated_user_credential']
+ obj_cred = Credential(string=user_cred)
+ obj_gid = obj_cred.get_gid_object()
+ str_cert = obj_gid.save_to_string()
+ response = HttpResponse(str_cert, content_type='text/plain')
+ response['Content-Disposition'] = 'attachment; filename="user_certificate.pem"'
+ return response
+ else:
+ messages.error(request, 'Download error: User credential is not stored in the server')
+ return HttpResponseRedirect("/portal/account/")
+
+ # Download user p12 = private_key + Certificate
+ elif 'dl_user_p12' in request.POST:
+ if 'user_credential' in account_config and 'user_private_key' in account_config:
+ user_cred = account_config['user_credential']
+ obj_cred = Credential(string=user_cred)
+ obj_gid = obj_cred.get_gid_object()
+ str_cert = obj_gid.save_to_string()
+ cert = crypto.load_certificate(crypto.FILETYPE_PEM, str_cert)
+ #ca = cert.get_issuer()
+
+ user_private_key = account_config['user_private_key'].encode('ascii')
+ pkey = crypto.load_privatekey(crypto.FILETYPE_PEM, user_private_key)
+
+ p12 = crypto.PKCS12()
+ p12.set_privatekey(pkey)
+ p12.set_certificate(cert)
+ #p12.set_ca_certificates(ca)
+ pkcs12 = p12.export()
+
+ pkcs12 = p12.get_ca_certificates()
+
+ response = HttpResponse(pkcs12, content_type='text/plain')
+ response['Content-Disposition'] = 'attachment; filename="user_pkcs.p12"'
+ return response
+
+ elif 'delegated_user_credential' in account_config and 'user_private_key' in account_config:
+ user_cred = account_config['delegated_user_credential']
+ obj_cred = Credential(string=user_cred)
+ obj_gid = obj_cred.get_gid_object()
+ str_cert = obj_gid.save_to_string()
+ cert = crypto.load_certificate(crypto.FILETYPE_PEM, str_cert)
+ #ca = cert.get_issuer()
+
+ user_private_key = account_config['user_private_key'].encode('ascii')
+ pkey = crypto.load_privatekey(crypto.FILETYPE_PEM, user_private_key)
+
+ p12 = crypto.PKCS12()
+ p12.set_privatekey(pkey)
+ p12.set_certificate(cert)
+ #p12.set_ca_certificates(ca)
+ pkcs12 = p12.export()
+ pkcs12 = p12.get_ca_certificates()
+
+ response = HttpResponse(pkcs12, content_type='text/plain')
+ response['Content-Disposition'] = 'attachment; filename="user_pkcs.p12"'
+ return response
+ else:
+ messages.error(request, 'Download error: User private key or credential is not stored in the server')
+ return HttpResponseRedirect("/portal/account/")