xmlsec-ruby 0.0.6 → 0.0.7a

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,11 @@
1
1
  require 'mkmf'
2
2
  if pkg_config('xmlsec1-openssl')
3
+ # The rightscale image appears to have incorrect
4
+ # pkg-config files - this flag is needed to link against an
5
+ # 64-bit libxmlsec1 but isn't included in the pkg-config
6
+ if system("uname -p") == 'x86_64'
7
+ $CFLAGS += " -DXMLSEC_NO_SIZE_T"
8
+ end
3
9
  create_makefile('xmlsec')
4
10
  else
5
11
  puts "xmlsec1 is not installed."
@@ -6,8 +6,6 @@
6
6
  #include <libxml/tree.h>
7
7
  #include <libxml/xmlmemory.h>
8
8
  #include <libxml/parser.h>
9
- #include <libxml/xpath.h>
10
- #include <libxml/xpathInternals.h>
11
9
 
12
10
  #include <xmlsec/xmlsec.h>
13
11
  #include <xmlsec/xmltree.h>
@@ -23,64 +21,69 @@ void cleanup(xmlSecDSigCtxPtr dsigCtx) ;
23
21
  int verify_document(xmlDocPtr doc, const char* key);
24
22
  int verify_file(const char* xmlMessage, const char* key);
25
23
  void xmlSecErrorCallback(const char* file, int line, const char* func, const char* errorObject, const char* errorSubject, int reason, const char* msg);
26
- int assign_id_attributes(xmlDocPtr doc) {
27
- // Assume the ID attribute is one of (ID | Id | id) and tell this to libxml
28
- xmlXPathContextPtr xpathCtx = xmlXPathNewContext(doc);
29
- if(xpathCtx == NULL) {
30
- xmlFreeDoc(doc);
31
- rb_raise(rb_eRuntimeError,"Error: unable to create new XPath context\n");
32
- return(-1);
33
- }
34
- xmlChar* xpathExpr = "//*[@ID | @Id | @id]";
35
-
36
- xmlXPathObjectPtr xpathObj = xmlXPathEvalExpression(xpathExpr, xpathCtx);
37
- if(xpathObj == NULL) {
38
- xmlXPathFreeContext(xpathCtx);
39
- xmlFreeDoc(doc);
40
- rb_raise(rb_eRuntimeError,"Error: unable to evaluate xpath expression \"%s\"\n", xpathExpr);
41
- return(-1);
42
- }
43
- xmlNodeSetPtr nodes = xpathObj->nodesetval;
44
- int size = (nodes) ? nodes->nodeNr : 0;
45
- char* idNames[] = {"ID", "Id", "id"};
46
- xmlAttrPtr attr, tmp;
47
- int i,j;
48
- for(i = 0; i < size; i++) {
49
- for(j=0; j<3;j++) {
50
- tmp = xmlHasProp(nodes->nodeTab[i], idNames[j]);
51
- if(tmp != NULL)
52
- attr = tmp;
53
- }
54
- if(attr == NULL) {
55
- xmlXPathFreeContext(xpathCtx);
56
- return(-1);
57
- }
58
- xmlChar* name = xmlNodeListGetString(doc, attr->children, 1);
59
- if(name == NULL) {
60
- xmlXPathFreeContext(xpathCtx);
61
- return(-1);
62
- }
63
- xmlAttrPtr tmp = xmlGetID(doc, name);
64
- if(tmp != NULL) {
65
- xmlFree(name);
66
- return 0;
67
- }
68
- xmlAddID(NULL, doc, name, attr);
69
- xmlFree(name);
70
- }
71
-
72
- xmlXPathFreeObject(xpathObj);
73
- xmlXPathFreeContext(xpathCtx);
24
+ static int
25
+ xmlSecAppAddIDAttr(xmlNodePtr node, const xmlChar* attrName, const xmlChar* nodeName, const xmlChar* nsHref) {
26
+ xmlAttrPtr attr, tmpAttr;
27
+ xmlNodePtr cur;
28
+ xmlChar* id;
29
+
30
+ if((node == NULL) || (attrName == NULL) || (nodeName == NULL)) {
31
+ return(-1);
32
+ }
33
+
34
+ /* process children first because it does not matter much but does simplify code */
35
+ cur = xmlSecGetNextElementNode(node->children);
36
+ while(cur != NULL) {
37
+ if(xmlSecAppAddIDAttr(cur, attrName, nodeName, nsHref) < 0) {
38
+ return(-1);
39
+ }
40
+ cur = xmlSecGetNextElementNode(cur->next);
41
+ }
42
+
43
+ /* node name must match */
44
+ if(!xmlStrEqual(node->name, nodeName)) {
45
+ return(0);
46
+ }
47
+
48
+ /* if nsHref is set then it also should match */
49
+ if((nsHref != NULL) && (node->ns != NULL) && (!xmlStrEqual(nsHref, node->ns->href))) {
50
+ return(0);
51
+ }
52
+
53
+ /* the attribute with name equal to attrName should exist */
54
+ for(attr = node->properties; attr != NULL; attr = attr->next) {
55
+ if(xmlStrEqual(attr->name, attrName)) {
56
+ break;
57
+ }
58
+ }
59
+ if(attr == NULL) {
60
+ return(0);
61
+ }
62
+
63
+ /* and this attr should have a value */
64
+ id = xmlNodeListGetString(node->doc, attr->children, 1);
65
+ if(id == NULL) {
66
+ return(0);
67
+ }
68
+
69
+ /* check that we don't have same ID already */
70
+ tmpAttr = xmlGetID(node->doc, id);
71
+ if(tmpAttr == NULL) {
72
+ xmlAddID(NULL, node->doc, id, attr);
73
+ } else if(tmpAttr != attr) {
74
+ fprintf(stderr, "Error: duplicate ID attribute \"%s\"\n", id);
75
+ xmlFree(id);
76
+ return(-1);
77
+ }
78
+ xmlFree(id);
79
+ return(0);
74
80
  }
75
-
76
81
 
77
82
  /* functions */
78
83
  int verify_file(const char* xmlMessage, const char* key) {
79
84
  xmlDocPtr doc = NULL;
80
85
  /* Init libxml and libxslt libraries */
81
- xmlInitParser();
82
86
  LIBXML_TEST_VERSION
83
- xmlLoadExtDtdDefaultValue = XML_DETECT_IDS | XML_COMPLETE_ATTRS;
84
87
  xmlSubstituteEntitiesDefault(1);
85
88
  doc = xmlParseDoc((xmlChar *) xmlMessage) ;
86
89
  return verify_document(doc, key);
@@ -93,19 +96,25 @@ int verify_document(xmlDocPtr doc, const char* key) {
93
96
  int res = 0;
94
97
 
95
98
  if ((doc == NULL) || (xmlDocGetRootElement(doc) == NULL)){
99
+ cleanup(dsigCtx);
96
100
  rb_raise(rb_eRuntimeError, "unable to parse XML document");
97
101
  }
98
102
 
99
103
  /* find start node */
100
104
  node = xmlSecFindNode(xmlDocGetRootElement(doc), xmlSecNodeSignature, xmlSecDSigNs);
101
105
  if(node == NULL) {
106
+ cleanup(dsigCtx);
102
107
  rb_raise(rb_eRuntimeError, "could not find start node in XML document");
103
108
  }
104
109
 
105
- if(assign_id_attributes(doc) < 0) {
106
- rb_raise(rb_eRuntimeError, "Could not find ID attribute in document");
110
+ xmlNodePtr cur = xmlSecGetNextElementNode(doc->children);
111
+ while(cur != NULL) {
112
+ if(xmlSecAppAddIDAttr(cur, "ID", "Response", "urn:oasis:names:tc:SAML:2.0:protocol") < 0) {
113
+ cleanup(dsigCtx);
114
+ rb_raise(rb_eRuntimeError, "could not define ID attribute");
115
+ }
116
+ cur = xmlSecGetNextElementNode(cur->next);
107
117
  }
108
-
109
118
 
110
119
  /* create signature context */
111
120
  dsigCtx = xmlSecDSigCtxCreate(NULL);
@@ -160,21 +169,6 @@ int initialize()
160
169
  return(-1);
161
170
  }
162
171
 
163
- /* Load default crypto engine if we are supporting dynamic
164
- * loading for xmlsec-crypto libraries. Use the crypto library
165
- * name ("openssl", "nss", etc.) to load corresponding
166
- * xmlsec-crypto library.
167
- */
168
- #ifdef XMLSEC_CRYPTO_DYNAMIC_LOADING
169
- if(xmlSecCryptoDLLoadLibrary(BAD_CAST XMLSEC_CRYPTO) < 0) {
170
- fprintf(stdout, "Error: unable to load default xmlsec-crypto library. Make sure\n"
171
- "that you have it installed and check shared libraries path\n"
172
- "(LD_LIBRARY_PATH) envornment variable.\n");
173
- fflush(stdout) ;
174
- return(-1);
175
- }
176
- #endif /* XMLSEC_CRYPTO_DYNAMIC_LOADING */
177
-
178
172
  /* Init xmlsec-crypto library */
179
173
  if(xmlSecCryptoInit() < 0) {
180
174
  fprintf(stderr, "Error: xmlsec-crypto initialization failed.\n");
@@ -194,11 +188,5 @@ void SecShutdown()
194
188
 
195
189
  /* Shutdown xmlsec library */
196
190
  xmlSecShutdown();
197
-
198
- /* Shutdown libxslt/libxml */
199
- #ifndef XMLSEC_NO_XSLT
200
- xsltCleanupGlobals();
201
- #endif /* XMLSEC_NO_XSLT */
202
- xmlCleanupParser();
203
191
  return ;
204
192
  }
@@ -1,6 +1,6 @@
1
1
  /* ----------------------------------------------------------------------------
2
2
  * This file was automatically generated by SWIG (http://www.swig.org).
3
- * Version 2.0.1
3
+ * Version 2.0.0
4
4
  *
5
5
  * This file is not intended to be easily readable and contains a number of
6
6
  * coding conventions designed to improve portability and efficiency. Do not make
@@ -281,7 +281,7 @@
281
281
  /*
282
282
  Flags/methods for returning states.
283
283
 
284
- The SWIG conversion methods, as ConvertPtr, return an integer
284
+ The SWIG conversion methods, as ConvertPtr, return and integer
285
285
  that tells if the conversion was successful or not. And if not,
286
286
  an error code can be returned (see swigerrors.swg for the codes).
287
287
 
@@ -998,7 +998,7 @@ static VALUE _mSWIG = Qnil;
998
998
 
999
999
  /* Define custom exceptions for errors that do not map to existing Ruby
1000
1000
  exceptions. Note this only works for C++ since a global cannot be
1001
- initialized by a function in C. For C, fallback to rb_eRuntimeError.*/
1001
+ initialized by a funtion in C. For C, fallback to rb_eRuntimeError.*/
1002
1002
 
1003
1003
  SWIGINTERN VALUE
1004
1004
  getNullReferenceError(void) {
@@ -1807,7 +1807,7 @@ static VALUE mXmlsec;
1807
1807
  #define SWIG_RUBY_THREAD_END_BLOCK
1808
1808
 
1809
1809
 
1810
- #define SWIGVERSION 0x020001
1810
+ #define SWIGVERSION 0x020000
1811
1811
  #define SWIG_VERSION SWIGVERSION
1812
1812
 
1813
1813
 
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xmlsec-ruby
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
5
- prerelease: false
4
+ hash: 54
5
+ prerelease: 5
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
9
+ - 7
10
+ - a
11
+ version: 0.0.7a
11
12
  platform: ruby
12
13
  authors:
13
14
  - Victor Lin
@@ -15,11 +16,11 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2010-12-14 00:00:00 -08:00
19
+ date: 2011-04-25 00:00:00 -07:00
19
20
  default_executable:
20
21
  dependencies: []
21
22
 
22
- description: "\txmlsec-ruby is a project using SWIG to create ruby bindings\n\
23
+ description: "\txmlsec-ruby is project using SWIG to create ruby bindings\n\
23
24
  \tfor the xmlsec library (http://www.aleksey.com/xmlsec/). \n"
24
25
  email: victor@coupa.com
25
26
  executables: []
@@ -53,16 +54,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
53
54
  required_rubygems_version: !ruby/object:Gem::Requirement
54
55
  none: false
55
56
  requirements:
56
- - - ">="
57
+ - - ">"
57
58
  - !ruby/object:Gem::Version
58
- hash: 3
59
+ hash: 25
59
60
  segments:
60
- - 0
61
- version: "0"
61
+ - 1
62
+ - 3
63
+ - 1
64
+ version: 1.3.1
62
65
  requirements: []
63
66
 
64
67
  rubyforge_project:
65
- rubygems_version: 1.3.7
68
+ rubygems_version: 1.6.2
66
69
  signing_key:
67
70
  specification_version: 3
68
71
  summary: Ruby bindings for xmlsec1