Put CHAP-MD5 specific attributes

For authenticating using CHAP-MD5 via RADIUS you have to put the challenge
and the response. The chapid is inserted in the first byte of the response.

@return void
1856
function putAuthAttributes()
    {
        if (isset($this->username)) {
            $this->putAttribute(RADIUS_USER_NAME, $this->username);
        }
        if (isset($this->response)) {
            $response = pack('C', $this->chapid) . $this->response;
            $this->putAttribute(RADIUS_CHAP_PASSWORD, $response);
        }
        if (isset($this->challenge)) {
            $this->putAttribute(RADIUS_CHAP_CHALLENGE, $this->challenge);
        }
    }
743206
protected function auth()
    {
        if ($this->state !== self::CONN_STATE_GOT_INITIAL_PACKET) {
            return;
        }

        if ($this->pool->config->authtype->value === 'md5') {
            $this->challenge(function ($conn, $challenge) {
                $packet = "Action: Login\r\n"
                    . "AuthType: MD5\r\n"
                    . "Username: " . $this->username . "\r\n"
                    . "Key: " . md5($challenge . $this->secret) . "\r\n"
                    . "Events: on\r\n"
                    . "\r\n";
                $this->state = self::CONN_STATE_LOGIN_PACKET_SENT_AFTER_CHALLENGE;
                $conn->write($packet);
            });
        } else {
            $this->login();
        }
    }
758672
private function prepare_auth_header() {
    $this->headers = array();
    uksort($this->auth_params, 'strcmp');
    if (!$this->config['as_header']) :
      $this->request_params = array_merge($this->request_params, $this->auth_params);
      return;
    endif;

    foreach ($this->auth_params as $k => $v) {
      $kv[] = "{$k}=\"{$v}\"";
    }
    $this->auth_header = 'OAuth ' . implode(', ', $kv);
    $this->headers['Authorization'] = $this->auth_header;
  }
940295
public function put( $key, $value = null ) {
		if ( ! is_array( $key ) ) {
			$key = [ $key => $value ];
		}

		foreach ( $key as $array_key => $array_value ) {
			Arr::set( $this->attributes, $array_key, $array_value );
		}
	}
365774
protected function _csrf_set_hash() {
		if ($this->_csrf_hash == '') {
			// If the cookie exists we will use it's value.
			// We don't necessarily want to regenerate it with
			// each page load since a page could contain embedded
			// sub-pages causing this feature to fail
			if (isset($_COOKIE[$this->_csrf_cookie_name]) && preg_match('#^[0-9a-f]{32}$#iS', $_COOKIE[$this->_csrf_cookie_name]) === 1) {
				return $this->_csrf_hash = $_COOKIE[$this->_csrf_cookie_name];
			}
			
			return $this->_csrf_hash = md5(uniqid(rand(), TRUE));
		}
		
		return $this->_csrf_hash;
	}
1161959
protected function method_put()
	{
		$params = is_array($this->params) ? $this->encode($this->params) : $this->params;

		$this->set_option(CURLOPT_POSTFIELDS, $params);

		// Override method, I think this makes $_POST DELETE data but... we'll see eh?
		$this->set_header('X-HTTP-Method-Override', 'PUT');
	}
278887
private function _setAttributes()
    {
        if (isset($this->_tokenData['sub'])) {
            $user_data = $this->_tokenData;

            // Remove the values that are part of the JWT and not user attributes.
            unset($user_data['sub']);
            unset($user_data['exp']);
            unset($user_data['nbf']);
            unset($user_data['aud']);
            unset($user_data['iss']);
            unset($user_data['jti']);
            unset($user_data['iat']);

            $this->attributes = $user_data;
            if (array_key_exists('eduPersonEntitlement', $this->attributes)) {
                if (is_array($this->attributes['eduPersonEntitlement'])) {
                    $this->entitlements = $this->attributes['eduPersonEntitlement'];
                } else {
                    $this->entitlements = [$this->attributes['eduPersonEntitlement']];
                }
            } else {
                $this->entitlements = [];
            }
        } else {
            throw new \Exception("No principal found!", 400);
        }
    }
479016
protected function doEncryptAttribute($key)
    {
        if ($this->shouldEncrypt($key) && ! $this->isEncrypted($this->attributes[$key])) {
            try {
                $this->attributes[$key] = $this->encryptedAttribute($this->attributes[$key]);
            } catch (EncryptException $e) {
            }
        }
    }
906902
protected function challenge($cb)
    {
        $this->onChallenge = $cb;
        $this->state = self::CONN_STATE_CHALLENGE_PACKET_SENT;
        $this->write(
            "Action: Challenge\r\n"
            . "AuthType: MD5\r\n"
            . "\r\n"
        );
    }
1358024
public function challengeResponse()
    {
        return pack('H*', md5(pack('C', $this->chapid) . $this->password . $this->challenge));
    }
348942
function putAuthAttributes()
    {
        $this->putAttribute(RADIUS_ACCT_SESSION_ID, $this->session_id);
        $this->putAttribute(RADIUS_ACCT_STATUS_TYPE, $this->status_type);
        if (isset($this->session_time) && $this->status_type == RADIUS_STOP) {
            $this->putAttribute(RADIUS_ACCT_SESSION_TIME, $this->session_time);
        }
        if (isset($this->authentic)) {
            $this->putAttribute(RADIUS_ACCT_AUTHENTIC, $this->authentic);
        }

    }
719535
protected function prepareForValidation(): void
    {
        $data = $this->all();

        $data['entity_id'] = $this->user($this->route('guard'))->getKey();
        $data['entity_type'] = $this->user($this->route('guard'))->getMorphClass();

        $this->replace($data);
    }
493213
public function prepare()
    {
        if (!$this->sessionBag->has(self::CSRF_TKN_NAME)) {
            $this->sessionBag->set(self::CSRF_TKN_NAME, $this->generateToken());
            $this->sessionBag->set(self::CSRF_TKN_TIME, time());
        }

        $this->prepared = true;
    }
997178
private function handleStrict(): void
    {
        if (!ini_get('session.use_strict_mode') || headers_sent()) {
            return;
        }

        $cookieName = session_name();
        if (empty($_COOKIE[$cookieName])) {
            return;
        }

        $sessionId = $_COOKIE[$cookieName];

        $identifier = $this->cryptProvider->makeSessionIdentifier($sessionId);

        if ($this->storageDriver->sessionExists($identifier)) {
            return;
        }

        $newSessionId = session_create_id();
        session_id($newSessionId);
    }
1155214
protected function insert()
    {
        $aggregate = $this->aggregate;

        $attributes = $aggregate->getRawAttributes();

        $keyName = $aggregate->getEntityMap()->getKeyName();

        // Check if the primary key is defined in the attributes
        if (array_key_exists($keyName, $attributes) && $attributes[$keyName] != null) {
            $this->query->insert($attributes);
        } else {
            // Prevent inserting with a null ID
            if (array_key_exists($keyName, $attributes)) {
                unset($attributes[$keyName]);
            }

            if (isset($attributes['attributes'])) {
                unset($attributes['attributes']);
            }

            $id = $this->query->insertGetId($attributes, $keyName);

            $aggregate->setEntityAttribute($keyName, $id);
        }
    }
866247
protected function _setChallengeHeaders()
    {
        if ($this->isProxyAuth()) {
            $statusCode = 407;
            $headerName = 'Proxy-Authenticate';
        } else {
            $statusCode = 401;
            $headerName = 'WWW-Authenticate';
        }

        // Send a challenge in each acceptable authentication scheme
        $this->response()->setStatusCode($statusCode);

        $headers = $this->response()->headers();
        $headers->insert(FactoryHttpHeader::of(array(
                $headerName => $this->_getAuthenticateChallengeHeader())
        ));

        // $headers->insert(FactoryHttpHeader::of( array('Authorization' => 'deleted')) );
    }
401214
public static function _init()
	{
		static::$crypter = new Crypt_AES();
		static::$hasher = new Crypt_Hash('sha256');

		// load the config
		\Config::load('crypt', true);
		static::$config = \Config::get('crypt', array ());

		// generate random crypto keys if we don't have them or they are incorrect length
		$update = false;
		foreach(array('crypto_key', 'crypto_iv', 'crypto_hmac') as $key)
		{
			if ( empty(static::$config[$key]) or (strlen(static::$config[$key]) % 4) != 0)
			{
				$crypto = '';
				for ($i = 0; $i < 8; $i++)
				{
					$crypto .= static::safe_b64encode(pack('n', mt_rand(0, 0xFFFF)));
				}
				static::$config[$key] = $crypto;
				$update = true;
			}
		}

		// update the config if needed
		if ($update === true)
		{
			try
			{
				\Config::save('crypt', static::$config);
			}
			catch (\FileAccessException $e)
			{
				// failed to write the config file, inform the user
				echo \View::forge('errors/crypt_keys', array(
					'keys' => static::$config
				));
				die();
			}
		}

		static::$crypter->enableContinuousBuffer();

		static::$hasher->setKey(static::safe_b64decode(static::$config['crypto_hmac']));
	}