tem_openssl 0.3.2
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/CHANGELOG +11 -0
- data/LICENSE +21 -0
- data/Manifest +10 -0
- data/README +35 -0
- data/bin/openssl_tem +6 -0
- data/lib/ossl/executor.rb +118 -0
- data/lib/ossl/key.rb +55 -0
- data/lib/ossl/tem_tools.rb +124 -0
- data/lib/tem_openssl.rb +9 -0
- data/tem_openssl.gemspec +55 -0
- data/test/test_executor.rb +54 -0
- metadata +83 -0
data/CHANGELOG
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
v0.3.2. Updated to the API of tem_ruby 0.7.1 (Tem#pubek instead of an ugly hack).
|
2
|
+
|
3
|
+
v0.3.1. Updated to the API of tem_ruby 0.7.0.
|
4
|
+
|
5
|
+
v0.3. Implemented rsautl -sign and -verify to meet the openssl specs.
|
6
|
+
|
7
|
+
v0.2.1. Implemented public key exporting to PEM files. Requires public keys instead of the full key when possible. The TEM should not be needed when only public keys are required.
|
8
|
+
|
9
|
+
v0.2. Implemented signing.
|
10
|
+
|
11
|
+
v0.1. Initial release.
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2007 Massachusetts Institute of Technology
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/Manifest
ADDED
data/README
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
This is a tool for the TEM-based OpenSSL engine.
|
2
|
+
|
3
|
+
Running coverage tests:
|
4
|
+
gem install rcov
|
5
|
+
rcov -Ilib test/*.rb
|
6
|
+
|
7
|
+
Implemented commands (the format is supposed to be compatible with the "openssl" tool):
|
8
|
+
|
9
|
+
openssl_tem reset
|
10
|
+
Resets the TEM to a working state. The TEM applet is reinitialized, and the TEM is emitted.
|
11
|
+
All key material and state on TEM is lost.
|
12
|
+
|
13
|
+
openssl_tem rsagen 2048 -out key.temkey
|
14
|
+
Generates a RSA key pair on the TEM (the size is ignored), outputs the TEM-bound key pair to
|
15
|
+
"key.temkey".
|
16
|
+
|
17
|
+
openssl_tem rsa -in key.temkey -out key.pem -pubout
|
18
|
+
Extracts the public key from a TEM-bound key pair, outputs it in PEM format to "key.pem"
|
19
|
+
|
20
|
+
openssl_tem rsautl -encrypt -in plain.txt -inkey key.pem -out crypted.txt -pkcs
|
21
|
+
Encrypts the data in "plain.txt" using the PEM public key (or public key in a TEM-bound key pair)
|
22
|
+
in "key.pem". PKCS#1 padding is always used.
|
23
|
+
|
24
|
+
openssl_tem rsautl -decrypt -in crypted.txt -inkey key.temkey -out plain2.txt -pkcs
|
25
|
+
Decrypts the data in "crypted.txt" using TEM-bound key pair in "key.temkey".
|
26
|
+
PKCS#1 padding is always used.
|
27
|
+
|
28
|
+
openssl_tem rsautl -xsign -in plain.txt -inkey key.temkey -out signature.txt -pkcs
|
29
|
+
Signs the data in "plain.txt" using the TEM-bound key pair in "key.temkey".
|
30
|
+
PKCS#1 padding over a SHA-1 message digest of the data is always used.
|
31
|
+
|
32
|
+
openssl_tem rsautl -xverify -in signature.txt -inkey key.pem -indata plain.txt -out verif.txt -pkcs
|
33
|
+
Verifies that "signature.txt" was produced by signing the data in "plain.txt" using the
|
34
|
+
TEM-bound key with the PEM public key in "key.pem". PKCS#1 padding over a SHA-1 of the data is
|
35
|
+
always used. The output is "true" or "false".
|
data/bin/openssl_tem
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'pp'
|
2
|
+
|
3
|
+
class Tem::OpenSSL::Executor
|
4
|
+
def initialize(args, test_options)
|
5
|
+
@args = args
|
6
|
+
# unknown args get thrown here
|
7
|
+
@arg_bag = {}
|
8
|
+
# read key from here
|
9
|
+
@in_key = nil
|
10
|
+
# read (original) data from here
|
11
|
+
@in_data = nil
|
12
|
+
# read input from here
|
13
|
+
@in = $stdin
|
14
|
+
# dump output here
|
15
|
+
@out = $stdout
|
16
|
+
# run the procs here to clean up
|
17
|
+
@cleanup_procs = []
|
18
|
+
|
19
|
+
# hash of flags to help unit tests
|
20
|
+
@test_options = test_options
|
21
|
+
|
22
|
+
connect_to_tem
|
23
|
+
parse_args
|
24
|
+
end
|
25
|
+
|
26
|
+
def run
|
27
|
+
case @args[0]
|
28
|
+
when 'reset'
|
29
|
+
@tem.kill
|
30
|
+
@tem.activate
|
31
|
+
@tem.emit
|
32
|
+
when 'rsa'
|
33
|
+
if @arg_bag[:pubout]
|
34
|
+
@key = Tem::OpenSSL::Key.load_from_tkfile @in
|
35
|
+
@out.write @key.pub_key.ssl_key.to_s
|
36
|
+
end
|
37
|
+
when 'rsagen'
|
38
|
+
@key = Tem::OpenSSL::Key.new_tem_key @tem
|
39
|
+
@out.write @key.to_tkfile
|
40
|
+
when 'rsautl'
|
41
|
+
@key = Tem::OpenSSL::Key.load_from_tkfile @in_key
|
42
|
+
data = @in.read
|
43
|
+
case
|
44
|
+
when @arg_bag[:decrypt]
|
45
|
+
# decrypting with private key
|
46
|
+
result = @key.privk_decrypt data, @tem
|
47
|
+
when @arg_bag[:encrypt]
|
48
|
+
# encrypting with public key
|
49
|
+
result = @key.pub_key.encrypt data
|
50
|
+
when @arg_bag[:sign]
|
51
|
+
# fake-signing (encrypting with private key)
|
52
|
+
result = @key.privk_encrypt data, @tem
|
53
|
+
when @arg_bag[:verify]
|
54
|
+
# fake-verifying (decrypting with public key)
|
55
|
+
result = @key.pub_key.decrypt data
|
56
|
+
when @arg_bag[:xsign]
|
57
|
+
result = @key.privk_sign data, @tem
|
58
|
+
when @arg_bag[:xverify]
|
59
|
+
orig_data = @in_data.read
|
60
|
+
result = @key.pub_key.verify orig_data, data
|
61
|
+
else
|
62
|
+
# ?!
|
63
|
+
end
|
64
|
+
@out.write result
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def parse_args
|
69
|
+
0.upto(@args.length - 1) do |i|
|
70
|
+
# the tokens that don't start with - are processed OOB
|
71
|
+
next unless @args[i][0] == ?-
|
72
|
+
case @args[i]
|
73
|
+
when '-in'
|
74
|
+
@in = File.open(@args[i + 1], 'rb')
|
75
|
+
@cleanup_procs << Proc.new { @in.close }
|
76
|
+
when '-inkey'
|
77
|
+
@in_key = File.open(@args[i + 1], 'r')
|
78
|
+
@cleanup_procs << Proc.new { @in_key.close }
|
79
|
+
when '-indata'
|
80
|
+
@in_data = File.open(@args[i + 1], 'r')
|
81
|
+
@cleanup_procs << Proc.new { @in_data.close }
|
82
|
+
when '-out'
|
83
|
+
@out = File.open(@args[i + 1], 'wb')
|
84
|
+
@cleanup_procs << Proc.new { @out.close }
|
85
|
+
else
|
86
|
+
@arg_bag[@args[i][1..-1].to_sym] = true
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def cleanup
|
92
|
+
@cleanup_procs.each { |p| p.call }
|
93
|
+
end
|
94
|
+
|
95
|
+
def connect_to_tem
|
96
|
+
@terminal = Tem::SCard::JCOPRemoteTerminal.new
|
97
|
+
if !@terminal.connect or @test_options[:no_tem]
|
98
|
+
@terminal.disconnect
|
99
|
+
@terminal = Tem::SCard::PCSCTerminal.new
|
100
|
+
if !@terminal.connect or @test_options[:no_tem]
|
101
|
+
@terminal.disconnect
|
102
|
+
@terminal = nil
|
103
|
+
end
|
104
|
+
end
|
105
|
+
unless @terminal.nil?
|
106
|
+
@javacard = Tem::SCard::JavaCard.new(@terminal)
|
107
|
+
@tem = Tem::Session.new(@javacard)
|
108
|
+
|
109
|
+
@cleanup_procs << Proc.new { @tem.disconnect; @terminal.disconnect }
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def self.run(args, test_options = {})
|
114
|
+
ex = self.new args, test_options
|
115
|
+
ex.run
|
116
|
+
ex.cleanup
|
117
|
+
end
|
118
|
+
end
|
data/lib/ossl/key.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'pp'
|
2
|
+
|
3
|
+
class Tem::OpenSSL::Key
|
4
|
+
include Tem::OpenSSL::TemTools
|
5
|
+
|
6
|
+
attr_reader :pub_key
|
7
|
+
|
8
|
+
def initialize(pub_key, priv_decrypt_sec, priv_encrypt_sec, priv_sign_sec)
|
9
|
+
@pub_key = pub_key
|
10
|
+
@priv_decrypt_sec = priv_decrypt_sec
|
11
|
+
@priv_encrypt_sec = priv_encrypt_sec
|
12
|
+
@priv_sign_sec = priv_sign_sec
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_tkfile
|
16
|
+
@pub_key.ssl_key.to_s + [@priv_decrypt_sec.to_array, @priv_encrypt_sec.to_array, @priv_sign_sec.to_array].to_yaml
|
17
|
+
end
|
18
|
+
|
19
|
+
def privk_decrypt(data, tem)
|
20
|
+
Tem::OpenSSL::TemTools.crypt_with_sec(data, @priv_decrypt_sec, tem)
|
21
|
+
end
|
22
|
+
|
23
|
+
def privk_encrypt(data, tem)
|
24
|
+
Tem::OpenSSL::TemTools.crypt_with_sec(data, @priv_encrypt_sec, tem)
|
25
|
+
end
|
26
|
+
|
27
|
+
def privk_sign(data, tem)
|
28
|
+
Tem::OpenSSL::TemTools.sign_with_sec(data, @priv_sign_sec, tem)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.new_tem_key(tem)
|
32
|
+
keys = Tem::OpenSSL::TemTools.generate_key_on_tem(tem)
|
33
|
+
priv_decrypt_sec = Tem::OpenSSL::TemTools.crypting_sec(keys[:privk], tem, :decrypt)
|
34
|
+
priv_encrypt_sec = Tem::OpenSSL::TemTools.crypting_sec(keys[:privk], tem, :encrypt)
|
35
|
+
priv_sign_sec = Tem::OpenSSL::TemTools.signing_sec(keys[:privk], tem)
|
36
|
+
return self.new(keys[:pubk], priv_decrypt_sec, priv_encrypt_sec, priv_sign_sec)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.load_from_tkfile(f)
|
40
|
+
ossl_pub_key = OpenSSL::PKey::RSA.new(f)
|
41
|
+
pub_key = Tem::CryptoAbi::new_key_from_ssl(ossl_pub_key, true)
|
42
|
+
begin
|
43
|
+
ds_ary, es_ary, ss_ary = *YAML.load(f)
|
44
|
+
priv_decrypt_sec = Tem::SecPack.new_from_array(ds_ary)
|
45
|
+
priv_encrypt_sec = Tem::SecPack.new_from_array(es_ary)
|
46
|
+
priv_sign_sec = Tem::SecPack.new_from_array(ss_ary)
|
47
|
+
rescue
|
48
|
+
priv_decrypt_sec = nil
|
49
|
+
priv_encrypt_sec = nil
|
50
|
+
priv_sign_sec = nil
|
51
|
+
end
|
52
|
+
return self.new(pub_key, priv_decrypt_sec, priv_encrypt_sec, priv_sign_sec)
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
module Tem::OpenSSL::TemTools
|
2
|
+
# generate an RSA key pair on the TEM
|
3
|
+
# slower than OpenSSL-based generation, but uses a hardware RNG
|
4
|
+
def self.generate_key_on_tem(tem)
|
5
|
+
kdata = tem.tk_gen_key(:asymmetric)
|
6
|
+
pubk = tem.tk_read_key(kdata[:pubk_id], kdata[:authz])
|
7
|
+
tem.tk_delete_key(kdata[:pubk_id], kdata[:authz])
|
8
|
+
privk = tem.tk_read_key(kdata[:privk_id], kdata[:authz])
|
9
|
+
tem.tk_delete_key(kdata[:privk_id], kdata[:authz])
|
10
|
+
|
11
|
+
return {:privk => privk, :pubk => pubk}
|
12
|
+
end
|
13
|
+
|
14
|
+
# generates a SECpack that encrypts/decrypts a user-supplied blob
|
15
|
+
# the SECpack is tied down to a TEM
|
16
|
+
def self.crypting_sec(key, tem, mode = :decrypt)
|
17
|
+
crypt_sec = tem.assemble do |s|
|
18
|
+
# load the key in the TEM
|
19
|
+
s.ldwc :const => :key_data
|
20
|
+
s.rdk
|
21
|
+
# allocate the output buffer
|
22
|
+
s.ldwc :const => 512
|
23
|
+
s.outnew
|
24
|
+
# decrypt the given data
|
25
|
+
s.ldw :from => :input_length
|
26
|
+
s.ldwc :const => :input_data
|
27
|
+
s.ldwc :const => -1
|
28
|
+
s.send({:encrypt => :kevb, :decrypt => :kdvb}[mode])
|
29
|
+
s.halt
|
30
|
+
|
31
|
+
# key material
|
32
|
+
s.label :key_data
|
33
|
+
s.immed :ubyte, key.to_tem_key
|
34
|
+
|
35
|
+
# user-supplied argument: the length of the blob to be encrypted/decrypted
|
36
|
+
s.label :input_length
|
37
|
+
s.immed :ushort, 256
|
38
|
+
|
39
|
+
# user-supplied argument: the blob to be encrypted/decrypted
|
40
|
+
s.label :input_data
|
41
|
+
s.filler :ubyte, 512
|
42
|
+
|
43
|
+
# the TEM stack
|
44
|
+
s.label :sec_stack
|
45
|
+
s.stack
|
46
|
+
s.extra 8
|
47
|
+
end
|
48
|
+
crypt_sec.seal(tem.pubek, :key_data, :input_length)
|
49
|
+
return crypt_sec
|
50
|
+
end
|
51
|
+
|
52
|
+
# generates a SECpack that decrypts a user-supplied blob
|
53
|
+
# the SECpack is tied down to a TEM
|
54
|
+
def self.signing_sec(key, tem)
|
55
|
+
sign_sec = tem.assemble do |s|
|
56
|
+
# load the key in the TEM
|
57
|
+
s.ldwc :const => :key_data
|
58
|
+
s.rdk
|
59
|
+
# allocate the output buffer
|
60
|
+
s.ldwc :const => key.ssl_key.n.num_bytes + 1
|
61
|
+
s.outnew
|
62
|
+
# sign the given data
|
63
|
+
s.ldw :from => :input_length
|
64
|
+
s.ldwc :const => :input_data
|
65
|
+
s.ldwc :const => -1
|
66
|
+
s.ksvb
|
67
|
+
s.halt
|
68
|
+
|
69
|
+
# key material
|
70
|
+
s.label :key_data
|
71
|
+
s.immed :ubyte, key.to_tem_key
|
72
|
+
|
73
|
+
# user-supplied argument: the length of the blob to be signed
|
74
|
+
s.label :input_length
|
75
|
+
s.immed :ushort, 256
|
76
|
+
|
77
|
+
# user-supplied argument: the blob to be signed
|
78
|
+
s.label :input_data
|
79
|
+
s.filler :ubyte, 512
|
80
|
+
|
81
|
+
# the TEM stack
|
82
|
+
s.label :sec_stack
|
83
|
+
s.stack
|
84
|
+
s.extra 8
|
85
|
+
end
|
86
|
+
sign_sec.seal(tem.pubek, :key_data, :input_length)
|
87
|
+
return sign_sec
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
# encrypts/decrypts using a SECpack generated via a previous call to crypting_sec
|
92
|
+
def self.crypt_with_sec(encrypted_data, dec_sec, tem)
|
93
|
+
# convert the data string to an array of numbers
|
94
|
+
ed = encrypted_data.unpack('C*')
|
95
|
+
|
96
|
+
# patch the data and its length into the SEC
|
97
|
+
elen = tem.to_tem_ushort(ed.length)
|
98
|
+
dec_sec.body[dec_sec.label_address(:input_length), elen.length] = elen
|
99
|
+
dec_sec.body[dec_sec.label_address(:input_data), ed.length] = ed
|
100
|
+
|
101
|
+
# run the sec and convert its output to a string
|
102
|
+
dd = tem.execute dec_sec
|
103
|
+
decrypted_data = dd.pack('C*')
|
104
|
+
|
105
|
+
return decrypted_data
|
106
|
+
end
|
107
|
+
|
108
|
+
# signs using a SECpack generated via a previous call to signing_sec
|
109
|
+
def self.sign_with_sec(data, sign_sec, tem)
|
110
|
+
# convert the data string to an array of numbers
|
111
|
+
d = data.unpack('C*')
|
112
|
+
|
113
|
+
# patch the data and its length into the SEC
|
114
|
+
len = tem.to_tem_ushort(d.length)
|
115
|
+
sign_sec.body[sign_sec.label_address(:input_length), len.length] = len
|
116
|
+
sign_sec.body[sign_sec.label_address(:input_data), d.length] = d
|
117
|
+
|
118
|
+
# run the sec and convert its output to a string
|
119
|
+
s = tem.execute sign_sec
|
120
|
+
signature = s.pack('C*')
|
121
|
+
|
122
|
+
return signature
|
123
|
+
end
|
124
|
+
end
|
data/lib/tem_openssl.rb
ADDED
data/tem_openssl.gemspec
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
|
2
|
+
# Gem::Specification for Tem_openssl-0.3.2
|
3
|
+
# Originally generated by Echoe
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = %q{tem_openssl}
|
7
|
+
s.version = "0.3.2"
|
8
|
+
|
9
|
+
s.specification_version = 2 if s.respond_to? :specification_version=
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.authors = ["Victor Costan"]
|
13
|
+
s.date = %q{2008-06-11}
|
14
|
+
s.default_executable = %q{openssl_tem}
|
15
|
+
s.description = %q{TEM (Trusted Execution Module) engine for OpenSSL.}
|
16
|
+
s.email = %q{victor@costan.us}
|
17
|
+
s.executables = ["openssl_tem"]
|
18
|
+
s.extra_rdoc_files = ["bin/openssl_tem", "LICENSE", "lib/ossl/key.rb", "lib/ossl/executor.rb", "lib/ossl/tem_tools.rb", "lib/tem_openssl.rb", "README", "CHANGELOG"]
|
19
|
+
s.files = ["bin/openssl_tem", "Manifest", "LICENSE", "test/test_executor.rb", "lib/ossl/key.rb", "lib/ossl/executor.rb", "lib/ossl/tem_tools.rb", "lib/tem_openssl.rb", "README", "CHANGELOG", "tem_openssl.gemspec"]
|
20
|
+
s.has_rdoc = true
|
21
|
+
s.homepage = %q{http://tem.rubyforge.org}
|
22
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Tem_openssl", "--main", "README"]
|
23
|
+
s.require_paths = ["lib"]
|
24
|
+
s.rubyforge_project = %q{tem}
|
25
|
+
s.rubygems_version = %q{1.1.1}
|
26
|
+
s.summary = %q{TEM (Trusted Execution Module) engine for OpenSSL.}
|
27
|
+
s.test_files = ["test/test_executor.rb"]
|
28
|
+
|
29
|
+
s.add_dependency(%q<tem_ruby>, [">= 0.9.0"])
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
# # Original Rakefile source (requires the Echoe gem):
|
34
|
+
#
|
35
|
+
# require 'rubygems'
|
36
|
+
# gem 'echoe'
|
37
|
+
# require 'echoe'
|
38
|
+
#
|
39
|
+
# Echoe.new('tem_openssl') do |p|
|
40
|
+
# p.project = 'tem' # rubyforge project
|
41
|
+
#
|
42
|
+
# p.author = 'Victor Costan'
|
43
|
+
# p.email = 'victor@costan.us'
|
44
|
+
# p.summary = 'TEM (Trusted Execution Module) engine for OpenSSL.'
|
45
|
+
# p.url = 'http://tem.rubyforge.org'
|
46
|
+
# p.dependencies = ['tem_ruby >=0.9.0']
|
47
|
+
#
|
48
|
+
# p.need_tar_gz = false
|
49
|
+
# p.rdoc_pattern = /^(lib|bin|tasks|ext)|^BUILD|^README|^CHANGELOG|^TODO|^LICENSE|^COPYING$/
|
50
|
+
# end
|
51
|
+
#
|
52
|
+
# if $0 == __FILE__
|
53
|
+
# Rake.application = Rake::Application.new
|
54
|
+
# Rake.application.run
|
55
|
+
# end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'tem_openssl'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class ExecutorTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
Tem::OpenSSL::Executor.run ['reset']
|
7
|
+
|
8
|
+
# generate key and extract public key
|
9
|
+
Tem::OpenSSL::Executor.run ['rsagen', '2048', '-out', 'test_key.tkey']
|
10
|
+
Tem::OpenSSL::Executor.run ['rsa', '-in', 'test_key.tkey', '-out', 'test_key.pem', '-pubout'], :no_tem => true
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown
|
14
|
+
['test_key.tkey', 'test_key.pem'].each { |fname| File.delete fname }
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_encryption
|
18
|
+
# test encryption and decryption (using the PEM file for the public key)
|
19
|
+
plain_text = 'Simple encryption test.\n'
|
20
|
+
File.open('test_plain.txt', 'wb') { |f| f.write plain_text }
|
21
|
+
Tem::OpenSSL::Executor.run ['rsautl', '-encrypt', '-inkey', 'test_key.pem', '-in', 'test_plain.txt', '-pkcs', '-out', 'test_enc.txt'], :no_tem => true
|
22
|
+
Tem::OpenSSL::Executor.run ['rsautl', '-decrypt', '-inkey', 'test_key.tkey', '-in', 'test_enc.txt', '-pkcs', '-out', 'test_plain2.txt']
|
23
|
+
assert_equal plain_text, File.open('test_plain2.txt', 'rb') { |f| f.read }, 'data corruption in encryption/decryption'
|
24
|
+
['test_plain.txt', 'test_plain2.txt', 'test_enc.txt'].each { |fname| File.delete fname }
|
25
|
+
|
26
|
+
# test encryption and decryption (using the TEM-bound file for the public key)
|
27
|
+
plain_text = 'Simple encryption test.\n'
|
28
|
+
File.open('test_plain.txt', 'wb') { |f| f.write plain_text }
|
29
|
+
Tem::OpenSSL::Executor.run ['rsautl', '-encrypt', '-inkey', 'test_key.tkey', '-in', 'test_plain.txt', '-pkcs', '-out', 'test_enc.txt']
|
30
|
+
Tem::OpenSSL::Executor.run ['rsautl', '-decrypt', '-inkey', 'test_key.tkey', '-in', 'test_enc.txt', '-pkcs', '-out', 'test_plain2.txt']
|
31
|
+
assert_equal plain_text, File.open('test_plain2.txt', 'rb') { |f| f.read }, 'data corruption in encryption/decryption'
|
32
|
+
['test_plain.txt', 'test_plain2.txt', 'test_enc.txt'].each { |fname| File.delete fname }
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_fake_signing
|
36
|
+
# test fake (openssl-compatible) signing
|
37
|
+
plain_text = 'Simple fake-signing test.\n'
|
38
|
+
File.open('test_plain.txt', 'wb') { |f| f.write plain_text }
|
39
|
+
Tem::OpenSSL::Executor.run ['rsautl', '-sign', '-inkey', 'test_key.tkey', '-in', 'test_plain.txt', '-pkcs', '-out', 'test_fsign.txt']
|
40
|
+
Tem::OpenSSL::Executor.run ['rsautl', '-verify', '-inkey', 'test_key.pem', '-in', 'test_fsign.txt', '-pkcs', '-out', 'test_fverify.txt']
|
41
|
+
assert_equal plain_text, File.open('test_fverify.txt', 'rb') { |f| f.read }, 'data corruption in fake-sign/verification'
|
42
|
+
['test_plain.txt', 'test_fsign.txt', 'test_fverify.txt'].each { |fname| File.delete fname }
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_xsigning
|
46
|
+
# test proper signing (using the PEM file for the public key)
|
47
|
+
plain_text = 'Simple signing test.\n'
|
48
|
+
File.open('test_plain.txt', 'wb') { |f| f.write plain_text }
|
49
|
+
Tem::OpenSSL::Executor.run ['rsautl', '-xsign', '-inkey', 'test_key.tkey', '-in', 'test_plain.txt', '-pkcs', '-out', 'test_sign.txt']
|
50
|
+
Tem::OpenSSL::Executor.run ['rsautl', '-xverify', '-inkey', 'test_key.pem', '-in', 'test_sign.txt', '-indata', 'test_plain.txt', '-pkcs', '-out', 'test_verify.txt'], :no_tem => true
|
51
|
+
assert_equal "true", File.open('test_verify.txt', 'rb') { |f| f.read }, 'data corruption in sign/verification'
|
52
|
+
['test_plain.txt', 'test_sign.txt', 'test_verify.txt'].each { |fname| File.delete fname }
|
53
|
+
end
|
54
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tem_openssl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Victor Costan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-06-11 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: tem_ruby
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.9.0
|
23
|
+
version:
|
24
|
+
description: TEM (Trusted Execution Module) engine for OpenSSL.
|
25
|
+
email: victor@costan.us
|
26
|
+
executables:
|
27
|
+
- openssl_tem
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files:
|
31
|
+
- bin/openssl_tem
|
32
|
+
- LICENSE
|
33
|
+
- lib/ossl/key.rb
|
34
|
+
- lib/ossl/executor.rb
|
35
|
+
- lib/ossl/tem_tools.rb
|
36
|
+
- lib/tem_openssl.rb
|
37
|
+
- README
|
38
|
+
- CHANGELOG
|
39
|
+
files:
|
40
|
+
- bin/openssl_tem
|
41
|
+
- Manifest
|
42
|
+
- LICENSE
|
43
|
+
- test/test_executor.rb
|
44
|
+
- lib/ossl/key.rb
|
45
|
+
- lib/ossl/executor.rb
|
46
|
+
- lib/ossl/tem_tools.rb
|
47
|
+
- lib/tem_openssl.rb
|
48
|
+
- README
|
49
|
+
- CHANGELOG
|
50
|
+
- tem_openssl.gemspec
|
51
|
+
has_rdoc: true
|
52
|
+
homepage: http://tem.rubyforge.org
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options:
|
55
|
+
- --line-numbers
|
56
|
+
- --inline-source
|
57
|
+
- --title
|
58
|
+
- Tem_openssl
|
59
|
+
- --main
|
60
|
+
- README
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
version:
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: "0"
|
74
|
+
version:
|
75
|
+
requirements: []
|
76
|
+
|
77
|
+
rubyforge_project: tem
|
78
|
+
rubygems_version: 1.1.1
|
79
|
+
signing_key:
|
80
|
+
specification_version: 2
|
81
|
+
summary: TEM (Trusted Execution Module) engine for OpenSSL.
|
82
|
+
test_files:
|
83
|
+
- test/test_executor.rb
|