From 5ac02b6e21a67fa38d434b7645fb8db0a3c2103f Mon Sep 17 00:00:00 2001 From: Sam Hemelryk Date: Fri, 17 Feb 2012 16:47:15 +1300 Subject: [PATCH] MDL-25299 mnet: Fixed validation when no public key is provided --- admin/mnet/peer_forms.php | 5 ++++- lang/en/mnet.php | 1 + mnet/peer.php | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/admin/mnet/peer_forms.php b/admin/mnet/peer_forms.php index 4e2e1738978..4c5243bf8a5 100644 --- a/admin/mnet/peer_forms.php +++ b/admin/mnet/peer_forms.php @@ -98,6 +98,7 @@ class mnet_review_host_form extends moodleform { $mform->addElement('textarea', 'public_key', get_string('publickey', 'mnet'), array('rows' => 17, 'cols' => 100, 'class' => 'smalltext')); $mform->setType('public_key', PARAM_PEM); + $mform->addRule('public_key', get_string('required'), 'required'); // finished with form controls, now the static informational stuff if ($mnet_peer && !empty($mnet_peer->bootstrapped)) { @@ -160,7 +161,9 @@ class mnet_review_host_form extends moodleform { } $mnet_peer = new mnet_peer(); // idiotic api $mnet_peer->wwwroot = $data['wwwroot']; // just hard-set this rather than bootstrap the object - if (!$credentials = $mnet_peer->check_credentials($data['public_key'])) { + if (empty($data['public_key'])) { + $errors['public_key'] = get_string('publickeyrequired', 'mnet'); + } else if (!$credentials = $mnet_peer->check_credentials($data['public_key'])) { $errmsg = ''; foreach ($mnet_peer->error as $err) { $errmsg .= $err['code'] . ': ' . $err['text'].'
'; diff --git a/lang/en/mnet.php b/lang/en/mnet.php index f087849c0ff..36cd958e370 100644 --- a/lang/en/mnet.php +++ b/lang/en/mnet.php @@ -179,6 +179,7 @@ $string['profileimportfields'] = 'Fields to import'; $string['promiscuous'] = 'Promiscuous'; $string['publickey'] = 'Public key'; $string['publickey_help'] = 'The public key is automatically obtained from the remote server.'; +$string['publickeyrequired'] = 'You must provide a public key.'; $string['publish'] = 'Publish'; $string['reallydeleteserver'] = 'Are you sure you want to delete the server'; $string['receivedwarnings'] = 'The following warnings were received'; diff --git a/mnet/peer.php b/mnet/peer.php index da46638931d..5d8936b04cb 100644 --- a/mnet/peer.php +++ b/mnet/peer.php @@ -155,7 +155,7 @@ class mnet_peer { function check_credentials($key) { $credentials = openssl_x509_parse($key); if ($credentials == false) { - $this->error[] = array('code' => 3, 'text' => get_string("nonmatchingcert", 'mnet', array('',''))); + $this->error[] = array('code' => 3, 'text' => get_string("nonmatchingcert", 'mnet', array('subject' => '','host' => ''))); return false; } elseif (array_key_exists('subjectAltName', $credentials['subject']) && $credentials['subject']['subjectAltName'] != $this->wwwroot) { $a['subject'] = $credentials['subject']['subjectAltName'];