1

我想使用 gSOAP 连接 HTTPS Web 服务,我发现如何使用 gSOAP 是首先调用soap_ssl_client_context(),我从这里找到的示例是

 if (soap_ssl_client_context(
   &soap,            //1
   SOAP_SSL_DEFAULT, //2 
   "client.pem",    //3 /* keyfile: required only when client must authenticate to server (see SSL docs on how to obtain this file) */ 
   "password",      //4 /* password to read the key file (not used with GNUTLS) */ 
   "cacerts.pem",   //5 /* cacert file to store trusted certificates (needed to verify server) */    
   NULL,            //6 /* capath to directory with trusted certificates */ 
   NULL             //7 /* if randfile!=NULL: use a file with random data to seed randomness */ 
)) 
{ 
   soap_print_fault(&soap, stderr); 
   exit(1); 
} 

但我找不到任何有关参数详细信息的文档。我的问题是:

  1. 第 5 个参数,它说它应该是一个“cacert 文件”。所有样本都使用 PEM 格式,是否支持 DER/PKCS 等其他格式?还是只有 PEM?我尝试使用 DER 文件,它生成无法读取 CA 证书文件错误。

  2. 第 6 个,它说它应该是“目录的路径”,但它是如何工作的?例如,该目录中的所有文件都必须是证书文件?它会迭代目录中的每个证书文件,直到验证成功?

- - - - - - - - 更新 - - - - - - - -

关于 #1 问题,我检查了 gSoap 和 OpenSSL 中的源代码,发现它使用 PEM (x.509) 函数来加载 certfile。

soap_init()
{
//...
soap->fsslauth = ssl_auth_init;
//...
}

soap_ssl_client_context()
{
//...
soap->cafile = cafile;
//...
return soap->fsslauth(soap);
}

ssl_auth_init()
{
//...
 SSL_CTX_set_client_CA_list(soap->ctx, SSL_load_client_CA_file(soap->cafile));
//...
}

SSL_load_client_CA_file
{
//...
if (PEM_read_bio_X509(in,&x,NULL,NULL) == NULL)
//...
}

非常感谢,

援助

4

1 回答 1

0

参数 3 和 5 支持常见的 PEM 格式。要将 CRT 转换为 PEM,请参阅:how-to-convert-crt-to-pem,同样您可以使用 openssl 命令将 DER 转换为 PEM。参数 6 是证书(PEM 格式)所在位置的目录路径。该选项很慢,因此首选带有 cacerts.pem(或特定 cacert.pem)的非 NULL 参数 5。

于 2013-10-31T02:48:03.190 回答