getKeySecretForLaunch - Retrieve a Key/Secret for a Launch

@param $url - The url to lookup
541818
public static function getKeySecretForLaunch($url) {
        global $CFG, $CONTEXT;

        $PDOX = self::getConnection();
        $host = parse_url($url, PHP_URL_HOST);
        $port = parse_url($url, PHP_URL_PORT);
        $key_id = self::ltiParameter('key_id', null);
        if ( $key_id == null ) return false;

        $sql = "SELECT consumer_key, secret FROM {$CFG->dbprefix}lti_domain
            WHERE domain = :DOM AND key_id = :KID";
        $values = array(":DOM" => $host, ":KID" => $key_id);
        if ( isset($CONTEXT->id) ) {
            $sql .= " AND (context_id IS NULL OR context_id = :CID)
                ORDER BY context_id DESC";
            $values[':CID'] = $CONTEXT->id;
        }

        $row = $PDOX->rowDie($sql, $values);
        if ( $row === false ) {
            error_log("Unable to key/secret key_id=$key_id url=$url");
            return false;
        }
        $row['key'] = $row['consumer_key'];
        return $row;
    }
564780
public function signatureB($url, $key = null, $timestamp = null)
    {
        $key = $key ?: $this->getConfig()->get('cdn_key');
        $timestamp = date('YmdHi', $timestamp ?: time());

        $parsed = parse_url($url);
        $hash = md5($key.$timestamp.$parsed['path']);

        return sprintf(
            '%s://%s/%s/%s%s',
            $parsed['scheme'], $parsed['host'], $timestamp, $hash, $parsed['path']
        );
    }
606612
private function getBodyKey($url, StreamInterface $body)
    {
        return $this->keyPrefix . md5($url) . Stream\Utils::hash($body, 'md5');
    }
1040330
private function openBrowser($url)
    {
        $url = ProcessExecutor::escape($url);

        if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
            return passthru('start "web" explorer "' . $url . '"');
        }

        passthru('which xdg-open', $linux);
        passthru('which open', $osx);

        if (0 === $linux) {
            passthru('xdg-open ' . $url);
        } elseif (0 === $osx) {
            passthru('open ' . $url);
        } else {
            $this->getIO()->writeError('no suitable browser opening command found, open yourself: ' . $url);
        }
    }
543577
public function retrieveCertsFromLocation($url)
  {
    // If we're retrieving a local file, just grab it.
    if ("http" != substr($url, 0, 4)) {
      $file = file_get_contents($url);
      if ($file) {
        return json_decode($file, true);
      } else {
        throw new Google_Auth_Exception(
            "Failed to retrieve verification certificates: '" .
            $url . "'."
        );
      }
    }

    // This relies on makeRequest caching certificate responses.
    $request = $this->client->getIo()->makeRequest(
        new Google_Http_Request(
            $url
        )
    );
    if ($request->getResponseHttpCode() == 200) {
      $certs = json_decode($request->getResponseBody(), true);
      if ($certs) {
        return $certs;
      }
    }
    throw new Google_Auth_Exception(
        "Failed to retrieve verification certificates: '" .
        $request->getResponseBody() . "'.",
        $request->getResponseHttpCode()
    );
  }
1335233
private function requestSuccessful($url, $ssl)
    {
        return
            $this->fetchResponse($url, $ssl)->getStatusCode() == 200 &&
            ! $this->requestTimedout();
    }
785419
static function quickGet($url)
    {
        $bits = parse_url($url);
        $host = $bits['host'];
        $port = isset($bits['port']) ? $bits['port'] : 80;
        $path = isset($bits['path']) ? $bits['path'] : '/';
        if (isset($bits['query']))
        {
            $path .= '?' . $bits['query'];
        }
        $client = new self($host, $port);
        if (!$client->get($path))
        {
            return false;
        }
        else
        {
            return $client->getContent();
        }
    }
241169
protected function ensureSslEndpoint($url)
    {
        // If the endpoint isn't on SSL
        if (substr($url, 0, 5) != 'https') {
            // Force an SSL endpoint
            $endpoint = parse_url($url);
            $url = 'https://' . $endpoint['host'] . $endpoint['path'];
        }

        // SSL already enabled
        return $url;
    }
289098
private function urlContainsToken($url)
    {
        // TODO: add test for this method.

        $query = parse_url($url, PHP_URL_QUERY);
        parse_str($query, $params);
        if (isset($params["token"])) {
            return true;
        } else {
            return false;
        }
    }
211860
private function _validateUrl($url)
    {
        $parsed = parse_url($url);
        if (empty($parsed['scheme'])
            || empty($parsed['host'])
            || $parsed['scheme'] !== 'https'
            || substr($url, -4) !== '.pem'
            || !preg_match($this->defaultHostPattern, $parsed['host'])
        ) {
            throw new OffAmazonPaymentsNotifications_InvalidMessageException(
                'The certificate is located on an invalid domain.'
            );
        }
    }
1259605
static function getToken($url, $login, $password) {
	    $responseEntity = RestHelper::post($url, [
		    'login' => $login,
		    'password' => $password,
	    ]);
	    if(!$responseEntity->is_ok) {
		    return null;
	    }
	    $token = self::getTokenFromResponse($responseEntity);
	    return $token;
    }
1026354
public function consumer($url, $key, $secret)
    {
        Argument::i()
            //argument 1 must be a string
            ->test(1, 'string')
            //argument 2 must be a string
            ->test(2, 'string')
            //argument 3 must be a string
            ->test(3, 'string');
            
        return Consumer::i($url, $key, $secret);
    }
755777
public function to($url)
	{
		$this->opts['source'] = $this->client->getDatabaseUri();
		$this->opts['target'] = $url;
		return $this->_launch();
	}
1293413
public static function getLaunchContent($endpoint, $debug=false)
    {
            $info = LTIX::getKeySecretForLaunch($endpoint);
            if ( $info === false ) {
                return '<p style="color:red">Unable to load key/secret for '.htmlentities($endpoint)."</p>\n";
            }
            $key = $info['key'];
            $secret = self::decrypt_secret($info['secret']);

            $parms = LTIX::getLaunchData();

            $parms = LTI::signParameters($parms, $endpoint, "POST", $key, $secret, "Button");

            $content = LTI::postLaunchHTML($parms, $endpoint, false);
            return $content;
    }
790140
public static function getFromUrl($url)
    {
        // check is valid url
        if (!filter_var($url, FILTER_VALIDATE_URL) || !function_exists('curl_init')) {
            return null;
        }

        // initialize curl & set required options and target url
        $curl = \curl_init();
        \curl_setopt($curl, CURLOPT_URL, $url);
        if (Str::startsWith('https', $url)) {
            \curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
            \curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        }
        \curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        \curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5);
        \curl_setopt($curl, CURLOPT_HEADER, 0);
        \curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)');
        \curl_setopt($curl, CURLOPT_FAILONERROR, true);
        \curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
        \curl_setopt($curl, CURLOPT_AUTOREFERER, true);
        \curl_setopt($curl, CURLOPT_TIMEOUT, 10);
        $content = \curl_exec($curl);
        \curl_close($curl);

        return $content;
    }
938904
public static function getToken($launch) {
        global $CFG;
        if ( ! isset($CFG->websocket_secret) || strlen($CFG->websocket_secret) < 1 ) return false;
        $plain = self::makeToken($launch);
        if ( ! $plain ) return $plain;
        $encrypted = AesCtr::encrypt($plain, $CFG->websocket_secret, 256) ;
        return $encrypted;
    }
1244209
private function getClusterHeader($url)
    {
        $cacheKey = 'project-cluster:' . $url;
        $cluster = $this->cache ? $this->cache->fetch($cacheKey) : false;
        if ($cluster === false) {
            $this->debug('Making a HEAD request to identify project from URL: ' . $url);
            try {
                $response = $this->api->getHttpClient()->head($url, [
                    'auth' => false,
                    'timeout' => 5,
                    'connect_timeout' => 5,
                    'allow_redirects' => false,
                ]);
            } catch (RequestException $e) {
                // We can use a failed response, if one exists.
                if ($e->getResponse()) {
                    $response = $e->getResponse();
                } else {
                    $this->debug($e->getMessage());

                    return false;
                }
            }
            $cluster = $response->getHeaderAsArray($this->config->get('service.header_prefix') . '-cluster');
            $canCache = !empty($cluster)
                || ($response->getStatusCode() >= 200 && $response->getStatusCode() < 300);
            if ($canCache) {
                $this->cache->save($cacheKey, $cluster, 86400);
            }
        }

        return is_array($cluster) ? reset($cluster) : false;
    }