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);
相关推荐
FungLeo1 天前
成为全栈·Vue 管理后台篇·用 fetch 建一层可控的请求内核
前端·javascript·vue.js·http·fetch·formdata·接口封装
wuyk5551 天前
Spider-第03讲-HTTP速通与读懂响应
网络·爬虫·网络协议·http
杨凯凡2 天前
Spring Framework 7 HTTP Interface 实战:声明式 RestClient、超时与测试
java·spring·http
CodeYp20192 天前
第11讲:应用层协议 HTTP
linux·http
Thanks_ks3 天前
HTTP 请求方法与 RESTful 接口设计:GET 和 POST 到底怎么用
http·api·restful·状态码·get·post·接口设计
LK_074 天前
【FastAPI】基础篇 01|开始之前:API、HTTP 与 FastAPI 到底是什么
网络协议·http·fastapi
阿星_4 天前
pydio登陆不了分析问题
网络协议·http·https
Joy T4 天前
Gzip 压缩原理与实践:HTTP 响应压缩、性能收益与工程配置
网络·网络协议·http
xixingzhe27 天前
AI 对话打字机效果:SSE 和 HTTP 的区别与适用场景
网络·网络协议·http
AI 编程助手GPT8 天前
curl 返回成功就能收文件?用本地 HTTP 验证错误页与超时
网络·网络协议·http