Class: Foxbat::Security
- Inherits:
-
Object
- Object
- Foxbat::Security
- Defined in:
- lib/foxbat/security.rb
Class Method Summary collapse
- .create_ssl_engine(context) ⇒ Object
- .setup_keystore(path) ⇒ Object
- .setup_ssl_context(keystore_path) ⇒ Object
Class Method Details
.create_ssl_engine(context) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/foxbat/security.rb', line 47 def self.create_ssl_engine(context) engine = context.createSSLEngine engine.setUseClientMode(false) 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 |
# 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 kmf = KeyManagerFactory.getInstance('SunX509') tmf = TrustManagerFactory.getInstance('SunX509') kmf.init(keystore, password) tmf.init(keystore) password = nil # Paranoid, per the JavaDoc puts 'Keystore successfully loaded.' [kmf, tmf] end |
.setup_ssl_context(keystore_path) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/foxbat/security.rb', line 40 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 |