-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Refactor 2FA from FOF to Joomla Core #11553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
240f12c
updated totp & yubikey templating to use JLayout
faynt0 e1a0876
removed FOF dependeny from Yubikey
faynt0 a60e5a3
refactored Totp class from fof package to libraries/encrypt package
2bc2b76
Merge remote-tracking branch 'origin/refactor_fof_to_core' into Refac…
faynt0 ddb7795
Merge remote-tracking branch 'origin/Feature_Refactor2FATemplateToJLa…
faynt0 2b0a95f
removed obsolete constructor
faynt0 7391252
cleaned phpcs errors
faynt0 9af2659
changed array for < PHP 5.4 compatibility
faynt0 0671a46
changed file and classname to match the autoload name convention
faynt0 0fdb34a
reverted layout changes due to B/C
faynt0 4bed2e5
Added proper attribution
faynt0 dc2655d
Use JPluginHelper to resolve the template path
faynt0 f68b544
Merge branch 'staging' into Refactor_2FA_to_Joomla_core
faynt0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,222 @@ | ||
| <?php | ||
| /** | ||
| * @package Joomla.Platform | ||
| * @subpackage Encrypt | ||
| * | ||
| * @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved. | ||
| * @license GNU General Public License version 2 or later; see LICENSE | ||
| */ | ||
|
|
||
|
|
||
| /** | ||
| * Base32 | ||
| * | ||
| * @since 1.0 | ||
| */ | ||
| class Base32 | ||
|
||
| { | ||
| /** | ||
| * CSRFC3548 | ||
| * | ||
| * The character set as defined by RFC3548 | ||
| * @link http://www.ietf.org/rfc/rfc3548.txt | ||
| */ | ||
| const CSRFC3548 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'; | ||
|
|
||
| /** | ||
| * str2bin | ||
| * | ||
| * Converts any ascii string to a binary string | ||
| * | ||
| * @param string $str The string you want to convert | ||
| * | ||
| * @return string String of 0's and 1's | ||
| */ | ||
| private function str2bin($str) | ||
| { | ||
| $chrs = unpack('C*', $str); | ||
|
|
||
| return vsprintf(str_repeat('%08b', count($chrs)), $chrs); | ||
| } | ||
|
|
||
| /** | ||
| * bin2str | ||
| * | ||
| * Converts a binary string to an ascii string | ||
| * | ||
| * @param string $str The string of 0's and 1's you want to convert | ||
| * | ||
| * @return string The ascii output | ||
| * | ||
| * @throws Exception | ||
| */ | ||
| private function bin2str($str) | ||
| { | ||
| if (strlen($str) % 8 > 0) | ||
| { | ||
| throw new Exception('Length must be divisible by 8'); | ||
| } | ||
|
|
||
| if (!preg_match('/^[01]+$/', $str)) | ||
| { | ||
| throw new Exception('Only 0\'s and 1\'s are permitted'); | ||
| } | ||
|
|
||
| preg_match_all('/.{8}/', $str, $chrs); | ||
| $chrs = array_map('bindec', $chrs[0]); | ||
|
|
||
| // I'm just being slack here | ||
| array_unshift($chrs, 'C*'); | ||
|
|
||
| return call_user_func_array('pack', $chrs); | ||
| } | ||
|
|
||
| /** | ||
| * fromBin | ||
| * | ||
| * Converts a correct binary string to base32 | ||
| * | ||
| * @param string $str The string of 0's and 1's you want to convert | ||
| * | ||
| * @return string String encoded as base32 | ||
| * | ||
| * @throws exception | ||
| */ | ||
| private function fromBin($str) | ||
| { | ||
| if (strlen($str) % 8 > 0) | ||
| { | ||
| throw new Exception('Length must be divisible by 8'); | ||
| } | ||
|
|
||
| if (!preg_match('/^[01]+$/', $str)) | ||
| { | ||
| throw new Exception('Only 0\'s and 1\'s are permitted'); | ||
| } | ||
|
|
||
| // Base32 works on the first 5 bits of a byte, so we insert blanks to pad it out | ||
| $str = preg_replace('/(.{5})/', '000$1', $str); | ||
|
|
||
| // We need a string divisible by 5 | ||
| $length = strlen($str); | ||
| $rbits = $length & 7; | ||
|
|
||
| if ($rbits > 0) | ||
| { | ||
| // Excessive bits need to be padded | ||
| $ebits = substr($str, $length - $rbits); | ||
| $str = substr($str, 0, $length - $rbits); | ||
| $str .= "000$ebits" . str_repeat('0', 5 - strlen($ebits)); | ||
| } | ||
|
|
||
| preg_match_all('/.{8}/', $str, $chrs); | ||
| $chrs = array_map(array($this, '_mapcharset'), $chrs[0]); | ||
|
|
||
| return join('', $chrs); | ||
| } | ||
|
|
||
| /** | ||
| * toBin | ||
| * | ||
| * Accepts a base32 string and returns an ascii binary string | ||
| * | ||
| * @param string $str The base32 string to convert | ||
| * | ||
| * @return string Ascii binary string | ||
| * | ||
| * @throws Exception | ||
| */ | ||
| private function toBin($str) | ||
| { | ||
| if (!preg_match('/^[' . self::CSRFC3548 . ']+$/', $str)) | ||
| { | ||
| throw new Exception('Must match character set'); | ||
| } | ||
|
|
||
| // Convert the base32 string back to a binary string | ||
| $str = join('', array_map(array($this, '_mapbin'), str_split($str))); | ||
|
|
||
| // Remove the extra 0's we added | ||
| $str = preg_replace('/000(.{5})/', '$1', $str); | ||
|
|
||
| // Unpad if nessicary | ||
| $length = strlen($str); | ||
| $rbits = $length & 7; | ||
|
|
||
| if ($rbits > 0) | ||
| { | ||
| $str = substr($str, 0, $length - $rbits); | ||
| } | ||
|
|
||
| return $str; | ||
| } | ||
|
|
||
| /** | ||
| * fromString | ||
| * | ||
| * Convert any string to a base32 string | ||
| * This should be binary safe... | ||
| * | ||
| * @param string $str The string to convert | ||
| * | ||
| * @return string The converted base32 string | ||
| */ | ||
| public function encode($str) | ||
| { | ||
| return $this->fromBin($this->str2bin($str)); | ||
| } | ||
|
|
||
| /** | ||
| * toString | ||
| * | ||
| * Convert any base32 string to a normal sctring | ||
| * This should be binary safe... | ||
| * | ||
| * @param string $str The base32 string to convert | ||
| * | ||
| * @return string The normal string | ||
| */ | ||
| public function decode($str) | ||
| { | ||
| $str = strtoupper($str); | ||
|
|
||
| return $this->bin2str($this->tobin($str)); | ||
| } | ||
|
|
||
| /** | ||
| * _mapcharset | ||
| * | ||
| * Used with array_map to map the bits from a binary string | ||
| * directly into a base32 character set | ||
| * | ||
| * @param string $str The string of 0's and 1's you want to convert | ||
| * | ||
| * @return string Resulting base32 character | ||
| * | ||
| * @access private | ||
| */ | ||
| private function _mapcharset($str) | ||
| { | ||
| // Huh! | ||
| $x = self::CSRFC3548; | ||
|
|
||
| return $x[bindec($str)]; | ||
| } | ||
|
|
||
| /** | ||
| * _mapbin | ||
| * | ||
| * Used with array_map to map the characters from a base32 | ||
| * character set directly into a binary string | ||
| * | ||
| * @param string $chr The caracter to map | ||
| * | ||
| * @return string String of 0's and 1's | ||
| * | ||
| * @access private | ||
| */ | ||
| private function _mapbin($chr) | ||
| { | ||
| return sprintf('%08b', strpos(self::CSRFC3548, $chr)); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this file a straight copy/paste out of the FOF library? If so, proper attribution must be given.