Class: Foxbat::Security
- Inherits:
-
Object
- Object
- Foxbat::Security
- Defined in:
- lib/foxbat/security.rb
Class Method Summary collapse
- .create_ssl_engine(context, client = false) ⇒ Object
- .setup_keystore(path) ⇒ Object
- .setup_ssl_client_context ⇒ Object
- .setup_ssl_context(keystore_path) ⇒ Object
Class Method Details
.create_ssl_engine(context, client = false) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/foxbat/security.rb', line 52 def self.create_ssl_engine(context, client=false) engine = context.createSSLEngine engine.setUseClientMode(client) engine.setNeedClientAuth(false) engine end |
.setup_keystore(path) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/foxbat/security.rb', line 11 def self.setup_keystore(path) keystore = KeyStore.getInstance(KeyStore.getDefaultType) fis = FileInputStream.new(path) puts 'Enter passphrase for keystore:' password = java.lang.System.console.readPassword begin keystore.load(fis, password) rescue IOException puts 'Invalid passphrase.' fis.close return setup_keystore(path) end fis.close algorithm = KeyManagerFactory.getDefaultAlgorithm kmf = KeyManagerFactory.getInstance(algorithm) tmf = TrustManagerFactory.getInstance(algorithm) kmf.init(keystore, password) tmf.init(keystore) password = nil # Paranoid, per the JavaDoc puts 'Keystore successfully loaded.' [kmf, tmf] end |
.setup_ssl_client_context ⇒ Object
48 49 50 |
# File 'lib/foxbat/security.rb', line 48 def self.setup_ssl_client_context SSLContext.getDefault end |
.setup_ssl_context(keystore_path) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/foxbat/security.rb', line 41 def self.setup_ssl_context(keystore_path) context = SSLContext.getInstance('TLSv1') kmf, tmf = setup_keystore(keystore_path) context.init(kmf.getKeyManagers, tmf.getTrustManagers, nil) context end |