__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
# This file is part of paramiko.
#
# Paramiko is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
#
# Paramiko is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Paramiko; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import bcrypt
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.ciphers import Cipher
import nacl.signing
from paramiko.message import Message
from paramiko.pkey import PKey, OPENSSH_AUTH_MAGIC, _unpad_openssh
from paramiko.util import b
from paramiko.ssh_exception import SSHException, PasswordRequiredException
class Ed25519Key(PKey):
"""
Representation of an `Ed25519 <https://ed25519.cr.yp.to/>`_ key.
.. note::
Ed25519 key support was added to OpenSSH in version 6.5.
.. versionadded:: 2.2
.. versionchanged:: 2.3
Added a ``file_obj`` parameter to match other key classes.
"""
name = "ssh-ed25519"
@classmethod
def identifiers(cls):
return [cls.name, "[email protected]"]
def __init__(
self, msg=None, data=None, filename=None, password=None, file_obj=None
):
self.public_blob = None
verifying_key = signing_key = None
if msg is None and data is not None:
msg = Message(data)
if msg is not None:
self._check_type_and_load_cert(
msg=msg,
key_type=self.name,
cert_type="[email protected]",
)
verifying_key = nacl.signing.VerifyKey(msg.get_binary())
elif filename is not None:
with open(filename, "r") as f:
pkformat, data = self._read_private_key("OPENSSH", f)
elif file_obj is not None:
pkformat, data = self._read_private_key("OPENSSH", file_obj)
if filename or file_obj:
signing_key = self._parse_signing_key_data(data, password)
if signing_key is None and verifying_key is None:
raise ValueError("need a key")
self._signing_key = signing_key
self._verifying_key = verifying_key
def _parse_signing_key_data(self, data, password):
from paramiko.transport import Transport
# We may eventually want this to be usable for other key types, as
# OpenSSH moves to it, but for now this is just for Ed25519 keys.
# This format is described here:
# https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.key
# The description isn't totally complete, and I had to refer to the
# source for a full implementation.
message = Message(data)
if message.get_bytes(len(OPENSSH_AUTH_MAGIC)) != OPENSSH_AUTH_MAGIC:
raise SSHException("Invalid key")
ciphername = message.get_text()
kdfname = message.get_text()
kdfoptions = message.get_binary()
num_keys = message.get_int()
if kdfname == "none":
# kdfname of "none" must have an empty kdfoptions, the ciphername
# must be "none"
if kdfoptions or ciphername != "none":
raise SSHException("Invalid key")
elif kdfname == "bcrypt":
if not password:
raise PasswordRequiredException(
"Private key file is encrypted"
)
kdf = Message(kdfoptions)
bcrypt_salt = kdf.get_binary()
bcrypt_rounds = kdf.get_int()
else:
raise SSHException("Invalid key")
if ciphername != "none" and ciphername not in Transport._cipher_info:
raise SSHException("Invalid key")
public_keys = []
for _ in range(num_keys):
pubkey = Message(message.get_binary())
if pubkey.get_text() != self.name:
raise SSHException("Invalid key")
public_keys.append(pubkey.get_binary())
private_ciphertext = message.get_binary()
if ciphername == "none":
private_data = private_ciphertext
else:
cipher = Transport._cipher_info[ciphername]
key = bcrypt.kdf(
password=b(password),
salt=bcrypt_salt,
desired_key_bytes=cipher["key-size"] + cipher["block-size"],
rounds=bcrypt_rounds,
# We can't control how many rounds are on disk, so no sense
# warning about it.
ignore_few_rounds=True,
)
decryptor = Cipher(
cipher["class"](key[: cipher["key-size"]]),
cipher["mode"](key[cipher["key-size"] :]),
backend=default_backend(),
).decryptor()
private_data = (
decryptor.update(private_ciphertext) + decryptor.finalize()
)
message = Message(_unpad_openssh(private_data))
if message.get_int() != message.get_int():
raise SSHException("Invalid key")
signing_keys = []
for i in range(num_keys):
if message.get_text() != self.name:
raise SSHException("Invalid key")
# A copy of the public key, again, ignore.
public = message.get_binary()
key_data = message.get_binary()
# The second half of the key data is yet another copy of the public
# key...
signing_key = nacl.signing.SigningKey(key_data[:32])
# Verify that all the public keys are the same...
assert (
signing_key.verify_key.encode()
== public
== public_keys[i]
== key_data[32:]
)
signing_keys.append(signing_key)
# Comment, ignore.
message.get_binary()
if len(signing_keys) != 1:
raise SSHException("Invalid key")
return signing_keys[0]
def asbytes(self):
if self.can_sign():
v = self._signing_key.verify_key
else:
v = self._verifying_key
m = Message()
m.add_string(self.name)
m.add_string(v.encode())
return m.asbytes()
@property
def _fields(self):
if self.can_sign():
v = self._signing_key.verify_key
else:
v = self._verifying_key
return (self.get_name(), v)
# TODO 4.0: remove
def get_name(self):
return self.name
def get_bits(self):
return 256
def can_sign(self):
return self._signing_key is not None
def sign_ssh_data(self, data, algorithm=None):
m = Message()
m.add_string(self.name)
m.add_string(self._signing_key.sign(data).signature)
return m
def verify_ssh_sig(self, data, msg):
if msg.get_text() != self.name:
return False
try:
self._verifying_key.verify(data, msg.get_binary())
except nacl.exceptions.BadSignatureError:
return False
else:
return True
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| __pycache__ | Folder | 0755 |
|
|
| __init__.py | File | 4.34 KB | 0644 |
|
| _version.py | File | 80 B | 0644 |
|
| _winapi.py | File | 10.94 KB | 0644 |
|
| agent.py | File | 15.5 KB | 0644 |
|
| auth_handler.py | File | 42 KB | 0644 |
|
| auth_strategy.py | File | 11.17 KB | 0644 |
|
| ber.py | File | 4.27 KB | 0644 |
|
| buffered_pipe.py | File | 7.06 KB | 0644 |
|
| channel.py | File | 48.07 KB | 0644 |
|
| client.py | File | 33.68 KB | 0644 |
|
| common.py | File | 7.57 KB | 0644 |
|
| compress.py | File | 1.25 KB | 0644 |
|
| config.py | File | 26.72 KB | 0644 |
|
| dsskey.py | File | 8.05 KB | 0644 |
|
| ecdsakey.py | File | 11.38 KB | 0644 |
|
| ed25519key.py | File | 7.39 KB | 0644 |
|
| file.py | File | 18.62 KB | 0644 |
|
| hostkeys.py | File | 12.92 KB | 0644 |
|
| kex_curve25519.py | File | 4.44 KB | 0644 |
|
| kex_ecdh_nist.py | File | 4.89 KB | 0644 |
|
| kex_gex.py | File | 10.08 KB | 0644 |
|
| kex_group1.py | File | 5.61 KB | 0644 |
|
| kex_group14.py | File | 1.79 KB | 0644 |
|
| kex_group16.py | File | 2.23 KB | 0644 |
|
| kex_gss.py | File | 23.99 KB | 0644 |
|
| message.py | File | 9.13 KB | 0644 |
|
| packet.py | File | 23.74 KB | 0644 |
|
| pipe.py | File | 3.81 KB | 0644 |
|
| pkey.py | File | 35.99 KB | 0644 |
|
| primes.py | File | 4.99 KB | 0644 |
|
| proxy.py | File | 4.54 KB | 0644 |
|
| rsakey.py | File | 7.37 KB | 0644 |
|
| server.py | File | 29.74 KB | 0644 |
|
| sftp.py | File | 6.32 KB | 0644 |
|
| sftp_attr.py | File | 8.06 KB | 0644 |
|
| sftp_client.py | File | 35.01 KB | 0644 |
|
| sftp_file.py | File | 21.31 KB | 0644 |
|
| sftp_handle.py | File | 7.25 KB | 0644 |
|
| sftp_server.py | File | 19.04 KB | 0644 |
|
| sftp_si.py | File | 12.25 KB | 0644 |
|
| ssh_exception.py | File | 7.32 KB | 0644 |
|
| ssh_gss.py | File | 28.21 KB | 0644 |
|
| transport.py | File | 132.45 KB | 0644 |
|
| util.py | File | 9.33 KB | 0644 |
|
| win_openssh.py | File | 1.87 KB | 0644 |
|
| win_pageant.py | File | 4.08 KB | 0644 |
|