summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lasso/xml/xml.c59
-rw-r--r--lasso/xml/xml.h44
2 files changed, 54 insertions, 49 deletions
diff --git a/lasso/xml/xml.c b/lasso/xml/xml.c
index 9ae2adc5..3fc11ca3 100644
--- a/lasso/xml/xml.c
+++ b/lasso/xml/xml.c
@@ -133,7 +133,7 @@ lasso_node_url_encode(LassoNode *node,
return (class->url_encode(node, sign_method, key_file));
}
-gchar *
+gint
lasso_node_verify_signature(LassoNode *node,
const gchar *certificate_file)
{
@@ -179,7 +179,7 @@ lasso_node_new_child(LassoNode *node,
gboolean unbounded)
{
LassoNodeClass *class = LASSO_NODE_GET_CLASS(node);
- return (class->new_child(node, name, content, unbounded));
+ class->new_child(node, name, content, unbounded);
}
static void
@@ -494,67 +494,72 @@ gint
lasso_node_impl_verify_signature(LassoNode *node,
const gchar *certificate_file)
{
- xmlNodePtr *signature;
- xmlSecKeysMngrPtr mngr;
+ xmlNodePtr signature;
+ xmlSecKeysMngrPtr mngr = NULL;
xmlSecDSigCtxPtr dsigCtx = NULL;
- int res = -1;
-
+ gint ret = -1;
+
/* find start node */
- signature = xmlSecFindNode(node->private->node, xmlSecNodeSignature, xmlSecDSigNs);
- if(signature == NULL) {
+ signature = xmlSecFindNode(node->private->node, xmlSecNodeSignature,
+ xmlSecDSigNs);
+ if (signature == NULL) {
fprintf(stderr, "Error: start node not found\n");
goto done;
}
/* create simple keys mngr */
mngr = xmlSecKeysMngrCreate();
- if(mngr == NULL) {
+ if (mngr == NULL) {
fprintf(stderr, "Error: failed to create keys manager.\n");
- return(NULL);
+ goto done;
}
- if(xmlSecCryptoAppDefaultKeysMngrInit(mngr) < 0) {
+ if (xmlSecCryptoAppDefaultKeysMngrInit(mngr) < 0) {
fprintf(stderr, "Error: failed to initialize keys manager.\n");
goto done;
}
/* load trusted cert */
- if(xmlSecCryptoAppKeysMngrCertLoad(mngr, certificate_file, xmlSecKeyDataFormatPem,
- xmlSecKeyDataTypeTrusted) < 0) {
- fprintf(stderr,"Error: failed to load pem certificate from \"%s\"\n", certificate_file);
+ if (xmlSecCryptoAppKeysMngrCertLoad(mngr, certificate_file,
+ xmlSecKeyDataFormatPem,
+ xmlSecKeyDataTypeTrusted) < 0) {
+ fprintf(stderr, "Error: failed to load pem certificate from \"%s\"\n",
+ certificate_file);
goto done;
}
/* create signature context */
dsigCtx = xmlSecDSigCtxCreate(mngr);
- if(dsigCtx == NULL) {
- fprintf(stderr,"Error: failed to create signature context\n");
+ if (dsigCtx == NULL) {
+ fprintf(stderr, "Error: failed to create signature context\n");
goto done;
}
- /* Verify signature */
- if(xmlSecDSigCtxVerify(dsigCtx, signature) < 0) {
- fprintf(stderr,"Error: signature verify\n");
+ /* verify signature */
+ if (xmlSecDSigCtxVerify(dsigCtx, signature) < 0) {
+ fprintf(stderr, "Error: signature verify\n");
goto done;
}
/* print verification result to stdout */
- if(dsigCtx->status == xmlSecDSigStatusSucceeded) {
+ if (dsigCtx->status == xmlSecDSigStatusSucceeded) {
fprintf(stdout, "Signature is OK\n");
- } else {
+ ret = 1;
+ }
+ else {
fprintf(stdout, "Signature is INVALID\n");
- }
- res = 1;
+ ret = 0;
+ }
- done:
+ done:
/* cleanup */
if(dsigCtx != NULL) {
- //xmlSecDSigCtxDestroy(dsigCtx);
+ xmlSecDSigCtxDestroy(dsigCtx);
}
if(mngr != NULL) {
- //xmlSecKeysMngrDestroy(mngr);
+ xmlSecKeysMngrDestroy(mngr);
}
- return (res);
+ return (ret);
}
/*****************************************************************************/
diff --git a/lasso/xml/xml.h b/lasso/xml/xml.h
index d646ab1c..3060779a 100644
--- a/lasso/xml/xml.h
+++ b/lasso/xml/xml.h
@@ -111,39 +111,39 @@ typedef enum {
LASSO_EXPORT GType lasso_node_get_type(void);
LASSO_EXPORT LassoNode* lasso_node_new(xmlNodePtr node);
-LASSO_EXPORT GString* lasso_node_build_query (LassoNode *node);
+LASSO_EXPORT GString* lasso_node_build_query (LassoNode *node);
-LASSO_EXPORT void lasso_node_dump (LassoNode *,
- const xmlChar *,
- int);
+LASSO_EXPORT void lasso_node_dump (LassoNode *,
+ const xmlChar *,
+ int);
-LASSO_EXPORT LassoAttr* lasso_node_get_attr (LassoNode *node,
- const xmlChar *name);
+LASSO_EXPORT LassoAttr* lasso_node_get_attr (LassoNode *node,
+ const xmlChar *name);
-LASSO_EXPORT GPtrArray* lasso_node_get_attrs (LassoNode *node);
+LASSO_EXPORT GPtrArray* lasso_node_get_attrs (LassoNode *node);
-LASSO_EXPORT LassoNode* lasso_node_get_child (LassoNode *node,
- const xmlChar *name);
+LASSO_EXPORT LassoNode* lasso_node_get_child (LassoNode *node,
+ const xmlChar *name);
-LASSO_EXPORT GPtrArray* lasso_node_get_children (LassoNode *node);
+LASSO_EXPORT GPtrArray* lasso_node_get_children (LassoNode *node);
-LASSO_EXPORT xmlChar* lasso_node_get_content (LassoNode *node);
+LASSO_EXPORT xmlChar* lasso_node_get_content (LassoNode *node);
-LASSO_EXPORT xmlChar* lasso_node_get_name (LassoNode *node);
+LASSO_EXPORT xmlChar* lasso_node_get_name (LassoNode *node);
-LASSO_EXPORT void lasso_node_rename_prop (LassoNode *node,
- const xmlChar *old_name,
- const xmlChar *new_name);
+LASSO_EXPORT void lasso_node_rename_prop (LassoNode *node,
+ const xmlChar *old_name,
+ const xmlChar *new_name);
-LASSO_EXPORT GData* lasso_node_serialize (LassoNode *node,
- GData *gd);
+LASSO_EXPORT GData* lasso_node_serialize (LassoNode *node,
+ GData *gd);
-LASSO_EXPORT gchar* lasso_node_url_encode (LassoNode *node,
- guint sign_method,
- const gchar *key_file);
+LASSO_EXPORT gchar* lasso_node_url_encode (LassoNode *node,
+ guint sign_method,
+ const gchar *key_file);
-LASSO_EXPORT gchar* lasso_node_verify_signature(LassoNode *node,
- const gchar *certificate_file);
+LASSO_EXPORT gint lasso_node_verify_signature (LassoNode *node,
+ const gchar *certificate_file);
#ifdef __cplusplus
}