aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2012-12-12 23:04:05 -0800
committerelijah <elijah@riseup.net>2012-12-12 23:04:05 -0800
commit32f00970fd6e5dbae3772f7f854b425098d94098 (patch)
tree954561f544588c188b43b99b4b2d070e44f9aef5 /lib
parent6e5d404bdd1a8f56fdfb0eee865f9029ae12b616 (diff)
downloadleap_cli-32f00970fd6e5dbae3772f7f854b425098d94098.tar.gz
leap_cli-32f00970fd6e5dbae3772f7f854b425098d94098.tar.bz2
added `leap inspect`
Diffstat (limited to 'lib')
-rw-r--r--lib/leap_cli/commands/inspect.rb65
1 files changed, 65 insertions, 0 deletions
diff --git a/lib/leap_cli/commands/inspect.rb b/lib/leap_cli/commands/inspect.rb
new file mode 100644
index 0000000..025d244
--- /dev/null
+++ b/lib/leap_cli/commands/inspect.rb
@@ -0,0 +1,65 @@
+module LeapCli; module Commands
+
+ desc 'Prints information about a file or node.'
+ command :inspect do |c|
+ c.action do |global_options,options,args|
+ object = args.first
+ method = inspection_method(object)
+ if method && defined?(method)
+ self.send(method, object, options)
+ else
+ log "Sorry, I don't know how to inspect that."
+ end
+ end
+ end
+
+ private
+
+ FTYPE_MAP = {
+ "PEM certificate" => :inspect_x509_cert,
+ "PEM RSA private key" => :inspect_x509_key,
+ "OpenSSH RSA public key" => :inspect_ssh_pub_key,
+ "PEM certificate request" => :inspect_x509_csr
+ }
+
+ def inspection_method(object)
+ if File.exists?(object)
+ ftype = `file #{object}`.split(':').last.strip
+ log 2, "file is of type '#{ftype}'"
+ if FTYPE_MAP[ftype]
+ FTYPE_MAP[ftype]
+ elsif ftype == "ASCII text"
+ nil
+ end
+ elsif manager.nodes[object]
+ :inspect_node
+ else
+ nil
+ end
+ end
+
+ def inspect_x509_key(file_path, options)
+ assert_bin! 'openssl'
+ puts assert_run! 'openssl rsa -in %s -text -check' % file_path
+ end
+
+ def inspect_x509_cert(file_path, options)
+ assert_bin! 'openssl'
+ puts assert_run! 'openssl x509 -in %s -text -noout' % file_path
+ log 0, :"SHA256 fingerprint", X509.fingerprint("SHA256", file_path)
+ end
+
+ def inspect_x509_csr(file_path, options)
+ assert_bin! 'openssl'
+ puts assert_run! 'openssl req -text -noout -verify -in %s' % file_path
+ end
+
+ #def inspect_ssh_pub_key(file_path)
+ #end
+
+ def inspect_node(node_name, options)
+ node = manager.nodes[node_name]
+ puts node.dump_json
+ end
+
+end; end