diff --git a/scripts/wsrep_sst_mariabackup.sh b/scripts/wsrep_sst_mariabackup.sh
index 7e26af83701..45dd1f3c4ff 100644
--- a/scripts/wsrep_sst_mariabackup.sh
+++ b/scripts/wsrep_sst_mariabackup.sh
@@ -1334,9 +1334,11 @@ else # joiner
                     'openssl not found but it is required for authentication'
                 exit 42
             fi
-            CN=$("$OPENSSL_BINARY" x509 -noout -subject -in "$tpem" | \
-                 tr ',' '\n' | grep -F 'CN =' | cut -d '=' -f2 | sed s/^\ // | \
-                 sed s/\ %//)
+            CN=$("$OPENSSL_BINARY" x509 -noout -subject -in "$tpem" | sed -e '
+		s/^subject=//
+		s/^/, /
+		s@.*[/,][[:blank:]]*CN[[:blank:]]*=[[:blank:]]*@@
+		s@[/,].*@@')
         fi
         MY_SECRET="$(wsrep_gen_secret)"
         # Add authentication data to address
