Class: Watobo::Gui::ClientCertDialog::PEMFrame

Inherits:
FXVerticalFrame
  • Object
show all
Defined in:
lib/watobo/gui/client_cert_dialog.rb

Instance Method Summary collapse

Constructor Details

#initialize(owner) ⇒ PEMFrame

Returns a new instance of PEMFrame.



73
74
75
76
77
78
79
80
81
82
83
84
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
# File 'lib/watobo/gui/client_cert_dialog.rb', line 73

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

#certObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/watobo/gui/client_cert_dialog.rb', line 15

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

#settingsObject



35
36
37
38
39
40
41
# File 'lib/watobo/gui/client_cert_dialog.rb', line 35

def settings
  s = {
    :certificate_file => @client_cert_dt.value,
    :password => @password_dt.value,
    :key_file => @client_key_dt.value
  }
end

#settings_valid?Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/watobo/gui/client_cert_dialog.rb', line 43

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