Skip to content

Commit

Permalink
MDL-25299 mnet: Fixed validation when no public key is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Hemelryk committed Feb 17, 2012
1 parent 0dde394 commit 4460312
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion admin/mnet/peer_forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ function definition() {

$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)) {
Expand Down Expand Up @@ -160,7 +161,9 @@ function validation($data) {
}
$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'].'<br />';
Expand Down
1 change: 1 addition & 0 deletions lang/en/mnet.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
$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';
Expand Down
2 changes: 1 addition & 1 deletion mnet/peer.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ function check_common_name($key) {
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'];
Expand Down

0 comments on commit 4460312

Please sign in to comment.