-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
155 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
# ------------------------------------------------------------------------------ | ||
# Copyright (c) 2019 SUSE LLC | ||
# | ||
# This program is free software; you can redistribute it and/or modify it under | ||
# the terms of version 2 of the GNU General Public License as published by the | ||
# Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
# | ||
# ------------------------------------------------------------------------------ | ||
# | ||
|
||
require "yast" | ||
|
||
require "registration/ssl_certificate_details" | ||
require "registration/ssl_error_codes" | ||
require "registration/url_helpers" | ||
|
||
|
||
module Registration | ||
module UI | ||
# this class displays and runs the dialog for importing a SSL certificate | ||
class FailedCertificatePopup | ||
include Yast::Logger | ||
include Yast::I18n | ||
|
||
attr_accessor :certificate, :error_code, :message | ||
|
||
Yast.import "Report" | ||
Yast.import "Stage" | ||
|
||
# create a new dialog for importing a SSL certificate and run it | ||
# @param cert [Registration::SslCertitificate] certificate to display | ||
# @return [Symbol] user input (:import, :cancel) | ||
def self.show(msg, cert, error_code) | ||
popup = FailedCertificatePopup.new(msg, cert, error_code) | ||
popup.show | ||
end | ||
|
||
# the constructor | ||
# @param cert [Registration::SslCertitificate] certificate to display | ||
def initialize(msg, cert, error_code) | ||
textdomain "registration" | ||
|
||
@certificate = cert | ||
@message = msg | ||
@error_code = error_code | ||
end | ||
|
||
# display the dialog and wait for a button click | ||
# @return [Symbol] user input (:import, :cancel) | ||
def show | ||
# this uses a RichText message format | ||
Yast::Report.LongError(ssl_error_message) | ||
end | ||
|
||
private | ||
|
||
def ssl_error_message | ||
# try to use a translatable message first, if not found then use | ||
# the original error message from openSSL | ||
msg = _(SslErrorCodes::OPENSSL_ERROR_MESSAGES[error_code]) || message | ||
url = UrlHelpers.registration_url || SUSE::Connect::YaST::DEFAULT_URL | ||
|
||
msg = "<p>" + (_("Secure connection error: %s") % "#{url}: #{msg}") + "</p>\n" | ||
|
||
if error_code == SslErrorCodes::NO_LOCAL_ISSUER_CERTIFICATE | ||
msg << import_hint | ||
end | ||
|
||
msg << "<hr><h3>" << _("Failed Certificate Details") << "</h3>" << | ||
ssl_certificate_details | ||
end | ||
|
||
# render Richtext description with the certificate details | ||
def ssl_certificate_details(richtext: true) | ||
details = SslCertificateDetails.new(certificate) | ||
richtext ? details.richtext_summary : details.summary | ||
end | ||
|
||
def import_hint | ||
"<p>" + _("The issuer certificate cannot be found, " \ | ||
"it needs to be installed manually.") + "</p>\n<p><ul>\n" + | ||
# TRANSLATORS: %{dir} is replaced by the certificate directory | ||
_("<li>Copy the certificate in PEM format to <tt>%{dir}</tt> directory</li>") % | ||
{ dir: "/etc/pki/trust/anchors" } + "\n" + | ||
import_commands + | ||
"<li>" + _("Run registration again") + "</li>" \ | ||
"\n</ul></p>" | ||
end | ||
|
||
def import_commands | ||
# in the inst-sys we need to import the certificate manually, | ||
# the update-ca-certificates script is missing | ||
commands = if Yast::Stage.initial | ||
["trust extract --format=openssl-directory --filter=ca-anchors " \ | ||
"--overwrite #{SslCertificate::TMP_CA_CERTS_DIR}", | ||
"cp #{SslCertificate::TMP_CA_CERTS_DIR}/* #{SslCertificate::CA_CERTS_DIR}/openssl"] | ||
else | ||
["update-ca-certificates"] | ||
end | ||
|
||
commands.map do |c| | ||
"<li>" + (_("Run command: %s") % "<tt>#{c}</tt>") + "</li>\n" | ||
end.join | ||
end | ||
end | ||
end | ||
end |