libcurl:Protocol "smtps" not supported or disabled in libcurl

libcurl:Protocol “smtps” not supported or disabled in libcurl

在使用libcurl来作为MUA时,开启DEBUG模式,使用smtps协议,在运行时报错:

libcurl:Protocol “smtps” not supported or disabled in libcurl

原因在于,安装libcurl时没有带着openssl。

安装包:curl-7.56.1.tar.gz

错误安装:

[jiang@localhost curl-7.56.1]$ ./configure --prefix=$HOME/libcurl
checking whether to enable maintainer-specific portions of Makefiles... no
……
configure: WARNING: SSL disabled, you will not be able to use HTTPS, FTPS, NTLM and more.
configure: WARNING: Use --with-ssl, --with-gnutls, --with-polarssl, --with-cyassl, --with-nss, --with-axtls, --with-winssl, or --with-darwinssl to address this.
……
configure: Configured to build curl/libcurl:

  curl version:     7.56.1
  Host setup:       x86_64-pc-linux-gnu
  Install prefix:   /home/jiang/libcurl
  Compiler:         gcc
  SSL support:      no      (--with-{ssl,gnutls,nss,polarssl,mbedtls,cyassl,axtls,winssl,darwinssl} )
  SSH support:      no      (--with-libssh2)
  zlib support:     no      (--with-zlib)
  GSS-API support:  no      (--with-gssapi)
  TLS-SRP support:  no      (--enable-tls-srp)
  resolver:         POSIX threaded
  IPv6 support:     enabled
  Unix sockets support: enabled
  IDN support:      no      (--with-{libidn2,winidn})
  Build libcurl:    Shared=yes, Static=yes
  Built-in manual:  enabled
  --libcurl option: enabled (--disable-libcurl-option)
  Verbose errors:   enabled (--disable-verbose)
  SSPI support:     no      (--enable-sspi)
  ca cert bundle:   /etc/pki/tls/certs/ca-bundle.crt
  ca cert path:     no
  ca fallback:      no
  LDAP support:     no      (--enable-ldap / --with-ldap-lib / --with-lber-lib)
  LDAPS support:    no      (--enable-ldaps)
  RTSP support:     enabled
  RTMP support:     no      (--with-librtmp)
  metalink support: no      (--with-libmetalink)
  PSL support:      no      (libpsl not found)
  HTTP2 support:    disabled (--with-nghttp2)
  Protocols:        DICT FILE FTP GOPHER HTTP IMAP POP3 RTSP SMTP TELNET TFTP

通常在./configure生成makefile这一步,我都基本不看,能生成makefile即可,然后直接编译安装。

ATTENTION:实际应该仔细确认summary这一部分,可能存在一些潜在的运行时问题。

继续进行编译安装:

[jiang@localhost curl-7.56.1]$ make && make install

OK,到此libcurl就安装完毕。

Code:

#include <stdio.h>
#include <string.h>
#include <curl/curl.h>

#define FROM_ADDR    "<1158801411@qq.com>"
#define TO_ADDR      "<jiangjinwang@ebupt.com>"

#define FROM_MAIL "1158801411@qq.com" FROM_ADDR
#define TO_MAIL   "jiangjinwang@ebupt.com" TO_ADDR

static const char *payload_text[] = {
  "To: " TO_MAIL "\r\n",
  "From: " FROM_MAIL "\r\n",
  "Subject: SMTP example message\r\n",
  "\r\n", /* empty line to divide headers from body, see RFC5322 */
  "The body of the message starts here.\r\n",
  "\r\n",
  "It could be a lot of lines, could be MIME encoded, whatever.\r\n",
  "Check RFC5322.\r\n",
  NULL
};

struct upload_status {
  int lines_read;
};

static size_t payload_source(void *ptr, size_t size, size_t nmemb, void *userp)
{
  struct upload_status *upload_ctx = (struct upload_status *)userp;
  const char *data;

  if((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) {
    return 0;
  }

  data = payload_text[upload_ctx->lines_read];

  if(data) {
    size_t len = strlen(data);
    memcpy(ptr, data, len);
    upload_ctx->lines_read++;

    return len;
  }

  return 0;
}

int main(void)
{
  CURL *curl;
  CURLcode res = CURLE_OK;
  struct curl_slist *recipients = NULL;
  struct upload_status upload_ctx;

  upload_ctx.lines_read = 0;

  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "smtps://smtp.qq.com:465");

    curl_easy_setopt(curl, CURLOPT_MAIL_FROM, FROM_ADDR);

    recipients = curl_slist_append(recipients, TO_ADDR);
    curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients);

    curl_easy_setopt(curl, CURLOPT_READFUNCTION, payload_source);
    curl_easy_setopt(curl, CURLOPT_READDATA, &upload_ctx);
    curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);

    curl_easy_setopt(curl, CURLOPT_USERNAME, "1158801411@qq.com");
    curl_easy_setopt(curl, CURLOPT_PASSWORD, "xxxxxxxxxxxxxxxx");

    curl_easy_setopt(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_ALL);
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);

    /* DEBUG */
    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);

    /* Send the message */
    res = curl_easy_perform(curl);

    /* Check for errors */
    if(res != CURLE_OK)
    fprintf(stderr, "curl_easy_perform() failed: %s\n",
        curl_easy_strerror(res));

    curl_slist_free_all(recipients);

    curl_easy_cleanup(curl);
  }

  return (int)res;
}

编译 && 执行:

[jiang@localhost ~]$ gcc -o ssl ssl.c -I/home/jiang/libcurl/include -L /home/jiang/libcurl/lib -lcurl
[jiang@localhost ~]$ ./ssl
* Protocol smtps not supported or disabled in libcurl
* Unsupported protocol
curl_easy_perform() failed: Unsupported protocol

仔细回头看看,想想。

libcurl如果使用smtps,即使用TLS/SSL,那必然涉及到加解密算法,谁来做这个工作呢?

刚刚似乎安装libcurl时没有带着openssl?

实际可能由于openssl版本和libcurl要求的openssl版本不一致或其他原因,导致./configure在生成libcurl的makefile时,并没有(发现)已存在的openssl库。

解决办法:

重新安装/升级openssl:

[root@localhost ~]# yum install openssl-devel -y

重新安装libcurl:

[jiang@localhost curl-7.56.1]$ ./configure --prefix=$HOME/libcurl
……
configure: Configured to build curl/libcurl:

  curl version:     7.56.1
  Host setup:       x86_64-pc-linux-gnu
  Install prefix:   /home/jiang/libcurl
  Compiler:         gcc
  SSL support:      enabled (OpenSSL)
  SSH support:      no      (--with-libssh2)
  zlib support:     enabled
  GSS-API support:  no      (--with-gssapi)
  TLS-SRP support:  no      (--enable-tls-srp)
  resolver:         POSIX threaded
  IPv6 support:     enabled
  Unix sockets support: enabled
  IDN support:      no      (--with-{libidn2,winidn})
  Build libcurl:    Shared=yes, Static=yes
  Built-in manual:  enabled
  --libcurl option: enabled (--disable-libcurl-option)
  Verbose errors:   enabled (--disable-verbose)
  SSPI support:     no      (--enable-sspi)
  ca cert bundle:   /etc/pki/tls/certs/ca-bundle.crt
  ca cert path:     no
  ca fallback:      no
  LDAP support:     no      (--enable-ldap / --with-ldap-lib / --with-lber-lib)
  LDAPS support:    no      (--enable-ldaps)
  RTSP support:     enabled
  RTMP support:     no      (--with-librtmp)
  metalink support: no      (--with-libmetalink)
  PSL support:      no      (libpsl not found)
  HTTP2 support:    disabled (--with-nghttp2)
  Protocols:        DICT FILE FTP FTPS GOPHER HTTP HTTPS IMAP IMAPS POP3 POP3S RTSP SMB SMBS SMTP SMTPS TELNET TFTP

[jiang@localhost curl-7.56.1]$ make && make install

仔细对比两次./configure生成输出的summary:

  Protocols:        DICT FILE FTP GOPHER HTTP IMAP POP3 RTSP SMTP TELNET TFTP
  Protocols:        DICT FILE FTP FTPS GOPHER HTTP HTTPS IMAP IMAPS POP3 POP3S RTSP SMB SMBS SMTP 

即,通过安装/升级openssl,使得在安装libcurl生成makefile时,让其发现openssl的存在,带着openssl编译安装,以支持所有需要TLS/SSL的协议(HTTPS、SMTPS等)。

代码编译&&执行如下:

[jiang@localhost ~]$ gcc -o ssl ssl.c -I/home/jiang/libcurl/include -L /home/jiang/libcurl/lib -lcurl
[jiang@localhost ~]$ ./ssl
* Rebuilt URL to: smtps://smtp.qq.com:465/
*   Trying 14.17.57.241...
* TCP_NODELAY set
* Connected to smtp.qq.com (14.17.57.241) port 465 (#0)
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none
* SSL connection using TLSv1.2 / AES128-SHA256
* Server certificate:
*  subject: C=CN; ST=Guangdong; L=Shenzhen; O=Shenzhen Tencent Computer Systems Company Limited; OU=R&D; CN=pop.qq.com
*  start date: Sep  7 00:00:00 2016 GMT
*  expire date: Dec  7 23:59:59 2018 GMT
*  issuer: C=US; O=GeoTrust Inc.; CN=GeoTrust SSL CA - G3
*  SSL certificate verify ok.
< 220 smtp.qq.com Esmtp QQ Mail Server
> EHLO localhost
< 250-smtp.qq.com
< 250-PIPELINING
< 250-SIZE 73400320
< 250-AUTH LOGIN PLAIN
< 250-AUTH=LOGIN
< 250-MAILCOMPRESS
< 250 8BITMIME
> AUTH LOGIN
< 334 VXNlcm5hbWU6
> MTE1ODgwMTQxMUBxcS5jb20=
< 334 UGFzc3dvcmQ6
> YmJ1eXVwZnphdmFoaGhpYw==
< 235 Authentication successful
> MAIL FROM:<1158801411@qq.com>
< 250 Ok
> RCPT TO:<jiangjinwang@ebupt.com>
< 250 Ok
> DATA
< 354 End data with <CR><LF>.<CR><LF>
< 250 Ok: queued as 
* Connection #0 to host smtp.qq.com left intact

OK,发送成功(TLS/SSL)。

还有一种可能,也会导致上面的错误信息:

可执行文件链接的动态库不是新版的,支持SMTPS的动态库,而是旧版本的libcurl动态库。

[jiang@localhost ~]$ ldd ./ssl
    linux-vdso.so.1 =>  (0x00007ffc6cbeb000)
    libcurl.so.4 => /usr/lib64/libcurl.so.4 (0x000000312ec00000)
    ……
[jiang@localhost ~]$ ./ssl
* Protocol smtps not supported or disabled in libcurl
* Unsupported protocol
curl_easy_perform() failed: Unsupported protocol

通过设置LD_LIBRARY_PATH,使其找到正确的libcurl动态库(当然,也存在很多其他方法啦):

[jiang@localhost ~]$ export LD_LIBRARY_PATH=$HOME/libcurl/lib:$LD_LIBRARY_PATH
[jiang@localhost ~]$ ./ssl
* Rebuilt URL to: smtps://smtp.qq.com:465/
*   Trying 14.17.57.241...
* TCP_NODELAY set
* Connected to smtp.qq.com (14.17.57.241) port 465 (#0)
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
……

总结:

有两种原因导致:

Protocol “smtps” not supported or disabled in libcurl

1.在./configure生成libcurl的makefile时,可能由于openssl库安装不正确、版本等问题导致configure找不到openssl库
2.执行可执行文件时,动态链接器ld找到的不是正确的,支持TLS/SSL的libcurl,而是其他版本、不支持TLS/SSL的libcurl

同理,可能存在:

Protocol “https” not supported or disabled in libcurl

当运行时发现这个问题,可以先检查下libcurl是否支持openssl?安装libcurl时是否是带着openssl进行编译的?

<think>好的,用户遇到了curl报错:“curl: (1) Protocol http not supported or disabled in libcurl”。我需要先分析可能的原因,然后给出解决方案。 首先,这个错误通常意味着libcurl在编译时没有支持HTTP协议。用户可能在执行curl命令时使用了http而不是https,或者他们的curl版本有问题。我需要确认用户是否在命令中正确使用了协议,或者是否curl本身配置有问题。 用户之前的问题是关于构造GitLab的CURL命令,给出的例子是http链接,而现在的错误提示是协议不被支持。可能用户的环境中的curl不支持http,或者被禁用了。需要检查curl的版本和支持的协议。 接下来,我应该分步骤引导用户排查问题。首先,让用户检查curl的版本和已支持的协议,使用curl -V命令。如果输出中没有HTTP,说明编译时没有包含HTTP支持。这时候需要用户重新安装或编译curl,确保启用HTTP。 另外,用户可能不小心省略了协议,比如在URL前没有写http://或https://,但根据之前的对话,用户提供的URL是正确的,所以可能问题出在curl的安装上。此外,用户可能使用的是Windows系统,而某些环境变量或配置导致问题,比如在PowerShell中可能需要正确转义字符,但错误提示是协议不支持,所以更可能是编译问题。 还要考虑用户是否使用了代理或网络配置问题,但错误提示明确是协议不支持,所以重点应放在curl的安装和编译选项上。需要提醒用户在不同操作系统下的解决方法,比如Ubuntu/Debian使用apt安装curl,CentOS使用yum,macOS用brew,Windows建议使用官方二进制包。 最后,给出示例命令,让用户测试,比如curl -v http://example.com,如果还是失败,确认问题所在。同时,提醒用户如果使用自签证书的https,可能需要忽略SSL检查,但当前错误是http的问题,所以暂时不需要涉及https部分。 总结:逐步引导用户检查curl版本,确认协议支持,重新安装或更新curl,确保http协议被启用,并提供各系统的安装命令。同时,验证用户命令的URL是否正确,排除其他可能性。</think>当使用CURL时出现 `curl: (1) Protocol http not supported or disabled in libcurl` 错误,表明你的CURL编译版本**未启用HTTP协议支持**,或系统环境存在特殊限制。以下是逐步排查和解决方法: --- ### 原因分析 1. **CURL编译选项问题** libcurl在编译时默认包含HTTP支持,但某些定制化安装可能禁用了该协议(例如通过 `--disable-http` 编译选项)。 2. **环境变量干扰** 特殊环境变量(如 `CURLOPT_PROTOCOLS`)可能限制了协议使用。 3. **系统安全策略** 企业或容器环境中可能通过安全策略禁用明文HTTP协议。 --- ### 解决方案 #### 1. 检查CURL支持的协议 运行以下命令查看已支持的协议列表: ```bash curl -V ``` 输出中需包含 `HTTP`(例如): ``` Protocols: dict file ftp gopher http imap ... ``` #### 2. 重新安装CURL(启用HTTP) 根据操作系统选择对应方式: - **Ubuntu/Debian** ```bash sudo apt-get install --reinstall curl ``` - **CentOS/RHEL** ```bash sudo yum reinstall curl ``` - **macOS (Homebrew)** ```bash brew reinstall curl ``` - **Windows** 从[官方下载页](https://curl.se/windows/)下载最新二进制文件(确保选择支持HTTP的版本)。 #### 3. 强制指定协议(仅限HTTP场景) 如果必须使用明文HTTP(非HTTPS),尝试强制声明协议: ```bash curl --proto http http://9.6.232.212/your_path ``` #### 4. 验证网络策略 若在受控环境中(如企业内网),联系管理员确认是否允许HTTP协议。 --- ### 测试命令 执行以下命令验证HTTP协议是否生效: ```bash curl -v http://example.com ``` 如果成功返回HTML内容,说明问题已解决。 --- ### 附加说明 - **HTTPS推荐** 建议优先使用HTTPS(将URL中的 `http://` 改为 `https://`),现代系统默认支持HTTPS。 - **Windows特殊注意** 某些Windows环境可能因PATH配置问题调用旧版CURL,尝试使用完整路径(如 `C:\Program Files\curl\bin\curl.exe`)。 --- 若问题仍未解决,请提供以下信息: 1. 操作系统类型及版本 2. `curl -V` 的完整输出 3. 完整的报错命令示例
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值