mbedtls 0.1.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +26 -0
- data/.ruby-version +1 -0
- data/.travis.yml +19 -0
- data/COPYING +674 -0
- data/COPYING.LESSER +171 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +24 -0
- data/RDOC_MAIN.rdoc +33 -0
- data/README.md +189 -0
- data/Rakefile +46 -0
- data/certs/michiels.pem +21 -0
- data/checksum/polarssl-1.0.1.gem.sha512 +1 -0
- data/ext/polarssl/cipher.c +360 -0
- data/ext/polarssl/cipher.h +1 -0
- data/ext/polarssl/ctr_drbg.c +80 -0
- data/ext/polarssl/ctr_drbg.h +1 -0
- data/ext/polarssl/entropy.c +72 -0
- data/ext/polarssl/entropy.h +1 -0
- data/ext/polarssl/extconf.rb +46 -0
- data/ext/polarssl/polarssl.c +41 -0
- data/ext/polarssl/polarssl.h +3 -0
- data/ext/polarssl/ssl.c +414 -0
- data/ext/polarssl/ssl.h +1 -0
- data/lib/.gitkeep +0 -0
- data/lib/polarssl.rb +2 -0
- data/lib/polarssl/version.rb +3 -0
- data/mbedtls.gemspec +23 -0
- data/polarssl-ruby.sublime-project +8 -0
- data/test/cipher_encryption_test.rb +40 -0
- data/test/ctr_drbg_test.rb +10 -0
- data/test/entropy_test.rb +14 -0
- data/test/ssl_connection_test.rb +41 -0
- data/test/test_helper.rb +2 -0
- metadata +82 -0
data/COPYING.LESSER
ADDED
@@ -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
data/Gemfile.lock
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
json (1.8.3)
|
5
|
+
minitest (5.7.0)
|
6
|
+
rake (10.0.4)
|
7
|
+
rake-compiler (0.9.1)
|
8
|
+
rake
|
9
|
+
rdoc (4.2.0)
|
10
|
+
sdoc (0.4.1)
|
11
|
+
json (~> 1.7, >= 1.7.7)
|
12
|
+
rdoc (~> 4.0)
|
13
|
+
|
14
|
+
PLATFORMS
|
15
|
+
ruby
|
16
|
+
|
17
|
+
DEPENDENCIES
|
18
|
+
minitest
|
19
|
+
rake
|
20
|
+
rake-compiler
|
21
|
+
sdoc
|
22
|
+
|
23
|
+
BUNDLED WITH
|
24
|
+
1.10.6
|
data/RDOC_MAIN.rdoc
ADDED
@@ -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
|
data/README.md
ADDED
@@ -0,0 +1,189 @@
|
|
1
|
+
PolarSSL for Ruby
|
2
|
+
=================
|
3
|
+
|
4
|
+
# IMPORTANT
|
5
|
+
|
6
|
+
This repository is a fork of [michiels/polarssl-ruby](https://github.com/michiels/polarssl-ruby) - it is being updated to reflect the new name of mbed TLS, and the changes that have occured over the last couple years since polarssl-ruby was last updated. For the moment, this repository should be seen as expirimental and unstable.
|
7
|
+
|
8
|
+
---------------------------
|
9
|
+
|
10
|
+
* API documentation: http://michiels.github.io/polarssl-ruby/doc
|
11
|
+
* RubyGems.org: http://rubygems.org/gems/polarssl
|
12
|
+
|
13
|
+
<table>
|
14
|
+
<tr>
|
15
|
+
<th>PolarSSL/mbed TLS version</th>
|
16
|
+
<th>Gem version</th>
|
17
|
+
</tr>
|
18
|
+
<tr>
|
19
|
+
<td><= 1.2.x</td><td>0.0.7</td>
|
20
|
+
</tr>
|
21
|
+
<tr>
|
22
|
+
<td>>= 1.3.0 and < 1.3.10</td><td>1.0.1</td>
|
23
|
+
</tr>
|
24
|
+
<tr>
|
25
|
+
<td>>= 1.3.10</td><td>1.0.2</td>
|
26
|
+
</tr>
|
27
|
+
</table>
|
28
|
+
|
29
|
+
## Description
|
30
|
+
|
31
|
+
With PolarSSL for Ruby, you can use SSL and cryptography functionality from PolarSSL in your Ruby programs.
|
32
|
+
|
33
|
+
## Features
|
34
|
+
|
35
|
+
* Encrypt/decrypt data.
|
36
|
+
* Set up encrypted SSL connections.
|
37
|
+
|
38
|
+
## Installation
|
39
|
+
|
40
|
+
PolarSSL is cryptographically signed. To be sure the gem you install hasn't been tampered with:
|
41
|
+
|
42
|
+
Add my public key as a trusted certificate:
|
43
|
+
|
44
|
+
|
45
|
+
```
|
46
|
+
gem cert --add <(curl -Ls https://raw.github.com/michiels/polarssl-ruby/master/certs/michiels.pem)
|
47
|
+
```
|
48
|
+
|
49
|
+
Then install the gem:
|
50
|
+
|
51
|
+
```
|
52
|
+
gem install polarssl -P HighSecurity
|
53
|
+
```
|
54
|
+
|
55
|
+
The `-P HighSecurity` will verify signed gems.
|
56
|
+
|
57
|
+
Or in your Gemfile:
|
58
|
+
|
59
|
+
```
|
60
|
+
gem "polarssl", "~> 1.0.2"
|
61
|
+
```
|
62
|
+
|
63
|
+
And install using:
|
64
|
+
|
65
|
+
```
|
66
|
+
bundle install --trust-policy HighSecurity
|
67
|
+
```
|
68
|
+
|
69
|
+
## Usage
|
70
|
+
|
71
|
+
### Setting up a SSL connection
|
72
|
+
|
73
|
+
This gem provides a pretty low level interface to the native PolarSSL C library.
|
74
|
+
The core API aims to reflect the PolarSSL library as much as possible. See the
|
75
|
+
[full API documentation](http://michiels.github.io/polarssl-ruby/doc/) for all classes and methods.
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
require 'polarssl'
|
79
|
+
|
80
|
+
socket = TCPSocket.new('polarssl', 443)
|
81
|
+
|
82
|
+
entropy = PolarSSL::Entropy.new
|
83
|
+
ctr_drbg = PolarSSL::CtrDrbg.new(entropy)
|
84
|
+
|
85
|
+
ssl = PolarSSL::SSL.new
|
86
|
+
ssl.set_endpoint(PolarSSL::SSL::SSL_IS_CLIENT)
|
87
|
+
ssl.set_authmode(PolarSSL::SSL::SSL_VERIFY_NONE)
|
88
|
+
ssl.set_rng(ctr_drbg)
|
89
|
+
ssl.set_socket(socket)
|
90
|
+
|
91
|
+
ssl.handshake
|
92
|
+
|
93
|
+
ssl.write("GET / HTTP/1.0\r\nHost: polarssl.org\r\n\r\n")
|
94
|
+
|
95
|
+
while chunk = ssl.read(1024)
|
96
|
+
response << chunk
|
97
|
+
end
|
98
|
+
|
99
|
+
puts response
|
100
|
+
|
101
|
+
ssl.close_notify
|
102
|
+
|
103
|
+
socket.close
|
104
|
+
|
105
|
+
ssl.close
|
106
|
+
```
|
107
|
+
|
108
|
+
### Encrypting data
|
109
|
+
|
110
|
+
The `PolarSSL::Cipher` class lets you encrypt data with a wide range of
|
111
|
+
encryption standards like AES, Blowfish and DES.
|
112
|
+
|
113
|
+
This sample encrypts a given plaintext with AES128 in CTR mode:
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
require 'polarssl'
|
117
|
+
require 'base64'
|
118
|
+
|
119
|
+
cipher = PolarSSL::Cipher.new("AES-128-CTR")
|
120
|
+
|
121
|
+
my_iv = SecureRandom.random_bytes(16)
|
122
|
+
|
123
|
+
cipher.set_iv(my_iv, 16)
|
124
|
+
cipher.setkey("my16bytekey23456", 128, PolarSSL::Cipher::OPERATION_ENCRYPT)
|
125
|
+
cipher.update("some secret message I want to keep")
|
126
|
+
encrypted_data = cipher.finish
|
127
|
+
|
128
|
+
encoded_encrypted_data = Base64.encode64(encrypted_data)
|
129
|
+
encoded_iv = Base64.encode64(my_iv)
|
130
|
+
```
|
131
|
+
|
132
|
+
See the documentation for the `Cipher` class in the [API documentation](http://michiels.github.io/polarssl-ruby/doc)
|
133
|
+
for all the available options.
|
134
|
+
|
135
|
+
## Contributing
|
136
|
+
|
137
|
+
Install PolarSSL from source via https://polarssl.org/download or install it using your operating system. For example:
|
138
|
+
|
139
|
+
On Ubuntu:
|
140
|
+
|
141
|
+
```
|
142
|
+
sudo apt-get install libpolarssl-dev
|
143
|
+
```
|
144
|
+
|
145
|
+
On Mac OS X with [Homebrew](http://mxcl.github.io/homebrew/):
|
146
|
+
|
147
|
+
```
|
148
|
+
brew install mbedtls
|
149
|
+
```
|
150
|
+
|
151
|
+
The following steps and commands are followed during development:
|
152
|
+
|
153
|
+
1. A branch is created.
|
154
|
+
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.
|
155
|
+
3. Code is written.
|
156
|
+
4. A pull request is created.
|
157
|
+
5. CI runs and verifies passing tests of the Pull Request.
|
158
|
+
6. The pull request is merged in.
|
159
|
+
7. Repeat.
|
160
|
+
|
161
|
+
Tools used when developing:
|
162
|
+
|
163
|
+
* Travis CI (http://travis-ci.org)
|
164
|
+
* MiniTest (built into Ruby 1.9 or newer)
|
165
|
+
* GitHub
|
166
|
+
|
167
|
+
## License
|
168
|
+
|
169
|
+
*Please note*: PolarSSL itself is released as GPL or a Commercial License.
|
170
|
+
You will need to take this into account when using PolarSSL and this Ruby extension in your
|
171
|
+
own software.
|
172
|
+
|
173
|
+
```
|
174
|
+
polar-ssl-ruby - A Ruby extension for using PolarSSL.
|
175
|
+
Copyright (C) 2013 Michiel Sikkes
|
176
|
+
|
177
|
+
This program is free software: you can redistribute it and/or modify
|
178
|
+
it under the terms of the GNU Lesser General Public License as published by
|
179
|
+
the Free Software Foundation, either version 3 of the License, or
|
180
|
+
(at your option) any later version.
|
181
|
+
|
182
|
+
This program is distributed in the hope that it will be useful,
|
183
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
184
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
185
|
+
GNU Lesser General Public License for more details.
|
186
|
+
|
187
|
+
You should have received a copy of the GNU Lesser General Public License
|
188
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
189
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
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.pattern = "test/*_test.rb"
|
16
|
+
t.libs << 'test'
|
17
|
+
end
|
18
|
+
|
19
|
+
task test: :compile
|
20
|
+
|
21
|
+
RDOC_FILES = FileList["RDOC_MAIN.rdoc", "lib/**/*.rb", "ext/polarssl/polarssl.c", "ext/polarssl/*.c"]
|
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
|
+
desc "Signs the gem"
|
38
|
+
task :sign_gem do
|
39
|
+
require 'digest/sha2'
|
40
|
+
built_gem_path = "polarssl-#{ENV["VERSION"]}.gem"
|
41
|
+
checksum = Digest::SHA512.new.hexdigest(File.read(built_gem_path))
|
42
|
+
checksum_path = "checksum/polarssl-#{ENV["VERSION"]}.gem.sha512"
|
43
|
+
File.open(checksum_path, 'w' ) {|f| f.write(checksum) }
|
44
|
+
end
|
45
|
+
|
46
|
+
task default: :test
|