def listobjects(self, type1, value=''): try: status = '' if (value == ''): lobjs = pyp11.listobjects(self.handle, self.slotid, type1) else: lobjs = pyp11.listobjects(self.handle, self.slotid, type1, value) except: #Проблемы с библиотекой токена e = sys.exc_info()[1] e1 = e.args[0] lobjs = '' status = e1 return (lobjs, status)
if (len(lcerts) == 0): print('На токене нет сертификатов') quit() #Перебираем сертификаты i = 0 for cert in lcerts: print(str(i) + '-ый сертификат') #Информация о сертификате for key in cert: print('\t' + key + ': ' + cert[key]) i += 1 #Сравним с pyp11.listobjects tobj = 'объект' #type = 'all' #type = 'cert' #type = 'pubkey' #type = 'data' type = 'privkey' if (type == 'cert'): tobj = 'сертификат' print('Работа с listobjects:') #lm = pyp11.listobjects(aa, 0, type, 'value') pyp11.login(aa, 0, '01234567') lm = pyp11.listobjects(aa, 0, type) i = 0 for obj in lm: print(str(i) + '-ый ' + tobj) for key in obj: print('\t' + key + ': ' + obj[key]) i += 1 quit()
if (verify == 1): print ('Подпись верна') else: print ('Подпись не верна') print ('Проверка 2-ой подписи') verify = pyp11.verify(aa, 0, digest_hex, sign1_hex1, pubkeyinfo) if (verify == 1): print ('Подпись верна') else: print ('Подпись не верна') #Rename key label = 'key_512_new' dd = dict(pkcs11_id=pkcs11_id, pkcs11_label=label) print ("Список открытых ключей на токене (наш ключ с меткой key_512) ") lobj = pyp11.listobjects(aa, 0, 'pubkey') for lo in lobj: for key in lo: print ('\t' + key + ': ' + lo[key]) print ('Переименовывакм ключи с меткой: ' + labkey + ' на ' + label) pyp11.rename(aa, 0, 'key', dd) print ("Список открытых ключей на токене после переименования") lobj = pyp11.listobjects(aa, 0, 'pubkey') for lo in lobj: for key in lo.keys(): print ('\t' + key + ': ' + lo[key]) #Delete keyPair: private key and public key dd = dict(pkcs11_id=pkcs11_id) #pyp11.delete(aa, 0, 'key', dd) #quit()
#Загружаем библиотеку aa = pyp11.loadmodule(lib) print (aa) try: bb = pyp11.login (aa, 0, '01234567') except: print('Except login: '******'3082069d30820648a00302010202021016300c06082a8503070101030205003081e2310b3009060355040613025255312c302a06035504080c23d09cd0bed181d0bad0bed0b2d181d0bad0b0d18f20d0bed0b1d0bbd0b0d181d182d18c3120301e06035504070c17476e75504720d093d09ed0a1d0a22d323031322d32353631143012060355040a0c0bd0a3d0a62031325f3235363114301206035504030c0bd0a3d0a62031325f323536311a301806082a85030381030101120c3132333435363738393031323118301606052a85036401120d313233343536373839303132333121301f06092a864886f70d010901161263615f31325f323536406c697373692e7275301e170d3230303631393039323533305a170d3233303931343039323533305a3081e4310b30090603550406130252553141303f06035504080c38d0a7d183d0b2d0b0d188d181d0bad0b0d18f20d0a0d0b5d181d0bfd183d0b1d0bbd0b8d0bad0b0202d20d0a7d183d0b2d0b0d188d0b8d18f310e300c06035504070c0564667364663111300f06035504030c0854657874344b6579310e300c06035504040c056473666664310e300c060355042a0c056378767863311a301806082a85030381030101120c3232323232323232323232323116301406052a85036403120b3333333333333333333333311b301906092a864886f70d010901160c6b657934406b6579342e72753066301f06082a85030701010101301306072a85030202240006082a850307010102020343000440a9816daf3fb8618718f5d9ed51ebf235bd09d6eb50184f3453dbf2481834211f7c6466b1aae96f1c0fee2675a74b71983df5a73dd60cf315b5d1028baa4e5a30a38203d9308203d5300c0603551d130101ff040230003081ae06052a850364700481a43081a10c3ad09dd0b0d0b8d0bcd0b5d0bdd0bed0b2d0b0d0bdd0b8d0b520d0a1d09ad097d09820d0bfd0bed0bbd18cd0b7d0bed0b2d0b0d182d0b5d0bbd18f0c1cd0a2d0b5d181d182d0bed0b2d18bd0b920d0a3d0a6204341464c36330c26d0a1d0b5d180d182d0b8d184d0b8d0bad0b0d18220d0a1d09ad097d09820d0a3d0a620e284960c1dd0a1d0b5d180d182d0b8d184d0b8d0bad0b0d18220d0a3d0a620e28496304506052a8503646f043c0c3ad09dd0b0d0b8d0bcd0b5d0bdd0bed0b2d0b0d0bdd0b8d0b520d0a1d09ad097d09820d0bfd0bed0bbd18cd0b7d0bed0b2d0b0d182d0b5d0bbd18f301d0603551d2004163014300806062a8503647101300806062a8503647102300b0603551d0f0404030204f0301106096086480186f84201010404030205a03082012c0603551d25048201233082011f06082b0601050507030206082b06010505070304060a2b06010401823714020206062a850364020106072a85030202220606082b0601050507030206082b0601050507030406092a850305011802010306052a8503060e06072a85030381570406072a85030381570506072a85030381570606072a85030381570706072a85030381570806072a85030381570906072a85030381570b06072a85030381570c06072a85030381570d060b2b0601040182bf2601010106082a8503024001010106082a850303050a020c06062a850306030206082a8503050118022e06082a8503062d01010106082a8503050118021e06072a850305011c0206072a850305011c0306082a850303814a010806082b0601050507030206082b06010505070304301d0603551d0e041604148491c02f2faa4711e096d0155d75f47540e878d2308201190603551d23048201103082010c80146d3700d64bf7ed43c3ebc25962639626272651cca181e8a481e53081e2310b3009060355040613025255312c302a06035504080c23d09cd0bed181d0bad0bed0b2d181d0bad0b0d18f20d0bed0b1d0bbd0b0d181d182d18c3120301e06035504070c17476e75504720d093d09ed0a1d0a22d323031322d32353631143012060355040a0c0bd0a3d0a62031325f3235363114301206035504030c0bd0a3d0a62031325f323536311a301806082a85030381030101120c3132333435363738393031323118301606052a85036401120d313233343536373839303132333121301f06092a864886f70d010901161263615f31325f323536406c697373692e7275820900c6047cfc0235e1eb30170603551d110410300e810c6b657934406b6579342e727530090603551d1204023000300c06082a85030701010302050003410015e2ad073f8bddfb763e0b46a5c8c554c359e4b989899f56850571ff2f6c967c953c61ae3e1f3eac45228dbbf6a31f7de2de07306c2d2be704712182eed71e8c' print ('ImportCert') lobj = pyp11.listobjects (aa, 0, 'cert') if (len(lobj) == 0): print ('На токене нет объектов типа сертификатов (CKO_CERTIFICATE)') lcerts = pyp11.listcerts (aa, 0) print (lcerts) if (len(lcerts) == 0): print ('На токене нет сертификатов') pyp11.logout(aa, 0) ckaid = pyp11.importcert (aa, 0, cert_der_hex, "TEST_IMPORT") print ('ImportCert END') print (ckaid) print ('LISTCERTSDER START') lcerts = pyp11.listcerts (aa, 0) print (lcerts) if (len(lcerts) == 0):
print(e1) quit() print(bb) if bb != 1: quit() tobj = 'объект' type = 'all' #type = 'cert' #type = 'pubkey' #type = 'data' #type = 'privkey' if (type == 'cert'): tobj = 'сертификат' #Читаем объекты с токена lm = pyp11.listobjects(aa, 0, type, 'value') print('Работа с listobjects: ' + type) i = 0 for obj in lm: print(str(i) + '-ый ' + tobj) for key in obj.keys(): print('\t' + key + ': ' + obj[key]) i += 1 #lm = pyp11.listobjects(aa, 0, 'cert', 'value') #print('Работа с listobjects cert value:') lm = pyp11.listobjects(aa, 0, 'pubkey', 'value') print('Работа с listobjects pubkey value:') i = 0 for obj in lm: print(str(i) + '-ый объект') for key in obj.keys():