From d4e4e9b278b6e56307c97da47cd27f65ae8913c5 Mon Sep 17 00:00:00 2001 From: youngS Date: Sat, 26 Jun 2021 10:19:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9p12=20=E8=AF=81=E4=B9=A6?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/user/FirSuperSignBase.vue | 66 +++++++++---------- fir_ser/api/utils/app/iossignapi.py | 32 ++++++--- fir_ser/api/utils/app/supersignutils.py | 9 ++- fir_ser/api/views/supersign.py | 16 +++-- 4 files changed, 73 insertions(+), 50 deletions(-) diff --git a/fir_client/src/components/user/FirSuperSignBase.vue b/fir_client/src/components/user/FirSuperSignBase.vue index 7e97445..1df8175 100644 --- a/fir_client/src/components/user/FirSuperSignBase.vue +++ b/fir_client/src/components/user/FirSuperSignBase.vue @@ -2,7 +2,7 @@ + :close-on-click-modal="false" style="text-align:center" width="700px"> - +
将p12证书文件拖到此处,或点击上传
- + 确定导入 取消
+ :close-on-click-modal="false" style="text-align:center" width="750px"> @@ -477,7 +477,7 @@ apple_auth_type: 0, loadingfun: {}, loading: false, - import_cert_info: {cert_pwd: '', cert_content: ''} + cert_pwd: '', } }, watch: { 'dialogaddDeveloperVisible': function () { @@ -491,39 +491,39 @@ const isLt2M = file.size / 1024 / 1024 < 2; if (file.type === 'application/x-pkcs12') { if (isLt2M) { - this.import_cert_info.cert_content = file; - let reader = new FileReader(); - reader.onload = evt => { - this.import_cert_info.cert_content = evt.target.result; - developercert(data => { - if (data.code === 1000) { - this.$message.success("证书导入成功"); - this.importcertDeveloperVisible = false; - this.dialogaddDeveloperVisible = false; - this.handleCurrentChange(this.pagination.currentPage) - } else { - this.$message.error("证书导入失败 " + data.msg) - } - }, { - methods: 'POST', - data: { - issuer_id: this.editdeveloperinfo.issuer_id, - cert_pwd: this.import_cert_info.cert_pwd, - cert_content: this.import_cert_info.cert_content - } - }) - }; - reader.readAsDataURL(file); - return false; + if (this.cert_pwd && this.cert_pwd.toString().trim().length > 0) { + let reader = new FileReader(); + reader.onload = evt => { + developercert(data => { + if (data.code === 1000) { + this.$message.success("证书导入成功"); + this.importcertDeveloperVisible = false; + this.dialogaddDeveloperVisible = false; + this.handleCurrentChange(this.pagination.currentPage) + } else { + this.$message.error("证书导入失败 " + data.msg) + } + }, { + methods: 'POST', + data: { + issuer_id: this.editdeveloperinfo.issuer_id, + cert_pwd: this.cert_pwd, + cert_content: evt.target.result + } + }) + }; + reader.readAsDataURL(file); + return false; + } else { + this.$message.warning('密码不能为空'); + } } else { - this.$message.error('上传大小有误'); + this.$message.warning('上传大小有误'); } } else { - this.$message.error('上传文件格式不正确!'); - + this.$message.warning('上传文件格式不正确!'); } return false; - }, developer_usedColor(percentage) { if (percentage < 20) { diff --git a/fir_ser/api/utils/app/iossignapi.py b/fir_ser/api/utils/app/iossignapi.py index 588d312..2083d19 100644 --- a/fir_ser/api/utils/app/iossignapi.py +++ b/fir_ser/api/utils/app/iossignapi.py @@ -73,16 +73,30 @@ class ResignApp(object): result["err_info"] = e return False, result + def write_cert(self): + for file in [self.app_dev_p12, self.app_dev_p12 + '.pwd', self.my_local_key, self.app_dev_pem]: + if os.path.exists(file): + os.rename(file, file + '.' + get_format_time() + '.bak') + os.rename(file + '.bak', file) + def make_cert_from_p12(self, password, p12_content=None): result = {} try: if p12_content: - with open(self.app_dev_p12 + '.bak', 'wb+') as f: - f.write(base64.b64decode(p12_content.split('data:application/x-pkcs12;base64,')[1])) - if password: - with open(self.app_dev_p12 + '.pwd.bak', 'w') as f: - f.write(password) - p12 = load_pkcs12(open(self.app_dev_p12, 'rb').read(), password) + p12_content_list = p12_content.split('data:application/x-pkcs12;base64,') + if len(p12_content_list) == 2: + with open(self.app_dev_p12 + '.bak', 'wb+') as f: + f.write(base64.b64decode(p12_content.split('data:application/x-pkcs12;base64,')[1])) + if password: + with open(self.app_dev_p12 + '.pwd.bak', 'w') as f: + f.write(password) + else: + result["err_info"] = '非法p12证书文件,请检查' + return False, result + else: + result["err_info"] = '证书内容有误,请检查' + return False, result + p12 = load_pkcs12(open(self.app_dev_p12 + '.bak', 'rb').read(), password) cert = p12.get_certificate() if cert.has_expired(): result["err_info"] = '证书已经过期' @@ -91,16 +105,14 @@ class ResignApp(object): f.write(dump_privatekey(FILETYPE_PEM, p12.get_privatekey())) with open(self.app_dev_pem + '.bak', 'wb+') as f: f.write(dump_certificate(FILETYPE_PEM, cert)) - for file in [self.app_dev_p12, self.app_dev_p12 + '.pwd', self.my_local_key, self.app_dev_pem]: - if os.path.exists(file): - os.rename(file, file + '.' + get_format_time() + '.bak') - os.rename(file + '.bak', file) return True, cert.get_version() except Exception as e: for file in [self.app_dev_p12, self.app_dev_p12 + '.pwd', self.my_local_key, self.app_dev_pem]: if os.path.exists(file + '.bak'): os.remove(file + '.bak') result["err_info"] = e + if 'mac verify failure' in str(e): + result["err_info"] = 'p12 导入密码错误,请检查' return False, result def sign(self, new_profile, org_ipa, new_ipa, info_plist_properties=None): diff --git a/fir_ser/api/utils/app/supersignutils.py b/fir_ser/api/utils/app/supersignutils.py index a4feabc..1e7bf0a 100644 --- a/fir_ser/api/utils/app/supersignutils.py +++ b/fir_ser/api/utils/app/supersignutils.py @@ -703,6 +703,13 @@ class IosUtils(object): developer_obj.save() return status, result + @staticmethod + def create_developer_space(developer_obj, user_obj): + auth = get_auth_form_developer(developer_obj) + file_format_path_name = file_format_path(user_obj, auth) + if not os.path.isdir(os.path.dirname(file_format_path_name)): + os.makedirs(os.path.dirname(file_format_path_name)) + @staticmethod def create_developer_cert(developer_obj, user_obj): auth = get_auth_form_developer(developer_obj) @@ -735,7 +742,7 @@ class IosUtils(object): auth = get_auth_form_developer(developer_obj) app_api_obj = get_api_obj(auth) file_format_path_name = file_format_path(user_obj, auth) - app_dev_pem = file_format_path_name + ".pem" + app_dev_pem = file_format_path_name + ".pem.bak" status, result = app_api_obj.auto_set_certid_by_p12(app_dev_pem) if status: AppIOSDeveloperInfo.objects.filter(user_id=user_obj, issuer_id=auth.get("issuer_id")).update( diff --git a/fir_ser/api/views/supersign.py b/fir_ser/api/views/supersign.py index 1cc599f..a65dc5d 100644 --- a/fir_ser/api/views/supersign.py +++ b/fir_ser/api/views/supersign.py @@ -164,7 +164,8 @@ class DeveloperView(APIView): try: logger.error("user %s add new developer %s data %s" % ( request.user, data.get("issuer_id", ""), datainfo)) - AppIOSDeveloperInfo.objects.create(user_id=request.user, **datainfo) + developer_obj = AppIOSDeveloperInfo.objects.create(user_id=request.user, **datainfo) + IosUtils.create_developer_space(developer_obj, request.user) except Exception as e: logger.error("user %s create developer %s failed Exception:%s" % ( request.user, datainfo, e)) @@ -287,12 +288,15 @@ class SuperSignCertView(APIView): resign_app_obj = IosUtils.get_resign_obj(request.user, developer_obj) status, result = resign_app_obj.make_cert_from_p12(request.data.get('cert_pwd', ''), request.data.get('cert_content', None)) - if not status: + if status: + status, result = IosUtils.auto_get_certid_by_p12(developer_obj, request.user) + if status: + resign_app_obj.write_cert() + else: + res.code = 1003 + res.msg = str('证书未在开发者账户找到,请检查推送证书是否属于该开发者') + else: res.code = 1002 res.msg = str(result['err_info']) return Response(res.dict) - status, result = IosUtils.auto_get_certid_by_p12(developer_obj, request.user) - if not status: - res.code = 1003 - res.msg = str('证书未在开发者账户找到,请检查推送证书是否属于该开发者') return Response(res.dict)