增加p8key 秘钥支持签名功能

super_sign_new
nineven 4 years ago
parent 4da62f86b9
commit 69d5979ff8
  1. 5
      fir_client/src/components/FirSuperSignBase.vue
  2. 82
      fir_ser/api/utils/app/iossignapi.py
  3. 36
      fir_ser/api/utils/app/supersignutils.py
  4. 10
      fir_ser/api/utils/utils.py
  5. 14
      fir_ser/api/views/supersign.py

@ -523,9 +523,14 @@
} }
}, },
activedeveloperFun(developer, act) { activedeveloperFun(developer, act) {
if(developer.email){
this.iosdeveloperFun({"methods": "PUT", "data": {"email": developer.email, "act": act}}); this.iosdeveloperFun({"methods": "PUT", "data": {"email": developer.email, "act": act}});
this.codeactiveVisible = true; this.codeactiveVisible = true;
this.authemail = developer.email; 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) // this.inputcode(developer)
}, },

@ -9,8 +9,9 @@ from fir_ser.settings import SUPER_SIGN_ROOT
import os import os
from api.utils.app.randomstrings import make_app_uuid from api.utils.app.randomstrings import make_app_uuid
import logging import logging
from api.utils.apple.appleapiv3 import AppStoreConnectApi
logger = logging.getLogger(__file__) logger = logging.getLogger(__file__)
import base64
def exec_shell(cmd, remote=False, timeout=None): 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)) self.cmd = self.cmd + " cert add '%s'" % (self.file_format_path_name(user_obj))
return exec_shell(self.cmd) 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'" % ( self.cmd = self.cmd + " profile add '%s' '%s' '%s' '%s' '%s' '%s'" % (
bundleId, app_id, device_udid, device_name, self.certid, provisionName) bundleId, app_id, device_udid, device_name, self.certid, provisionName)
return exec_shell(self.cmd) return exec_shell(self.cmd)
@ -121,3 +122,80 @@ class ResignApp(object):
def sign(self, new_profile, org_ipa, new_ipa): def sign(self, new_profile, org_ipa, new_ipa):
self.cmd = self.cmd + " -p '%s' -o '%s' '%s'" % (new_profile, new_ipa, org_ipa) self.cmd = self.cmd + " -p '%s' -o '%s' '%s'" % (new_profile, new_ipa, org_ipa)
result = exec_shell(self.cmd) 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)

@ -6,7 +6,7 @@
import uuid, xmltodict, os, re, logging, time import uuid, xmltodict, os, re, logging, time
from fir_ser.settings import SUPER_SIGN_ROOT, MEDIA_ROOT, SERVER_DOMAIN, MOBILECONFIG_SIGN_SSL 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, \ from api.models import APPSuperSignUsedInfo, AppUDID, AppIOSDeveloperInfo, AppReleaseInfo, Apps, APPToDeveloper, \
UDIDsyncDeveloper UDIDsyncDeveloper
from api.utils.app.randomstrings import make_app_uuid, make_from_user_uuid 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): def get_developer_auth(self):
developer_obj = self.get_developer_user_by_app_udid() developer_obj = self.get_developer_user_by_app_udid()
if developer_obj.email:
auth = { auth = {
"username": developer_obj.email, "username": developer_obj.email,
"password": developer_obj.password, "password": developer_obj.password,
"certid": developer_obj.certid "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.developer_obj = developer_obj
self.auth = auth self.auth = auth
@ -203,15 +214,22 @@ class IosUtils(object):
return developer_obj return developer_obj
def download_profile(self): def download_profile(self):
if self.auth.get("username",None):
app_api_obj = AppDeveloperApi(**self.auth) app_api_obj = AppDeveloperApi(**self.auth)
else:
app_api_obj = AppDeveloperApiV2(**self.auth)
bundleId = self.app_obj.bundle_id bundleId = self.app_obj.bundle_id
app_id = self.app_obj.app_id app_id = self.app_obj.app_id
device_udid = self.udid_info.get('udid') device_udid = self.udid_info.get('udid')
device_name = self.udid_info.get('product') 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): 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") cert_dir_path = os.path.join(SUPER_SIGN_ROOT, cert_dir_name, "profile")
if not os.path.isdir(cert_dir_path): if not os.path.isdir(cert_dir_path):
os.makedirs(cert_dir_path) os.makedirs(cert_dir_path)
@ -430,12 +448,24 @@ class IosUtils(object):
:param code: :param code:
:return: :return:
''' '''
if developer_obj.email:
auth = { auth = {
"username": developer_obj.email, "username": developer_obj.email,
"password": developer_obj.password, "password": developer_obj.password,
"certid": developer_obj.certid "certid": developer_obj.certid
} }
app_api_obj = AppDeveloperApi(**auth) 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) status, result = app_api_obj.active(user_obj)
if status: if status:
developer_obj.is_actived = True developer_obj.is_actived = True

@ -27,7 +27,10 @@ def file_format_path(user_obj, auth=None, email=None):
if email: if email:
cert_dir_name = make_app_uuid(user_obj, email) cert_dir_name = make_app_uuid(user_obj, email)
else: 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) cert_dir_path = os.path.join(SUPER_SIGN_ROOT, cert_dir_name)
if not os.path.isdir(cert_dir_path): if not os.path.isdir(cert_dir_path):
os.makedirs(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): 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") cert_dir_path = os.path.join(SUPER_SIGN_ROOT, cert_dir_name, "profile")
provisionName = os.path.join(cert_dir_path, app_obj.app_id) provisionName = os.path.join(cert_dir_path, app_obj.app_id)
return provisionName + '.mobileprovision' return provisionName + '.mobileprovision'

@ -75,11 +75,18 @@ class DeveloperView(APIView):
res = BaseResponse() res = BaseResponse()
logger.info("user %s iosdeveloper %s act %s" % (request.user, developer_obj, act)) logger.info("user %s iosdeveloper %s act %s" % (request.user, developer_obj, act))
if act == "preactive": if act == "preactive":
if developer_obj.email:
developer_auth_code("del", request.user, 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) status, result = IosUtils.active_developer(developer_obj, request.user)
if status: if status:
if not developer_obj.certid: if not developer_obj.certid:
if developer_obj.email:
status, result = IosUtils.create_developer_cert(developer_obj, request.user) status, result = IosUtils.create_developer_cert(developer_obj, request.user)
elif developer_obj.issuer_id:
return Response(res.dict)
if status: if status:
IosUtils.get_device_from_developer(developer_obj, request.user) IosUtils.get_device_from_developer(developer_obj, request.user)
else: else:
@ -89,7 +96,7 @@ class DeveloperView(APIView):
return self.get(request) return self.get(request)
else: else:
res.code = 1008 res.code = 1008
res.msg = result.get("return_info") res.msg = result.get("return_info","未知错误")
return Response(res.dict) return Response(res.dict)
elif act == "nowactive": elif act == "nowactive":
code = data.get("code", None) code = data.get("code", None)
@ -138,8 +145,11 @@ class DeveloperView(APIView):
if password != "" and password != developer_obj.password: if password != "" and password != developer_obj.password:
developer_obj.password = password developer_obj.password = password
developer_obj.is_actived = False 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) 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: if p8key != "" and p8key != developer_obj.p8key:
developer_obj.p8key = p8key developer_obj.p8key = p8key
developer_obj.is_actived = False developer_obj.is_actived = False

Loading…
Cancel
Save