xmlsec-ruby 0.0.6 → 0.0.7a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ext/xmlsec/extconf.rb +6 -0
- data/ext/xmlsec/simple-xmlsec.c +65 -77
- data/ext/xmlsec/simple-xmlsec_wrap.c +4 -4
- metadata +14 -11
data/ext/xmlsec/extconf.rb
CHANGED
@@ -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."
|
data/ext/xmlsec/simple-xmlsec.c
CHANGED
@@ -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
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
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
|
-
|
106
|
-
|
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.
|
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
|
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
|
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
|
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:
|
5
|
-
prerelease:
|
4
|
+
hash: 54
|
5
|
+
prerelease: 5
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
|
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:
|
19
|
+
date: 2011-04-25 00:00:00 -07:00
|
19
20
|
default_executable:
|
20
21
|
dependencies: []
|
21
22
|
|
22
|
-
description: "\txmlsec-ruby is
|
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:
|
59
|
+
hash: 25
|
59
60
|
segments:
|
60
|
-
-
|
61
|
-
|
61
|
+
- 1
|
62
|
+
- 3
|
63
|
+
- 1
|
64
|
+
version: 1.3.1
|
62
65
|
requirements: []
|
63
66
|
|
64
67
|
rubyforge_project:
|
65
|
-
rubygems_version: 1.
|
68
|
+
rubygems_version: 1.6.2
|
66
69
|
signing_key:
|
67
70
|
specification_version: 3
|
68
71
|
summary: Ruby bindings for xmlsec1
|