本文整理汇总了Python中paramiko.Message.add_byte方法的典型用法代码示例。如果您正苦于以下问题:Python Message.add_byte方法的具体用法?Python Message.add_byte怎么用?Python Message.add_byte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类paramiko.Message
的用法示例。
在下文中一共展示了Message.add_byte方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_1_write
# 需要导入模块: from paramiko import Message [as 别名]
# 或者: from paramiko.Message import add_byte [as 别名]
def test_1_write(self):
rsock = LoopSocket()
wsock = LoopSocket()
rsock.link(wsock)
p = Packetizer(wsock)
p.set_log(util.get_logger("paramiko.transport"))
p.set_hexdump(True)
encryptor = Cipher(
algorithms.AES(zero_byte * 16),
modes.CBC(x55 * 16),
backend=default_backend(),
).encryptor()
p.set_outbound_cipher(encryptor, 16, sha1, 12, x1f * 20)
# message has to be at least 16 bytes long, so we'll have at least one
# block of data encrypted that contains zero random padding bytes
m = Message()
m.add_byte(byte_chr(100))
m.add_int(100)
m.add_int(1)
m.add_int(900)
p.send_message(m)
data = rsock.recv(100)
# 32 + 12 bytes of MAC = 44
self.assertEqual(44, len(data))
self.assertEqual(
b"\x43\x91\x97\xbd\x5b\x50\xac\x25\x87\xc2\xc4\x6b\xc7\xe9\x38\xc0",
data[:16],
)
示例2: test_1_write
# 需要导入模块: from paramiko import Message [as 别名]
# 或者: from paramiko.Message import add_byte [as 别名]
def test_1_write(self):
rsock = LoopSocket()
wsock = LoopSocket()
rsock.link(wsock)
p = Packetizer(wsock)
p.set_log(util.get_logger("paramiko.transport"))
p.set_hexdump(True)
cipher = AES.new(b"\x00" * 16, AES.MODE_CBC, b"\x55" * 16)
p.set_outbound_cipher(cipher, 16, SHA, 12, b"\x1f" * 20)
# message has to be at least 16 bytes long, so we'll have at least one
# block of data encrypted that contains zero random padding bytes
m = Message()
m.add_byte(chr(100).encode())
m.add_int(100)
m.add_int(1)
m.add_int(900)
p.send_message(m)
data = rsock.recv(100)
# 32 + 12 bytes of MAC = 44
self.assertEquals(44, len(data))
self.assertEquals(b"\x43\x91\x97\xbd\x5b\x50\xac\x25\x87\xc2\xc4\x6b\xc7\xe9\x38\xc0", data[:16])
示例3: test_3_closed
# 需要导入模块: from paramiko import Message [as 别名]
# 或者: from paramiko.Message import add_byte [as 别名]
def test_3_closed(self):
if sys.platform.startswith("win"): # no SIGALRM on windows
return
rsock = LoopSocket()
wsock = LoopSocket()
rsock.link(wsock)
p = Packetizer(wsock)
p.set_log(util.get_logger("paramiko.transport"))
p.set_hexdump(True)
encryptor = Cipher(
algorithms.AES(zero_byte * 16),
modes.CBC(x55 * 16),
backend=default_backend(),
).encryptor()
p.set_outbound_cipher(encryptor, 16, sha1, 12, x1f * 20)
# message has to be at least 16 bytes long, so we'll have at least one
# block of data encrypted that contains zero random padding bytes
m = Message()
m.add_byte(byte_chr(100))
m.add_int(100)
m.add_int(1)
m.add_int(900)
wsock.send = lambda x: 0
from functools import wraps
import errno
import os
import signal
class TimeoutError(Exception):
def __init__(self, error_message):
if hasattr(errno, "ETIME"):
self.message = os.sterror(errno.ETIME)
else:
self.messaage = error_message
def timeout(seconds=1, error_message="Timer expired"):
def decorator(func):
def _handle_timeout(signum, frame):
raise TimeoutError(error_message)
def wrapper(*args, **kwargs):
signal.signal(signal.SIGALRM, _handle_timeout)
signal.alarm(seconds)
try:
result = func(*args, **kwargs)
finally:
signal.alarm(0)
return result
return wraps(func)(wrapper)
return decorator
send = timeout()(p.send_message)
self.assertRaises(EOFError, send, m)
示例4: test_3_closed
# 需要导入模块: from paramiko import Message [as 别名]
# 或者: from paramiko.Message import add_byte [as 别名]
def test_3_closed(self):
rsock = LoopSocket()
wsock = LoopSocket()
rsock.link(wsock)
p = Packetizer(wsock)
p.set_log(util.get_logger('paramiko.transport'))
p.set_hexdump(True)
cipher = AES.new(zero_byte * 16, AES.MODE_CBC, x55 * 16)
p.set_outbound_cipher(cipher, 16, sha1, 12, x1f * 20)
# message has to be at least 16 bytes long, so we'll have at least one
# block of data encrypted that contains zero random padding bytes
m = Message()
m.add_byte(byte_chr(100))
m.add_int(100)
m.add_int(1)
m.add_int(900)
wsock.send = lambda x: 0
from functools import wraps
import errno
import os
import signal
class TimeoutError(Exception):
pass
def timeout(seconds=1, error_message=os.strerror(errno.ETIME)):
def decorator(func):
def _handle_timeout(signum, frame):
raise TimeoutError(error_message)
def wrapper(*args, **kwargs):
signal.signal(signal.SIGALRM, _handle_timeout)
signal.alarm(seconds)
try:
result = func(*args, **kwargs)
finally:
signal.alarm(0)
return result
return wraps(func)(wrapper)
return decorator
send = timeout()(p.send_message)
self.assertRaises(EOFError, send, m)
示例5: playbook_on_play_start
# 需要导入模块: from paramiko import Message [as 别名]
# 或者: from paramiko.Message import add_byte [as 别名]
def playbook_on_play_start(self, name):
play_vars = merge_hash(self.play.vars,
getattr(self.play, 'vars_file_vars', {}))
play_vars = merge_hash(play_vars,
getattr(self.playbook, 'extra_vars', {}))
pem = play_vars.get('creds_ssh_private_key', None)
if pem is None: return
key = RSAKey.from_private_key(StringIO.StringIO(pem))
hexdigest = unpack('16B', key.get_fingerprint())
hexdigest = ':'.join(['%02x' % x for x in hexdigest])
display('Loading SSH private key %s' % hexdigest)
pub = '%s %s %s' % (key.get_name(), key.get_base64(), self.KEY_COMMENT)
for x in self.play.tasks() + self.play.handlers():
y = getattr(x, 'module_vars', None)
if y: y['creds_ssh_public_key'] = pub
ssh_agent = play_vars.get('creds_ssh_agent', True)
if not ssh_agent: return
msg = Message()
msg.add_byte(chr(self.SSH2_AGENTC_ADD_IDENTITY))
msg.add_string(key.get_name())
msg.add_mpint(key.n)
msg.add_mpint(key.e)
msg.add_mpint(key.d)
msg.add_mpint(0)
msg.add_mpint(key.p)
msg.add_mpint(key.q)
msg.add_string(self.KEY_COMMENT)
agent = Agent()
if agent._conn:
agent._send_message(msg)
else:
warning('Failed to connect to ssh-agent')
agent.close()