Class: MyPKI::SSH
- Inherits:
-
Object
- Object
- MyPKI::SSH
- Includes:
- Configuration::Loader, Prompter
- Defined in:
- lib/mypki/loaders/ssh.rb
Instance Attribute Summary
Attributes included from Configuration::Loader
Instance Method Summary collapse
-
#initialize(options) ⇒ SSH
constructor
A new instance of SSH.
- #load(config) ⇒ Object
Methods included from Configuration::Loader
Methods included from Prompter
#file_prompt, #pass_prompt, #prompter
Constructor Details
#initialize(options) ⇒ SSH
Returns a new instance of SSH.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/mypki/loaders/ssh.rb', line 9 def initialize super if [:ssh] Prompter.send :alias_method, :original, :pass_prompt Prompter.send(:define_method, :pass_prompt) do |*a| [:password] = original *a end end end |
Instance Method Details
#load(config) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/mypki/loaders/ssh.rb', line 20 def load config if [:ssh] and Instance.cert and Instance.key ssh_path = File. '~/.ssh/' FileUtils.mkdir ssh_path unless File.exist? ssh_path FileUtils.chmod 0700, ssh_path key_path = File. '~/.ssh/id_rsa' pub_path = File. '~/.ssh/id_rsa.pub' = File. '~/.ssh/authorized_keys' if password = .delete(:password) pass = Shellwords.escape password result = `echo "#{Instance.key.to_pem}" | \ openssl pkcs8 -topk8 -out #{key_path} -v2 des3 -passout pass:#{pass} 2>&1` else result = `echo "#{Instance.key.to_pem}" | \ openssl pkcs8 -topk8 -out #{key_path} -v2 des3 -nocrypt 2>&1` end fail result unless result.empty? FileUtils.chmod 0600, key_path if password `ssh-keygen -f #{key_path} -y -P #{pass} > #{pub_path}` else `ssh-keygen -f #{key_path} -y > #{pub_path}` end FileUtils.cp pub_path, end end |