WiKID 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,144 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+
3
+ Version 2.1, February 1999
4
+
5
+
6
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
7
+ 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
8
+ Everyone is permitted to copy and distribute verbatim copies
9
+ of this license document, but changing it is not allowed.
10
+
11
+ [This is the first released version of the Lesser GPL. It also counts
12
+ as the successor of the GNU Library Public License, version 2, hence
13
+ the version number 2.1.]
14
+ Preamble
15
+
16
+ The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users.
17
+
18
+ This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below.
19
+
20
+ When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things.
21
+
22
+ To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it.
23
+
24
+ For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights.
25
+
26
+ We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library.
27
+
28
+ To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others.
29
+
30
+ Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license.
31
+
32
+ Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs.
33
+
34
+ When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library.
35
+
36
+ We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances.
37
+
38
+ For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License.
39
+
40
+ In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system.
41
+
42
+ Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library.
43
+
44
+ The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run.
45
+
46
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
47
+
48
+ 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you".
49
+
50
+ A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables.
51
+
52
+ The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".)
53
+
54
+ "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library.
55
+
56
+ Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does.
57
+
58
+ 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library.
59
+
60
+ You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.
61
+
62
+ 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:
63
+
64
+ a) The modified work must itself be a software library.
65
+ b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change.
66
+ c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License.
67
+ d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful.
68
+
69
+ (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.)
70
+
71
+ These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it.
72
+
73
+ Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library.
74
+
75
+ In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.
76
+
77
+ 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices.
78
+
79
+ Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy.
80
+
81
+ This option is useful when you wish to copy part of the code of the Library into a program that is not a library.
82
+
83
+ 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange.
84
+
85
+ If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code.
86
+
87
+ 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License.
88
+
89
+ However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables.
90
+
91
+ When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law.
92
+
93
+ If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.)
94
+
95
+ Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself.
96
+
97
+ 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications.
98
+
99
+ You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things:
100
+
101
+ a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.)
102
+ b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with.
103
+ c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution.
104
+ d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place.
105
+ e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy.
106
+
107
+ For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable.
108
+
109
+ It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute.
110
+
111
+ 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things:
112
+
113
+ a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above.
114
+ b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work.
115
+
116
+ 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.
117
+
118
+ 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it.
119
+
120
+ 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License.
121
+
122
+ 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library.
123
+
124
+ If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances.
125
+
126
+ It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice.
127
+
128
+ This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.
129
+
130
+ 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License.
131
+
132
+ 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
133
+
134
+ Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation.
135
+
136
+ 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally.
137
+
138
+ NO WARRANTY
139
+
140
+ 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
141
+
142
+ 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
143
+
144
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,15 @@
1
+ /lib
2
+ /lib/WiKID.rb
3
+ /docs
4
+ /docs/example
5
+ /docs/example/example.rhtml
6
+ /docs/example/example.rb
7
+ /docs/rubygems-0.8.11.security-patch.diff
8
+ /docs/LICENSE.txt
9
+ /share
10
+ /share/data
11
+ /share/data/WiKID-ca.pem
12
+ /tests
13
+ /tests/ts_wikid.rb
14
+ /README
15
+ /MANIFEST
@@ -0,0 +1,83 @@
1
+ Wikid Strong Authentication Module
2
+ http://sourceforge.net/projects/wikid-two-factor
3
+
4
+ Hate passwords? The WiKID Strong Authentication System is a key-based
5
+ two-factor authentication system. We built WiKID to be a flexible, extensible,
6
+ and secure alternative to tokens or passwords. Application support for Java,
7
+ Windows, PHP, SugarCRM, and Ruby.
8
+
9
+ ============================
10
+ INSTALLATION
11
+ ============================
12
+ The WiKID Ruby module is packaged in rubygem format. Download the latest version
13
+ from SourceForge, then run:
14
+
15
+ # gem install WiKID-x.y.z.gem
16
+
17
+ If you don't already have rubygems installed, you can get the latest version from
18
+ http://rubyforge.org/projects/rubygems/
19
+
20
+ ============================
21
+ !!! MOD_RUBY WARNING !!!
22
+ ============================
23
+ Versions of RubyGems up to 0.8.11 (the most recent as of Nov 1, 2005) do not
24
+ function properly when $SAFE = 1, which is the default setting when running
25
+ under mod_ruby.
26
+
27
+ Until this is corrected in the offical code, there are two work-arounds:
28
+
29
+ 1. If you're running a safe & secure Apache server (you are, right?), you can
30
+ simply turn of the safety checks with:
31
+
32
+ <IfModule mod_ruby.c>
33
+ RubySafeLevel 0
34
+ </IfModule>
35
+
36
+ 2. Apply the included patch docs/rubygems-0.8.11.security-patch.diff to your
37
+ rubygems installation (assumed to be in /usr/lib/ruby/site_ruby/1.8/rubygems/).
38
+ This will add the missing untaint'ings.
39
+
40
+ Note that FastCGI environments are not affected.
41
+
42
+ ============================
43
+ NETWORK CLIENT SETUP
44
+ ============================
45
+
46
+ Every WiKID network client needs a certificate from the WiKID server to talk
47
+ via SSL with the WiKID server. Create a network client on the WiKID server for
48
+ your Ruby network client and download the network client PKCS12 certificate to
49
+ your Ruby server.
50
+
51
+ To extract it from the .p12 file for use by Ruby, run:
52
+
53
+ # openssl pkcs12 -in clientcertkey.p12 -clcerts -out clientcertkey.pem
54
+
55
+ You will also need a copy of the server's cert too:
56
+
57
+ # scp root@yourwikidserver.com:/opt/WiKID/private/WiKIDCA.cer yourlocaldirectory
58
+
59
+ You need to let the WiKID.rb file know the location and passphrase for the
60
+ WiKID server's certificate. Find these lines and edit them for your set up:
61
+
62
+ @@cafile = "/opt/WiKID/private/WiKIDCA.cer";
63
+
64
+ Save the file.
65
+
66
+ We have provided sample files under docs/example/ for use with the WiKID server.
67
+ Use example.rb for command line or CGI, or example.rhtml for mod_ruby/eruby.
68
+ Edit for your correct variables:
69
+
70
+ servercode_default = "127000000001"
71
+ server_host = "wikid-server.example.com"
72
+ server_port = 8388
73
+ ca_cert_file = "WiKID-ca.pem"
74
+ client_key_file = "issued-client-cert-and-key.pem"
75
+ client_key_pass = "changeme"
76
+
77
+ That should be it! For help, please use the forums and documentation on our
78
+ SourceForge page.
79
+
80
+ ============================
81
+ The WiKID Team
82
+ http://www.wikidsystems.net
83
+
@@ -0,0 +1,40 @@
1
+ *** custom_require.rb 2005-07-06 10:14:03.000000000 -0400
2
+ --- /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb 2005-11-13 09:23:14.000000000 -0500
3
+ ***************
4
+ *** 96,102 ****
5
+ #
6
+ def matching_file(spec, path) # :doc:
7
+ glob = "#{@lib_dirs[spec.object_id]}/#{path}#{SUFFIX_PATTERN}"
8
+ ! return true unless Dir[glob].select { |f| File.file?(f) }.empty?
9
+ end
10
+
11
+ # Return a list of all installed gemspecs, sorted by alphabetical
12
+ --- 96,102 ----
13
+ #
14
+ def matching_file(spec, path) # :doc:
15
+ glob = "#{@lib_dirs[spec.object_id]}/#{path}#{SUFFIX_PATTERN}"
16
+ ! return true unless Dir[glob].select { |f| File.file?(f.untaint) }.empty?
17
+ end
18
+
19
+ # Return a list of all installed gemspecs, sorted by alphabetical
20
+ *** source_index.rb 2005-03-16 21:01:37.000000000 -0500
21
+ --- /usr/lib/ruby/site_ruby/1.8/rubygems/source_index.rb 2005-11-13 09:22:22.000000000 -0500
22
+ ***************
23
+ *** 70,77 ****
24
+ #
25
+ def self.load_specification(file_name)
26
+ begin
27
+ ! spec_code = File.read(file_name)
28
+ ! gemspec = eval(spec_code)
29
+ if gemspec.is_a?(Gem::Specification)
30
+ gemspec.loaded_from = file_name
31
+ return gemspec
32
+ --- 70,77 ----
33
+ #
34
+ def self.load_specification(file_name)
35
+ begin
36
+ ! spec_code = File.read(file_name.untaint)
37
+ ! gemspec = eval(spec_code.untaint)
38
+ if gemspec.is_a?(Gem::Specification)
39
+ gemspec.loaded_from = file_name
40
+ return gemspec
@@ -0,0 +1,587 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: :nodoc:
4
+
5
+ module WiKID
6
+
7
+ =begin rdoc
8
+
9
+ == Title
10
+
11
+ WiKID Strong Authentication module for Ruby
12
+
13
+ http://sourceforge.net/projects/wikid-twofactor/
14
+
15
+ == Synopsis
16
+
17
+ This is the core SSL client for WiKID Authentication. Auth_WiKID manages
18
+ communication between Network Clients (NC) and the WiKID Authentication
19
+ Server (wAuth).
20
+
21
+ == License
22
+ Lesser GNU Public License
23
+
24
+ This library is free software; you can redistribute it and/or
25
+ modify it under the terms of the GNU Lesser General Public
26
+ License as published by the Free Software Foundation; either
27
+ version 2.1 of the License, or (at your option) any later version.
28
+
29
+ This library is distributed in the hope that it will be useful,
30
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
31
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
32
+ Lesser General Public License for more details.
33
+
34
+ You should have received a copy of the GNU Lesser General Public
35
+ License along with this library; if not, write to the Free Software
36
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
37
+
38
+ == Author
39
+ Greg Haygood <ghaygood@wikidsystems.com>
40
+
41
+ == Copyright
42
+ Copyright (c) 2001-2005 WiKID Systems, Inc. All rights reserved.
43
+
44
+ == Version
45
+ CVS: Id: WiKID.rb,v 1.0 2005/09/22 05:32:19 ghaygood Exp
46
+
47
+ =end
48
+
49
+ ## Not necessarily true, but only tested with 1.8.x
50
+ raise "Please, use ruby 1.8.0 or later." if RUBY_VERSION < "1.8.0"
51
+
52
+ require 'socket'
53
+ require "rexml/document"
54
+ include REXML
55
+
56
+ SSLEnabled = begin
57
+ require 'openssl'
58
+ true
59
+ rescue LoadError
60
+ false
61
+ end
62
+
63
+ class Auth
64
+
65
+ private
66
+
67
+ =begin rdoc
68
+
69
+ Idle time to allow before closing socket, and time limit on socket
70
+ * open attempt
71
+
72
+ =end
73
+ @@timeout = 30
74
+
75
+ =begin rdoc
76
+
77
+ Controls whether debug messages will be printed
78
+
79
+ =end
80
+ @@DEBUG = false
81
+
82
+ @@VERSION = "3.0"
83
+
84
+ public
85
+
86
+ =begin rdoc
87
+
88
+ This constructor allows the Auth_WiKID module to be initialized from
89
+ either a properties file or via explicit arguments.
90
+
91
+ @param string host_or_file Either the IP address or hostname of
92
+ the wAuth server, or the path to a
93
+ properties file
94
+ @param int port The SSL listener port for the wAuth
95
+ daemon on the wAuth server
96
+ @param string keyfile The PKCS12 keystore generated for this
97
+ client by the wAuth server
98
+ @param string pass The passphrase securing the keys in keyfile
99
+ @param string cafile The certificate authority store for
100
+ validating the wAuth server certificate
101
+
102
+ The contents of the propertiesfile should contain the following
103
+ key-value pairs:
104
+ <ul>
105
+ <li> host - The IP address or hostname of the wAuth server
106
+ <li> port - The SSL listener port for the wAuth daemon on the
107
+ wAuth server
108
+ <li> keyfile - The PKCS12 keystore generated for client by
109
+ the wAuth server
110
+ <li> pass - The passphrase securing the keys in keyfile
111
+ <li> cafile - The PEM-encoded certificate file for validating the wAuth
112
+ server certificate
113
+ </ul>
114
+
115
+ =end
116
+ def initialize(host_or_file, port, keyfile, keypass, cafile = '')
117
+
118
+ unless SSLEnabled
119
+ raise RuntimeError.new("Ruby/OpenSSL module is required for WiKID authentication.")
120
+ end
121
+
122
+ if (cafile.empty?)
123
+ cafile = File.expand_path(File.join(File.dirname(__FILE__), "..", "share", "data", "WiKID-ca.pem"))
124
+ end
125
+
126
+ if (File.exist?(host_or_file))
127
+ # props = parse_ini_file(host_or_file)
128
+ props = Hash.new
129
+
130
+ @host = props['host']
131
+ @port = props['port']
132
+ @keyfile = props['keyfile']
133
+ @keypass = props['pass']
134
+ @cafile = props['cafile']
135
+ else
136
+ @host = host_or_file.untaint
137
+ @port = port.untaint
138
+ @keyfile = keyfile.untaint
139
+ @keypass = keypass.untaint
140
+ unless (cafile.nil? || cafile.empty?)
141
+ @cafile = cafile.untaint
142
+ end
143
+ end
144
+ if (!@port.is_a?(Integer))
145
+ @port = 0
146
+ end
147
+
148
+ _dprint("WiKID.rb initialized: host=#{@host}, port=#{@port}, keyfile=#{@keyfile}, cafile=#{@cafile}")
149
+
150
+ ## simple hack to allow for testing during gem installation (prevents security errors since keys may not yet be available)
151
+ unless port == -1
152
+ checkKeys()
153
+ end
154
+
155
+ return true
156
+ end
157
+
158
+ =begin rdoc
159
+
160
+ Class destructor, which just calls close().
161
+
162
+
163
+ =end
164
+ def _WiKID()
165
+ close()
166
+ end
167
+
168
+ =begin rdoc
169
+
170
+ This method simply closes the connection to the wAuth.
171
+
172
+
173
+ =end
174
+ def close()
175
+ _dprint("Closing Auth_WiKID connection ...")
176
+ if (!$sslsocket.nil? || $sslsocket.closed?)
177
+ $sslsocket.puts("QUIT");
178
+ $sslsocket.flush
179
+ $sslsocket.close
180
+ end
181
+ @isConnected = false
182
+ end
183
+
184
+ =begin rdoc
185
+
186
+ This method checks that the certificates are readable.
187
+
188
+
189
+ =end
190
+ def checkKeys()
191
+
192
+ data = nil
193
+ if (@cafile.nil? || @cafile.empty? || !File.exists?(@cafile) || OpenSSL::X509::Certificate.new(File.read(@cafile)).nil?)
194
+ raise SecurityError, "CA Public key NOT OK!"
195
+ else
196
+ _dprint("CA Public Key OK")
197
+ end
198
+
199
+ if (@keyfile.nil? || @keyfile.empty? || !File.exists?(@keyfile) || OpenSSL::X509::Certificate.new(File.read(@keyfile)).nil?)
200
+ raise SecurityError, "Public key NOT OK!"
201
+ else
202
+ _dprint("Public Key OK")
203
+ end
204
+
205
+ if (!File.exists?(@keyfile) || OpenSSL::PKey::RSA.new(File.read(@keyfile), @keypass).nil?)
206
+ raise SecurityError, "Private key NOT OK!"
207
+ else
208
+ _dprint("Private Key OK")
209
+ end
210
+
211
+ end
212
+
213
+ =begin rdoc
214
+
215
+ @param string mesg The message to send to the server
216
+
217
+ @return string response The response from the server
218
+
219
+ =end
220
+
221
+ def _request(mesg)
222
+ mesg.gsub!(/\n/, '')
223
+ _dprint("send.request is: #{mesg.inspect}")
224
+ _dprint("---------------------------------")
225
+ $sslsocket.puts(mesg)
226
+ $sslsocket.flush
227
+
228
+ _dprint("checking response...")
229
+ response = $sslsocket.gets.chomp!
230
+ _dprint("send.response is: #{response.inspect}")
231
+ unless response.nil?
232
+ xml = Document.new response
233
+ _dprint(xml.inspect);
234
+ else
235
+ _dprint('No response received.');
236
+ xml = nil
237
+ end
238
+ return xml;
239
+ end
240
+
241
+ =begin rdoc
242
+
243
+ =end
244
+ def _ping()
245
+ mesg = '<transaction> <type>1</type> <data> <value>TX</value> </data> </transaction>';
246
+ xml = _request(mesg);
247
+ end
248
+
249
+ =begin rdoc
250
+ This method initiates the connection to the wAuth server.
251
+
252
+ @return boolean Whether the socket is connected
253
+ =end
254
+ def _startConnection()
255
+ _dprint("startConnection() called.");
256
+ valid_tag = "ACCEPT";
257
+ # The client initiates the transaction
258
+ mesg = "CONNECT: WiKID Ruby version #{@@VERSION}"
259
+ mesg = '<transaction> <type>1</type> <data> <client-string>wClient Ruby #{@@VERSION}</client-string> <server-string>null</server-string> <result>null</result> </data> </transaction>
260
+ '
261
+
262
+ xml = _request(mesg);
263
+ result = XPath.first(xml, '//data/result')
264
+ if result == "ACCEPT"
265
+ _dprint("wClient connection ACCEPTED")
266
+ @isConnected = true
267
+ else
268
+ _dprint("wClient connection FAILED")
269
+ @isConnected = false
270
+ end
271
+ return @isConnected
272
+ end
273
+
274
+ =begin rdoc
275
+
276
+ This method reconnects to the wAuth server, if the socket handle is dead.
277
+
278
+ @return boolean Whether the socket is connected
279
+
280
+ =end
281
+ def reconnect()
282
+
283
+ _dprint("reconnect() called.")
284
+
285
+ begin
286
+
287
+ if ($sslsocket.nil? || $sslsocket.closed?)
288
+ _dprint("Socket inactive. Reconnecting...")
289
+
290
+ _dprint("Setting up SSL context ...")
291
+ ctx = OpenSSL::SSL::SSLContext.new()
292
+
293
+ # Options:
294
+ # "cert", "key", "client_ca", "ca_file", "ca_path",
295
+ # "timeout", "verify_mode", "verify_depth",
296
+ # "verify_callback", "options", "cert_store", "extra_chain_cert"
297
+
298
+ ctx.cert = OpenSSL::X509::Certificate.new(File.read(@keyfile))
299
+ ctx.key = OpenSSL::PKey::RSA.new(File.read(@keyfile), @keypass)
300
+
301
+ ctx.ca_file = @cafile
302
+ ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER | OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT
303
+ #ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER
304
+ #ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
305
+ ctx.timeout = @@timeout
306
+
307
+ if ctx.cert.nil?
308
+ warn "warning: peer certificate won't be verified this session."
309
+ ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
310
+ end
311
+
312
+ _dprint("Opening socket to #{@host}:#{@port}...")
313
+ @socket = TCPSocket.open(@host, @port)
314
+ @socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_RCVTIMEO, @@timeout)
315
+ @socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_SNDTIMEO, @@timeout)
316
+
317
+ $sslsocket = OpenSSL::SSL::SSLSocket.new(@socket, ctx)
318
+ #$sslsocket.sync_close = true
319
+
320
+ # $sslsocket should be good now
321
+ _dprint("Connecting SSL socket ...")
322
+ $sslsocket.connect
323
+
324
+ _startConnection()
325
+
326
+ end
327
+
328
+ if block_given?
329
+ _dprint("Connecting SSL socket in block ...")
330
+ $sslsocket.connect if $sslsocket.closed?
331
+ yield
332
+ _dprint("SSL connection block finished.")
333
+ else
334
+ _dprint("SSL connection wanting to do something else ...")
335
+ # do something non-OO
336
+ end
337
+ rescue Exception => ex
338
+ warn "Error reading from server: #{ex}"
339
+ end
340
+
341
+ end
342
+
343
+ =begin rdoc
344
+
345
+ Is the socket connected?
346
+
347
+ @return boolean Status of handle: true indicates connection is active
348
+
349
+ =end
350
+ def isConnected()
351
+ return @isConnected
352
+ end
353
+
354
+ =begin rdoc
355
+
356
+ Creates an association between the userid and the device registered
357
+ by the user.
358
+
359
+ @param string username Users login ID in this authentication domain
360
+ @param string regcode Registration code provided to user when
361
+ setting up this domain on users device
362
+ @param string domaincode 12 digit code representing this
363
+ authentication domain
364
+ @param string passcode Optional passcode provided by the user, to
365
+ link this device to an existing registration
366
+ @return int Result code from the registration attempt
367
+
368
+
369
+ =end
370
+ def registerUsername(username, regcode, domaincode, passcode = '')
371
+
372
+ _dprint("registerUsername() called ...")
373
+ valid_tag = "REGUSER:SUCESS"
374
+
375
+ if (!passcode.nil? && passcode.length > 0)
376
+ _dprint("Adding new device ...")
377
+ command = "ADDREGUSER"
378
+ type = 5;
379
+ passcodeline = "<passcode>#{passcode}</passcode>";
380
+ format = "add";
381
+ else
382
+ _dprint("Registering user ...")
383
+ command = "REGUSER"
384
+ type = 4;
385
+ passcodeline = "";
386
+ format = "new";
387
+ end
388
+
389
+ mesg = "#{command}:#{uname}\t#{regcode}\t#{domaincode}\t#{passcode}"
390
+ mesg = <<XML
391
+ <transaction>
392
+ <type format="#{format}">#{type}</type>
393
+ <data>
394
+ <user-id>#{username}</user-id>
395
+ <registration-code>#{regcode}</registration-code>
396
+ <domaincode>#{domaincode}</domaincode>
397
+ #{passcodeline}
398
+ <error-code>null</error-code>
399
+ <result>null</result>
400
+ </data>
401
+ </transaction>
402
+ XML
403
+
404
+ reconnect {
405
+
406
+ _dprint("registerUsername() sending '#{mesg}' ...")
407
+
408
+ xml = _request(mesg)
409
+ response = XPath.first(xml, '//data/result')
410
+ _dprint("response: '#{response}'")
411
+ if response =~ /SUCC?ESS/
412
+ _dprint("Registered!")
413
+ return 0
414
+ else
415
+ err = XPath.first(xml, '//data/error-code')
416
+ _dprint("Failed to register! Error: #{err}")
417
+ return err
418
+ end
419
+ }
420
+
421
+ end
422
+
423
+ =begin rdoc
424
+
425
+ Verifies credentials generated using the online mechanism.
426
+
427
+ @param string username Users login ID in this authentication domain
428
+ @param string passcode Passcode provided by the user
429
+ @param string domaincode 12 digit code representing the
430
+ authentication domain
431
+ @return boolean 'true' indicates credentials were valid,
432
+ 'false' if credentials were invalid or
433
+ an error occurred
434
+
435
+ =end
436
+ def checkCredentials(username, passcode, domaincode = '127000000001')
437
+
438
+ _dprint("checkCredentials(#{username}, #{passcode}, #{domaincode}) called ...")
439
+
440
+ validCredentials = false
441
+ offline_challenge = ''
442
+ offline_response = ''
443
+ chap_password = ''
444
+ chap_challenge = ''
445
+ valid_tag = "VERIFY:VALID"
446
+
447
+ _dprint("Checking Credentials...")
448
+
449
+ mesg = "VERIFY:" + username + "\t" + passcode + "\t" + domaincode
450
+ mesg = <<XML
451
+ <transaction>
452
+ <type format="base">2</type>
453
+ <data>
454
+ <user-id>#{username}</user-id>
455
+ <passcode>#{passcode}</passcode>
456
+ <domaincode>#{domaincode}</domaincode>
457
+ <offline-challenge encoding="none">#{offline_challenge}</offline-challenge>
458
+ <offline-response encoding="none">#{offline_response}</offline-response>
459
+ <chap-password encoding="none">#{chap_password}</chap-password>
460
+ <chap-challenge encoding="none">#{chap_challenge}</chap-challenge>
461
+ <result>null</result>
462
+ </data>
463
+ </transaction>
464
+ XML
465
+
466
+ reconnect {
467
+
468
+ xml = _request(mesg)
469
+ response = XPath.first(xml, '//data/result')
470
+
471
+ if response =~ /VALID/
472
+ validCredentials = true
473
+ else
474
+ validCredentials = false
475
+ end
476
+ _dprint("Read response: verdict = " + validCredentials.to_s)
477
+ }
478
+
479
+ _dprint("Returning Results...")
480
+ return validCredentials
481
+ end
482
+
483
+ =begin rdoc
484
+
485
+ Verifies the credentials via challenge-response.
486
+
487
+ <b>!!! Not currently supported by the Open Source release of WiKID.</b>
488
+
489
+ @ignore
490
+ @return boolean 'true' indicates credentials were valid,
491
+ 'false' if credentials were invalid or
492
+ an error occurred
493
+
494
+ =end
495
+ def chapVerify(username, domaincode, wikidChallenge = '', chapPassword = '', chapChallenge = '')
496
+
497
+ _dprint("chapVerify() called ...")
498
+ reconnect()
499
+ validCredentials = false
500
+ valid_tag = "VERIFY:VALID"
501
+ _dprint("Checking Chap Credentials")
502
+
503
+ mesg = "CHAPOFFVERIFY:" + username + "\t" + "nil" + "\t" + domaincode + "\t" + wikidChallenge
504
+
505
+ reconnect {
506
+
507
+ $sslsocket.puts(chapPassword.length)
508
+ $sslsocket.puts(chapPassword)
509
+ $sslsocket.puts(chapChallenge.length)
510
+ $sslsocket.puts(chapChallenge.length)
511
+ $sslsocket.flush
512
+
513
+ _dprint("Reading in...")
514
+
515
+ inputLine = $sslsocket.gets.chomp!
516
+ if (inputLine[0, valid_tag.length] == valid_tag)
517
+ validCredentials = true
518
+ end
519
+ }
520
+
521
+ return validCredentials
522
+ end
523
+
524
+ =begin rdoc
525
+
526
+ Fetches a list of domains served by the currently connected server code.
527
+
528
+ <b>!!! Not currently supported by the Open Source release of WiKID.</b>
529
+
530
+
531
+ @ignore
532
+ @return boolean 'true' indicates credentials were valid,
533
+ 'false' if credentials were invalid or
534
+ an error occurred
535
+
536
+ =end
537
+ def getDomains()
538
+
539
+ _dprint("getDomains() called ...")
540
+
541
+ valid_tag = "DOMAINLIST"
542
+ _dprint("Getting Domains")
543
+
544
+ mesg = <<XML
545
+ <transaction>
546
+ <type>3</type>
547
+ <data>
548
+ <domain-list>null</domain-list>
549
+ </data>
550
+ </transaction>
551
+ XML
552
+ reconnect {
553
+ xml = _request(mesg)
554
+ domains = XPath.match(xml, '//data/domain-list')
555
+ }
556
+ _dprint("Returning Results...")
557
+ return domains
558
+ end
559
+
560
+ def setDebug(newval)
561
+ @@DEBUG = (newval == true) ? true : false
562
+ end
563
+
564
+ =begin rdoc
565
+
566
+ Prints a time-stamped (since the epoch) message if _@@DEBUG is true.
567
+
568
+ @param string str Message to print out
569
+
570
+ =end
571
+ def _dprint(msg)
572
+
573
+ if (@@DEBUG)
574
+ show = Time.now.to_s + ': ' + msg
575
+ show += '<br />' if !ENV['REQUEST_URI'].nil?
576
+
577
+ puts show
578
+ #STDERR.puts show
579
+ #STDERR.flush()
580
+ end
581
+ return true
582
+ end
583
+
584
+ end
585
+
586
+ end
587
+
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ # $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
5
+
6
+ class TestWiKID < Test::Unit::TestCase
7
+
8
+ def test_001_rubygems
9
+
10
+ begin
11
+ require 'rubygems'
12
+ loaded = 1
13
+ rescue Exception
14
+ # puts "WARNING: RubyGems not installed"
15
+ loaded = 0
16
+ end
17
+ assert(loaded == 1, "Unable to load RubyGems!")
18
+
19
+ require 'rubygems/rubygems_version.rb'
20
+ # puts "Loaded RubyGems #{Gem::RubyGemsVersion} ..."
21
+
22
+ if (Gem::RubyGemsVersion <= '0.8.11')
23
+ # puts "WARNING: RubyGems may need patching for a mod_ruby environment. Please see doc/README for more details"
24
+ end
25
+
26
+ end
27
+
28
+ def test_002_load_module
29
+
30
+ begin
31
+ require_gem 'WiKID'
32
+ loaded = 1
33
+ rescue
34
+ loaded = 0
35
+ end
36
+ assert(loaded == 1, "Unable to load WiKID module!")
37
+
38
+ end
39
+
40
+ def test_003_init_module
41
+
42
+ server_host = "127000000001"
43
+ server_port = -1
44
+ client_key_file = "/path/to/nowhere.pem"
45
+ client_key_pass = "changeme"
46
+
47
+ wc = WiKID::Auth.new(server_host, server_port, client_key_file, client_key_pass)
48
+ assert_not_nil(wc, "WiKID module successfully loaded!")
49
+
50
+ end
51
+
52
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: WiKID
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Greg Haygood
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-02-25 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: ghaygood @nospam@ wikidsystems.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - doc/README
24
+ files:
25
+ - lib/WiKID.rb
26
+ - doc/example
27
+ - doc/rubygems-0.8.11.security-patch.diff
28
+ - doc/MANIFEST
29
+ - doc/README
30
+ - doc/LICENSE.txt
31
+ - share/data
32
+ - test/ts_wikid.rb
33
+ has_rdoc: true
34
+ homepage: http://sourgeforge.net/projects/two-factor
35
+ post_install_message:
36
+ rdoc_options: []
37
+
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: "0"
45
+ version:
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ requirements: []
53
+
54
+ rubyforge_project: wikid
55
+ rubygems_version: 1.0.1
56
+ signing_key:
57
+ specification_version: 2
58
+ summary: A network client module for the WiKID Strong Authentication system
59
+ test_files: []
60
+