From 69d5979ff8a27c07e693037da4be19076ac3ebe2 Mon Sep 17 00:00:00 2001 From: nineven Date: Sat, 30 Jan 2021 16:50:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0p8key=20=E7=A7=98=E9=92=A5?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E7=AD=BE=E5=90=8D=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 | 11 ++- fir_ser/api/utils/app/iossignapi.py | 82 ++++++++++++++++++- fir_ser/api/utils/app/supersignutils.py | 60 ++++++++++---- fir_ser/api/utils/utils.py | 10 ++- fir_ser/api/views/supersign.py | 18 +++- 5 files changed, 155 insertions(+), 26 deletions(-) diff --git a/fir_client/src/components/FirSuperSignBase.vue b/fir_client/src/components/FirSuperSignBase.vue index 79abd5e..f207613 100644 --- a/fir_client/src/components/FirSuperSignBase.vue +++ b/fir_client/src/components/FirSuperSignBase.vue @@ -523,9 +523,14 @@ } }, activedeveloperFun(developer, act) { - this.iosdeveloperFun({"methods": "PUT", "data": {"email": developer.email, "act": act}}); - this.codeactiveVisible = true; - this.authemail = developer.email; + if(developer.email){ + this.iosdeveloperFun({"methods": "PUT", "data": {"email": developer.email, "act": act}}); + this.codeactiveVisible = true; + this.authemail = developer.email; + }else if(developer.issuer_id){ + this.iosdeveloperFun({"methods": "PUT", "data": {"issuer_id": developer.issuer_id, "act": act}}); + this.codeactiveVisible = true; + } // this.inputcode(developer) }, diff --git a/fir_ser/api/utils/app/iossignapi.py b/fir_ser/api/utils/app/iossignapi.py index 3a61e62..c68d160 100644 --- a/fir_ser/api/utils/app/iossignapi.py +++ b/fir_ser/api/utils/app/iossignapi.py @@ -9,8 +9,9 @@ from fir_ser.settings import SUPER_SIGN_ROOT import os from api.utils.app.randomstrings import make_app_uuid import logging - +from api.utils.apple.appleapiv3 import AppStoreConnectApi logger = logging.getLogger(__file__) +import base64 def exec_shell(cmd, remote=False, timeout=None): @@ -70,7 +71,7 @@ class AppDeveloperApi(object): self.cmd = self.cmd + " cert add '%s'" % (self.file_format_path_name(user_obj)) return exec_shell(self.cmd) - def get_profile(self, bundleId, app_id, device_udid, device_name, provisionName): + def get_profile(self, bundleId, app_id, device_udid, device_name, provisionName,auth=None): self.cmd = self.cmd + " profile add '%s' '%s' '%s' '%s' '%s' '%s'" % ( bundleId, app_id, device_udid, device_name, self.certid, provisionName) return exec_shell(self.cmd) @@ -121,3 +122,80 @@ class ResignApp(object): def sign(self, new_profile, org_ipa, new_ipa): self.cmd = self.cmd + " -p '%s' -o '%s' '%s'" % (new_profile, new_ipa, org_ipa) result = exec_shell(self.cmd) + + +class AppDeveloperApiV2(object): + def __init__(self, issuer_id, private_key_id, p8key, certid): + self.issuer_id = issuer_id + self.private_key_id = private_key_id + self.p8key = p8key + self.certid = certid + + def active(self,user_obj): + result = {} + try: + apple_obj = AppStoreConnectApi(self.issuer_id, self.private_key_id, self.p8key) + certificates = apple_obj.get_all_certificates() + logger.info("ios developer active result:%s" %certificates) + if len(certificates) > 0: + return True, result + except Exception as e: + logger.error("ios developer active Failed Exception:%s" % e) + result['return_info'] = "%s" %e + return False, result + + def file_format_path_name(self, user_obj): + cert_dir_name = make_app_uuid(user_obj, self.issuer_id) + cert_dir_path = os.path.join(SUPER_SIGN_ROOT, cert_dir_name) + if not os.path.isdir(cert_dir_path): + os.makedirs(cert_dir_path) + return os.path.join(cert_dir_path, cert_dir_name) + + def create_cert(self, user_obj): + pass + + def get_profile(self, bundleId, app_id, device_udid, device_name, provisionName,auth): + result={} + try: + apple_obj = AppStoreConnectApi(self.issuer_id, self.private_key_id, self.p8key) + bundle_obj = apple_obj.register_bundle_id_enable_capability(app_id,bundleId + app_id) + apple_obj.register_device(device_name,device_udid) + profile_obj = apple_obj.create_profile(bundle_obj.id,auth.get('certid'),provisionName.split("/")[-1]) + if profile_obj: + n=base64.b64decode(profile_obj.profileContent) + if not os.path.isdir(os.path.basename(provisionName)): + os.makedirs(os.path.basename(provisionName)) + with open(provisionName,'wb') as f: + f.write(n) + return True, profile_obj.profileContent + except Exception as e: + logger.error("ios developer active Failed Exception:%s" % e) + result['return_info'] = "%s" % e + return False, result + + def del_profile(self, bundleId, app_id): + self.cmd = self.cmd + " profile del '%s' '%s'" % (bundleId, app_id) + result = exec_shell(self.cmd) + + def set_device_status(self, status, device_udid): + if status == "enable": + self.cmd = self.cmd + " device enable '%s'" % (device_udid) + else: + self.cmd = self.cmd + " device disable '%s'" % (device_udid) + result = exec_shell(self.cmd) + + def add_device(self, device_udid, device_name): + self.cmd = self.cmd + " device add '%s' '%s'" % (device_udid, device_name) + result = exec_shell(self.cmd) + + def get_device(self, user_obj): + self.cmd = self.cmd + " device get '%s' " % (self.file_format_path_name(user_obj)) + return exec_shell(self.cmd) + + def add_app(self, bundleId, app_id): + self.cmd = self.cmd + " app add '%s' '%s'" % (bundleId, app_id) + result = exec_shell(self.cmd) + + def del_app(self, bundleId, app_id): + self.cmd = self.cmd + " app del '%s' '%s'" % (bundleId, app_id) + result = exec_shell(self.cmd) diff --git a/fir_ser/api/utils/app/supersignutils.py b/fir_ser/api/utils/app/supersignutils.py index a380c20..d58c855 100644 --- a/fir_ser/api/utils/app/supersignutils.py +++ b/fir_ser/api/utils/app/supersignutils.py @@ -6,7 +6,7 @@ import uuid, xmltodict, os, re, logging, time from fir_ser.settings import SUPER_SIGN_ROOT, MEDIA_ROOT, SERVER_DOMAIN, MOBILECONFIG_SIGN_SSL -from api.utils.app.iossignapi import AppDeveloperApi, ResignApp +from api.utils.app.iossignapi import AppDeveloperApi, ResignApp, AppDeveloperApiV2 from api.models import APPSuperSignUsedInfo, AppUDID, AppIOSDeveloperInfo, AppReleaseInfo, Apps, APPToDeveloper, \ UDIDsyncDeveloper from api.utils.app.randomstrings import make_app_uuid, make_from_user_uuid @@ -170,11 +170,22 @@ class IosUtils(object): def get_developer_auth(self): developer_obj = self.get_developer_user_by_app_udid() - auth = { - "username": developer_obj.email, - "password": developer_obj.password, - "certid": developer_obj.certid - } + if developer_obj.email: + auth = { + "username": developer_obj.email, + "password": developer_obj.password, + "certid": developer_obj.certid + } + + elif developer_obj.issuer_id: + auth = { + "issuer_id": developer_obj.issuer_id, + "private_key_id": developer_obj.private_key_id, + "p8key": developer_obj.p8key, + "certid": developer_obj.certid + } + else: + auth={} self.developer_obj = developer_obj self.auth = auth @@ -203,15 +214,22 @@ class IosUtils(object): return developer_obj def download_profile(self): - app_api_obj = AppDeveloperApi(**self.auth) + if self.auth.get("username",None): + app_api_obj = AppDeveloperApi(**self.auth) + else: + app_api_obj = AppDeveloperApiV2(**self.auth) + bundleId = self.app_obj.bundle_id app_id = self.app_obj.app_id device_udid = self.udid_info.get('udid') device_name = self.udid_info.get('product') - return app_api_obj.get_profile(bundleId, app_id, device_udid, device_name, self.get_profile_full_path()) + return app_api_obj.get_profile(bundleId, app_id, device_udid, device_name, self.get_profile_full_path(),self.auth) def get_profile_full_path(self): - cert_dir_name = make_app_uuid(self.user_obj, self.auth.get("username")) + mpkey = self.auth.get("username") + if self.auth.get("issuer_id"): + mpkey = self.auth.get("issuer_id") + cert_dir_name = make_app_uuid(self.user_obj, mpkey) cert_dir_path = os.path.join(SUPER_SIGN_ROOT, cert_dir_name, "profile") if not os.path.isdir(cert_dir_path): os.makedirs(cert_dir_path) @@ -430,12 +448,24 @@ class IosUtils(object): :param code: :return: ''' - auth = { - "username": developer_obj.email, - "password": developer_obj.password, - "certid": developer_obj.certid - } - app_api_obj = AppDeveloperApi(**auth) + if developer_obj.email: + auth = { + "username": developer_obj.email, + "password": developer_obj.password, + "certid": developer_obj.certid + } + app_api_obj = AppDeveloperApi(**auth) + + elif developer_obj.issuer_id: + auth = { + "issuer_id": developer_obj.issuer_id, + "private_key_id": developer_obj.private_key_id, + "p8key": developer_obj.p8key, + "certid": developer_obj.certid + } + app_api_obj = AppDeveloperApiV2(**auth) + else: + return False, {} status, result = app_api_obj.active(user_obj) if status: developer_obj.is_actived = True diff --git a/fir_ser/api/utils/utils.py b/fir_ser/api/utils/utils.py index 662a2e3..59ed1f4 100644 --- a/fir_ser/api/utils/utils.py +++ b/fir_ser/api/utils/utils.py @@ -27,7 +27,10 @@ def file_format_path(user_obj, auth=None, email=None): if email: cert_dir_name = make_app_uuid(user_obj, email) else: - cert_dir_name = make_app_uuid(user_obj, auth.get("username")) + pkey = auth.get("username") + if auth.get("issuer_id"): + pkey= auth.get("issuer_id") + cert_dir_name = make_app_uuid(user_obj, pkey) cert_dir_path = os.path.join(SUPER_SIGN_ROOT, cert_dir_name) if not os.path.isdir(cert_dir_path): os.makedirs(cert_dir_path) @@ -36,7 +39,10 @@ def file_format_path(user_obj, auth=None, email=None): def get_profile_full_path(developer_obj, app_obj): - cert_dir_name = make_app_uuid(developer_obj.user_id, developer_obj.email) + pkey = developer_obj.email + if developer_obj.issuer_id: + pkey = developer_obj.issuer_id + cert_dir_name = make_app_uuid(developer_obj.user_id, pkey) cert_dir_path = os.path.join(SUPER_SIGN_ROOT, cert_dir_name, "profile") provisionName = os.path.join(cert_dir_path, app_obj.app_id) return provisionName + '.mobileprovision' diff --git a/fir_ser/api/views/supersign.py b/fir_ser/api/views/supersign.py index 508f714..8863b1f 100644 --- a/fir_ser/api/views/supersign.py +++ b/fir_ser/api/views/supersign.py @@ -75,11 +75,18 @@ class DeveloperView(APIView): res = BaseResponse() logger.info("user %s iosdeveloper %s act %s" % (request.user, developer_obj, act)) if act == "preactive": - developer_auth_code("del", request.user, developer_obj.email) + if developer_obj.email: + developer_auth_code("del", request.user, developer_obj.email) + elif developer_obj.issuer_id: + developer_auth_code("del", request.user, developer_obj.issuer_id) + status, result = IosUtils.active_developer(developer_obj, request.user) if status: if not developer_obj.certid: - status, result = IosUtils.create_developer_cert(developer_obj, request.user) + if developer_obj.email: + status, result = IosUtils.create_developer_cert(developer_obj, request.user) + elif developer_obj.issuer_id: + return Response(res.dict) if status: IosUtils.get_device_from_developer(developer_obj, request.user) else: @@ -89,7 +96,7 @@ class DeveloperView(APIView): return self.get(request) else: res.code = 1008 - res.msg = result.get("return_info") + res.msg = result.get("return_info","未知错误") return Response(res.dict) elif act == "nowactive": code = data.get("code", None) @@ -138,8 +145,11 @@ class DeveloperView(APIView): if password != "" and password != developer_obj.password: developer_obj.password = password developer_obj.is_actived = False - developer_obj.private_key_id = data.get("private_key_id", developer_obj.private_key_id) + private_key_id = data.get("private_key_id", developer_obj.private_key_id) p8key = data.get("p8key", developer_obj.p8key) + if private_key_id != "" and private_key_id != developer_obj.private_key_id: + developer_obj.private_key_id = private_key_id + developer_obj.is_actived = False if p8key != "" and p8key != developer_obj.p8key: developer_obj.p8key = p8key developer_obj.is_actived = False