Файловый менеджер - Редактировать - /var/www/html/jakobo.zip
Ðазад
PK ! 沲� � hotp-php/README.markdownnu �Iw�� HOTP - PHP Based HMAC One Time Passwords ======================================== **What is HOTP**: HOTP is a class that simplifies One Time Password systems for PHP Authentication. The HOTP/TOTP Algorithms have been around for a bit, so this is a straightforward class to meet the test vector requirements. **What works with HOTP/TOTP**: It's been tested to the test vectors, and I've verified the time-sync hashes against the following: * Android: Mobile-OTP * iPhone: OATH Token **Why would I use this**: Who wouldn't love a simple drop-in class for HMAC Based One Time Passwords? It's a great extra layer of security (creating two-factor auth) and it's pretty darn zippy. **Okay you sold me. Give me some docs**: ```php use jakobo\HOTP\HOTP; // event based $result = HOTP::generateByCounter( $key, $counter ); // time based within a "window" of time $result = HOTP::generateByTime( $key, $window ); // same as generateByTime, but for $min windows before and $max windows after $result = HOTP::generateByTimeWindow( $key, $window, $min, $max ); ``` with `$result`, you can do all sorts of neat things... ```php $result->toString(); $result->toHex(); $result->doDec(); // how many digits in your OTP? $result->toHotp( $length ); ``` PK ! ?�}�~ ~ hotp-php/src/HOTP.phpnu �Iw�� <?php namespace jakobo\HOTP; /** * HOTP Class * Based on the work of OAuth, and the sample implementation of HMAC OTP * http://tools.ietf.org/html/draft-mraihi-oath-hmac-otp-04#appendix-D * @author Jakob Heuser (firstname)@felocity.com * @copyright 2011-2020 * @license BSD-3-Clause * @version 1.0 */ class HOTP { /** * Generate a HOTP key based on a counter value (event based HOTP) * @param string $key the key to use for hashing * @param int $counter the number of attempts represented in this hashing * @return HOTPResult a HOTP Result which can be truncated or output */ public static function generateByCounter( string $key, int $counter ): HOTPResult { // the counter value can be more than one byte long, // so we need to pack it down properly. $cur_counter = [ 0, 0, 0, 0, 0, 0, 0, 0 ]; for ( $i = 7; $i >= 0; $i-- ) { $cur_counter[$i] = pack( 'C*', $counter ); $counter = $counter >> 8; } $bin_counter = implode( $cur_counter ); // Pad to 8 chars if ( strlen( $bin_counter ) < 8 ) { $bin_counter = str_repeat( chr(0 ), 8 - strlen( $bin_counter ) ) . $bin_counter; } // HMAC $hash = hash_hmac( 'sha1', $bin_counter, $key ); return new HOTPResult( $hash ); } /** * Generate a HOTP key based on a timestamp and window size * @param string $key the key to use for hashing * @param int $window the size of the window a key is valid for in seconds * @param int|false $timestamp a timestamp to calculate for, defaults to time() * @return HOTPResult a HOTP Result which can be truncated or output */ public static function generateByTime( string $key, int $window, $timestamp = false ): HOTPResult { if ( !$timestamp && $timestamp !== 0 ) { // @codeCoverageIgnoreStart $timestamp = self::getTime(); // @codeCoverageIgnoreEnd } $counter = intval( $timestamp / $window) ; return self::generateByCounter( $key, $counter ); } /** * Generate a HOTP key collection based on a timestamp and window size * all keys that could exist between a start and end time will be included * in the returned array * @param string $key the key to use for hashing * @param int $window the size of the window a key is valid for in seconds * @param int $min the minimum window to accept before $timestamp * @param int $max the maximum window to accept after $timestamp * @param int|false $timestamp a timestamp to calculate for, defaults to time() * @return array of HOTPResult */ public static function generateByTimeWindow( string $key, int $window, int $min = -1, int $max = 1, $timestamp = false ): array { if ( !$timestamp && $timestamp !== 0 ) { // @codeCoverageIgnoreStart $timestamp = self::getTime(); // @codeCoverageIgnoreEnd } $counter = intval( $timestamp / $window ); $window = range( $min, $max ); $out = []; foreach ( $window as $value ) { $shift_counter = $counter + $value; $out[$shift_counter] = self::generateByCounter( $key, $shift_counter ); } return $out; } /** * Gets the current time * Ensures we are operating in UTC for the entire framework * Restores the timezone on exit. * @return int the current time * @codeCoverageIgnore */ public static function getTime(): int { // PHP's time is always UTC return time(); } } PK ! >|x' ' hotp-php/src/HOTPResult.phpnu �Iw�� <?php namespace jakobo\HOTP; /** * The HOTPResult Class converts an HOTP item to various forms * Supported formats include hex, decimal, string, and HOTP * @author Jakob Heuser (firstname)@felocity.com * @copyright 2011-2020 * @license BSD-3-Clause * @version 1.0 */ class HOTPResult { protected $hash; protected $decimal; protected $hex; /** * Build an HOTP Result * @param string $value the value to construct with * @codeCoverageIgnore */ public function __construct( string $value ) { // store raw $this->hash = $value; } /** * Returns the string version of the HOTP * @return string */ public function toString(): string { return $this->hash; } /** * Returns the hex version of the HOTP * @return string */ public function toHex(): string { if( !$this->hex ) { $this->hex = dechex( $this->toDec() ); } return $this->hex; } /** * Returns the decimal version of the HOTP * @return int */ public function toDec(): int { if( !$this->decimal ) { // store calculate decimal $hmac_result = []; // Convert to decimal foreach ( str_split( $this->hash,2 ) as $hex ) { $hmac_result[] = hexdec($hex); } $offset = $hmac_result[19] & 0xf; $this->decimal = ( ( ( $hmac_result[$offset+0] & 0x7f ) << 24 ) | ( ( $hmac_result[$offset+1] & 0xff ) << 16 ) | ( ( $hmac_result[$offset+2] & 0xff ) << 8 ) | ( $hmac_result[$offset+3] & 0xff ) ); } return $this->decimal; } /** * Returns the truncated decimal form of the HOTP * @param int $length the length of the HOTP to return * @return string */ public function toHOTP( int $length ): string { $str = str_pad( $this->toDec(), $length, "0", STR_PAD_LEFT ); return substr( $str, ( -1 * $length ) ); } } PK ! �fg� � hotp-php/LICENSEnu �Iw�� Copyright (c) 2008-2020, Jakob Heuser All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of HOTP-PHP nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY Jakob Heuser ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Jakob Heuser BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. PK ! 沲� � hotp-php/README.markdownnu �Iw�� PK ! ?�}�~ ~ ) hotp-php/src/HOTP.phpnu �Iw�� PK ! >|x' ' � hotp-php/src/HOTPResult.phpnu �Iw�� PK ! �fg� � ^ hotp-php/LICENSEnu �Iw�� PK X V"