Loading

CentOS7安装 xmlsec1 编译并运行官方示例

1. 自动安装下列软件和依赖(默认已安装libxml2和libxslt)

yum install xmlsec1-openssl xmlsec1-openssl-devel

2. 查看官网 www.aleksey.com 示例 (sign1.c)

https://www.aleksey.com/xmlsec/api/xmlsec-examples.html

3. 拷贝到linux中,在这里放在 /srv/xmlsec/ 中

4. 查看gcc include 默认位置

`gcc -print-prog-name=cc1plus` -v

在这里找到了如下所示的位置:

 /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../include/c++/4.8.5
 /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../include/c++/4.8.5/x86_64-redhat-linux
 /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../include/c++/4.8.5/backward
 /usr/lib/gcc/x86_64-redhat-linux/4.8.5/include
 /usr/local/include
 /usr/include

然而xmlsec1、libxml2是在 /usr/include 的二级子目录里面,所以为了编译的时候少写点(嘻嘻),将目录软链接到include下

ln -s /usr/include/libxml2/libxml/ /usr/include/
ln -s /usr/include/xmlsec1/xmlsec/ /usr/include/

5.编译

gcc `xml2-config --cflags --libs` `xslt-config --cflags --libs` -lxmlsec1 -g -D__XMLSEC_FUNCTION__=__FUNCTION__ -DXMLSEC_NO_XKMS=1 -DXMLSEC_CRYPTO_OPENSSL -DXMLSEC_CRYPTO_DYNAMIC_LOADING=1 -DUNIX_SOCKETS -DXMLSEC_NO_SIZE_T sign.c -o sign1

因为是用的自动安装,所以没有configure配置选择,在后面加上配置

  • -DXMLSEC_CRYPTO_OPENSSL:使用openssl作为crypto库

否则会出现下面的错误

[root@bogon xmlsec]# ./sign1 sign1-tmpl.xml rsakey.pem > xml.xml
func=xmlSecDSigCtxProcessSignatureNode:file=xmldsig.c:line=479:obj=unknown:subj=dsigCtx->signValueNode == NULL:error=100:assertion: 
func=xmlSecDSigCtxSign:file=xmldsig.c:line=319:obj=unknown:subj=xmlSecDSigCtxSignatureProcessNode:error=1:xmlsec library function failed: 
Error: signature failed 
posted @ 2018-07-19 16:57  Gsealy  阅读(1369)  评论(0编辑  收藏  举报