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);
相关推荐
BD_Marathon1 分钟前
【JavaWeb】HTTP_请求和响应的报文格式
网络·网络协议·http
gxh199212 小时前
4步将HTTP请求升级为HTTPS
运维·服务器·网络协议·http·https
2501_9159184116 小时前
HTTPS 端口深度解析,443 并不是唯一入口,理解 TLS 流量行为与抓包策略
网络协议·http·ios·小程序·https·uni-app·iphone
ogre202019 小时前
http header Authorization: Bearer和token之间可以有几个空格
http
咋吃都不胖lyh20 小时前
urllib3.util.retry.Retry 是 Python HTTP 客户端库 urllib3 中的一个核心组件,用于实现智能的请求重试机制
网络·网络协议·http
Hard but lovely20 小时前
http的content-text对照表
网络·网络协议·http
wgego21 小时前
http协议中各个网段含义
网络·网络协议·http
ASKED_20191 天前
不同 QPS 场景下的服务部署架构指南(实战经验总结)
http·架构
BD_Marathon1 天前
【JavaWeb】HTTP简介
网络·网络协议·http
槿花Hibiscus2 天前
C++基础:session实现和http server类最终组装
服务器·c++·http·muduo