本文整理汇总了Python中paramiko.rsakey.RSAKey.generate方法的典型用法代码示例。如果您正苦于以下问题:Python RSAKey.generate方法的具体用法?Python RSAKey.generate怎么用?Python RSAKey.generate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类paramiko.rsakey.RSAKey
的用法示例。
在下文中一共展示了RSAKey.generate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_two_phase_renewal_stop
# 需要导入模块: from paramiko.rsakey import RSAKey [as 别名]
# 或者: from paramiko.rsakey.RSAKey import generate [as 别名]
def test_two_phase_renewal_stop(fx_authorized_servers, fx_master_key):
remote_set = {
Remote('user', '127.0.0.1', port)
for port in fx_authorized_servers
}
old_key = fx_master_key
new_key = RSAKey.generate(1024)
for t, path, ev in fx_authorized_servers.values():
assert authorized_key_set(path) == {old_key}
SomeException = type('SomeException', (Exception,), {})
with raises(SomeException):
with TwoPhaseRenewal(remote_set, old_key, new_key):
for t, path, ev in fx_authorized_servers.values():
assert authorized_key_set(path) == {old_key, new_key}
raise SomeException('something went wrong')
for t, path, ev in fx_authorized_servers.values():
assert old_key in authorized_key_set(path)
示例2: test_cloud_master_key_store
# 需要导入模块: from paramiko.rsakey import RSAKey [as 别名]
# 或者: from paramiko.rsakey.RSAKey import generate [as 别名]
def test_cloud_master_key_store():
driver = DummyStorageDriver('', '')
container = driver.create_container('geofront-test')
s = CloudMasterKeyStore(driver, container, 'test_id_rsa')
with raises(EmptyStoreError):
s.load()
key = RSAKey.generate(1024)
s.save(key)
driver.get_object(container.name, 'test_id_rsa') # assert object exists
# Mocking implementation
with io.StringIO() as mock:
key.write_private_key(mock)
mock.seek(0)
dummy.DummyFileObject = lambda *a, **k: mock
stored_key = s.load()
assert isinstance(stored_key, RSAKey)
assert stored_key.get_base64() == stored_key.get_base64()
示例3: assert_keystore_compliance
# 需要导入模块: from paramiko.rsakey import RSAKey [as 别名]
# 或者: from paramiko.rsakey.RSAKey import generate [as 别名]
def assert_keystore_compliance(keystore, identity):
"""Test basic behaviors of a KeyStore implementation."""
# "List registered public keys of the given ``identity``."
keys = keystore.list_keys(identity)
assert isinstance(keys, collections.abc.Set)
assert not keys
# "Register the given ``public_key`` to the ``identity``."
key = RSAKey.generate(1024)
keystore.register(identity, key)
keys = keystore.list_keys(identity)
assert isinstance(keys, collections.abc.Set)
assert keys == {key}
# ":raise geofront.keystore.DuplicatePublicKeyError:
# when the ``public_key`` is already in use"
with raises(DuplicatePublicKeyError):
keystore.register(identity, key)
# "Remove the given ``public_key`` of the ``identity``."
keystore.deregister(identity, key)
keys = keystore.list_keys(identity)
assert isinstance(keys, collections.abc.Set)
assert not keys
# "It silently does nothing if there isn't the given ``public_key``
# in the store."
keystore.deregister(identity, key)
示例4: test_list_public_keys
# 需要导入模块: from paramiko.rsakey import RSAKey [as 别名]
# 或者: from paramiko.rsakey.RSAKey import generate [as 别名]
def test_list_public_keys(fx_app, fx_key_store,
fx_authorized_identity,
fx_token_id):
with fx_app.test_client() as c:
response = c.get(get_url('list_public_keys', token_id=fx_token_id))
assert response.status_code == 200
assert response.mimetype == 'application/json'
assert response.get_data() == b'{}'
key = RSAKey.generate(1024)
fx_key_store.register(fx_authorized_identity, key)
with fx_app.test_client() as c:
response = c.get(get_url('list_public_keys', token_id=fx_token_id))
assert response.status_code == 200
assert response.mimetype == 'application/json'
data = {f: parse_openssh_pubkey(k)
for f, k in json.loads(response.get_data()).items()}
assert data == {get_key_fingerprint(key): key}
示例5: _get_key_name_pattern
# 需要导入模块: from paramiko.rsakey import RSAKey [as 别名]
# 或者: from paramiko.rsakey.RSAKey import generate [as 别名]
def _get_key_name_pattern(self,
identity: Identity) -> Pattern[str]:
"""Make the regex pattern from the format string. Put two different
random keys, compare two outputs, and then replace the difference
with wildcard.
"""
cls = type(self)
sample_keys = cls._sample_keys
if sample_keys is None:
sample_keys = (RSAKey.generate(bits=512),
RSAKey.generate(bits=512),
ECDSAKey.generate(bits=256),
ECDSAKey.generate(bits=256))
cls._sample_keys = sample_keys
sample_names = [self._get_key_name(identity, k) for k in sample_keys]
if len(frozenset(sample_names)) < 2:
return re.compile('^' + re.escape(sample_names[0]) + '$')
prefix = os.path.commonprefix(sample_names)
postfix = os.path.commonprefix([n[::-1] for n in sample_names])[::-1]
return re.compile(
'^{}.+?{}$'.format(re.escape(prefix), re.escape(postfix))
)
示例6: test_fs_master_key_store_save
# 需要导入模块: from paramiko.rsakey import RSAKey [as 别名]
# 或者: from paramiko.rsakey.RSAKey import generate [as 别名]
def test_fs_master_key_store_save(tmpdir):
path = tmpdir.join('id_rsa')
s = FileSystemMasterKeyStore(str(path))
with raises(EmptyStoreError):
s.load()
key = RSAKey.generate(1024)
s.save(key)
stored_key = s.load()
assert isinstance(stored_key, RSAKey)
assert stored_key.get_base64() == stored_key.get_base64()
示例7: test_two_phase_renewal
# 需要导入模块: from paramiko.rsakey import RSAKey [as 别名]
# 或者: from paramiko.rsakey.RSAKey import generate [as 别名]
def test_two_phase_renewal(fx_authorized_servers, fx_master_key):
remote_set = {
Remote('user', '127.0.0.1', port)
for port in fx_authorized_servers
}
old_key = fx_master_key
new_key = RSAKey.generate(1024)
for t, path, ev in fx_authorized_servers.values():
assert authorized_key_set(path) == {old_key}
with TwoPhaseRenewal(remote_set, old_key, new_key):
for t, path, ev in fx_authorized_servers.values():
assert authorized_key_set(path) == {old_key, new_key}
for t, path, ev in fx_authorized_servers.values():
assert authorized_key_set(path) == {new_key}
示例8: test_authorized_keys_list_insert
# 需要导入模块: from paramiko.rsakey import RSAKey [as 别名]
# 或者: from paramiko.rsakey.RSAKey import generate [as 别名]
def test_authorized_keys_list_insert(fx_authorized_sftp):
sftp_client, path, keys = fx_authorized_sftp
key_list = AuthorizedKeyList(sftp_client)
new_key = RSAKey.generate(1024)
key_list.insert(2, new_key)
with path.join('.ssh', 'authorized_keys').open() as f:
assert parse_openssh_pubkey(get_next_line(f)) == keys[0]
assert parse_openssh_pubkey(get_next_line(f)) == keys[1]
assert parse_openssh_pubkey(get_next_line(f)) == new_key
for i in range(2, 6):
assert parse_openssh_pubkey(get_next_line(f)) == keys[i]
assert not get_next_line(f)
示例9: test_authorized_keys_list_extend
# 需要导入模块: from paramiko.rsakey import RSAKey [as 别名]
# 或者: from paramiko.rsakey.RSAKey import generate [as 别名]
def test_authorized_keys_list_extend(fx_authorized_sftp):
sftp_client, path, keys = fx_authorized_sftp
key_list = AuthorizedKeyList(sftp_client)
new_keys = [RSAKey.generate(1024) for _ in range(3)]
key_list.extend(new_keys)
with path.join('.ssh', 'authorized_keys').open() as f:
for i in range(6):
assert parse_openssh_pubkey(get_next_line(f)) == keys[i]
for i in range(3):
assert parse_openssh_pubkey(get_next_line(f)) == new_keys[i]
assert not get_next_line(f)
示例10: fx_authorized_keys
# 需要导入模块: from paramiko.rsakey import RSAKey [as 别名]
# 或者: from paramiko.rsakey.RSAKey import generate [as 别名]
def fx_authorized_keys():
return [RSAKey.generate(1024) for _ in range(5)]
示例11: fx_authorized_sftp
# 需要导入模块: from paramiko.rsakey import RSAKey [as 别名]
# 或者: from paramiko.rsakey.RSAKey import generate [as 别名]
def fx_authorized_sftp(fx_sftpd, fx_authorized_keys):
port, (thread, path, ev) = fx_sftpd.popitem()
thread.start()
key = RSAKey.generate(1024)
dot_ssh = path.mkdir('.ssh')
with dot_ssh.join('authorized_keys').open('w') as f:
print(format_openssh_pubkey(key), file=f)
for authorized_key in fx_authorized_keys:
print(format_openssh_pubkey(authorized_key), file=f)
transport = Transport(('127.0.0.1', port))
transport.connect(username='user', pkey=key)
sftp_client = SFTPClient.from_transport(transport)
yield sftp_client, path, [key] + fx_authorized_keys
sftp_client.close()
transport.close()
示例12: fx_master_key
# 需要导入模块: from paramiko.rsakey import RSAKey [as 别名]
# 或者: from paramiko.rsakey.RSAKey import generate [as 别名]
def fx_master_key():
return RSAKey.generate(1024)
示例13: test_cloud_master_key_store_s3
# 需要导入模块: from paramiko.rsakey import RSAKey [as 别名]
# 或者: from paramiko.rsakey.RSAKey import generate [as 别名]
def test_cloud_master_key_store_s3(request, tmpdir):
try:
access_key = request.config.getoption('--aws-access-key')
secret_key = request.config.getoption('--aws-secret-key')
bucket_name = request.config.getoption('--aws-s3-bucket')
except ValueError:
access_key = secret_key = bucket_name = None
if access_key is None or secret_key is None or bucket_name is None:
skip(
'--aws-access-key/--aws-secret-key/--aws-s3-bucket are not '
'provided; skipped'
)
driver_cls = get_driver(Provider.S3)
driver = driver_cls(access_key, secret_key)
container = driver.get_container(container_name=bucket_name)
tmpname = ''.join(map('{:02x}'.format, os.urandom(16)))
s = CloudMasterKeyStore(driver, container, tmpname)
key = RSAKey.generate(1024)
# load() -- when not exists
with raises(EmptyStoreError):
s.load()
try:
# save()
s.save(key)
obj = driver.get_object(container.name, tmpname)
dest = tmpdir / tmpname
obj.download(str(dest))
saved = read_private_key_file(dest.open())
assert isinstance(saved, RSAKey)
assert saved.get_base64() == key.get_base64()
# load() -- when exists
loaded = s.load()
assert isinstance(loaded, RSAKey)
assert loaded.get_base64() == key.get_base64()
finally:
try:
o = driver.get_object(container.name, tmpname)
except ObjectDoesNotExistError:
pass
else:
o.delete()
示例14: test_cloud_master_public_key_store
# 需要导入模块: from paramiko.rsakey import RSAKey [as 别名]
# 或者: from paramiko.rsakey.RSAKey import generate [as 别名]
def test_cloud_master_public_key_store():
driver = KeyPairSupportedDummyNodeDriver('')
actual_store = MemoryMasterKeyStore()
store = CloudMasterPublicKeyStore(driver,
'geofront-masterkey',
actual_store)
for _ in range(2):
master_key = RSAKey.generate(1024)
store.save(master_key)
assert actual_store.load() == store.load() == master_key
assert parse_openssh_pubkey(
driver.get_key_pair('geofront-masterkey').public_key
) == master_key
示例15: start_server
# 需要导入模块: from paramiko.rsakey import RSAKey [as 别名]
# 或者: from paramiko.rsakey.RSAKey import generate [as 别名]
def start_server(path: str, host: str, port: int, terminated: threading.Event):
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.settimeout(1)
server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
server_socket.bind((host, port))
server_socket.listen(1)
stub_cls = type('StubSFTPServer', (StubSFTPServer,), {'ROOT': path})
host_key = RSAKey.generate(1024)
def accept(server_socket, mask):
conn, addr = server_socket.accept()
transport = Transport(conn)
transport.add_server_key(host_key)
transport.set_subsystem_handler('sftp', SFTPServer, stub_cls)
server = StubServer(path)
transport.start_server(server=server)
while not terminated.is_set():
channel = transport.accept(1)
if channel is not None and not terminated.is_set():
while transport.is_active() and not terminated.is_set():
terminated.wait(1)
break
sel = selectors.DefaultSelector()
sel.register(server_socket, selectors.EVENT_READ, accept)
last_used = time.time()
while not terminated.is_set() and last_used + 10 > time.time():
events = sel.select(1)
for key, mask in events:
key.data(key.fileobj, mask)
last_used = time.time()