Skip to content

Commit a5cf518

Browse files
author
Tui
committed
update libssh2 binding to version 1.11.1
- Add new crypto engine types and security key functionality - Add new error codes and host key types - Add session timeout and crypto engine methods - Update type names to match upstream conventions - Deprecate session_callback_set in favor of session_callback_set2 - Add documentation for new security key functions - Bump package version to 0.1.9
1 parent 2ca9128 commit a5cf518

File tree

2 files changed

+97
-8
lines changed

2 files changed

+97
-8
lines changed

libssh2.nim

Lines changed: 96 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ type
3939
PollFd* = ptr SSH2Struct
4040
PublicKey* = ptr SSH2Struct
4141

42+
CryptoEngine* = enum
43+
CRYPTO_ENGINE_NONE
44+
CRYPTO_ENGINE_OPENSSL
45+
CRYPTO_ENGINE_GCRYPT
46+
CRYPTO_ENGINE_MBEDTLS
47+
CRYPTO_ENGINE_WINCNG
48+
CRYPTO_ENGINE_OS400QC3
49+
4250
Sftp* = ptr SSH2Struct
4351
SftpHandle* = ptr SSH2Struct
4452

@@ -85,10 +93,34 @@ type
8593
blobLen*: culong
8694
attrs*: publickey_attribute_st
8795

88-
passwd_changereq_func* = proc(session: Session, newpw: ptr cstring, newpwLen: int, abstract: pointer) {.cdecl.}
89-
96+
PASSWD_CHANGEREQ_FUNC* = proc(session: Session, newpw: ptr cstring, newpwLen: int, abstract: pointer) {.cdecl.}
97+
98+
USERAUTH_SK_SIGN_FUNC* = proc (session: Session, sig: ptr SK_SIG_INFO, data: cstring, data_len: csize_t, abstract: pointer) {.cdecl.}
99+
## Callback function type for security key signing operations
100+
101+
SK_SIG_INFO* {.final, pure.} = object
102+
## Security Key signature information structure
103+
flags*: uint8 ## Flags indicating signature properties
104+
counter*: uint32 ## Operation counter
105+
sig_r*: cstring ## R component of the signature
106+
sig_r_len*: csize_t ## Length of R component
107+
sig_s*: cstring ## S component of the signature
108+
sig_s_len*: csize_t ## Length of S component
109+
110+
PRIVKEY_SK* {.final, pure.} = object
111+
## Security Key private key structure
112+
algorithm*: cstring ## Name of the algorithm
113+
flags*: uint8 ## Key flags
114+
application*: cstring ## Application identifier
115+
key_handle*: cstring ## Handle to the key
116+
key_handle_len*: csize_t ## Length of the key handle
117+
reserved*: array[7, uint8] ## Reserved for future use
90118

91119
const
120+
LIBSSH2_VERSION* = "1.11.1"
121+
LIBSSH2_VERSION_MAJOR* = 1
122+
LIBSSH2_VERSION_MINOR* = 11
123+
LIBSSH2_VERSION_PATCH* = 1
92124
LIBSSH2_INVALID_SOCKET* = -1
93125
LIBSSH2_DH_GEX_MINGROUP* = 1024
94126
LIBSSH2_DH_GEX_OPTGROUP* = 1536
@@ -137,11 +169,19 @@ const
137169
LIBSSH2_POLLFD_LISTENER_CLOSED* = 0x0080
138170
LIBSSH2_SESSION_BLOCK_INBOUND* = 0x0001
139171
LIBSSH2_SESSION_BLOCK_OUTBOUND* = 0x0002
172+
LIBSSH2_SK_PRESENCE_REQUIRED* = 0x01
173+
LIBSSH2_SK_VERIFICATION_REQUIRED* = 0x04
174+
LIBSSH2_VERSION_NUM* = 0x010b01
140175
LIBSSH2_HOSTKEY_HASH_MD5* = 1
141176
LIBSSH2_HOSTKEY_HASH_SHA1* = 2
177+
LIBSSH2_HOSTKEY_HASH_SHA256* = 3
142178
LIBSSH2_HOSTKEY_TYPE_UNKNOWN* = 0
143179
LIBSSH2_HOSTKEY_TYPE_RSA* = 1
144180
LIBSSH2_HOSTKEY_TYPE_DSS* = 2
181+
LIBSSH2_HOSTKEY_TYPE_ECDSA_256* = 3
182+
LIBSSH2_HOSTKEY_TYPE_ECDSA_384* = 4
183+
LIBSSH2_HOSTKEY_TYPE_ECDSA_521* = 5
184+
LIBSSH2_HOSTKEY_TYPE_ED25519* = 6
145185
LIBSSH2_ERROR_NONE* = 0
146186
LIBSSH2_ERROR_SOCKET_NONE* = -1
147187
LIBSSH2_ERROR_BANNER_RECV* = -2
@@ -190,6 +230,14 @@ const
190230
LIBSSH2_ERROR_ENCRYPT* = -44
191231
LIBSSH2_ERROR_BAD_SOCKET* = -45
192232
LIBSSH2_ERROR_KNOWN_HOSTS* = -46
233+
LIBSSH2_ERROR_CHANNEL_WINDOW_FULL* = -47
234+
LIBSSH2_ERROR_KEYFILE_AUTH_FAILED* = -48
235+
LIBSSH2_ERROR_RANDGEN* = -49
236+
LIBSSH2_ERROR_MISSING_USERAUTH_BANNER* = -50
237+
LIBSSH2_ERROR_ALGO_UNSUPPORTED* = -51
238+
LIBSSH2_ERROR_MAC_FAILURE* = -52
239+
LIBSSH2_ERROR_HASH_INIT* = -53
240+
LIBSSH2_ERROR_HASH_CALC* = -54
193241
LIBSSH2_ERROR_BANNER_NONE* = LIBSSH2_ERROR_BANNER_RECV
194242
LIBSSH2_INIT_NO_CRYPTO* = 0x0001
195243
LIBSSH2_CHANNEL_WINDOW_DEFAULT* = (2*1024*1024)
@@ -545,7 +593,7 @@ proc session_banner_set*(s: Session, banner: cstring): cint {.ssh2.}
545593

546594
proc session_block_directions*(s: Session): cint {.ssh2.}
547595

548-
proc session_callback_set*(s: Session, cbtype: int, f: pointer) {.ssh2.}
596+
proc session_callback_set*(s: Session, cbtype: int, f: pointer) {.ssh2, deprecated: "Use session_callback_set2 instead".}
549597

550598
proc session_disconnect_ex*(s: Session, reason: int, description, lang: cstring): cint {.ssh2.}
551599

@@ -589,6 +637,22 @@ proc session_startup*(s: Session, socket: int): cint {.ssh2.}
589637

590638
proc session_supported_algs*(s: Session, methodType: int, algs: var cstring) {.ssh2.}
591639

640+
proc session_set_read_timeout*(s: Session, timeout: cint) {.ssh2.}
641+
## Set the read timeout for the session. A timeout of 0 disables timeouts.
642+
## Timeout is in milliseconds.
643+
644+
proc session_get_read_timeout*(s: Session): cint {.ssh2.}
645+
## Get the current read timeout for the session.
646+
## Returns the timeout in milliseconds, or 0 if timeouts are disabled.
647+
648+
proc session_callback_set2*(s: Session, cbtype: int, callback: pointer): pointer {.ssh2.}
649+
## Set or get a callback function for the specified callback type.
650+
## Returns the previous callback function or nil.
651+
652+
proc crypto_engine*(s: Session): CryptoEngine {.ssh2.}
653+
## Get the crypto engine being used by the session.
654+
## Returns the crypto engine type.
655+
592656
proc sftp_close_handle*(h: SftpHandle): cint {.ssh2.}
593657

594658
proc sftp_close*(h: SftpHandle): cint {.inline.} =
@@ -710,9 +774,9 @@ proc userauth_keyboard_interactive*(s: Session, uname: cstring, cb: Function): c
710774

711775
proc userauth_list*(s: Session, username: cstring, usernameLen: int): cstring {.ssh2.}
712776

713-
proc userauth_password_ex*(s: Session, uname: cstring, unameLen: uint, password: cstring, passwordLen: uint, cb: passwd_changereq_func): cint {.ssh2.}
777+
proc userauth_password_ex*(s: Session, uname: cstring, unameLen: uint, password: cstring, passwordLen: uint, cb: PASSWD_CHANGEREQ_FUNC): cint {.ssh2.}
714778

715-
proc userauth_password*(s: Session, uname: cstring, password: cstring, cb: passwd_changereq_func): cint {.inline.} =
779+
proc userauth_password*(s: Session, uname: cstring, password: cstring, cb: PASSWD_CHANGEREQ_FUNC): cint {.inline.} =
716780
userauth_password_ex(s, uname, uname.len.uint, password, password.len.uint, cb)
717781

718782
proc userauth_publickey*(s: Session, user: cstring, pkdata: cstring, pubkeydataLen: int, cb: Function) {.ssh2.}
@@ -722,8 +786,33 @@ proc userauth_publickey_fromfile_ex*(s: Session, uname: cstring, unameLen: uint,
722786
proc userauth_publickey_fromfile*(s: Session, uname: cstring, pk, pv, pp: cstring): cint {.inline.} =
723787
userauth_publickey_fromfile_ex(s, uname, uname.len.uint, pk, pv, pp)
724788

725-
when defined(ssl):
726-
proc userauth_publickey_frommemory*(s: Session, uname: cstring, unameLen: int, pk: cstring, pkLen: int, pv: cstring, pvLen: int, pp: cstring, ppLen: int): cint {.ssh2.}
789+
proc userauth_publickey_frommemory*(s: Session, uname: cstring, unameLen: int, pk: cstring, pkLen: int, pv: cstring, pvLen: int, pp: cstring, ppLen: int): cint {.ssh2.}
790+
791+
proc userauth_publickey_sk*(s: Session, username: cstring, pubkeydata: cstring, pubkeydata_len: csize_t, sign_callback: USERAUTH_SK_SIGN_FUNC, abstract: pointer): cint {.ssh2.}
792+
## Perform public key authentication using a security key.
793+
##
794+
## Parameters:
795+
## - s: The session handle
796+
## - username: The username to authenticate as
797+
## - pubkeydata: The public key data
798+
## - pubkeydata_len: Length of the public key data
799+
## - sign_callback: Callback function for signing operations
800+
## - abstract: User-provided context passed to callback
801+
##
802+
## Returns 0 on success, negative on failure
803+
804+
proc sign_sk*(session: Session, sig: ptr SK_SIG_INFO, data: cstring,data_len: csize_t, flags: cint): cint {.ssh2.}
805+
## Sign data using a security key.
806+
##
807+
## Parameters:
808+
## - session: The session handle
809+
## - sig: Pointer to signature information structure
810+
## - data: Data to be signed
811+
## - data_len: Length of data
812+
## - flags: Signing operation flags (LIBSSH2_SK_*)
813+
##
814+
## Returns 0 on success, negative on failure.
815+
## Use session_last_error() to get error details.
727816

728817
proc version*(version: int): cstring {.ssh2.}
729818

libssh2.nimble

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[Package]
22
name = "libssh2"
3-
version = "0.1.8"
3+
version = "0.1.9"
44
author = "Huy Doan"
55
description = "Nim wrapper for libssh2"
66
license = "MIT"

0 commit comments

Comments
 (0)