修改p12 证书导入逻辑

dependabot/npm_and_yarn/fir_admin/ws-5.2.3
youngS 3 years ago
parent a6f0cb0174
commit d4e4e9b278
  1. 66
      fir_client/src/components/user/FirSuperSignBase.vue
  2. 32
      fir_ser/api/utils/app/iossignapi.py
  3. 9
      fir_ser/api/utils/app/supersignutils.py
  4. 16
      fir_ser/api/views/supersign.py

@ -2,7 +2,7 @@
<el-main>
<el-dialog title="发布证书导入" :visible.sync="importcertDeveloperVisible" :destroy-on-close="true"
:close-on-click-modal="false" style="text-align:center">
:close-on-click-modal="false" style="text-align:center" width="700px">
<el-form label-width="30%">
<el-form-item label="发布证书p12文件" style="width: 80%">
<el-upload
@ -15,19 +15,19 @@
:auto-upload="false"
:limit="1"
>
<i class="el-icon-upload"></i>
<i class="el-icon-upload"/>
<div class="el-upload__text">将p12证书文件拖到此处<em>点击上传</em></div>
</el-upload>
</el-form-item>
<el-form-item label="发布证书p12密码" style="width: 80%">
<el-input label="证书密码" v-model="import_cert_info.cert_pwd"></el-input>
<el-input label="证书密码" v-model="cert_pwd"/>
</el-form-item>
<el-button @click="$refs.upload.submit()">确定导入</el-button>
<el-button @click="importcertDeveloperVisible=false">取消</el-button>
</el-form>
</el-dialog>
<el-dialog :title="title" :visible.sync="dialogaddDeveloperVisible" :destroy-on-close="true"
:close-on-click-modal="false" style="text-align:center">
:close-on-click-modal="false" style="text-align:center" width="750px">
<el-form ref="storageinfoform" :model="editdeveloperinfo"
label-width="80px" style="margin:0 auto;">
@ -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) {

@ -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):

@ -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(

@ -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)

Loading…
Cancel
Save