Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add xmlsec/1.2.30 #3314

Merged
merged 28 commits into from
Nov 6, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5d4d631
Folder structure and recipe for xmlsec 1.2.30
steinerthomas Oct 25, 2020
60822fe
Add option with_xslt
steinerthomas Oct 25, 2020
1a162cf
Trigger build
steinerthomas Oct 26, 2020
352a8dd
Remove fpic option for Windows
steinerthomas Oct 26, 2020
8682819
Add support for Windows builds
steinerthomas Oct 26, 2020
925dfb8
Remove fPIC if shared
steinerthomas Oct 26, 2020
4f4480f
Bump openssl version
steinerthomas Oct 26, 2020
8cc4e16
Append standard includedirs instead of overwriting
steinerthomas Oct 26, 2020
0e4e49a
Clean configure_args
steinerthomas Oct 26, 2020
e250b0a
Only run tests if not cross-compiling
steinerthomas Oct 26, 2020
9d328dc
Use remove_files_by_mask instead of glob
steinerthomas Oct 26, 2020
0a21f4b
Remove comma
steinerthomas Oct 26, 2020
4bc104a
Fix Windows build
steinerthomas Oct 26, 2020
e724117
Fix Windows build
steinerthomas Oct 26, 2020
4d4a38a
MSVC build
steinerthomas Oct 30, 2020
64d47dc
Fix debug MSVC build
steinerthomas Oct 31, 2020
bc8f273
xmlsec: add components + double quotes + crypto engine option
madebr Nov 1, 2020
bfca3ae
Merge pull request #1 from madebr/pr_xmlsec
steinerthomas Nov 1, 2020
d4b7e77
Comment fix for mingw
steinerthomas Nov 1, 2020
c59b9b8
Initialize autotools.libs
steinerthomas Nov 1, 2020
3ff9e41
Use msvc property
steinerthomas Nov 2, 2020
a8adef6
Use format for string concat
steinerthomas Nov 2, 2020
f1e6e1e
Docs always no
steinerthomas Nov 2, 2020
aaf0df6
Initialize autotools.libs with syslib pthread (fix build)
steinerthomas Nov 2, 2020
f771c97
Initialize autotools.libs with syslib pthread (fix build) - only for …
steinerthomas Nov 2, 2020
40cbcd2
Use whit_openssl option, remove pthread syslib
steinerthomas Nov 3, 2020
77cd57e
Better check for CONAN_BASH_PATH
steinerthomas Nov 3, 2020
8ef237a
Fix openssl component
steinerthomas Nov 4, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions recipes/xmlsec/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"1.2.30":
url: "https://github.com/lsh123/xmlsec/archive/xmlsec-1_2_30.tar.gz"
sha256: "57f6a5f3b9f2d17859a5583dc0b23f47130cc1c909ed6caf596ab0cd388237ec"
96 changes: 96 additions & 0 deletions recipes/xmlsec/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
from conans import ConanFile, tools, AutoToolsBuildEnvironment
import os
import glob

class XmlSecConan(ConanFile):
name = "xmlsec"
description = "XML Security Library is a C library based on LibXML2. The library supports major XML security standards."
license = ("MIT", "MPL-1.1")
steinerthomas marked this conversation as resolved.
Show resolved Hide resolved
homepage = "https://github.com/lsh123/xmlsec"
url = "https://github.com/conan-io/conan-center-index"
generators = "pkg_config"
settings = "os", "compiler", "arch", "build_type"
topics = ("xml", "signature", "encryption")
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_xslt": [True, False]
}
default_options = {
"shared": False,
"fPIC": True,
"with_xslt": False
}

_autotools = None

@property
def _source_subfolder(self):
return "source_subfolder"

def requirements(self):
self.requires("libxml2/2.9.10")
self.requires("openssl/1.1.1g")
steinerthomas marked this conversation as resolved.
Show resolved Hide resolved
if self.options.with_xslt:
self.requires("libxslt/1.1.34")

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
del self.settings.compiler.libcxx
steinerthomas marked this conversation as resolved.
Show resolved Hide resolved
del self.settings.compiler.cppstd

def build_requirements(self):
self.build_requires("libtool/2.4.6")
steinerthomas marked this conversation as resolved.
Show resolved Hide resolved
self.build_requires("pkgconf/1.7.3")

def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_folder = "xmlsec-xmlsec-{}".format(self.version.replace('.', '_'))
os.rename(extracted_folder, self._source_subfolder)

def _configure_autotools(self):
if self._autotools:
return self._autotools
self._autotools = AutoToolsBuildEnvironment(self)
steinerthomas marked this conversation as resolved.
Show resolved Hide resolved
configure_args = [
"--enable-crypto-dl=no",
"--enable-apps-crypto-dl=no",
]
if not self.options.with_xslt:
configure_args.append("--with-libxslt=no")
if self.options.shared:
configure_args.extend(["--disable-static", "--enable-shared"])
else:
configure_args.extend(["--disable-shared", "--enable-static"])
steinerthomas marked this conversation as resolved.
Show resolved Hide resolved
self._autotools.configure(args=configure_args, configure_dir=self._source_subfolder)
return self._autotools

def build(self):
with tools.chdir(self._source_subfolder):
self.run("autoreconf -fiv")
steinerthomas marked this conversation as resolved.
Show resolved Hide resolved
autotools = self._configure_autotools()
autotools.make()

def package(self):
self.copy("Copyright", src=self._source_subfolder, dst="licenses")
autotools = self._configure_autotools()
autotools.install()
tools.rmdir(os.path.join(self.package_folder, "share"))
for la_file in glob.glob(os.path.join(self.package_folder, "lib", "*.la")):
os.remove(la_file)
steinerthomas marked this conversation as resolved.
Show resolved Hide resolved
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
os.remove(os.path.join(self.package_folder, "lib", "xmlsec1Conf.sh"))

def package_info(self):
self.cpp_info.includedirs = ["include", os.path.join("include", "xmlsec1")]
steinerthomas marked this conversation as resolved.
Show resolved Hide resolved
self.cpp_info.defines.append("XMLSEC_CRYPTO_OPENSSL")
if not self.options.with_xslt:
self.cpp_info.defines.append("XMLSEC_NO_XSLT")
self.cpp_info.defines.append("XMLSEC_NO_SIZE_T")
self.cpp_info.libs = ["xmlsec1-openssl", "xmlsec1"]
self.cpp_info.names["pkg_config"] = "xmlsec1"
if self.settings.os == "Linux":
self.cpp_info.system_libs = ["m", "dl", "pthread"]
8 changes: 8 additions & 0 deletions recipes/xmlsec/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
CONAN_BASIC_SETUP(TARGETS)

add_executable(${PROJECT_NAME} sign1.c)
target_link_libraries(${PROJECT_NAME} CONAN_PKG::xmlsec)
19 changes: 19 additions & 0 deletions recipes/xmlsec/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from conans import ConanFile, CMake
steinerthomas marked this conversation as resolved.
Show resolved Hide resolved
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
bin_path = os.path.join("bin", "test_package")
arg_path1 = os.path.abspath(os.path.join(os.path.dirname(__file__), "sign1-tmpl.xml"))
arg_path2 = os.path.abspath(os.path.join(os.path.dirname(__file__), "rsakey.pem"))
bin_arg_path = "%s %s %s" % (bin_path, arg_path1, arg_path2)
self.run(bin_arg_path, run_environment=True)
steinerthomas marked this conversation as resolved.
Show resolved Hide resolved
9 changes: 9 additions & 0 deletions recipes/xmlsec/all/test_package/rsakey.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-----BEGIN RSA PRIVATE KEY-----
MIIBPAIBAAJBANPQbQ92nlbeg1Q5JNHSO1Yey46nZ7GJltLWw1ccSvp7pnvmfUm+
steinerthomas marked this conversation as resolved.
Show resolved Hide resolved
M521CpFpfr4EAE3UVBMoU9j/hqq3dFAc2H0CAwEAAQJBALFVCjmsAZyQ5jqZLO5N
qEfNuHZSSUol+xPBogFIOq3BWa269eNNcAK5or5g0XWWon7EPdyGT4qyDVH9KzXK
RLECIQDzm/Nj0epUGN51/rKJgRXWkXW/nfSCMO9fvQR6Ujoq3wIhAN6WeHK9vgWg
wBWqMdq5sR211+LlDH7rOUQ6rBpbsoQjAiEA7jzpfglgPPZFOOfo+oh/LuP6X3a+
FER/FQXpRyb7M8kCIETUrwZ8WkiPPxbz/Fqw1W5kjw/g2I5e2uSYaCP2eyuVAiEA
mOI6RhRyMqgxQyy0plJVjG1s4fdu92AWYy9AwYeyd/8=
-----END RSA PRIVATE KEY-----
26 changes: 26 additions & 0 deletions recipes/xmlsec/all/test_package/sign1-tmpl.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
XML Security Library example: Simple signature template file for sign1 example.
-->
<Envelope xmlns="urn:envelope">
<Data>
Hello, World!
</Data>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
<Reference URI="">
<Transforms>
<Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<DigestValue></DigestValue>
</Reference>
</SignedInfo>
<SignatureValue/>
<KeyInfo>
<KeyName/>
</KeyInfo>
</Signature>
</Envelope>
211 changes: 211 additions & 0 deletions recipes/xmlsec/all/test_package/sign1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
/**
* XML Security Library example: Signing a template file.
*
* Signs a template file using a key from PEM file
*
* Usage:
* ./sign1 <xml-tmpl> <pem-key>
*
* Example:
* ./sign1 sign1-tmpl.xml rsakey.pem > sign1-res.xml
*
* The result signature could be validated using verify1 example:
* ./verify1 sign1-res.xml rsapub.pem
*
* This is free software; see Copyright file in the source
* distribution for preciese wording.
*
* Copyright (C) 2002-2016 Aleksey Sanin <[email protected]>. All Rights Reserved.
*/
#include <stdlib.h>
#include <string.h>
#include <assert.h>

#include <libxml/tree.h>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>

#ifndef XMLSEC_NO_XSLT
#include <libxslt/xslt.h>
#include <libxslt/security.h>
#endif /* XMLSEC_NO_XSLT */

#include <xmlsec/xmlsec.h>
#include <xmlsec/xmltree.h>
#include <xmlsec/xmldsig.h>
#include <xmlsec/crypto.h>

int sign_file(const char* tmpl_file, const char* key_file);

int
main(int argc, char **argv) {
#ifndef XMLSEC_NO_XSLT
xsltSecurityPrefsPtr xsltSecPrefs = NULL;
#endif /* XMLSEC_NO_XSLT */

assert(argv);

if(argc != 3) {
fprintf(stderr, "Error: wrong number of arguments.\n");
fprintf(stderr, "Usage: %s <tmpl-file> <key-file>\n", argv[0]);
return(1);
}

/* Init libxml and libxslt libraries */
xmlInitParser();
LIBXML_TEST_VERSION
xmlLoadExtDtdDefaultValue = XML_DETECT_IDS | XML_COMPLETE_ATTRS;
xmlSubstituteEntitiesDefault(1);
#ifndef XMLSEC_NO_XSLT
xmlIndentTreeOutput = 1;
#endif /* XMLSEC_NO_XSLT */

/* Init libxslt */
#ifndef XMLSEC_NO_XSLT
/* disable everything */
xsltSecPrefs = xsltNewSecurityPrefs();
xsltSetSecurityPrefs(xsltSecPrefs, XSLT_SECPREF_READ_FILE, xsltSecurityForbid);
xsltSetSecurityPrefs(xsltSecPrefs, XSLT_SECPREF_WRITE_FILE, xsltSecurityForbid);
xsltSetSecurityPrefs(xsltSecPrefs, XSLT_SECPREF_CREATE_DIRECTORY, xsltSecurityForbid);
xsltSetSecurityPrefs(xsltSecPrefs, XSLT_SECPREF_READ_NETWORK, xsltSecurityForbid);
xsltSetSecurityPrefs(xsltSecPrefs, XSLT_SECPREF_WRITE_NETWORK, xsltSecurityForbid);
xsltSetDefaultSecurityPrefs(xsltSecPrefs);
#endif /* XMLSEC_NO_XSLT */

/* Init xmlsec library */
if(xmlSecInit() < 0) {
fprintf(stderr, "Error: xmlsec initialization failed.\n");
return(-1);
}

/* Check loaded library version */
if(xmlSecCheckVersion() != 1) {
fprintf(stderr, "Error: loaded xmlsec library version is not compatible.\n");
return(-1);
}

/* Load default crypto engine if we are supporting dynamic
* loading for xmlsec-crypto libraries. Use the crypto library
* name ("openssl", "nss", etc.) to load corresponding
* xmlsec-crypto library.
*/
#ifdef XMLSEC_CRYPTO_DYNAMIC_LOADING
if(xmlSecCryptoDLLoadLibrary(NULL) < 0) {
fprintf(stderr, "Error: unable to load default xmlsec-crypto library. Make sure\n"
"that you have it installed and check shared libraries path\n"
"(LD_LIBRARY_PATH and/or LTDL_LIBRARY_PATH) environment variables.\n");
return(-1);
}
#endif /* XMLSEC_CRYPTO_DYNAMIC_LOADING */

/* Init crypto library */
if(xmlSecCryptoAppInit(NULL) < 0) {
fprintf(stderr, "Error: crypto initialization failed.\n");
return(-1);
}

/* Init xmlsec-crypto library */
if(xmlSecCryptoInit() < 0) {
fprintf(stderr, "Error: xmlsec-crypto initialization failed.\n");
return(-1);
}

if(sign_file(argv[1], argv[2]) < 0) {
return(-1);
}

/* Shutdown xmlsec-crypto library */
xmlSecCryptoShutdown();

/* Shutdown crypto library */
xmlSecCryptoAppShutdown();

/* Shutdown xmlsec library */
xmlSecShutdown();

/* Shutdown libxslt/libxml */
#ifndef XMLSEC_NO_XSLT
xsltFreeSecurityPrefs(xsltSecPrefs);
xsltCleanupGlobals();
#endif /* XMLSEC_NO_XSLT */
xmlCleanupParser();

return(0);
}

/**
* sign_file:
* @tmpl_file: the signature template file name.
* @key_file: the PEM private key file name.
*
* Signs the #tmpl_file using private key from #key_file.
*
* Returns 0 on success or a negative value if an error occurs.
*/
int
sign_file(const char* tmpl_file, const char* key_file) {
xmlDocPtr doc = NULL;
xmlNodePtr node = NULL;
xmlSecDSigCtxPtr dsigCtx = NULL;
int res = -1;

assert(tmpl_file);
assert(key_file);

/* load template */
doc = xmlParseFile(tmpl_file);
if ((doc == NULL) || (xmlDocGetRootElement(doc) == NULL)){
fprintf(stderr, "Error: unable to parse file \"%s\"\n", tmpl_file);
goto done;
}

/* find start node */
node = xmlSecFindNode(xmlDocGetRootElement(doc), xmlSecNodeSignature, xmlSecDSigNs);
if(node == NULL) {
fprintf(stderr, "Error: start node not found in \"%s\"\n", tmpl_file);
goto done;
}

/* create signature context, we don't need keys manager in this example */
dsigCtx = xmlSecDSigCtxCreate(NULL);
if(dsigCtx == NULL) {
fprintf(stderr,"Error: failed to create signature context\n");
goto done;
}

/* load private key, assuming that there is not password */
dsigCtx->signKey = xmlSecCryptoAppKeyLoad(key_file, xmlSecKeyDataFormatPem, NULL, NULL, NULL);
if(dsigCtx->signKey == NULL) {
fprintf(stderr,"Error: failed to load private pem key from \"%s\"\n", key_file);
goto done;
}

/* set key name to the file name, this is just an example! */
if(xmlSecKeySetName(dsigCtx->signKey, key_file) < 0) {
fprintf(stderr,"Error: failed to set key name for key from \"%s\"\n", key_file);
goto done;
}

/* sign the template */
if(xmlSecDSigCtxSign(dsigCtx, node) < 0) {
fprintf(stderr,"Error: signature failed\n");
goto done;
}

/* print signed document to stdout */
xmlDocDump(stdout, doc);

/* success */
res = 0;

done:
/* cleanup */
if(dsigCtx != NULL) {
xmlSecDSigCtxDestroy(dsigCtx);
}

if(doc != NULL) {
xmlFreeDoc(doc);
}
return(res);
}
3 changes: 3 additions & 0 deletions recipes/xmlsec/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.2.30":
folder: all