polarssl 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,171 @@
1
+ *Please note*:
2
+ PolarSSL itself is released as GPL or a Commercial License.
3
+ You will need to take this into account when using PolarSSL and this Ruby extension in your
4
+ own software.
5
+
6
+ ======
7
+ GNU LESSER GENERAL PUBLIC LICENSE
8
+ Version 3, 29 June 2007
9
+
10
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
11
+ Everyone is permitted to copy and distribute verbatim copies
12
+ of this license document, but changing it is not allowed.
13
+
14
+
15
+ This version of the GNU Lesser General Public License incorporates
16
+ the terms and conditions of version 3 of the GNU General Public
17
+ License, supplemented by the additional permissions listed below.
18
+
19
+ 0. Additional Definitions.
20
+
21
+ As used herein, "this License" refers to version 3 of the GNU Lesser
22
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
23
+ General Public License.
24
+
25
+ "The Library" refers to a covered work governed by this License,
26
+ other than an Application or a Combined Work as defined below.
27
+
28
+ An "Application" is any work that makes use of an interface provided
29
+ by the Library, but which is not otherwise based on the Library.
30
+ Defining a subclass of a class defined by the Library is deemed a mode
31
+ of using an interface provided by the Library.
32
+
33
+ A "Combined Work" is a work produced by combining or linking an
34
+ Application with the Library. The particular version of the Library
35
+ with which the Combined Work was made is also called the "Linked
36
+ Version".
37
+
38
+ The "Minimal Corresponding Source" for a Combined Work means the
39
+ Corresponding Source for the Combined Work, excluding any source code
40
+ for portions of the Combined Work that, considered in isolation, are
41
+ based on the Application, and not on the Linked Version.
42
+
43
+ The "Corresponding Application Code" for a Combined Work means the
44
+ object code and/or source code for the Application, including any data
45
+ and utility programs needed for reproducing the Combined Work from the
46
+ Application, but excluding the System Libraries of the Combined Work.
47
+
48
+ 1. Exception to Section 3 of the GNU GPL.
49
+
50
+ You may convey a covered work under sections 3 and 4 of this License
51
+ without being bound by section 3 of the GNU GPL.
52
+
53
+ 2. Conveying Modified Versions.
54
+
55
+ If you modify a copy of the Library, and, in your modifications, a
56
+ facility refers to a function or data to be supplied by an Application
57
+ that uses the facility (other than as an argument passed when the
58
+ facility is invoked), then you may convey a copy of the modified
59
+ version:
60
+
61
+ a) under this License, provided that you make a good faith effort to
62
+ ensure that, in the event an Application does not supply the
63
+ function or data, the facility still operates, and performs
64
+ whatever part of its purpose remains meaningful, or
65
+
66
+ b) under the GNU GPL, with none of the additional permissions of
67
+ this License applicable to that copy.
68
+
69
+ 3. Object Code Incorporating Material from Library Header Files.
70
+
71
+ The object code form of an Application may incorporate material from
72
+ a header file that is part of the Library. You may convey such object
73
+ code under terms of your choice, provided that, if the incorporated
74
+ material is not limited to numerical parameters, data structure
75
+ layouts and accessors, or small macros, inline functions and templates
76
+ (ten or fewer lines in length), you do both of the following:
77
+
78
+ a) Give prominent notice with each copy of the object code that the
79
+ Library is used in it and that the Library and its use are
80
+ covered by this License.
81
+
82
+ b) Accompany the object code with a copy of the GNU GPL and this license
83
+ document.
84
+
85
+ 4. Combined Works.
86
+
87
+ You may convey a Combined Work under terms of your choice that,
88
+ taken together, effectively do not restrict modification of the
89
+ portions of the Library contained in the Combined Work and reverse
90
+ engineering for debugging such modifications, if you also do each of
91
+ the following:
92
+
93
+ a) Give prominent notice with each copy of the Combined Work that
94
+ the Library is used in it and that the Library and its use are
95
+ covered by this License.
96
+
97
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
98
+ document.
99
+
100
+ c) For a Combined Work that displays copyright notices during
101
+ execution, include the copyright notice for the Library among
102
+ these notices, as well as a reference directing the user to the
103
+ copies of the GNU GPL and this license document.
104
+
105
+ d) Do one of the following:
106
+
107
+ 0) Convey the Minimal Corresponding Source under the terms of this
108
+ License, and the Corresponding Application Code in a form
109
+ suitable for, and under terms that permit, the user to
110
+ recombine or relink the Application with a modified version of
111
+ the Linked Version to produce a modified Combined Work, in the
112
+ manner specified by section 6 of the GNU GPL for conveying
113
+ Corresponding Source.
114
+
115
+ 1) Use a suitable shared library mechanism for linking with the
116
+ Library. A suitable mechanism is one that (a) uses at run time
117
+ a copy of the Library already present on the user's computer
118
+ system, and (b) will operate properly with a modified version
119
+ of the Library that is interface-compatible with the Linked
120
+ Version.
121
+
122
+ e) Provide Installation Information, but only if you would otherwise
123
+ be required to provide such information under section 6 of the
124
+ GNU GPL, and only to the extent that such information is
125
+ necessary to install and execute a modified version of the
126
+ Combined Work produced by recombining or relinking the
127
+ Application with a modified version of the Linked Version. (If
128
+ you use option 4d0, the Installation Information must accompany
129
+ the Minimal Corresponding Source and Corresponding Application
130
+ Code. If you use option 4d1, you must provide the Installation
131
+ Information in the manner specified by section 6 of the GNU GPL
132
+ for conveying Corresponding Source.)
133
+
134
+ 5. Combined Libraries.
135
+
136
+ You may place library facilities that are a work based on the
137
+ Library side by side in a single library together with other library
138
+ facilities that are not Applications and are not covered by this
139
+ License, and convey such a combined library under terms of your
140
+ choice, if you do both of the following:
141
+
142
+ a) Accompany the combined library with a copy of the same work based
143
+ on the Library, uncombined with any other library facilities,
144
+ conveyed under the terms of this License.
145
+
146
+ b) Give prominent notice with the combined library that part of it
147
+ is a work based on the Library, and explaining where to find the
148
+ accompanying uncombined form of the same work.
149
+
150
+ 6. Revised Versions of the GNU Lesser General Public License.
151
+
152
+ The Free Software Foundation may publish revised and/or new versions
153
+ of the GNU Lesser General Public License from time to time. Such new
154
+ versions will be similar in spirit to the present version, but may
155
+ differ in detail to address new problems or concerns.
156
+
157
+ Each version is given a distinguishing version number. If the
158
+ Library as you received it specifies that a certain numbered version
159
+ of the GNU Lesser General Public License "or any later version"
160
+ applies to it, you have the option of following the terms and
161
+ conditions either of that published version or of any later version
162
+ published by the Free Software Foundation. If the Library as you
163
+ received it does not specify a version number of the GNU Lesser
164
+ General Public License, you may choose any version of the GNU Lesser
165
+ General Public License ever published by the Free Software Foundation.
166
+
167
+ If the Library as you received it specifies that a proxy can decide
168
+ whether future versions of the GNU Lesser General Public License shall
169
+ apply, that proxy's public statement of acceptance of any version is
170
+ permanent authorization for you to choose that version for the
171
+ Library.
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "rake"
4
+ gem "rake-compiler"
5
+ gem "sdoc", require: false
@@ -0,0 +1,20 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ json (1.8.0)
5
+ rake (10.0.4)
6
+ rake-compiler (0.9.1)
7
+ rake
8
+ rdoc (3.12.2)
9
+ json (~> 1.4)
10
+ sdoc (0.3.20)
11
+ json (>= 1.1.3)
12
+ rdoc (~> 3.10)
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ rake
19
+ rake-compiler
20
+ sdoc
@@ -0,0 +1,33 @@
1
+ = Using PolarSSL
2
+
3
+ == Setting up an SSL Connection
4
+
5
+ require 'polarssl'
6
+
7
+ socket = TCPSocket.new('polarssl.org', 443)
8
+
9
+ entropy = PolarSSL::Entropy.new
10
+ ctr_drbg = PolarSSL::CtrDrbg.new(entropy)
11
+ ssl = PolarSSL::SSL.new
12
+
13
+ ssl.set_endpoint(PolarSSL::SSL::SSL_IS_CLIENT)
14
+ ssl.set_authmode(PolarSSL::SSL::SSL_VERIFY_NONE)
15
+ ssl.set_rng(ctr_drbg)
16
+
17
+ ssl.set_socket(socket)
18
+
19
+ ssl.handshake
20
+
21
+ ssl.write("GET / HTTP/1.0\r\nHost: polarssl.org\r\n\r\n")
22
+
23
+ while chunk = ssl.read(1024)
24
+ response << chunk
25
+ end
26
+
27
+ puts response
28
+
29
+ ssl.close_notify
30
+
31
+ socket.close
32
+
33
+ ssl.close
@@ -0,0 +1,111 @@
1
+ PolarSSL for Ruby
2
+ =================
3
+
4
+ * API documentation: http://michiels.github.io/polarssl-ruby/doc
5
+
6
+ ## Description
7
+
8
+ With PolarSSL for Ruby, you can use SSL and cryptography functionality from PolarSSL in your Ruby programs.
9
+
10
+ ## Features
11
+
12
+ * Set up encrypted SSL connections.
13
+
14
+ ## Installation
15
+
16
+ ```
17
+ gem install polarssl
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ This gem provides a pretty low level interface to the native PolarSSL C library.
23
+ The core API aims to reflect the PolarSSL library as much as possible. See the
24
+ [full API documentation](http://michiels.github.io/polarssl-ruby/doc/) for all classes and methods.
25
+
26
+ ```ruby
27
+ require 'polarssl'
28
+
29
+ socket = TCPSocket.new('polarssl', 443)
30
+
31
+ entropy = PolarSSL::Entropy.new
32
+ ctr_drbg = PolarSSL::CtrDrbg.new(entropy)
33
+
34
+ ssl = PolarSSL::SSL.new
35
+ ssl.set_endpoint(PolarSSL::SSL::SSL_IS_CLIENT)
36
+ ssl.set_authmode(PolarSSL::SSL::SSL_VERIFY_NONE)
37
+ ssl.set_rng(ctr_drbg)
38
+ ssl.set_socket(socket)
39
+
40
+ ssl.handshake
41
+
42
+ ssl.write("GET / HTTP/1.0\r\nHost: polarssl.org\r\n\r\n")
43
+
44
+ while chunk = ssl.read(1024)
45
+ response << chunk
46
+ end
47
+
48
+ puts response
49
+
50
+ ssl.close_notify
51
+
52
+ socket.close
53
+
54
+ ssl.close
55
+ ```
56
+
57
+ ## Contributing
58
+
59
+ Install PolarSSL from source via https://polarssl.org/download or install it using your operating system. For example:
60
+
61
+ On Ubuntu:
62
+
63
+ ```
64
+ sudo apt-get install libpolarssl-dev
65
+ ```
66
+
67
+ On Mac OS X with [Homebrew](http://mxcl.github.io/homebrew/):
68
+
69
+ ```
70
+ brew install polarssl
71
+ ```
72
+
73
+ The following steps and commands are followed during development:
74
+
75
+ 1. A branch is created.
76
+ 2. Tests are created in `test/` before code is written and ran with `rake test`. This rake task takes care of compiling the binary and executing the tests.
77
+ 3. Code is written.
78
+ 4. A pull request is created.
79
+ 5. CI runs and verifies passing tests of the Pull Request.
80
+ 6. The pull request is merged in.
81
+ 7. Repeat.
82
+
83
+ Tools used when developing:
84
+
85
+ * Travis CI (http://travis-ci.org)
86
+ * MiniTest (built into Ruby 1.9 or newer)
87
+ * GitHub
88
+
89
+ ## License
90
+
91
+ *Please note*: PolarSSL itself is released as GPL or a Commercial License.
92
+ You will need to take this into account when using PolarSSL and this Ruby extension in your
93
+ own software.
94
+
95
+ ```
96
+ polar-ssl-ruby - A Ruby extension for using PolarSSL.
97
+ Copyright (C) 2013 Michiel Sikkes
98
+
99
+ This program is free software: you can redistribute it and/or modify
100
+ it under the terms of the GNU Lesser General Public License as published by
101
+ the Free Software Foundation, either version 3 of the License, or
102
+ (at your option) any later version.
103
+
104
+ This program is distributed in the hope that it will be useful,
105
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
106
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
107
+ GNU Lesser General Public License for more details.
108
+
109
+ You should have received a copy of the GNU Lesser General Public License
110
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
111
+ ```
@@ -0,0 +1,37 @@
1
+ require 'rake/testtask'
2
+ require 'rake/extensiontask'
3
+ require 'rake/clean'
4
+ require 'sdoc'
5
+
6
+ NAME = "polarssl"
7
+ DLEXT = RbConfig::CONFIG['DLEXT']
8
+
9
+ CLEAN.include("ext/**/*{.o,.log,.#{DLEXT}}")
10
+ CLEAN.include("ext/**/Makefile")
11
+ CLEAN.include("doc/**")
12
+ CLOBBER.include("lib/**/*.#{DLEXT}")
13
+
14
+ Rake::TestTask.new do |t|
15
+ t.libs << "polarssl"
16
+ t.pattern = "test/*_test.rb"
17
+ end
18
+
19
+ task test: :compile
20
+
21
+ RDOC_FILES = FileList["RDOC_MAIN.rdoc", "ext/polarssl/*.c", "lib/**/*.rb"]
22
+
23
+ RDoc::Task.new do |rd|
24
+ rd.rdoc_dir = "doc"
25
+ rd.main = "RDOC_MAIN.rdoc"
26
+ rd.title = "PolarSSL Ruby API"
27
+ rd.rdoc_files.include(RDOC_FILES)
28
+ rd.options << '-e' << 'UTF-8'
29
+ rd.options << '-f' << 'sdoc'
30
+ rd.options << '-T' << 'sdoc'
31
+ end
32
+
33
+ Rake::ExtensionTask.new "polarssl" do |ext|
34
+ ext.lib_dir = "lib/polarssl"
35
+ end
36
+
37
+ task default: :test
@@ -0,0 +1,80 @@
1
+ /*
2
+ * Wrapping code for the PolarSSL::CtrDrbg class.
3
+ *
4
+ * Copyright (C) 2013 Michiel Sikkes
5
+ *
6
+ * This file is part of polarssl-ruby (http://github.com/michiels/polarssl-ruby)
7
+ *
8
+ * All rights reserved.
9
+ *
10
+ * This program is free software: you can redistribute it and/or modify
11
+ * it under the terms of the GNU Lesser General Public License as published by
12
+ * the Free Software Foundation, either version 3 of the License, or
13
+ * (at your option) any later version.
14
+ *
15
+ * This program is distributed in the hope that it will be useful,
16
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ * GNU Lesser General Public License for more details.
19
+ *
20
+ * You should have received a copy of the GNU Lesser General Public License
21
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
22
+ */
23
+
24
+ #include "polarssl.h"
25
+ #include "polarssl/ctr_drbg.h"
26
+ #include "polarssl/entropy.h"
27
+
28
+ static VALUE e_EntropySourceFailed;
29
+
30
+ static VALUE R_ctr_drbg_allocate();
31
+ static VALUE R_ctr_drbg_initialize();
32
+ static VALUE R_ctr_drbg_self_test();
33
+
34
+ void Init_ctr_drbg()
35
+ {
36
+ VALUE cCtrDrbg = rb_define_class_under( rb_mPolarSSL, "CtrDrbg", rb_cObject );
37
+
38
+ rb_define_singleton_method( cCtrDrbg, "self_test", R_ctr_drbg_self_test, 0 );
39
+
40
+ rb_define_alloc_func( cCtrDrbg, R_ctr_drbg_allocate );
41
+ rb_define_method( cCtrDrbg, "initialize", R_ctr_drbg_initialize, 1 );
42
+ }
43
+
44
+ static VALUE R_ctr_drbg_allocate( VALUE klass )
45
+ {
46
+ ctr_drbg_context *ctr_drbg;
47
+
48
+ return Data_Make_Struct( klass, ctr_drbg_context, 0, -1, ctr_drbg );
49
+ }
50
+
51
+ static VALUE R_ctr_drbg_initialize( VALUE self, VALUE entropy )
52
+ {
53
+ entropy_context *entropy_p;
54
+ ctr_drbg_context *ctr_drbg;
55
+ int ret;
56
+
57
+ Data_Get_Struct( self, ctr_drbg_context, ctr_drbg );
58
+ Data_Get_Struct( entropy, entropy_context, entropy_p );
59
+
60
+ ret = ctr_drbg_init( ctr_drbg, entropy_func, entropy_p, NULL, 0 );
61
+
62
+ if( ret == POLARSSL_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED )
63
+ rb_raise( e_EntropySourceFailed, "Could not initialize entropy source" );
64
+
65
+ return self;
66
+ }
67
+
68
+ static VALUE R_ctr_drbg_self_test( VALUE klass )
69
+ {
70
+ VALUE ret;
71
+
72
+ if ( ctr_drbg_self_test( 1 ) == 0 )
73
+ {
74
+ ret = Qtrue;
75
+ } else {
76
+ ret = Qfalse;
77
+ }
78
+
79
+ return ret;
80
+ }