partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit 5ce385552608d34af1cf57497ca1d0d3c0970692
parent 0d9da8e9651a38c6f19caee11b0cfca81d8103a1
Author: Felicitus <felicitus@felicitus.org>
Date:   Sat,  1 Aug 2015 19:24:03 +0200

Refactored authentification to use WSSE headers and FOSUserBundle

Diffstat:
Mapp/AppKernel.php | 3+++
Mapp/config/config.yml | 5+++++
Mapp/config/security.yml | 34++++++++++++++++++++++++++++++++++
Mcomposer.json | 4+++-
Mcomposer.lock | 141+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
Msrc/PartKeepr/AuthBundle/Console/Command/CreateUserCommand.php | 2+-
Msrc/PartKeepr/AuthBundle/Console/Command/SetPasswordCommand.php | 2+-
Msrc/PartKeepr/AuthBundle/Controller/DefaultController.php | 46+++++++++++++++++++++++++++++++++++++---------
Msrc/PartKeepr/AuthBundle/DataFixtures/LoadUserData.php | 2+-
Asrc/PartKeepr/AuthBundle/Entity/User.php | 20++++++++++++++++++++
Dsrc/PartKeepr/AuthBundle/Entity/User/User.php | 267-------------------------------------------------------------------------------
Dsrc/PartKeepr/AuthBundle/Entity/UserManager.php | 103-------------------------------------------------------------------------------
Msrc/PartKeepr/FrontendBundle/Controller/IndexController.php | 2+-
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/Session/SessionManager.js | 258++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Data/HydraProxy.js | 9+++++++++
Msrc/PartKeepr/FrontendBundle/Resources/public/js/PartKeepr.js | 69+++++++++++++--------------------------------------------------------
Asrc/PartKeepr/FrontendBundle/Resources/public/js/Util/Crypto/bcrypt.js | 601+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/PartKeepr/FrontendBundle/Resources/public/js/Util/Crypto/core.js | 707+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/PartKeepr/FrontendBundle/Resources/public/js/Util/Crypto/enc-base64.js | 104+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/PartKeepr/FrontendBundle/Resources/public/js/Util/Crypto/isaac.js | 240+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/PartKeepr/FrontendBundle/Resources/public/js/Util/Crypto/sha1.js | 131+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/PartKeepr/FrontendBundle/Resources/public/js/Util/Crypto/sha512.js | 304+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/PartKeepr/FrontendBundle/Resources/public/js/Util/Crypto/x64-core.js | 285+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/PartKeepr/FrontendBundle/Resources/views/index.html.twig | 7+++++++
Msrc/PartKeepr/TipOfTheDayBundle/Entity/TipOfTheDayHistory.php | 6+++---
Msrc/backend/PartKeepr/Part/PartService.php | 2+-
Msrc/backend/PartKeepr/PartKeepr.php | 2+-
Msrc/backend/PartKeepr/Project/Project.php | 7++++---
Msrc/backend/PartKeepr/Service/Service.php | 4++--
Msrc/backend/PartKeepr/Service/ServiceManager.php | 2+-
Msrc/backend/PartKeepr/Session/Session.php | 7++++---
Msrc/backend/PartKeepr/Session/SessionManager.php | 2+-
Msrc/backend/PartKeepr/Setup/UserSetup.php | 4++--
Msrc/backend/PartKeepr/Stock/StockEntry.php | 9+++++----
Msrc/backend/PartKeepr/Stock/StockService.php | 2+-
Msrc/backend/PartKeepr/User/UserService.php | 1+
Msrc/backend/PartKeepr/UserPreference/Exceptions/UserPreferenceNotFoundException.php | 2+-
Msrc/backend/PartKeepr/UserPreference/UserPreference.php | 32+++++++++++++++++++-------------
Msrc/backend/PartKeepr/UserPreference/UserPreferenceService.php | 2+-
39 files changed, 2857 insertions(+), 573 deletions(-)

diff --git a/app/AppKernel.php b/app/AppKernel.php @@ -56,12 +56,15 @@ class AppKernel extends Kernel new Symfony\Bundle\MonologBundle\MonologBundle(), new Symfony\Bundle\AsseticBundle\AsseticBundle(), new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), + new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(), new FOS\RestBundle\FOSRestBundle(), + new FOS\UserBundle\FOSUserBundle(), new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), new Nelmio\ApiDocBundle\NelmioApiDocBundle(), new \Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(), new PartKeepr\DoctrineReflectionBundle\PartKeeprDoctrineReflectionBundle(), new PartKeepr\RESTBundle\PartKeeprRESTBundle(), + new Escape\WSSEAuthenticationBundle\EscapeWSSEAuthenticationBundle(), //new PartKeepr\ApiDocBundle\PartKeeprApiDocBundle(), new Dunglas\ApiBundle\DunglasApiBundle(), new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(), diff --git a/app/config/config.yml b/app/config/config.yml @@ -100,6 +100,11 @@ stof_doctrine_extensions: twig: exception_controller: 'FOS\RestBundle\Controller\ExceptionController::showAction' +fos_user: + db_driver: orm + firewall_name: main + user_class: PartKeepr\AuthBundle\Entity\User + doctrine_migrations: dir_name: %kernel.root_dir%/../src/PartKeepr/CoreBundle/DoctrineMigrations namespace: PartKeepr\CoreBundle\DoctrineMigrations diff --git a/app/config/security.yml b/app/config/security.yml @@ -0,0 +1,33 @@ +security: + encoders: + FOS\UserBundle\Model\UserInterface: + algorithm: sha512 + iterations: 1 + + role_hierarchy: + ROLE_ADMIN: ROLE_USER + ROLE_SUPER_ADMIN: ROLE_ADMIN + + providers: + fos_userbundle: + id: fos_user.user_provider.username + + firewalls: + login: + pattern: ^/auth/getSalt + security: false + main: + pattern: ^/api/.* + wsse: + realm: "Secured with WSSE" #identifies the set of resources to which the authentication information will apply (WWW-Authenticate) + profile: "UsernameToken" #WSSE profile (WWW-Authenticate) + encoder: #digest algorithm + algorithm: sha512 + encodeHashAsBase64: true + iterations: 1 + + access_control: + - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY } + - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY } + - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY } + - { path: ^/admin/, role: ROLE_ADMIN }+ \ No newline at end of file diff --git a/composer.json b/composer.json @@ -47,7 +47,9 @@ "moontoast/math": "^1.1", "doctrine/migrations": "dev-master", "doctrine/doctrine-migrations-bundle": "dev-master", - "stof/doctrine-extensions-bundle": "~1.1@dev" + "stof/doctrine-extensions-bundle": "~1.1@dev", + "friendsofsymfony/user-bundle": "~2.0@dev", + "escapestudios/wsse-authentication-bundle": "2.3.x-dev" }, "require-dev": { "phpunit/phpunit": "4.7.*", diff --git a/composer.lock b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "ac03d457735e05a64fe83e65feb4c8db", + "hash": "0b52ddf9f844bd369edccc24ab973bb4", "packages": [ { "name": "behat/transliterator", @@ -872,7 +872,7 @@ }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/DoctrineMigrationsBundle/zipball/861d3564c03b3867845ffd87d9b19f49dc673c69", + "url": "https://api.github.com/repos/doctrine/DoctrineMigrationsBundle/zipball/ac96a0e2a09ebf5655b087ff9bc23809a7b4899f", "reference": "861d3564c03b3867845ffd87d9b19f49dc673c69", "shasum": "" }, @@ -1105,7 +1105,7 @@ }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/migrations/zipball/78954cce4962a4655ff47c0751eb78021fbaf2cc", + "url": "https://api.github.com/repos/doctrine/migrations/zipball/ce9f840f76e725a4b2701ca10def178142878c6b", "reference": "78954cce4962a4655ff47c0751eb78021fbaf2cc", "shasum": "" }, @@ -1246,7 +1246,7 @@ }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/dunglas/DunglasApiBundle/zipball/2229fcf0a32c17af89732fac58d47854a10a5214", + "url": "https://api.github.com/repos/dunglas/DunglasApiBundle/zipball/c88496b2591ae4ec936649adaa543a9cf210b0e2", "reference": "2229fcf0a32c17af89732fac58d47854a10a5214", "shasum": "" }, @@ -1366,6 +1366,64 @@ "time": "2015-04-03 17:49:18" }, { + "name": "escapestudios/wsse-authentication-bundle", + "version": "dev-master", + "target-dir": "Escape/WSSEAuthenticationBundle", + "source": { + "type": "git", + "url": "https://github.com/escapestudios/EscapeWSSEAuthenticationBundle.git", + "reference": "013b7d36c46a950c0a4d7f7b3b824ce7f64ea904" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/escapestudios/EscapeWSSEAuthenticationBundle/zipball/013b7d36c46a950c0a4d7f7b3b824ce7f64ea904", + "reference": "013b7d36c46a950c0a4d7f7b3b824ce7f64ea904", + "shasum": "" + }, + "require": { + "doctrine/common": "~2.2", + "php": ">=5.3.2", + "symfony/framework-bundle": "~2.3", + "symfony/security-bundle": "~2.3" + }, + "require-dev": { + "symfony/finder": "~2.3" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-master": "2.3.x-dev" + } + }, + "autoload": { + "psr-0": { + "Escape\\WSSEAuthenticationBundle": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "David Joos", + "email": "david@escapestudios.com" + }, + { + "name": "Community contributors", + "homepage": "https://github.com/escapestudios/EscapeWSSEAuthenticationBundle/graphs/contributors" + } + ], + "description": "Symfony2 bundle to implement WSSE authentication", + "homepage": "https://github.com/escapestudios/EscapeWSSEAuthenticationBundle", + "keywords": [ + "Authentication", + "bundle", + "wsse" + ], + "time": "2015-04-10 17:37:02" + }, + { "name": "fortawesome/font-awesome", "version": "v4.3.0", "source": { @@ -1498,6 +1556,73 @@ "time": "2015-06-16 08:39:26" }, { + "name": "friendsofsymfony/user-bundle", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/FriendsOfSymfony/FOSUserBundle.git", + "reference": "5d7017d35f73cdb74e069f9d607cd0448d305078" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/FriendsOfSymfony/FOSUserBundle/zipball/5d7017d35f73cdb74e069f9d607cd0448d305078", + "reference": "5d7017d35f73cdb74e069f9d607cd0448d305078", + "shasum": "" + }, + "require": { + "php": ">=5.3.2", + "symfony/form": "~2.3", + "symfony/framework-bundle": "~2.3", + "symfony/security-bundle": "~2.3", + "symfony/twig-bundle": "~2.3" + }, + "require-dev": { + "doctrine/doctrine-bundle": "~1.3", + "swiftmailer/swiftmailer": "~4.3|~5", + "symfony/validator": "~2.3", + "symfony/yaml": "~2.3", + "willdurand/propel-typehintable-behavior": "~1.0" + }, + "suggest": { + "willdurand/propel-typehintable-behavior": "Needed when using the propel implementation" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "FOS\\UserBundle\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Christophe Coevoet", + "email": "stof@notk.org" + }, + { + "name": "FriendsOfSymfony Community", + "homepage": "https://github.com/friendsofsymfony/FOSUserBundle/contributors" + }, + { + "name": "Thibault Duplessis", + "email": "thibault.duplessis@gmail.com" + } + ], + "description": "Symfony FOSUserBundle", + "homepage": "http://friendsofsymfony.github.com", + "keywords": [ + "User management" + ], + "time": "2015-07-31 13:22:19" + }, + { "name": "gedmo/doctrine-extensions", "version": "v2.3.12", "source": { @@ -2336,7 +2461,7 @@ }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ramsey/uuid/zipball/32d2a7ffe9aca7370c98f092f86c0e16f2b2d15b", + "url": "https://api.github.com/repos/ramsey/uuid/zipball/41f8db48808eee34c5e0b1199283dcce968fd117", "reference": "32d2a7ffe9aca7370c98f092f86c0e16f2b2d15b", "shasum": "" }, @@ -2796,7 +2921,7 @@ }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/DoctrineBridge/zipball/ebb229c16d04ef5548551a1294d3a7c219ef39ca", + "url": "https://api.github.com/repos/symfony/DoctrineBridge/zipball/8861d96cfe54e8ed679a20b0b98265bf80e194b6", "reference": "ebb229c16d04ef5548551a1294d3a7c219ef39ca", "shasum": "" }, @@ -4535,12 +4660,14 @@ "doctrine/migrations": 20, "doctrine/doctrine-migrations-bundle": 20, "stof/doctrine-extensions-bundle": 20, + "friendsofsymfony/user-bundle": 20, + "escapestudios/wsse-authentication-bundle": 20, "codeclimate/php-test-reporter": 20 }, "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=5.3.3" + "php": ">=5.6.0" }, "platform-dev": [] } diff --git a/src/PartKeepr/AuthBundle/Console/Command/CreateUserCommand.php b/src/PartKeepr/AuthBundle/Console/Command/CreateUserCommand.php @@ -2,7 +2,7 @@ namespace PartKeepr\AuthBundle\Console\Command; use Doctrine\ORM\EntityManager; -use PartKeepr\AuthBundle\Entity\User\User; +use PartKeepr\AuthBundle\Entity\User; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; diff --git a/src/PartKeepr/AuthBundle/Console/Command/SetPasswordCommand.php b/src/PartKeepr/AuthBundle/Console/Command/SetPasswordCommand.php @@ -2,7 +2,7 @@ namespace PartKeepr\AuthBundle\Console\Command; use Doctrine\ORM\EntityManager; -use PartKeepr\AuthBundle\Entity\User\User; +use PartKeepr\AuthBundle\Entity\User; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; diff --git a/src/PartKeepr/AuthBundle/Controller/DefaultController.php b/src/PartKeepr/AuthBundle/Controller/DefaultController.php @@ -2,19 +2,19 @@ namespace PartKeepr\AuthBundle\Controller; -use FOS\RestBundle\Controller\FOSRestController; -use PartKeepr\AuthBundle\Response\LoginResponse; -use Sensio\Bundle\FrameworkExtraBundle\Configuration as Routing; -use PartKeepr\AuthBundle\Entity\User\User; -use Nelmio\ApiDocBundle\Annotation\ApiDoc; -use FOS\RestBundle\Controller\Annotations\View; -use PartKeepr\Session\SessionManager; use FOS\RestBundle\Controller\Annotations\RequestParam; +use FOS\RestBundle\Controller\Annotations\View; +use FOS\RestBundle\Controller\FOSRestController; use FOS\RestBundle\Request\ParamFetcher; -use PartKeepr\AuthBundle\Entity\UserManager; +use Nelmio\ApiDocBundle\Annotation\ApiDoc; +use PartKeepr\AuthBundle\Entity\User; use PartKeepr\AuthBundle\Entity\User\Exceptions\InvalidLoginDataException; -use PartKeepr\AuthBundle\Validator\Constraints\Username; +use PartKeepr\AuthBundle\Entity\UserManager; +use PartKeepr\AuthBundle\Response\LoginResponse; use PartKeepr\AuthBundle\Validator\Constraints\PasswordMD5Hash; +use PartKeepr\AuthBundle\Validator\Constraints\Username; +use PartKeepr\Session\SessionManager; +use Sensio\Bundle\FrameworkExtraBundle\Configuration as Routing; use Symfony\Component\HttpKernel\Exception\HttpException; class DefaultController extends FOSRestController @@ -60,4 +60,32 @@ class DefaultController extends FOSRestController return $loginResponse; } + + /** + * Retrieves the salt for a given user + * + * @Routing\Route("/auth/getSalt", defaults={"method" = "get","_format" = "json"}) + * @Routing\Method({"POST"}) + * @RequestParam(name="username", strict=true, description="The username, 3-50 characters. Allowed characters: a-z, A-Z, 0-9, an underscore (_), a backslash (\), a slash (/), a dot (.) or a dash (-)", requirements=@Username, allowBlank=false) + * @View() + * + * @param ParamFetcher $paramFetcher + * + * @return LoginResponse + * @throws InvalidLoginDataException + */ + public function getSaltAction (ParamFetcher $paramFetcher) { + $entityManager = $this->getDoctrine()->getManager(); + + $repository = $entityManager->getRepository( + 'PartKeepr\AuthBundle\Entity\User' + ); + + /** + * @var $user User + */ + $user = $repository->findOneBy(array("username" => $paramFetcher->get("username"))); + + return $user->getSalt(); + } } \ No newline at end of file diff --git a/src/PartKeepr/AuthBundle/DataFixtures/LoadUserData.php b/src/PartKeepr/AuthBundle/DataFixtures/LoadUserData.php @@ -3,7 +3,7 @@ namespace PartKeepr\AuthBundle\DataFixtures; use Doctrine\Common\DataFixtures\FixtureInterface; use Doctrine\Common\Persistence\ObjectManager; -use PartKeepr\AuthBundle\Entity\User\User; +use PartKeepr\AuthBundle\Entity\User; class LoadUserData implements FixtureInterface { public function load (ObjectManager $manager) { diff --git a/src/PartKeepr/AuthBundle/Entity/User.php b/src/PartKeepr/AuthBundle/Entity/User.php @@ -0,0 +1,19 @@ +<?php +namespace PartKeepr\AuthBundle\Entity; + +use Doctrine\ORM\Mapping as ORM; +use FOS\UserBundle\Model\User as BaseUser; + +/** + * @ORM\Entity + * @ORM\Table(name="PartKeeprUser") + */ +class User extends BaseUser +{ + /** + * @ORM\Id + * @ORM\Column(type="integer") + * @ORM\GeneratedValue(strategy="AUTO") + */ + protected $id; +}+ \ No newline at end of file diff --git a/src/PartKeepr/AuthBundle/Entity/User/User.php b/src/PartKeepr/AuthBundle/Entity/User/User.php @@ -1,266 +0,0 @@ -<?php -namespace PartKeepr\AuthBundle\Entity\User; - -use Doctrine\ORM\Mapping as ORM; -use PartKeepr\PartKeepr; -use PartKeepr\UserPreference\UserPreference; -use PartKeepr\Util\BaseEntity; -use PartKeepr\Util\Deserializable; -use PartKeepr\Util\Serializable; - -/** @ORM\Entity @ORM\Table(name="PartKeeprUser") */ -class User extends BaseEntity implements Serializable, Deserializable { - /** @ORM\Column(length=50,unique=true) */ - private $username; - - /** @ORM\Column(length=32) */ - private $password; - - /** @ORM\Column(type="boolean") */ - private $admin; - - /** @ORM\Column(type="datetime",nullable=true) */ - private $lastSeen; - - /** - * Creates a new user object. - * - * @param string $username The username to set (optional) - * @param string $password The password to set (optional) - */ - public function __construct ($username = null, $password = null) { - if ($username !== null) { - $this->setUsername($username); - } - - if ($password !== null) { - $this->setPassword($password); - } - - $this->setAdmin(false); - } - - /** - * Sets the username. - * - * @param string $username The username to set. - * @return nothing - */ - public function setUsername ($username) { - $this->username = $username; - } - - /** - * Sets the raw username, without replacing any special chars. - * - * This method should only be used for building a temporary user - * for login checks. - * - * @param string $username The raw username - * @return nothing - */ - public function setRawUsername ($username) { - $this->username = $username; - } - - /** - * Returns the username. - * @param none - * @return string The username - */ - public function getUsername () { - return $this->username; - } - - /** - * Sets the admin flag - * @param boolean $bAdmin True if the user is an admin, false otherwise - */ - public function setAdmin ($bAdmin) { - $this->admin = (boolean)$bAdmin; - } - - /** - * Returns the admin flag - * @return boolean True if the user is an admin - */ - public function isAdmin () { - return $this->admin; - } - - /** - * Sets the user's password. Automatically - * applies md5 hashing. - * - * @param string $password The unencrypted password - */ - public function setPassword ($password) { - $this->setHashedPassword(md5($password)); - } - - /** - * Returns the user's md5-hashed password. - * @param none - * @return string The md5-hashed password - */ - public function getHashedPassword () { - return $this->password; - } - - /** - * Sets the user's password. Expects a hash - * and does not apply md5 hasing. - * - * @param string $hashedPassword - */ - public function setHashedPassword ($hashedPassword) { - $this->password = $hashedPassword; - } - - /** - * Compares the given un-hashed password with the - * object's hashed password. - * - * - * @param string $password The unhashed password - * @return boolean true if the passwords match, false otherwise - */ - public function comparePassword ($password) { - return $this->compareHashedPassword(md5($password)); - } - - /** - * Compares the given hashed password with the object's - * hashed password. - * - * @param string $hashedPassword The md5-hashed password - * @return boolean true if the passwords match, false otherwise - */ - public function compareHashedPassword ($hashedPassword) { - if ($hashedPassword == $this->password) { - return true; - } else { - return false; - } - } - - /** - * Updates the last seen field to the current time. - */ - public function updateSeen() { - $this->lastSeen = new \DateTime("now"); - } - - /** - * Retrieve the last seen flag for a user. - * @return \DateTime - */ - public function getLastSeen() { - return $this->lastSeen; - } - - /** - * Serializes the user object and returns it as array, suitable - * to process via json_encode. - * @param none - * @return array An array containing the object information - */ - public function serialize () { - return array( - "id" => $this->getId(), - "username" => $this->getUsername() - ); - } - - /** - * Deserializes the user - * @param array $parameters The array with the parameters to set - */ - public function deserialize (array $parameters) { - foreach ($parameters as $key => $value) { - switch ($key) { - case "username": - $this->setUsername($value); - break; - case "password": - if ($value !== "") { - $this->setPassword($value); - } - break; - } - } - } - - /** - * Sets a user preference - * - * @param string $preferenceKey The preference key - * @param string $preferenceValue The preference value - * @throws EntityNotPersistantException Thrown if the entity is not persistant - */ - public function setPreference ($preferenceKey, $preferenceValue) { - return UserPreference::setPreference($this, $preferenceKey, $preferenceValue); - } - - /** - * Returns a given preference object - * - * @param string $preferenceKey The preference key - * @return UserPreference The user preference object - * @throws UserPreferenceNotFoundException If the preference key was not found - * @throws EntityNotPersistantException Thrown if the entity is not persistant - */ - public function getPreference ($preferenceKey) { - return UserPreference::getPreference($this, $preferenceKey); - } - - /** - * Returns a given preference value - * - * @param string $preferenceKey The preference key - * @return UserPreference The user preference object - * @throws UserPreferenceNotFoundException If the preference key was not found - * @throws EntityNotPersistantException Thrown if the entity is not persistant - */ - public function getPreferenceValue ($preferenceKey) { - return UserPreference::getPreferenceValue($this, $preferenceKey); - } - - /** - * Deletes the given preference - * - * @param string $preferenceKey The preference key - * @return UserPreference The user preference object - * @throws UserPreferenceNotFoundException If the preference key was not found - * @throws EntityNotPersistantException Thrown if the entity is not persistant - */ - public function deletePreference ($preferenceKey) { - UserPreference::deletePreference($this, $preferenceKey); - } - - /** - * Returns all user preferences for this user - * - * @param none - * @return UserPreference[] An array of UserPreference objects - * @throws EntityNotPersistantException Thrown if the entity is not persistant - */ - public function getPreferences () { - return UserPreference::getPreferences($this); - } - /** - * Loads a user by name. - * - * @param $username string The username to query - * @return User A user object - * @throws Doctrine\ORM\NoResultException If no user was found - */ - public static function loadByName ($username) { - $dql = "SELECT u FROM PartKeepr\AuthBundle\Entity\User\User u WHERE u.username = :username"; - - $query = PartKeepr::getEM()->createQuery($dql); - $query->setParameter("username", $username); - - return $query->getSingleResult(); - } -}- \ No newline at end of file diff --git a/src/PartKeepr/AuthBundle/Entity/UserManager.php b/src/PartKeepr/AuthBundle/Entity/UserManager.php @@ -1,102 +0,0 @@ -<?php -namespace PartKeepr\AuthBundle\Entity; - -use PartKeepr\AuthBundle\Entity\User\Exceptions\InvalidLoginDataException; -use PartKeepr\AuthBundle\Entity\User\Exceptions\UserAlreadyExistsException; -use PartKeepr\AuthBundle\Entity\User\Exceptions\UserNotFoundException; -use PartKeepr\AuthBundle\Entity\User\User; -use PartKeepr\Category\CategoryManager; -use PartKeepr\Manager\AbstractManager; -use PartKeepr\PartKeepr; - -class UserManager extends AbstractManager { - public function getEntityName () { - return 'PartKeepr\AuthBundle\Entity\User\User'; - } - - public function getQueryFields () { - return array("id","username"); - } - - public function getDefaultSortField () { - return "username"; - } - - /** - * Checks if the passed user already exists. - * - * @param $username string The username to check - */ - public function userExists ($username) { - $dql = "SELECT COUNT(u) FROM PartKeepr\AuthBundle\Entity\User\User u WHERE u.username = :name"; - - $query = PartKeepr::getEM()->createQuery($dql); - $query->setParameter("name", $username); - - $count = $query->getSingleScalarResult(); - - if ($count == 0) { - return false; - } else { - return true; - } - } - - /** - * Creates the given user. Checks if the user already exists - * - * @param User $user The user to create - * @throws UserAlreadyExistsException - */ - public function createUser (User $user) { - if ($this->userExists($user->getUsername())) { - throw new UserAlreadyExistsException($user->getUsername()); - } - - PartKeepr::getEM()->persist($user); - PartKeepr::getEM()->flush(); - } - - /** - * Returns the user for a given user id - * @param integer $id The user id - */ - public function getUser ($id) { - return User::loadById($id); - } - - /** - * Deletes an user by id - * @param int $id The user's id - */ - public function deleteUser ($id) { - $user = User::loadById($id); - - PartKeepr::getEM()->remove($user); - PartKeepr::getEM()->flush(); - } - - /** - * Authenticates the given user. If successful, an instance - * of the user is returned. - * - * @param User $user The user to authenticate - * @throws InvalidLoginDataException Thrown if the user's credentials are not valid - */ - public function authenticate (User $user) { - $result = PartKeepr::getEM() - ->getRepository("PartKeepr\AuthBundle\Entity\User\User") - ->findOneBy( - array( - "username" => $user->getUsername(), - "password" => $user->getHashedPassword() - ) - ); - - if ($result == null) { - throw new InvalidLoginDataException(); - } else { - return $result; - } - } -}- \ No newline at end of file diff --git a/src/PartKeepr/FrontendBundle/Controller/IndexController.php b/src/PartKeepr/FrontendBundle/Controller/IndexController.php @@ -3,7 +3,7 @@ namespace PartKeepr\FrontendBundle\Controller; use Doctrine\ORM\NoResultException; -use PartKeepr\AuthBundle\Entity\User\User; +use PartKeepr\AuthBundle\Entity\User; use PartKeepr\PartKeepr; use PartKeepr\Session\SessionManager; use PartKeepr\Util\Configuration; diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Session/SessionManager.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Session/SessionManager.js @@ -2,95 +2,175 @@ * Represents a session against the PartKeepr Server. */ Ext.define("PartKeepr.SessionManager", { - extend: 'Ext.util.Observable', - - /** - * Holds the current session ID, or null if no session is active - * - * @var string - */ - session: null, - - /** - * Holds an instance of the login dialog, or "null" if no login dialog is active. - * - * @var object - */ - loginDialog: null, - - - /** - * Constructs a new SessionManager. - * - * @param config Optional: Specifies a configuration object - */ - constructor: function(config){ - this.callParent(arguments); - }, - /** - * Creates and shows the login dialog, as well as setting up any event handlers. - */ - login: function (username, password) { - this.loginDialog = Ext.create("PartKeepr.LoginDialog"); - - if (username && password) { - this.onLogin(username, password); - } else { - this.loginDialog.on("login", this.onLogin, this); - this.loginDialog.show(); + extend: 'Ext.util.Observable', + + /** + * Holds the current session ID, or null if no session is active + * + * @var string + */ + session: null, + + /** + * Holds an instance of the login dialog, or "null" if no login dialog is active. + * + * @var object + */ + loginDialog: null, + + + /** + * Constructs a new SessionManager. + * + * @param config Optional: Specifies a configuration object + */ + constructor: function (config) + { + this.callParent(arguments); + }, + generateNonce: function (length) + { + var nonceChars = "0123456789abcdef"; + var result = ""; + for (var i = 0; i < length; i++) { + result += nonceChars.charAt(Math.floor(Math.random() * nonceChars.length)); + } + return result; + }, + getW3CDate: function (date) + { + var yyyy = date.getUTCFullYear(); + var mm = (date.getUTCMonth() + 1); + if (mm < 10) { + mm = "0" + mm; } - }, - /** - * Removes the current session. - */ - logout: function () { - this.session = null; - }, - /** - * Callback from the login dialog when the "login" button was clicked. - * - * @param username The username, as entered in the login dialog - * @param password The password, as entered - */ - onLogin: function (username, password) { - var k = new PartKeepr.ServiceCall("auth", "login"); - k.setParameter("username", username); - k.setParameter("password", md5(password)); - - k.enableAnonymous(); - k.setHandler(Ext.bind(this.onAfterLogin, this)); - k.doCall(); - }, - /** - * Callback when the service call is complete. - * - * @param response The session ID - */ - onAfterLogin: function (response) { + var dd = (date.getUTCDate()); + if (dd < 10) { + dd = "0" + dd; + } + var hh = (date.getUTCHours()); + if (hh < 10) { + hh = "0" + hh; + } + var mn = (date.getUTCMinutes()); + if (mn < 10) { + mn = "0" + mn; + } + var ss = (date.getUTCSeconds()); + if (ss < 10) { + ss = "0" + ss; + } + return yyyy + "-" + mm + "-" + dd + "T" + hh + ":" + mn + ":" + ss + "Z"; + }, + /** + * Creates and shows the login dialog, as well as setting up any event handlers. + */ + login: function (username, password) + { + this.loginDialog = Ext.create("PartKeepr.LoginDialog"); + + if (username && password) { + this.onLogin(username, password); + } else { + this.loginDialog.on("login", this.onLogin, this); + this.loginDialog.show(); + } + }, + onSaltRetrieved: function (salt) + { + this.salt = salt; + + + this.secret = CryptoJS.enc.Base64.stringify(CryptoJS.SHA512(this.password + "{" + this.salt + "}")); + this.fireEvent("login"); + }, + getWSSE: function () { + var nonce = this.generateNonce(16); + var nonce64 = base64_encode(nonce); + var created = this.getW3CDate(new Date()); + + var digest = this.encodePassword(nonce + created + this.secret, this.salt, 1); + return "UsernameToken Username=\"" + + this.username + "\", PasswordDigest=\"" + + digest + "\", Nonce=\"" + + nonce64 + "\", Created=\"" + + created + "\""; + }, + mergePasswordAndSalt: function (raw, salt) + { + "use strict"; + return raw + "{" + salt + "}"; + }, + encodePassword: function (raw, salt, iterations) + { + "use strict"; + var salted = this.mergePasswordAndSalt(raw, salt); + + var digest = CryptoJS.SHA512(salted); + + for (var i = 1; i < digest; i++) { + digest = CryptoJS.SHA512(digest + salted); + } + + return CryptoJS.enc.Base64.stringify(digest); + }, + /** + * Removes the current session. + */ + logout: function () + { + this.session = null; + }, + /** + * Callback from the login dialog when the "login" button was clicked. + * + * @param username The username, as entered in the login dialog + * @param password The password, as entered + */ + onLogin: function (username, password) + { + this.username = username; + this.password = password; + + var k = new PartKeepr.ServiceCall("auth", "getSalt"); + k.setParameter("username", username); + k.setHandler(Ext.bind(this.onSaltRetrieved, this)); + k.doCall(); + + }, + /** + * Callback when the service call is complete. + * + * @param response The session ID + */ + onAfterLogin: function (response) + { console.log(response); - this.setSession(response.sessionId); - this.loginDialog.destroy(); - - PartKeepr.getApplication().setAdmin(response.isAdmin); - PartKeepr.getApplication().setUsername(response.username); - - PartKeepr.getApplication().setInitialUserPreferences(response.userPreferences); - - this.fireEvent("login"); - - }, - /** - * Sets the session - */ - setSession: function (sessionid) { - this.session = sessionid; - }, - /** - * Returns the current session - * - * @returns the session, or null if no session is available - */ - getSession: function () { - return this.session; - } + this.setSession(response.sessionId); + this.loginDialog.destroy(); + + PartKeepr.getApplication().setAdmin(response.isAdmin); + PartKeepr.getApplication().setUsername(response.username); + + PartKeepr.getApplication().setInitialUserPreferences(response.userPreferences); + + this.fireEvent("login"); + + }, + /** + * Sets the session + */ + setSession: function (sessionid) + { + this.session = sessionid; + }, + /** + * Returns the current session + * + * @returns the session, or null if no session is available + */ + getSession: function () + { + return this.session; + } }); \ No newline at end of file diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Data/HydraProxy.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Data/HydraProxy.js @@ -12,6 +12,8 @@ Ext.define("PartKeepr.data.HydraProxy", { limitParam: "itemsPerPage", defaultListenerScope: true, sortParam: "order", + headers: { + }, /** * An ID which should be ignored when loading items. Usually we use the item ID as URL as per JSON-LD spec, @@ -33,6 +35,13 @@ Ext.define("PartKeepr.data.HydraProxy", { this.showException(response); } }, + getHeaders: function () { + var headers = this.callParent(arguments); + + headers["X-WSSE"] = PartKeepr.getApplication().getSessionManager().getWSSE(); + + return headers; + }, buildUrl: function (request) { var operation = request.getOperation(); diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/PartKeepr.js b/src/PartKeepr/FrontendBundle/Resources/public/js/PartKeepr.js @@ -51,51 +51,8 @@ Ext.application({ * enables the menu bar and creates the stores+loads them. */ onLogin: function () { - var session = new Ext.data.Session(); - this.siPrefixStore = Ext.create("Ext.data.Store", - { - storeId: 'myStore', - model: 'PartKeepr.SiPrefixBundle.Entity.SiPrefix', - pageSize: 999, - autoLoad: true - }); - - this.fooStore = Ext.create("Ext.data.Store", - { - session: session, - model: 'PartKeepr.UnitBundle.Entity.Unit', - pageSize: 30, - autoLoad: false - }); - - this.fooStore2 = Ext.create("Ext.data.Store", - { - session: session, - model: 'PartKeepr.UnitBundle.Entity.Unit', - pageSize: 20, - autoLoad: false - }); - - - this.fooStore.load(); - this.fooStore2.load(); - - console.log(this.fooStore); - console.log(this.fooStore2); - - /*var j = new Ext.create("PartKeepr.FootprintEditorComponent"); - - var k = new Ext.create("Ext.Window", { - height: 400, - items: j - }); - - k.show();*/ - this.menuBar.enable(); - return; this.createGlobalStores(); - if (window.parameters.userPreferences) { PartKeepr.getApplication().setInitialUserPreferences(window.parameters.userPreferences); } @@ -257,56 +214,56 @@ Ext.application({ this.footprintStore = Ext.create("Ext.data.Store", { model: 'PartKeepr.FootprintBundle.Entity.Footprint', - pageSize: -1, + pageSize: 99999999, autoLoad: false }); this.siPrefixStore = Ext.create("Ext.data.Store", { model: 'PartKeepr.SiPrefixBundle.Entity.SiPrefix', - pageSize: -1, + pageSize: 99999999, autoLoad: true }); this.distributorStore = Ext.create("Ext.data.Store", { - model: 'PartKeepr.Distributor.Distributor', - pageSize: -1, + model: 'PartKeepr.DistributorBundle.Entity.Distributor', + pageSize: 99999999, autoLoad: false }); this.manufacturerStore = Ext.create("Ext.data.Store", { - model: 'PartKeepr.Manufacturer.Manufacturer', - pageSize: -1, + model: 'PartKeepr.ManufacturerBundle.Entity.Manufacturer', + pageSize: 99999999, autoLoad: false }); this.partUnitStore = Ext.create("Ext.data.Store", { - model: 'PartKeepr.Part.PartMeasurementUnit', - pageSize: -1, + model: 'PartKeepr.PartBundle.Entity.PartMeasurementUnit', + pageSize: 99999999, autoLoad: false }); this.unitStore = Ext.create("Ext.data.Store", { model: 'PartKeepr.UnitBundle.Entity.Unit', - pageSize: -1, + pageSize: 99999999, autoLoad: false }); this.userStore = Ext.create("Ext.data.Store", { model: 'PartKeepr.AuthBundle.Entity.User.User', - pageSize: -1, + pageSize: 99999999, autoLoad: false }); this.tipOfTheDayStore = Ext.create("Ext.data.Store", { - model: 'PartKeepr.TipOfTheDay.TipOfTheDay', - pageSize: -1, + model: 'PartKeepr.TipOfTheDayBundle.Entity.TipOfTheDay', + pageSize: 99999999, autoLoad: true, listeners: { scope: this, @@ -317,7 +274,7 @@ Ext.application({ this.userPreferenceStore = Ext.create("Ext.data.Store", { model: 'PartKeepr.UserPreference.UserPreference', - pageSize: -1, + pageSize: 99999999, autoLoad: false, listeners: { scope: this, diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Util/Crypto/bcrypt.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Util/Crypto/bcrypt.js @@ -0,0 +1,600 @@ +function bCrypt() { + this.GENSALT_DEFAULT_LOG2_ROUNDS = 10; + this.BCRYPT_SALT_LEN = 16; + this.BLOWFISH_NUM_ROUNDS = 16; + this.MAX_EXECUTION_TIME = 100; + this.P_orig = [0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, + 0x299f31d0, 0x082efa98, 0xec4e6c89, 0x452821e6, 0x38d01377, + 0xbe5466cf, 0x34e90c6c, 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, + 0xb5470917, 0x9216d5d9, 0x8979fb1b]; + this.S_orig = [0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, + 0x6a267e96, 0xba7c9045, 0xf12c7f99, 0x24a19947, 0xb3916cf7, + 0x0801f2e2, 0x858efc16, 0x636920d8, 0x71574e69, 0xa458fea3, + 0xf4933d7e, 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, + 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013, 0xc5d1b023, + 0x286085f0, 0xca417918, 0xb8db38ef, 0x8e79dcb0, 0x603a180e, + 0x6c9e0e8b, 0xb01e8a3e, 0xd71577c1, 0xbd314b27, 0x78af2fda, + 0x55605c60, 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440, + 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce, 0xa15486af, + 0x7c72e993, 0xb3ee1411, 0x636fbc2a, 0x2ba9c55d, 0x741831f6, + 0xce5c3e16, 0x9b87931e, 0xafd6ba33, 0x6c24cf5c, 0x7a325381, + 0x28958677, 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193, + 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032, 0xef845d5d, + 0xe98575b1, 0xdc262302, 0xeb651b88, 0x23893e81, 0xd396acc5, + 0x0f6d6ff3, 0x83f44239, 0x2e0b4482, 0xa4842004, 0x69c8f04a, + 0x9e1f9b5e, 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0, + 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3, 0x6eef0b6c, + 0x137a3be4, 0xba3bf050, 0x7efb2a98, 0xa1f1651d, 0x39af0176, + 0x66ca593e, 0x82430e88, 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, + 0x3b8b5ebe, 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, + 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d, 0x37d0d724, + 0xd00a1248, 0xdb0fead3, 0x49f1c09b, 0x075372c9, 0x80991b7b, + 0x25d479d8, 0xf6e8def7, 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, + 0x04c006ba, 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463, + 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, 0x6dfc511f, + 0x9b30952c, 0xcc814544, 0xaf5ebd09, 0xbee3d004, 0xde334afd, + 0x660f2807, 0x192e4bb3, 0xc0cba857, 0x45c8740f, 0xd20b5f39, + 0xb9d3fbdb, 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279, + 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8, 0x3c7516df, + 0xfd616b15, 0x2f501ec8, 0xad0552ab, 0x323db5fa, 0xfd238760, + 0x53317b48, 0x3e00df82, 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, + 0xdf1769db, 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573, + 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0, 0x10fa3d98, + 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b, 0x9a53e479, 0xb6f84565, + 0xd28e49bc, 0x4bfb9790, 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, + 0xcee4c6e8, 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4, + 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0, 0xd08ed1d0, + 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7, 0x8ff6e2fb, 0xf2122b64, + 0x8888b812, 0x900df01c, 0x4fad5ea0, 0x688fc31c, 0xd1cff191, + 0xb3a8c1ad, 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1, + 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299, 0xb4a84fe0, + 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9, 0x165fa266, 0x80957705, + 0x93cc7314, 0x211a1477, 0xe6ad2065, 0x77b5fa86, 0xc75442f5, + 0xfb9d35cf, 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, + 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af, 0x2464369b, + 0xf009b91e, 0x5563911d, 0x59dfa6aa, 0x78c14389, 0xd95a537f, + 0x207d5ba2, 0x02e5b9c5, 0x83260376, 0x6295cfa9, 0x11c81968, + 0x4e734a41, 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915, + 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, 0x08ba6fb5, + 0x571be91f, 0xf296ec6b, 0x2a0dd915, 0xb6636521, 0xe7b9f9b6, + 0xff34052e, 0xc5855664, 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, + 0x6e85076a, 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, + 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266, 0xecaa8c71, + 0x699a17ff, 0x5664526c, 0xc2b19ee1, 0x193602a5, 0x75094c29, + 0xa0591340, 0xe4183a3e, 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, + 0x99f73fd6, 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1, + 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, 0x09686b3f, + 0x3ebaefc9, 0x3c971814, 0x6b6a70a1, 0x687f3584, 0x52a0e286, + 0xb79c5305, 0xaa500737, 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, + 0x5716f2b8, 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff, + 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd, 0xd19113f9, + 0x7ca92ff6, 0x94324773, 0x22f54701, 0x3ae5e581, 0x37c2dadc, + 0xc8b57634, 0x9af3dda7, 0xa9446146, 0x0fd0030e, 0xecc8c73e, + 0xa4751e41, 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331, + 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf, 0x2cb81290, + 0x24977c79, 0x5679b072, 0xbcaf89af, 0xde9a771f, 0xd9930810, + 0xb38bae12, 0xdccf3f2e, 0x5512721f, 0x2e6b7124, 0x501adde6, + 0x9f84cd87, 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c, + 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2, 0xef1c1847, + 0x3215d908, 0xdd433b37, 0x24c2ba16, 0x12a14d43, 0x2a65c451, + 0x50940002, 0x133ae4dd, 0x71dff89e, 0x10314e55, 0x81ac77d6, + 0x5f11199b, 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509, + 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e, 0x86e34570, + 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3, 0x771fe71c, 0x4e3d06fa, + 0x2965dcb9, 0x99e71d0f, 0x803e89d6, 0x5266c825, 0x2e4cc978, + 0x9c10b36a, 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, + 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960, 0x5223a708, + 0xf71312b6, 0xebadfe6e, 0xeac31f66, 0xe3bc4595, 0xa67bc883, + 0xb17f37d1, 0x018cff28, 0xc332ddef, 0xbe6c5aa5, 0x65582185, + 0x68ab9802, 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84, + 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, 0x13cca830, + 0xeb61bd96, 0x0334fe1e, 0xaa0363cf, 0xb5735c90, 0x4c70a239, + 0xd59e9e0b, 0xcbaade14, 0xeecc86bc, 0x60622ca7, 0x9cab5cab, + 0xb2f3846e, 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50, + 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7, 0x9b540b19, + 0x875fa099, 0x95f7997e, 0x623d7da8, 0xf837889a, 0x97e32d77, + 0x11ed935f, 0x16681281, 0x0e358829, 0xc7e61fd6, 0x96dedfa1, + 0x7858ba99, 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696, + 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128, 0x58ebf2ef, + 0x34c6ffea, 0xfe28ed61, 0xee7c3c73, 0x5d4a14d9, 0xe864b7e3, + 0x42105d14, 0x203e13e0, 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, + 0xfacb4fd0, 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105, + 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250, 0xcf62a1f2, + 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3, 0x7f1524c3, 0x69cb7492, + 0x47848a0b, 0x5692b285, 0x095bbf00, 0xad19489d, 0x1462b174, + 0x23820e00, 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061, + 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb, 0x7cde3759, + 0xcbee7460, 0x4085f2a7, 0xce77326e, 0xa6078084, 0x19f8509e, + 0xe8efd855, 0x61d99735, 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, + 0x800bcadc, 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, + 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340, 0xc5c43465, + 0x713e38d8, 0x3d28f89e, 0xf16dff20, 0x153e21e7, 0x8fb03d4a, + 0xe6e39f2b, 0xdb83adf7, 0xe93d5a68, 0x948140f7, 0xf64c261c, + 0x94692934, 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068, + 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, 0x1e39f62e, + 0x97244546, 0x14214f74, 0xbf8b8840, 0x4d95fc1d, 0x96b591af, + 0x70f4ddd3, 0x66a02f45, 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, + 0x31cb8504, 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, + 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb, 0x68dc1462, + 0xd7486900, 0x680ec0a4, 0x27a18dee, 0x4f3ffea2, 0xe887ad8c, + 0xb58ce006, 0x7af4d6b6, 0xaace1e7c, 0xd3375fec, 0xce78a399, + 0x406b2a42, 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b, + 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, 0x3a6efa74, + 0xdd5b4332, 0x6841e7f7, 0xca7820fb, 0xfb0af54e, 0xd8feb397, + 0x454056ac, 0xba489527, 0x55533a3a, 0x20838d87, 0xfe6ba9b7, + 0xd096954b, 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33, + 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c, 0xfdf8e802, + 0x04272f70, 0x80bb155c, 0x05282ce3, 0x95c11548, 0xe4c66d22, + 0x48c1133f, 0xc70f86dc, 0x07f9c9ee, 0x41041f0f, 0x404779a4, + 0x5d886e17, 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564, + 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b, 0x0e12b4c2, + 0x02e1329e, 0xaf664fd1, 0xcad18115, 0x6b2395e0, 0x333e92e1, + 0x3b240b62, 0xeebeb922, 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, + 0x2da2f728, 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0, + 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e, 0x0a476341, + 0x992eff74, 0x3a6f6eab, 0xf4f8fd37, 0xa812dc60, 0xa1ebddf8, + 0x991be14c, 0xdb6e6b0d, 0xc67b5510, 0x6d672c37, 0x2765d43b, + 0xdcd0e804, 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b, + 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3, 0xbb132f88, + 0x515bad24, 0x7b9479bf, 0x763bd6eb, 0x37392eb3, 0xcc115979, + 0x8026e297, 0xf42e312d, 0x6842ada7, 0xc66a2b3b, 0x12754ccc, + 0x782ef11c, 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, + 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9, 0x44421659, + 0x0a121386, 0xd90cec6e, 0xd5abea2a, 0x64af674e, 0xda86a85f, + 0xbebfe988, 0x64e4c3fe, 0x9dbc8057, 0xf0f7c086, 0x60787bf8, + 0x6003604d, 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc, + 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, 0x77a057be, + 0xbde8ae24, 0x55464299, 0xbf582e61, 0x4e58f48f, 0xf2ddfda2, + 0xf474ef38, 0x8789bdc2, 0x5366f9c3, 0xc8b38e74, 0xb475f255, + 0x46fcd9b9, 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2, + 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c, 0xb90bace1, + 0xbb8205d0, 0x11a86248, 0x7574a99e, 0xb77f19b6, 0xe0a9dc09, + 0x662d09a1, 0xc4324633, 0xe85a1f02, 0x09f0be8c, 0x4a99a025, + 0x1d6efe10, 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169, + 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52, 0x50115e01, + 0xa70683fa, 0xa002b5c4, 0x0de6d027, 0x9af88c27, 0x773f8641, + 0xc3604c06, 0x61a806b5, 0xf0177a28, 0xc0f586e0, 0x006058aa, + 0x30dc7d62, 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634, + 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76, 0x6f05e409, + 0x4b7c0188, 0x39720a3d, 0x7c927c24, 0x86e3725f, 0x724d9db9, + 0x1ac15bb4, 0xd39eb8fc, 0xed545578, 0x08fca5b5, 0xd83d7cd3, + 0x4dad0fc4, 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c, + 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, 0xd79a3234, + 0x92638212, 0x670efa8e, 0x406000e0, 0x3a39ce37, 0xd3faf5cf, + 0xabc27737, 0x5ac52d1b, 0x5cb0679e, 0x4fa33742, 0xd3822740, + 0x99bc9bbe, 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, + 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4, 0x5748ab2f, + 0xbc946e79, 0xc6a376d2, 0x6549c2c8, 0x530ff8ee, 0x468dde7d, + 0xd5730a1d, 0x4cd04dc6, 0x2939bbdb, 0xa9ba4650, 0xac9526e8, + 0xbe5ee304, 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22, + 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4, 0x83c061ba, + 0x9be96a4d, 0x8fe51550, 0xba645bd6, 0x2826a2f9, 0xa73a3ae1, + 0x4ba99586, 0xef5562e9, 0xc72fefd3, 0xf752f7da, 0x3f046f69, + 0x77fa0a59, 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, + 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51, 0x96d5ac3a, + 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28, 0x1f9f25cf, 0xadf2b89b, + 0x5ad6b472, 0x5a88f54c, 0xe029ac71, 0xe019a5e6, 0x47b0acfd, + 0xed93fa9b, 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28, + 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, 0x15056dd4, + 0x88f46dba, 0x03a16125, 0x0564f0bd, 0xc3eb9e15, 0x3c9057a2, + 0x97271aec, 0xa93a072a, 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, + 0x26dcf319, 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb, + 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f, 0x4de81751, + 0x3830dc8e, 0x379d5862, 0x9320f991, 0xea7a90c2, 0xfb3e7bce, + 0x5121ce64, 0x774fbe32, 0xa8b6e37e, 0xc3293d46, 0x48de5369, + 0x6413e680, 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166, + 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae, 0x5bbef7dd, + 0x1b588d40, 0xccd2017f, 0x6bb4e3bb, 0xdda26a7e, 0x3a59ff45, + 0x3e350a44, 0xbcb4cdd5, 0x72eacea8, 0xfa6484bb, 0x8d6612ae, + 0xbf3c6f47, 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370, + 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d, 0x4040cb08, + 0x4eb4e2cc, 0x34d2466a, 0x0115af84, 0xe1b00428, 0x95983a1d, + 0x06b89fb4, 0xce6ea048, 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, + 0x277227f8, 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd, + 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9, 0xe01cc87e, + 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7, 0x1a908749, 0xd44fbd9a, + 0xd0dadecb, 0xd50ada38, 0x0339c32a, 0xc6913667, 0x8df9317c, + 0xe0b12b4f, 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, + 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525, 0xfae59361, + 0xceb69ceb, 0xc2a86459, 0x12baa8d1, 0xb6c1075e, 0xe3056a0c, + 0x10d25065, 0xcb03a442, 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, + 0x3278e964, 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e, + 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, 0xdf359f8d, + 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d, 0xe54cda54, 0x1edad891, + 0xce6279cf, 0xcd3e7e6f, 0x1618b166, 0xfd2c1d05, 0x848fd2c5, + 0xf6fb2299, 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02, + 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc, 0xde966292, + 0x81b949d0, 0x4c50901b, 0x71c65614, 0xe6c6c7bd, 0x327a140a, + 0x45e1d006, 0xc3f27b9a, 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, + 0x35bdd2f6, 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b, + 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, 0xba38209c, + 0xf746ce76, 0x77afa1c5, 0x20756060, 0x85cbfe4e, 0x8ae88dd8, + 0x7aaaf9b0, 0x4cf9aa7e, 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, + 0xd6ebe1f9, 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, + 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6]; + this.bf_crypt_ciphertext = [0x4f727068, 0x65616e42, 0x65686f6c, 0x64657253, + 0x63727944, 0x6f756274]; + this.base64_code = ['.', '/', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', + 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', + 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', + 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', + 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', + '9']; + this.index_64 = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, + 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, -1, -1, -1, -1, -1, -1, -1, + 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + 21, 22, 23, 24, 25, 26, 27, -1, -1, -1, -1, -1, -1, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, + 49, 50, 51, 52, 53, -1, -1, -1, -1, -1]; + this.P; + this.S; + this.lr; + this.offp; +}; +bCrypt.prototype.getByte = function(c) { + var ret = 0; + try { + var b = c.charCodeAt(0); + } catch (err) { + b = c; + } + if (b > 127) { + return -128 + (b % 128); + } else { + return b; + } +}; +bCrypt.prototype.encode_base64 = function(d, len) { + var off = 0; + var rs = []; + var c1; + var c2; + if (len <= 0 || len > d.length) + throw "Invalid len"; + while (off < len) { + c1 = d[off++] & 0xff; + rs.push(this.base64_code[(c1 >> 2) & 0x3f]); + c1 = (c1 & 0x03) << 4; + if (off >= len) { + rs.push(this.base64_code[c1 & 0x3f]); + break; + } + c2 = d[off++] & 0xff; + c1 |= (c2 >> 4) & 0x0f; + rs.push(this.base64_code[c1 & 0x3f]); + c1 = (c2 & 0x0f) << 2; + if (off >= len) { + rs.push(this.base64_code[c1 & 0x3f]); + break; + } + c2 = d[off++] & 0xff; + c1 |= (c2 >> 6) & 0x03; + rs.push(this.base64_code[c1 & 0x3f]); + rs.push(this.base64_code[c2 & 0x3f]); + } + return rs.join(''); +}; +bCrypt.prototype.char64 = function(x) { + var code = x.charCodeAt(0); + if (code < 0 || code > this.index_64.length) { + return -1; + } + return this.index_64[code]; +}; +bCrypt.prototype.decode_base64 = function(s, maxolen) { + var off = 0; + var slen = s.length; + var olen = 0; + var rs = []; + var c1, c2, c3, c4, o; + if (maxolen <= 0) + throw "Invalid maxolen"; + while (off < slen - 1 && olen < maxolen) { + c1 = this.char64(s.charAt(off++)); + c2 = this.char64(s.charAt(off++)); + if (c1 == -1 || c2 == -1) { + break; + } + o = this.getByte(c1 << 2); + o |= (c2 & 0x30) >> 4; + rs.push(String.fromCharCode(o)); + if (++olen >= maxolen || off >= slen) { + break; + } + c3 = this.char64(s.charAt(off++)); + if (c3 == -1) { + break; + } + o = this.getByte((c2 & 0x0f) << 4); + o |= (c3 & 0x3c) >> 2; + rs.push(String.fromCharCode(o)); + if (++olen >= maxolen || off >= slen) { + break; + } + c4 = this.char64(s.charAt(off++)); + o = this.getByte((c3 & 0x03) << 6); + o |= c4; + rs.push(String.fromCharCode(o)); + ++olen; + } + var ret = []; + for (off = 0; off < olen; off++) { + ret.push(this.getByte(rs[off])); + } + return ret; +}; +bCrypt.prototype.encipher = function(lr, off) { + var i; + var n; + var l = lr[off]; + var r = lr[off + 1]; + + l ^= this.P[0]; + for (i = 0; i <= this.BLOWFISH_NUM_ROUNDS - 2;) { + // Feistel substitution on left word + n = this.S[(l >> 24) & 0xff]; + n += this.S[0x100 | ((l >> 16) & 0xff)]; + n ^= this.S[0x200 | ((l >> 8) & 0xff)]; + n += this.S[0x300 | (l & 0xff)]; + r ^= n ^ this.P[++i]; + + // Feistel substitution on right word + n = this.S[(r >> 24) & 0xff]; + n += this.S[0x100 | ((r >> 16) & 0xff)]; + n ^= this.S[0x200 | ((r >> 8) & 0xff)]; + n += this.S[0x300 | (r & 0xff)]; + l ^= n ^ this.P[++i]; + } + lr[off] = r ^ this.P[this.BLOWFISH_NUM_ROUNDS + 1]; + lr[off + 1] = l; +}; +bCrypt.prototype.streamtoword = function(data, offp) { + var i; + var word = 0; + var off = offp; + for (i = 0; i < 4; i++) { + word = (word << 8) | (data[off] & 0xff); + off = (off + 1) % data.length; + } + this.offp = off; + return word; +}; +bCrypt.prototype.init_key = function() { + this.P = this.P_orig.slice(); + this.S = this.S_orig.slice(); +}; +bCrypt.prototype.key = function(key) { + var i; + this.offp = 0; + var lr = new Array(0x00000000, 0x00000000); + var plen = this.P.length; + var slen = this.S.length; + + for (i = 0; i < plen; i++) { + this.P[i] = this.P[i] ^ this.streamtoword(key, this.offp); + } + for (i = 0; i < plen; i += 2) { + this.encipher(lr, 0); + this.P[i] = lr[0]; + this.P[i + 1] = lr[1]; + } + + for (i = 0; i < slen; i += 2) { + this.encipher(lr, 0); + this.S[i] = lr[0]; + this.S[i + 1] = lr[1]; + } +}; +bCrypt.prototype.ekskey = function(data, key) { + var i; + this.offp = 0; + var lr = new Array(0x00000000, 0x00000000); + var plen = this.P.length; + var slen = this.S.length; + + for (i = 0; i < plen; i++) + this.P[i] = this.P[i] ^ this.streamtoword(key, this.offp); + this.offp = 0; + for (i = 0; i < plen; i += 2) { + lr[0] ^= this.streamtoword(data, this.offp); + lr[1] ^= this.streamtoword(data, this.offp); + this.encipher(lr, 0); + this.P[i] = lr[0]; + this.P[i + 1] = lr[1]; + } + for (i = 0; i < slen; i += 2) { + lr[0] ^= this.streamtoword(data, this.offp); + lr[1] ^= this.streamtoword(data, this.offp); + this.encipher(lr, 0); + this.S[i] = lr[0]; + this.S[i + 1] = lr[1]; + } +}; + +bCrypt.prototype.crypt_raw = function(password, salt, log_rounds, cdata, callback, progress) { + var rounds; + var j; + var clen = cdata.length; + var one_percent; + + if (log_rounds < 4) { + throw "Minium of 4 rounds required, changing to default"; + } + if (log_rounds > 30) { + throw "Maximum of 30 rounds exceded"; + } + + if (salt.length != this.BCRYPT_SALT_LEN) + throw "Bad salt length"; + + rounds = 1 << log_rounds; + one_percent = Math.floor(rounds / 100) + 1; + this.init_key(); + this.ekskey(salt, password); + + var obj = this; + var i = 0; + setTimeout(function(){ + if(i < rounds){ + var start = new Date(); + for (; i != rounds;) { + i = i + 1; + obj.key(password); + obj.key(salt); + if(i % one_percent == 0){ + progress(); + } + if((new Date() - start) > obj.MAX_EXECUTION_TIME){ + break; + } + } + setTimeout(arguments.callee, 0); + }else{ + for (i = 0; i < 64; i++) { + for (j = 0; j < (clen >> 1); j++) { + obj.encipher(cdata, j << 1); + } + } + var ret = []; + for (i = 0; i < clen; i++) { + ret.push(obj.getByte((cdata[i] >> 24) & 0xff)); + ret.push(obj.getByte((cdata[i] >> 16) & 0xff)); + ret.push(obj.getByte((cdata[i] >> 8) & 0xff)); + ret.push(obj.getByte(cdata[i] & 0xff)); + } + callback(ret); + } + }, 0); +}; +/* + * callback: a function that will be passed the hash when it is complete + * progress: optional - this function will be called every time 1% of hashing + * is complete. + */ +bCrypt.prototype.hashpw = function(password, salt, callback, progress) { + var real_salt; + var passwordb = []; + var saltb = []; + var hashed = []; + var minor = String.fromCharCode(0); + var rounds = 0; + var off = 0; + + if (!progress){ + var progress = function() {}; + } + + if (salt.charAt(0) != '$' || salt.charAt(1) != '2') + throw "Invalid salt version"; + if (salt.charAt(2) == '$') + off = 3; + else { + minor = salt.charAt(2); + if (minor != 'y' || salt.charAt(3) != '$') + throw "Invalid salt revision"; + off = 4; + } + + // Extract number of rounds + if (salt.charAt(off + 2) > '$') + throw "Missing salt rounds"; + var r1 = parseInt(salt.substring(off, off + 1)) * 10; + var r2 = parseInt(salt.substring(off + 1, off + 2)); + rounds = r1 + r2; + real_salt = salt.substring(off + 3, off + 25); + password = password + (minor >= 'a' ? "\000" : ""); + for (var n = 0; n < password.length; n++) { + var c = password.charCodeAt(n); + if (c < 128) { + passwordb.push(c); + } + else if((c > 127) && (c < 2048)) { + passwordb.push((c >> 6) | 192); + passwordb.push((c & 63) | 128); + } + else if ((c >= 55296) && (c <= 56319)) { + n++; + if (n > password.length) { + throw "utf-16 Decoding error: lead surrogate found without trail surrogate"; + } + c = password.charCodeAt(n); + if (c < 56320 || c > 57343) { + throw "utf-16 Decoding error: trail surrogate not in the range of 0xdc00 through 0xdfff"; + } + c = ((password.charCodeAt(n - 1) - 55296) << 10) + (c - 56320) + 65536; + passwordb.push((c >> 18) | 240); + passwordb.push(((c >> 12) & 63) | 128); + passwordb.push(((c >> 6) & 63) | 128); + passwordb.push((c & 63) | 128); + } + else { + passwordb.push((c >> 12) | 224); + passwordb.push(((c >> 6) & 63) | 128); + passwordb.push((c & 63) | 128); + } + } + saltb = this.decode_base64(real_salt, this.BCRYPT_SALT_LEN); + var obj = this; + this.crypt_raw(passwordb, saltb, rounds, obj.bf_crypt_ciphertext.slice(), function(hashed) { + var rs = []; + rs.push("$2"); + if (minor >= 'a') + rs.push(minor); + rs.push("$"); + if (rounds < 10) + rs.push("0"); + rs.push(rounds.toString()); + rs.push("$"); + rs.push(obj.encode_base64(saltb, saltb.length)); + rs.push(obj.encode_base64(hashed, obj.bf_crypt_ciphertext.length * 4 - 1)); + callback(rs.join('')); + }, progress); +}; + +bCrypt.prototype.gensalt = function(rounds) { + var iteration_count = rounds; + if (iteration_count < 4 || iteration_count > 30) { + throw "Rounds exceded maximum (30)!" + } + var output = []; + output.push("$2a$"); + if (iteration_count < 10) + output.push("0"); + output.push(iteration_count.toString()); + output.push('$'); + var s1 = []; + for (var r = 0; r < this.BCRYPT_SALT_LEN; r++){ + s1.push(Math.abs(isaac.rand())); + } + output.push(this.encode_base64(s1,this.BCRYPT_SALT_LEN)) + return output.join(''); +}; + +bCrypt.prototype.ready = function(){ + return true; +}; + +bCrypt.prototype.checkpw = function(plaintext, hashed, callback, progress) { + var off = 0; + if (hashed.charAt(0) != '$' || hashed.charAt(1) != '2') + throw "Invalid salt version"; + if (hashed.charAt(2) == '$') + off = 3; + else { + minor = hashed.charAt(2); + if (minor != 'a' || hashed.charAt(3) != '$') { + throw "Invalid salt revision"; + } + off = 4; + } + salt = hashed.substring(0, off + 25) + this.hashpw(plaintext, salt, function(try_pass) { + var ret = 0; + for(var i = 0; i < hashed.length; i++){ + ret |= bcrypt.getByte(hashed[i]) ^ bcrypt.getByte(try_pass[i]) + } + callback(ret == 0); + }, progress); +};+ \ No newline at end of file diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Util/Crypto/core.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Util/Crypto/core.js @@ -0,0 +1,706 @@ +/** + * CryptoJS core components. + */ +var CryptoJS = CryptoJS || (function (Math, undefined) { + /** + * CryptoJS namespace. + */ + var C = {}; + + /** + * Library namespace. + */ + var C_lib = C.lib = {}; + + /** + * Base object for prototypal inheritance. + */ + var Base = C_lib.Base = (function () { + function F() {} + + return { + /** + * Creates a new object that inherits from this object. + * + * @param {Object} overrides Properties to copy into the new object. + * + * @return {Object} The new object. + * + * @static + * + * @example + * + * var MyType = CryptoJS.lib.Base.extend({ + * field: 'value', + * + * method: function () { + * } + * }); + */ + extend: function (overrides) { + // Spawn + F.prototype = this; + var subtype = new F(); + + // Augment + if (overrides) { + subtype.mixIn(overrides); + } + + // Create default initializer + if (!subtype.hasOwnProperty('init')) { + subtype.init = function () { + subtype.$super.init.apply(this, arguments); + }; + } + + // Initializer's prototype is the subtype object + subtype.init.prototype = subtype; + + // Reference supertype + subtype.$super = this; + + return subtype; + }, + + /** + * Extends this object and runs the init method. + * Arguments to create() will be passed to init(). + * + * @return {Object} The new object. + * + * @static + * + * @example + * + * var instance = MyType.create(); + */ + create: function () { + var instance = this.extend(); + instance.init.apply(instance, arguments); + + return instance; + }, + + /** + * Initializes a newly created object. + * Override this method to add some logic when your objects are created. + * + * @example + * + * var MyType = CryptoJS.lib.Base.extend({ + * init: function () { + * // ... + * } + * }); + */ + init: function () { + }, + + /** + * Copies properties into this object. + * + * @param {Object} properties The properties to mix in. + * + * @example + * + * MyType.mixIn({ + * field: 'value' + * }); + */ + mixIn: function (properties) { + for (var propertyName in properties) { + if (properties.hasOwnProperty(propertyName)) { + this[propertyName] = properties[propertyName]; + } + } + + // IE won't copy toString using the loop above + if (properties.hasOwnProperty('toString')) { + this.toString = properties.toString; + } + }, + + /** + * Creates a copy of this object. + * + * @return {Object} The clone. + * + * @example + * + * var clone = instance.clone(); + */ + clone: function () { + return this.init.prototype.extend(this); + } + }; + }()); + + /** + * An array of 32-bit words. + * + * @property {Array} words The array of 32-bit words. + * @property {number} sigBytes The number of significant bytes in this word array. + */ + var WordArray = C_lib.WordArray = Base.extend({ + /** + * Initializes a newly created word array. + * + * @param {Array} words (Optional) An array of 32-bit words. + * @param {number} sigBytes (Optional) The number of significant bytes in the words. + * + * @example + * + * var wordArray = CryptoJS.lib.WordArray.create(); + * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]); + * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6); + */ + init: function (words, sigBytes) { + words = this.words = words || []; + + if (sigBytes != undefined) { + this.sigBytes = sigBytes; + } else { + this.sigBytes = words.length * 4; + } + }, + + /** + * Converts this word array to a string. + * + * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex + * + * @return {string} The stringified word array. + * + * @example + * + * var string = wordArray + ''; + * var string = wordArray.toString(); + * var string = wordArray.toString(CryptoJS.enc.Utf8); + */ + toString: function (encoder) { + return (encoder || Hex).stringify(this); + }, + + /** + * Concatenates a word array to this word array. + * + * @param {WordArray} wordArray The word array to append. + * + * @return {WordArray} This word array. + * + * @example + * + * wordArray1.concat(wordArray2); + */ + concat: function (wordArray) { + // Shortcuts + var thisWords = this.words; + var thatWords = wordArray.words; + var thisSigBytes = this.sigBytes; + var thatSigBytes = wordArray.sigBytes; + + // Clamp excess bits + this.clamp(); + + // Concat + if (thisSigBytes % 4) { + // Copy one byte at a time + for (var i = 0; i < thatSigBytes; i++) { + var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; + thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8); + } + } else if (thatWords.length > 0xffff) { + // Copy one word at a time + for (var i = 0; i < thatSigBytes; i += 4) { + thisWords[(thisSigBytes + i) >>> 2] = thatWords[i >>> 2]; + } + } else { + // Copy all words at once + thisWords.push.apply(thisWords, thatWords); + } + this.sigBytes += thatSigBytes; + + // Chainable + return this; + }, + + /** + * Removes insignificant bits. + * + * @example + * + * wordArray.clamp(); + */ + clamp: function () { + // Shortcuts + var words = this.words; + var sigBytes = this.sigBytes; + + // Clamp + words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8); + words.length = Math.ceil(sigBytes / 4); + }, + + /** + * Creates a copy of this word array. + * + * @return {WordArray} The clone. + * + * @example + * + * var clone = wordArray.clone(); + */ + clone: function () { + var clone = Base.clone.call(this); + clone.words = this.words.slice(0); + + return clone; + }, + + /** + * Creates a word array filled with random bytes. + * + * @param {number} nBytes The number of random bytes to generate. + * + * @return {WordArray} The random word array. + * + * @static + * + * @example + * + * var wordArray = CryptoJS.lib.WordArray.random(16); + */ + random: function (nBytes) { + var words = []; + for (var i = 0; i < nBytes; i += 4) { + words.push((Math.random() * 0x100000000) | 0); + } + + return new WordArray.init(words, nBytes); + } + }); + + /** + * Encoder namespace. + */ + var C_enc = C.enc = {}; + + /** + * Hex encoding strategy. + */ + var Hex = C_enc.Hex = { + /** + * Converts a word array to a hex string. + * + * @param {WordArray} wordArray The word array. + * + * @return {string} The hex string. + * + * @static + * + * @example + * + * var hexString = CryptoJS.enc.Hex.stringify(wordArray); + */ + stringify: function (wordArray) { + // Shortcuts + var words = wordArray.words; + var sigBytes = wordArray.sigBytes; + + // Convert + var hexChars = []; + for (var i = 0; i < sigBytes; i++) { + var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; + hexChars.push((bite >>> 4).toString(16)); + hexChars.push((bite & 0x0f).toString(16)); + } + + return hexChars.join(''); + }, + + /** + * Converts a hex string to a word array. + * + * @param {string} hexStr The hex string. + * + * @return {WordArray} The word array. + * + * @static + * + * @example + * + * var wordArray = CryptoJS.enc.Hex.parse(hexString); + */ + parse: function (hexStr) { + // Shortcut + var hexStrLength = hexStr.length; + + // Convert + var words = []; + for (var i = 0; i < hexStrLength; i += 2) { + words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4); + } + + return new WordArray.init(words, hexStrLength / 2); + } + }; + + /** + * Latin1 encoding strategy. + */ + var Latin1 = C_enc.Latin1 = { + /** + * Converts a word array to a Latin1 string. + * + * @param {WordArray} wordArray The word array. + * + * @return {string} The Latin1 string. + * + * @static + * + * @example + * + * var latin1String = CryptoJS.enc.Latin1.stringify(wordArray); + */ + stringify: function (wordArray) { + // Shortcuts + var words = wordArray.words; + var sigBytes = wordArray.sigBytes; + + // Convert + var latin1Chars = []; + for (var i = 0; i < sigBytes; i++) { + var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; + latin1Chars.push(String.fromCharCode(bite)); + } + + return latin1Chars.join(''); + }, + + /** + * Converts a Latin1 string to a word array. + * + * @param {string} latin1Str The Latin1 string. + * + * @return {WordArray} The word array. + * + * @static + * + * @example + * + * var wordArray = CryptoJS.enc.Latin1.parse(latin1String); + */ + parse: function (latin1Str) { + // Shortcut + var latin1StrLength = latin1Str.length; + + // Convert + var words = []; + for (var i = 0; i < latin1StrLength; i++) { + words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8); + } + + return new WordArray.init(words, latin1StrLength); + } + }; + + /** + * UTF-8 encoding strategy. + */ + var Utf8 = C_enc.Utf8 = { + /** + * Converts a word array to a UTF-8 string. + * + * @param {WordArray} wordArray The word array. + * + * @return {string} The UTF-8 string. + * + * @static + * + * @example + * + * var utf8String = CryptoJS.enc.Utf8.stringify(wordArray); + */ + stringify: function (wordArray) { + try { + return decodeURIComponent(escape(Latin1.stringify(wordArray))); + } catch (e) { + throw new Error('Malformed UTF-8 data'); + } + }, + + /** + * Converts a UTF-8 string to a word array. + * + * @param {string} utf8Str The UTF-8 string. + * + * @return {WordArray} The word array. + * + * @static + * + * @example + * + * var wordArray = CryptoJS.enc.Utf8.parse(utf8String); + */ + parse: function (utf8Str) { + return Latin1.parse(unescape(encodeURIComponent(utf8Str))); + } + }; + + /** + * Abstract buffered block algorithm template. + * + * The property blockSize must be implemented in a concrete subtype. + * + * @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0 + */ + var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({ + /** + * Resets this block algorithm's data buffer to its initial state. + * + * @example + * + * bufferedBlockAlgorithm.reset(); + */ + reset: function () { + // Initial values + this._data = new WordArray.init(); + this._nDataBytes = 0; + }, + + /** + * Adds new data to this block algorithm's buffer. + * + * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8. + * + * @example + * + * bufferedBlockAlgorithm._append('data'); + * bufferedBlockAlgorithm._append(wordArray); + */ + _append: function (data) { + // Convert string to WordArray, else assume WordArray already + if (typeof data == 'string') { + data = Utf8.parse(data); + } + + // Append + this._data.concat(data); + this._nDataBytes += data.sigBytes; + }, + + /** + * Processes available data blocks. + * + * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype. + * + * @param {boolean} doFlush Whether all blocks and partial blocks should be processed. + * + * @return {WordArray} The processed data. + * + * @example + * + * var processedData = bufferedBlockAlgorithm._process(); + * var processedData = bufferedBlockAlgorithm._process(!!'flush'); + */ + _process: function (doFlush) { + // Shortcuts + var data = this._data; + var dataWords = data.words; + var dataSigBytes = data.sigBytes; + var blockSize = this.blockSize; + var blockSizeBytes = blockSize * 4; + + // Count blocks ready + var nBlocksReady = dataSigBytes / blockSizeBytes; + if (doFlush) { + // Round up to include partial blocks + nBlocksReady = Math.ceil(nBlocksReady); + } else { + // Round down to include only full blocks, + // less the number of blocks that must remain in the buffer + nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0); + } + + // Count words ready + var nWordsReady = nBlocksReady * blockSize; + + // Count bytes ready + var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes); + + // Process blocks + if (nWordsReady) { + for (var offset = 0; offset < nWordsReady; offset += blockSize) { + // Perform concrete-algorithm logic + this._doProcessBlock(dataWords, offset); + } + + // Remove processed words + var processedWords = dataWords.splice(0, nWordsReady); + data.sigBytes -= nBytesReady; + } + + // Return processed words + return new WordArray.init(processedWords, nBytesReady); + }, + + /** + * Creates a copy of this object. + * + * @return {Object} The clone. + * + * @example + * + * var clone = bufferedBlockAlgorithm.clone(); + */ + clone: function () { + var clone = Base.clone.call(this); + clone._data = this._data.clone(); + + return clone; + }, + + _minBufferSize: 0 + }); + + /** + * Abstract hasher template. + * + * @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits) + */ + var Hasher = C_lib.Hasher = BufferedBlockAlgorithm.extend({ + /** + * Configuration options. + */ + cfg: Base.extend(), + + /** + * Initializes a newly created hasher. + * + * @param {Object} cfg (Optional) The configuration options to use for this hash computation. + * + * @example + * + * var hasher = CryptoJS.algo.SHA256.create(); + */ + init: function (cfg) { + // Apply config defaults + this.cfg = this.cfg.extend(cfg); + + // Set initial values + this.reset(); + }, + + /** + * Resets this hasher to its initial state. + * + * @example + * + * hasher.reset(); + */ + reset: function () { + // Reset data buffer + BufferedBlockAlgorithm.reset.call(this); + + // Perform concrete-hasher logic + this._doReset(); + }, + + /** + * Updates this hasher with a message. + * + * @param {WordArray|string} messageUpdate The message to append. + * + * @return {Hasher} This hasher. + * + * @example + * + * hasher.update('message'); + * hasher.update(wordArray); + */ + update: function (messageUpdate) { + // Append + this._append(messageUpdate); + + // Update the hash + this._process(); + + // Chainable + return this; + }, + + /** + * Finalizes the hash computation. + * Note that the finalize operation is effectively a destructive, read-once operation. + * + * @param {WordArray|string} messageUpdate (Optional) A final message update. + * + * @return {WordArray} The hash. + * + * @example + * + * var hash = hasher.finalize(); + * var hash = hasher.finalize('message'); + * var hash = hasher.finalize(wordArray); + */ + finalize: function (messageUpdate) { + // Final message update + if (messageUpdate) { + this._append(messageUpdate); + } + + // Perform concrete-hasher logic + var hash = this._doFinalize(); + + return hash; + }, + + blockSize: 512/32, + + /** + * Creates a shortcut function to a hasher's object interface. + * + * @param {Hasher} hasher The hasher to create a helper for. + * + * @return {Function} The shortcut function. + * + * @static + * + * @example + * + * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256); + */ + _createHelper: function (hasher) { + return function (message, cfg) { + return new hasher.init(cfg).finalize(message); + }; + }, + + /** + * Creates a shortcut function to the HMAC's object interface. + * + * @param {Hasher} hasher The hasher to use in this HMAC helper. + * + * @return {Function} The shortcut function. + * + * @static + * + * @example + * + * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256); + */ + _createHmacHelper: function (hasher) { + return function (message, key) { + return new C_algo.HMAC.init(hasher, key).finalize(message); + }; + } + }); + + /** + * Algorithm namespace. + */ + var C_algo = C.algo = {}; + + return C; +}(Math));+ \ No newline at end of file diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Util/Crypto/enc-base64.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Util/Crypto/enc-base64.js @@ -0,0 +1,103 @@ +(function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var WordArray = C_lib.WordArray; + var C_enc = C.enc; + + /** + * Base64 encoding strategy. + */ + var Base64 = C_enc.Base64 = { + /** + * Converts a word array to a Base64 string. + * + * @param {WordArray} wordArray The word array. + * + * @return {string} The Base64 string. + * + * @static + * + * @example + * + * var base64String = CryptoJS.enc.Base64.stringify(wordArray); + */ + stringify: function (wordArray) { + // Shortcuts + var words = wordArray.words; + var sigBytes = wordArray.sigBytes; + var map = this._map; + + // Clamp excess bits + wordArray.clamp(); + + // Convert + var base64Chars = []; + for (var i = 0; i < sigBytes; i += 3) { + var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; + var byte2 = (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff; + var byte3 = (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff; + + var triplet = (byte1 << 16) | (byte2 << 8) | byte3; + + for (var j = 0; (j < 4) && (i + j * 0.75 < sigBytes); j++) { + base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f)); + } + } + + // Add padding + var paddingChar = map.charAt(64); + if (paddingChar) { + while (base64Chars.length % 4) { + base64Chars.push(paddingChar); + } + } + + return base64Chars.join(''); + }, + + /** + * Converts a Base64 string to a word array. + * + * @param {string} base64Str The Base64 string. + * + * @return {WordArray} The word array. + * + * @static + * + * @example + * + * var wordArray = CryptoJS.enc.Base64.parse(base64String); + */ + parse: function (base64Str) { + // Shortcuts + var base64StrLength = base64Str.length; + var map = this._map; + + // Ignore padding + var paddingChar = map.charAt(64); + if (paddingChar) { + var paddingIndex = base64Str.indexOf(paddingChar); + if (paddingIndex != -1) { + base64StrLength = paddingIndex; + } + } + + // Convert + var words = []; + var nBytes = 0; + for (var i = 0; i < base64StrLength; i++) { + if (i % 4) { + var bits1 = map.indexOf(base64Str.charAt(i - 1)) << ((i % 4) * 2); + var bits2 = map.indexOf(base64Str.charAt(i)) >>> (6 - (i % 4) * 2); + words[nBytes >>> 2] |= (bits1 | bits2) << (24 - (nBytes % 4) * 8); + nBytes++; + } + } + + return WordArray.create(words, nBytes); + }, + + _map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=' + }; +}());+ \ No newline at end of file diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Util/Crypto/isaac.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Util/Crypto/isaac.js @@ -0,0 +1,239 @@ +/* ---------------------------------------------------------------------- + * Copyright (c) 2012 Yves-Marie K. Rinquin + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * ---------------------------------------------------------------------- + * + * ISAAC is a cryptographically secure pseudo-random number generator + * (or CSPRNG for short) designed by Robert J. Jenkins Jr. in 1996 and + * based on RC4. It is designed for speed and security. + * + * ISAAC's informations & analysis: + * http://burtleburtle.net/bob/rand/isaac.html + * ISAAC's implementation details: + * http://burtleburtle.net/bob/rand/isaacafa.html + * + * ISAAC succesfully passed TestU01 + * + * ---------------------------------------------------------------------- + * + * Usage: + * <script src="isaac.js"></script> + * var random_number = isaac.random(); + * + * Output: [ 0x00000000; 0xffffffff] + * [-2147483648; 2147483647] + * + */ + + +/* js string (ucs-2/utf16) to a 32-bit integer (utf-8 chars, little-endian) array */ +String.prototype.toIntArray = function() { + var w1, w2, u, r4 = [], r = [], i = 0; + var s = this + '\0\0\0'; // pad string to avoid discarding last chars + var l = s.length - 1; + + while(i < l) { + w1 = s.charCodeAt(i++); + w2 = s.charCodeAt(i+1); + if (w1 < 0x0080) { + // 0x0000 - 0x007f code point: basic ascii + r4.push(w1); + } else if(w1 < 0x0800) { + // 0x0080 - 0x07ff code point + r4.push(((w1 >>> 6) & 0x1f) | 0xc0); + r4.push(((w1 >>> 0) & 0x3f) | 0x80); + } else if((w1 & 0xf800) != 0xd800) { + // 0x0800 - 0xd7ff / 0xe000 - 0xffff code point + r4.push(((w1 >>> 12) & 0x0f) | 0xe0); + r4.push(((w1 >>> 6) & 0x3f) | 0x80); + r4.push(((w1 >>> 0) & 0x3f) | 0x80); + } else if(((w1 & 0xfc00) == 0xd800) + && ((w2 & 0xfc00) == 0xdc00)) { + // 0xd800 - 0xdfff surrogate / 0x10ffff - 0x10000 code point + u = ((w2 & 0x3f) | ((w1 & 0x3f) << 10)) + 0x10000; + r4.push(((u >>> 18) & 0x07) | 0xf0); + r4.push(((u >>> 12) & 0x3f) | 0x80); + r4.push(((u >>> 6) & 0x3f) | 0x80); + r4.push(((u >>> 0) & 0x3f) | 0x80); + i++; + } else { + // invalid char + } + /* add integer (four utf-8 value) to array */ + if(r4.length > 3) { + // little endian + r.push((r4.shift() << 0) | (r4.shift() << 8) | + (r4.shift() << 16) | (r4.shift() << 24)); + } + } + + return r; +} + +/* isaac module pattern */ +var isaac = (function(){ + + /* private: internal states */ + var m = Array(256), // internal memory + acc = 0, // accumulator + brs = 0, // last result + cnt = 0, // counter + r = Array(256), // result array + gnt = 0; // generation counter + + seed(Math.random() * 0xffffffff); + + /* private: 32-bit integer safe adder */ + function add(x, y) { + var lsb = (x & 0xffff) + (y & 0xffff); + var msb = (x >>> 16) + (y >>> 16) + (lsb >>> 16); + return (msb << 16) | (lsb & 0xffff); + } + + /* public: initialisation */ + function reset() { + acc = brs = cnt = 0; + for(var i = 0; i < 256; ++i) + m[i] = r[i] = 0; + gnt = 0; + } + + /* public: seeding function */ + function seed(s) { + var a, b, c, d, e, f, g, h, i; + + /* seeding the seeds of love */ + a = b = c = d = + e = f = g = h = 0x9e3779b9; /* the golden ratio */ + + if(s && typeof(s) === 'string') + s = s.toIntArray(); + + if(s && typeof(s) === 'number') { + s = [s]; + } + + if(s instanceof Array) { + reset(); + for(i = 0; i < s.length; i++) + r[i & 0xff] += (typeof(s[i]) === 'number') ? s[i] : 0; + } + + /* private: seed mixer */ + function seed_mix() { + a ^= b << 11; d = add(d, a); b = add(b, c); + b ^= c >>> 2; e = add(e, b); c = add(c, d); + c ^= d << 8; f = add(f, c); d = add(d, e); + d ^= e >>> 16; g = add(g, d); e = add(e, f); + e ^= f << 10; h = add(h, e); f = add(f, g); + f ^= g >>> 4; a = add(a, f); g = add(g, h); + g ^= h << 8; b = add(b, g); h = add(h, a); + h ^= a >>> 9; c = add(c, h); a = add(a, b); + } + + for(i = 0; i < 4; i++) /* scramble it */ + seed_mix(); + + for(i = 0; i < 256; i += 8) { + if(s) { /* use all the information in the seed */ + a = add(a, r[i + 0]); b = add(b, r[i + 1]); + c = add(c, r[i + 2]); d = add(d, r[i + 3]); + e = add(e, r[i + 4]); f = add(f, r[i + 5]); + g = add(g, r[i + 6]); h = add(h, r[i + 7]); + } + seed_mix(); + /* fill in m[] with messy stuff */ + m[i + 0] = a; m[i + 1] = b; m[i + 2] = c; m[i + 3] = d; + m[i + 4] = e; m[i + 5] = f; m[i + 6] = g; m[i + 7] = h; + } + if(s) { + /* do a second pass to make all of the seed affect all of m[] */ + for(i = 0; i < 256; i += 8) { + a = add(a, m[i + 0]); b = add(b, m[i + 1]); + c = add(c, m[i + 2]); d = add(d, m[i + 3]); + e = add(e, m[i + 4]); f = add(f, m[i + 5]); + g = add(g, m[i + 6]); h = add(h, m[i + 7]); + seed_mix(); + /* fill in m[] with messy stuff (again) */ + m[i + 0] = a; m[i + 1] = b; m[i + 2] = c; m[i + 3] = d; + m[i + 4] = e; m[i + 5] = f; m[i + 6] = g; m[i + 7] = h; + } + } + + prng(); /* fill in the first set of results */ + gnt = 256; /* prepare to use the first set of results */; + } + + /* public: isaac generator, n = number of run */ + function prng(n){ + var i, x, y; + + n = (n && typeof(n) === 'number') + ? Math.abs(Math.floor(n)) : 1; + + while(n--) { + cnt = add(cnt, 1); + brs = add(brs, cnt); + + for(i = 0; i < 256; i++) { + switch(i & 3) { + case 0: acc ^= acc << 13; break; + case 1: acc ^= acc >>> 6; break; + case 2: acc ^= acc << 2; break; + case 3: acc ^= acc >>> 16; break; + } + acc = add(m[(i + 128) & 0xff], acc); x = m[i]; + m[i] = y = add(m[(x >>> 2) & 0xff], add(acc, brs)); + r[i] = brs = add(m[(y >>> 10) & 0xff], x); + } + } + } + + /* public: return a random number between */ + function rand() { + if(!gnt--) { + prng(); gnt = 255; + } + return r[gnt]; + } + + /* public: return internals in an object*/ + function internals(){ + return {a: acc, b: brs, c: cnt, m: m, r: r}; + } + + function random(){ + return 0.5 + this.rand() * 2.3283064365386963e-10; // 2^-32 + } + + /* return class object */ + return { + 'reset': reset, + 'seed': seed, + 'prng': prng, + 'rand': rand, + 'random': random, + 'internals': internals + }; +})(); /* declare and execute */ + +( "undefined" !== ( typeof( module ) ) ) && module.exports && ( module.exports = isaac );+ \ No newline at end of file diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Util/Crypto/sha1.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Util/Crypto/sha1.js @@ -0,0 +1,130 @@ +(function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var WordArray = C_lib.WordArray; + var Hasher = C_lib.Hasher; + var C_algo = C.algo; + + // Reusable object + var W = []; + + /** + * SHA-1 hash algorithm. + */ + var SHA1 = C_algo.SHA1 = Hasher.extend({ + _doReset: function () { + this._hash = new WordArray.init([ + 0x67452301, 0xefcdab89, + 0x98badcfe, 0x10325476, + 0xc3d2e1f0 + ]); + }, + + _doProcessBlock: function (M, offset) { + // Shortcut + var H = this._hash.words; + + // Working variables + var a = H[0]; + var b = H[1]; + var c = H[2]; + var d = H[3]; + var e = H[4]; + + // Computation + for (var i = 0; i < 80; i++) { + if (i < 16) { + W[i] = M[offset + i] | 0; + } else { + var n = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]; + W[i] = (n << 1) | (n >>> 31); + } + + var t = ((a << 5) | (a >>> 27)) + e + W[i]; + if (i < 20) { + t += ((b & c) | (~b & d)) + 0x5a827999; + } else if (i < 40) { + t += (b ^ c ^ d) + 0x6ed9eba1; + } else if (i < 60) { + t += ((b & c) | (b & d) | (c & d)) - 0x70e44324; + } else /* if (i < 80) */ { + t += (b ^ c ^ d) - 0x359d3e2a; + } + + e = d; + d = c; + c = (b << 30) | (b >>> 2); + b = a; + a = t; + } + + // Intermediate hash value + H[0] = (H[0] + a) | 0; + H[1] = (H[1] + b) | 0; + H[2] = (H[2] + c) | 0; + H[3] = (H[3] + d) | 0; + H[4] = (H[4] + e) | 0; + }, + + _doFinalize: function () { + // Shortcuts + var data = this._data; + var dataWords = data.words; + + var nBitsTotal = this._nDataBytes * 8; + var nBitsLeft = data.sigBytes * 8; + + // Add padding + dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); + dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000); + dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; + data.sigBytes = dataWords.length * 4; + + // Hash final blocks + this._process(); + + // Return final computed hash + return this._hash; + }, + + clone: function () { + var clone = Hasher.clone.call(this); + clone._hash = this._hash.clone(); + + return clone; + } + }); + + /** + * Shortcut function to the hasher's object interface. + * + * @param {WordArray|string} message The message to hash. + * + * @return {WordArray} The hash. + * + * @static + * + * @example + * + * var hash = CryptoJS.SHA1('message'); + * var hash = CryptoJS.SHA1(wordArray); + */ + C.SHA1 = Hasher._createHelper(SHA1); + + /** + * Shortcut function to the HMAC's object interface. + * + * @param {WordArray|string} message The message to hash. + * @param {WordArray|string} key The secret key. + * + * @return {WordArray} The HMAC. + * + * @static + * + * @example + * + * var hmac = CryptoJS.HmacSHA1(message, key); + */ + C.HmacSHA1 = Hasher._createHmacHelper(SHA1); +}());+ \ No newline at end of file diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Util/Crypto/sha512.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Util/Crypto/sha512.js @@ -0,0 +1,303 @@ +(function () { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var Hasher = C_lib.Hasher; + var C_x64 = C.x64; + var X64Word = C_x64.Word; + var X64WordArray = C_x64.WordArray; + var C_algo = C.algo; + + function X64Word_create() { + return X64Word.create.apply(X64Word, arguments); + } + + // Constants + var K = [ + X64Word_create(0x428a2f98, 0xd728ae22), X64Word_create(0x71374491, 0x23ef65cd), + X64Word_create(0xb5c0fbcf, 0xec4d3b2f), X64Word_create(0xe9b5dba5, 0x8189dbbc), + X64Word_create(0x3956c25b, 0xf348b538), X64Word_create(0x59f111f1, 0xb605d019), + X64Word_create(0x923f82a4, 0xaf194f9b), X64Word_create(0xab1c5ed5, 0xda6d8118), + X64Word_create(0xd807aa98, 0xa3030242), X64Word_create(0x12835b01, 0x45706fbe), + X64Word_create(0x243185be, 0x4ee4b28c), X64Word_create(0x550c7dc3, 0xd5ffb4e2), + X64Word_create(0x72be5d74, 0xf27b896f), X64Word_create(0x80deb1fe, 0x3b1696b1), + X64Word_create(0x9bdc06a7, 0x25c71235), X64Word_create(0xc19bf174, 0xcf692694), + X64Word_create(0xe49b69c1, 0x9ef14ad2), X64Word_create(0xefbe4786, 0x384f25e3), + X64Word_create(0x0fc19dc6, 0x8b8cd5b5), X64Word_create(0x240ca1cc, 0x77ac9c65), + X64Word_create(0x2de92c6f, 0x592b0275), X64Word_create(0x4a7484aa, 0x6ea6e483), + X64Word_create(0x5cb0a9dc, 0xbd41fbd4), X64Word_create(0x76f988da, 0x831153b5), + X64Word_create(0x983e5152, 0xee66dfab), X64Word_create(0xa831c66d, 0x2db43210), + X64Word_create(0xb00327c8, 0x98fb213f), X64Word_create(0xbf597fc7, 0xbeef0ee4), + X64Word_create(0xc6e00bf3, 0x3da88fc2), X64Word_create(0xd5a79147, 0x930aa725), + X64Word_create(0x06ca6351, 0xe003826f), X64Word_create(0x14292967, 0x0a0e6e70), + X64Word_create(0x27b70a85, 0x46d22ffc), X64Word_create(0x2e1b2138, 0x5c26c926), + X64Word_create(0x4d2c6dfc, 0x5ac42aed), X64Word_create(0x53380d13, 0x9d95b3df), + X64Word_create(0x650a7354, 0x8baf63de), X64Word_create(0x766a0abb, 0x3c77b2a8), + X64Word_create(0x81c2c92e, 0x47edaee6), X64Word_create(0x92722c85, 0x1482353b), + X64Word_create(0xa2bfe8a1, 0x4cf10364), X64Word_create(0xa81a664b, 0xbc423001), + X64Word_create(0xc24b8b70, 0xd0f89791), X64Word_create(0xc76c51a3, 0x0654be30), + X64Word_create(0xd192e819, 0xd6ef5218), X64Word_create(0xd6990624, 0x5565a910), + X64Word_create(0xf40e3585, 0x5771202a), X64Word_create(0x106aa070, 0x32bbd1b8), + X64Word_create(0x19a4c116, 0xb8d2d0c8), X64Word_create(0x1e376c08, 0x5141ab53), + X64Word_create(0x2748774c, 0xdf8eeb99), X64Word_create(0x34b0bcb5, 0xe19b48a8), + X64Word_create(0x391c0cb3, 0xc5c95a63), X64Word_create(0x4ed8aa4a, 0xe3418acb), + X64Word_create(0x5b9cca4f, 0x7763e373), X64Word_create(0x682e6ff3, 0xd6b2b8a3), + X64Word_create(0x748f82ee, 0x5defb2fc), X64Word_create(0x78a5636f, 0x43172f60), + X64Word_create(0x84c87814, 0xa1f0ab72), X64Word_create(0x8cc70208, 0x1a6439ec), + X64Word_create(0x90befffa, 0x23631e28), X64Word_create(0xa4506ceb, 0xde82bde9), + X64Word_create(0xbef9a3f7, 0xb2c67915), X64Word_create(0xc67178f2, 0xe372532b), + X64Word_create(0xca273ece, 0xea26619c), X64Word_create(0xd186b8c7, 0x21c0c207), + X64Word_create(0xeada7dd6, 0xcde0eb1e), X64Word_create(0xf57d4f7f, 0xee6ed178), + X64Word_create(0x06f067aa, 0x72176fba), X64Word_create(0x0a637dc5, 0xa2c898a6), + X64Word_create(0x113f9804, 0xbef90dae), X64Word_create(0x1b710b35, 0x131c471b), + X64Word_create(0x28db77f5, 0x23047d84), X64Word_create(0x32caab7b, 0x40c72493), + X64Word_create(0x3c9ebe0a, 0x15c9bebc), X64Word_create(0x431d67c4, 0x9c100d4c), + X64Word_create(0x4cc5d4be, 0xcb3e42b6), X64Word_create(0x597f299c, 0xfc657e2a), + X64Word_create(0x5fcb6fab, 0x3ad6faec), X64Word_create(0x6c44198c, 0x4a475817) + ]; + + // Reusable objects + var W = []; + (function () { + for (var i = 0; i < 80; i++) { + W[i] = X64Word_create(); + } + }()); + + /** + * SHA-512 hash algorithm. + */ + var SHA512 = C_algo.SHA512 = Hasher.extend({ + _doReset: function () { + this._hash = new X64WordArray.init([ + new X64Word.init(0x6a09e667, 0xf3bcc908), new X64Word.init(0xbb67ae85, 0x84caa73b), + new X64Word.init(0x3c6ef372, 0xfe94f82b), new X64Word.init(0xa54ff53a, 0x5f1d36f1), + new X64Word.init(0x510e527f, 0xade682d1), new X64Word.init(0x9b05688c, 0x2b3e6c1f), + new X64Word.init(0x1f83d9ab, 0xfb41bd6b), new X64Word.init(0x5be0cd19, 0x137e2179) + ]); + }, + + _doProcessBlock: function (M, offset) { + // Shortcuts + var H = this._hash.words; + + var H0 = H[0]; + var H1 = H[1]; + var H2 = H[2]; + var H3 = H[3]; + var H4 = H[4]; + var H5 = H[5]; + var H6 = H[6]; + var H7 = H[7]; + + var H0h = H0.high; + var H0l = H0.low; + var H1h = H1.high; + var H1l = H1.low; + var H2h = H2.high; + var H2l = H2.low; + var H3h = H3.high; + var H3l = H3.low; + var H4h = H4.high; + var H4l = H4.low; + var H5h = H5.high; + var H5l = H5.low; + var H6h = H6.high; + var H6l = H6.low; + var H7h = H7.high; + var H7l = H7.low; + + // Working variables + var ah = H0h; + var al = H0l; + var bh = H1h; + var bl = H1l; + var ch = H2h; + var cl = H2l; + var dh = H3h; + var dl = H3l; + var eh = H4h; + var el = H4l; + var fh = H5h; + var fl = H5l; + var gh = H6h; + var gl = H6l; + var hh = H7h; + var hl = H7l; + + // Rounds + for (var i = 0; i < 80; i++) { + // Shortcut + var Wi = W[i]; + + // Extend message + if (i < 16) { + var Wih = Wi.high = M[offset + i * 2] | 0; + var Wil = Wi.low = M[offset + i * 2 + 1] | 0; + } else { + // Gamma0 + var gamma0x = W[i - 15]; + var gamma0xh = gamma0x.high; + var gamma0xl = gamma0x.low; + var gamma0h = ((gamma0xh >>> 1) | (gamma0xl << 31)) ^ ((gamma0xh >>> 8) | (gamma0xl << 24)) ^ (gamma0xh >>> 7); + var gamma0l = ((gamma0xl >>> 1) | (gamma0xh << 31)) ^ ((gamma0xl >>> 8) | (gamma0xh << 24)) ^ ((gamma0xl >>> 7) | (gamma0xh << 25)); + + // Gamma1 + var gamma1x = W[i - 2]; + var gamma1xh = gamma1x.high; + var gamma1xl = gamma1x.low; + var gamma1h = ((gamma1xh >>> 19) | (gamma1xl << 13)) ^ ((gamma1xh << 3) | (gamma1xl >>> 29)) ^ (gamma1xh >>> 6); + var gamma1l = ((gamma1xl >>> 19) | (gamma1xh << 13)) ^ ((gamma1xl << 3) | (gamma1xh >>> 29)) ^ ((gamma1xl >>> 6) | (gamma1xh << 26)); + + // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16] + var Wi7 = W[i - 7]; + var Wi7h = Wi7.high; + var Wi7l = Wi7.low; + + var Wi16 = W[i - 16]; + var Wi16h = Wi16.high; + var Wi16l = Wi16.low; + + var Wil = gamma0l + Wi7l; + var Wih = gamma0h + Wi7h + ((Wil >>> 0) < (gamma0l >>> 0) ? 1 : 0); + var Wil = Wil + gamma1l; + var Wih = Wih + gamma1h + ((Wil >>> 0) < (gamma1l >>> 0) ? 1 : 0); + var Wil = Wil + Wi16l; + var Wih = Wih + Wi16h + ((Wil >>> 0) < (Wi16l >>> 0) ? 1 : 0); + + Wi.high = Wih; + Wi.low = Wil; + } + + var chh = (eh & fh) ^ (~eh & gh); + var chl = (el & fl) ^ (~el & gl); + var majh = (ah & bh) ^ (ah & ch) ^ (bh & ch); + var majl = (al & bl) ^ (al & cl) ^ (bl & cl); + + var sigma0h = ((ah >>> 28) | (al << 4)) ^ ((ah << 30) | (al >>> 2)) ^ ((ah << 25) | (al >>> 7)); + var sigma0l = ((al >>> 28) | (ah << 4)) ^ ((al << 30) | (ah >>> 2)) ^ ((al << 25) | (ah >>> 7)); + var sigma1h = ((eh >>> 14) | (el << 18)) ^ ((eh >>> 18) | (el << 14)) ^ ((eh << 23) | (el >>> 9)); + var sigma1l = ((el >>> 14) | (eh << 18)) ^ ((el >>> 18) | (eh << 14)) ^ ((el << 23) | (eh >>> 9)); + + // t1 = h + sigma1 + ch + K[i] + W[i] + var Ki = K[i]; + var Kih = Ki.high; + var Kil = Ki.low; + + var t1l = hl + sigma1l; + var t1h = hh + sigma1h + ((t1l >>> 0) < (hl >>> 0) ? 1 : 0); + var t1l = t1l + chl; + var t1h = t1h + chh + ((t1l >>> 0) < (chl >>> 0) ? 1 : 0); + var t1l = t1l + Kil; + var t1h = t1h + Kih + ((t1l >>> 0) < (Kil >>> 0) ? 1 : 0); + var t1l = t1l + Wil; + var t1h = t1h + Wih + ((t1l >>> 0) < (Wil >>> 0) ? 1 : 0); + + // t2 = sigma0 + maj + var t2l = sigma0l + majl; + var t2h = sigma0h + majh + ((t2l >>> 0) < (sigma0l >>> 0) ? 1 : 0); + + // Update working variables + hh = gh; + hl = gl; + gh = fh; + gl = fl; + fh = eh; + fl = el; + el = (dl + t1l) | 0; + eh = (dh + t1h + ((el >>> 0) < (dl >>> 0) ? 1 : 0)) | 0; + dh = ch; + dl = cl; + ch = bh; + cl = bl; + bh = ah; + bl = al; + al = (t1l + t2l) | 0; + ah = (t1h + t2h + ((al >>> 0) < (t1l >>> 0) ? 1 : 0)) | 0; + } + + // Intermediate hash value + H0l = H0.low = (H0l + al); + H0.high = (H0h + ah + ((H0l >>> 0) < (al >>> 0) ? 1 : 0)); + H1l = H1.low = (H1l + bl); + H1.high = (H1h + bh + ((H1l >>> 0) < (bl >>> 0) ? 1 : 0)); + H2l = H2.low = (H2l + cl); + H2.high = (H2h + ch + ((H2l >>> 0) < (cl >>> 0) ? 1 : 0)); + H3l = H3.low = (H3l + dl); + H3.high = (H3h + dh + ((H3l >>> 0) < (dl >>> 0) ? 1 : 0)); + H4l = H4.low = (H4l + el); + H4.high = (H4h + eh + ((H4l >>> 0) < (el >>> 0) ? 1 : 0)); + H5l = H5.low = (H5l + fl); + H5.high = (H5h + fh + ((H5l >>> 0) < (fl >>> 0) ? 1 : 0)); + H6l = H6.low = (H6l + gl); + H6.high = (H6h + gh + ((H6l >>> 0) < (gl >>> 0) ? 1 : 0)); + H7l = H7.low = (H7l + hl); + H7.high = (H7h + hh + ((H7l >>> 0) < (hl >>> 0) ? 1 : 0)); + }, + + _doFinalize: function () { + // Shortcuts + var data = this._data; + var dataWords = data.words; + + var nBitsTotal = this._nDataBytes * 8; + var nBitsLeft = data.sigBytes * 8; + + // Add padding + dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); + dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 30] = Math.floor(nBitsTotal / 0x100000000); + dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 31] = nBitsTotal; + data.sigBytes = dataWords.length * 4; + + // Hash final blocks + this._process(); + + // Convert hash to 32-bit word array before returning + var hash = this._hash.toX32(); + + // Return final computed hash + return hash; + }, + + clone: function () { + var clone = Hasher.clone.call(this); + clone._hash = this._hash.clone(); + + return clone; + }, + + blockSize: 1024/32 + }); + + /** + * Shortcut function to the hasher's object interface. + * + * @param {WordArray|string} message The message to hash. + * + * @return {WordArray} The hash. + * + * @static + * + * @example + * + * var hash = CryptoJS.SHA512('message'); + * var hash = CryptoJS.SHA512(wordArray); + */ + C.SHA512 = Hasher._createHelper(SHA512); + + /** + * Shortcut function to the HMAC's object interface. + * + * @param {WordArray|string} message The message to hash. + * @param {WordArray|string} key The secret key. + * + * @return {WordArray} The HMAC. + * + * @static + * + * @example + * + * var hmac = CryptoJS.HmacSHA512(message, key); + */ + C.HmacSHA512 = Hasher._createHmacHelper(SHA512); +}());+ \ No newline at end of file diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Util/Crypto/x64-core.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Util/Crypto/x64-core.js @@ -0,0 +1,284 @@ +(function (undefined) { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var Base = C_lib.Base; + var X32WordArray = C_lib.WordArray; + + /** + * x64 namespace. + */ + var C_x64 = C.x64 = {}; + + /** + * A 64-bit word. + */ + var X64Word = C_x64.Word = Base.extend({ + /** + * Initializes a newly created 64-bit word. + * + * @param {number} high The high 32 bits. + * @param {number} low The low 32 bits. + * + * @example + * + * var x64Word = CryptoJS.x64.Word.create(0x00010203, 0x04050607); + */ + init: function (high, low) { + this.high = high; + this.low = low; + } + + /** + * Bitwise NOTs this word. + * + * @return {X64Word} A new x64-Word object after negating. + * + * @example + * + * var negated = x64Word.not(); + */ + // not: function () { + // var high = ~this.high; + // var low = ~this.low; + + // return X64Word.create(high, low); + // }, + + /** + * Bitwise ANDs this word with the passed word. + * + * @param {X64Word} word The x64-Word to AND with this word. + * + * @return {X64Word} A new x64-Word object after ANDing. + * + * @example + * + * var anded = x64Word.and(anotherX64Word); + */ + // and: function (word) { + // var high = this.high & word.high; + // var low = this.low & word.low; + + // return X64Word.create(high, low); + // }, + + /** + * Bitwise ORs this word with the passed word. + * + * @param {X64Word} word The x64-Word to OR with this word. + * + * @return {X64Word} A new x64-Word object after ORing. + * + * @example + * + * var ored = x64Word.or(anotherX64Word); + */ + // or: function (word) { + // var high = this.high | word.high; + // var low = this.low | word.low; + + // return X64Word.create(high, low); + // }, + + /** + * Bitwise XORs this word with the passed word. + * + * @param {X64Word} word The x64-Word to XOR with this word. + * + * @return {X64Word} A new x64-Word object after XORing. + * + * @example + * + * var xored = x64Word.xor(anotherX64Word); + */ + // xor: function (word) { + // var high = this.high ^ word.high; + // var low = this.low ^ word.low; + + // return X64Word.create(high, low); + // }, + + /** + * Shifts this word n bits to the left. + * + * @param {number} n The number of bits to shift. + * + * @return {X64Word} A new x64-Word object after shifting. + * + * @example + * + * var shifted = x64Word.shiftL(25); + */ + // shiftL: function (n) { + // if (n < 32) { + // var high = (this.high << n) | (this.low >>> (32 - n)); + // var low = this.low << n; + // } else { + // var high = this.low << (n - 32); + // var low = 0; + // } + + // return X64Word.create(high, low); + // }, + + /** + * Shifts this word n bits to the right. + * + * @param {number} n The number of bits to shift. + * + * @return {X64Word} A new x64-Word object after shifting. + * + * @example + * + * var shifted = x64Word.shiftR(7); + */ + // shiftR: function (n) { + // if (n < 32) { + // var low = (this.low >>> n) | (this.high << (32 - n)); + // var high = this.high >>> n; + // } else { + // var low = this.high >>> (n - 32); + // var high = 0; + // } + + // return X64Word.create(high, low); + // }, + + /** + * Rotates this word n bits to the left. + * + * @param {number} n The number of bits to rotate. + * + * @return {X64Word} A new x64-Word object after rotating. + * + * @example + * + * var rotated = x64Word.rotL(25); + */ + // rotL: function (n) { + // return this.shiftL(n).or(this.shiftR(64 - n)); + // }, + + /** + * Rotates this word n bits to the right. + * + * @param {number} n The number of bits to rotate. + * + * @return {X64Word} A new x64-Word object after rotating. + * + * @example + * + * var rotated = x64Word.rotR(7); + */ + // rotR: function (n) { + // return this.shiftR(n).or(this.shiftL(64 - n)); + // }, + + /** + * Adds this word with the passed word. + * + * @param {X64Word} word The x64-Word to add with this word. + * + * @return {X64Word} A new x64-Word object after adding. + * + * @example + * + * var added = x64Word.add(anotherX64Word); + */ + // add: function (word) { + // var low = (this.low + word.low) | 0; + // var carry = (low >>> 0) < (this.low >>> 0) ? 1 : 0; + // var high = (this.high + word.high + carry) | 0; + + // return X64Word.create(high, low); + // } + }); + + /** + * An array of 64-bit words. + * + * @property {Array} words The array of CryptoJS.x64.Word objects. + * @property {number} sigBytes The number of significant bytes in this word array. + */ + var X64WordArray = C_x64.WordArray = Base.extend({ + /** + * Initializes a newly created word array. + * + * @param {Array} words (Optional) An array of CryptoJS.x64.Word objects. + * @param {number} sigBytes (Optional) The number of significant bytes in the words. + * + * @example + * + * var wordArray = CryptoJS.x64.WordArray.create(); + * + * var wordArray = CryptoJS.x64.WordArray.create([ + * CryptoJS.x64.Word.create(0x00010203, 0x04050607), + * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f) + * ]); + * + * var wordArray = CryptoJS.x64.WordArray.create([ + * CryptoJS.x64.Word.create(0x00010203, 0x04050607), + * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f) + * ], 10); + */ + init: function (words, sigBytes) { + words = this.words = words || []; + + if (sigBytes != undefined) { + this.sigBytes = sigBytes; + } else { + this.sigBytes = words.length * 8; + } + }, + + /** + * Converts this 64-bit word array to a 32-bit word array. + * + * @return {CryptoJS.lib.WordArray} This word array's data as a 32-bit word array. + * + * @example + * + * var x32WordArray = x64WordArray.toX32(); + */ + toX32: function () { + // Shortcuts + var x64Words = this.words; + var x64WordsLength = x64Words.length; + + // Convert + var x32Words = []; + for (var i = 0; i < x64WordsLength; i++) { + var x64Word = x64Words[i]; + x32Words.push(x64Word.high); + x32Words.push(x64Word.low); + } + + return X32WordArray.create(x32Words, this.sigBytes); + }, + + /** + * Creates a copy of this word array. + * + * @return {X64WordArray} The clone. + * + * @example + * + * var clone = x64WordArray.clone(); + */ + clone: function () { + var clone = Base.clone.call(this); + + // Clone "words" array + var words = clone.words = this.words.slice(0); + + // Clone each X64Word object + var wordsLength = words.length; + for (var i = 0; i < wordsLength; i++) { + words[i] = words[i].clone(); + } + + return clone; + } + }); +}());+ \ No newline at end of file diff --git a/src/PartKeepr/FrontendBundle/Resources/views/index.html.twig b/src/PartKeepr/FrontendBundle/Resources/views/index.html.twig @@ -39,6 +39,13 @@ 'js/packages/extjs6/build/ext-all-debug.js' 'js/packages/extjs6/build/packages/charts/classic/charts.js' 'js/packages/extjs6/build/packages/ux/classic/ux.js' + '@PartKeeprFrontendBundle/Resources/public/js/Util/Crypto/isaac.js' + '@PartKeeprFrontendBundle/Resources/public/js/Util/Crypto/bcrypt.js' + '@PartKeeprFrontendBundle/Resources/public/js/Util/Crypto/core.js' + '@PartKeeprFrontendBundle/Resources/public/js/Util/Crypto/x64-core.js' + '@PartKeeprFrontendBundle/Resources/public/js/Util/Crypto/sha512.js' + '@PartKeeprFrontendBundle/Resources/public/js/Util/Crypto/sha1.js' + '@PartKeeprFrontendBundle/Resources/public/js/Util/Crypto/enc-base64.js' '@PartKeeprFrontendBundle/Resources/public/js/ExtJS/Bugfixes/Ext.data.Model-EXTJS-15037.js' '@PartKeeprFrontendBundle/Resources/public/js/Util/i18n.js' '@PartKeeprFrontendBundle/Resources/public/js/Util/JsonWithAssociationsWriter.js' diff --git a/src/PartKeepr/TipOfTheDayBundle/Entity/TipOfTheDayHistory.php b/src/PartKeepr/TipOfTheDayBundle/Entity/TipOfTheDayHistory.php @@ -2,7 +2,7 @@ namespace PartKeepr\TipOfTheDayBundle\Entity; use Doctrine\ORM\Mapping as ORM; -use PartKeepr\AuthBundle\Entity\User\User; +use PartKeepr\AuthBundle\Entity\User; use PartKeepr\Util\BaseEntity; /** @@ -22,9 +22,9 @@ class TipOfTheDayHistory extends BaseEntity /** * Defines the user - * @ORM\ManyToOne(targetEntity="PartKeepr\AuthBundle\Entity\User\User") + * @ORM\ManyToOne(targetEntity="PartKeepr\AuthBundle\Entity\User") * - * @var User + * @var \PartKeepr\AuthBundle\Entity\User */ private $user; diff --git a/src/backend/PartKeepr/Part/PartService.php b/src/backend/PartKeepr/Part/PartService.php @@ -1,7 +1,7 @@ <?php namespace PartKeepr\Part; -use PartKeepr\AuthBundle\Entity\User\User; +use PartKeepr\AuthBundle\Entity\User; use PartKeepr\Manager\ManagerFilter; use PartKeepr\PartBundle\Entity\Part; use \PartKeepr\PartBundle\Entity\PartCategory; diff --git a/src/backend/PartKeepr/PartKeepr.php b/src/backend/PartKeepr/PartKeepr.php @@ -148,7 +148,7 @@ class PartKeepr { */ public static function getEntityClasses () { return array( - 'PartKeepr\AuthBundle\Entity\User\User', + 'PartKeepr\AuthBundle\Entity\User', 'PartKeepr\Session\Session', 'PartKeepr\EventNotification\Event', diff --git a/src/backend/PartKeepr/Project/Project.php b/src/backend/PartKeepr/Project/Project.php @@ -2,7 +2,7 @@ namespace PartKeepr\Project; use Doctrine\ORM\Mapping as ORM; -use PartKeepr\AuthBundle\Entity\User\User; +use PartKeepr\AuthBundle\Entity\User; use PartKeepr\Util\BaseEntity; use PartKeepr\Util\Deserializable; use PartKeepr\Util\Serializable; @@ -19,7 +19,7 @@ class Project extends BaseEntity implements Serializable, Deserializable { /** * Specifies the user this project belongs to - * @ORM\ManyToOne(targetEntity="PartKeepr\AuthBundle\Entity\User\User") + * @ORM\ManyToOne(targetEntity="PartKeepr\AuthBundle\Entity\User") */ private $user; @@ -63,7 +63,8 @@ class Project extends BaseEntity implements Serializable, Deserializable { /** * Gets the user for this project - * @return User + * +*@return \PartKeepr\AuthBundle\Entity\User */ public function getUser () { return $this->user; diff --git a/src/backend/PartKeepr/Service/Service.php b/src/backend/PartKeepr/Service/Service.php @@ -1,7 +1,7 @@ <?php namespace PartKeepr\Service; -use PartKeepr\AuthBundle\Entity\User\User; +use PartKeepr\AuthBundle\Entity\User; use PartKeepr\Service\Exceptions\ServiceException; use PartKeepr\Session\SessionManager; @@ -48,7 +48,7 @@ class Service { /** * Returns the current user for this session * - * @return User The user + * @return \PartKeepr\AuthBundle\Entity\User The user */ public function getUser () { return SessionManager::getCurrentSession()->getUser(); diff --git a/src/backend/PartKeepr/Service/ServiceManager.php b/src/backend/PartKeepr/Service/ServiceManager.php @@ -1,7 +1,7 @@ <?php namespace PartKeepr\Service; -use PartKeepr\AuthBundle\Entity\User\User; +use PartKeepr\AuthBundle\Entity\User; use PartKeepr\AuthBundle\Entity\User\UserManager; use PartKeepr\PartKeepr; use PartKeepr\REST\Request; diff --git a/src/backend/PartKeepr/Session/Session.php b/src/backend/PartKeepr/Session/Session.php @@ -2,7 +2,7 @@ namespace PartKeepr\Session; use Doctrine\ORM\Mapping as ORM; -use PartKeepr\AuthBundle\Entity\User\User; +use PartKeepr\AuthBundle\Entity\User; use Symfony\Component\HttpFoundation\Session\Session as SymfonySession; use PartKeepr\PartKeepr; use Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage; @@ -19,7 +19,7 @@ class Session { /** * @var User - * @ORM\ManyToOne(targetEntity="PartKeepr\AuthBundle\Entity\User\User") + * @ORM\ManyToOne(targetEntity="PartKeepr\AuthBundle\Entity\User") */ private $user; @@ -58,7 +58,8 @@ class Session { /** * Returns the user object - * @return User + * +*@return \PartKeepr\AuthBundle\Entity\User */ public function getUser () { return $this->user; diff --git a/src/backend/PartKeepr/Session/SessionManager.php b/src/backend/PartKeepr/Session/SessionManager.php @@ -1,7 +1,7 @@ <?php namespace PartKeepr\Session; -use PartKeepr\AuthBundle\Entity\User\User; +use PartKeepr\AuthBundle\Entity\User; use PartKeepr\PartKeepr; use PartKeepr\Session\Exceptions\SessionNotFoundException; use PartKeepr\Util\Singleton; diff --git a/src/backend/PartKeepr/Setup/UserSetup.php b/src/backend/PartKeepr/Setup/UserSetup.php @@ -1,14 +1,14 @@ <?php namespace PartKeepr\Setup; -use PartKeepr\AuthBundle\Entity\User\User; +use PartKeepr\AuthBundle\Entity\User; /** * Creates a new admin user, but only if no admin user exists. */ class UserSetup extends AbstractSetup { public function run () { - $dql = "SELECT COUNT(u) FROM PartKeepr\AuthBundle\Entity\User\User u WHERE u.username = :username OR u.admin = :admin"; + $dql = "SELECT COUNT(u) FROM PartKeepr\AuthBundle\Entity\User u WHERE u.username = :username OR u.admin = :admin"; $query = $this->entityManager->createQuery($dql); $query->setParameter("username", "admin"); $query->setParameter("admin", true); diff --git a/src/backend/PartKeepr/Stock/StockEntry.php b/src/backend/PartKeepr/Stock/StockEntry.php @@ -3,7 +3,7 @@ namespace PartKeepr\Stock; use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping\HasLifecycleCallbacks; -use PartKeepr\AuthBundle\Entity\User\User; +use PartKeepr\AuthBundle\Entity\User; use PartKeepr\PartBundle\Entity\Part; use PartKeepr\PartKeepr; use PartKeepr\Util\BaseEntity; @@ -22,7 +22,7 @@ class StockEntry extends BaseEntity implements Serializable { private $part; /** - * @ORM\ManyToOne(targetEntity="PartKeepr\AuthBundle\Entity\User\User") + * @ORM\ManyToOne(targetEntity="PartKeepr\AuthBundle\Entity\User") */ private $user; @@ -60,7 +60,7 @@ class StockEntry extends BaseEntity implements Serializable { * * @param \PartKeepr\PartBundle\Entity\Part $part The part which was added/removed * @param int $stockLevel The stock level. Positive value means added parts, negative values means removed parts. - * @param User $user The user who removed/added parts + * @param \PartKeepr\AuthBundle\Entity\User $user The user who removed/added parts */ public function __construct (Part $part, $stockLevel, User $user = null) { $this->setPart($part); @@ -158,7 +158,8 @@ class StockEntry extends BaseEntity implements Serializable { /** * Sets the user assigned to this entry. - * @param User $user The user The user to set + * +*@param \PartKeepr\AuthBundle\Entity\User $user The user The user to set */ public function setUser (User $user = null) { $this->user = $user; diff --git a/src/backend/PartKeepr/Stock/StockService.php b/src/backend/PartKeepr/Stock/StockService.php @@ -1,7 +1,7 @@ <?php namespace PartKeepr\Stock; -use PartKeepr\AuthBundle\Entity\User\User; +use PartKeepr\AuthBundle\Entity\User; use PartKeepr\Manager\ManagerFilter; use PartKeepr\PartKeepr; use PartKeepr\Service\RestfulService; diff --git a/src/backend/PartKeepr/User/UserService.php b/src/backend/PartKeepr/User/UserService.php @@ -1,6 +1,7 @@ <?php namespace PartKeepr\AuthBundle\Entity\User; +use PartKeepr\AuthBundle\Entity\User; use PartKeepr\Manager\ManagerFilter; use PartKeepr\PartKeepr; use PartKeepr\Service\FilterExtractor; diff --git a/src/backend/PartKeepr/UserPreference/Exceptions/UserPreferenceNotFoundException.php b/src/backend/PartKeepr/UserPreference/Exceptions/UserPreferenceNotFoundException.php @@ -1,7 +1,7 @@ <?php namespace PartKeepr\UserPreference\Exceptions; -use PartKeepr\AuthBundle\Entity\User\User; +use PartKeepr\AuthBundle\Entity\User; use PartKeepr\PartKeepr; use PartKeepr\Util\SerializableException; diff --git a/src/backend/PartKeepr/UserPreference/UserPreference.php b/src/backend/PartKeepr/UserPreference/UserPreference.php @@ -3,7 +3,7 @@ namespace PartKeepr\UserPreference; use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\NoResultException; -use PartKeepr\AuthBundle\Entity\User\User; +use PartKeepr\AuthBundle\Entity\User; use PartKeepr\PartKeepr; use PartKeepr\UserPreference\Exceptions\UserPreferenceNotFoundException; use PartKeepr\Util\Exceptions\EntityNotPersistantException; @@ -39,16 +39,18 @@ class UserPreference implements Serializable { /** * Defines the user - * @ORM\ManyToOne(targetEntity="PartKeepr\AuthBundle\Entity\User\User") - * @ORM\Id - * @var User + * @ORM\ManyToOne(targetEntity="PartKeepr\AuthBundle\Entity\User") + * +*@ORM\Id + * @var \PartKeepr\AuthBundle\Entity\User */ private $user; /** * Sets the user for this entry - * @param User $user + * +*@param \PartKeepr\AuthBundle\Entity\User $user */ public function setUser (User $user) { $this->user = $user; @@ -57,7 +59,7 @@ class UserPreference implements Serializable { /** * Returns the user associated with this entry * -*@return \PartKeepr\AuthBundle\Entity\User\User +*@return \PartKeepr\AuthBundle\Entity\User */ public function getUser () { return $this->user; @@ -159,8 +161,10 @@ class UserPreference implements Serializable { /** * Returns all preferences for the given user - * @param User $user The user - * @throws EntityNotPersistantException Thrown if the user entity is not persistent + * +*@param \PartKeepr\AuthBundle\Entity\User $user The user + * +*@throws EntityNotPersistantException Thrown if the user entity is not persistent */ public static function getPreferences (User $user) { if (!PartKeepr::getEM()->contains($user)) { @@ -178,9 +182,10 @@ class UserPreference implements Serializable { /** * Returns a specific preference object for the given user * - * @param User $user The user to retrieve the preference for + * @param \PartKeepr\AuthBundle\Entity\User $user The user to retrieve the preference for * @param string $key The preference key to retrieve - * @return UserPreference The preference object + * +*@return UserPreference The preference object * @throws UserPreferenceNotFoundException Thrown if the preference key was not found * @throws EntityNotPersistantException Thrown if the entity is not persistant */ @@ -206,10 +211,11 @@ class UserPreference implements Serializable { /** * Removes a specific setting for a specific user. - * - * @param User $user The user to delete the preference for + * + * @param \PartKeepr\AuthBundle\Entity\User $user The user to delete the preference for * @param string $key The key to delete - * @throws EntityNotPersistantException Thrown if the entity is not persistant + * +*@throws EntityNotPersistantException Thrown if the entity is not persistant */ public static function deletePreference (User $user, $key) { if (!PartKeepr::getEM()->contains($user)) { diff --git a/src/backend/PartKeepr/UserPreference/UserPreferenceService.php b/src/backend/PartKeepr/UserPreference/UserPreferenceService.php @@ -1,7 +1,7 @@ <?php namespace PartKeepr\UserPreference; -use PartKeepr\AuthBundle\Entity\User\User; +use PartKeepr\AuthBundle\Entity\User; use PartKeepr\PartKeepr; use PartKeepr\Service\RestfulService; use PartKeepr\Service\Service;