diff options
author | Valery Febvre <vfebvre at easter-eggs.com> | 2004-05-25 23:45:38 +0000 |
---|---|---|
committer | Valery Febvre <vfebvre at easter-eggs.com> | 2004-05-25 23:45:38 +0000 |
commit | f64826244700e3e366b4f3933eb40a2960bdd217 (patch) | |
tree | cf18cb58158c4b7d2dfe5191d3faa5bfab9cb255 /lasso | |
parent | 01da79e0a3fc1365abb0763d0a466033d225f6c5 (diff) | |
download | lasso-f64826244700e3e366b4f3933eb40a2960bdd217.tar.gz lasso-f64826244700e3e366b4f3933eb40a2960bdd217.tar.xz lasso-f64826244700e3e366b4f3933eb40a2960bdd217.zip |
Modified function lasso_str_sign()
Diffstat (limited to 'lasso')
-rw-r--r-- | lasso/xml/tools.c | 21 | ||||
-rw-r--r-- | lasso/xml/tools.h | 11 | ||||
-rw-r--r-- | lasso/xml/xml.c | 156 | ||||
-rw-r--r-- | lasso/xml/xml.h | 17 |
4 files changed, 174 insertions, 31 deletions
diff --git a/lasso/xml/tools.c b/lasso/xml/tools.c index bf1d5da8..9d967c36 100644 --- a/lasso/xml/tools.c +++ b/lasso/xml/tools.c @@ -202,7 +202,7 @@ lasso_query_verify_signature(const gchar *query, return (2); /* re-create doc to verify (signed + enrypted) */ doc = lasso_str_sign(str_split[0], - xmlSecTransformRsaSha1Id, + lassoSignatureMethodRsaSha1, recipient_private_key_file); sigValNode = xmlSecFindNode(xmlDocGetRootElement(doc), xmlSecNodeSignatureValue, @@ -271,9 +271,9 @@ lasso_str_escape(xmlChar *str) } xmlDocPtr -lasso_str_sign(xmlChar *str, - xmlSecTransformId signMethodId, - const char* private_key_file) +lasso_str_sign(xmlChar *str, + lassoSignatureMethod sign_method, + const char *private_key_file) { /* FIXME : renamed fct into lasso_query_add_signature SHOULD returned a query (xmlChar) instead of xmlDoc */ @@ -293,8 +293,17 @@ lasso_str_sign(xmlChar *str, xmlAddChild((xmlNodePtr)doc, envelope); /* create signature template for enveloped signature */ - signNode = xmlSecTmplSignatureCreate(doc, xmlSecTransformExclC14NId, - signMethodId, NULL); + switch (sign_method) { + case lassoSignatureMethodRsaSha1: + signNode = xmlSecTmplSignatureCreate(doc, xmlSecTransformExclC14NId, + xmlSecTransformRsaSha1Id, NULL); + break; + case lassoSignatureMethodDsaSha1: + signNode = xmlSecTmplSignatureCreate(doc, xmlSecTransformExclC14NId, + xmlSecTransformDsaSha1Id, NULL); + break; + } + if (signNode == NULL) { fprintf(stderr, "Error: failed to create signature template\n"); goto done; diff --git a/lasso/xml/tools.h b/lasso/xml/tools.h index a2c9cfe7..c5a79c96 100644 --- a/lasso/xml/tools.h +++ b/lasso/xml/tools.h @@ -39,6 +39,11 @@ extern "C" { #include <lasso/export.h> +typedef enum { + lassoSignatureMethodRsaSha1 = 1, + lassoSignatureMethodDsaSha1 +} lassoSignatureMethod; + LASSO_EXPORT xmlChar* lasso_build_unique_id (guint8 size); LASSO_EXPORT xmlChar* lasso_doc_get_node_content (xmlDocPtr doc, @@ -60,9 +65,9 @@ LASSO_EXPORT int lasso_query_verify_signature (const gchar *query, LASSO_EXPORT xmlChar* lasso_str_escape (xmlChar *str); -LASSO_EXPORT xmlDocPtr lasso_str_sign (xmlChar *str, - xmlSecTransformId signMethodId, - const char *private_key_file); +LASSO_EXPORT xmlDocPtr lasso_str_sign (xmlChar *str, + lassoSignatureMethod sign_method, + const char *private_key_file); LASSO_EXPORT xmlChar* lasso_str_unescape (xmlChar *str); diff --git a/lasso/xml/xml.c b/lasso/xml/xml.c index 1c47a7f6..698013b3 100644 --- a/lasso/xml/xml.c +++ b/lasso/xml/xml.c @@ -36,6 +36,14 @@ struct _LassoNodePrivate /* virtual public methods */ /*****************************************************************************/ +/** + * lasso_node_copy: + * @node: a LassoNode + * + * Build a copy of the node + * + * Return value: a copy of the node + **/ LassoNode * lasso_node_copy(LassoNode *node) { @@ -45,6 +53,16 @@ lasso_node_copy(LassoNode *node) return (class->copy(node)); } +/** + * lasso_node_dump: + * @node: a LassoNode + * @encoding: the name of the encoding to use or NULL. + * @format: is formatting allowed + * + * Dumps the LassoNode. All datas in object are dumped in an XML format. + * + * Return value: a full XML dump of the LassoNode + **/ xmlChar * lasso_node_dump(LassoNode *node, const xmlChar *encoding, @@ -56,6 +74,12 @@ lasso_node_dump(LassoNode *node, return (class->dump(node, encoding, format)); } +/** + * lasso_node_destroy: + * @node: a LassoNode + * + * Destroys the LassoNode + **/ void lasso_node_destroy(LassoNode *node) { @@ -65,6 +89,14 @@ lasso_node_destroy(LassoNode *node) return (class->destroy(node)); } +/** + * lasso_node_export: + * @node: a LassoNode + * + * Exports the LassoNode. + * + * Return value: an XML dump of the LassoNode (UTF-8 encoding) + **/ xmlChar * lasso_node_export(LassoNode *node) { @@ -74,6 +106,14 @@ lasso_node_export(LassoNode *node) return (class->export(node)); } +/** + * lasso_node_export_to_base64: + * @node: a LassoNode + * + * Like lasso_node_export() method except that result is Base64 encoded. + * + * Return value: a Base64 encoded dump of the LassoNode + **/ xmlChar * lasso_node_export_to_base64(LassoNode *node) { @@ -83,10 +123,21 @@ lasso_node_export_to_base64(LassoNode *node) return (class->export_to_base64(node)); } +/** + * lasso_node_export_to_query: + * @node: a LassoNode + * @sign_method: the Signature Transform method + * @private_key_file: a private key (Optional) + * + * URL-encodes and signes the LassoNode. + * If private_key_file is NULL, query won't be signed. + * + * Return value: URL-encoded and signed LassoNode + **/ gchar * -lasso_node_export_to_query(LassoNode *node, - gint sign_method, - const gchar *private_key_file) +lasso_node_export_to_query(LassoNode *node, + lassoSignatureMethod sign_method, + const gchar *private_key_file) { g_return_val_if_fail (LASSO_IS_NODE(node), NULL); @@ -94,6 +145,14 @@ lasso_node_export_to_query(LassoNode *node, return (class->export_to_query(node, sign_method, private_key_file)); } +/** + * lasso_node_export_to_soap: + * @node: a LassoNode + * + * Like lasso_node_export() method except that result is SOAP enveloped. + * + * Return value: an SOAP enveloped export of the LassoNode + **/ xmlChar * lasso_node_export_to_soap(LassoNode *node) { @@ -103,6 +162,15 @@ lasso_node_export_to_soap(LassoNode *node) return (class->export_to_soap(node)); } +/** + * lasso_node_get_attr: + * @node: a LassoNode + * @name: the attribut name + * + * Gets an attribut associated with the node. + * + * Return value: the attribut or NULL if not found. + **/ LassoAttr * lasso_node_get_attr(LassoNode *node, const xmlChar *name) @@ -113,6 +181,16 @@ lasso_node_get_attr(LassoNode *node, return (class->get_attr(node, name)); } +/** + * lasso_node_get_attr_value: + * @node: a LassoNode + * @name: the attribut name + * + * Gets the value of an attribute associated to a node. + * + * Return value: the attribute value or NULL if not found. It's up to the caller + * to free the memory with xmlFree(). + **/ xmlChar * lasso_node_get_attr_value(LassoNode *node, const xmlChar *name) @@ -123,6 +201,14 @@ lasso_node_get_attr_value(LassoNode *node, return (class->get_attr_value(node, name)); } +/** + * lasso_node_get_attrs: + * @node: a LassoNode + * + * Gets attributs associated with the node. + * + * Return value: an array of attributs or NULL if no attribut found. + **/ GPtrArray * lasso_node_get_attrs(LassoNode *node) { @@ -132,6 +218,16 @@ lasso_node_get_attrs(LassoNode *node) return (class->get_attrs(node)); } +/** + * lasso_node_get_child: + * @node: a LassoNode + * @name: the name + * @href: the namespace href (may be NULL) + * + * Gets child of node having given name and namespace href. + * + * Return value: a child node + **/ LassoNode * lasso_node_get_child(LassoNode *node, const xmlChar *name, @@ -143,6 +239,14 @@ lasso_node_get_child(LassoNode *node, return (class->get_child(node, name, href)); } +/** + * lasso_node_get_children: + * @node: a LassoNode + * + * Gets direct children of node + * + * Return value: an array of node or NULL if no children found. + **/ GPtrArray * lasso_node_get_children(LassoNode *node) { @@ -154,7 +258,7 @@ lasso_node_get_children(LassoNode *node) /** * lasso_node_get_content: - * @node: the LassoNode + * @node: a LassoNode * * Read the value of a node, this can be either the text carried directly by * this node if it's a TEXT node or the aggregate string of the values carried @@ -173,6 +277,14 @@ lasso_node_get_content(LassoNode *node) return (class->get_content(node)); } +/** + * lasso_node_get_name: + * @node: a LassoNode + * + * Gets the name of the node + * + * Return value: the name of the node + **/ const xmlChar * lasso_node_get_name(LassoNode *node) { @@ -182,6 +294,13 @@ lasso_node_get_name(LassoNode *node) return (class->get_name(node)); } +/** + * lasso_node_import: + * @node: a LassoNode + * @buffer: an XML buffer + * + * parse an XML buffer and build a LassoNode + **/ void lasso_node_import(LassoNode *node, const xmlChar *buffer) @@ -192,6 +311,14 @@ lasso_node_import(LassoNode *node, class->import(node, buffer); } +/** + * lasso_node_rename_prop: + * @node: a LassoNode + * @old_name: the attribut name + * @new_name: the new attribut name + * + * Renames an attribut of the node + **/ void lasso_node_rename_prop(LassoNode *node, const xmlChar *old_name, @@ -203,6 +330,15 @@ lasso_node_rename_prop(LassoNode *node, class->rename_prop(node, old_name, new_name); } +/** + * lasso_node_verify_signature: + * @node: a LassoNode + * @certificate_file: a certificate + * + * Verifys the node signature. + * + * Return value: 1 if signature is valid, 0 if invalid. -1 if an error occurs. + **/ gint lasso_node_verify_signature(LassoNode *node, const gchar *certificate_file) @@ -417,9 +553,9 @@ lasso_node_impl_export_to_base64(LassoNode *node) } static gchar * -lasso_node_impl_export_to_query(LassoNode *node, - gint sign_method, - const gchar *private_key_file) +lasso_node_impl_export_to_query(LassoNode *node, + lassoSignatureMethod sign_method, + const gchar *private_key_file) { GString *query; xmlDocPtr doc; @@ -437,15 +573,13 @@ lasso_node_impl_export_to_query(LassoNode *node, switch (sign_method) { case lassoSignatureMethodRsaSha1: str_escaped = lasso_str_escape((xmlChar *)xmlSecHrefRsaSha1); - query = g_string_append(query, str_escaped); - doc = lasso_str_sign(query->str, xmlSecTransformRsaSha1Id, private_key_file); break; case lassoSignatureMethodDsaSha1: str_escaped = lasso_str_escape((xmlChar *)xmlSecHrefDsaSha1); - query = g_string_append(query, str_escaped); - doc = lasso_str_sign(query->str, xmlSecTransformDsaSha1Id, private_key_file); break; } + query = g_string_append(query, str_escaped); + doc = lasso_str_sign(query->str, sign_method, private_key_file); xmlFree(str_escaped); query = g_string_append(query, "&Signature="); str1 = lasso_doc_get_node_content(doc, xmlSecNodeSignatureValue); diff --git a/lasso/xml/xml.h b/lasso/xml/xml.h index 457894de..320c6bdf 100644 --- a/lasso/xml/xml.h +++ b/lasso/xml/xml.h @@ -67,9 +67,9 @@ struct _LassoNodeClass { int format); xmlChar* (* export) (LassoNode *node); xmlChar* (* export_to_base64) (LassoNode *node); - gchar* (* export_to_query) (LassoNode *node, - gint sign_method, - const gchar *private_key_file); + gchar* (* export_to_query) (LassoNode *node, + lassoSignatureMethod sign_method, + const gchar *private_key_file); xmlChar* (* export_to_soap) (LassoNode *node); LassoAttr* (* get_attr) (LassoNode *node, const xmlChar *name); @@ -117,11 +117,6 @@ struct _LassoNodeClass { xmlNodePtr libxml_node); }; -typedef enum { - lassoSignatureMethodRsaSha1 = 1, - lassoSignatureMethodDsaSha1 -} lassoSignatureMethod; - LASSO_EXPORT GType lasso_node_get_type (void); LASSO_EXPORT LassoNode* lasso_node_new (void); @@ -140,9 +135,9 @@ LASSO_EXPORT xmlChar* lasso_node_export (LassoNode *node); LASSO_EXPORT xmlChar* lasso_node_export_to_base64 (LassoNode *node); -LASSO_EXPORT gchar* lasso_node_export_to_query (LassoNode *node, - gint sign_method, - const gchar *private_key_file); +LASSO_EXPORT gchar* lasso_node_export_to_query (LassoNode *node, + lassoSignatureMethod sign_method, + const gchar *private_key_file); LASSO_EXPORT xmlChar* lasso_node_export_to_soap (LassoNode *node); |