views:

43

answers:

0

Hi, I use PyMe to sign and verify messages. I have a problem setting a pass-phrase callback that will return a password for the private signature key whenever needed for signing. My code looks like this:

def passphrase_callback(hint='', desc='', prev_bad=''): return 'password'

class CryptoEngine: def init(self, user_id, passphrase): "Initialize with ID (e-mail)" self.user_id = user_id self.passphrase = passphrase def verify(self, data): c = core.Context() sig = core.Data(string = data) file = None plain = core.Data() c.op_verify(sig, file, plain) result = c.op_verify_result() plain.seek(0, 0) plaintext = plain.read() sig = result.signatures status = False for s in sig: status = (s.status == 0) return status, plaintext

def sign(self, data): c = core.Context() for sigkey in c.op_keylist_all(self.user_id, 1): if sigkey.can_sign: c.signers_add(sigkey) if not c.signers_enum(0): raise CryptoEngine.NoSignKeys("No secret %s's keys suitable for signing" % self.user_id)

plain = core.Data(data)
sig = core.Data()
c.set_passphrase_cb(passphrase_callback)
c.op_sign(plain, sig, mode.CLEAR)
sig.seek(0, 0)
return sig.read()

Despite setting the passphrase callback I still either get a message box asking for the pass-phrase or just an exception notifying of a bad password. Did someone solve this problem and could share his knowledge? Thanks, Yan