From 08282dc4d9958d8a2ac6163d6d0921517ec45f92 Mon Sep 17 00:00:00 2001 From: Ainar Garipov Date: Tue, 22 Nov 2022 17:07:49 +0300 Subject: [PATCH] Pull request: 4927-imp-ui Updates #4927. Squashed commit of the following: commit 510143325805133e379ebc207cdc6bff59c94ade Author: Ainar Garipov Date: Tue Nov 22 15:00:13 2022 +0300 home: imp err commit fd65a9914494b6dccdee7c0f0aa08bce80ce0945 Author: Ainar Garipov Date: Mon Nov 21 18:53:39 2022 +0300 client: imp validation ui --- client/src/__locales/en.json | 1 + .../components/Settings/Encryption/Form.js | 28 +++++++++++++++---- internal/home/tls.go | 8 ++++-- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/client/src/__locales/en.json b/client/src/__locales/en.json index b986dea1..7ec9c779 100644 --- a/client/src/__locales/en.json +++ b/client/src/__locales/en.json @@ -393,6 +393,7 @@ "encryption_issuer": "Issuer", "encryption_hostnames": "Hostnames", "encryption_reset": "Are you sure you want to reset encryption settings?", + "encryption_warning": "Warning", "topline_expiring_certificate": "Your SSL certificate is about to expire. Update <0>Encryption settings.", "topline_expired_certificate": "Your SSL certificate is expired. Update <0>Encryption settings.", "form_error_port_range": "Enter port number in the range of 80-65535", diff --git a/client/src/components/Settings/Encryption/Form.js b/client/src/components/Settings/Encryption/Form.js index b94dd94b..9df440aa 100644 --- a/client/src/components/Settings/Encryption/Form.js +++ b/client/src/components/Settings/Encryption/Form.js @@ -56,6 +56,26 @@ const clearFields = (change, setTlsConfig, t) => { } }; +const validationMessage = (warningValidation, isWarning) => { + if (!warningValidation) { + return null; + } + + if (isWarning) { + return ( +
+

encryption_warning: {warningValidation}

+
+ ); + } + + return ( +
+

{warningValidation}

+
+ ); +}; + let Form = (props) => { const { t, @@ -95,6 +115,8 @@ let Form = (props) => { || !valid_cert || !valid_pair; + const isWarning = valid_key && valid_cert && valid_pair; + return (
@@ -382,11 +404,7 @@ let Form = (props) => { )}
- {warning_validation && ( -
-

{warning_validation}

-
- )} + {validationMessage(warning_validation, isWarning)}
diff --git a/internal/home/tls.go b/internal/home/tls.go index 7fdd64d8..c9086629 100644 --- a/internal/home/tls.go +++ b/internal/home/tls.go @@ -513,6 +513,11 @@ func validateCertChain(certs []*x509.Certificate, srvName string) (err error) { return nil } +// errNoIPInCert is the error that is returned from [parseCertChain] if the leaf +// certificate doesn't contain IPs. +const errNoIPInCert errors.Error = `certificates has no IP addresses; ` + + `DNS-over-TLS won't be advertised via DDR` + // parseCertChain parses the certificate chain from raw data, and returns it. // If ok is true, the returned error, if any, is not critical. func parseCertChain(chain []byte) (parsedCerts []*x509.Certificate, ok bool, err error) { @@ -535,8 +540,7 @@ func parseCertChain(chain []byte) (parsedCerts []*x509.Certificate, ok bool, err log.Info("tls: number of certs: %d", len(parsedCerts)) if !aghtls.CertificateHasIP(parsedCerts[0]) { - err = errors.Error(`certificate has no IP addresses` + - `, this may cause issues with DNS-over-TLS clients`) + err = errNoIPInCert } return parsedCerts, true, err