mirror of
https://github.com/romanz/amodem.git
synced 2026-04-20 21:26:39 +08:00
gpg: refactor sign_message method
This commit is contained in:
@@ -172,6 +172,23 @@ def create_subkey(primary_bytes, pubkey, signer_func, ecdh=False):
|
|||||||
return primary_bytes + subkey_packet + sign_packet
|
return primary_bytes + subkey_packet + sign_packet
|
||||||
|
|
||||||
|
|
||||||
|
def sign_message(signer_func, msg, pubkey, sign_time):
|
||||||
|
"""Sign GPG message at specified time."""
|
||||||
|
log.info('signing %d byte message at %s',
|
||||||
|
len(msg), _time_format(sign_time))
|
||||||
|
hashed_subpackets = [proto.subpacket_time(sign_time)]
|
||||||
|
unhashed_subpackets = [
|
||||||
|
proto.subpacket(16, pubkey.key_id())] # issuer key id
|
||||||
|
|
||||||
|
blob = proto.make_signature(
|
||||||
|
signer_func=signer_func,
|
||||||
|
data_to_sign=msg,
|
||||||
|
public_algo=pubkey.algo_id,
|
||||||
|
hashed_subpackets=hashed_subpackets,
|
||||||
|
unhashed_subpackets=unhashed_subpackets)
|
||||||
|
return proto.packet(tag=2, blob=blob)
|
||||||
|
|
||||||
|
|
||||||
class Factory(object):
|
class Factory(object):
|
||||||
"""Performs GPG signing operations."""
|
"""Performs GPG signing operations."""
|
||||||
|
|
||||||
@@ -217,20 +234,8 @@ class Factory(object):
|
|||||||
"""Sign GPG message at specified time."""
|
"""Sign GPG message at specified time."""
|
||||||
if sign_time is None:
|
if sign_time is None:
|
||||||
sign_time = int(time.time())
|
sign_time = int(time.time())
|
||||||
|
return sign_message(signer_func=self.conn.sign, pubkey=self.pubkey,
|
||||||
log.info('signing %d byte message at %s',
|
msg=msg, sign_time=sign_time)
|
||||||
len(msg), _time_format(sign_time))
|
|
||||||
hashed_subpackets = [proto.subpacket_time(sign_time)]
|
|
||||||
unhashed_subpackets = [
|
|
||||||
proto.subpacket(16, self.pubkey.key_id())] # issuer key id
|
|
||||||
|
|
||||||
blob = proto.make_signature(
|
|
||||||
signer_func=self.conn.sign,
|
|
||||||
data_to_sign=msg,
|
|
||||||
public_algo=self.pubkey.algo_id,
|
|
||||||
hashed_subpackets=hashed_subpackets,
|
|
||||||
unhashed_subpackets=unhashed_subpackets)
|
|
||||||
return proto.packet(tag=2, blob=blob)
|
|
||||||
|
|
||||||
def get_shared_secret(self, pubkey):
|
def get_shared_secret(self, pubkey):
|
||||||
"""Derive shared secret using ECDH from remote public key."""
|
"""Derive shared secret using ECDH from remote public key."""
|
||||||
|
|||||||
Reference in New Issue
Block a user