Class: Watobo::Gui::ClientCertDialog::PEMFrame
- Inherits:
-
FXVerticalFrame
- Object
- FXVerticalFrame
- Watobo::Gui::ClientCertDialog::PEMFrame
- Defined in:
- lib/watobo/gui/client_cert_dialog.rb
Instance Method Summary collapse
- #cert ⇒ Object
-
#initialize(owner) ⇒ PEMFrame
constructor
A new instance of PEMFrame.
- #settings ⇒ Object
- #settings_valid? ⇒ Boolean
Constructor Details
#initialize(owner) ⇒ PEMFrame
Returns a new instance of PEMFrame.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/watobo/gui/client_cert_dialog.rb', line 85 def initialize(owner) @client_cert_dt = FXDataTarget.new('') @client_key_dt = FXDataTarget.new('') @password_dt = FXDataTarget.new('') @retype_dt = FXDataTarget.new('') super owner, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_RAISED matrix = FXMatrix.new(self, 3, :opts => MATRIX_BY_COLUMNS|LAYOUT_FILL_X|LAYOUT_FILL_Y) FXLabel.new(matrix, "Certificate File:", nil, LAYOUT_TOP|JUSTIFY_RIGHT) @client_cert_txt = FXTextField.new(matrix, 25, :target => @client_cert_dt, :selector => FXDataTarget::ID_VALUE, :opts => TEXTFIELD_NORMAL|LAYOUT_SIDE_RIGHT) FXButton.new(matrix, "Select").connect(SEL_COMMAND){ select_cert_file } FXLabel.new(matrix, "Key File:", nil, LAYOUT_TOP|JUSTIFY_RIGHT) @client_key_txt = FXTextField.new(matrix, 25, :target => @client_key_dt, :selector => FXDataTarget::ID_VALUE, :opts => TEXTFIELD_NORMAL|LAYOUT_SIDE_RIGHT) FXButton.new(matrix, "Select").connect(SEL_COMMAND){ select_key_file } # matrix = FXMatrix.new(main_frame, 2, :opts => MATRIX_BY_COLUMNS|LAYOUT_FILL_X|LAYOUT_FILL_Y) FXLabel.new(matrix, "Password:", nil, LAYOUT_TOP|JUSTIFY_RIGHT) @password_txt = FXTextField.new(matrix, 25, :target => @password_dt, :selector => FXDataTarget::ID_VALUE, :opts => TEXTFIELD_NORMAL|LAYOUT_SIDE_RIGHT|TEXTFIELD_PASSWD) FXButton.new(matrix, "", :opts=>FRAME_NONE).disable FXLabel.new(matrix, "Retype:", nil, LAYOUT_TOP|JUSTIFY_RIGHT) @retype_txt = FXTextField.new(matrix, 25, :target => @retype_dt, :selector => FXDataTarget::ID_VALUE, :opts => TEXTFIELD_NORMAL|LAYOUT_SIDE_RIGHT|TEXTFIELD_PASSWD) FXButton.new(matrix, "", :opts=>FRAME_NONE).disable end |
Instance Method Details
#cert ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/watobo/gui/client_cert_dialog.rb', line 27 def cert client_cert = {} begin if File.exist?(@client_cert_dt.value) client_cert[:ssl_client_cert] = OpenSSL::X509::Certificate.new(File.read(@client_cert_dt.value)) end if File.exist?(@client_key_dt.value) client_cert[:ssl_client_key] = OpenSSL::PKey::RSA.new(File.read(@client_key_dt.value), @password_dt.value) end return client_cert rescue => bang puts bang puts bang.backtrace end return nil end |
#settings ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/watobo/gui/client_cert_dialog.rb', line 47 def settings s = { :certificate_file => @client_cert_dt.value, :password => @password_dt.value, :key_file => @client_key_dt.value } end |
#settings_valid? ⇒ Boolean
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/watobo/gui/client_cert_dialog.rb', line 55 def settings_valid? unless @password_dt.value.empty? puts "* password is set" if @password_dt.value != @retype_dt.value FXMessageBox.information(self, MBOX_OK, "Passwords", "Passwords don't match!") return false end password = @password_dt.value end unless File.exist?(@client_cert_dt.value) FXMessageBox.information(self, MBOX_OK, "File not found", "#{@client_cert_dt.value} does not exist!") return false end unless File.exist?(@client_key_dt.value) FXMessageBox.information(self, MBOX_OK, "File not found", "#{@client_key_dt.value} does not exist!") return false end # last but not least check if private key can be accessed begin key = OpenSSL::PKey::RSA.new(File.open(@client_key_dt.value), password) rescue => bang FXMessageBox.information(self, MBOX_OK, "Wrong Password", "Could not open private key file. Wrong password?") return false end true end |