Class: Watobo::Gui::ClientCertDialog::PKCS12Frame
- Inherits:
-
FXVerticalFrame
- Object
- FXVerticalFrame
- Watobo::Gui::ClientCertDialog::PKCS12Frame
- Defined in:
- lib/watobo/gui/client_cert_dialog.rb
Instance Method Summary collapse
- #cert ⇒ Object
-
#initialize(owner) ⇒ PKCS12Frame
constructor
A new instance of PKCS12Frame.
- #settings ⇒ Object
- #settings_valid? ⇒ Boolean
- #update_fields(c) ⇒ Object
Constructor Details
#initialize(owner) ⇒ PKCS12Frame
Returns a new instance of PKCS12Frame.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/watobo/gui/client_cert_dialog.rb', line 217 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, "PKCS12 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, "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
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/watobo/gui/client_cert_dialog.rb', line 152 def cert client_cert = {} password = @password_dt.value begin if File.exist?(@client_cert_dt.value) p12_data = nil File.open(@client_cert_dt.value, "rb") { |fh| p12_data = fh.read } p12 = OpenSSL::PKCS12.new(p12_data, password) client_cert[:ssl_client_cert] = p12.certificate client_cert[:ssl_client_key] = p12.key client_cert[:extra_chain_certs] = p12.ca_certs client_cert[:certificate_file] = @client_cert_dt.value client_cert[:password] = password client_cert[:type] = :pkcs12 end return client_cert rescue => bang puts bang puts bang.backtrace end return nil end |
#settings ⇒ Object
210 211 212 213 214 215 |
# File 'lib/watobo/gui/client_cert_dialog.rb', line 210 def settings s = { :certificate_file => @client_cert_dt.value, :password => @password_dt.value } end |
#settings_valid? ⇒ Boolean
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/watobo/gui/client_cert_dialog.rb', line 192 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 true end |
#update_fields(c) ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/watobo/gui/client_cert_dialog.rb', line 180 def update_fields(c) unless c.nil? @client_cert_dt.value = c[:certificate_file] @cert_path = File.dirname(c[:certificate_file]) + '/' @password_dt.value = c[:password].nil? ? '' : c[:password] @retype_dt.value = c[:password].nil? ? '' : c[:password] @client_cert_txt.handle(self, FXSEL(SEL_UPDATE, 0), nil) @password_txt.handle(self, FXSEL(SEL_UPDATE, 0), nil) @retype_txt.handle(self, FXSEL(SEL_UPDATE, 0), nil) end end |