diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/Makefile.am | 11 | ||||
-rw-r--r-- | apps/Makefile.in | 38 | ||||
-rw-r--r-- | apps/cmdline.c | 308 | ||||
-rw-r--r-- | apps/cmdline.h | 86 | ||||
-rw-r--r-- | apps/crypto.c | 356 | ||||
-rw-r--r-- | apps/crypto.h | 62 | ||||
-rw-r--r-- | apps/xmlsec.c | 2164 |
7 files changed, 1486 insertions, 1539 deletions
diff --git a/apps/Makefile.am b/apps/Makefile.am index 278ddf49..eebbccac 100644 --- a/apps/Makefile.am +++ b/apps/Makefile.am @@ -2,14 +2,12 @@ NULL = bin_PROGRAMS = xmlsec1 -XMLSEC_LIBS = $(top_builddir)/src/libxmlsec1.la - - # check if we use dynamic loading for xmlsec-crypto or not if XMLSEC_NO_APPS_CRYPTO_DYNAMIC_LOADING CRYPTO_DEPS = \ $(top_builddir)/src/$(XMLSEC_CRYPTO)/lib$(XMLSEC_CRYPTO_LIB).la \ + $(top_builddir)/src/libxmlsec1.la \ $(NULL) CRYPTO_INCLUDES = \ @@ -20,13 +18,14 @@ CRYPTO_LD_FLAGS = \ $(NULL) CRYPTO_LD_ADD = \ - $(XMLSEC_CRYPTO_LIBS) \ $(CRYPTO_DEPS) \ + $(XMLSEC_CRYPTO_LIBS) \ $(NULL) else CRYPTO_DEPS = \ + $(top_builddir)/src/libxmlsec1.la \ $(NULL) CRYPTO_INCLUDES = \ @@ -70,15 +69,13 @@ xmlsec1_LDFLAGS = \ $(NULL) xmlsec1_LDADD = \ + $(CRYPTO_LD_ADD) \ $(LIBXSLT_LIBS) \ $(LIBXML_LIBS) \ - $(CRYPTO_LD_ADD) \ - $(XMLSEC_LIBS) \ $(XMLSEC_DL_LIBS) \ $(NULL) xmlsec1_DEPENDENCIES = \ $(CRYPTO_DEPS) \ - $(XMLSEC_LIBS) \ $(NULL) diff --git a/apps/Makefile.in b/apps/Makefile.in index 82af5089..c361f4eb 100644 --- a/apps/Makefile.in +++ b/apps/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.11.1 from Makefile.am. +# Makefile.in generated by automake 1.11 from Makefile.am. # @configure_input@ # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, @@ -38,13 +38,10 @@ bin_PROGRAMS = xmlsec1$(EXEEXT) subdir = apps DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \ - $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ - $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ - $(top_srcdir)/configure.in +am__aclocal_m4_deps = $(top_srcdir)/configure.in am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) -mkinstalldirs = $(install_sh) -d +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = @@ -55,13 +52,15 @@ am_xmlsec1_OBJECTS = xmlsec.$(OBJEXT) crypto.$(OBJEXT) \ cmdline.$(OBJEXT) $(am__objects_1) xmlsec1_OBJECTS = $(am_xmlsec1_OBJECTS) am__DEPENDENCIES_1 = -@XMLSEC_NO_APPS_CRYPTO_DYNAMIC_LOADING_FALSE@am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1) +@XMLSEC_NO_APPS_CRYPTO_DYNAMIC_LOADING_FALSE@am__DEPENDENCIES_2 = $(top_builddir)/src/libxmlsec1.la \ +@XMLSEC_NO_APPS_CRYPTO_DYNAMIC_LOADING_FALSE@ $(am__DEPENDENCIES_1) @XMLSEC_NO_APPS_CRYPTO_DYNAMIC_LOADING_TRUE@am__DEPENDENCIES_2 = $(top_builddir)/src/$(XMLSEC_CRYPTO)/lib$(XMLSEC_CRYPTO_LIB).la \ +@XMLSEC_NO_APPS_CRYPTO_DYNAMIC_LOADING_TRUE@ $(top_builddir)/src/libxmlsec1.la \ @XMLSEC_NO_APPS_CRYPTO_DYNAMIC_LOADING_TRUE@ $(am__DEPENDENCIES_1) @XMLSEC_NO_APPS_CRYPTO_DYNAMIC_LOADING_FALSE@am__DEPENDENCIES_3 = $(am__DEPENDENCIES_2) \ @XMLSEC_NO_APPS_CRYPTO_DYNAMIC_LOADING_FALSE@ $(am__DEPENDENCIES_1) -@XMLSEC_NO_APPS_CRYPTO_DYNAMIC_LOADING_TRUE@am__DEPENDENCIES_3 = $(am__DEPENDENCIES_1) \ -@XMLSEC_NO_APPS_CRYPTO_DYNAMIC_LOADING_TRUE@ $(am__DEPENDENCIES_2) \ +@XMLSEC_NO_APPS_CRYPTO_DYNAMIC_LOADING_TRUE@am__DEPENDENCIES_3 = $(am__DEPENDENCIES_2) \ +@XMLSEC_NO_APPS_CRYPTO_DYNAMIC_LOADING_TRUE@ $(am__DEPENDENCIES_1) \ @XMLSEC_NO_APPS_CRYPTO_DYNAMIC_LOADING_TRUE@ $(am__DEPENDENCIES_1) xmlsec1_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(xmlsec1_LDFLAGS) \ @@ -108,10 +107,6 @@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ -GCRYPT_CFLAGS = @GCRYPT_CFLAGS@ -GCRYPT_CRYPTO_LIB = @GCRYPT_CRYPTO_LIB@ -GCRYPT_LIBS = @GCRYPT_LIBS@ -GCRYPT_MIN_VERSION = @GCRYPT_MIN_VERSION@ GNUTLS_CFLAGS = @GNUTLS_CFLAGS@ GNUTLS_CRYPTO_LIB = @GNUTLS_CRYPTO_LIB@ GNUTLS_LIBS = @GNUTLS_LIBS@ @@ -173,10 +168,8 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ -PKGCONFIG_PRESENT = @PKGCONFIG_PRESENT@ PKG_CONFIG = @PKG_CONFIG@ -PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ -PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ +PKG_CONFIG_ENABLED = @PKG_CONFIG_ENABLED@ RANLIB = @RANLIB@ RM = @RM@ SED = @SED@ @@ -203,18 +196,15 @@ XMLSEC_DL_INCLUDES = @XMLSEC_DL_INCLUDES@ XMLSEC_DL_LIBS = @XMLSEC_DL_LIBS@ XMLSEC_DOCDIR = @XMLSEC_DOCDIR@ XMLSEC_EXTRA_LDFLAGS = @XMLSEC_EXTRA_LDFLAGS@ -XMLSEC_GCRYPT_CFLAGS = @XMLSEC_GCRYPT_CFLAGS@ -XMLSEC_GCRYPT_LIBS = @XMLSEC_GCRYPT_LIBS@ XMLSEC_GNUTLS_CFLAGS = @XMLSEC_GNUTLS_CFLAGS@ XMLSEC_GNUTLS_LIBS = @XMLSEC_GNUTLS_LIBS@ XMLSEC_LIBDIR = @XMLSEC_LIBDIR@ -XMLSEC_LIBS = $(top_builddir)/src/libxmlsec1.la +XMLSEC_LIBS = @XMLSEC_LIBS@ XMLSEC_NO_AES = @XMLSEC_NO_AES@ XMLSEC_NO_APPS_CRYPTO_DYNAMIC_LOADING = @XMLSEC_NO_APPS_CRYPTO_DYNAMIC_LOADING@ XMLSEC_NO_CRYPTO_DYNAMIC_LOADING = @XMLSEC_NO_CRYPTO_DYNAMIC_LOADING@ XMLSEC_NO_DES = @XMLSEC_NO_DES@ XMLSEC_NO_DSA = @XMLSEC_NO_DSA@ -XMLSEC_NO_GCRYPT = @XMLSEC_NO_GCRYPT@ XMLSEC_NO_GNUTLS = @XMLSEC_NO_GNUTLS@ XMLSEC_NO_GOST = @XMLSEC_NO_GOST@ XMLSEC_NO_HMAC = @XMLSEC_NO_HMAC@ @@ -300,12 +290,14 @@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ NULL = @XMLSEC_NO_APPS_CRYPTO_DYNAMIC_LOADING_FALSE@CRYPTO_DEPS = \ +@XMLSEC_NO_APPS_CRYPTO_DYNAMIC_LOADING_FALSE@ $(top_builddir)/src/libxmlsec1.la \ @XMLSEC_NO_APPS_CRYPTO_DYNAMIC_LOADING_FALSE@ $(NULL) # check if we use dynamic loading for xmlsec-crypto or not @XMLSEC_NO_APPS_CRYPTO_DYNAMIC_LOADING_TRUE@CRYPTO_DEPS = \ @XMLSEC_NO_APPS_CRYPTO_DYNAMIC_LOADING_TRUE@ $(top_builddir)/src/$(XMLSEC_CRYPTO)/lib$(XMLSEC_CRYPTO_LIB).la \ +@XMLSEC_NO_APPS_CRYPTO_DYNAMIC_LOADING_TRUE@ $(top_builddir)/src/libxmlsec1.la \ @XMLSEC_NO_APPS_CRYPTO_DYNAMIC_LOADING_TRUE@ $(NULL) @XMLSEC_NO_APPS_CRYPTO_DYNAMIC_LOADING_FALSE@CRYPTO_INCLUDES = \ @@ -326,8 +318,8 @@ NULL = @XMLSEC_NO_APPS_CRYPTO_DYNAMIC_LOADING_FALSE@ $(NULL) @XMLSEC_NO_APPS_CRYPTO_DYNAMIC_LOADING_TRUE@CRYPTO_LD_ADD = \ -@XMLSEC_NO_APPS_CRYPTO_DYNAMIC_LOADING_TRUE@ $(XMLSEC_CRYPTO_LIBS) \ @XMLSEC_NO_APPS_CRYPTO_DYNAMIC_LOADING_TRUE@ $(CRYPTO_DEPS) \ +@XMLSEC_NO_APPS_CRYPTO_DYNAMIC_LOADING_TRUE@ $(XMLSEC_CRYPTO_LIBS) \ @XMLSEC_NO_APPS_CRYPTO_DYNAMIC_LOADING_TRUE@ $(NULL) INCLUDES = \ @@ -357,16 +349,14 @@ xmlsec1_LDFLAGS = \ $(NULL) xmlsec1_LDADD = \ + $(CRYPTO_LD_ADD) \ $(LIBXSLT_LIBS) \ $(LIBXML_LIBS) \ - $(CRYPTO_LD_ADD) \ - $(XMLSEC_LIBS) \ $(XMLSEC_DL_LIBS) \ $(NULL) xmlsec1_DEPENDENCIES = \ $(CRYPTO_DEPS) \ - $(XMLSEC_LIBS) \ $(NULL) all: all-am diff --git a/apps/cmdline.c b/apps/cmdline.c index b9ecafb5..fe09b7b1 100644 --- a/apps/cmdline.c +++ b/apps/cmdline.c @@ -19,18 +19,18 @@ #include "cmdline.h" -static int xmlSecAppCmdLineMatchParam (const char* argvParam, - const char* paramName, - int canHaveNameString); -static xmlSecAppCmdLineParamPtr xmlSecAppCmdLineParamsListFind (xmlSecAppCmdLineParamPtr* params, - xmlSecAppCmdLineParamTopic topics, - const char* name); -static int xmlSecAppCmdLineParamRead (xmlSecAppCmdLineParamPtr param, - const char** argv, - int argc, - int pos); -static int xmlSecAppCmdLineTimeParamRead (const char* str, - time_t* t); +static int xmlSecAppCmdLineMatchParam (const char* argvParam, + const char* paramName, + int canHaveNameString); +static xmlSecAppCmdLineParamPtr xmlSecAppCmdLineParamsListFind (xmlSecAppCmdLineParamPtr* params, + xmlSecAppCmdLineParamTopic topics, + const char* name); +static int xmlSecAppCmdLineParamRead (xmlSecAppCmdLineParamPtr param, + const char** argv, + int argc, + int pos); +static int xmlSecAppCmdLineTimeParamRead (const char* str, + time_t* t); int xmlSecAppCmdLineParamIsSet(xmlSecAppCmdLineParamPtr param) { @@ -40,8 +40,8 @@ xmlSecAppCmdLineParamIsSet(xmlSecAppCmdLineParamPtr param) { const char* xmlSecAppCmdLineParamGetString(xmlSecAppCmdLineParamPtr param) { if(param->type != xmlSecAppCmdLineParamTypeString) { - fprintf(stderr, "Error: parameter \"%s\" is not string.\n", param->fullName); - return(NULL); + fprintf(stderr, "Error: parameter \"%s\" is not string.\n", param->fullName); + return(NULL); } return((param->value != NULL) ? param->value->strValue : NULL); } @@ -49,8 +49,8 @@ xmlSecAppCmdLineParamGetString(xmlSecAppCmdLineParamPtr param) { const char* xmlSecAppCmdLineParamGetStringList(xmlSecAppCmdLineParamPtr param) { if(param->type != xmlSecAppCmdLineParamTypeStringList) { - fprintf(stderr, "Error: parameter \"%s\" is not string list.\n", param->fullName); - return(NULL); + fprintf(stderr, "Error: parameter \"%s\" is not string list.\n", param->fullName); + return(NULL); } return((param->value != NULL) ? param->value->strListValue : NULL); } @@ -58,8 +58,8 @@ xmlSecAppCmdLineParamGetStringList(xmlSecAppCmdLineParamPtr param) { int xmlSecAppCmdLineParamGetInt(xmlSecAppCmdLineParamPtr param, int def) { if(param->type != xmlSecAppCmdLineParamTypeNumber) { - fprintf(stderr, "Error: parameter \"%s\" is not integer.\n", param->fullName); - return(def); + fprintf(stderr, "Error: parameter \"%s\" is not integer.\n", param->fullName); + return(def); } return((param->value != NULL) ? param->value->intValue : def); } @@ -67,16 +67,16 @@ xmlSecAppCmdLineParamGetInt(xmlSecAppCmdLineParamPtr param, int def) { time_t xmlSecAppCmdLineParamGetTime(xmlSecAppCmdLineParamPtr param, time_t def) { if(param->type != xmlSecAppCmdLineParamTypeTime) { - fprintf(stderr, "Error: parameter \"%s\" is not time.\n", param->fullName); - return(def); + fprintf(stderr, "Error: parameter \"%s\" is not time.\n", param->fullName); + return(def); } return((param->value != NULL) ? param->value->timeValue : def); } int xmlSecAppCmdLineParamsListParse(xmlSecAppCmdLineParamPtr* params, - xmlSecAppCmdLineParamTopic topics, - const char** argv, int argc, int pos) { + xmlSecAppCmdLineParamTopic topics, + const char** argv, int argc, int pos) { xmlSecAppCmdLineParamPtr param; int ii; int ret; @@ -85,27 +85,27 @@ xmlSecAppCmdLineParamsListParse(xmlSecAppCmdLineParamPtr* params, assert(argv != NULL); while((pos < argc) && (argv[pos][0] == '-')) { - param = xmlSecAppCmdLineParamsListFind(params, topics, argv[pos]); - if(param == NULL) { - fprintf(stderr, "Error: parameter \"%s\" is not supported or the requested\nfeature might have been disabled during compilation.\n", argv[pos]); - return(-1); - } - - ret = xmlSecAppCmdLineParamRead(param, argv, argc, pos); - if(ret < pos) { - fprintf(stderr, "Error: failed to parse parameter \"%s\".\n", argv[pos]); - return(-1); - } - pos = ret + 1; + param = xmlSecAppCmdLineParamsListFind(params, topics, argv[pos]); + if(param == NULL) { + fprintf(stderr, "Error: parameter \"%s\" is not supported or the requested\nfeature might have been disabled during compilation.\n", argv[pos]); + return(-1); + } + + ret = xmlSecAppCmdLineParamRead(param, argv, argc, pos); + if(ret < pos) { + fprintf(stderr, "Error: failed to parse parameter \"%s\".\n", argv[pos]); + return(-1); + } + pos = ret + 1; } /* check that all parameters at the end are filenames */ for(ii = pos; (ii < argc); ++ii) { - if(argv[ii][0] == '-') { - fprintf(stderr, "Error: filename is expected instead of parameter \"%s\".\n", argv[ii]); - return(-1); - - } + if(argv[ii][0] == '-') { + fprintf(stderr, "Error: filename is expected instead of parameter \"%s\".\n", argv[ii]); + return(-1); + + } } @@ -121,27 +121,27 @@ xmlSecAppCmdLineParamsListClean(xmlSecAppCmdLineParamPtr* params) { assert(params != NULL); for(i = 0; params[i] != NULL; ++i) { - while(params[i]->value != NULL) { - tmp = params[i]->value; - params[i]->value = params[i]->value->next; - xmlSecAppCmdLineValueDestroy(tmp); - } + while(params[i]->value != NULL) { + tmp = params[i]->value; + params[i]->value = params[i]->value->next; + xmlSecAppCmdLineValueDestroy(tmp); + } } } void xmlSecAppCmdLineParamsListPrint(xmlSecAppCmdLineParamPtr* params, - xmlSecAppCmdLineParamTopic topics, - FILE* output) { + xmlSecAppCmdLineParamTopic topics, + FILE* output) { size_t i; assert(params != NULL); assert(output != NULL); for(i = 0; params[i] != NULL; ++i) { - if(((params[i]->topics & topics) != 0) && (params[i]->help != NULL)) { - fprintf(output, " %s\n", params[i]->help); - } + if(((params[i]->topics & topics) != 0) && (params[i]->help != NULL)) { + fprintf(output, " %s\n", params[i]->help); + } } } @@ -152,8 +152,8 @@ xmlSecAppCmdLineValueCreate(xmlSecAppCmdLineParamPtr param, int pos) { assert(param != NULL); value = (xmlSecAppCmdLineValuePtr) malloc(sizeof(xmlSecAppCmdLineValue)); if(value == NULL) { - fprintf(stderr, "Error: malloc failed (%d bytes).\n", sizeof(xmlSecAppCmdLineValue)); - return(NULL); + fprintf(stderr, "Error: malloc failed (%d bytes).\n", sizeof(xmlSecAppCmdLineValue)); + return(NULL); } memset(value, 0, sizeof(xmlSecAppCmdLineValue)); @@ -167,34 +167,34 @@ xmlSecAppCmdLineValueDestroy(xmlSecAppCmdLineValuePtr value) { assert(value != NULL); if(value->strListValue != NULL) { - free((void*)value->strListValue); + free((void*)value->strListValue); } free(value); } static int xmlSecAppCmdLineMatchParam(const char* argvParam, const char* paramName, - int canHaveNameString) { + int canHaveNameString) { assert(argvParam != NULL); assert(paramName != NULL); if(canHaveNameString != 0) { - int len = strlen(paramName); - - if((strncmp(argvParam, paramName, len) == 0) && - ((argvParam[len] == '\0') || (argvParam[len] == ':'))) { - - return(1); - } + int len = strlen(paramName); + + if((strncmp(argvParam, paramName, len) == 0) && + ((argvParam[len] == '\0') || (argvParam[len] == ':'))) { + + return(1); + } } else if(strcmp(argvParam, paramName) == 0) { - return(1); + return(1); } return(0); } -static xmlSecAppCmdLineParamPtr +static xmlSecAppCmdLineParamPtr xmlSecAppCmdLineParamsListFind(xmlSecAppCmdLineParamPtr* params, xmlSecAppCmdLineParamTopic topics, - const char* name) { + const char* name) { size_t i; int canHaveNameString; @@ -202,22 +202,22 @@ xmlSecAppCmdLineParamsListFind(xmlSecAppCmdLineParamPtr* params, xmlSecAppCmdLin assert(name != NULL); for(i = 0; params[i] != NULL; ++i) { - if((params[i]->topics & topics) == 0) { - continue; - } + if((params[i]->topics & topics) == 0) { + continue; + } - canHaveNameString = ((params[i]->flags & xmlSecAppCmdLineParamFlagParamNameValue) != 0) ? 1 : 0; - if((params[i]->fullName != NULL) && - (xmlSecAppCmdLineMatchParam(name, params[i]->fullName, canHaveNameString) == 1)) { - - return(params[i]); - } + canHaveNameString = ((params[i]->flags & xmlSecAppCmdLineParamFlagParamNameValue) != 0) ? 1 : 0; + if((params[i]->fullName != NULL) && + (xmlSecAppCmdLineMatchParam(name, params[i]->fullName, canHaveNameString) == 1)) { + + return(params[i]); + } - if((params[i]->shortName != NULL) && - (xmlSecAppCmdLineMatchParam(name, params[i]->shortName, canHaveNameString) == 1)) { - - return(params[i]); - } + if((params[i]->shortName != NULL) && + (xmlSecAppCmdLineMatchParam(name, params[i]->shortName, canHaveNameString) == 1)) { + + return(params[i]); + } } return(NULL); @@ -235,90 +235,90 @@ xmlSecAppCmdLineParamRead(xmlSecAppCmdLineParamPtr param, const char** argv, int /* first find the previous value in the list */ if((param->flags & xmlSecAppCmdLineParamFlagMultipleValues) != 0) { - prev = param->value; - while((prev != NULL) && (prev->next != NULL)) { - prev = prev->next; - } + prev = param->value; + while((prev != NULL) && (prev->next != NULL)) { + prev = prev->next; + } } else if(param->value != NULL) { - fprintf(stderr, "Error: only one parameter \"%s\" is allowed.\n", argv[pos]); - return(-1); + fprintf(stderr, "Error: only one parameter \"%s\" is allowed.\n", argv[pos]); + return(-1); } /* create new value and add to the list */ value = xmlSecAppCmdLineValueCreate(param, pos); if(value == NULL) { - fprintf(stderr, "Error: failed to create value for parameter \"%s\".\n", argv[pos]); - return(-1); + fprintf(stderr, "Error: failed to create value for parameter \"%s\".\n", argv[pos]); + return(-1); } if(prev != NULL) { - assert(prev->next == NULL); - prev->next = value; + assert(prev->next == NULL); + prev->next = value; } else { - param->value = value; + param->value = value; } /* if we can have a string value after the name, parse it */ if((param->flags & xmlSecAppCmdLineParamFlagParamNameValue) != 0) { - value->paramNameValue = strchr(argv[pos], ':'); - if(value->paramNameValue != NULL) { - ++value->paramNameValue; - } + value->paramNameValue = strchr(argv[pos], ':'); + if(value->paramNameValue != NULL) { + ++value->paramNameValue; + } } switch(param->type) { - case xmlSecAppCmdLineParamTypeFlag: - /* do nothing */ - break; - case xmlSecAppCmdLineParamTypeString: - if(pos + 1 >= argc) { - fprintf(stderr, "Error: string argument expected for parameter \"%s\".\n", argv[pos]); - return(-1); - } - value->strValue = argv[++pos]; - break; - case xmlSecAppCmdLineParamTypeStringList: - if(pos + 1 >= argc) { - fprintf(stderr, "Error: string list argument expected for parameter \"%s\".\n", argv[pos]); - return(-1); - } - value->strValue = argv[++pos]; - buf = (char*)malloc(strlen(value->strValue) + 2); - if(buf == NULL) { - fprintf(stderr, "Error: failed to allocate memory (%d bytes).\n", strlen(value->strValue) + 2); - return(-1); - } - memset(buf, 0, strlen(value->strValue) + 2); - memcpy(buf, value->strValue, strlen(value->strValue)); - value->strListValue = buf; - while((*buf) != '\0') { - if((*buf) == ',') { - (*buf) = '\0'; - } - ++buf; - } - break; - case xmlSecAppCmdLineParamTypeNumber: - if(pos + 1 >= argc) { - fprintf(stderr, "Error: integer argument expected for parameter \"%s\".\n", argv[pos]); - return(-1); - } - value->strValue = argv[++pos]; - if(sscanf(value->strValue, "%d", &(value->intValue)) != 1) { - fprintf(stderr, "Error: integer argument \"%s\" is invalid.\n", value->strValue); - return(-1); - } - break; - case xmlSecAppCmdLineParamTypeTime: - if(pos + 1 >= argc) { - fprintf(stderr, "Error: time argument expected for parameter \"%s\".\n", argv[pos]); - return(-1); - } - value->strValue = argv[++pos]; - if(xmlSecAppCmdLineTimeParamRead(value->strValue, &(value->timeValue)) < 0) { - fprintf(stderr, "Error: time argument \"%s\" is invalid, expected format is \"YYYY-MM-DD HH:MM:SS\").\n", value->strValue); - return(-1); - } - break; + case xmlSecAppCmdLineParamTypeFlag: + /* do nothing */ + break; + case xmlSecAppCmdLineParamTypeString: + if(pos + 1 >= argc) { + fprintf(stderr, "Error: string argument expected for parameter \"%s\".\n", argv[pos]); + return(-1); + } + value->strValue = argv[++pos]; + break; + case xmlSecAppCmdLineParamTypeStringList: + if(pos + 1 >= argc) { + fprintf(stderr, "Error: string list argument expected for parameter \"%s\".\n", argv[pos]); + return(-1); + } + value->strValue = argv[++pos]; + buf = (char*)malloc(strlen(value->strValue) + 2); + if(buf == NULL) { + fprintf(stderr, "Error: failed to allocate memory (%d bytes).\n", strlen(value->strValue) + 2); + return(-1); + } + memset(buf, 0, strlen(value->strValue) + 2); + memcpy(buf, value->strValue, strlen(value->strValue)); + value->strListValue = buf; + while((*buf) != '\0') { + if((*buf) == ',') { + (*buf) = '\0'; + } + ++buf; + } + break; + case xmlSecAppCmdLineParamTypeNumber: + if(pos + 1 >= argc) { + fprintf(stderr, "Error: integer argument expected for parameter \"%s\".\n", argv[pos]); + return(-1); + } + value->strValue = argv[++pos]; + if(sscanf(value->strValue, "%d", &(value->intValue)) != 1) { + fprintf(stderr, "Error: integer argument \"%s\" is invalid.\n", value->strValue); + return(-1); + } + break; + case xmlSecAppCmdLineParamTypeTime: + if(pos + 1 >= argc) { + fprintf(stderr, "Error: time argument expected for parameter \"%s\".\n", argv[pos]); + return(-1); + } + value->strValue = argv[++pos]; + if(xmlSecAppCmdLineTimeParamRead(value->strValue, &(value->timeValue)) < 0) { + fprintf(stderr, "Error: time argument \"%s\" is invalid, expected format is \"YYYY-MM-DD HH:MM:SS\").\n", value->strValue); + return(-1); + } + break; } return(pos); } @@ -329,21 +329,21 @@ xmlSecAppCmdLineTimeParamRead(const char* str, time_t* t) { int n; if((str == NULL) || (t == NULL)) { - return(-1); + return(-1); } memset(&tm, 0, sizeof(tm)); tm.tm_isdst = -1; n = sscanf(str, "%4d-%2d-%2d%*c%2d:%2d:%2d", - &tm.tm_year, &tm.tm_mon, &tm.tm_mday, - &tm.tm_hour, &tm.tm_min, &tm.tm_sec); + &tm.tm_year, &tm.tm_mon, &tm.tm_mday, + &tm.tm_hour, &tm.tm_min, &tm.tm_sec); if((n != 6) || (tm.tm_year < 1900) - || (tm.tm_mon < 1) || (tm.tm_mon > 12) - || (tm.tm_mday < 1) || (tm.tm_mday > 31) - || (tm.tm_hour < 0) || (tm.tm_hour > 23) - || (tm.tm_min < 0) || (tm.tm_min > 59) - || (tm.tm_sec < 0) || (tm.tm_sec > 61)) { - return(-1); + || (tm.tm_mon < 1) || (tm.tm_mon > 12) + || (tm.tm_mday < 1) || (tm.tm_mday > 31) + || (tm.tm_hour < 0) || (tm.tm_hour > 23) + || (tm.tm_min < 0) || (tm.tm_min > 59) + || (tm.tm_sec < 0) || (tm.tm_sec > 61)) { + return(-1); } tm.tm_year -= 1900; /* tm relative format year */ diff --git a/apps/cmdline.h b/apps/cmdline.h index 9466f972..60391222 100644 --- a/apps/cmdline.h +++ b/apps/cmdline.h @@ -16,15 +16,15 @@ extern "C" { #include <time.h> -typedef struct _xmlSecAppCmdLineParam xmlSecAppCmdLineParam, - *xmlSecAppCmdLineParamPtr; -typedef struct _xmlSecAppCmdLineValue xmlSecAppCmdLineValue, - *xmlSecAppCmdLineValuePtr; -typedef unsigned int xmlSecAppCmdLineParamTopic; +typedef struct _xmlSecAppCmdLineParam xmlSecAppCmdLineParam, + *xmlSecAppCmdLineParamPtr; +typedef struct _xmlSecAppCmdLineValue xmlSecAppCmdLineValue, + *xmlSecAppCmdLineValuePtr; +typedef unsigned int xmlSecAppCmdLineParamTopic; -#define xmlSecAppCmdLineParamFlagNone 0x0000 -#define xmlSecAppCmdLineParamFlagParamNameValue 0x0001 -#define xmlSecAppCmdLineParamFlagMultipleValues 0x0002 +#define xmlSecAppCmdLineParamFlagNone 0x0000 +#define xmlSecAppCmdLineParamFlagParamNameValue 0x0001 +#define xmlSecAppCmdLineParamFlagMultipleValues 0x0002 typedef enum { xmlSecAppCmdLineParamTypeFlag, @@ -35,48 +35,48 @@ typedef enum { } xmlSecAppCmdLineParamType; struct _xmlSecAppCmdLineParam { - xmlSecAppCmdLineParamTopic topics; - const char* fullName; - const char* shortName; - const char* help; - xmlSecAppCmdLineParamType type; - int flags; - xmlSecAppCmdLineValuePtr value; + xmlSecAppCmdLineParamTopic topics; + const char* fullName; + const char* shortName; + const char* help; + xmlSecAppCmdLineParamType type; + int flags; + xmlSecAppCmdLineValuePtr value; }; -int xmlSecAppCmdLineParamIsSet (xmlSecAppCmdLineParamPtr param); -const char* xmlSecAppCmdLineParamGetString (xmlSecAppCmdLineParamPtr param); -const char* xmlSecAppCmdLineParamGetStringList (xmlSecAppCmdLineParamPtr param); -int xmlSecAppCmdLineParamGetInt (xmlSecAppCmdLineParamPtr param, - int def); -time_t xmlSecAppCmdLineParamGetTime (xmlSecAppCmdLineParamPtr param, - time_t def); - -int xmlSecAppCmdLineParamsListParse (xmlSecAppCmdLineParamPtr* params, - xmlSecAppCmdLineParamTopic topcis, - const char** argv, - int argc, - int pos); -void xmlSecAppCmdLineParamsListClean (xmlSecAppCmdLineParamPtr* params); -void xmlSecAppCmdLineParamsListPrint (xmlSecAppCmdLineParamPtr* params, - xmlSecAppCmdLineParamTopic topic, - FILE* output); +int xmlSecAppCmdLineParamIsSet (xmlSecAppCmdLineParamPtr param); +const char* xmlSecAppCmdLineParamGetString (xmlSecAppCmdLineParamPtr param); +const char* xmlSecAppCmdLineParamGetStringList (xmlSecAppCmdLineParamPtr param); +int xmlSecAppCmdLineParamGetInt (xmlSecAppCmdLineParamPtr param, + int def); +time_t xmlSecAppCmdLineParamGetTime (xmlSecAppCmdLineParamPtr param, + time_t def); + +int xmlSecAppCmdLineParamsListParse (xmlSecAppCmdLineParamPtr* params, + xmlSecAppCmdLineParamTopic topcis, + const char** argv, + int argc, + int pos); +void xmlSecAppCmdLineParamsListClean (xmlSecAppCmdLineParamPtr* params); +void xmlSecAppCmdLineParamsListPrint (xmlSecAppCmdLineParamPtr* params, + xmlSecAppCmdLineParamTopic topic, + FILE* output); struct _xmlSecAppCmdLineValue { - xmlSecAppCmdLineParamPtr param; - int pos; - const char* paramNameValue; - const char* strValue; - const char* strListValue; - int intValue; - time_t timeValue; - xmlSecAppCmdLineValuePtr next; + xmlSecAppCmdLineParamPtr param; + int pos; + const char* paramNameValue; + const char* strValue; + const char* strListValue; + int intValue; + time_t timeValue; + xmlSecAppCmdLineValuePtr next; }; -xmlSecAppCmdLineValuePtr xmlSecAppCmdLineValueCreate (xmlSecAppCmdLineParamPtr param, - int pos); -void xmlSecAppCmdLineValueDestroy (xmlSecAppCmdLineValuePtr value); +xmlSecAppCmdLineValuePtr xmlSecAppCmdLineValueCreate (xmlSecAppCmdLineParamPtr param, + int pos); +void xmlSecAppCmdLineValueDestroy (xmlSecAppCmdLineValuePtr value); #ifdef __cplusplus diff --git a/apps/crypto.c b/apps/crypto.c index 49dd127c..5e3d5ca3 100644 --- a/apps/crypto.c +++ b/apps/crypto.c @@ -23,20 +23,20 @@ int xmlSecAppCryptoInit(const char* config) { if(xmlSecCryptoAppInit(config) < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecCryptoAppInit", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); - return(-1); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecCryptoAppInit", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + XMLSEC_ERRORS_NO_MESSAGE); + return(-1); } if(xmlSecCryptoInit() < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecCryptoInit", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); - return(-1); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecCryptoInit", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + XMLSEC_ERRORS_NO_MESSAGE); + return(-1); } return(0); @@ -45,21 +45,21 @@ xmlSecAppCryptoInit(const char* config) { int xmlSecAppCryptoShutdown(void) { if(xmlSecCryptoShutdown() < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecCryptoShutdown", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); - return(-1); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecCryptoShutdown", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + XMLSEC_ERRORS_NO_MESSAGE); + return(-1); } if(xmlSecCryptoAppShutdown() < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecCryptoAppShutdown", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); - return(-1); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecCryptoAppShutdown", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + XMLSEC_ERRORS_NO_MESSAGE); + return(-1); } return(0); } @@ -89,11 +89,11 @@ xmlSecAppCryptoSimpleKeysMngrSave(xmlSecKeysMngrPtr mngr, const char *filename, int xmlSecAppCryptoSimpleKeysMngrCertLoad(xmlSecKeysMngrPtr mngr, const char *filename, - xmlSecKeyDataFormat format, xmlSecKeyDataType type) { + xmlSecKeyDataFormat format, xmlSecKeyDataType type) { xmlSecAssert2(mngr != NULL, -1); xmlSecAssert2(filename != NULL, -1); -#ifndef XMLSEC_NO_X509 +#ifndef XMLSEC_NO_X509 return(xmlSecCryptoAppKeysMngrCertLoad(mngr, filename, format, type)); #else /* XMLSEC_NO_X509 */ return(-1); @@ -102,9 +102,9 @@ xmlSecAppCryptoSimpleKeysMngrCertLoad(xmlSecKeysMngrPtr mngr, const char *filena int xmlSecAppCryptoSimpleKeysMngrKeyAndCertsLoad(xmlSecKeysMngrPtr mngr, - const char* files, const char* pwd, - const char* name, - xmlSecKeyDataFormat format) { + const char* files, const char* pwd, + const char* name, + xmlSecKeyDataFormat format) { xmlSecKeyPtr key; int ret; @@ -113,66 +113,66 @@ xmlSecAppCryptoSimpleKeysMngrKeyAndCertsLoad(xmlSecKeysMngrPtr mngr, /* first is the key file */ key = xmlSecCryptoAppKeyLoad(files, format, pwd, - xmlSecCryptoAppGetDefaultPwdCallback(), (void*)files); + xmlSecCryptoAppGetDefaultPwdCallback(), (void*)files); if(key == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecCryptoAppKeyLoad", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "uri=%s", - xmlSecErrorsSafeString(files)); - return(-1); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecCryptoAppKeyLoad", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + "uri=%s", + xmlSecErrorsSafeString(files)); + return(-1); } if(name != NULL) { - ret = xmlSecKeySetName(key, BAD_CAST name); - if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecKeySetName", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "name=%s", - xmlSecErrorsSafeString(name)); - xmlSecKeyDestroy(key); - return(-1); - } + ret = xmlSecKeySetName(key, BAD_CAST name); + if(ret < 0) { + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecKeySetName", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + "name=%s", + xmlSecErrorsSafeString(name)); + xmlSecKeyDestroy(key); + return(-1); + } } #ifndef XMLSEC_NO_X509 for(files += strlen(files) + 1; (files[0] != '\0'); files += strlen(files) + 1) { - ret = xmlSecCryptoAppKeyCertLoad(key, files, format); - if(ret < 0){ - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecCryptoAppKeyCertLoad", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "uri=%s", - xmlSecErrorsSafeString(files)); - xmlSecKeyDestroy(key); - return(-1); - } + ret = xmlSecCryptoAppKeyCertLoad(key, files, format); + if(ret < 0){ + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecCryptoAppKeyCertLoad", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + "uri=%s", + xmlSecErrorsSafeString(files)); + xmlSecKeyDestroy(key); + return(-1); + } } #else /* XMLSEC_NO_X509 */ files += strlen(files) + 1; if(files[0] != '\0') { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "x509", - XMLSEC_ERRORS_R_DISABLED, - XMLSEC_ERRORS_NO_MESSAGE); - return(-1); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "x509", + XMLSEC_ERRORS_R_DISABLED, + XMLSEC_ERRORS_NO_MESSAGE); + return(-1); } #endif /* XMLSEC_NO_X509 */ ret = xmlSecCryptoAppDefaultKeysMngrAdoptKey(mngr, key); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecCryptoAppDefaultKeysMngrAdoptKey", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); - xmlSecKeyDestroy(key); - return(-1); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecCryptoAppDefaultKeysMngrAdoptKey", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + XMLSEC_ERRORS_NO_MESSAGE); + xmlSecKeyDestroy(key); + return(-1); } return(0); @@ -189,49 +189,49 @@ xmlSecAppCryptoSimpleKeysMngrPkcs12KeyLoad(xmlSecKeysMngrPtr mngr, const char *f #ifndef XMLSEC_NO_X509 key = xmlSecCryptoAppKeyLoad(filename, xmlSecKeyDataFormatPkcs12, pwd, - xmlSecCryptoAppGetDefaultPwdCallback(), (void*)filename); + xmlSecCryptoAppGetDefaultPwdCallback(), (void*)filename); if(key == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecCryptoAppKeyLoad", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "filename=%s", - xmlSecErrorsSafeString(filename)); - return(-1); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecCryptoAppKeyLoad", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + "filename=%s", + xmlSecErrorsSafeString(filename)); + return(-1); } if(name != NULL) { - ret = xmlSecKeySetName(key, BAD_CAST name); - if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecKeySetName", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "name=%s", - xmlSecErrorsSafeString(name)); - xmlSecKeyDestroy(key); - return(-1); - } + ret = xmlSecKeySetName(key, BAD_CAST name); + if(ret < 0) { + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecKeySetName", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + "name=%s", + xmlSecErrorsSafeString(name)); + xmlSecKeyDestroy(key); + return(-1); + } } ret = xmlSecCryptoAppDefaultKeysMngrAdoptKey(mngr, key); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecCryptoAppDefaultKeysMngrAdoptKey", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); - xmlSecKeyDestroy(key); - return(-1); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecCryptoAppDefaultKeysMngrAdoptKey", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + XMLSEC_ERRORS_NO_MESSAGE); + xmlSecKeyDestroy(key); + return(-1); } return(0); #else /* XMLSEC_NO_X509 */ xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "x509", - XMLSEC_ERRORS_R_DISABLED, - XMLSEC_ERRORS_NO_MESSAGE); + NULL, + "x509", + XMLSEC_ERRORS_R_DISABLED, + XMLSEC_ERRORS_NO_MESSAGE); return(-1); #endif /* XMLSEC_NO_X509 */ } @@ -248,49 +248,49 @@ xmlSecAppCryptoSimpleKeysMngrBinaryKeyLoad(xmlSecKeysMngrPtr mngr, const char* k /* find requested data */ dataId = xmlSecKeyDataIdListFindByName(xmlSecKeyDataIdsGet(), BAD_CAST keyKlass, - xmlSecKeyDataUsageAny); + xmlSecKeyDataUsageAny); if(dataId == xmlSecKeyDataIdUnknown) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecKeyDataIdListFindByName", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "name=%s", - xmlSecErrorsSafeString(keyKlass)); - return(-1); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecKeyDataIdListFindByName", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + "name=%s", + xmlSecErrorsSafeString(keyKlass)); + return(-1); } key = xmlSecKeyReadBinaryFile(dataId, filename); if(key == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecKeyReadBinaryFile", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); - return(-1); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecKeyReadBinaryFile", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + XMLSEC_ERRORS_NO_MESSAGE); + return(-1); } ret = xmlSecKeySetName(key, BAD_CAST name); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecKeySetName", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "name=%s", - xmlSecErrorsSafeString(name)); - xmlSecKeyDestroy(key); - return(-1); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecKeySetName", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + "name=%s", + xmlSecErrorsSafeString(name)); + xmlSecKeyDestroy(key); + return(-1); } /* finally add it to keys manager */ ret = xmlSecCryptoAppDefaultKeysMngrAdoptKey(mngr, key); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecCryptoAppDefaultKeysMngrAdoptKey", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); - xmlSecKeyDestroy(key); - return(-1); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecCryptoAppDefaultKeysMngrAdoptKey", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + XMLSEC_ERRORS_NO_MESSAGE); + xmlSecKeyDestroy(key); + return(-1); } return(0); @@ -307,24 +307,24 @@ xmlSecAppCryptoSimpleKeysMngrKeyGenerate(xmlSecKeysMngrPtr mngr, const char* key key = xmlSecAppCryptoKeyGenerate(keyKlassAndSize, name, xmlSecKeyDataTypePermanent); if(key == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecAppCryptoSimpleKeysMngrKeyGenerate", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "name=%s", - xmlSecErrorsSafeString(name)); - return(-1); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecAppCryptoSimpleKeysMngrKeyGenerate", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + "name=%s", + xmlSecErrorsSafeString(name)); + return(-1); } ret = xmlSecCryptoAppDefaultKeysMngrAdoptKey(mngr, key); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecCryptoAppDefaultKeysMngrAdoptKey", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - XMLSEC_ERRORS_NO_MESSAGE); - xmlSecKeyDestroy(key); - return(-1); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecCryptoAppDefaultKeysMngrAdoptKey", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + XMLSEC_ERRORS_NO_MESSAGE); + xmlSecKeyDestroy(key); + return(-1); } return(0); } @@ -341,54 +341,54 @@ xmlSecAppCryptoKeyGenerate(const char* keyKlassAndSize, const char* name, xmlSec buf = (char*) xmlStrdup(BAD_CAST keyKlassAndSize); if(buf == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - NULL, - XMLSEC_ERRORS_R_STRDUP_FAILED, - "name=%s", - xmlSecErrorsSafeString(name)); - return(NULL); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + NULL, + XMLSEC_ERRORS_R_STRDUP_FAILED, + "name=%s", + xmlSecErrorsSafeString(name)); + return(NULL); } /* separate key klass and size */ p = strchr(buf, '-'); if(p == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - NULL, - XMLSEC_ERRORS_R_INVALID_DATA, - "key size is not specified %s", - xmlSecErrorsSafeString(buf)); - xmlFree(buf); - return(NULL); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + NULL, + XMLSEC_ERRORS_R_INVALID_DATA, + "key size is not specified %s", + xmlSecErrorsSafeString(buf)); + xmlFree(buf); + return(NULL); } *(p++) = '\0'; size = atoi(p); key = xmlSecKeyGenerateByName(BAD_CAST buf, size, type); if(key == NULL) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecKeyGenerate", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "klass=%s;size=%d", - xmlSecErrorsSafeString(buf), - size); - xmlFree(buf); - return(NULL); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecKeyGenerate", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + "klass=%s;size=%d", + xmlSecErrorsSafeString(buf), + size); + xmlFree(buf); + return(NULL); } ret = xmlSecKeySetName(key, BAD_CAST name); if(ret < 0) { - xmlSecError(XMLSEC_ERRORS_HERE, - NULL, - "xmlSecKeySetName", - XMLSEC_ERRORS_R_XMLSEC_FAILED, - "name=\"%s\"", - xmlSecErrorsSafeString(name)); - xmlSecKeyDestroy(key); - xmlFree(buf); - return(NULL); + xmlSecError(XMLSEC_ERRORS_HERE, + NULL, + "xmlSecKeySetName", + XMLSEC_ERRORS_R_XMLSEC_FAILED, + "name=\"%s\"", + xmlSecErrorsSafeString(name)); + xmlSecKeyDestroy(key); + xmlFree(buf); + return(NULL); } xmlFree(buf); diff --git a/apps/crypto.h b/apps/crypto.h index 63a94a40..1ce2c3e9 100644 --- a/apps/crypto.h +++ b/apps/crypto.h @@ -20,44 +20,44 @@ extern "C" { #include <xmlsec/keysmngr.h> #include <xmlsec/crypto.h> -int xmlSecAppCryptoInit (const char* config); -int xmlSecAppCryptoShutdown (void); +int xmlSecAppCryptoInit (const char* config); +int xmlSecAppCryptoShutdown (void); -xmlSecKeyPtr xmlSecAppCryptoKeyGenerate (const char* keyKlassAndSize, - const char* name, - xmlSecKeyDataType type); +xmlSecKeyPtr xmlSecAppCryptoKeyGenerate (const char* keyKlassAndSize, + const char* name, + xmlSecKeyDataType type); /***************************************************************************** * * Simple keys manager * ****************************************************************************/ -int xmlSecAppCryptoSimpleKeysMngrInit (xmlSecKeysMngrPtr mngr); -int xmlSecAppCryptoSimpleKeysMngrLoad (xmlSecKeysMngrPtr mngr, - const char *filename); -int xmlSecAppCryptoSimpleKeysMngrSave (xmlSecKeysMngrPtr mngr, - const char *filename, - xmlSecKeyDataType type); -int xmlSecAppCryptoSimpleKeysMngrCertLoad (xmlSecKeysMngrPtr mngr, - const char *filename, - xmlSecKeyDataFormat format, - xmlSecKeyDataType type); -int xmlSecAppCryptoSimpleKeysMngrKeyAndCertsLoad (xmlSecKeysMngrPtr mngr, - const char *files, - const char* pwd, - const char* name, - xmlSecKeyDataFormat format); -int xmlSecAppCryptoSimpleKeysMngrPkcs12KeyLoad (xmlSecKeysMngrPtr mngr, - const char *filename, - const char* pwd, - const char *name); -int xmlSecAppCryptoSimpleKeysMngrBinaryKeyLoad (xmlSecKeysMngrPtr mngr, - const char* keyKlass, - const char* filename, - const char *name); -int xmlSecAppCryptoSimpleKeysMngrKeyGenerate (xmlSecKeysMngrPtr mngr, - const char* keyKlassAndSize, - const char* name); +int xmlSecAppCryptoSimpleKeysMngrInit (xmlSecKeysMngrPtr mngr); +int xmlSecAppCryptoSimpleKeysMngrLoad (xmlSecKeysMngrPtr mngr, + const char *filename); +int xmlSecAppCryptoSimpleKeysMngrSave (xmlSecKeysMngrPtr mngr, + const char *filename, + xmlSecKeyDataType type); +int xmlSecAppCryptoSimpleKeysMngrCertLoad (xmlSecKeysMngrPtr mngr, + const char *filename, + xmlSecKeyDataFormat format, + xmlSecKeyDataType type); +int xmlSecAppCryptoSimpleKeysMngrKeyAndCertsLoad (xmlSecKeysMngrPtr mngr, + const char *files, + const char* pwd, + const char* name, + xmlSecKeyDataFormat format); +int xmlSecAppCryptoSimpleKeysMngrPkcs12KeyLoad (xmlSecKeysMngrPtr mngr, + const char *filename, + const char* pwd, + const char *name); +int xmlSecAppCryptoSimpleKeysMngrBinaryKeyLoad (xmlSecKeysMngrPtr mngr, + const char* keyKlass, + const char* filename, + const char *name); +int xmlSecAppCryptoSimpleKeysMngrKeyGenerate (xmlSecKeysMngrPtr mngr, + const char* keyKlassAndSize, + const char* name); #ifdef __cplusplus diff --git a/apps/xmlsec.c b/apps/xmlsec.c index d551b5a6..f2fa9f64 100644 --- a/apps/xmlsec.c +++ b/apps/xmlsec.c @@ -24,7 +24,6 @@ #include <libxslt/extensions.h> #include <libxslt/xsltInternals.h> #include <libxslt/xsltutils.h> -#include <libxslt/security.h> #include <libexslt/exslt.h> #endif /* XMLSEC_NO_XSLT */ @@ -57,23 +56,23 @@ static const char helpCommands1[] = "\n" "xmlsec is a command line tool for signing, verifying, encrypting and\n" "decrypting XML documents. The allowed <command> values are:\n" - " --help " "\tdisplay this help information and exit\n" - " --help-all " "\tdisplay help information for all commands/options and exit\n" - " --help-<cmd>" "\tdisplay help information for command <cmd> and exit\n" - " --version " "\tprint version information and exit\n" - " --keys " "\tkeys XML file manipulation\n"; + " --help " "\tdisplay this help information and exit\n" + " --help-all " "\tdisplay help information for all commands/options and exit\n" + " --help-<cmd>" "\tdisplay help information for command <cmd> and exit\n" + " --version " "\tprint version information and exit\n" + " --keys " "\tkeys XML file manipulation\n"; static const char helpCommands2[] = #ifndef XMLSEC_NO_XMLDSIG - " --sign " "\tsign data and output XML document\n" - " --verify " "\tverify signed document\n" + " --sign " "\tsign data and output XML document\n" + " --verify " "\tverify signed document\n" #ifndef XMLSEC_NO_TMPL_TEST - " --sign-tmpl " "\tcreate and sign dynamicaly generated signature template\n" + " --sign-tmpl " "\tcreate and sign dynamicaly generated signature template\n" #endif /* XMLSEC_NO_TMPL_TEST */ #endif /* XMLSEC_NO_XMLDSIG */ #ifndef XMLSEC_NO_XMLENC - " --encrypt " "\tencrypt data and output XML document\n" - " --decrypt " "\tdecrypt data from XML document\n" + " --encrypt " "\tencrypt data and output XML document\n" + " --decrypt " "\tdecrypt data from XML document\n" #endif /* XMLSEC_NO_XMLENC */ #ifndef XMLSEC_NO_XKMS " --xkms-server-request ""\tprocess data as XKMS server request\n" @@ -133,19 +132,18 @@ static const char helpCheckTransforms[] = "Usage: xmlsec check-transforms <transform-name> [<transform-name> ... ]\n" "Checks the given transforms against the list of known transform klasses\n"; -#define xmlSecAppCmdLineTopicGeneral 0x0001 -#define xmlSecAppCmdLineTopicDSigCommon 0x0002 -#define xmlSecAppCmdLineTopicDSigSign 0x0004 -#define xmlSecAppCmdLineTopicDSigVerify 0x0008 -#define xmlSecAppCmdLineTopicEncCommon 0x0010 -#define xmlSecAppCmdLineTopicEncEncrypt 0x0020 -#define xmlSecAppCmdLineTopicEncDecrypt 0x0040 -#define xmlSecAppCmdLineTopicXkmsCommon 0x0080 -#define xmlSecAppCmdLineTopicKeysMngr 0x1000 -#define xmlSecAppCmdLineTopicX509Certs 0x2000 -#define xmlSecAppCmdLineTopicVersion 0x4000 -#define xmlSecAppCmdLineTopicCryptoConfig 0x8000 -#define xmlSecAppCmdLineTopicAll 0xFFFF +#define xmlSecAppCmdLineTopicGeneral 0x0001 +#define xmlSecAppCmdLineTopicDSigCommon 0x0002 +#define xmlSecAppCmdLineTopicDSigSign 0x0004 +#define xmlSecAppCmdLineTopicDSigVerify 0x0008 +#define xmlSecAppCmdLineTopicEncCommon 0x0010 +#define xmlSecAppCmdLineTopicEncEncrypt 0x0020 +#define xmlSecAppCmdLineTopicEncDecrypt 0x0040 +#define xmlSecAppCmdLineTopicXkmsCommon 0x0080 +#define xmlSecAppCmdLineTopicKeysMngr 0x1000 +#define xmlSecAppCmdLineTopicX509Certs 0x2000 +#define xmlSecAppCmdLineTopicVersion 0x4000 +#define xmlSecAppCmdLineTopicAll 0xFFFF /**************************************************************** * @@ -161,23 +159,25 @@ static xmlSecAppCmdLineParam helpParam = { xmlSecAppCmdLineParamTypeFlag, xmlSecAppCmdLineParamFlagNone, NULL -}; +}; +#if !defined(XMLSEC_NO_CRYPTO_DYNAMIC_LOADING) && defined(XMLSEC_CRYPTO_DYNAMIC_LOADING) static xmlSecAppCmdLineParam cryptoParam = { - xmlSecAppCmdLineTopicCryptoConfig, + xmlSecAppCmdLineTopicGeneral, "--crypto", NULL, "--crypto <name>" "\n\tthe name of the crypto engine to use from the following" - "\n\tlist: openssl, mscrypto, nss, gnutls, gcrypt (if no crypto engine is" + "\n\tlist: openssl, gnutls, nss, mscrypto (if no crypto engine is" "\n\tspecified then the default one is used)", xmlSecAppCmdLineParamTypeString, xmlSecAppCmdLineParamFlagNone, NULL -}; +}; +#endif /* !defined(XMLSEC_NO_CRYPTO_DYNAMIC_LOADING) && defined(XMLSEC_CRYPTO_DYNAMIC_LOADING) */ static xmlSecAppCmdLineParam cryptoConfigParam = { - xmlSecAppCmdLineTopicCryptoConfig, + xmlSecAppCmdLineTopicGeneral, "--crypto-config", NULL, "--crypto-config <path>" @@ -185,11 +185,11 @@ static xmlSecAppCmdLineParam cryptoConfigParam = { xmlSecAppCmdLineParamTypeString, xmlSecAppCmdLineParamFlagNone, NULL -}; +}; static xmlSecAppCmdLineParam repeatParam = { - xmlSecAppCmdLineTopicCryptoConfig, + xmlSecAppCmdLineTopicGeneral, "--repeat", "-r", "--repeat <number>" @@ -197,7 +197,7 @@ static xmlSecAppCmdLineParam repeatParam = { xmlSecAppCmdLineParamTypeNumber, xmlSecAppCmdLineParamFlagNone, NULL -}; +}; static xmlSecAppCmdLineParam disableErrorMsgsParam = { @@ -898,7 +898,9 @@ static xmlSecAppCmdLineParamPtr parameters[] = { #endif /* XMLSEC_NO_X509 */ /* General configuration params */ +#if !defined(XMLSEC_NO_CRYPTO_DYNAMIC_LOADING) && defined(XMLSEC_CRYPTO_DYNAMIC_LOADING) &cryptoParam, +#endif /* !defined(XMLSEC_NO_CRYPTO_DYNAMIC_LOADING) && defined(XMLSEC_CRYPTO_DYNAMIC_LOADING) */ &cryptoConfigParam, &repeatParam, &disableErrorMsgsParam, @@ -927,71 +929,71 @@ typedef enum { xmlSecAppCommandXkmsServerRequest } xmlSecAppCommand; -typedef struct _xmlSecAppXmlData xmlSecAppXmlData, - *xmlSecAppXmlDataPtr; +typedef struct _xmlSecAppXmlData xmlSecAppXmlData, + *xmlSecAppXmlDataPtr; struct _xmlSecAppXmlData { - xmlDocPtr doc; - xmlDtdPtr dtd; - xmlNodePtr startNode; + xmlDocPtr doc; + xmlDtdPtr dtd; + xmlNodePtr startNode; }; -static xmlSecAppXmlDataPtr xmlSecAppXmlDataCreate (const char* filename, - const xmlChar* defStartNodeName, - const xmlChar* defStartNodeNs); -static void xmlSecAppXmlDataDestroy (xmlSecAppXmlDataPtr data); +static xmlSecAppXmlDataPtr xmlSecAppXmlDataCreate (const char* filename, + const xmlChar* defStartNodeName, + const xmlChar* defStartNodeNs); +static void xmlSecAppXmlDataDestroy (xmlSecAppXmlDataPtr data); -static xmlSecAppCommand xmlSecAppParseCommand (const char* cmd, - xmlSecAppCmdLineParamTopic* topics, - xmlSecAppCommand* subCommand); -static void xmlSecAppPrintHelp (xmlSecAppCommand command, - xmlSecAppCmdLineParamTopic topics); -#define xmlSecAppPrintUsage() xmlSecAppPrintHelp(xmlSecAppCommandUnknown, 0) -static int xmlSecAppInit (void); -static void xmlSecAppShutdown (void); -static int xmlSecAppLoadKeys (void); -static int xmlSecAppPrepareKeyInfoReadCtx (xmlSecKeyInfoCtxPtr ctx); +static xmlSecAppCommand xmlSecAppParseCommand (const char* cmd, + xmlSecAppCmdLineParamTopic* topics, + xmlSecAppCommand* subCommand); +static void xmlSecAppPrintHelp (xmlSecAppCommand command, + xmlSecAppCmdLineParamTopic topics); +#define xmlSecAppPrintUsage() xmlSecAppPrintHelp(xmlSecAppCommandUnknown, 0) +static int xmlSecAppInit (void); +static void xmlSecAppShutdown (void); +static int xmlSecAppLoadKeys (void); +static int xmlSecAppPrepareKeyInfoReadCtx (xmlSecKeyInfoCtxPtr ctx); #ifndef XMLSEC_NO_XMLDSIG -static int xmlSecAppSignFile (const char* filename); -static int xmlSecAppVerifyFile (const char* filename); +static int xmlSecAppSignFile (const char* filename); +static int xmlSecAppVerifyFile (const char* filename); #ifndef XMLSEC_NO_TMPL_TEST -static int xmlSecAppSignTmpl (void); +static int xmlSecAppSignTmpl (void); #endif /* XMLSEC_NO_TMPL_TEST */ -static int xmlSecAppPrepareDSigCtx (xmlSecDSigCtxPtr dsigCtx); -static void xmlSecAppPrintDSigCtx (xmlSecDSigCtxPtr dsigCtx); +static int xmlSecAppPrepareDSigCtx (xmlSecDSigCtxPtr dsigCtx); +static void xmlSecAppPrintDSigCtx (xmlSecDSigCtxPtr dsigCtx); #endif /* XMLSEC_NO_XMLDSIG */ #ifndef XMLSEC_NO_XMLENC -static int xmlSecAppEncryptFile (const char* filename); -static int xmlSecAppDecryptFile (const char* filename); +static int xmlSecAppEncryptFile (const char* filename); +static int xmlSecAppDecryptFile (const char* filename); #ifndef XMLSEC_NO_TMPL_TEST -static int xmlSecAppEncryptTmpl (void); +static int xmlSecAppEncryptTmpl (void); #endif /* XMLSEC_NO_TMPL_TEST */ -static int xmlSecAppPrepareEncCtx (xmlSecEncCtxPtr encCtx); -static void xmlSecAppPrintEncCtx (xmlSecEncCtxPtr encCtx); +static int xmlSecAppPrepareEncCtx (xmlSecEncCtxPtr encCtx); +static void xmlSecAppPrintEncCtx (xmlSecEncCtxPtr encCtx); #endif /* XMLSEC_NO_XMLENC */ #ifndef XMLSEC_NO_XKMS -static int xmlSecAppXkmsServerProcess (const char* filename); -static int xmlSecAppPrepareXkmsServerCtx (xmlSecXkmsServerCtxPtr xkmsServerCtx); -static void xmlSecAppPrintXkmsServerCtx (xmlSecXkmsServerCtxPtr xkmsServerCtx); +static int xmlSecAppXkmsServerProcess (const char* filename); +static int xmlSecAppPrepareXkmsServerCtx (xmlSecXkmsServerCtxPtr xkmsServerCtx); +static void xmlSecAppPrintXkmsServerCtx (xmlSecXkmsServerCtxPtr xkmsServerCtx); #endif /* XMLSEC_NO_XKMS */ -static void xmlSecAppListKeyData (void); -static int xmlSecAppCheckKeyData (const char * name); -static void xmlSecAppListTransforms (void); -static int xmlSecAppCheckTransform (const char * name); - -static xmlSecTransformUriType xmlSecAppGetUriType (const char* string); -static FILE* xmlSecAppOpenFile (const char* filename); -static void xmlSecAppCloseFile (FILE* file); -static int xmlSecAppWriteResult (xmlDocPtr doc, - xmlSecBufferPtr buffer); -static int xmlSecAppAddIDAttr (xmlNodePtr cur, - const xmlChar* attr, - const xmlChar* node, - const xmlChar* nsHref); +static void xmlSecAppListKeyData (void); +static int xmlSecAppCheckKeyData (const char * name); +static void xmlSecAppListTransforms (void); +static int xmlSecAppCheckTransform (const char * name); + +static xmlSecTransformUriType xmlSecAppGetUriType (const char* string); +static FILE* xmlSecAppOpenFile (const char* filename); +static void xmlSecAppCloseFile (FILE* file); +static int xmlSecAppWriteResult (xmlDocPtr doc, + xmlSecBufferPtr buffer); +static int xmlSecAppAddIDAttr (xmlNodePtr cur, + const xmlChar* attr, + const xmlChar* node, + const xmlChar* nsHref); xmlSecKeysMngrPtr gKeysMngr = NULL; int repeats = 1; @@ -1005,208 +1007,201 @@ int main(int argc, const char **argv) { xmlSecAppCommand command, subCommand; int pos, i; int res = 1; - + /* read the command (first argument) */ if(argc < 2) { - xmlSecAppPrintUsage(); - goto fail; + xmlSecAppPrintUsage(); + goto fail; } command = xmlSecAppParseCommand(argv[1], &cmdLineTopics, &subCommand); if(command == xmlSecAppCommandUnknown) { - fprintf(stderr, "Error: unknown command \"%s\"\n", argv[1]); - xmlSecAppPrintUsage(); - goto fail; + fprintf(stderr, "Error: unknown command \"%s\"\n", argv[1]); + xmlSecAppPrintUsage(); + goto fail; } /* do as much as we can w/o initialization */ if(command == xmlSecAppCommandHelp) { - xmlSecAppPrintHelp(subCommand, cmdLineTopics); - goto success; + xmlSecAppPrintHelp(subCommand, cmdLineTopics); + goto success; } else if(command == xmlSecAppCommandVersion) { - fprintf(stdout, "%s %s (%s)\n", PACKAGE, XMLSEC_VERSION, xmlsec_crypto); - goto success; + fprintf(stdout, "%s %s (%s)\n", PACKAGE, XMLSEC_VERSION, xmlsec_crypto); + goto success; } /* parse command line */ pos = xmlSecAppCmdLineParamsListParse(parameters, cmdLineTopics, argv, argc, 2); if(pos < 0) { - fprintf(stderr, "Error: invalid parameters\n"); - xmlSecAppPrintUsage(); - goto fail; + fprintf(stderr, "Error: invalid parameters\n"); + xmlSecAppPrintUsage(); + goto fail; } /* is it a help request? */ if(xmlSecAppCmdLineParamIsSet(&helpParam)) { - xmlSecAppPrintHelp(command, cmdLineTopics); - goto success; + xmlSecAppPrintHelp(command, cmdLineTopics); + goto success; } /* we need to have some files at the end */ switch(command) { - case xmlSecAppCommandKeys: - case xmlSecAppCommandSign: - case xmlSecAppCommandVerify: - case xmlSecAppCommandEncrypt: - case xmlSecAppCommandDecrypt: - case xmlSecAppCommandXkmsServerRequest: - if(pos >= argc) { - fprintf(stderr, "Error: <file> parameter is requried for this command\n"); - xmlSecAppPrintUsage(); - goto fail; - } - break; - default: - break; + case xmlSecAppCommandKeys: + case xmlSecAppCommandSign: + case xmlSecAppCommandVerify: + case xmlSecAppCommandEncrypt: + case xmlSecAppCommandDecrypt: + case xmlSecAppCommandXkmsServerRequest: + if(pos >= argc) { + fprintf(stderr, "Error: <file> parameter is requried for this command\n"); + xmlSecAppPrintUsage(); + goto fail; + } + break; + default: + break; } - + /* now init the xmlsec and all other libs */ - /* ignore "--crypto" if we don't have dynamic loading */ - tmp = xmlSecAppCmdLineParamGetString(&cryptoParam); #if !defined(XMLSEC_NO_CRYPTO_DYNAMIC_LOADING) && defined(XMLSEC_CRYPTO_DYNAMIC_LOADING) + tmp = xmlSecAppCmdLineParamGetString(&cryptoParam); if((tmp != NULL) && (strcmp(tmp, "default") != 0)) { - xmlsec_crypto = tmp; - } -#else /* !defined(XMLSEC_NO_CRYPTO_DYNAMIC_LOADING) && defined(XMLSEC_CRYPTO_DYNAMIC_LOADING) */ - if((tmp != NULL) && (strcmp(tmp, xmlsec_crypto) != 0)) { - fprintf(stderr, "Error: dynaimc crypto libraries loading is disabled and the only available crypto library is '%s'\n", xmlsec_crypto); - xmlSecAppPrintUsage(); - goto fail; + xmlsec_crypto = tmp; } #endif /* !defined(XMLSEC_NO_CRYPTO_DYNAMIC_LOADING) && defined(XMLSEC_CRYPTO_DYNAMIC_LOADING) */ - + if(xmlSecAppInit() < 0) { - fprintf(stderr, "Error: initialization failed\n"); - xmlSecAppPrintUsage(); - goto fail; + fprintf(stderr, "Error: initialization failed\n"); + xmlSecAppPrintUsage(); + goto fail; } /* load keys */ if(xmlSecAppLoadKeys() < 0) { - fprintf(stderr, "Error: keys manager creation failed\n"); - xmlSecAppPrintUsage(); - goto fail; + fprintf(stderr, "Error: keys manager creation failed\n"); + xmlSecAppPrintUsage(); + goto fail; } /* get the "repeats" number */ if(xmlSecAppCmdLineParamIsSet(&repeatParam) && (xmlSecAppCmdLineParamGetInt(&repeatParam, 1) > 0)) { - repeats = xmlSecAppCmdLineParamGetInt(&repeatParam, 1); + repeats = xmlSecAppCmdLineParamGetInt(&repeatParam, 1); } /* execute requested number of times */ for(; repeats > 0; --repeats) { - switch(command) { - case xmlSecAppCommandListKeyData: - xmlSecAppListKeyData(); - break; - case xmlSecAppCommandCheckKeyData: - for(i = pos; i < argc; ++i) { + switch(command) { + case xmlSecAppCommandListKeyData: + xmlSecAppListKeyData(); + break; + case xmlSecAppCommandCheckKeyData: + for(i = pos; i < argc; ++i) { if(xmlSecAppCheckKeyData(argv[i]) < 0) { fprintf(stderr, "Error: key data \"%s\" not found\n", argv[i]); goto fail; } else { fprintf(stdout, "Key data \"%s\" found\n", argv[i]); } - } - break; - case xmlSecAppCommandListTransforms: - xmlSecAppListTransforms(); - break; - case xmlSecAppCommandCheckTransforms: - for(i = pos; i < argc; ++i) { + } + break; + case xmlSecAppCommandListTransforms: + xmlSecAppListTransforms(); + break; + case xmlSecAppCommandCheckTransforms: + for(i = pos; i < argc; ++i) { if(xmlSecAppCheckTransform(argv[i]) < 0) { fprintf(stderr, "Error: transform \"%s\" not found\n", argv[i]); goto fail; } else { fprintf(stdout, "Transforms \"%s\" found\n", argv[i]); } - } - break; - case xmlSecAppCommandKeys: - for(i = pos; i < argc; ++i) { - if(xmlSecAppCryptoSimpleKeysMngrSave(gKeysMngr, argv[i], xmlSecKeyDataTypeAny) < 0) { - fprintf(stderr, "Error: failed to save keys to file \"%s\"\n", argv[i]); - goto fail; - } - } - break; + } + break; + case xmlSecAppCommandKeys: + for(i = pos; i < argc; ++i) { + if(xmlSecAppCryptoSimpleKeysMngrSave(gKeysMngr, argv[i], xmlSecKeyDataTypeAny) < 0) { + fprintf(stderr, "Error: failed to save keys to file \"%s\"\n", argv[i]); + goto fail; + } + } + break; #ifndef XMLSEC_NO_XMLDSIG - case xmlSecAppCommandSign: - for(i = pos; i < argc; ++i) { - if(xmlSecAppSignFile(argv[i]) < 0) { - fprintf(stderr, "Error: failed to sign file \"%s\"\n", argv[i]); - goto fail; - } - } - break; - case xmlSecAppCommandVerify: - for(i = pos; i < argc; ++i) { - if(xmlSecAppVerifyFile(argv[i]) < 0) { - fprintf(stderr, "Error: failed to verify file \"%s\"\n", argv[i]); - goto fail; - } - } - break; + case xmlSecAppCommandSign: + for(i = pos; i < argc; ++i) { + if(xmlSecAppSignFile(argv[i]) < 0) { + fprintf(stderr, "Error: failed to sign file \"%s\"\n", argv[i]); + goto fail; + } + } + break; + case xmlSecAppCommandVerify: + for(i = pos; i < argc; ++i) { + if(xmlSecAppVerifyFile(argv[i]) < 0) { + fprintf(stderr, "Error: failed to verify file \"%s\"\n", argv[i]); + goto fail; + } + } + break; #ifndef XMLSEC_NO_TMPL_TEST - case xmlSecAppCommandSignTmpl: - if(xmlSecAppSignTmpl() < 0) { - fprintf(stderr, "Error: failed to create and sign template\n"); - goto fail; - } - break; + case xmlSecAppCommandSignTmpl: + if(xmlSecAppSignTmpl() < 0) { + fprintf(stderr, "Error: failed to create and sign template\n"); + goto fail; + } + break; #endif /* XMLSEC_NO_TMPL_TEST */ #endif /* XMLSEC_NO_XMLDSIG */ #ifndef XMLSEC_NO_XMLENC - case xmlSecAppCommandEncrypt: - for(i = pos; i < argc; ++i) { - if(xmlSecAppEncryptFile(argv[i]) < 0) { - fprintf(stderr, "Error: failed to encrypt file with template \"%s\"\n", argv[i]); - goto fail; - } - } - break; - case xmlSecAppCommandDecrypt: - for(i = pos; i < argc; ++i) { - if(xmlSecAppDecryptFile(argv[i]) < 0) { - fprintf(stderr, "Error: failed to decrypt file \"%s\"\n", argv[i]); - goto fail; - } - } - break; + case xmlSecAppCommandEncrypt: + for(i = pos; i < argc; ++i) { + if(xmlSecAppEncryptFile(argv[i]) < 0) { + fprintf(stderr, "Error: failed to encrypt file with template \"%s\"\n", argv[i]); + goto fail; + } + } + break; + case xmlSecAppCommandDecrypt: + for(i = pos; i < argc; ++i) { + if(xmlSecAppDecryptFile(argv[i]) < 0) { + fprintf(stderr, "Error: failed to decrypt file \"%s\"\n", argv[i]); + goto fail; + } + } + break; #ifndef XMLSEC_NO_TMPL_TEST - case xmlSecAppCommandEncryptTmpl: - if(xmlSecAppEncryptTmpl() < 0) { - fprintf(stderr, "Error: failed to create and encrypt template\n"); - goto fail; - } - break; + case xmlSecAppCommandEncryptTmpl: + if(xmlSecAppEncryptTmpl() < 0) { + fprintf(stderr, "Error: failed to create and encrypt template\n"); + goto fail; + } + break; #endif /* XMLSEC_NO_TMPL_TEST */ #endif /* XMLSEC_NO_XMLENC */ #ifndef XMLSEC_NO_XKMS - case xmlSecAppCommandXkmsServerRequest: - for(i = pos; i < argc; ++i) { - if(xmlSecAppXkmsServerProcess(argv[i]) < 0) { - fprintf(stderr, "Error: failed to process XKMS server request from file \"%s\"\n", argv[i]); - goto fail; - } - } - break; + case xmlSecAppCommandXkmsServerRequest: + for(i = pos; i < argc; ++i) { + if(xmlSecAppXkmsServerProcess(argv[i]) < 0) { + fprintf(stderr, "Error: failed to process XKMS server request from file \"%s\"\n", argv[i]); + goto fail; + } + } + break; #endif /* XMLSEC_NO_XKMS */ - default: - fprintf(stderr, "Error: invalid command %d\n", command); - xmlSecAppPrintUsage(); - goto fail; - } + default: + fprintf(stderr, "Error: invalid command %d\n", command); + xmlSecAppPrintUsage(); + goto fail; + } } /* print perf stats results */ if(xmlSecAppCmdLineParamIsSet(&repeatParam) && (xmlSecAppCmdLineParamGetInt(&repeatParam, 1) > 0)) { - repeats = xmlSecAppCmdLineParamGetInt(&repeatParam, 1); + repeats = xmlSecAppCmdLineParamGetInt(&repeatParam, 1); fprintf(stderr, "Executed %d tests in %ld msec\n", repeats, (1000 * total_time) / CLOCKS_PER_SEC); } @@ -1215,8 +1210,8 @@ success: res = 0; fail: if(gKeysMngr != NULL) { - xmlSecKeysMngrDestroy(gKeysMngr); - gKeysMngr = NULL; + xmlSecKeysMngrDestroy(gKeysMngr); + gKeysMngr = NULL; } xmlSecAppShutdown(); xmlSecAppCmdLineParamsListClean(parameters); @@ -1233,24 +1228,24 @@ xmlSecAppSignFile(const char* filename) { int res = -1; if(filename == NULL) { - return(-1); + return(-1); } if(xmlSecDSigCtxInitialize(&dsigCtx, gKeysMngr) < 0) { - fprintf(stderr, "Error: dsig context initialization failed\n"); - return(-1); + fprintf(stderr, "Error: dsig context initialization failed\n"); + return(-1); } if(xmlSecAppPrepareDSigCtx(&dsigCtx) < 0) { - fprintf(stderr, "Error: dsig context preparation failed\n"); - goto done; + fprintf(stderr, "Error: dsig context preparation failed\n"); + goto done; } /* parse template and select start node */ data = xmlSecAppXmlDataCreate(filename, xmlSecNodeSignature, xmlSecDSigNs); if(data == NULL) { - fprintf(stderr, "Error: failed to load template \"%s\"\n", filename); - goto done; + fprintf(stderr, "Error: failed to load template \"%s\"\n", filename); + goto done; } @@ -1258,32 +1253,32 @@ xmlSecAppSignFile(const char* filename) { start_time = clock(); if(xmlSecDSigCtxSign(&dsigCtx, data->startNode) < 0) { fprintf(stderr,"Error: signature failed \n"); - goto done; + goto done; } total_time += clock() - start_time; if(repeats <= 1) { - FILE* f; + FILE* f; - f = xmlSecAppOpenFile(xmlSecAppCmdLineParamGetString(&outputParam)); - if(f == NULL) { - fprintf(stderr,"Error: failed to open output file \"%s\"\n", - xmlSecAppCmdLineParamGetString(&outputParam)); - goto done; - } - xmlDocDump(f, data->doc); - xmlSecAppCloseFile(f); + f = xmlSecAppOpenFile(xmlSecAppCmdLineParamGetString(&outputParam)); + if(f == NULL) { + fprintf(stderr,"Error: failed to open output file \"%s\"\n", + xmlSecAppCmdLineParamGetString(&outputParam)); + goto done; + } + xmlDocDump(f, data->doc); + xmlSecAppCloseFile(f); } res = 0; done: /* print debug info if requested */ if(repeats <= 1) { - xmlSecAppPrintDSigCtx(&dsigCtx); + xmlSecAppPrintDSigCtx(&dsigCtx); } xmlSecDSigCtxFinalize(&dsigCtx); if(data != NULL) { - xmlSecAppXmlDataDestroy(data); + xmlSecAppXmlDataDestroy(data); } return(res); } @@ -1296,98 +1291,98 @@ xmlSecAppVerifyFile(const char* filename) { int res = -1; if(filename == NULL) { - return(-1); + return(-1); } if(xmlSecDSigCtxInitialize(&dsigCtx, gKeysMngr) < 0) { - fprintf(stderr, "Error: dsig context initialization failed\n"); - return(-1); + fprintf(stderr, "Error: dsig context initialization failed\n"); + return(-1); } if(xmlSecAppPrepareDSigCtx(&dsigCtx) < 0) { - fprintf(stderr, "Error: dsig context preparation failed\n"); - goto done; + fprintf(stderr, "Error: dsig context preparation failed\n"); + goto done; } /* parse template and select start node */ data = xmlSecAppXmlDataCreate(filename, xmlSecNodeSignature, xmlSecDSigNs); if(data == NULL) { - fprintf(stderr, "Error: failed to load document \"%s\"\n", filename); - goto done; + fprintf(stderr, "Error: failed to load document \"%s\"\n", filename); + goto done; } /* sign */ start_time = clock(); if(xmlSecDSigCtxVerify(&dsigCtx, data->startNode) < 0) { fprintf(stderr,"Error: signature failed \n"); - goto done; + goto done; } total_time += clock() - start_time; if((repeats <= 1) && (dsigCtx.status != xmlSecDSigStatusSucceeded)){ - /* return an error if signature does not match */ - goto done; + /* return an error if signature does not match */ + goto done; } res = 0; done: /* print debug info if requested */ if(repeats <= 1) { - xmlSecDSigReferenceCtxPtr dsigRefCtx; - xmlSecSize good, i, size; - FILE* f; + xmlSecDSigReferenceCtxPtr dsigRefCtx; + xmlSecSize good, i, size; + FILE* f; - f = xmlSecAppOpenFile(xmlSecAppCmdLineParamGetString(&outputParam)); - if(f == NULL) { - fprintf(stderr,"Error: failed to open output file \"%s\"\n", - xmlSecAppCmdLineParamGetString(&outputParam)); - goto done; - } - xmlSecAppCloseFile(f); - - switch(dsigCtx.status) { - case xmlSecDSigStatusUnknown: - fprintf(stderr, "ERROR\n"); - break; - case xmlSecDSigStatusSucceeded: - fprintf(stderr, "OK\n"); - break; - case xmlSecDSigStatusInvalid: - fprintf(stderr, "FAIL\n"); - break; - } - - /* print stats about # of good/bad references/manifests */ - size = xmlSecPtrListGetSize(&(dsigCtx.signedInfoReferences)); - for(i = good = 0; i < size; ++i) { - dsigRefCtx = (xmlSecDSigReferenceCtxPtr)xmlSecPtrListGetItem(&(dsigCtx.signedInfoReferences), i); - if(dsigRefCtx == NULL) { - fprintf(stderr,"Error: reference ctx is null\n"); - goto done; - } - if(dsigRefCtx->status == xmlSecDSigStatusSucceeded) { - ++good; - } - } - fprintf(stderr, "SignedInfo References (ok/all): %d/%d\n", good, size); - - size = xmlSecPtrListGetSize(&(dsigCtx.manifestReferences)); - for(i = good = 0; i < size; ++i) { - dsigRefCtx = (xmlSecDSigReferenceCtxPtr)xmlSecPtrListGetItem(&(dsigCtx.manifestReferences), i); - if(dsigRefCtx == NULL) { - fprintf(stderr,"Error: reference ctx is null\n"); - goto done; - } - if(dsigRefCtx->status == xmlSecDSigStatusSucceeded) { - ++good; - } - } - fprintf(stderr, "Manifests References (ok/all): %d/%d\n", good, size); - - xmlSecAppPrintDSigCtx(&dsigCtx); + f = xmlSecAppOpenFile(xmlSecAppCmdLineParamGetString(&outputParam)); + if(f == NULL) { + fprintf(stderr,"Error: failed to open output file \"%s\"\n", + xmlSecAppCmdLineParamGetString(&outputParam)); + goto done; + } + xmlSecAppCloseFile(f); + + switch(dsigCtx.status) { + case xmlSecDSigStatusUnknown: + fprintf(stderr, "ERROR\n"); + break; + case xmlSecDSigStatusSucceeded: + fprintf(stderr, "OK\n"); + break; + case xmlSecDSigStatusInvalid: + fprintf(stderr, "FAIL\n"); + break; + } + + /* print stats about # of good/bad references/manifests */ + size = xmlSecPtrListGetSize(&(dsigCtx.signedInfoReferences)); + for(i = good = 0; i < size; ++i) { + dsigRefCtx = (xmlSecDSigReferenceCtxPtr)xmlSecPtrListGetItem(&(dsigCtx.signedInfoReferences), i); + if(dsigRefCtx == NULL) { + fprintf(stderr,"Error: reference ctx is null\n"); + goto done; + } + if(dsigRefCtx->status == xmlSecDSigStatusSucceeded) { + ++good; + } + } + fprintf(stderr, "SignedInfo References (ok/all): %d/%d\n", good, size); + + size = xmlSecPtrListGetSize(&(dsigCtx.manifestReferences)); + for(i = good = 0; i < size; ++i) { + dsigRefCtx = (xmlSecDSigReferenceCtxPtr)xmlSecPtrListGetItem(&(dsigCtx.manifestReferences), i); + if(dsigRefCtx == NULL) { + fprintf(stderr,"Error: reference ctx is null\n"); + goto done; + } + if(dsigRefCtx->status == xmlSecDSigStatusSucceeded) { + ++good; + } + } + fprintf(stderr, "Manifests References (ok/all): %d/%d\n", good, size); + + xmlSecAppPrintDSigCtx(&dsigCtx); } xmlSecDSigCtxFinalize(&dsigCtx); if(data != NULL) { - xmlSecAppXmlDataDestroy(data); + xmlSecAppXmlDataDestroy(data); } return(res); } @@ -1402,109 +1397,109 @@ xmlSecAppSignTmpl(void) { int res = -1; if(xmlSecDSigCtxInitialize(&dsigCtx, gKeysMngr) < 0) { - fprintf(stderr, "Error: dsig context initialization failed\n"); - return(-1); + fprintf(stderr, "Error: dsig context initialization failed\n"); + return(-1); } if(xmlSecAppPrepareDSigCtx(&dsigCtx) < 0) { - fprintf(stderr, "Error: dsig context preparation failed\n"); - goto done; + fprintf(stderr, "Error: dsig context preparation failed\n"); + goto done; } /* prepare template */ doc = xmlNewDoc(BAD_CAST "1.0"); if(doc == NULL) { - fprintf(stderr, "Error: failed to create doc\n"); - goto done; + fprintf(stderr, "Error: failed to create doc\n"); + goto done; } cur = xmlSecTmplSignatureCreate(doc, xmlSecTransformInclC14NId, - xmlSecTransformHmacSha1Id, NULL); + xmlSecTransformHmacSha1Id, NULL); if(cur == NULL) { - fprintf(stderr, "Error: failed to create Signature node\n"); - goto done; + fprintf(stderr, "Error: failed to create Signature node\n"); + goto done; } xmlDocSetRootElement(doc, cur); /* set hmac signature length */ cur = xmlSecTmplSignatureGetSignMethodNode(xmlDocGetRootElement(doc)); if(cur == NULL) { - fprintf(stderr, "Error: failed to find SignatureMethod node\n"); - goto done; + fprintf(stderr, "Error: failed to find SignatureMethod node\n"); + goto done; } if(xmlSecTmplTransformAddHmacOutputLength(cur, 93) < 0) { - fprintf(stderr, "Error: failed to set hmac length\n"); - goto done; + fprintf(stderr, "Error: failed to set hmac length\n"); + goto done; } cur = xmlSecTmplSignatureAddReference(xmlDocGetRootElement(doc), - xmlSecTransformSha1Id, - BAD_CAST "ref1", NULL, NULL); + xmlSecTransformSha1Id, + BAD_CAST "ref1", NULL, NULL); if(cur == NULL) { - fprintf(stderr, "Error: failed to add Reference node\n"); - goto done; + fprintf(stderr, "Error: failed to add Reference node\n"); + goto done; } cur = xmlSecTmplReferenceAddTransform(cur, xmlSecTransformXPath2Id); if(cur == NULL) { - fprintf(stderr, "Error: failed to add XPath transform\n"); - goto done; + fprintf(stderr, "Error: failed to add XPath transform\n"); + goto done; } if(xmlSecTmplTransformAddXPath2(cur, BAD_CAST "intersect", - BAD_CAST "//*[@Id='object1']", NULL) < 0) { - fprintf(stderr, "Error: failed to set XPath expression\n"); - goto done; + BAD_CAST "//*[@Id='object1']", NULL) < 0) { + fprintf(stderr, "Error: failed to set XPath expression\n"); + goto done; } cur = xmlSecTmplSignatureAddObject(xmlDocGetRootElement(doc), - BAD_CAST "object1", NULL, NULL); + BAD_CAST "object1", NULL, NULL); if(cur == NULL) { - fprintf(stderr, "Error: failed to add Object node\n"); - goto done; + fprintf(stderr, "Error: failed to add Object node\n"); + goto done; } xmlNodeSetContent(cur, BAD_CAST "This is signed data"); /* add key information */ cur = xmlSecTmplSignatureEnsureKeyInfo(xmlDocGetRootElement(doc), NULL); if(cur == NULL) { - fprintf(stderr, "Error: failed to add KeyInfo node\n"); - goto done; + fprintf(stderr, "Error: failed to add KeyInfo node\n"); + goto done; } if(xmlSecTmplKeyInfoAddKeyName(cur, NULL) == NULL) { - fprintf(stderr, "Error: failed to add KeyName node\n"); - goto done; + fprintf(stderr, "Error: failed to add KeyName node\n"); + goto done; } /* sign */ start_time = clock(); if(xmlSecDSigCtxSign(&dsigCtx, xmlDocGetRootElement(doc)) < 0) { fprintf(stderr,"Error: signature failed \n"); - goto done; + goto done; } total_time += clock() - start_time; if(repeats <= 1) { - FILE* f; + FILE* f; - f = xmlSecAppOpenFile(xmlSecAppCmdLineParamGetString(&outputParam)); - if(f == NULL) { - fprintf(stderr,"Error: failed to open output file \"%s\"\n", - xmlSecAppCmdLineParamGetString(&outputParam)); - goto done; - } - xmlDocDump(f, doc); - xmlSecAppCloseFile(f); + f = xmlSecAppOpenFile(xmlSecAppCmdLineParamGetString(&outputParam)); + if(f == NULL) { + fprintf(stderr,"Error: failed to open output file \"%s\"\n", + xmlSecAppCmdLineParamGetString(&outputParam)); + goto done; + } + xmlDocDump(f, doc); + xmlSecAppCloseFile(f); } res = 0; done: /* print debug info if requested */ if(repeats <= 1) { - xmlSecAppPrintDSigCtx(&dsigCtx); + xmlSecAppPrintDSigCtx(&dsigCtx); } xmlSecDSigCtxFinalize(&dsigCtx); if(doc != NULL) { - xmlFreeDoc(doc); + xmlFreeDoc(doc); } return(res); } @@ -1513,51 +1508,51 @@ done: static int xmlSecAppPrepareDSigCtx(xmlSecDSigCtxPtr dsigCtx) { if(dsigCtx == NULL) { - fprintf(stderr, "Error: dsig context is null\n"); - return(-1); + fprintf(stderr, "Error: dsig context is null\n"); + return(-1); } /* set key info params */ if(xmlSecAppPrepareKeyInfoReadCtx(&(dsigCtx->keyInfoReadCtx)) < 0) { - fprintf(stderr, "Error: failed to prepare key info context\n"); - return(-1); + fprintf(stderr, "Error: failed to prepare key info context\n"); + return(-1); } if(xmlSecAppCmdLineParamGetString(&sessionKeyParam) != NULL) { - dsigCtx->signKey = xmlSecAppCryptoKeyGenerate(xmlSecAppCmdLineParamGetString(&sessionKeyParam), - NULL, xmlSecKeyDataTypeSession); - if(dsigCtx->signKey == NULL) { - fprintf(stderr, "Error: failed to generate a session key \"%s\"\n", - xmlSecAppCmdLineParamGetString(&sessionKeyParam)); - return(-1); - } + dsigCtx->signKey = xmlSecAppCryptoKeyGenerate(xmlSecAppCmdLineParamGetString(&sessionKeyParam), + NULL, xmlSecKeyDataTypeSession); + if(dsigCtx->signKey == NULL) { + fprintf(stderr, "Error: failed to generate a session key \"%s\"\n", + xmlSecAppCmdLineParamGetString(&sessionKeyParam)); + return(-1); + } } /* set dsig params */ if(xmlSecAppCmdLineParamIsSet(&ignoreManifestsParam)) { - dsigCtx->flags |= XMLSEC_DSIG_FLAGS_IGNORE_MANIFESTS; + dsigCtx->flags |= XMLSEC_DSIG_FLAGS_IGNORE_MANIFESTS; } if(xmlSecAppCmdLineParamIsSet(&storeReferencesParam)) { - dsigCtx->flags |= XMLSEC_DSIG_FLAGS_STORE_SIGNEDINFO_REFERENCES | - XMLSEC_DSIG_FLAGS_STORE_MANIFEST_REFERENCES; - print_debug = 1; + dsigCtx->flags |= XMLSEC_DSIG_FLAGS_STORE_SIGNEDINFO_REFERENCES | + XMLSEC_DSIG_FLAGS_STORE_MANIFEST_REFERENCES; + print_debug = 1; } if(xmlSecAppCmdLineParamIsSet(&storeSignaturesParam)) { - dsigCtx->flags |= XMLSEC_DSIG_FLAGS_STORE_SIGNATURE; - print_debug = 1; + dsigCtx->flags |= XMLSEC_DSIG_FLAGS_STORE_SIGNATURE; + print_debug = 1; } if(xmlSecAppCmdLineParamIsSet(&enableVisa3DHackParam)) { - dsigCtx->flags |= XMLSEC_DSIG_FLAGS_USE_VISA3D_HACK; + dsigCtx->flags |= XMLSEC_DSIG_FLAGS_USE_VISA3D_HACK; } if(xmlSecAppCmdLineParamGetStringList(&enabledRefUrisParam) != NULL) { - dsigCtx->enabledReferenceUris = xmlSecAppGetUriType( - xmlSecAppCmdLineParamGetStringList(&enabledRefUrisParam)); - if(dsigCtx->enabledReferenceUris == xmlSecTransformUriTypeNone) { - fprintf(stderr, "Error: failed to parse \"%s\"\n", - xmlSecAppCmdLineParamGetStringList(&enabledRefUrisParam)); - return(-1); - } + dsigCtx->enabledReferenceUris = xmlSecAppGetUriType( + xmlSecAppCmdLineParamGetStringList(&enabledRefUrisParam)); + if(dsigCtx->enabledReferenceUris == xmlSecTransformUriTypeNone) { + fprintf(stderr, "Error: failed to parse \"%s\"\n", + xmlSecAppCmdLineParamGetStringList(&enabledRefUrisParam)); + return(-1); + } } return(0); @@ -1566,20 +1561,20 @@ xmlSecAppPrepareDSigCtx(xmlSecDSigCtxPtr dsigCtx) { static void xmlSecAppPrintDSigCtx(xmlSecDSigCtxPtr dsigCtx) { if(dsigCtx == NULL) { - return; + return; } if(xmlSecAppCmdLineParamIsSet(&printDebugParam) || xmlSecAppCmdLineParamIsSet(&printXmlDebugParam)) { - print_debug = 0; + print_debug = 0; } /* print debug info if requested */ if((print_debug != 0) || xmlSecAppCmdLineParamIsSet(&printDebugParam)) { - xmlSecDSigCtxDebugDump(dsigCtx, stdout); + xmlSecDSigCtxDebugDump(dsigCtx, stdout); } - if(xmlSecAppCmdLineParamIsSet(&printXmlDebugParam)) { - xmlSecDSigCtxDebugXmlDump(dsigCtx, stdout); + if(xmlSecAppCmdLineParamIsSet(&printXmlDebugParam)) { + xmlSecDSigCtxDebugXmlDump(dsigCtx, stdout); } } @@ -1596,89 +1591,89 @@ xmlSecAppEncryptFile(const char* filename) { int res = -1; if(filename == NULL) { - return(-1); + return(-1); } if(xmlSecEncCtxInitialize(&encCtx, gKeysMngr) < 0) { - fprintf(stderr, "Error: enc context initialization failed\n"); - return(-1); + fprintf(stderr, "Error: enc context initialization failed\n"); + return(-1); } if(xmlSecAppPrepareEncCtx(&encCtx) < 0) { - fprintf(stderr, "Error: enc context preparation failed\n"); - goto done; + fprintf(stderr, "Error: enc context preparation failed\n"); + goto done; } /* parse doc and find template node */ doc = xmlSecParseFile(filename); if(doc == NULL) { - fprintf(stderr, "Error: failed to parse xml file \"%s\"\n", - filename); - goto done; + fprintf(stderr, "Error: failed to parse xml file \"%s\"\n", + filename); + goto done; } startTmplNode = xmlSecFindNode(xmlDocGetRootElement(doc), xmlSecNodeEncryptedData, xmlSecEncNs); if(startTmplNode == NULL) { - fprintf(stderr, "Error: failed to find default node with name=\"%s\"\n", - xmlSecNodeEncryptedData); - goto done; + fprintf(stderr, "Error: failed to find default node with name=\"%s\"\n", + xmlSecNodeEncryptedData); + goto done; } if(xmlSecAppCmdLineParamGetString(&binaryDataParam) != NULL) { - /* encrypt */ - start_time = clock(); - if(xmlSecEncCtxUriEncrypt(&encCtx, startTmplNode, BAD_CAST xmlSecAppCmdLineParamGetString(&binaryDataParam)) < 0) { - fprintf(stderr, "Error: failed to encrypt file \"%s\"\n", - xmlSecAppCmdLineParamGetString(&binaryDataParam)); - goto done; - } - total_time += clock() - start_time; + /* encrypt */ + start_time = clock(); + if(xmlSecEncCtxUriEncrypt(&encCtx, startTmplNode, BAD_CAST xmlSecAppCmdLineParamGetString(&binaryDataParam)) < 0) { + fprintf(stderr, "Error: failed to encrypt file \"%s\"\n", + xmlSecAppCmdLineParamGetString(&binaryDataParam)); + goto done; + } + total_time += clock() - start_time; } else if(xmlSecAppCmdLineParamGetString(&xmlDataParam) != NULL) { - /* parse file and select node for encryption */ + /* parse file and select node for encryption */ data = xmlSecAppXmlDataCreate(xmlSecAppCmdLineParamGetString(&xmlDataParam), NULL, NULL); - if(data == NULL) { - fprintf(stderr, "Error: failed to load file \"%s\"\n", - xmlSecAppCmdLineParamGetString(&xmlDataParam)); - goto done; - } - - /* encrypt */ - start_time = clock(); - if(xmlSecEncCtxXmlEncrypt(&encCtx, startTmplNode, data->startNode) < 0) { - fprintf(stderr, "Error: failed to encrypt xml file \"%s\"\n", - xmlSecAppCmdLineParamGetString(&xmlDataParam)); - goto done; - } - total_time += clock() - start_time; + if(data == NULL) { + fprintf(stderr, "Error: failed to load file \"%s\"\n", + xmlSecAppCmdLineParamGetString(&xmlDataParam)); + goto done; + } + + /* encrypt */ + start_time = clock(); + if(xmlSecEncCtxXmlEncrypt(&encCtx, startTmplNode, data->startNode) < 0) { + fprintf(stderr, "Error: failed to encrypt xml file \"%s\"\n", + xmlSecAppCmdLineParamGetString(&xmlDataParam)); + goto done; + } + total_time += clock() - start_time; } else { - fprintf(stderr, "Error: encryption data not specified (use \"--xml\" or \"--binary\" options)\n"); - goto done; + fprintf(stderr, "Error: encryption data not specified (use \"--xml\" or \"--binary\" options)\n"); + goto done; } /* print out result only once per execution */ if(repeats <= 1) { - if(encCtx.resultReplaced) { - if(xmlSecAppWriteResult((data != NULL) ? data->doc : doc, NULL) < 0) { - goto done; - } - } else { - if(xmlSecAppWriteResult(NULL, encCtx.result) < 0) { - goto done; - } - } + if(encCtx.resultReplaced) { + if(xmlSecAppWriteResult((data != NULL) ? data->doc : doc, NULL) < 0) { + goto done; + } + } else { + if(xmlSecAppWriteResult(NULL, encCtx.result) < 0) { + goto done; + } + } } res = 0; done: /* print debug info if requested */ if(repeats <= 1) { - xmlSecAppPrintEncCtx(&encCtx); + xmlSecAppPrintEncCtx(&encCtx); } xmlSecEncCtxFinalize(&encCtx); if(data != NULL) { - xmlSecAppXmlDataDestroy(data); + xmlSecAppXmlDataDestroy(data); } if(doc != NULL) { - xmlFreeDoc(doc); + xmlFreeDoc(doc); } return(res); } @@ -1691,43 +1686,43 @@ xmlSecAppDecryptFile(const char* filename) { int res = -1; if(filename == NULL) { - return(-1); + return(-1); } if(xmlSecEncCtxInitialize(&encCtx, gKeysMngr) < 0) { - fprintf(stderr, "Error: enc context initialization failed\n"); - return(-1); + fprintf(stderr, "Error: enc context initialization failed\n"); + return(-1); } if(xmlSecAppPrepareEncCtx(&encCtx) < 0) { - fprintf(stderr, "Error: enc context preparation failed\n"); - goto done; + fprintf(stderr, "Error: enc context preparation failed\n"); + goto done; } /* parse template and select start node */ data = xmlSecAppXmlDataCreate(filename, xmlSecNodeEncryptedData, xmlSecEncNs); if(data == NULL) { - fprintf(stderr, "Error: failed to load template \"%s\"\n", filename); - goto done; + fprintf(stderr, "Error: failed to load template \"%s\"\n", filename); + goto done; } start_time = clock(); if(xmlSecEncCtxDecrypt(&encCtx, data->startNode) < 0) { - fprintf(stderr, "Error: failed to decrypt file\n"); - goto done; + fprintf(stderr, "Error: failed to decrypt file\n"); + goto done; } total_time += clock() - start_time; /* print out result only once per execution */ if(repeats <= 1) { - if(encCtx.resultReplaced) { - if(xmlSecAppWriteResult(data->doc, NULL) < 0) { - goto done; - } - } else { - if(xmlSecAppWriteResult(NULL, encCtx.result) < 0) { - goto done; - } - } + if(encCtx.resultReplaced) { + if(xmlSecAppWriteResult(data->doc, NULL) < 0) { + goto done; + } + } else { + if(xmlSecAppWriteResult(NULL, encCtx.result) < 0) { + goto done; + } + } } res = 0; @@ -1739,7 +1734,7 @@ done: xmlSecEncCtxFinalize(&encCtx); if(data != NULL) { - xmlSecAppXmlDataDestroy(data); + xmlSecAppXmlDataDestroy(data); } return(res); } @@ -1755,76 +1750,76 @@ xmlSecAppEncryptTmpl(void) { int res = -1; if(xmlSecEncCtxInitialize(&encCtx, gKeysMngr) < 0) { - fprintf(stderr, "Error: enc context initialization failed\n"); - return(-1); + fprintf(stderr, "Error: enc context initialization failed\n"); + return(-1); } if(xmlSecAppPrepareEncCtx(&encCtx) < 0) { - fprintf(stderr, "Error: enc context preparation failed\n"); - goto done; + fprintf(stderr, "Error: enc context preparation failed\n"); + goto done; } /* prepare template */ doc = xmlNewDoc(BAD_CAST "1.0"); if(doc == NULL) { - fprintf(stderr, "Error: failed to create doc\n"); - goto done; + fprintf(stderr, "Error: failed to create doc\n"); + goto done; } cur = xmlSecTmplEncDataCreate(doc, xmlSecTransformDes3CbcId, - NULL, NULL, NULL, NULL); + NULL, NULL, NULL, NULL); if(cur == NULL) { - fprintf(stderr, "Error: failed to encryption template\n"); - goto done; + fprintf(stderr, "Error: failed to encryption template\n"); + goto done; } xmlDocSetRootElement(doc, cur); if(xmlSecTmplEncDataEnsureCipherValue(xmlDocGetRootElement(doc)) == NULL) { - fprintf(stderr, "Error: failed to add CipherValue node\n"); - goto done; + fprintf(stderr, "Error: failed to add CipherValue node\n"); + goto done; } /* add key information */ cur = xmlSecTmplEncDataEnsureKeyInfo(xmlDocGetRootElement(doc), NULL); if(cur == NULL) { - fprintf(stderr, "Error: failed to add KeyInfo node\n"); - goto done; + fprintf(stderr, "Error: failed to add KeyInfo node\n"); + goto done; } if(xmlSecTmplKeyInfoAddKeyName(cur, NULL) == NULL) { - fprintf(stderr, "Error: failed to add KeyName node\n"); - goto done; + fprintf(stderr, "Error: failed to add KeyName node\n"); + goto done; } /* encrypt */ start_time = clock(); if(xmlSecEncCtxBinaryEncrypt(&encCtx, xmlDocGetRootElement(doc), - (const xmlSecByte*)data, strlen(data)) < 0) { - fprintf(stderr, "Error: failed to encrypt data\n"); - goto done; + (const xmlSecByte*)data, strlen(data)) < 0) { + fprintf(stderr, "Error: failed to encrypt data\n"); + goto done; } total_time += clock() - start_time; /* print out result only once per execution */ if(repeats <= 1) { - if(encCtx.resultReplaced) { - if(xmlSecAppWriteResult(doc, NULL) < 0) { - goto done; - } - } else { - if(xmlSecAppWriteResult(NULL, encCtx.result) < 0) { - goto done; - } - } + if(encCtx.resultReplaced) { + if(xmlSecAppWriteResult(doc, NULL) < 0) { + goto done; + } + } else { + if(xmlSecAppWriteResult(NULL, encCtx.result) < 0) { + goto done; + } + } } res = 0; done: /* print debug info if requested */ if(repeats <= 1) { - xmlSecAppPrintEncCtx(&encCtx); + xmlSecAppPrintEncCtx(&encCtx); } xmlSecEncCtxFinalize(&encCtx); if(doc != NULL) { - xmlFreeDoc(doc); + xmlFreeDoc(doc); } return(res); } @@ -1833,34 +1828,34 @@ done: static int xmlSecAppPrepareEncCtx(xmlSecEncCtxPtr encCtx) { if(encCtx == NULL) { - fprintf(stderr, "Error: enc context is null\n"); - return(-1); + fprintf(stderr, "Error: enc context is null\n"); + return(-1); } /* set key info params */ if(xmlSecAppPrepareKeyInfoReadCtx(&(encCtx->keyInfoReadCtx)) < 0) { - fprintf(stderr, "Error: failed to prepare key info context\n"); - return(-1); + fprintf(stderr, "Error: failed to prepare key info context\n"); + return(-1); } if(xmlSecAppCmdLineParamGetString(&sessionKeyParam) != NULL) { - encCtx->encKey = xmlSecAppCryptoKeyGenerate(xmlSecAppCmdLineParamGetString(&sessionKeyParam), - NULL, xmlSecKeyDataTypeSession); - if(encCtx->encKey == NULL) { - fprintf(stderr, "Error: failed to generate a session key \"%s\"\n", - xmlSecAppCmdLineParamGetString(&sessionKeyParam)); - return(-1); - } + encCtx->encKey = xmlSecAppCryptoKeyGenerate(xmlSecAppCmdLineParamGetString(&sessionKeyParam), + NULL, xmlSecKeyDataTypeSession); + if(encCtx->encKey == NULL) { + fprintf(stderr, "Error: failed to generate a session key \"%s\"\n", + xmlSecAppCmdLineParamGetString(&sessionKeyParam)); + return(-1); + } } if(xmlSecAppCmdLineParamGetStringList(&enabledCipherRefUrisParam) != NULL) { - encCtx->transformCtx.enabledUris = xmlSecAppGetUriType( - xmlSecAppCmdLineParamGetStringList(&enabledCipherRefUrisParam)); - if(encCtx->transformCtx.enabledUris == xmlSecTransformUriTypeNone) { - fprintf(stderr, "Error: failed to parse \"%s\"\n", - xmlSecAppCmdLineParamGetStringList(&enabledCipherRefUrisParam)); - return(-1); - } + encCtx->transformCtx.enabledUris = xmlSecAppGetUriType( + xmlSecAppCmdLineParamGetStringList(&enabledCipherRefUrisParam)); + if(encCtx->transformCtx.enabledUris == xmlSecTransformUriTypeNone) { + fprintf(stderr, "Error: failed to parse \"%s\"\n", + xmlSecAppCmdLineParamGetStringList(&enabledCipherRefUrisParam)); + return(-1); + } } return(0); } @@ -1868,16 +1863,16 @@ xmlSecAppPrepareEncCtx(xmlSecEncCtxPtr encCtx) { static void xmlSecAppPrintEncCtx(xmlSecEncCtxPtr encCtx) { if(encCtx == NULL) { - return; + return; } /* print debug info if requested */ if((print_debug != 0) || xmlSecAppCmdLineParamIsSet(&printDebugParam)) { - xmlSecEncCtxDebugDump(encCtx, stdout); + xmlSecEncCtxDebugDump(encCtx, stdout); } - if(xmlSecAppCmdLineParamIsSet(&printXmlDebugParam)) { - xmlSecEncCtxDebugXmlDump(encCtx, stdout); + if(xmlSecAppCmdLineParamIsSet(&printXmlDebugParam)) { + xmlSecEncCtxDebugXmlDump(encCtx, stdout); } } @@ -1895,48 +1890,48 @@ xmlSecAppXkmsServerProcess(const char* filename) { int res = -1; if(filename == NULL) { - return(-1); + return(-1); } if(xmlSecXkmsServerCtxInitialize(&xkmsServerCtx, gKeysMngr) < 0) { - fprintf(stderr, "Error: XKMS server context initialization failed\n"); - return(-1); + fprintf(stderr, "Error: XKMS server context initialization failed\n"); + return(-1); } if(xmlSecAppPrepareXkmsServerCtx(&xkmsServerCtx) < 0) { - fprintf(stderr, "Error: XKMS server context preparation failed\n"); - goto done; + fprintf(stderr, "Error: XKMS server context preparation failed\n"); + goto done; } /* get the input format */ if(xmlSecAppCmdLineParamGetString(&xkmsFormatParam) != NULL) { - format = xmlSecXkmsServerFormatFromString(BAD_CAST xmlSecAppCmdLineParamGetString(&xkmsFormatParam)); - if(format == xmlSecXkmsServerFormatUnknown) { - fprintf(stderr, "Error: unknown format \"%s\"\n", - xmlSecAppCmdLineParamGetString(&xkmsFormatParam)); - return(-1); - } + format = xmlSecXkmsServerFormatFromString(BAD_CAST xmlSecAppCmdLineParamGetString(&xkmsFormatParam)); + if(format == xmlSecXkmsServerFormatUnknown) { + fprintf(stderr, "Error: unknown format \"%s\"\n", + xmlSecAppCmdLineParamGetString(&xkmsFormatParam)); + return(-1); + } } /* parse template and select start node, there are multiple options * for start node thus we don't provide the default start node name */ data = xmlSecAppXmlDataCreate(filename, NULL, NULL); if(data == NULL) { - fprintf(stderr, "Error: failed to load request from file \"%s\"\n", filename); - goto done; + fprintf(stderr, "Error: failed to load request from file \"%s\"\n", filename); + goto done; } /* prepare result document */ doc = xmlNewDoc(BAD_CAST "1.0"); if(doc == NULL) { - fprintf(stderr, "Error: failed to create doc\n"); - goto done; + fprintf(stderr, "Error: failed to create doc\n"); + goto done; } start_time = clock(); result = xmlSecXkmsServerCtxProcess(&xkmsServerCtx, data->startNode, format, doc); if(result == NULL) { - fprintf(stderr, "Error: failed to process xkms server request\n"); - goto done; + fprintf(stderr, "Error: failed to process xkms server request\n"); + goto done; } total_time += clock() - start_time; @@ -1944,9 +1939,9 @@ xmlSecAppXkmsServerProcess(const char* filename) { /* print out result only once per execution */ xmlDocSetRootElement(doc, result); if(repeats <= 1) { - if(xmlSecAppWriteResult(doc, NULL) < 0) { - goto done; - } + if(xmlSecAppWriteResult(doc, NULL) < 0) { + goto done; + } } res = 0; @@ -1959,10 +1954,10 @@ done: xmlSecXkmsServerCtxFinalize(&xkmsServerCtx); if(doc != NULL) { - xmlFreeDoc(doc); + xmlFreeDoc(doc); } if(data != NULL) { - xmlSecAppXmlDataDestroy(data); + xmlSecAppXmlDataDestroy(data); } return(res); } @@ -1970,33 +1965,33 @@ done: static int xmlSecAppPrepareXkmsServerCtx(xmlSecXkmsServerCtxPtr xkmsServerCtx) { if(xkmsServerCtx == NULL) { - fprintf(stderr, "Error: XKMS context is null\n"); - return(-1); + fprintf(stderr, "Error: XKMS context is null\n"); + return(-1); } /* set key info params */ if(xmlSecAppPrepareKeyInfoReadCtx(&(xkmsServerCtx->keyInfoReadCtx)) < 0) { - fprintf(stderr, "Error: failed to prepare key info context\n"); - return(-1); + fprintf(stderr, "Error: failed to prepare key info context\n"); + return(-1); } if(xmlSecAppCmdLineParamGetString(&xkmsServiceParam) != NULL) { - xkmsServerCtx->expectedService = xmlStrdup(BAD_CAST xmlSecAppCmdLineParamGetString(&xkmsServiceParam)); - if(xkmsServerCtx->expectedService == NULL) { - fprintf(stderr, "Error: failed to duplicate string \"%s\"\n", - xmlSecAppCmdLineParamGetString(&xkmsServiceParam)); - return(-1); - } + xkmsServerCtx->expectedService = xmlStrdup(BAD_CAST xmlSecAppCmdLineParamGetString(&xkmsServiceParam)); + if(xkmsServerCtx->expectedService == NULL) { + fprintf(stderr, "Error: failed to duplicate string \"%s\"\n", + xmlSecAppCmdLineParamGetString(&xkmsServiceParam)); + return(-1); + } } if(xmlSecAppCmdLineParamIsSet(&xkmsStopUnknownResponseMechanismParam)) { - xkmsServerCtx->flags |= XMLSEC_XKMS_SERVER_FLAGS_STOP_ON_UNKNOWN_RESPONSE_MECHANISM; + xkmsServerCtx->flags |= XMLSEC_XKMS_SERVER_FLAGS_STOP_ON_UNKNOWN_RESPONSE_MECHANISM; } if(xmlSecAppCmdLineParamIsSet(&xkmsStopUnknownRespondWithParam)) { - xkmsServerCtx->flags |= XMLSEC_XKMS_SERVER_FLAGS_STOP_ON_UNKNOWN_RESPOND_WITH; + xkmsServerCtx->flags |= XMLSEC_XKMS_SERVER_FLAGS_STOP_ON_UNKNOWN_RESPOND_WITH; } if(xmlSecAppCmdLineParamIsSet(&xkmsStopUnknownKeyUsageParam)) { - xkmsServerCtx->flags |= XMLSEC_XKMS_SERVER_FLAGS_STOP_ON_UNKNOWN_KEY_USAGE; + xkmsServerCtx->flags |= XMLSEC_XKMS_SERVER_FLAGS_STOP_ON_UNKNOWN_KEY_USAGE; } return(0); } @@ -2004,16 +1999,16 @@ xmlSecAppPrepareXkmsServerCtx(xmlSecXkmsServerCtxPtr xkmsServerCtx) { static void xmlSecAppPrintXkmsServerCtx(xmlSecXkmsServerCtxPtr xkmsServerCtx) { if(xkmsServerCtx == NULL) { - return; + return; } /* print debug info if requested */ if((print_debug != 0) || xmlSecAppCmdLineParamIsSet(&printDebugParam)) { - xmlSecXkmsServerCtxDebugDump(xkmsServerCtx, stdout); + xmlSecXkmsServerCtxDebugDump(xkmsServerCtx, stdout); } - if(xmlSecAppCmdLineParamIsSet(&printXmlDebugParam)) { - xmlSecXkmsServerCtxDebugXmlDump(xkmsServerCtx, stdout); + if(xmlSecAppCmdLineParamIsSet(&printXmlDebugParam)) { + xmlSecXkmsServerCtxDebugXmlDump(xkmsServerCtx, stdout); } } @@ -2053,56 +2048,56 @@ xmlSecAppPrepareKeyInfoReadCtx(xmlSecKeyInfoCtxPtr keyInfoCtx) { int ret; if(keyInfoCtx == NULL) { - fprintf(stderr, "Error: key info context is null\n"); - return(-1); + fprintf(stderr, "Error: key info context is null\n"); + return(-1); } #ifndef XMLSEC_NO_X509 if(xmlSecAppCmdLineParamIsSet(&verificationTimeParam)) { - keyInfoCtx->certsVerificationTime = xmlSecAppCmdLineParamGetTime(&verificationTimeParam, 0); + keyInfoCtx->certsVerificationTime = xmlSecAppCmdLineParamGetTime(&verificationTimeParam, 0); } if(xmlSecAppCmdLineParamIsSet(&depthParam)) { - keyInfoCtx->certsVerificationDepth = xmlSecAppCmdLineParamGetInt(&depthParam, 0); + keyInfoCtx->certsVerificationDepth = xmlSecAppCmdLineParamGetInt(&depthParam, 0); } if(xmlSecAppCmdLineParamIsSet(&X509SkipStrictChecksParam)) { - keyInfoCtx->flags |= XMLSEC_KEYINFO_FLAGS_X509DATA_SKIP_STRICT_CHECKS; + keyInfoCtx->flags |= XMLSEC_KEYINFO_FLAGS_X509DATA_SKIP_STRICT_CHECKS; } #endif /* XMLSEC_NO_X509 */ /* read enabled key data list */ for(value = enabledKeyDataParam.value; value != NULL; value = value->next) { - if(value->strListValue == NULL) { - fprintf(stderr, "Error: invalid value for option \"%s\".\n", - enabledKeyDataParam.fullName); - return(-1); - } else { - xmlSecKeyDataId dataId; - const char* p; - - for(p = value->strListValue; (p != NULL) && ((*p) != '\0'); p += strlen(p)) { - dataId = xmlSecKeyDataIdListFindByName(xmlSecKeyDataIdsGet(), BAD_CAST p, xmlSecKeyDataUsageAny); - if(dataId == xmlSecKeyDataIdUnknown) { - fprintf(stderr, "Error: key data \"%s\" is unknown.\n", p); - return(-1); - } - ret = xmlSecPtrListAdd(&(keyInfoCtx->enabledKeyData), (const xmlSecPtr)dataId); - if(ret < 0) { - fprintf(stderr, "Error: failed to enable key data \"%s\".\n", p); - return(-1); - } - } - } + if(value->strListValue == NULL) { + fprintf(stderr, "Error: invalid value for option \"%s\".\n", + enabledKeyDataParam.fullName); + return(-1); + } else { + xmlSecKeyDataId dataId; + const char* p; + + for(p = value->strListValue; (p != NULL) && ((*p) != '\0'); p += strlen(p)) { + dataId = xmlSecKeyDataIdListFindByName(xmlSecKeyDataIdsGet(), BAD_CAST p, xmlSecKeyDataUsageAny); + if(dataId == xmlSecKeyDataIdUnknown) { + fprintf(stderr, "Error: key data \"%s\" is unknown.\n", p); + return(-1); + } + ret = xmlSecPtrListAdd(&(keyInfoCtx->enabledKeyData), (const xmlSecPtr)dataId); + if(ret < 0) { + fprintf(stderr, "Error: failed to enable key data \"%s\".\n", p); + return(-1); + } + } + } } /* read enabled RetrievalMethod uris */ if(xmlSecAppCmdLineParamGetStringList(&enabledRetrievalMethodUrisParam) != NULL) { - keyInfoCtx->retrievalMethodCtx.enabledUris = xmlSecAppGetUriType( - xmlSecAppCmdLineParamGetStringList(&enabledRetrievalMethodUrisParam)); - if(keyInfoCtx->retrievalMethodCtx.enabledUris == xmlSecTransformUriTypeNone) { - fprintf(stderr, "Error: failed to parse \"%s\"\n", - xmlSecAppCmdLineParamGetStringList(&enabledRetrievalMethodUrisParam)); - return(-1); - } + keyInfoCtx->retrievalMethodCtx.enabledUris = xmlSecAppGetUriType( + xmlSecAppCmdLineParamGetStringList(&enabledRetrievalMethodUrisParam)); + if(keyInfoCtx->retrievalMethodCtx.enabledUris == xmlSecTransformUriTypeNone) { + fprintf(stderr, "Error: failed to parse \"%s\"\n", + xmlSecAppCmdLineParamGetStringList(&enabledRetrievalMethodUrisParam)); + return(-1); + } } return(0); @@ -2113,290 +2108,290 @@ xmlSecAppLoadKeys(void) { xmlSecAppCmdLineValuePtr value; if(gKeysMngr != NULL) { - fprintf(stderr, "Error: keys manager already initialized.\n"); - return(-1); + fprintf(stderr, "Error: keys manager already initialized.\n"); + return(-1); } /* create and initialize keys manager */ gKeysMngr = xmlSecKeysMngrCreate(); if(gKeysMngr == NULL) { - fprintf(stderr, "Error: failed to create keys manager.\n"); - return(-1); + fprintf(stderr, "Error: failed to create keys manager.\n"); + return(-1); } if(xmlSecAppCryptoSimpleKeysMngrInit(gKeysMngr) < 0) { - fprintf(stderr, "Error: failed to initialize keys manager.\n"); - return(-1); + fprintf(stderr, "Error: failed to initialize keys manager.\n"); + return(-1); } /* generate new key file */ for(value = genKeyParam.value; value != NULL; value = value->next) { - if(value->strValue == NULL) { - fprintf(stderr, "Error: invalid value for option \"%s\".\n", genKeyParam.fullName); - return(-1); - } else if(xmlSecAppCryptoSimpleKeysMngrKeyGenerate(gKeysMngr, value->strValue, value->paramNameValue) < 0) { - fprintf(stderr, "Error: failed to generate key \"%s\".\n", value->strValue); - return(-1); - } + if(value->strValue == NULL) { + fprintf(stderr, "Error: invalid value for option \"%s\".\n", genKeyParam.fullName); + return(-1); + } else if(xmlSecAppCryptoSimpleKeysMngrKeyGenerate(gKeysMngr, value->strValue, value->paramNameValue) < 0) { + fprintf(stderr, "Error: failed to generate key \"%s\".\n", value->strValue); + return(-1); + } } /* read all xml key files */ for(value = keysFileParam.value; value != NULL; value = value->next) { - if(value->strValue == NULL) { - fprintf(stderr, "Error: invalid value for option \"%s\".\n", keysFileParam.fullName); - return(-1); - } else if(xmlSecAppCryptoSimpleKeysMngrLoad(gKeysMngr, value->strValue) < 0) { - fprintf(stderr, "Error: failed to load xml keys file \"%s\".\n", value->strValue); - return(-1); - } + if(value->strValue == NULL) { + fprintf(stderr, "Error: invalid value for option \"%s\".\n", keysFileParam.fullName); + return(-1); + } else if(xmlSecAppCryptoSimpleKeysMngrLoad(gKeysMngr, value->strValue) < 0) { + fprintf(stderr, "Error: failed to load xml keys file \"%s\".\n", value->strValue); + return(-1); + } } /* read all private keys */ for(value = privkeyParam.value; value != NULL; value = value->next) { - if(value->strValue == NULL) { - fprintf(stderr, "Error: invalid value for option \"%s\".\n", - privkeyParam.fullName); - return(-1); - } else if(xmlSecAppCryptoSimpleKeysMngrKeyAndCertsLoad(gKeysMngr, - value->strListValue, - xmlSecAppCmdLineParamGetString(&pwdParam), - value->paramNameValue, - xmlSecKeyDataFormatPem) < 0) { - fprintf(stderr, "Error: failed to load private key from \"%s\".\n", - value->strListValue); - return(-1); - } + if(value->strValue == NULL) { + fprintf(stderr, "Error: invalid value for option \"%s\".\n", + privkeyParam.fullName); + return(-1); + } else if(xmlSecAppCryptoSimpleKeysMngrKeyAndCertsLoad(gKeysMngr, + value->strListValue, + xmlSecAppCmdLineParamGetString(&pwdParam), + value->paramNameValue, + xmlSecKeyDataFormatPem) < 0) { + fprintf(stderr, "Error: failed to load private key from \"%s\".\n", + value->strListValue); + return(-1); + } } for(value = privkeyDerParam.value; value != NULL; value = value->next) { - if(value->strValue == NULL) { - fprintf(stderr, "Error: invalid value for option \"%s\".\n", - privkeyDerParam.fullName); - return(-1); - } else if(xmlSecAppCryptoSimpleKeysMngrKeyAndCertsLoad(gKeysMngr, - value->strListValue, - xmlSecAppCmdLineParamGetString(&pwdParam), - value->paramNameValue, - xmlSecKeyDataFormatDer) < 0) { - fprintf(stderr, "Error: failed to load private key from \"%s\".\n", - value->strListValue); - return(-1); - } + if(value->strValue == NULL) { + fprintf(stderr, "Error: invalid value for option \"%s\".\n", + privkeyDerParam.fullName); + return(-1); + } else if(xmlSecAppCryptoSimpleKeysMngrKeyAndCertsLoad(gKeysMngr, + value->strListValue, + xmlSecAppCmdLineParamGetString(&pwdParam), + value->paramNameValue, + xmlSecKeyDataFormatDer) < 0) { + fprintf(stderr, "Error: failed to load private key from \"%s\".\n", + value->strListValue); + return(-1); + } } for(value = pkcs8PemParam.value; value != NULL; value = value->next) { - if(value->strValue == NULL) { - fprintf(stderr, "Error: invalid value for option \"%s\".\n", - pkcs8PemParam.fullName); - return(-1); - } else if(xmlSecAppCryptoSimpleKeysMngrKeyAndCertsLoad(gKeysMngr, - value->strListValue, - xmlSecAppCmdLineParamGetString(&pwdParam), - value->paramNameValue, - xmlSecKeyDataFormatPkcs8Pem) < 0) { - fprintf(stderr, "Error: failed to load private key from \"%s\".\n", - value->strListValue); - return(-1); - } + if(value->strValue == NULL) { + fprintf(stderr, "Error: invalid value for option \"%s\".\n", + pkcs8PemParam.fullName); + return(-1); + } else if(xmlSecAppCryptoSimpleKeysMngrKeyAndCertsLoad(gKeysMngr, + value->strListValue, + xmlSecAppCmdLineParamGetString(&pwdParam), + value->paramNameValue, + xmlSecKeyDataFormatPkcs8Pem) < 0) { + fprintf(stderr, "Error: failed to load private key from \"%s\".\n", + value->strListValue); + return(-1); + } } for(value = pkcs8DerParam.value; value != NULL; value = value->next) { - if(value->strValue == NULL) { - fprintf(stderr, "Error: invalid value for option \"%s\".\n", - pkcs8DerParam.fullName); - return(-1); - } else if(xmlSecAppCryptoSimpleKeysMngrKeyAndCertsLoad(gKeysMngr, - value->strListValue, - xmlSecAppCmdLineParamGetString(&pwdParam), - value->paramNameValue, - xmlSecKeyDataFormatPkcs8Der) < 0) { - fprintf(stderr, "Error: failed to load private key from \"%s\".\n", - value->strListValue); - return(-1); - } + if(value->strValue == NULL) { + fprintf(stderr, "Error: invalid value for option \"%s\".\n", + pkcs8DerParam.fullName); + return(-1); + } else if(xmlSecAppCryptoSimpleKeysMngrKeyAndCertsLoad(gKeysMngr, + value->strListValue, + xmlSecAppCmdLineParamGetString(&pwdParam), + value->paramNameValue, + xmlSecKeyDataFormatPkcs8Der) < 0) { + fprintf(stderr, "Error: failed to load private key from \"%s\".\n", + value->strListValue); + return(-1); + } } /* read all public keys */ for(value = pubkeyParam.value; value != NULL; value = value->next) { - if(value->strValue == NULL) { - fprintf(stderr, "Error: invalid value for option \"%s\".\n", - pubkeyParam.fullName); - return(-1); - } else if(xmlSecAppCryptoSimpleKeysMngrKeyAndCertsLoad(gKeysMngr, - value->strListValue, - xmlSecAppCmdLineParamGetString(&pwdParam), - value->paramNameValue, - xmlSecKeyDataFormatPem) < 0) { - fprintf(stderr, "Error: failed to load public key from \"%s\".\n", - value->strListValue); - return(-1); - } + if(value->strValue == NULL) { + fprintf(stderr, "Error: invalid value for option \"%s\".\n", + pubkeyParam.fullName); + return(-1); + } else if(xmlSecAppCryptoSimpleKeysMngrKeyAndCertsLoad(gKeysMngr, + value->strListValue, + xmlSecAppCmdLineParamGetString(&pwdParam), + value->paramNameValue, + xmlSecKeyDataFormatPem) < 0) { + fprintf(stderr, "Error: failed to load public key from \"%s\".\n", + value->strListValue); + return(-1); + } } for(value = pubkeyDerParam.value; value != NULL; value = value->next) { - if(value->strValue == NULL) { - fprintf(stderr, "Error: invalid value for option \"%s\".\n", - pubkeyDerParam.fullName); - return(-1); - } else if(xmlSecAppCryptoSimpleKeysMngrKeyAndCertsLoad(gKeysMngr, - value->strListValue, - xmlSecAppCmdLineParamGetString(&pwdParam), - value->paramNameValue, - xmlSecKeyDataFormatDer) < 0) { - fprintf(stderr, "Error: failed to load public key from \"%s\".\n", - value->strListValue); - return(-1); - } + if(value->strValue == NULL) { + fprintf(stderr, "Error: invalid value for option \"%s\".\n", + pubkeyDerParam.fullName); + return(-1); + } else if(xmlSecAppCryptoSimpleKeysMngrKeyAndCertsLoad(gKeysMngr, + value->strListValue, + xmlSecAppCmdLineParamGetString(&pwdParam), + value->paramNameValue, + xmlSecKeyDataFormatDer) < 0) { + fprintf(stderr, "Error: failed to load public key from \"%s\".\n", + value->strListValue); + return(-1); + } } #ifndef XMLSEC_NO_AES /* read all AES keys */ for(value = aeskeyParam.value; value != NULL; value = value->next) { - if(value->strValue == NULL) { - fprintf(stderr, "Error: invalid value for option \"%s\".\n", - aeskeyParam.fullName); - return(-1); - } else if(xmlSecAppCryptoSimpleKeysMngrBinaryKeyLoad(gKeysMngr, - "aes", value->strValue, value->paramNameValue) < 0) { - fprintf(stderr, "Error: failed to load aes key from \"%s\".\n", - value->strValue); - return(-1); - } + if(value->strValue == NULL) { + fprintf(stderr, "Error: invalid value for option \"%s\".\n", + aeskeyParam.fullName); + return(-1); + } else if(xmlSecAppCryptoSimpleKeysMngrBinaryKeyLoad(gKeysMngr, + "aes", value->strValue, value->paramNameValue) < 0) { + fprintf(stderr, "Error: failed to load aes key from \"%s\".\n", + value->strValue); + return(-1); + } } #endif /* XMLSEC_NO_AES */ #ifndef XMLSEC_NO_DES /* read all des keys */ for(value = deskeyParam.value; value != NULL; value = value->next) { - if(value->strValue == NULL) { - fprintf(stderr, "Error: invalid value for option \"%s\".\n", - deskeyParam.fullName); - return(-1); - } else if(xmlSecAppCryptoSimpleKeysMngrBinaryKeyLoad(gKeysMngr, - "des", value->strValue, value->paramNameValue) < 0) { - fprintf(stderr, "Error: failed to load des key from \"%s\".\n", - value->strValue); - return(-1); - } + if(value->strValue == NULL) { + fprintf(stderr, "Error: invalid value for option \"%s\".\n", + deskeyParam.fullName); + return(-1); + } else if(xmlSecAppCryptoSimpleKeysMngrBinaryKeyLoad(gKeysMngr, + "des", value->strValue, value->paramNameValue) < 0) { + fprintf(stderr, "Error: failed to load des key from \"%s\".\n", + value->strValue); + return(-1); + } } #endif /* XMLSEC_NO_DES */ #ifndef XMLSEC_NO_HMAC /* read all hmac keys */ for(value = hmackeyParam.value; value != NULL; value = value->next) { - if(value->strValue == NULL) { - fprintf(stderr, "Error: invalid value for option \"%s\".\n", - hmackeyParam.fullName); - return(-1); - } else if(xmlSecAppCryptoSimpleKeysMngrBinaryKeyLoad(gKeysMngr, - "hmac", value->strValue, value->paramNameValue) < 0) { - fprintf(stderr, "Error: failed to load hmac key from \"%s\".\n", - value->strValue); - return(-1); - } + if(value->strValue == NULL) { + fprintf(stderr, "Error: invalid value for option \"%s\".\n", + hmackeyParam.fullName); + return(-1); + } else if(xmlSecAppCryptoSimpleKeysMngrBinaryKeyLoad(gKeysMngr, + "hmac", value->strValue, value->paramNameValue) < 0) { + fprintf(stderr, "Error: failed to load hmac key from \"%s\".\n", + value->strValue); + return(-1); + } } #endif /* XMLSEC_NO_HMAC */ #ifndef XMLSEC_NO_X509 /* read all pkcs12 files */ for(value = pkcs12Param.value; value != NULL; value = value->next) { - if(value->strValue == NULL) { - fprintf(stderr, "Error: invalid value for option \"%s\".\n", pkcs12Param.fullName); - return(-1); - } else if(xmlSecAppCryptoSimpleKeysMngrPkcs12KeyLoad(gKeysMngr, - value->strValue, - xmlSecAppCmdLineParamGetString(&pwdParam), - value->paramNameValue) < 0) { - fprintf(stderr, "Error: failed to load pkcs12 key from \"%s\".\n", - value->strValue); - return(-1); - } + if(value->strValue == NULL) { + fprintf(stderr, "Error: invalid value for option \"%s\".\n", pkcs12Param.fullName); + return(-1); + } else if(xmlSecAppCryptoSimpleKeysMngrPkcs12KeyLoad(gKeysMngr, + value->strValue, + xmlSecAppCmdLineParamGetString(&pwdParam), + value->paramNameValue) < 0) { + fprintf(stderr, "Error: failed to load pkcs12 key from \"%s\".\n", + value->strValue); + return(-1); + } } /* read all trusted certs */ for(value = trustedParam.value; value != NULL; value = value->next) { - if(value->strValue == NULL) { - fprintf(stderr, "Error: invalid value for option \"%s\".\n", trustedParam.fullName); - return(-1); - } else if(xmlSecAppCryptoSimpleKeysMngrCertLoad(gKeysMngr, - value->strValue, xmlSecKeyDataFormatPem, - xmlSecKeyDataTypeTrusted) < 0) { - fprintf(stderr, "Error: failed to load trusted cert from \"%s\".\n", - value->strValue); - return(-1); - } + if(value->strValue == NULL) { + fprintf(stderr, "Error: invalid value for option \"%s\".\n", trustedParam.fullName); + return(-1); + } else if(xmlSecAppCryptoSimpleKeysMngrCertLoad(gKeysMngr, + value->strValue, xmlSecKeyDataFormatPem, + xmlSecKeyDataTypeTrusted) < 0) { + fprintf(stderr, "Error: failed to load trusted cert from \"%s\".\n", + value->strValue); + return(-1); + } } for(value = trustedDerParam.value; value != NULL; value = value->next) { - if(value->strValue == NULL) { - fprintf(stderr, "Error: invalid value for option \"%s\".\n", trustedDerParam.fullName); - return(-1); - } else if(xmlSecAppCryptoSimpleKeysMngrCertLoad(gKeysMngr, - value->strValue, xmlSecKeyDataFormatDer, - xmlSecKeyDataTypeTrusted) < 0) { - fprintf(stderr, "Error: failed to load trusted cert from \"%s\".\n", - value->strValue); - return(-1); - } + if(value->strValue == NULL) { + fprintf(stderr, "Error: invalid value for option \"%s\".\n", trustedDerParam.fullName); + return(-1); + } else if(xmlSecAppCryptoSimpleKeysMngrCertLoad(gKeysMngr, + value->strValue, xmlSecKeyDataFormatDer, + xmlSecKeyDataTypeTrusted) < 0) { + fprintf(stderr, "Error: failed to load trusted cert from \"%s\".\n", + value->strValue); + return(-1); + } } /* read all public keys in certs */ for(value = pubkeyCertParam.value; value != NULL; value = value->next) { - if(value->strValue == NULL) { - fprintf(stderr, "Error: invalid value for option \"%s\".\n", - pubkeyCertParam.fullName); - return(-1); - } else if(xmlSecAppCryptoSimpleKeysMngrKeyAndCertsLoad(gKeysMngr, - value->strListValue, - xmlSecAppCmdLineParamGetString(&pwdParam), - value->paramNameValue, - xmlSecKeyDataFormatCertPem) < 0) { - fprintf(stderr, "Error: failed to load public key from \"%s\".\n", - value->strListValue); - return(-1); - } + if(value->strValue == NULL) { + fprintf(stderr, "Error: invalid value for option \"%s\".\n", + pubkeyCertParam.fullName); + return(-1); + } else if(xmlSecAppCryptoSimpleKeysMngrKeyAndCertsLoad(gKeysMngr, + value->strListValue, + xmlSecAppCmdLineParamGetString(&pwdParam), + value->paramNameValue, + xmlSecKeyDataFormatCertPem) < 0) { + fprintf(stderr, "Error: failed to load public key from \"%s\".\n", + value->strListValue); + return(-1); + } } for(value = pubkeyCertDerParam.value; value != NULL; value = value->next) { - if(value->strValue == NULL) { - fprintf(stderr, "Error: invalid value for option \"%s\".\n", - pubkeyCertDerParam.fullName); - return(-1); - } else if(xmlSecAppCryptoSimpleKeysMngrKeyAndCertsLoad(gKeysMngr, - value->strListValue, - xmlSecAppCmdLineParamGetString(&pwdParam), - value->paramNameValue, - xmlSecKeyDataFormatCertDer) < 0) { - fprintf(stderr, "Error: failed to load public key from \"%s\".\n", - value->strListValue); - return(-1); - } + if(value->strValue == NULL) { + fprintf(stderr, "Error: invalid value for option \"%s\".\n", + pubkeyCertDerParam.fullName); + return(-1); + } else if(xmlSecAppCryptoSimpleKeysMngrKeyAndCertsLoad(gKeysMngr, + value->strListValue, + xmlSecAppCmdLineParamGetString(&pwdParam), + value->paramNameValue, + xmlSecKeyDataFormatCertDer) < 0) { + fprintf(stderr, "Error: failed to load public key from \"%s\".\n", + value->strListValue); + return(-1); + } } /* read all untrusted certs */ for(value = untrustedParam.value; value != NULL; value = value->next) { - if(value->strValue == NULL) { - fprintf(stderr, "Error: invalid value for option \"%s\".\n", untrustedParam.fullName); - return(-1); - } else if(xmlSecAppCryptoSimpleKeysMngrCertLoad(gKeysMngr, - value->strValue, xmlSecKeyDataFormatPem, - xmlSecKeyDataTypeNone) < 0) { - fprintf(stderr, "Error: failed to load untrusted cert from \"%s\".\n", - value->strValue); - return(-1); - } + if(value->strValue == NULL) { + fprintf(stderr, "Error: invalid value for option \"%s\".\n", untrustedParam.fullName); + return(-1); + } else if(xmlSecAppCryptoSimpleKeysMngrCertLoad(gKeysMngr, + value->strValue, xmlSecKeyDataFormatPem, + xmlSecKeyDataTypeNone) < 0) { + fprintf(stderr, "Error: failed to load untrusted cert from \"%s\".\n", + value->strValue); + return(-1); + } } for(value = untrustedDerParam.value; value != NULL; value = value->next) { - if(value->strValue == NULL) { - fprintf(stderr, "Error: invalid value for option \"%s\".\n", untrustedDerParam.fullName); - return(-1); - } else if(xmlSecAppCryptoSimpleKeysMngrCertLoad(gKeysMngr, - value->strValue, xmlSecKeyDataFormatDer, - xmlSecKeyDataTypeNone) < 0) { - fprintf(stderr, "Error: failed to load untrusted cert from \"%s\".\n", - value->strValue); - return(-1); - } + if(value->strValue == NULL) { + fprintf(stderr, "Error: invalid value for option \"%s\".\n", untrustedDerParam.fullName); + return(-1); + } else if(xmlSecAppCryptoSimpleKeysMngrCertLoad(gKeysMngr, + value->strValue, xmlSecKeyDataFormatDer, + xmlSecKeyDataTypeNone) < 0) { + fprintf(stderr, "Error: failed to load untrusted cert from \"%s\".\n", + value->strValue); + return(-1); + } } #endif /* XMLSEC_NO_X509 */ @@ -2405,15 +2400,10 @@ xmlSecAppLoadKeys(void) { } static int intialized = 0; - -#ifndef XMLSEC_NO_XSLT -static xsltSecurityPrefsPtr xsltSecPrefs = NULL; -#endif /* XMLSEC_NO_XSLT */ - static int xmlSecAppInit(void) { if(intialized != 0) { - return(0); + return(0); } intialized = 1; @@ -2424,44 +2414,31 @@ xmlSecAppInit(void) { #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 */ if(xmlSecInit() < 0) { - fprintf(stderr, "Error: xmlsec intialization failed.\n"); - return(-1); + fprintf(stderr, "Error: xmlsec intialization failed.\n"); + return(-1); } if(xmlSecCheckVersion() != 1) { - fprintf(stderr, "Error: loaded xmlsec library version is not compatible.\n"); - return(-1); + fprintf(stderr, "Error: loaded xmlsec library version is not compatible.\n"); + return(-1); } #if !defined(XMLSEC_NO_CRYPTO_DYNAMIC_LOADING) && defined(XMLSEC_CRYPTO_DYNAMIC_LOADING) if(xmlSecCryptoDLLoadLibrary(BAD_CAST xmlsec_crypto) < 0) { - fprintf(stderr, "Error: unable to load xmlsec-%s library. Make sure that you have\n" - "this it installed, check shared libraries path (LD_LIBRARY_PATH)\n" - "envornment variable or use \"--crypto\" option to specify different\n" - "crypto engine.\n", xmlsec_crypto); - return(-1); + fprintf(stderr, "Error: unable to load xmlsec-%s library. Make sure that you have\n" + "this it installed, check shared libraries path (LD_LIBRARY_PATH)\n" + "envornment variable or use \"--crypto\" option to specify different\n" + "crypto engine.\n", xmlsec_crypto); + return(-1); } #endif /* !defined(XMLSEC_NO_CRYPTO_DYNAMIC_LOADING) && defined(XMLSEC_CRYPTO_DYNAMIC_LOADING) */ /* Init Crypto */ if(xmlSecAppCryptoInit(xmlSecAppCmdLineParamGetString(&cryptoConfigParam)) < 0) { - fprintf(stderr, "Error: xmlsec crypto intialization failed.\n"); - return(-1); + fprintf(stderr, "Error: xmlsec crypto intialization failed.\n"); + return(-1); } return(0); } @@ -2469,22 +2446,21 @@ xmlSecAppInit(void) { static void xmlSecAppShutdown(void) { if(intialized == 0) { - return; + return; } /* Shutdown Crypto */ if(xmlSecAppCryptoShutdown() < 0) { - fprintf(stderr, "Error: xmlsec crypto shutdown failed.\n"); + fprintf(stderr, "Error: xmlsec crypto shutdown failed.\n"); } /* Shutdown xmlsec */ if(xmlSecShutdown() < 0) { - fprintf(stderr, "Error: xmlsec shutdown failed.\n"); + fprintf(stderr, "Error: xmlsec shutdown failed.\n"); } /* Shutdown libxslt/libxml */ #ifndef XMLSEC_NO_XSLT - xsltFreeSecurityPrefs(xsltSecPrefs); xsltCleanupGlobals(); #endif /* XMLSEC_NO_XSLT */ xmlCleanupParser(); @@ -2497,25 +2473,25 @@ xmlSecAppXmlDataCreate(const char* filename, const xmlChar* defStartNodeName, co xmlNodePtr cur = NULL; if(filename == NULL) { - fprintf(stderr, "Error: xml filename is null\n"); - return(NULL); + fprintf(stderr, "Error: xml filename is null\n"); + return(NULL); } /* create object */ data = (xmlSecAppXmlDataPtr) xmlMalloc(sizeof(xmlSecAppXmlData)); if(data == NULL) { - fprintf(stderr, "Error: failed to create xml data\n"); - return(NULL); + fprintf(stderr, "Error: failed to create xml data\n"); + return(NULL); } memset(data, 0, sizeof(xmlSecAppXmlData)); /* parse doc */ data->doc = xmlSecParseFile(filename); if(data->doc == NULL) { - fprintf(stderr, "Error: failed to parse xml file \"%s\"\n", - filename); - xmlSecAppXmlDataDestroy(data); - return(NULL); + fprintf(stderr, "Error: failed to parse xml file \"%s\"\n", + filename); + xmlSecAppXmlDataDestroy(data); + return(NULL); } /* load dtd and set default attrs and ids */ @@ -2523,178 +2499,178 @@ xmlSecAppXmlDataCreate(const char* filename, const xmlChar* defStartNodeName, co xmlValidCtxt ctx; data->dtd = xmlParseDTD(NULL, BAD_CAST xmlSecAppCmdLineParamGetString(&dtdFileParam)); - if(data->dtd == NULL) { - fprintf(stderr, "Error: failed to parse dtd file \"%s\"\n", - xmlSecAppCmdLineParamGetString(&dtdFileParam)); - xmlSecAppXmlDataDestroy(data); - return(NULL); - } + if(data->dtd == NULL) { + fprintf(stderr, "Error: failed to parse dtd file \"%s\"\n", + xmlSecAppCmdLineParamGetString(&dtdFileParam)); + xmlSecAppXmlDataDestroy(data); + return(NULL); + } - memset(&ctx, 0, sizeof(ctx)); - /* we don't care is doc actually valid or not */ - xmlValidateDtd(&ctx, data->doc, data->dtd); + memset(&ctx, 0, sizeof(ctx)); + /* we don't care is doc actually valid or not */ + xmlValidateDtd(&ctx, data->doc, data->dtd); } /* set ID attributes from command line */ for(value = idAttrParam.value; value != NULL; value = value->next) { - if(value->strValue == NULL) { - fprintf(stderr, "Error: invalid value for option \"%s\".\n", - idAttrParam.fullName); - xmlSecAppXmlDataDestroy(data); - return(NULL); - } else { - xmlChar* attrName = (value->paramNameValue != NULL) ? BAD_CAST value->paramNameValue : BAD_CAST "id"; - xmlChar* nodeName; - xmlChar* nsHref; - xmlChar* buf; - - buf = xmlStrdup(BAD_CAST value->strValue); - if(buf == NULL) { - fprintf(stderr, "Error: failed to duplicate string \"%s\"\n", value->strValue); - xmlSecAppXmlDataDestroy(data); - return(NULL); - } - nodeName = (xmlChar*)strrchr((char*)buf, ':'); - if(nodeName != NULL) { - (*(nodeName++)) = '\0'; - nsHref = buf; - } else { - nodeName = buf; - nsHref = NULL; - } - - /* process children first because it does not matter much but does simplify code */ - cur = xmlSecGetNextElementNode(data->doc->children); - while(cur != NULL) { - if(xmlSecAppAddIDAttr(cur, attrName, nodeName, nsHref) < 0) { - fprintf(stderr, "Error: failed to add ID attribute \"%s\" for node \"%s\"\n", attrName, value->strValue); - xmlFree(buf); - xmlSecAppXmlDataDestroy(data); - return(NULL); - } - cur = xmlSecGetNextElementNode(cur->next); - } - - xmlFree(buf); - } + if(value->strValue == NULL) { + fprintf(stderr, "Error: invalid value for option \"%s\".\n", + idAttrParam.fullName); + xmlSecAppXmlDataDestroy(data); + return(NULL); + } else { + xmlChar* attrName = (value->paramNameValue != NULL) ? BAD_CAST value->paramNameValue : BAD_CAST "id"; + xmlChar* nodeName; + xmlChar* nsHref; + xmlChar* buf; + + buf = xmlStrdup(BAD_CAST value->strValue); + if(buf == NULL) { + fprintf(stderr, "Error: failed to duplicate string \"%s\"\n", value->strValue); + xmlSecAppXmlDataDestroy(data); + return(NULL); + } + nodeName = (xmlChar*)strrchr((char*)buf, ':'); + if(nodeName != NULL) { + (*(nodeName++)) = '\0'; + nsHref = buf; + } else { + nodeName = buf; + nsHref = NULL; + } + + /* process children first because it does not matter much but does simplify code */ + cur = xmlSecGetNextElementNode(data->doc->children); + while(cur != NULL) { + if(xmlSecAppAddIDAttr(cur, attrName, nodeName, nsHref) < 0) { + fprintf(stderr, "Error: failed to add ID attribute \"%s\" for node \"%s\"\n", attrName, value->strValue); + xmlFree(buf); + xmlSecAppXmlDataDestroy(data); + return(NULL); + } + cur = xmlSecGetNextElementNode(cur->next); + } + + xmlFree(buf); + } } /* now find the start node */ if(xmlSecAppCmdLineParamGetString(&nodeIdParam) != NULL) { - xmlAttrPtr attr; - - attr = xmlGetID(data->doc, BAD_CAST xmlSecAppCmdLineParamGetString(&nodeIdParam)); - if(attr == NULL) { - fprintf(stderr, "Error: failed to find node with id=\"%s\"\n", - xmlSecAppCmdLineParamGetString(&nodeIdParam)); - xmlSecAppXmlDataDestroy(data); - return(NULL); - } - cur = attr->parent; + xmlAttrPtr attr; + + attr = xmlGetID(data->doc, BAD_CAST xmlSecAppCmdLineParamGetString(&nodeIdParam)); + if(attr == NULL) { + fprintf(stderr, "Error: failed to find node with id=\"%s\"\n", + xmlSecAppCmdLineParamGetString(&nodeIdParam)); + xmlSecAppXmlDataDestroy(data); + return(NULL); + } + cur = attr->parent; } else if(xmlSecAppCmdLineParamGetString(&nodeNameParam) != NULL) { - xmlChar* buf; - xmlChar* name; - xmlChar* ns; - - buf = xmlStrdup(BAD_CAST xmlSecAppCmdLineParamGetString(&nodeNameParam)); - if(buf == NULL) { - fprintf(stderr, "Error: failed to duplicate node \"%s\"\n", - xmlSecAppCmdLineParamGetString(&nodeNameParam)); - xmlSecAppXmlDataDestroy(data); - return(NULL); - } - name = (xmlChar*)strrchr((char*)buf, ':'); - if(name != NULL) { - (*(name++)) = '\0'; - ns = buf; - } else { - name = buf; - ns = NULL; - } - - cur = xmlSecFindNode(xmlDocGetRootElement(data->doc), name, ns); - if(cur == NULL) { - fprintf(stderr, "Error: failed to find node with name=\"%s\"\n", - name); - xmlFree(buf); - xmlSecAppXmlDataDestroy(data); - return(NULL); - } - xmlFree(buf); + xmlChar* buf; + xmlChar* name; + xmlChar* ns; + + buf = xmlStrdup(BAD_CAST xmlSecAppCmdLineParamGetString(&nodeNameParam)); + if(buf == NULL) { + fprintf(stderr, "Error: failed to duplicate node \"%s\"\n", + xmlSecAppCmdLineParamGetString(&nodeNameParam)); + xmlSecAppXmlDataDestroy(data); + return(NULL); + } + name = (xmlChar*)strrchr((char*)buf, ':'); + if(name != NULL) { + (*(name++)) = '\0'; + ns = buf; + } else { + name = buf; + ns = NULL; + } + + cur = xmlSecFindNode(xmlDocGetRootElement(data->doc), name, ns); + if(cur == NULL) { + fprintf(stderr, "Error: failed to find node with name=\"%s\"\n", + name); + xmlFree(buf); + xmlSecAppXmlDataDestroy(data); + return(NULL); + } + xmlFree(buf); } else if(xmlSecAppCmdLineParamGetString(&nodeXPathParam) != NULL) { - xmlXPathContextPtr ctx = NULL; - xmlXPathObjectPtr obj = NULL; - xmlNodePtr rootNode; - xmlNsPtr ns; - int ret; - - rootNode = xmlDocGetRootElement(data->doc); - if(rootNode == NULL) { - fprintf(stderr, "Error: failed to find root node\n"); - xmlSecAppXmlDataDestroy(data); - return(NULL); - } - - ctx = xmlXPathNewContext(data->doc); - if(ctx == NULL) { - fprintf(stderr, "Error: failed to create xpath context\n"); - xmlSecAppXmlDataDestroy(data); - return(NULL); - } - - /* register namespaces from the root node */ - for(ns = rootNode->nsDef; ns != NULL; ns = ns->next) { - if(ns->prefix != NULL){ - ret = xmlXPathRegisterNs(ctx, ns->prefix, ns->href); - if(ret != 0) { - fprintf(stderr, "Error: failed to register namespace \"%s\"\n", ns->prefix); - xmlXPathFreeContext(ctx); - xmlSecAppXmlDataDestroy(data); - return(NULL); - } - } - } - - obj = xmlXPathEval(BAD_CAST xmlSecAppCmdLineParamGetString(&nodeXPathParam), ctx); - if(obj == NULL) { - fprintf(stderr, "Error: failed to evaluate xpath expression\n"); - xmlXPathFreeContext(ctx); - xmlSecAppXmlDataDestroy(data); - return(NULL); - } - - if((obj->nodesetval == NULL) || (obj->nodesetval->nodeNr != 1)) { - fprintf(stderr, "Error: xpath expression evaluation does not return a single node as expected\n"); - xmlXPathFreeObject(obj); - xmlXPathFreeContext(ctx); - xmlSecAppXmlDataDestroy(data); - return(NULL); - } - - cur = obj->nodesetval->nodeTab[0]; - xmlXPathFreeContext(ctx); - xmlXPathFreeObject(obj); - + xmlXPathContextPtr ctx = NULL; + xmlXPathObjectPtr obj = NULL; + xmlNodePtr rootNode; + xmlNsPtr ns; + int ret; + + rootNode = xmlDocGetRootElement(data->doc); + if(rootNode == NULL) { + fprintf(stderr, "Error: failed to find root node\n"); + xmlSecAppXmlDataDestroy(data); + return(NULL); + } + + ctx = xmlXPathNewContext(data->doc); + if(ctx == NULL) { + fprintf(stderr, "Error: failed to create xpath context\n"); + xmlSecAppXmlDataDestroy(data); + return(NULL); + } + + /* register namespaces from the root node */ + for(ns = rootNode->nsDef; ns != NULL; ns = ns->next) { + if(ns->prefix != NULL){ + ret = xmlXPathRegisterNs(ctx, ns->prefix, ns->href); + if(ret != 0) { + fprintf(stderr, "Error: failed to register namespace \"%s\"\n", ns->prefix); + xmlXPathFreeContext(ctx); + xmlSecAppXmlDataDestroy(data); + return(NULL); + } + } + } + + obj = xmlXPathEval(BAD_CAST xmlSecAppCmdLineParamGetString(&nodeXPathParam), ctx); + if(obj == NULL) { + fprintf(stderr, "Error: failed to evaluate xpath expression\n"); + xmlXPathFreeContext(ctx); + xmlSecAppXmlDataDestroy(data); + return(NULL); + } + + if((obj->nodesetval == NULL) || (obj->nodesetval->nodeNr != 1)) { + fprintf(stderr, "Error: xpath expression evaluation does not return a single node as expected\n"); + xmlXPathFreeObject(obj); + xmlXPathFreeContext(ctx); + xmlSecAppXmlDataDestroy(data); + return(NULL); + } + + cur = obj->nodesetval->nodeTab[0]; + xmlXPathFreeContext(ctx); + xmlXPathFreeObject(obj); + } else { - cur = xmlDocGetRootElement(data->doc); - if(cur == NULL) { - fprintf(stderr, "Error: failed to get root element\n"); - xmlSecAppXmlDataDestroy(data); - return(NULL); - } + cur = xmlDocGetRootElement(data->doc); + if(cur == NULL) { + fprintf(stderr, "Error: failed to get root element\n"); + xmlSecAppXmlDataDestroy(data); + return(NULL); + } } if(defStartNodeName != NULL) { - data->startNode = xmlSecFindNode(cur, defStartNodeName, defStartNodeNs); - if(data->startNode == NULL) { - fprintf(stderr, "Error: failed to find default node with name=\"%s\"\n", - defStartNodeName); - xmlSecAppXmlDataDestroy(data); - return(NULL); - } + data->startNode = xmlSecFindNode(cur, defStartNodeName, defStartNodeNs); + if(data->startNode == NULL) { + fprintf(stderr, "Error: failed to find default node with name=\"%s\"\n", + defStartNodeName); + xmlSecAppXmlDataDestroy(data); + return(NULL); + } } else { - data->startNode = cur; + data->startNode = cur; } return(data); @@ -2703,14 +2679,14 @@ xmlSecAppXmlDataCreate(const char* filename, const xmlChar* defStartNodeName, co static void xmlSecAppXmlDataDestroy(xmlSecAppXmlDataPtr data) { if(data == NULL) { - fprintf(stderr, "Error: xml data is null\n"); - return; + fprintf(stderr, "Error: xml data is null\n"); + return; } if(data->dtd != NULL) { - xmlFreeDtd(data->dtd); + xmlFreeDtd(data->dtd); } if(data->doc != NULL) { - xmlFreeDoc(data->doc); + xmlFreeDoc(data->doc); } memset(data, 0, sizeof(xmlSecAppXmlData)); xmlFree(data); @@ -2719,99 +2695,91 @@ xmlSecAppXmlDataDestroy(xmlSecAppXmlDataPtr data) { static xmlSecAppCommand xmlSecAppParseCommand(const char* cmd, xmlSecAppCmdLineParamTopic* cmdLineTopics, xmlSecAppCommand* subCommand) { if(subCommand != NULL) { - (*subCommand) = xmlSecAppCommandUnknown; + (*subCommand) = xmlSecAppCommandUnknown; } if((cmd == NULL) || (cmdLineTopics == NULL)) { - return(xmlSecAppCommandUnknown); + return(xmlSecAppCommandUnknown); } else if((strcmp(cmd, "help") == 0) || (strcmp(cmd, "--help") == 0)) { - (*cmdLineTopics) = 0; - return(xmlSecAppCommandHelp); + (*cmdLineTopics) = 0; + return(xmlSecAppCommandHelp); } else if((strcmp(cmd, "help-all") == 0) || (strcmp(cmd, "--help-all") == 0)) { - (*cmdLineTopics) = xmlSecAppCmdLineTopicAll; - return(xmlSecAppCommandHelp); + (*cmdLineTopics) = xmlSecAppCmdLineTopicAll; + return(xmlSecAppCommandHelp); } else - if((strncmp(cmd, "help-", 5) == 0) || (strncmp(cmd, "--help-", 7) == 0)) { - cmd = (cmd[0] == '-') ? cmd + 7 : cmd + 5; - if(subCommand) { - (*subCommand) = xmlSecAppParseCommand(cmd, cmdLineTopics, NULL); - } else { - (*cmdLineTopics) = 0; - } - return(xmlSecAppCommandHelp); + if((strncmp(cmd, "help-", 5) == 0) || (strncmp(cmd, "--help-", 7) == 0)) { + cmd = (cmd[0] == '-') ? cmd + 7 : cmd + 5; + if(subCommand) { + (*subCommand) = xmlSecAppParseCommand(cmd, cmdLineTopics, NULL); + } else { + (*cmdLineTopics) = 0; + } + return(xmlSecAppCommandHelp); } else if((strcmp(cmd, "version") == 0) || (strcmp(cmd, "--version") == 0)) { - (*cmdLineTopics) = xmlSecAppCmdLineTopicVersion; - return(xmlSecAppCommandVersion); + (*cmdLineTopics) = xmlSecAppCmdLineTopicVersion; + return(xmlSecAppCommandVersion); } else if((strcmp(cmd, "list-key-data") == 0) || (strcmp(cmd, "--list-key-data") == 0)) { - (*cmdLineTopics) = xmlSecAppCmdLineTopicCryptoConfig; - return(xmlSecAppCommandListKeyData); + (*cmdLineTopics) = 0; + return(xmlSecAppCommandListKeyData); } else if((strcmp(cmd, "check-key-data") == 0) || (strcmp(cmd, "--check-key-data") == 0)) { - (*cmdLineTopics) = xmlSecAppCmdLineTopicCryptoConfig; - return(xmlSecAppCommandCheckKeyData); + (*cmdLineTopics) = 0; + return(xmlSecAppCommandCheckKeyData); } else if((strcmp(cmd, "list-transforms") == 0) || (strcmp(cmd, "--list-transforms") == 0)) { - (*cmdLineTopics) = xmlSecAppCmdLineTopicCryptoConfig; - return(xmlSecAppCommandListTransforms); + (*cmdLineTopics) = 0; + return(xmlSecAppCommandListTransforms); } else if((strcmp(cmd, "check-transforms") == 0) || (strcmp(cmd, "--check-transforms") == 0)) { - (*cmdLineTopics) = xmlSecAppCmdLineTopicCryptoConfig; - return(xmlSecAppCommandCheckTransforms); + (*cmdLineTopics) = 0; + return(xmlSecAppCommandCheckTransforms); } else if((strcmp(cmd, "keys") == 0) || (strcmp(cmd, "--keys") == 0)) { - (*cmdLineTopics) = - xmlSecAppCmdLineTopicGeneral | - xmlSecAppCmdLineTopicCryptoConfig | - xmlSecAppCmdLineTopicKeysMngr | - xmlSecAppCmdLineTopicX509Certs; - return(xmlSecAppCommandKeys); + (*cmdLineTopics) = xmlSecAppCmdLineTopicGeneral | + xmlSecAppCmdLineTopicKeysMngr | + xmlSecAppCmdLineTopicX509Certs; + return(xmlSecAppCommandKeys); } else #ifndef XMLSEC_NO_XMLDSIG if((strcmp(cmd, "sign") == 0) || (strcmp(cmd, "--sign") == 0)) { - (*cmdLineTopics) = - xmlSecAppCmdLineTopicGeneral | - xmlSecAppCmdLineTopicCryptoConfig | - xmlSecAppCmdLineTopicDSigCommon | - xmlSecAppCmdLineTopicDSigSign | - xmlSecAppCmdLineTopicKeysMngr | - xmlSecAppCmdLineTopicX509Certs; - return(xmlSecAppCommandSign); + (*cmdLineTopics) = xmlSecAppCmdLineTopicGeneral | + xmlSecAppCmdLineTopicDSigCommon | + xmlSecAppCmdLineTopicDSigSign | + xmlSecAppCmdLineTopicKeysMngr | + xmlSecAppCmdLineTopicX509Certs; + return(xmlSecAppCommandSign); } else if((strcmp(cmd, "verify") == 0) || (strcmp(cmd, "--verify") == 0)) { - (*cmdLineTopics) = - xmlSecAppCmdLineTopicGeneral | - xmlSecAppCmdLineTopicCryptoConfig | - xmlSecAppCmdLineTopicDSigCommon | - xmlSecAppCmdLineTopicDSigVerify | - xmlSecAppCmdLineTopicKeysMngr | - xmlSecAppCmdLineTopicX509Certs; - return(xmlSecAppCommandVerify); + (*cmdLineTopics) = xmlSecAppCmdLineTopicGeneral | + xmlSecAppCmdLineTopicDSigCommon | + xmlSecAppCmdLineTopicDSigVerify | + xmlSecAppCmdLineTopicKeysMngr | + xmlSecAppCmdLineTopicX509Certs; + return(xmlSecAppCommandVerify); } else #ifndef XMLSEC_NO_TMPL_TEST if((strcmp(cmd, "sign-tmpl") == 0) || (strcmp(cmd, "--sign-tmpl") == 0)) { - (*cmdLineTopics) = - xmlSecAppCmdLineTopicGeneral | - xmlSecAppCmdLineTopicCryptoConfig | - xmlSecAppCmdLineTopicDSigCommon | - xmlSecAppCmdLineTopicDSigSign | - xmlSecAppCmdLineTopicKeysMngr | - xmlSecAppCmdLineTopicX509Certs; - return(xmlSecAppCommandSignTmpl); + (*cmdLineTopics) = xmlSecAppCmdLineTopicGeneral | + xmlSecAppCmdLineTopicDSigCommon | + xmlSecAppCmdLineTopicDSigSign | + xmlSecAppCmdLineTopicKeysMngr | + xmlSecAppCmdLineTopicX509Certs; + return(xmlSecAppCommandSignTmpl); } else #endif /* XMLSEC_NO_TMPL_TEST */ @@ -2819,110 +2787,102 @@ xmlSecAppParseCommand(const char* cmd, xmlSecAppCmdLineParamTopic* cmdLineTopics #ifndef XMLSEC_NO_XMLENC if((strcmp(cmd, "encrypt") == 0) || (strcmp(cmd, "--encrypt") == 0)) { - (*cmdLineTopics) = - xmlSecAppCmdLineTopicGeneral | - xmlSecAppCmdLineTopicCryptoConfig | - xmlSecAppCmdLineTopicEncCommon | - xmlSecAppCmdLineTopicEncEncrypt | - xmlSecAppCmdLineTopicKeysMngr | - xmlSecAppCmdLineTopicX509Certs; - return(xmlSecAppCommandEncrypt); + (*cmdLineTopics) = xmlSecAppCmdLineTopicGeneral | + xmlSecAppCmdLineTopicEncCommon | + xmlSecAppCmdLineTopicEncEncrypt | + xmlSecAppCmdLineTopicKeysMngr | + xmlSecAppCmdLineTopicX509Certs; + return(xmlSecAppCommandEncrypt); } else if((strcmp(cmd, "decrypt") == 0) || (strcmp(cmd, "--decrypt") == 0)) { - (*cmdLineTopics) = - xmlSecAppCmdLineTopicGeneral | - xmlSecAppCmdLineTopicCryptoConfig | - xmlSecAppCmdLineTopicEncCommon | - xmlSecAppCmdLineTopicEncDecrypt | - xmlSecAppCmdLineTopicKeysMngr | - xmlSecAppCmdLineTopicX509Certs; - return(xmlSecAppCommandDecrypt); + (*cmdLineTopics) = xmlSecAppCmdLineTopicGeneral | + xmlSecAppCmdLineTopicEncCommon | + xmlSecAppCmdLineTopicEncDecrypt | + xmlSecAppCmdLineTopicKeysMngr | + xmlSecAppCmdLineTopicX509Certs; + return(xmlSecAppCommandDecrypt); } else #ifndef XMLSEC_NO_TMPL_TEST if((strcmp(cmd, "encrypt-tmpl") == 0) || (strcmp(cmd, "--encrypt-tmpl") == 0)) { - (*cmdLineTopics) = - xmlSecAppCmdLineTopicGeneral | - xmlSecAppCmdLineTopicCryptoConfig | - xmlSecAppCmdLineTopicEncCommon | - xmlSecAppCmdLineTopicEncEncrypt | - xmlSecAppCmdLineTopicKeysMngr | - xmlSecAppCmdLineTopicX509Certs; - return(xmlSecAppCommandEncryptTmpl); + (*cmdLineTopics) = xmlSecAppCmdLineTopicGeneral | + xmlSecAppCmdLineTopicEncCommon | + xmlSecAppCmdLineTopicEncEncrypt | + xmlSecAppCmdLineTopicKeysMngr | + xmlSecAppCmdLineTopicX509Certs; + return(xmlSecAppCommandEncryptTmpl); } else #endif /* XMLSEC_NO_TMPL_TEST */ #endif /* XMLSEC_NO_XMLENC */ #ifndef XMLSEC_NO_XKMS if(strcmp(cmd, "--xkms-server-request") == 0) { - (*cmdLineTopics) = - xmlSecAppCmdLineTopicGeneral | - xmlSecAppCmdLineTopicCryptoConfig | - xmlSecAppCmdLineTopicXkmsCommon | - xmlSecAppCmdLineTopicKeysMngr | - xmlSecAppCmdLineTopicX509Certs; - return(xmlSecAppCommandXkmsServerRequest); + (*cmdLineTopics) = xmlSecAppCmdLineTopicGeneral | + xmlSecAppCmdLineTopicXkmsCommon | + xmlSecAppCmdLineTopicKeysMngr | + xmlSecAppCmdLineTopicX509Certs; + return(xmlSecAppCommandXkmsServerRequest); } else #endif /* XMLSEC_NO_XKMS */ if(1) { - (*cmdLineTopics) = 0; - return(xmlSecAppCommandUnknown); + (*cmdLineTopics) = 0; + return(xmlSecAppCommandUnknown); } } - + static void xmlSecAppPrintHelp(xmlSecAppCommand command, xmlSecAppCmdLineParamTopic topics) { switch(command) { case xmlSecAppCommandUnknown: case xmlSecAppCommandHelp: - fprintf(stdout, "%s%s\n", helpCommands1, helpCommands2); + fprintf(stdout, "%s%s\n", helpCommands1, helpCommands2); break; case xmlSecAppCommandVersion: - fprintf(stdout, "%s\n", helpVersion); + fprintf(stdout, "%s\n", helpVersion); break; case xmlSecAppCommandListKeyData: - fprintf(stdout, "%s\n", helpListKeyData); + fprintf(stdout, "%s\n", helpListKeyData); break; case xmlSecAppCommandCheckKeyData: - fprintf(stdout, "%s\n", helpCheckKeyData); + fprintf(stdout, "%s\n", helpCheckKeyData); break; case xmlSecAppCommandListTransforms: - fprintf(stdout, "%s\n", helpListTransforms); + fprintf(stdout, "%s\n", helpListTransforms); break; case xmlSecAppCommandCheckTransforms: - fprintf(stdout, "%s\n", helpCheckTransforms); + fprintf(stdout, "%s\n", helpCheckTransforms); break; case xmlSecAppCommandKeys: - fprintf(stdout, "%s\n", helpKeys); + fprintf(stdout, "%s\n", helpKeys); break; case xmlSecAppCommandSign: - fprintf(stdout, "%s\n", helpSign); + fprintf(stdout, "%s\n", helpSign); break; case xmlSecAppCommandVerify: - fprintf(stdout, "%s\n", helpVerify); + fprintf(stdout, "%s\n", helpVerify); break; case xmlSecAppCommandEncrypt: - fprintf(stdout, "%s\n", helpEncrypt); + fprintf(stdout, "%s\n", helpEncrypt); break; case xmlSecAppCommandDecrypt: - fprintf(stdout, "%s\n", helpDecrypt); + fprintf(stdout, "%s\n", helpDecrypt); break; case xmlSecAppCommandSignTmpl: - fprintf(stdout, "%s\n", helpSignTmpl); + fprintf(stdout, "%s\n", helpSignTmpl); break; case xmlSecAppCommandEncryptTmpl: - fprintf(stdout, "%s\n", helpEncryptTmpl); + fprintf(stdout, "%s\n", helpEncryptTmpl); break; case xmlSecAppCommandXkmsServerRequest: - fprintf(stdout, "%s\n", helpXkmsServerRequest); + fprintf(stdout, "%s\n", helpXkmsServerRequest); break; } if(topics != 0) { - fprintf(stdout, "Options:\n"); - xmlSecAppCmdLineParamsListPrint(parameters, topics, stdout); - fprintf(stdout, "\n"); + fprintf(stdout, "Options:\n"); + xmlSecAppCmdLineParamsListPrint(parameters, topics, stdout); + fprintf(stdout, "\n"); } fprintf(stdout, "\n%s\n", bugs); fprintf(stdout, "%s\n", copyright); @@ -2933,19 +2893,19 @@ xmlSecAppGetUriType(const char* string) { xmlSecTransformUriType type = xmlSecTransformUriTypeNone; while((string != NULL) && (string[0] != '\0')) { - if(strcmp(string, "empty") == 0) { - type |= xmlSecTransformUriTypeEmpty; - } else if(strcmp(string, "same-doc") == 0) { - type |= xmlSecTransformUriTypeSameDocument; - } else if(strcmp(string, "local") == 0) { - type |= xmlSecTransformUriTypeLocal; - } else if(strcmp(string, "remote") == 0) { - type |= xmlSecTransformUriTypeRemote; - } else { - fprintf(stderr, "Error: invalid uri type: \"%s\"\n", string); - return(xmlSecTransformUriTypeNone); - } - string += strlen(string) + 1; + if(strcmp(string, "empty") == 0) { + type |= xmlSecTransformUriTypeEmpty; + } else if(strcmp(string, "same-doc") == 0) { + type |= xmlSecTransformUriTypeSameDocument; + } else if(strcmp(string, "local") == 0) { + type |= xmlSecTransformUriTypeLocal; + } else if(strcmp(string, "remote") == 0) { + type |= xmlSecTransformUriTypeRemote; + } else { + fprintf(stderr, "Error: invalid uri type: \"%s\"\n", string); + return(xmlSecTransformUriTypeNone); + } + string += strlen(string) + 1; } return(type); } @@ -2955,12 +2915,12 @@ xmlSecAppOpenFile(const char* filename) { FILE* file; if((filename == NULL) || (strcmp(filename, "-") == 0)) { - return(stdout); + return(stdout); } file = fopen(filename, "wb"); if(file == NULL) { - fprintf(stderr, "Error: failed to open file \"%s\"\n", filename); - return(NULL); + fprintf(stderr, "Error: failed to open file \"%s\"\n", filename); + return(NULL); } return(file); @@ -2969,7 +2929,7 @@ xmlSecAppOpenFile(const char* filename) { static void xmlSecAppCloseFile(FILE* file) { if((file == NULL) || (file == stdout) || (file == stderr)) { - return; + return; } fclose(file); @@ -2981,16 +2941,16 @@ xmlSecAppWriteResult(xmlDocPtr doc, xmlSecBufferPtr buffer) { f = xmlSecAppOpenFile(xmlSecAppCmdLineParamGetString(&outputParam)); if(f == NULL) { - return(-1); + return(-1); } if(doc != NULL) { - xmlDocDump(f, doc); + xmlDocDump(f, doc); } else if((buffer != NULL) && (xmlSecBufferGetData(buffer) != NULL)) { - fwrite(xmlSecBufferGetData(buffer), xmlSecBufferGetSize(buffer), 1, f); + fwrite(xmlSecBufferGetData(buffer), xmlSecBufferGetSize(buffer), 1, f); } else { - fprintf(stderr, "Error: both result doc and result buffer are null\n"); - xmlSecAppCloseFile(f); - return(-1); + fprintf(stderr, "Error: both result doc and result buffer are null\n"); + xmlSecAppCloseFile(f); + return(-1); } xmlSecAppCloseFile(f); return(0); @@ -3003,52 +2963,52 @@ xmlSecAppAddIDAttr(xmlNodePtr node, const xmlChar* attrName, const xmlChar* node xmlChar* id; if((node == NULL) || (attrName == NULL) || (nodeName == NULL)) { - return(-1); + return(-1); } /* process children first because it does not matter much but does simplify code */ cur = xmlSecGetNextElementNode(node->children); while(cur != NULL) { - if(xmlSecAppAddIDAttr(cur, attrName, nodeName, nsHref) < 0) { - return(-1); - } - cur = xmlSecGetNextElementNode(cur->next); + if(xmlSecAppAddIDAttr(cur, attrName, nodeName, nsHref) < 0) { + return(-1); + } + cur = xmlSecGetNextElementNode(cur->next); } /* node name must match */ if(!xmlStrEqual(node->name, nodeName)) { - return(0); + return(0); } - + /* if nsHref is set then it also should match */ if((nsHref != NULL) && (node->ns != NULL) && (!xmlStrEqual(nsHref, node->ns->href))) { - return(0); + return(0); } /* the attribute with name equal to attrName should exist */ for(attr = node->properties; attr != NULL; attr = attr->next) { - if(xmlStrEqual(attr->name, attrName)) { - break; - } + if(xmlStrEqual(attr->name, attrName)) { + break; + } } if(attr == NULL) { - return(0); + return(0); } /* and this attr should have a value */ id = xmlNodeListGetString(node->doc, attr->children, 1); if(id == NULL) { - return(0); + return(0); } /* check that we don't have same ID already */ tmpAttr = xmlGetID(node->doc, id); if(tmpAttr == NULL) { - xmlAddID(NULL, node->doc, id, attr); + xmlAddID(NULL, node->doc, id, attr); } else if(tmpAttr != attr) { - fprintf(stderr, "Error: duplicate ID attribute \"%s\"\n", id); - xmlFree(id); - return(-1); + fprintf(stderr, "Error: duplicate ID attribute \"%s\"\n", id); + xmlFree(id); + return(-1); } xmlFree(id); return(0); |