文章目录
- 一、libSSH2介绍
- 二、文件下载
- 三、文件分析
- 四、pro文件
- 五、编译实践
一、libSSH2介绍
libSSH2是一个开源的C函数库,用来实现SSH2协议。
SSH(Secure SHell)到目前为止有两个不兼容的版本——SSH1和SSH2。
SSH2避免了RSA的专利问题,并修补了CRC的缺陷,增加了AES和Twofish等对称加密算法。
二、文件下载
libSSH2网站:
libSSH2
下载压缩包:libssh2-1.10.0.tar.gz
三、文件分析
解压缩libssh2-1.10.0.tar.gz文件。
进入libssh2-1.10.0目录
CMakeLists.txt记录了要加载的文件目录。
四、pro文件
windows环境下的libssh2_config.h文件:
从libssh2-1.10.0/win32目录下,拷贝libssh2_config.h,到win目录下:
linuxmac目录下的libssh2_config.h文件进行修改如下:
配置头文件:
#头文件
HEADERS += ./agent.h \./blf.h \./channel.h \./comp.h \./crypto.h \./libssh2.h \./libssh2_priv.h \./mac.h \./mbedtls.h \./misc.h \./openssl.h \./packet.h \./session.h \./sftp.h \./transport.h \./userauth.h \./wincng.h
win32 {HEADERS += ./win/libssh2_config.h
}
linux* {HEADERS += ./linuxmac/libssh2_config.h
}
macx {HEADERS += ./linuxmac/libssh2_config.h
}
配置源文件:
#源文件
SOURCES += ./agent.c \./agent_win.c \./bcrypt_pbkdf.c \./blowfish.c \./channel.c \./comp.c \./crypt.c \./global.c \./hostkey.c \./keepalive.c \./kex.c \./knownhost.c \./mac.c \./mbedtls.c \./misc.c \./openssl.c \./packet.c \./pem.c \./publickey.c \./scp.c \./session.c \./sftp.c \./transport.c \./userauth.c \./version.c \./wincng.c
配置预定义项:
DEFINES -= UNICODE
DEFINES += LIBSSH2_OPENSSL
win32 {DEFINES += LIBSSH2_WIN32 _CRT_SECURE_NO_DEPRECATE _CRT_NONSTDC_NO_DEPRECATE
}
依赖库配置:
win32 {LIBS += -LD:/Qt/Tools/OpenSSL/Win_x64/libLIBS += -llibcryptoLIBS += -luser32 -lws2_32
}
linux* {LIBS += -lcrypto
}
macx {LIBS += -L/usr/local/opt/openssl@3/libLIBS += -lcrypto
}
形成003.libssh2-1.10.0.pro文件:
QT += core networkTEMPLATE = lib
CONFIG += c++17DESTDIR = ../QGIS
CONFIG(debug, debug|release){MOC_DIR = ../build-QGIS/ssh2/Debug/mocRCC_DIR = ../build-QGIS/ssh2/Debug/rccUI_DIR = ../build-QGIS/ssh2/Debug/uiOBJECTS_DIR = ../build-QGIS/ssh2/Debug/obj
}else{MOC_DIR = ../build-QGIS/ssh2/Release/mocRCC_DIR = ../build-QGIS/ssh2/Release/rccUI_DIR = ../build-QGIS/ssh2/Release/uiOBJECTS_DIR = ../build-QGIS/ssh2/Release/obj
}CONFIG(debug, debug|release){TARGET = ssh2d
}else{TARGET = ssh2
}
DEFINES -= UNICODE
DEFINES += LIBSSH2_OPENSSL
win32 {DEFINES += LIBSSH2_WIN32 _CRT_SECURE_NO_DEPRECATE _CRT_NONSTDC_NO_DEPRECATE
}# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
#当前目录
INCLUDEPATH += ./
#openssl路径
win32 {INCLUDEPATH += ./winINCLUDEPATH += D:/Qt/Tools/OpenSSL/Win_x64/includeINCLUDEPATH += D:/Qt/Tools/OpenSSL/Win_x64/include/openssl
}
linux* {INCLUDEPATH += ./linuxmacINCLUDEPATH += /opt/Qt/Tools/OpenSSL/src/includeINCLUDEPATH += /opt/Qt/Tools/OpenSSL/src/include/openssl
}
macx {INCLUDEPATH += ./linuxmacINCLUDEPATH += /usr/local/opt/openssl@3/includeINCLUDEPATH += /usr/local/opt/openssl@3/include/openssl
}#ZLIB路径
INCLUDEPATH += ../zlib-1.2.12
#LIBS
LIBS += -L../QGISCONFIG(debug, debug|release){LIBS += -lzlibd
}else{LIBS += -lzlib
}
win32 {LIBS += -LD:/Qt/Tools/OpenSSL/Win_x64/libLIBS += -llibcryptoLIBS += -luser32 -lws2_32
}
linux* {LIBS += -lcrypto
}
macx {LIBS += -L/usr/local/opt/openssl@3/libLIBS += -lcrypto
}#头文件
HEADERS += ./agent.h \./blf.h \./channel.h \./comp.h \./crypto.h \./libssh2.h \./libssh2_priv.h \./mac.h \./mbedtls.h \./misc.h \./openssl.h \./packet.h \./session.h \./sftp.h \./transport.h \./userauth.h \./wincng.h
win32 {HEADERS += ./win/libssh2_config.h
}
linux* {HEADERS += ./linuxmac/libssh2_config.h
}
macx {HEADERS += ./linuxmac/libssh2_config.h
}#源文件
SOURCES += ./agent.c \./agent_win.c \./bcrypt_pbkdf.c \./blowfish.c \./channel.c \./comp.c \./crypt.c \./global.c \./hostkey.c \./keepalive.c \./kex.c \./knownhost.c \./mac.c \./mbedtls.c \./misc.c \./openssl.c \./packet.c \./pem.c \./publickey.c \./scp.c \./session.c \./sftp.c \./transport.c \./userauth.c \./version.c \./wincng.c# Default rules for deployment.
#unix {
# target.path = /usr/lib
#}
#!isEmpty(target.path): INSTALLS += target
五、编译实践
用QtCreator程序,打开003.libssh2-1.10.0.pro文件。
在windows下编译,形成:
在linux下编译,形成:
在macos下编译,形成: