Esempio n. 1
0
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
require_once dirname(__FILE__) . "/BitID.php";
require_once dirname(__FILE__) . "/DAO.php";
$bitid = new BitID();
$dao = new DAO();
$variables = $_POST;
$post_data = json_decode(file_get_contents('php://input'), true);
// SIGNED VIA PHONE WALLET (data is send as payload)
if ($post_data !== null) {
    $variables = $post_data;
}
// ALL THOSE VARIABLES HAVE TO BE SANITIZED !
$signValid = $bitid->isMessageSignatureValidSafe(@$variables['address'], @$variables['signature'], @$variables['uri'], true);
$nonce = $bitid->extractNonce($variables['uri']);
if ($signValid && $dao->checkNonce($nonce) && $bitid->buildURI(SERVER_URL . 'callback.php', $nonce) === $variables['uri']) {
    $dao->update($nonce, $variables['address']);
    // SIGNED VIA PHONE WALLET (data is send as payload)
    if ($post_data !== null) {
        //DO NOTHING
Esempio n. 2
0
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// BitID is required for login (do not modify)
// DAO could be replace by your CMS/FRAMEWORK database classes
require_once dirname(__FILE__) . "/config.php";
require_once dirname(__FILE__) . "/BitID.php";
require_once dirname(__FILE__) . "/DAO.php";
$bitid = new BitID();
// generate a nonce
$nonce = $bitid->generateNonce();
// build uri with nonce, nonce is optional, but we pre-calculate it to avoid extracting it later
$bitid_uri = $bitid->buildURI(SERVER_URL . 'callback.php', $nonce);
// Insert nonce + IP in the database to avoid an attacker go and try several nonces
// This will only allow one nonce per IP, but it could be easily modified to allow severals per IP
// (this is deleted after an user successfully log in the system, so only will collide if two or more users try to log in at the same time)
$dao = new DAO();
$result = $dao->insert($nonce, @$_SERVER['REMOTE_ADDR']);
if (!$result) {
    echo "<pre>";
    echo "Database failer\n";
    var_dump($dao);
    die;
}