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 — Function
lib_version() -> VersionNumber
Get the version of the libssh library that's used.
LibSSH.get_hexa — Function
get_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 — Function
isavailable() -> 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 — Function
principal_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 — Function
message_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 — Function
message_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 — Function
message_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 — Type
primitive type HashType <: Enum{Int32} 32Enum for possible hash types to use to hash a public key:
HashType_Sha1HashType_Md5HashType_Sha256
LibSSH.PKI.KeyCmp — Type
primitive type KeyCmp <: Enum{Int32} 32Enum for ways to compare keys:
KeyCmp_PublicKeyCmp_Private
LibSSH.PKI.KeyType — Type
primitive type KeyType <: Enum{Int32} 32Enum for the types of keys that are supported:
KeyType_unknownKeyType_dssKeyType_rsaKeyType_rsa1KeyType_ecdsaKeyType_ed25519KeyType_dss_cert01KeyType_rsa_cert01KeyType_ecdsa_p256KeyType_ecdsa_p384KeyType_ecdsa_p521KeyType_ecdsa_p256_cert01KeyType_ecdsa_p384_cert01KeyType_ecdsa_p521_cert01KeyType_ed25519_cert01KeyType_sk_ecdsaKeyType_sk_ecdsa_cert01KeyType_sk_ed25519KeyType_sk_ed25519_cert01
LibSSH.PKI.SshKey — Type
mutable struct SshKeyptr::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 — Method
isassigned(key::LibSSH.PKI.SshKey) -> Bool
Check if the SshKey holds a valid pointer to a lib.ssh_key.
LibSSH.PKI.generate — Method
generate(
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 — Method
get_fingerprint_hash(key::LibSSH.PKI.SshKey) -> String
Get a fingerprint straight from a SshKey.
LibSSH.PKI.get_fingerprint_hash — Method
get_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 — Function
get_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.import_privkey_file — Method
import_privkey_file(
path::AbstractString;
passphrase
) -> LibSSH.PKI.SshKey
Import a private key from a file. Wrapper around lib.ssh_pki_import_privkey_file().
LibSSH.PKI.import_pubkey_file — Method
import_pubkey_file(
path::AbstractString
) -> LibSSH.PKI.SshKey
Import a public key from a file. Wrapper around lib.ssh_pki_import_pubkey_file().
LibSSH.PKI.key_cmp — Method
key_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 — Method
key_type(key::LibSSH.PKI.SshKey) -> LibSSH.PKI.KeyType
Wrapper around lib.ssh_key_type().