123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- from . import mpfun
- from models import *
- from sqlalchemy.orm import Session
- from database import get_local_db
- # 应急预案人员信息表
- # 加密和HMAC签名
- def sign_row(db: Session, row: EmergencyContactInfo) -> None:
- if row.sign != '':
- return
-
- unit_id = str(row.unit_id) # 单位ID
- unit_name = mpfun.base64_data(row.unit_name) # 单位名称
- contact_name = mpfun.base64_data(row.contact_name) # 联系人
- position = mpfun.base64_data(row.position) # 职务
- yue_gov_ease_phone = mpfun.enc_data(row.yue_gov_ease_phone) # 粤政易手机号码
- del_flag = row.del_flag # 是否已删除
- sign_data = ",".join([unit_id, unit_name, contact_name, position, yue_gov_ease_phone, del_flag])
- sign_hmac = mpfun.sign_data(sign_data)
- # print('sign_tbl_user sign_data:', sign_data)
- # print('sign_tbl_user sign_hmac:', sign_hmac)
- row.yue_gov_ease_phone = yue_gov_ease_phone
- row.sign = sign_hmac
-
- db.commit()
- # 比较字段合并字符串是否和MAC值匹配上,调用密码服务器[验证HMAC]接口
- def sign_valid_row(row: EmergencyContactInfo) -> bool:
- if row.sign == '':
- return True
- # 关键字段合并字符串
- sign_data = get_sign_str(row)
- # print('sys_user sign_data:', sign_data)
-
- # 原HMACSM3数值
- sign_hmac = row.sign
- # print('sign_hmac:', sign_hmac)
- return mpfun.hmac_verify(sign_data, sign_hmac)
- # 生成待签名的字符串
- def get_sign_str(row: EmergencyContactInfo) -> str:
- unit_id = str(row.unit_id) # 单位ID
- unit_name = mpfun.base64_data(row.unit_name) # 单位名称
- contact_name = mpfun.base64_data(row.contact_name) # 联系人
- position = mpfun.base64_data(row.position) # 职务
- yue_gov_ease_phone = row.yue_gov_ease_phone # 粤政易手机号码
- del_flag = row.del_flag # 是否已删除
- # 关键字段合并字符串
- sign_data = ",".join([unit_id, unit_name, contact_name, position, yue_gov_ease_phone, del_flag])
- return sign_data
- # 生成HAMC签名值
- def get_sign_hmac(row: EmergencyContactInfo) -> str:
- sign_data = get_sign_str(row)
- return mpfun.sign_data(sign_data)
- # 对所有数据进行签名
- def sign_table():
- print('sign_emergency_contact_info table =====>>>')
- with get_local_db() as db:
- rows = db.query(EmergencyContactInfo).filter(EmergencyContactInfo.sign == '').all()
- for row in rows:
- sign_row(db, row)
|