Utilities
The symbols documented on this page are intended to be safe. They may throw exceptions but they should never cause memory corruptions or segfaults if used correctly.
This documents the various other parts of the libssh API that aren't strictly connected to client or server support.
LibSSH.lib_version
— Functionlib_version() -> VersionNumber
Get the version of the libssh library that's used.
LibSSH.get_hexa
— Functionget_hexa(buffer::Vector{UInt8}) -> String
Convert a buffer to a colon-separated hex string. This is identical to bytes2hex()
, except that each byte will be separated by a colon.
Wrapper around lib.ssh_get_hexa()
.
Examples
julia> import LibSSH as ssh
julia> buffer = collect(UInt8, 1:10);
julia> ssh.get_hexa(buffer)
"01:02:03:04:05:06:07:08:09:0a"
julia> bytes2hex(buffer)
"0102030405060708090a"
GSSAPI support
LibSSH.Gssapi.isavailable
— Functionisavailable() -> Bool
Check if GSSAPI support is available. Currently this is only available on Linux and FreeBSD because it's difficult to cross-compile Kerberos_krb5_jll
for other platforms (which is what we depend on for GSSAPI).
LibSSH.Gssapi.principal_name
— Functionprincipal_name() -> Union{Nothing, String}
Returns the name of the default principal from the default credential cache, or nothing
if a principal with a valid ticket was not found. This can be used to check if ssh.userauth_gssapi()
can be called. Under the hood it uses:
Throws
ErrorException
: If GSSAPI support is not available on the current platform (seeisavailable()
).
Messages
LibSSH.message_type
— Functionmessage_type(
message::Ptr{LibSSH.lib.ssh_message_struct}
) -> LibSSH.RequestType
Get the type of a message. Wrapper around lib.ssh_message_type()
.
LibSSH.message_subtype
— Functionmessage_subtype(
message::Ptr{LibSSH.lib.ssh_message_struct}
) -> Int32
Get the subtype of a message. Wrapper around lib.ssh_message_subtype()
.
LibSSH.message_auth_interactive_request
— Functionmessage_auth_interactive_request(
msg::Ptr{LibSSH.lib.ssh_message_struct},
name::AbstractString,
instruction::AbstractString,
prompts::Vector{String},
echo::Vector{Bool}
) -> Int32
This is useful when writing a server, it will specify the requirements for keyboard-interactive authentication to the client.
Parameters
msg
: The message to reply to.name
: The name of the message block.instruction
: The instruction for the user.prompts
: The prompts to show to the user.echo
: Whether the client should echo the answer to the prompts (e.g. it probably shouldn't echo the password).
Wrapper around lib.ssh_message_auth_interactive_request()
.
PKI
LibSSH.PKI.HashType
— Typeprimitive type HashType <: Enum{Int32} 32
Enum for possible hash types to use to hash a public key:
HashType_Sha1
HashType_Md5
HashType_Sha256
LibSSH.PKI.KeyCmp
— Typeprimitive type KeyCmp <: Enum{Int32} 32
Enum for ways to compare keys:
KeyCmp_Public
KeyCmp_Private
LibSSH.PKI.KeyType
— Typeprimitive type KeyType <: Enum{Int32} 32
Enum for the types of keys that are supported:
KeyType_unknown
KeyType_dss
KeyType_rsa
KeyType_rsa1
KeyType_ecdsa
KeyType_ed25519
KeyType_dss_cert01
KeyType_rsa_cert01
KeyType_ecdsa_p256
KeyType_ecdsa_p384
KeyType_ecdsa_p521
KeyType_ecdsa_p256_cert01
KeyType_ecdsa_p384_cert01
KeyType_ecdsa_p521_cert01
KeyType_ed25519_cert01
KeyType_sk_ecdsa
KeyType_sk_ecdsa_cert01
KeyType_sk_ed25519
KeyType_sk_ed25519_cert01
LibSSH.PKI.SshKey
— Typemutable struct SshKey
ptr::Union{Nothing, Ptr{LibSSH.lib.ssh_key_struct}}
owning::Bool
Use PKI.generate
to create a key rather than calling the constructors. A SshKey
can be owning or non-owning of its pointer to the lib.ssh_key
.
Adding a SshKey
to a ssh.Bind
will cause the key to be free'd when the ssh.Bind
is closed! Never use a SshKey
after its server has been closed, or make sure it hasn't been free'd by checking isassigned(::SshKey)
.
Base.isassigned
— Methodisassigned(key::LibSSH.PKI.SshKey) -> Bool
Check if the SshKey
holds a valid pointer to a lib.ssh_key
.
LibSSH.PKI.generate
— Methodgenerate(
ktype::LibSSH.PKI.KeyType;
bits
) -> LibSSH.PKI.SshKey
Wrapper around lib.ssh_pki_generate()
. Note that bits=2048
by default.
LibSSH.PKI.get_fingerprint_hash
— Methodget_fingerprint_hash(key::LibSSH.PKI.SshKey) -> String
Get a fingerprint straight from a SshKey
.
LibSSH.PKI.get_fingerprint_hash
— Methodget_fingerprint_hash(hash_buffer::Vector{UInt8}) -> String
Get a fingerprint of a public key from a hash. This will automatically guess the kind of hash that was used from the length of hash_buffer
.
Wrapper around lib.ssh_get_fingerprint_hash()
.
Examples
julia> import LibSSH.PKI as pki
julia> key = pki.generate(pki.KeyType_ed25519)
julia> sha256_hash = pki.get_publickey_hash(key)
julia> pki.get_fingerprint_hash(sha256_hash)
"SHA256:5muLWD4Cl6FYh5ZRr/DYKvmb5r+kJUZQXLuc6ocVRH0"
LibSSH.PKI.get_publickey_hash
— Functionget_publickey_hash(key::LibSSH.PKI.SshKey) -> Vector{UInt8}
get_publickey_hash(
key::LibSSH.PKI.SshKey,
hash_type::LibSSH.PKI.HashType
) -> Vector{UInt8}
Get the hash of the public key of a SshKey
(SHA256 by default).
Wrapper around lib.ssh_get_publickey_hash()
.
LibSSH.PKI.key_cmp
— Methodkey_cmp(
key1::LibSSH.PKI.SshKey,
key2::LibSSH.PKI.SshKey,
part::LibSSH.PKI.KeyCmp
) -> Bool
Compare parts of an SSH key. Wrapper around lib.ssh_key_cmp()
.
LibSSH.PKI.key_type
— Methodkey_type(key::LibSSH.PKI.SshKey) -> LibSSH.PKI.KeyType
Wrapper around lib.ssh_key_type()
.