/** * Get your SSL keys from the database, or create them (if they don't exist yet) * * Get your SSL keys from the database, or (if they don't exist yet) call * mnet_generate_keypair to create them * * @param string $string The text you want to sign * @return string The signature over that text */ function mnet_get_keypair() { global $CFG; static $keypair = null; if (!is_null($keypair)) { return $keypair; } if ($result = get_field('config_plugins', 'value', 'plugin', 'mnet', 'name', 'openssl')) { list($keypair['certificate'], $keypair['keypair_PEM']) = explode('@@@@@@@@', $result); $keypair['privatekey'] = openssl_pkey_get_private($keypair['keypair_PEM']); $keypair['publickey'] = openssl_pkey_get_public($keypair['certificate']); return $keypair; } else { $keypair = mnet_generate_keypair(); return $keypair; } }
function replace_keys() { global $DB, $CFG; $keypair = mnet_generate_keypair(); if (empty($keypair)) { error_log('Can not generate keypair, sorry'); return; } $this->keypair = array(); $this->keypair = $keypair; $this->public_key = $this->keypair['certificate']; $details = openssl_x509_parse($this->public_key); $this->public_key_expires = $details['validTo_time_t']; $this->wwwroot = $CFG->wwwroot; if (empty($_SERVER['SERVER_ADDR'])) { // SERVER_ADDR is only returned by Apache-like webservers $my_hostname = mnet_get_hostname_from_uri($CFG->wwwroot); $my_ip = gethostbyname($my_hostname); // Returns unmodified hostname on failure. DOH! if ($my_ip == $my_hostname) { $this->ip_address = 'UNKNOWN'; } else { $this->ip_address = $my_ip; } } else { $this->ip_address = $_SERVER['SERVER_ADDR']; } set_config('openssl', implode('@@@@@@@@', $this->keypair), 'mnet'); $DB->update_record('mnet_host', $this); error_log('New public key has been generated. It expires ' . date('Y/m/d h:i:s', $this->public_key_expires)); }
function replace_keys() { global $CFG; $this->keypair = array(); $this->keypair = mnet_generate_keypair(); $this->public_key = $this->keypair['certificate']; $this->wwwroot = $CFG->wwwroot; $details = openssl_x509_parse($this->public_key); $this->public_key_expires = $details['validTo_time_t']; if (empty($_SERVER['SERVER_ADDR'])) { // SERVER_ADDR is only returned by Apache-like webservers $my_hostname = mnet_get_hostname_from_uri($CFG->wwwroot); $my_ip = gethostbyname($my_hostname); // Returns unmodified hostname on failure. DOH! if ($my_ip == $my_hostname) { $this->ip_address = 'UNKNOWN'; } else { $this->ip_address = $my_ip; } } else { $this->ip_address = $_SERVER['SERVER_ADDR']; } set_config('openssl', implode('@@@@@@@@', $this->keypair), 'mnet'); // clone the proper object and then unset anything that isn't required to go into the database // most fields don't matter but things that are arrays, will break things. $dbobject = (object) clone $this; unset($dbobject->keypair); update_record('mnet_host', addslashes_object($dbobject)); error_log('New public key has been generated. It expires ' . date('Y/m/d h:i:s', $this->public_key_expires)); }
/** * Get your SSL keys from the database, or create them (if they don't exist yet) * * Get your SSL keys from the database, or (if they don't exist yet) call * mnet_generate_keypair to create them * * @param string $string The text you want to sign * @return string The signature over that text */ function mnet_get_keypair() { global $CFG, $DB;; static $keypair = null; if (!is_null($keypair)) return $keypair; if ($result = get_config('mnet', 'openssl')) { list($keypair['certificate'], $keypair['keypair_PEM']) = explode('@@@@@@@@', $result); $keypair['privatekey'] = openssl_pkey_get_private($keypair['keypair_PEM']); $keypair['publickey'] = openssl_pkey_get_public($keypair['certificate']); return $keypair; } else { $keypair = mnet_generate_keypair(); return $keypair; } }
/** * setup and configure a mnet environment that describes this vmoodle * @uses $USER for generating keys * @uses $CFG * @param object $vmoodle * @param handle $cnx a connection */ function vmoodle_setup_mnet_environment($vmoodle, $cnx) { global $USER, $CFG; // Make an empty mnet environment. $mnet_env = new mnet_environment(); $mnet_env->wwwroot = $vmoodle->vhostname; $mnet_env->ip_address = $CFG->local_vmoodle_vmoodleip; $mnet_env->keypair = array(); $mnet_env->keypair = mnet_generate_keypair(null); $mnet_env->public_key = $mnet_env->keypair['certificate']; $details = openssl_x509_parse($mnet_env->public_key); $mnet_env->public_key_expires = $details['validTo_time_t']; return $mnet_env; }
function replace_keys() { $this->keypair = array(); $this->keypair = mnet_generate_keypair(); $this->public_key = $this->keypair['certificate']; $details = openssl_x509_parse($this->public_key); $this->public_key_expires = $details['validTo_time_t']; set_config('openssl', implode('@@@@@@@@', $this->keypair), 'mnet'); update_record('mnet_host', $this); error_log('New public key has been generated. It expires ' . date('Y/m/d h:i:s', $this->public_key_expires)); }