From 082b56121f165d72520dfc2da6011a270d1fa242 Mon Sep 17 00:00:00 2001 From: nineven Date: Sat, 30 Jan 2021 19:28:52 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=88=9B=E5=BB=BA=E8=AF=81?= =?UTF-8?q?=E4=B9=A6=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/FirSuperSignBase.vue | 6 ++- fir_ser/api/utils/app/iossignapi.py | 52 ++++++++++++++++++- fir_ser/api/utils/app/supersignutils.py | 28 ++++++---- 3 files changed, 72 insertions(+), 14 deletions(-) diff --git a/fir_client/src/components/FirSuperSignBase.vue b/fir_client/src/components/FirSuperSignBase.vue index 18f91cb..4caac7d 100644 --- a/fir_client/src/components/FirSuperSignBase.vue +++ b/fir_client/src/components/FirSuperSignBase.vue @@ -510,9 +510,13 @@ }); }, isocertcert() { + let data={"email": this.editdeveloperinfo.email, "act": "ioscert"}; + if(this.editdeveloperinfo.issuer_id){ + data={"issuer_id": this.editdeveloperinfo.issuer_id, "act": "ioscert"}; + } this.iosdeveloperFun({ "methods": "PUT", - "data": {"email": this.editdeveloperinfo.email, "act": "ioscert"} + "data": data }); }, inputcode() { diff --git a/fir_ser/api/utils/app/iossignapi.py b/fir_ser/api/utils/app/iossignapi.py index 95008e0..18c9088 100644 --- a/fir_ser/api/utils/app/iossignapi.py +++ b/fir_ser/api/utils/app/iossignapi.py @@ -3,6 +3,7 @@ # project: 4月 # author: liuyu # date: 2020/4/24 +import OpenSSL from api.utils.app.shellcmds import shell_command, use_user_pass, pshell_command from fir_ser.settings import SUPER_SIGN_ROOT @@ -12,7 +13,8 @@ import logging from api.utils.apple.appleapiv3 import AppStoreConnectApi logger = logging.getLogger(__file__) import base64 - +from OpenSSL.SSL import FILETYPE_PEM +from OpenSSL.crypto import (dump_certificate_request, dump_privatekey, PKey, TYPE_RSA, X509Req,dump_certificate) def exec_shell(cmd, remote=False, timeout=None): if remote: @@ -151,8 +153,54 @@ class AppDeveloperApiV2(object): os.makedirs(cert_dir_path) return os.path.join(cert_dir_path, cert_dir_name) + def make_csr_content(self,csr_file_path,private_key_path): + # create public/private key + key = PKey() + key.generate_key(TYPE_RSA, 2048) + # Generate CSR + req = X509Req() + req.get_subject().CN = 'BJ' + req.get_subject().O = 'FLY APP Inc' + req.get_subject().OU = 'IT' + req.get_subject().L = 'BJ' + req.get_subject().ST = 'BJ' + req.get_subject().C = 'CN' + req.get_subject().emailAddress = 'fly@fly.com' + req.set_pubkey(key) + req.sign(key, 'sha256') + csr_content = dump_certificate_request(FILETYPE_PEM, req) + with open(csr_file_path, 'wb+') as f: + f.write(csr_content) + with open(private_key_path, 'wb+') as f: + f.write(dump_privatekey(FILETYPE_PEM, key)) + + return csr_content + + def make_pem(self,cer_content,pem_path): + cert = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_ASN1,cer_content) + with open(pem_path, 'wb+') as f: + f.write(dump_certificate(FILETYPE_PEM,cert)) + def create_cert(self, user_obj): - pass + result = {} + try: + apple_obj = AppStoreConnectApi(self.issuer_id, self.private_key_id, self.p8key) + csr_path = self.file_format_path_name(user_obj) + if not os.path.isdir(os.path.dirname(csr_path)): + os.makedirs(os.path.dirname(csr_path)) + csr_content = self.make_csr_content(csr_path+".csr",csr_path+".key") + certificates = apple_obj.create_certificate(csr_content.decode("utf-8")) + if certificates: + n=base64.b64decode(certificates.certificateContent) + with open(csr_path+".cer",'wb') as f: + f.write(n) + self.make_pem(n,csr_path+".pem") + logger.info("ios developer create result:%s" % certificates.certificateContent) + return True, certificates + except Exception as e: + logger.error("ios developer active Failed Exception:%s" % e) + result['return_info'] = "%s" %e + return False, result def get_profile(self, bundleId, app_id, device_udid, device_name, provisionName,auth): result={} diff --git a/fir_ser/api/utils/app/supersignutils.py b/fir_ser/api/utils/app/supersignutils.py index 6c875cf..d2c4ec3 100644 --- a/fir_ser/api/utils/app/supersignutils.py +++ b/fir_ser/api/utils/app/supersignutils.py @@ -463,18 +463,24 @@ class IosUtils(object): app_api_obj = get_api_obj(auth) status, result = app_api_obj.create_cert(user_obj) if status: - file_format_path_name = file_format_path(user_obj, auth) - cert_info = None - try: - with open(file_format_path_name + '.info', "r") as f: - cert_info = f.read() - except Exception as e: - logger.error("create_developer_cert developer_obj:%s user_obj:%s delete file failed Exception:%s" % ( - developer_obj, user_obj, e)) - if cert_info: - cert_id = re.findall(r'.*\n\tid=(.*),.*', cert_info)[0].replace('"', '') - AppIOSDeveloperInfo.objects.filter(user_id=user_obj, email=auth.get("username")).update(is_actived=True, + if auth.get("issuer_id"): + cert_id = result.id + AppIOSDeveloperInfo.objects.filter(user_id=user_obj, issuer_id=auth.get("issuer_id")).update(is_actived=True, certid=cert_id) + else: + + file_format_path_name = file_format_path(user_obj, auth) + cert_info = None + try: + with open(file_format_path_name + '.info', "r") as f: + cert_info = f.read() + except Exception as e: + logger.error("create_developer_cert developer_obj:%s user_obj:%s delete file failed Exception:%s" % ( + developer_obj, user_obj, e)) + if cert_info: + cert_id = re.findall(r'.*\n\tid=(.*),.*', cert_info)[0].replace('"', '') + AppIOSDeveloperInfo.objects.filter(user_id=user_obj, email=auth.get("username")).update(is_actived=True, + certid=cert_id) return status, result @staticmethod