Class: Touchpass::KeyFileCreator
- Inherits:
-
Object
- Object
- Touchpass::KeyFileCreator
- Defined in:
- lib/touchpass/key_file_creator.rb
Overview
Used to help with creation of public / private key files for a device (by clients)
Constant Summary collapse
- DEFAULT_KEYS_PATH =
File.join(ENV['HOME'], ".touchpass", "certs")
- PRIVATE_KEY =
"private.pem"
- PUBLIC_KEY =
"public.pem"
Class Attribute Summary collapse
-
.keys_path ⇒ Object
Returns the value of attribute keys_path.
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#private_key ⇒ Object
Returns the value of attribute private_key.
-
#public_key ⇒ Object
Returns the value of attribute public_key.
Instance Method Summary collapse
-
#generate_keys ⇒ Object
Use openssl command to generate key pair.
-
#initialize(id) ⇒ KeyFileCreator
constructor
A new instance of KeyFileCreator.
- #keys_path ⇒ Object
- #private_key_path ⇒ Object
- #public_key_path ⇒ Object
- #public_key_text ⇒ Object
- #read_key(pem_file) ⇒ Object
Constructor Details
#initialize(id) ⇒ KeyFileCreator
Returns a new instance of KeyFileCreator.
17 18 19 |
# File 'lib/touchpass/key_file_creator.rb', line 17 def initialize(id) @id = id.to_s end |
Class Attribute Details
.keys_path ⇒ Object
Returns the value of attribute keys_path.
12 13 14 |
# File 'lib/touchpass/key_file_creator.rb', line 12 def keys_path @keys_path end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
15 16 17 |
# File 'lib/touchpass/key_file_creator.rb', line 15 def id @id end |
#private_key ⇒ Object
Returns the value of attribute private_key.
15 16 17 |
# File 'lib/touchpass/key_file_creator.rb', line 15 def private_key @private_key end |
#public_key ⇒ Object
Returns the value of attribute public_key.
15 16 17 |
# File 'lib/touchpass/key_file_creator.rb', line 15 def public_key @public_key end |
Instance Method Details
#generate_keys ⇒ Object
Use openssl command to generate key pair. RSA public key PEM generated by Ruby’s OpenSSL::PKey::RSA are unreadable by OpenSSL. See: barelyenough.org/blog/2008/04/fun-with-public-keys/
24 25 26 27 28 29 |
# File 'lib/touchpass/key_file_creator.rb', line 24 def generate_keys directory = keys_path prepare_directories directory `openssl genrsa -out #{directory}/#{PRIVATE_KEY} 1024 > /dev/null 2>&1` `openssl rsa -in #{directory}/#{PRIVATE_KEY} -out #{directory}/#{PUBLIC_KEY} -outform PEM -pubout > /dev/null 2>&1` end |
#keys_path ⇒ Object
48 49 50 |
# File 'lib/touchpass/key_file_creator.rb', line 48 def keys_path File.join(self.class.keys_path, @id) end |
#private_key_path ⇒ Object
56 57 58 |
# File 'lib/touchpass/key_file_creator.rb', line 56 def private_key_path return File.join(keys_path, PRIVATE_KEY) end |
#public_key_path ⇒ Object
52 53 54 |
# File 'lib/touchpass/key_file_creator.rb', line 52 def public_key_path return File.join(keys_path, PUBLIC_KEY) end |
#public_key_text ⇒ Object
40 41 42 |
# File 'lib/touchpass/key_file_creator.rb', line 40 def public_key_text return File.read(public_key_path) end |
#read_key(pem_file) ⇒ Object
44 45 46 |
# File 'lib/touchpass/key_file_creator.rb', line 44 def read_key(pem_file) return OpenSSL::PKey::RSA.new(File.read(pem_file)) end |