def SignBaidu(file,para): #if file already signed,return command = sign_conf.byp_bin_path + 'SignVerify.exe ' + file ret = os.system(command.encode(sys.getfilesystemencoding())) if ret == 0: return product = para[0] signType = para[1] sign_product = '' if product == 'bdm': sign_product = sign_conf.sign_file_product.encode(sys.getfilesystemencoding()) elif product == 'bdkv': sign_product = sign_conf.kvsign_file_product.encode(sys.getfilesystemencoding()) file_path = file[0:file.rfind('\\')+1] file_name = file[file.rfind('\\')+1:] logging.info( 'Signning File ' + file + ' through connection to ' + sign_conf.cerf_addr) files,fields = [],[] fields.append(('desc',sign_product)) fields.append(('cert',signType)) #files.append(('f1',file,comm.getFileBuf(file))) #blanks = ['f2','f3','f4','f5','f6','f7','f8','f9'] files.append(('file[]',file,comm.getFileBuf(file))) #blanks = ['file[]','file[]','file[]','file[]'] blanks = [] digitalSign = '' if signType == '2': digitalSign = 'baidu_cn' elif signType == '1': digitalSign = 'baidu_bj_netcom' elif signType == '3': digitalSign = 'baidu_jp' for i in range(0,10): response = post_multipart(sign_conf.cerf_addr,'/sign.php',fields,files,blanks) logging.info( response) iStart = response.find('href=') + 6 if iStart != 5: part2 = response[iStart:] iStop = part2.find("'") if iStop != -1: downloadPath = response[iStart:iStart + iStop] urllib.urlretrieve('http://' + sign_conf.cerf_addr + '/' + downloadPath, file + '.sign') command = sign_conf.byp_bin_path + 'SignVerify.exe ' + file + '.sign ' + digitalSign ret = os.system(command.encode(sys.getfilesystemencoding())) if ret == 0: shutil.move(file+'.sign', file) break; if i == 9: logging.info('Sign baidu official digital signature failed.') print '\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a' f = open('c:\\sign_output.txt','a') f.write("file sign baidu failed %s\r\n" % file) f.close() #raise SignBaiduException('Sign baidu official digital signature failed.') return
def SignBaidu2(file,para): #if file already signed,return command = conf.byp_bin_path + 'SignVerify.exe ' + file ret = os.system(command.encode(sys.getfilesystemencoding())) if ret == 0: return product = para[0] signType = para[1] sign_product = '' if product == 'bdm': sign_product = conf.sign_file_product.encode(sys.getfilesystemencoding()) elif product == 'bdkv': sign_product = conf.kvsign_file_product.encode(sys.getfilesystemencoding()) file_path = file[0:file.rfind('\\')+1] file_name = file[file.rfind('\\')+1:] logging.info( 'Signning File ' + file + ' through connection to ' + conf.local_cerf_addr) files,fields = [],[] fields.append(('desc',sign_product)) fields.append(('cert',signType)) #files.append(('f1',file,comm.getFileBuf(file))) #blanks = ['f2','f3','f4','f5','f6','f7','f8','f9'] files.append(('file',file,comm.getFileBuf(file))) #blanks = ['file[]','file[]','file[]','file[]'] blanks = [] digitalSign = '' if signType == '2': digitalSign = 'baidu_cn' elif signType == '1': digitalSign = 'baidu_bj_netcom' elif signType == '3': digitalSign = 'baidu_jp' while True: response = post_multipart2(conf.local_cerf_addr,conf.local_cerf_url,fields,files,blanks) logging.info( response) print response if response.find('failed') != -1: #i = i + 1 #if i == 9: # logging.info('Sign baidu official digital signature failed.') # print '\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a' # f = open('c:\\sign_output.txt','a') # f.write("file sign baidu failed %s\r\n" % file) # f.close() # raise SignBaiduException('Sign baidu official digital signature failed.') continue iStart = response.find('msg:') + 4 if iStart != 3: part2 = response[iStart:] while True: try: urllib.urlretrieve(part2, file + '.sign') break except Exception,e: print 'error while calling urllib.urlretrieve' print str(e) print 'try recalling ...' command = conf.byp_bin_path + 'SignVerify.exe ' + file + '.sign ' + digitalSign ret = os.system(command.encode(sys.getfilesystemencoding())) if ret == 0: shutil.move(file+'.sign', file) break
def SignBaidu2(file, para): #if file already signed,return command = conf.byp_bin_path + 'SignVerify.exe ' + file ret = os.system(command.encode(sys.getfilesystemencoding())) if ret == 0: return product = para[0] signType = para[1] sign_product = '' if product == 'bdm': sign_product = conf.sign_file_product.encode( sys.getfilesystemencoding()) elif product == 'bdkv': sign_product = conf.kvsign_file_product.encode( sys.getfilesystemencoding()) file_path = file[0:file.rfind('\\') + 1] file_name = file[file.rfind('\\') + 1:] logging.info('Signning File ' + file + ' through connection to ' + conf.local_cerf_addr) files, fields = [], [] fields.append(('desc', sign_product)) fields.append(('cert', signType)) #files.append(('f1',file,comm.getFileBuf(file))) #blanks = ['f2','f3','f4','f5','f6','f7','f8','f9'] files.append(('file', file, comm.getFileBuf(file))) #blanks = ['file[]','file[]','file[]','file[]'] blanks = [] digitalSign = '' if signType == '2': digitalSign = 'baidu_cn' elif signType == '1': digitalSign = 'baidu_bj_netcom' elif signType == '3': digitalSign = 'baidu_jp' while True: response = post_multipart2(conf.local_cerf_addr, conf.local_cerf_url, fields, files, blanks) logging.info(response) print response if response.find('failed') != -1: #i = i + 1 #if i == 9: # logging.info('Sign baidu official digital signature failed.') # print '\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a' # f = open('c:\\sign_output.txt','a') # f.write("file sign baidu failed %s\r\n" % file) # f.close() # raise SignBaiduException('Sign baidu official digital signature failed.') continue iStart = response.find('msg:') + 4 if iStart != 3: part2 = response[iStart:] while True: try: urllib.urlretrieve(part2, file + '.sign') break except Exception, e: print 'error while calling urllib.urlretrieve' print str(e) print 'try recalling ...' command = conf.byp_bin_path + 'SignVerify.exe ' + file + '.sign ' + digitalSign ret = os.system(command.encode(sys.getfilesystemencoding())) if ret == 0: shutil.move(file + '.sign', file) break
def SignBaidu(file, para): #if file already signed,return command = conf.byp_bin_path + 'SignVerify.exe ' + file ret = os.system(command.encode(sys.getfilesystemencoding())) if ret == 0: return product = para[0] signType = para[1] sign_product = '' if product == 'bdm': sign_product = conf.sign_file_product.encode( sys.getfilesystemencoding()) elif product == 'bdkv': sign_product = conf.kvsign_file_product.encode( sys.getfilesystemencoding()) file_path = file[0:file.rfind('\\') + 1] file_name = file[file.rfind('\\') + 1:] logging.info('Signning File ' + file + ' through connection to ' + conf.cerf_addr) files, fields = [], [] fields.append(('desc', sign_product)) fields.append(('cert', signType)) #files.append(('f1',file,comm.getFileBuf(file))) #blanks = ['f2','f3','f4','f5','f6','f7','f8','f9'] files.append(('file[]', file, comm.getFileBuf(file))) #blanks = ['file[]','file[]','file[]','file[]'] blanks = [] digitalSign = '' if signType == '2': digitalSign = 'baidu_cn' elif signType == '1': digitalSign = 'baidu_bj_netcom' elif signType == '3': digitalSign = 'baidu_jp' for i in range(0, 10): response = post_multipart(conf.cerf_addr, '/sign.php', fields, files, blanks) logging.info(response) iStart = response.find('href=') + 6 if iStart != 5: part2 = response[iStart:] iStop = part2.find("'") if iStop != -1: downloadPath = response[iStart:iStart + iStop] while True: try: urllib.urlretrieve( 'http://' + conf.cerf_addr + '/' + downloadPath, file + '.sign') break except Exception, e: print 'error while calling urllib.urlretrieve' print str(e) print 'try recalling ...' command = conf.byp_bin_path + 'SignVerify.exe ' + file + '.sign ' + digitalSign ret = os.system(command.encode(sys.getfilesystemencoding())) if ret == 0: shutil.move(file + '.sign', file) break if i == 9: logging.info('Sign baidu official digital signature failed.') print '\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a' f = open('c:\\sign_output.txt', 'a') f.write("file sign baidu failed %s\r\n" % file) f.close() raise SignBaiduException( 'Sign baidu official digital signature failed.')