Class: Yast::SignatureCheckDialogsClass

Inherits:
Module
  • Object
show all
Defined in:
../../src/modules/SignatureCheckDialogs.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) CheckSignatures

A semi-public helper. Convert the kernel parameter to the sysconfig string

Returns:

  • sysconfig value: yes, yast, no



246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File '../../src/modules/SignatureCheckDialogs.rb', line 246

def CheckSignatures
  cmdline = Linuxrc.InstallInf("Cmdline")
  Builtins.y2milestone("Cmdline: %1", cmdline)

  val = Builtins.regexpsub(
    cmdline,
    "CHECK_SIGNATURES=([[:alpha:]]+)",
    "\\1"
  )
  if val.nil?
    val = Builtins.regexpsub(cmdline, "no_sig_check=([^[:digit:]]+)", "\\1")
    if !val.nil?
      trans = { "0" => "yes", "1" => "yast", "2" => "no" }
      val = Ops.get(trans, val)
    end
  end
  val = "yes" if val.nil?
  val
end

- (Object) CheckSignaturesInYaST

Should signatures be checked at all? Check a sysconfig variable (or a kernel parameter for the 1st installation stage).

Returns:

  • do checking?



269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File '../../src/modules/SignatureCheckDialogs.rb', line 269

def CheckSignaturesInYaST
  if @check_signatures.nil?
    chs = nil
    if Stage.initial
      chs = CheckSignatures()
    else
      # default is "yes"
      chs = Convert.to_string(
        SCR.Read(path(".sysconfig.security.CHECK_SIGNATURES"))
      )
    end
    Builtins.y2milestone("CHECK_SIGNATURES: %1", chs)
    @check_signatures = chs != "no"
  end
  @check_signatures
end

- (Object) GetDefaultDialogReturn(popup_type, popup_url)

Function returns the default popup return value for case when user selected “don't show again”

Parameters:

  • popup_type (String)

    dialog type



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File '../../src/modules/SignatureCheckDialogs.rb', line 188

def GetDefaultDialogReturn(popup_type, popup_url)
  if popup_type.nil?
    Builtins.y2error("popup_type %1 mustn't be nil!", popup_type)
    return false
  end

  stored_return = Convert.to_boolean(
    DontShowAgain.GetDefaultReturn(

      "q_type"  => "inst-source",
      "q_ident" => popup_type,
      "q_url"   => popup_url

    )
  )

  Builtins.y2milestone(
    "User decided not to show popup for '%1' again, returning user-decision '%2'",
    popup_type,
    stored_return
  )
  stored_return
end

- (Boolean) GetShowThisPopup(popup_type, popup_url)

Function returns whether user want's to show the dialog (again). true is the default if nothing is set.

Parameters:

  • popup_type (String)

    dialog type

  • popup_url (String)

    if any

Returns:

  • (Boolean)

    show the dialog



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File '../../src/modules/SignatureCheckDialogs.rb', line 127

def GetShowThisPopup(popup_type, popup_url)
  if popup_type.nil?
    Builtins.y2error("popup_type %1 mustn't be nil!", popup_type)
    return true
  end

  # Read the current configuration from system configuration
  stored = DontShowAgain.GetShowQuestionAgain(

    "q_type"  => "inst-source",
    "q_ident" => popup_type,
    "q_url"   => popup_url

  )

  # Stored in the configuration
  if !stored.nil?
    return stored
  else
    # Unknown status, return default
    return true
  end
end

- (Object) GPGKeyAsString(key)



614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
# File '../../src/modules/SignatureCheckDialogs.rb', line 614

def GPGKeyAsString(key)
  key = deep_copy(key)
  # Part of the GnuPG key description in popup, %1 is a GnuPG key ID
  Ops.add(
    Ops.add(
      Ops.add(
        Ops.add(
          Ops.add(
            Builtins.sformat(_("ID: %1"), Ops.get_string(key, "id", "")),
            "\n"
          ),
          if Ops.get_string(key, "fingerprint", "").nil? ||
            Ops.get_string(key, "fingerprint", "") == ""
            # Part of the GnuPG key description in popup, %1 is a GnuPG key fingerprint
            ""
          else
            Builtins.sformat(
              _("Fingerprint: %1") + "\n",
              StringSplitter(Ops.get_string(key, "fingerprint", ""), " ", 4)
            )
          end
        ),
        # Part of the GnuPG key description in popup, %1 is a GnuPG key name
        Builtins.sformat(_("Name: %1"), Ops.get_string(key, "name", ""))
      ),
      if Ops.get_string(key, "created", "") != ""
        Ops.add(
          "\n",
          Builtins.sformat(
            _("Created: %1"),
            Ops.get_string(key, "created", "")
          )
        )
      else
        ""
      end
    ),
    if Ops.get_string(key, "expires", "") != ""
      Ops.add(
        "\n",
        Builtins.sformat(
          _("Expires: %1"),
          Ops.get_string(key, "expires", "")
        )
      )
    else
      ""
    end
  )
end

- (Object) GPGKeyAsTerm(key)



665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
# File '../../src/modules/SignatureCheckDialogs.rb', line 665

def GPGKeyAsTerm(key)
  key = deep_copy(key)
  rt = Ops.add(
    # GPG key property
    Builtins.sformat(
      "<b>%1</b>%2",
      _("ID: "),
      Ops.get_string(key, "id", "")
    ),
    # GPG key property
    Builtins.sformat(
      "<br><b>%1</b>%2",
      _("Name: "),
      Ops.get_string(key, "name", "")
    )
  )
  if Ops.greater_than(
    Builtins.size(Ops.get_string(key, "fingerprint", "")),
    0
    )
    # GPG key property
    rt = Ops.add(
      rt,
      Builtins.sformat(
        "<br><b>%1</b>%2",
        _("Fingerprint: "),
        StringSplitter(Ops.get_string(key, "fingerprint", ""), " ", 4)
      )
    )
  end
  if Ops.greater_than(Builtins.size(Ops.get_string(key, "created", "")), 0)
    # GPG key property
    rt = Ops.add(
      rt,
      Builtins.sformat(
        "<br><b>%1</b>%2",
        _("Created: "),
        Ops.get_string(key, "created", "")
      )
    )
  end
  if Ops.greater_than(Builtins.size(Ops.get_string(key, "expires", "")), 0)
    # GPG key property
    rt = Ops.add(
      rt,
      Builtins.sformat(
        "<br><b>%1</b>%2",
        _("Expires: "),
        Ops.get_string(key, "expires", "")
      )
    )
  end
  RichText(rt)
end

- (Object) HandleDoNotShowDialogAgain(default_return, dont_show_dialog_ident, dont_show_dialog_checkboxid, dont_show_url)



212
213
214
215
216
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
# File '../../src/modules/SignatureCheckDialogs.rb', line 212

def HandleDoNotShowDialogAgain(default_return, dont_show_dialog_ident, dont_show_dialog_checkboxid, dont_show_url)
  dont_show_status = Convert.to_boolean(
    UI.QueryWidget(Id(dont_show_dialog_checkboxid), :Value)
  )
  # Widget doesn't exist
  if dont_show_status.nil?
    Builtins.y2warning(
      "No such UI widget with ID: %1",
      dont_show_dialog_checkboxid
    )
    # Checkbox selected -> Don't show again
  elsif dont_show_status == true
    Builtins.y2debug(
      "User decision -- don't show the dialog %1 again, setting default return %2",
      dont_show_dialog_ident,
      default_return
    )
    SetShowThisPopup(dont_show_dialog_ident, false, dont_show_url)
    SetDefaultDialogReturn(
      dont_show_dialog_ident,
      default_return,
      dont_show_url
    )
    # Checkbox not selected -> Show again
  else
    SetShowThisPopup(dont_show_dialog_ident, true, dont_show_url)
  end

  nil
end

- (Boolean) ImportGPGKeyIntoTrustedDialog(key, repository)

ImportUntrustedGPGKeyIntoTrustedDialog

Parameters:

  • string

    key_id

  • string

    key_name

  • string

    fingerprint

Returns:

  • (Boolean)

    whether zypp should import the key into the keyring of trusted keys



970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
# File '../../src/modules/SignatureCheckDialogs.rb', line 970

def ImportGPGKeyIntoTrustedDialog(key, repository)
  key = deep_copy(key)
  # additional Richtext (HTML) warning text (kind of help), 1/2
  warning_text = _(
    "<p>The owner of the key may distribute updates,\n" \
      "packages, and package repositories that your system will trust and offer\n" \
      "for installation and update without any further warning. In this way,\n" \
      "importing the key into your keyring of trusted keys allows the key owner\n" \
      "to have a certain amount of control over the software on your system.</p>"
  ) +
    # additional Richtext (HTML) warning text (kind of help), 2/2
    _(
      "<p>A warning dialog opens for every package that\n" \
        "is not signed by a trusted (imported) key. If you do not trust the key,\n" \
        "the packages or repositories created by the owner of the key will not be used.</p>"
    )

  repo = Pkg.SourceGeneralData(repository)

  # popup message - label, part 1, %1 stands for repository name, %2 for its URL
  dialog_text = Builtins.sformat(
    _(
      "The following GnuPG key has been found in repository\n" \
        "%1\n" \
        "(%2):"
    ),
    Ops.get_locale(repo, "name", _("Unknown")),
    repo && repo["url"] ? repo["url"].scan(/.{1,59}/).join("\n") :
      _("Unknown")
  )

  # popup message - label, part 2
  dialog_text2 = _(
    "You can choose to import it into your keyring of trusted\n" \
      "public keys, meaning that you trust the owner of the key.\n" \
      "You should be sure that you can trust the owner and that\n" \
      "the key really belongs to that owner before importing it."
  )

  expires = Ops.get_integer(key, "expires_raw", 0)
  if Ops.greater_than(expires, 0) &&
      Ops.greater_than(Builtins.time, expires)
    # warning label - the key to import is expired
    dialog_text2 = Ops.add(
      Ops.add(Builtins.sformat(_("WARNING: The key has expired!")), "\n\n"),
      dialog_text2
    )
  end

  displayinfo = UI.GetDisplayInfo
  # hide additional help text in not enough wide terminals so
  # the important GPG key properties are completely displayed
  hide_help = Ops.get_boolean(displayinfo, "TextMode", false) &&
    Ops.less_than(Ops.get_integer(displayinfo, "Width", 80), 105)

  UI.OpenDialog(
    Opt(:decorated),
    HBox(
      # left-side help
      if hide_help
        Empty()
      else
        HWeight(3, VBox(RichText(warning_text)))
      end,
      HSpacing(1.5),
      # dialog
      HWeight(
        5,
        VBox(
          HBox(
            VCenter(MessageIcon("question")),
            # popup heading
            VCenter(Heading(_("Import Untrusted GnuPG Key"))),
            HStretch()
          ),
          # dialog message
          MarginBox(
            0.4,
            0.4,
            VBox(
              Left(Label(dialog_text)),
              GPGKeyAsTerm(key),
              Left(Label(dialog_text2))
            )
          ),
          # dialog buttons
          ButtonBox(
            # push button
            PushButton(Id(:trust), Opt(:key_F10, :okButton), _("&Trust")),
            PushButton(
              Id(:cancel),
              Opt(:key_F9, :cancelButton),
              Label.CancelButton
            )
          )
        )
      )
    )
  )

  UI.SetFocus(:cancel)

  ret = Convert.to_symbol(UI.UserInput)

  UI.CloseDialog

  ret == :trust
end

- (Symbol) ItemSignedWithPublicSignature(item_type, item_name, key)

Used for file or package signed by a public key. This key is still not listed in trusted keys.

Parameters:

  • item_type (Symbol)

    file orpackage

  • item_name (String)

    file name or package name

  • string

    key_id

  • string

    key_name

Returns:

  • (Symbol)

    key_import,install, `skip



889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
# File '../../src/modules/SignatureCheckDialogs.rb', line 889

def ItemSignedWithPublicSignature(item_type, item_name, key)
  key = deep_copy(key)
  description_text = Builtins.sformat(
    if item_type == :package
      # popup question, %1 stands for the package name, %2 for the key ID, %3 for the key name
      _(
        "The package %1 is digitally signed\n" \
          "with key '%2 (%3)'.\n" \
          "\n" \
          "There is no trust relationship with the owner of the key.\n" \
          "If you trust the owner, mark the key as trusted.\n" \
          "\n" \
          "Installing a package from an unknown repository puts\n" \
          "the integrity of your system at risk. It is safest\n" \
          "to skip the package.\n"
      )
    else
      # popup question, %1 stands for the filename, %2 for the key ID, %3 for the key name
      _(
        "The file %1 is digitally signed\n" \
          "with key '%2 (%3)'.\n" \
          "\n" \
          "There is no trust relationship with the owner of the key.\n" \
          "If you trust the owner, mark the key as trusted.\n" \
          "\n" \
          "Installing a file from an unknown repository puts\n" \
          "the integrity of your system at risk. It is safest\n" \
          "to skip it.\n"
      )
    end,
    item_name,
    Ops.get_string(key, "id", ""),
    Ops.get_string(key, "name", "")
  )

  UI.OpenDialog(
    Opt(:decorated),
    VBox(
      HBox(
        VCenter(MessageIcon("warning")),
        # popup heading
        VCenter(Heading(_("Signed with Untrusted Public Key"))),
        HStretch()
      ),
      MarginBox(0.5, 0.5, Label(description_text)),
      ButtonBox(
        # push button
        PushButton(
          Id(:trust),
          Opt(:okButton, :key_F10),
          _("&Trust and Import the Key")
        ),
        PushButton(Id(:skip), Opt(:cancelButton, :key_F9), Label.SkipButton)
      )
    )
  )
  UI.SetFocus(:skip)

  # wait for one of listed ID's, return the default value in case of `cancel
  ret = WaitForSymbolUserInput([:trust, :skip], :skip)

  if ret == :trust
    # later, if asking whether to import the key, the key is trusted
    # so it will be also imported
    # bugzilla #282254
    @list_of_trusted_keys = Builtins.add(
      @list_of_trusted_keys,
      Ops.get_string(key, "id", "")
    )
  end

  UI.CloseDialog
  ret
end

- (Boolean) ItemSignedWithUnknownSignature(item_type, item_name, key_id, dont_show_dialog_ident, repoid)

Used for file or package signed by unknown key.

Parameters:

  • item_type (Symbol)

    file orpackage

  • item_name (String)

    file name or package name

  • key_id (String)
  • string

    fingerprint

  • dont_show_dialog_ident (String)

    for the identification in magic “don't show” functions

  • repoid (Fixnum)

    Id of the repository from the item was downloaded

Returns:

  • (Boolean)

    true if 'yes, use file'



796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
# File '../../src/modules/SignatureCheckDialogs.rb', line 796

def ItemSignedWithUnknownSignature(item_type, item_name, key_id, dont_show_dialog_ident, repoid)
  repo_url = Ops.get_string(Pkg.SourceGeneralData(repoid), "url", "")
  description_text = Builtins.sformat(
    if item_type == :package
      # popup question, %1 stands for the package name, %2 for the complex multiline description of the GnuPG key
      _(
        "The package %1 is digitally signed\n" \
          "with the following unknown GnuPG key: %2.\n" \
          "\n" \
          "This means that a trust relationship to the creator of the package\n" \
          "cannot be established. Installing the package may put the integrity\n" \
          "of your system at risk.\n" \
          "\n" \
          "Install it anyway?"
      )
    else
      # popup question, %1 stands for the filename, %2 for the complex multiline description of the GnuPG key
      _(
        "The file %1\n" \
          "is digitally signed with the following unknown GnuPG key: %2.\n" \
          "\n" \
          "This means that a trust relationship to the creator of the file\n" \
          "cannot be established. Using the file may put the integrity\n" \
          "of your system at risk.\n" \
          "\n" \
          "Use it anyway?"
      )
    end,
    # TODO: use something like "%1 from %2" and make it translatable
    if repo_url != ""
      Builtins.sformat("%1 (%2)", item_name, repo_url)
    else
      item_name
    end,
    Ops.add(
      "\n",
      # Part of the GnuPG key description in popup, %1 is a GnuPG key ID
      Builtins.sformat(_("ID: %1"), key_id)
    )
  )

  UI.OpenDialog(
    Opt(:decorated),
    VBox(
      HBox(
        VCenter(MessageIcon("warning")),
        # popup heading
        VCenter(Heading(_("Unknown GnuPG Key"))),
        HStretch()
      ),
      MarginBox(0.5, 0.5, Label(description_text)),
      Left(
        MarginBox(
          0,
          1.2,
          CheckBox(
            Id(:dont_show_again),
            Message.DoNotShowMessageAgain,
            GetShowThisPopup(dont_show_dialog_ident, item_name) ? false : true
          )
        )
      ),
      YesNoButtons(:no)
    )
  )

  # This will optionally offer to retrieve the key from gpg keyservers
  # That's why it will return 'symbol' instead of 'boolean'
  # But by now it only handles yes/no/cancel
  ret = WaitForYesNoCancelUserInput()
  # default value
  ret = false if ret.nil?

  # Store the don't show value, store the default return value
  HandleDoNotShowDialogAgain(
    ret,
    dont_show_dialog_ident,
    :dont_show_again,
    item_name
  )

  UI.CloseDialog
  ret
end

- (Object) main



34
35
36
37
38
39
40
41
42
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
72
73
# File '../../src/modules/SignatureCheckDialogs.rb', line 34

def main
  Yast.import "Pkg"
  Yast.import "UI"
  textdomain "base"

  Yast.import "Label"
  Yast.import "Popup"
  Yast.import "Message"
  Yast.import "DontShowAgain"
  Yast.import "Stage"
  Yast.import "Linuxrc"

  # --------------------------- Don't show this dialog again Magic ---------------------------

  # /etc/sysconfig/security:CHECK_SIGNATURES

  @check_signatures = nil # lazy

  # Standard text strings

  # GnuPG fingerprint used as "Fingerprint: AAA BBB CCC"
  @s_fingerprint = _("Fingerprint")
  # GnuPG key ID used as "Key ID: 1144AAAA444"
  @s_keyid = _("Key ID")

  # Defining icons for dialogs
  @msg_icons = {
    "error"    => "/usr/share/YaST2/theme/current/icons/32x32/apps/msg_error.png",
    "warning"  => "/usr/share/YaST2/theme/current/icons/32x32/apps/msg_warning.png",
    "question" => "/usr/share/YaST2/theme/current/icons/32x32/apps/msg_warning.png"
  }

  # UI can show images
  @has_local_image_support = nil

  # List of trusted keys
  #
  # @see bugzilla #282254
  @list_of_trusted_keys = []
end

- (Yast::Term) MessageIcon(msg_type)

Returns term with message icon

Parameters:

  • string

    message type “error”, “warning” or “question”

Returns:

  • (Yast::Term)

    `Image(…) with margins



323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
# File '../../src/modules/SignatureCheckDialogs.rb', line 323

def MessageIcon(msg_type)
  # lazy loading
  if @has_local_image_support.nil?
    ui_capabilities = UI.GetDisplayInfo
    @has_local_image_support = Ops.get_boolean(
      ui_capabilities,
      "HasLocalImageSupport",
      false
    )
  end

  # UI can show images
  if @has_local_image_support
    if Ops.get(@msg_icons, msg_type).nil?
      Builtins.y2warning("Message type %1 not defined", msg_type)
      return Empty()
    end
    return MarginBox(
      1,
      0.5,
      Image(Ops.get(@msg_icons, msg_type, ""), "[!]")
    )
  else
    return Empty()
  end
end

- (Object) RunSimpleErrorPopup(heading, description_text, dont_show_dialog_ident, dont_show_dialog_param)



1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
# File '../../src/modules/SignatureCheckDialogs.rb', line 1079

def RunSimpleErrorPopup(heading, description_text, dont_show_dialog_ident, dont_show_dialog_param)
  UI.OpenDialog(
    Opt(:decorated),
    VBox(
      # popup heading
      HBox(
        VCenter(MessageIcon("error")),
        # dialog heading - displayed in a big bold font
        VCenter(Heading(heading)),
        HStretch()
      ),
      MarginBox(0.5, 0.5, Label(description_text)),
      Left(
        MarginBox(
          0,
          1.2,
          CheckBox(
            Id(:dont_show_again),
            Message.DoNotShowMessageAgain,
            GetShowThisPopup(dont_show_dialog_ident, dont_show_dialog_param) ? false : true
          )
        )
      ),
      YesNoButtons(:no)
    )
  )

  ret = WaitForYesNoCancelUserInput()
  # default value
  ret = false if ret.nil?

  # Store the don't show value, store the default return value
  HandleDoNotShowDialogAgain(
    ret,
    dont_show_dialog_ident,
    :dont_show_again,
    dont_show_dialog_param
  )

  UI.CloseDialog

  ret
end

- (Object) SetDefaultDialogReturn(popup_type, default_return, popup_url)

Function sets the default dialog return value for case when user selected “don't show again”

Parameters:

  • popup_type (String)

    dialog type

  • default_return (Boolean)


156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File '../../src/modules/SignatureCheckDialogs.rb', line 156

def SetDefaultDialogReturn(popup_type, default_return, popup_url)
  if popup_type.nil? || default_return.nil?
    Builtins.y2error(
      "Neither popup_type %1 nor default_return %2 can be nil!",
      popup_type,
      default_return
    )
    return
  end
  Builtins.y2milestone(
    "User decision in default return for '%1' for '%2' is '%3'",
    popup_type,
    popup_url,
    default_return
  )
  DontShowAgain.SetDefaultReturn(
    {
      "q_type"  => "inst-source",
      "q_ident" => popup_type,
      "q_url"   => popup_url
    },
    default_return
  )

  nil
end

- (Object) SetShowThisPopup(popup_type, show_it, popup_url)

Functions sets whether user want's to show the dialog again

Parameters:

  • popup_type (String)

    dialog type

  • boolean

    show again

  • popup_url (String)


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
111
112
113
114
115
116
117
118
119
# File '../../src/modules/SignatureCheckDialogs.rb', line 82

def SetShowThisPopup(popup_type, show_it, popup_url)
  if popup_type.nil? || show_it.nil?
    Builtins.y2error(
      "Neither popup_type %1 nor show_it %2 can be nil!",
      popup_type,
      show_it
    )
    return
  end

  # it's the default
  if show_it
    Builtins.y2debug(
      "User decision to show dialog '%1' again is '%2'",
      popup_type,
      show_it
    )
    # store only "don't show"
  else
    Builtins.y2milestone(
      "User decision to show dialog '%1' for '%2' again is '%3'",
      popup_type,
      popup_url,
      show_it
    )
    # Show again -> false, so, store it
    DontShowAgain.SetShowQuestionAgain(
      {
        "q_type"  => "inst-source",
        "q_ident" => popup_type,
        "q_url"   => popup_url
      },
      show_it
    )
  end

  nil
end

- (String) StringSplitter(whattosplit, delimiter, after_chars)

Function adds delimiter between after_chars characters in the string

Parameters:

  • string

    to be splitted

  • delimiter (String)
  • integer

    after characters

Returns:

  • (String)

    with delimiters



292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File '../../src/modules/SignatureCheckDialogs.rb', line 292

def StringSplitter(whattosplit, delimiter, after_chars)
  splittedstring = ""
  after_chars_counter = 0
  max_size = Builtins.size(whattosplit)

  loop do
    if Ops.greater_or_equal(
      Ops.add(after_chars_counter, after_chars),
      max_size
      )
      splittedstring = Ops.add(
        Ops.add(splittedstring, splittedstring == "" ? "" : delimiter),
        Builtins.substring(whattosplit, after_chars_counter)
      )
      break
    else
      splittedstring = Ops.add(
        Ops.add(splittedstring, splittedstring == "" ? "" : delimiter),
        Builtins.substring(whattosplit, after_chars_counter, after_chars)
      )
      after_chars_counter = Ops.add(after_chars_counter, after_chars)
    end
  end

  splittedstring
end

- (Boolean) UseCorruptedItem(item_type, item_name, key, repository)

Used for corrupted file or package. Opens dialog asking whether user wants to use this corrupted item.

Parameters:

  • item_type (Symbol)

    file orpackage

  • item_name (String)

    file name or package name

  • key (Hash{String => Object})

    Used key

Returns:

  • (Boolean)

    use or don't use ('true' if 'yes')



727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
# File '../../src/modules/SignatureCheckDialogs.rb', line 727

def UseCorruptedItem(item_type, item_name, key, repository)
  key = deep_copy(key)
  repo = Pkg.SourceGeneralData(repository)

  description_text = Builtins.sformat(
    if item_type == :package
      # popup question, %1 stands for the package name, %2 for the complete description of the GnuPG key (multiline)
      _(
        "Package %1 from repository %2\n" \
          "%3\n" \
          "is signed with the following GnuPG key, but the integrity check failed: %4\n" \
          "\n" \
          "The package has been changed, either by accident or by an attacker,\n" \
          "since the repository creator signed it. Installing it is a big risk\n" \
          "for the integrity and security of your system.\n" \
          "\n" \
          "Install it anyway?\n"
      )
    else
      # popup question, %1 stands for the filename, %2 for the complete description of the GnuPG key (multiline)
      _(
        "File %1 from repository %2\n" \
          "%3\n" \
          "is signed with the following GnuPG key, but the integrity check failed: %4\n" \
          "\n" \
          "The file has been changed, either by accident or by an attacker,\n" \
          "since the repository creator signed it. Using it is a big risk\n" \
          "for the integrity and security of your system.\n" \
          "\n" \
          "Use it anyway?\n"
      )
    end,
    item_name,
    Ops.get_locale(repo, "name", _("Unknown")),
    Ops.get_locale(repo, "url", _("Unknown")),
    Ops.add("\n\n", GPGKeyAsString(key))
  )

  UI.OpenDialog(
    Opt(:decorated),
    VBox(
      # popup heading
      HBox(
        VCenter(MessageIcon("error")),
        VCenter(Heading(_("Validation Check Failed"))),
        HStretch()
      ),
      MarginBox(0.5, 0.5, Label(description_text)),
      YesNoButtons(:no)
    )
  )

  ret = WaitForYesNoCancelUserInput()
  # default value
  ret = false if ret.nil?

  UI.CloseDialog
  ret
end

- (Boolean) UseFileWithUnknownDigest(filename, digest, dont_show_dialog_ident)

Ask user to accept a file with unknown checksum

Parameters:

  • filename (String)

    Name of the file

  • digest (String)

    Current checksum

  • dont_show_dialog_ident (String)

    Uniq ID for “don't show again”

Returns:

  • (Boolean)

    true when user accepts the file



1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
# File '../../src/modules/SignatureCheckDialogs.rb', line 1166

def UseFileWithUnknownDigest(filename, digest, dont_show_dialog_ident)
  description_text =
    # popup question, %1 stands for the filename, %2 is expected digest, %3 is the current digest
    Builtins.sformat(
      _(
        "The checksum of file %1\n" \
          "is %2,\n" \
          "but the expected checksum is not known.\n" \
          "\n" \
          "This means that the origin and integrity of the file\n" \
          "cannot be verified. Using the file puts the integrity of your system at risk.\n" \
          "\n" \
          "Use it anyway?\n"
      ),
      filename,
      digest
    )
  # dialog heading - displayed in a big bold font
  heading = _("Unknown Digest")

  RunSimpleErrorPopup(
    heading,
    description_text,
    dont_show_dialog_ident,
    filename
  )
end

- (Boolean) UseFileWithWrongDigest(filename, requested_digest, found_digest, dont_show_dialog_ident)

Ask user to accept wrong digest

Parameters:

  • filename (String)

    Name of the file

  • requested_digest (String)

    Expected checksum

  • found_digest (String)

    Current checksum

  • dont_show_dialog_ident (String)

    Uniq ID for “don't show again”

Returns:

  • (Boolean)

    true when user accepts the file



1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
# File '../../src/modules/SignatureCheckDialogs.rb', line 1129

def UseFileWithWrongDigest(filename, requested_digest, found_digest, dont_show_dialog_ident)
  description_text =
    # popup question, %1 stands for the filename, %2 is expected checksum
    # %3 is the current checksum (e.g. "803a8ff00d00c9075a1bd223a480bcf92d2481c1")
    Builtins.sformat(
      _(
        "The expected checksum of file %1\n" \
          "is %2,\n" \
          "but the current checksum is %3.\n" \
          "\n" \
          "The file has been changed by accident or by an attacker\n" \
          "since the repository creator signed it. Using it is a big risk\n" \
          "for the integrity and security of your system.\n" \
          "\n" \
          "Use it anyway?\n"
      ),
      filename,
      requested_digest,
      found_digest
    )

  # dialog heading - displayed in a big bold font
  heading = _("Wrong Digest")

  RunSimpleErrorPopup(
    heading,
    description_text,
    dont_show_dialog_ident,
    filename
  )
end

- (Boolean) UseItemWithNoChecksum(item_type, item_name, dont_show_dialog_ident)

Used for file or package on signed repository but without any checksum. Opens dialog asking whether user wants to use this item.

Parameters:

  • item_type (Symbol)

    file orpackage

  • item_name (String)

    file name or package name

  • dont_show_dialog_ident (String)

    for the identification in magic “don't show” functions

Returns:

  • (Boolean)

    use or don't use ('true' if 'yes')



547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
# File '../../src/modules/SignatureCheckDialogs.rb', line 547

def UseItemWithNoChecksum(item_type, item_name, dont_show_dialog_ident)
  description_text = Builtins.sformat(
    if item_type == :package
      # popup question, %1 stands for the package name
      _(
        "No checksum for package %1 was found in the repository.\n" \
          "While the package is part of the signed repository, it is not contained \n" \
          "in the list of checksums in this repository. Installing the package puts \n" \
          "the integrity of your system at risk.\n" \
          "\n" \
          "Install it anyway?\n"
      )
    else
      # popup question, %1 stands for the filename
      _(
        "No checksum for file %1 was found in the repository.\n" \
          "This means that the file is part of the signed repository,\n" \
          "but the list of checksums in this repository does not mention this file. Using the file\n" \
          "may put the integrity of your system at risk.\n" \
          "\n" \
          "Use it anyway?"
      )
    end,
    item_name
  )

  UI.OpenDialog(
    Opt(:decorated),
    VBox(
      HBox(
        VCenter(MessageIcon("warning")),
        # popup heading
        VCenter(Heading(_("No Checksum Found"))),
        HStretch()
      ),
      MarginBox(0.5, 0.5, Label(description_text)),
      Left(
        MarginBox(
          0,
          1.2,
          CheckBox(
            Id(:dont_show_again),
            Message.DoNotShowMessageAgain,
            GetShowThisPopup(dont_show_dialog_ident, item_name) ? false : true
          )
        )
      ),
      YesNoButtons(:no)
    )
  )

  ret = WaitForYesNoCancelUserInput()
  # default value
  ret = false if ret.nil?

  # Store the don't show value, store the default return value
  HandleDoNotShowDialogAgain(
    ret,
    dont_show_dialog_ident,
    :dont_show_again,
    item_name
  )

  UI.CloseDialog
  ret
end

- (Boolean) UseUnsignedItem(item_type, item_name, dont_show_dialog_ident, repository)

Used for unsiged file or package. Opens dialog asking whether user wants to use this unsigned item.

Parameters:

  • item_type (Symbol)

    file orpackage

  • item_name (String)

    file name or package name

  • dont_show_dialog_ident (String)

    for the identification in magic “don't show” functions

Returns:

  • (Boolean)

    use or don't use ('true' if 'yes')



447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
# File '../../src/modules/SignatureCheckDialogs.rb', line 447

def UseUnsignedItem(item_type, item_name, dont_show_dialog_ident, repository)
  Builtins.y2milestone(
    "UseUnsignedItem: type: %1, name: %2, dontshowid: %3, repo: %4",
    item_type,
    item_name,
    dont_show_dialog_ident,
    repository
  )

  repo = Pkg.SourceGeneralData(repository)

  description_text = Builtins.sformat(
    if item_type == :package
      # popup question, %1 stands for the package name
      # %2 is a repository name
      # %3 is URL of the repository
      _(
        "The package %1 from repository %2\n" \
          "%3\n" \
          "is not digitally signed. This means that the origin\n" \
          "and integrity of the package cannot be verified. Installing the package\n" \
          "may put the integrity of your system at risk.\n" \
          "\n" \
          "Install it anyway?"
      )
    else
      # popup question, %1 stands for the filename
      # %2 is a repository name
      # %3 is URL of the repository
      _(
        "The file %1 from repository %2\n" \
          "%3\n" \
          "is not digitally signed. The origin and integrity of the file\n" \
          "cannot be verified. Using the file anyway puts the integrity of your \n" \
          "system at risk.\n" \
          "\n" \
          "Use it anyway?\n"
      )
    end,
    item_name,
    Ops.get_locale(repo, "name", _("Unknown")),
    Ops.get_locale(repo, "url", _("Unknown"))
  )

  UI.OpenDialog(
    Opt(:decorated),
    VBox(
      HBox(
        VCenter(MessageIcon("warning")),
        # popup heading
        VCenter(
          Heading(
            if item_type == :package
              _("Unsigned Package")
            else
              _("Unsigned File")
            end
          )
        ),
        HStretch()
      ),
      MarginBox(0.5, 0.5, Label(description_text)),
      Left(
        MarginBox(
          0,
          1.2,
          CheckBox(
            Id(:dont_show_again),
            Message.DoNotShowMessageAgain,
            GetShowThisPopup(dont_show_dialog_ident, item_name) ? false : true
          )
        )
      ),
      YesNoButtons(:no)
    )
  )

  ret = WaitForYesNoCancelUserInput()
  # default value
  ret = false if ret.nil?

  # Store the don't show value, store the default return value
  HandleDoNotShowDialogAgain(
    ret,
    dont_show_dialog_ident,
    :dont_show_again,
    item_name
  )

  UI.CloseDialog
  ret
end

- (Object) WaitForSymbolUserInput(list_of_accepted, default_symb)

Waits for user input and checks it agains accepted symbols. Returns the default symbol in case of `cancel (user closes the dialog).

Parameters:

  • list (symbol)

    of accepted symbol by UserInput

  • symbol

    default return for case of `cancel



418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
# File '../../src/modules/SignatureCheckDialogs.rb', line 418

def WaitForSymbolUserInput(list_of_accepted, default_symb)
  list_of_accepted = deep_copy(list_of_accepted)
  user_input = nil
  ret = nil

  loop do
    user_input = Convert.to_symbol(UI.UserInput)
    if Builtins.contains(list_of_accepted, user_input)
      ret = user_input
      break
    elsif user_input == :cancel
      ret = default_symb
      break
    else
      Builtins.y2error("Unknown user input: '%1'", user_input)
      next
    end
  end

  ret
end

- (Boolean) WaitForYesNoCancelUserInput

Returns 'true' (yes), 'false' (no) or 'nil' (cancel)

Returns:

  • (Boolean)

    user input yes==true



386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
# File '../../src/modules/SignatureCheckDialogs.rb', line 386

def WaitForYesNoCancelUserInput
  user_input = nil
  ret = nil

  loop do
    user_input = UI.UserInput
    # yes button
    if user_input == :yes
      ret = true
      break
      # no button
    elsif user_input == :no
      ret = false
      break
      # closing window uisng [x]
    elsif user_input == :cancel
      ret = nil
      break
    else
      Builtins.y2error("Unknown user input: '%1'", user_input)
      next
    end
  end

  ret
end

- (Yast::Term) YesNoButtons(default_button)

Returns term of yes/no buttons

Parameters:

  • symbol

    default button yes orno

Returns:

  • (Yast::Term)

    with buttons



354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
# File '../../src/modules/SignatureCheckDialogs.rb', line 354

def YesNoButtons(default_button)
  yes_button = PushButton(
    Id(:yes),
    Opt(:okButton, :key_F10),
    Label.YesButton
  )
  no_button = PushButton(
    Id(:no),
    Opt(:cancelButton, :key_F9),
    Label.NoButton
  )

  if default_button == :yes
    yes_button = PushButton(
      Id(:yes),
      Opt(:default, :okButton, :key_F10),
      Label.YesButton
    )
  else
    no_button = PushButton(
      Id(:no),
      Opt(:default, :cancelButton, :key_F9),
      Label.NoButton
    )
  end

  ButtonBox(yes_button, no_button)
end