libsoup 调用http API报错 unacceptable TLS certificate

环境:macos、libsoup-2.4

问题:通过soup_session_send调用http api报错 "unacceptable TLS certificate"

原因:libsoup使用gio-network的gnutls后端,默认查找证书在/opt/homebrew/etc/gnutls/cert.pem下,部分mac不存在这个证书文件。

解决:将/opt/homebrew/etc/gnutls/cert.pem证书打包到程序中,在代码中将证书设置到SoupSession的tls-database属性上

cpp 复制代码
    self->session = soup_session_new();
    char exePath[512];
    uint32_t size = sizeof(exePath);
    if (_NSGetExecutablePath(exePath, &size) != 0) {
        g_warning("Executable path too long\n");
        return;
    }
    
    char *dir = dirname(exePath);
    char env_path[512];
    memset(env_path, 0, sizeof(env_path));
    snprintf(env_path, sizeof(env_path), "%s/../Resources/gnutls/cert.pem", dir);

    GError *error = NULL;
    GTlsDatabase *db = g_tls_file_database_new(env_path, &error);
    if (!db) {
        g_warning("load cert failed: %s", error->message);
        g_clear_error(&error);
    }
    g_object_set(self->session, "tls-database", db, NULL);
    g_object_unref(db);
相关推荐
小小测试开发3 小时前
JMeter HTTP URL重写修饰符用法详解:解决会话传递与URL参数动态处理
网络协议·jmeter·http
red watchma3 小时前
OTA的HTTP笔记
笔记·网络协议·http
2301_8035545214 小时前
https
网络协议·http·https
AuroraDPY1 天前
计算机网络:HTTP协议
网络协议·计算机网络·http
小马_6661 天前
[好记性不如烂笔头]RT_Thread http ota升级踩坑笔记(CRC校验不通过)
笔记·物联网·网络协议·http
心一信息1 天前
http与https的详细介绍
网络协议·http·https
r***86981 天前
Nginx中$http_host、$host、$proxy_host的区别
运维·nginx·http
想不明白的过度思考者1 天前
Cookie与Session深度解析:原理、区别
网络·http·客户端·cookie·session·服务端
谢尔登1 天前
HTTPS 究竟比 HTTP 好在哪?
http·https·ssl