datein hinzufügen
This commit is contained in:
1283
api/1.0/index.php
Normal file
1283
api/1.0/index.php
Normal file
File diff suppressed because it is too large
Load Diff
1268
api/1.1/index.php
Normal file
1268
api/1.1/index.php
Normal file
File diff suppressed because it is too large
Load Diff
2071
api/1.2/index.php
Normal file
2071
api/1.2/index.php
Normal file
File diff suppressed because it is too large
Load Diff
191
api/dashboard/webauthn.php
Normal file
191
api/dashboard/webauthn.php
Normal file
@@ -0,0 +1,191 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2022 Lukas Buchs
|
||||
* license https://github.com/lbuchs/WebAuthn/blob/master/LICENSE MIT
|
||||
*
|
||||
* Server test script for WebAuthn library. Saves new registrations in session.
|
||||
*
|
||||
* JAVASCRIPT | SERVER
|
||||
* ------------------------------------------------------------
|
||||
*
|
||||
* REGISTRATION
|
||||
*
|
||||
* window.fetch -----------------> getCreateArgs
|
||||
* |
|
||||
* navigator.credentials.create <-------------'
|
||||
* |
|
||||
* '-------------------------> processCreate
|
||||
* |
|
||||
* alert ok or fail <----------------'
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
*
|
||||
* VALIDATION
|
||||
*
|
||||
* window.fetch ------------------> getGetArgs
|
||||
* |
|
||||
* navigator.credentials.get <----------------'
|
||||
* |
|
||||
* '-------------------------> processGet
|
||||
* |
|
||||
* alert ok or fail <----------------'
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
*/
|
||||
include '../../includes/misc/autoload.phtml';
|
||||
require_once '../../vendor/lbuchs/webauthn/src/WebAuthn.php';
|
||||
try {
|
||||
// read get argument and post body
|
||||
$fn = filter_input(INPUT_GET, 'fn');
|
||||
if(empty($fn)) {
|
||||
die("Can't access directly");
|
||||
}
|
||||
$post = trim(file_get_contents('php://input'));
|
||||
$userId = bin2hex(openssl_random_pseudo_bytes(10));
|
||||
if ($post) {
|
||||
$post = json_decode($post);
|
||||
}
|
||||
|
||||
session_start();
|
||||
// Formats
|
||||
$formats = array();
|
||||
$formats[] = 'none';
|
||||
|
||||
$rpId = $_SERVER['HTTP_HOST'];
|
||||
|
||||
// cross-platform: true, if type internal is not allowed
|
||||
// false, if only internal is allowed
|
||||
// null, if internal and cross-platform is allowed
|
||||
$crossPlatformAttachment = null;
|
||||
|
||||
|
||||
// new Instance of the server library.
|
||||
// make sure that $rpId is the domain name.
|
||||
$WebAuthn = new lbuchs\WebAuthn\WebAuthn('KeyAuth', $rpId, $formats);
|
||||
|
||||
// ------------------------------------
|
||||
// request for create arguments
|
||||
// ------------------------------------
|
||||
|
||||
if ($fn === 'getCreateArgs') {
|
||||
$createArgs = $WebAuthn->getCreateArgs($userId, $_SESSION['username'], "", 20, 0, "discouraged", $crossPlatformAttachment);
|
||||
|
||||
header('Content-Type: application/json');
|
||||
print(json_encode($createArgs));
|
||||
|
||||
// save challange to session. you have to deliver it to processGet later.
|
||||
$_SESSION['challenge'] = $WebAuthn->getChallenge();
|
||||
|
||||
|
||||
|
||||
// ------------------------------------
|
||||
// request for get arguments
|
||||
// ------------------------------------
|
||||
|
||||
} else if ($fn === 'getGetArgs') {
|
||||
$ids = array();
|
||||
|
||||
// load registrations from session stored there by processCreate.
|
||||
|
||||
$query = misc\mysql\query("SELECT * FROM `securityKeys` WHERE `username` = ?", [$_SESSION['pendingUsername']]);
|
||||
if ($query->num_rows > 0) {
|
||||
while ($row = mysqli_fetch_array($query->result)) {
|
||||
$ids[] = base64_decode($row["credentialId"]);
|
||||
}
|
||||
}
|
||||
|
||||
if (count($ids) === 0) {
|
||||
throw new Exception('No security key registrations found for this user!');
|
||||
}
|
||||
|
||||
$getArgs = $WebAuthn->getGetArgs($ids, 20, 1, 1, 1, 1, 0);
|
||||
|
||||
header('Content-Type: application/json');
|
||||
print(json_encode($getArgs));
|
||||
|
||||
// save challange to session. you have to deliver it to processGet later.
|
||||
$_SESSION['challenge'] = $WebAuthn->getChallenge();
|
||||
|
||||
|
||||
|
||||
// ------------------------------------
|
||||
// process create
|
||||
// ------------------------------------
|
||||
|
||||
} else if ($fn === 'processCreate') {
|
||||
$clientDataJSON = base64_decode($post->clientDataJSON);
|
||||
$attestationObject = base64_decode($post->attestationObject);
|
||||
$challenge = $_SESSION['challenge'];
|
||||
|
||||
// processCreate returns data to be stored for future logins.
|
||||
$data = $WebAuthn->processCreate($clientDataJSON, $attestationObject, $challenge, 0, false, false);
|
||||
|
||||
unset($_SESSION['challenge']); // disgard challenge array from session file, no longer needed
|
||||
|
||||
$name = misc\etc\sanitize($_GET['name']);
|
||||
|
||||
misc\mysql\query("INSERT INTO `securityKeys` (`username`, `name`, `credentialId`, `credentialPublicKey`) VALUES (?, ?, ?, ?)", [$_SESSION['username'], $name, base64_encode($data->credentialId), $data->credentialPublicKey]);
|
||||
misc\mysql\query("UPDATE `accounts` SET `securityKey` = 1 WHERE `username` = ?", [$_SESSION['username']]);
|
||||
|
||||
$return = new stdClass();
|
||||
$return->success = true;
|
||||
$return->msg = 'registration success.';
|
||||
|
||||
header('Content-Type: application/json');
|
||||
print(json_encode($return));
|
||||
|
||||
|
||||
|
||||
// ------------------------------------
|
||||
// proccess get
|
||||
// ------------------------------------
|
||||
|
||||
} else if ($fn === 'processGet') {
|
||||
$clientDataJSON = base64_decode($post->clientDataJSON);
|
||||
$authenticatorData = base64_decode($post->authenticatorData);
|
||||
$signature = base64_decode($post->signature);
|
||||
$userHandle = base64_decode($post->userHandle);
|
||||
$id = base64_decode($post->id);
|
||||
$challenge = $_SESSION['challenge'];
|
||||
$credentialPublicKey = null;
|
||||
|
||||
// looking up correspondending public key of the credential id
|
||||
// you should also validate that only ids of the given user name
|
||||
// are taken for the login.
|
||||
|
||||
$query = misc\mysql\query("SELECT * FROM `securityKeys` WHERE `username` = ?", [$_SESSION['pendingUsername']]);
|
||||
if ($query->num_rows > 0) {
|
||||
while ($row = mysqli_fetch_array($query->result)) {
|
||||
if(base64_decode($row["credentialId"]) === $id) {
|
||||
$credentialPublicKey = $row["credentialPublicKey"];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($credentialPublicKey === null) {
|
||||
throw new Exception('This security key wasn\'t found!');
|
||||
}
|
||||
|
||||
// process the get request. throws WebAuthnException if it fails
|
||||
$WebAuthn->processGet($clientDataJSON, $authenticatorData, $signature, $credentialPublicKey, $challenge, null, 0);
|
||||
|
||||
unset($_SESSION['challenge']); // disgard challenge array from session file, no longer needed
|
||||
$_SESSION['username'] = $_SESSION['pendingUsername'];
|
||||
unset($_SESSION['pendingUsername']);
|
||||
|
||||
$return = new stdClass();
|
||||
$return->success = true;
|
||||
|
||||
header('Content-Type: application/json');
|
||||
print(json_encode($return));
|
||||
}
|
||||
|
||||
} catch (Throwable $ex) {
|
||||
$return = new stdClass();
|
||||
$return->success = false;
|
||||
$return->msg = $ex->getMessage();
|
||||
|
||||
header('Content-Type: application/json');
|
||||
print(json_encode($return));
|
||||
}
|
||||
3
api/index.php
Normal file
3
api/index.php
Normal file
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
header("Location: https://keyauth.cc/docs");
|
||||
exit();
|
||||
304
api/reseller/index.php
Normal file
304
api/reseller/index.php
Normal file
@@ -0,0 +1,304 @@
|
||||
<?php
|
||||
if (!isset($_SERVER["HTTP_X_SELLIX_SIGNATURE"]) && !isset($_SERVER["HTTP_X_SHOPPY_SIGNATURE"]) && !isset($_SERVER["HTTP_SIGNATURE"]))
|
||||
{
|
||||
require '../../includes/dashboard/autoload.phtml';
|
||||
die("Request isn't coming from SellApp, Sellix, or Shoppy.");
|
||||
}
|
||||
|
||||
include '../../includes/misc/autoload.phtml';
|
||||
require '../../includes/dashboard/autoload.phtml';
|
||||
|
||||
if (isset($_SERVER["HTTP_X_SELLIX_SIGNATURE"]))
|
||||
{
|
||||
$app = misc\etc\sanitize($_GET['app']);
|
||||
$query = misc\mysql\query("SELECT * FROM `apps` WHERE `secret` = ?", [$app]);
|
||||
|
||||
if ($query->num_rows < 1)
|
||||
{ // if no application was found with the supplied secret as the 'app' paramater
|
||||
die("Failure: application not found");
|
||||
}
|
||||
$row = mysqli_fetch_array($query->result);
|
||||
$name = $row["name"];
|
||||
$secret = $row["sellixsecret"];
|
||||
$dayproduct = $row["sellixdayproduct"];
|
||||
$weekproduct = $row["sellixweekproduct"];
|
||||
$monthproduct = $row["sellixmonthproduct"];
|
||||
$lifetimeproduct = $row["sellixlifetimeproduct"];
|
||||
|
||||
$payload = file_get_contents('php://input');
|
||||
$header_signature = misc\etc\sanitize($_SERVER["HTTP_X_SELLIX_SIGNATURE"]);
|
||||
$signature = hash_hmac('sha512', $payload, $secret);
|
||||
if (!hash_equals($signature, $header_signature))
|
||||
{ // if the sellix webhook secret the request was sent from didn't match the one set in the database
|
||||
die("Failure: authentication with sellix secret failed");
|
||||
}
|
||||
|
||||
$json = json_decode($payload);
|
||||
$data = $json->data;
|
||||
$custom = $data->custom_fields; // getting custom fields, the hidden fields on KeyAuth sellix embed which provide sellix the KeyAuth username
|
||||
$un = misc\etc\sanitize($custom->username);
|
||||
|
||||
$query = misc\mysql\query("SELECT `balance` FROM `accounts` WHERE `username` = ? AND `app` = ?", [$un, $name]);
|
||||
|
||||
if ($query->num_rows < 1)
|
||||
{ // if reseller not found
|
||||
die("Failure: No account with the supplied username under this application found");
|
||||
}
|
||||
// getting the balance of each key length for the specified reseller account
|
||||
$row = mysqli_fetch_array($query->result);
|
||||
$balance = $row["balance"];
|
||||
$balance = explode("|", $balance);
|
||||
$day = $balance[0];
|
||||
$week = $balance[1];
|
||||
$month = $balance[2];
|
||||
$threemonth = $balance[3];
|
||||
$sixmonth = $balance[4];
|
||||
$lifetime = $balance[5];
|
||||
$year = $balance[6];
|
||||
|
||||
$amount = misc\etc\sanitize($data->quantity); // find quantity of keys purchased
|
||||
// then given the duration of keys they purchased, add to their balance
|
||||
|
||||
if(isset($_GET['expiry'])) {
|
||||
$expiry = misc\etc\sanitize($_GET['expiry']);
|
||||
$level = misc\etc\sanitize($_GET['level']);
|
||||
|
||||
$key = misc\license\createLicense($amount, "******-******-******-******-******-******", $expiry, $level, NULL, 86400, $app, $un);
|
||||
|
||||
$keys = NULL;
|
||||
for ($i = 0; $i < count($key); $i++) {
|
||||
$keys .= "" . $key[$i] . "\n";
|
||||
}
|
||||
$keys = preg_replace(
|
||||
|
||||
'~[\r\n]+~',
|
||||
|
||||
"\r\n",
|
||||
|
||||
trim($keys)
|
||||
);
|
||||
die($keys);
|
||||
}
|
||||
|
||||
switch (misc\etc\sanitize($data->product_id))
|
||||
{
|
||||
case $dayproduct:
|
||||
$day = $day + $amount;
|
||||
break;
|
||||
case $weekproduct:
|
||||
$week = $week + $amount;
|
||||
break;
|
||||
case $monthproduct:
|
||||
$month = $month + $amount;
|
||||
break;
|
||||
case $lifetimeproduct:
|
||||
$lifetime = $lifetime + $amount;
|
||||
break;
|
||||
default:
|
||||
die("You didn't set product id in app settings.");
|
||||
}
|
||||
|
||||
$balance = $day . '|' . $week . '|' . $month . '|' . $threemonth . '|' . $sixmonth . '|' . $lifetime . '|' . $year;
|
||||
// set balance
|
||||
misc\mysql\query("UPDATE `accounts` SET `balance` = ? WHERE `username` = ?", [$balance, $un]);
|
||||
die("Success: Reseller Balance Increased");
|
||||
}
|
||||
|
||||
if (isset($_SERVER["HTTP_X_SHOPPY_SIGNATURE"]))
|
||||
{
|
||||
$app = misc\etc\sanitize($_GET['app']);
|
||||
$query = misc\mysql\query("SELECT * FROM `apps` WHERE `secret` = ?", [$app]);
|
||||
|
||||
if ($query->num_rows < 1)
|
||||
{ // if no application was found with the supplied secret as the 'app' paramater
|
||||
die("Failure: application not found");
|
||||
}
|
||||
|
||||
$row = mysqli_fetch_array($query->result);
|
||||
$name = $row["name"];
|
||||
$secret = $row["shoppysecret"];
|
||||
$dayproduct = $row["shoppydayproduct"];
|
||||
$weekproduct = $row["shoppyweekproduct"];
|
||||
$monthproduct = $row["shoppymonthproduct"];
|
||||
$lifetimeproduct = $row["shoppylifetimeproduct"];
|
||||
|
||||
$payload = file_get_contents('php://input');
|
||||
$header_signature = misc\etc\sanitize($_SERVER["HTTP_X_SHOPPY_SIGNATURE"]);
|
||||
$signature = hash_hmac('sha512', $payload, $secret);
|
||||
if (!hash_equals($signature, $header_signature))
|
||||
{
|
||||
// if the shoppy webhook secret the request was sent from didn't match the one set in the database
|
||||
die("Failure: authentication with shoppy secret failed");
|
||||
}
|
||||
$json = json_decode($payload);
|
||||
$un = misc\etc\sanitize($json->data->order->custom_fields[0]->value);
|
||||
|
||||
$productid = misc\etc\sanitize($json->data->order->product_id);
|
||||
|
||||
$query = misc\mysql\query("SELECT `balance` FROM `accounts` WHERE `username` = ? AND `app` = ?", [$un, $name]);
|
||||
|
||||
if ($query->num_rows < 1)
|
||||
{
|
||||
// if reseller not found
|
||||
die("Failure: No account with the supplied username under this application found");
|
||||
}
|
||||
// getting the balance of each key length for the specified reseller account
|
||||
$row = mysqli_fetch_array($query->result);
|
||||
$balance = $row["balance"];
|
||||
$balance = explode("|", $balance);
|
||||
$day = $balance[0];
|
||||
$week = $balance[1];
|
||||
$month = $balance[2];
|
||||
$threemonth = $balance[3];
|
||||
$sixmonth = $balance[4];
|
||||
$lifetime = $balance[5];
|
||||
$year = $balance[6];
|
||||
|
||||
$amount = misc\etc\sanitize($json->data->order->quantity); // find quantity of keys purchased
|
||||
// then given the duration of keys they purchased, add to their balance
|
||||
|
||||
if(isset($_GET['expiry'])) {
|
||||
$expiry = misc\etc\sanitize($_GET['expiry']);
|
||||
$level = misc\etc\sanitize($_GET['level']);
|
||||
|
||||
$key = misc\license\createLicense($amount, "******-******-******-******-******-******", $expiry, $level, NULL, 86400, $app, $un);
|
||||
|
||||
$keys = NULL;
|
||||
for ($i = 0; $i < count($key); $i++) {
|
||||
$keys .= "" . $key[$i] . "\n";
|
||||
}
|
||||
$keys = preg_replace(
|
||||
|
||||
'~[\r\n]+~',
|
||||
|
||||
"\r\n",
|
||||
|
||||
trim($keys)
|
||||
);
|
||||
die($keys);
|
||||
}
|
||||
|
||||
switch ($productid)
|
||||
{
|
||||
case $dayproduct:
|
||||
$day = $day + $amount;
|
||||
break;
|
||||
case $weekproduct:
|
||||
$week = $week + $amount;
|
||||
break;
|
||||
case $monthproduct:
|
||||
$month = $month + $amount;
|
||||
break;
|
||||
case $lifetimeproduct:
|
||||
$lifetime = $lifetime + $amount;
|
||||
break;
|
||||
default:
|
||||
die("You didn't set product id in app settings.");
|
||||
}
|
||||
|
||||
$balance = $day . '|' . $week . '|' . $month . '|' . $threemonth . '|' . $sixmonth . '|' . $lifetime . '|' . $year;
|
||||
// set balance
|
||||
misc\mysql\query("UPDATE `accounts` SET `balance` = ? WHERE `username` = ?", [$balance, $un]);
|
||||
die("Success: Reseller Balance Increased");
|
||||
}
|
||||
|
||||
if (isset($_SERVER["HTTP_SIGNATURE"]))
|
||||
{
|
||||
$app = misc\etc\sanitize($_GET['app']);
|
||||
$query = misc\mysql\query("SELECT * FROM `apps` WHERE `secret` = ?", [$app]);
|
||||
|
||||
if ($query->num_rows < 1)
|
||||
{
|
||||
// if no application was found with the supplied secret as the 'app' paramater
|
||||
die("Failure: application not found");
|
||||
}
|
||||
|
||||
$row = mysqli_fetch_array($query->result);
|
||||
$name = $row["name"];
|
||||
$secret = $row["sellappsecret"];
|
||||
$dayproduct = $row["sellappdayproduct"];
|
||||
$weekproduct = $row["sellappweekproduct"];
|
||||
$monthproduct = $row["sellappmonthproduct"];
|
||||
$lifetimeproduct = $row["sellapplifetimeproduct"];
|
||||
|
||||
$payload = file_get_contents('php://input');
|
||||
|
||||
$header_signature = misc\etc\sanitize($_SERVER["HTTP_SIGNATURE"]);
|
||||
$signature = hash_hmac('sha256', $payload, $secret);
|
||||
if (!hash_equals($signature, $header_signature))
|
||||
{
|
||||
// if the SellApp webhook secret the request was sent from didn't match the one set in the database
|
||||
die("Failure: authentication with SellApp secret failed");
|
||||
}
|
||||
$json = json_decode($payload);
|
||||
$un = misc\etc\sanitize($json->additional_information[0]->value);
|
||||
|
||||
$product = misc\etc\sanitize($json->listing->slug);
|
||||
|
||||
$query = misc\mysql\query("SELECT `balance` FROM `accounts` WHERE `username` = ? AND `app` = ?", [$un, $name]);
|
||||
|
||||
if ($query->num_rows < 1)
|
||||
{
|
||||
// if reseller not found
|
||||
die("Failure: No account with the supplied username under this application found");
|
||||
}
|
||||
// getting the balance of each key length for the specified reseller account
|
||||
$row = mysqli_fetch_array($query->result);
|
||||
$balance = $row["balance"];
|
||||
$balance = explode("|", $balance);
|
||||
$day = $balance[0];
|
||||
$week = $balance[1];
|
||||
$month = $balance[2];
|
||||
$threemonth = $balance[3];
|
||||
$sixmonth = $balance[4];
|
||||
$lifetime = $balance[5];
|
||||
$year = $balance[6];
|
||||
|
||||
$amount = misc\etc\sanitize($json->quantity); // find quantity of keys purchased
|
||||
// then given the duration of keys they purchased, add to their balance
|
||||
|
||||
if(isset($_GET['expiry'])) {
|
||||
$expiry = misc\etc\sanitize($_GET['expiry']);
|
||||
$level = misc\etc\sanitize($_GET['level']);
|
||||
|
||||
$key = misc\license\createLicense($amount, "******-******-******-******-******-******", $expiry, $level, NULL, 86400, $app, $un);
|
||||
|
||||
$keys = NULL;
|
||||
for ($i = 0; $i < count($key); $i++) {
|
||||
$keys .= "" . $key[$i] . "\n";
|
||||
}
|
||||
$keys = preg_replace(
|
||||
|
||||
'~[\r\n]+~',
|
||||
|
||||
"\r\n",
|
||||
|
||||
trim($keys)
|
||||
);
|
||||
die($keys);
|
||||
}
|
||||
|
||||
switch(true) {
|
||||
case stristr($dayproduct, $product):
|
||||
$day = $day + $amount;
|
||||
break;
|
||||
case stristr($weekproduct, $product):
|
||||
$week = $week + $amount;
|
||||
break;
|
||||
case stristr($monthproduct, $product):
|
||||
$month = $month + $amount;
|
||||
break;
|
||||
case stristr($lifetimeproduct, $product):
|
||||
$lifetime = $lifetime + $amount;
|
||||
break;
|
||||
default:
|
||||
die("You didn't set product URL in app settings.");
|
||||
}
|
||||
|
||||
$balance = $day . '|' . $week . '|' . $month . '|' . $threemonth . '|' . $sixmonth . '|' . $lifetime . '|' . $year;
|
||||
// set balance
|
||||
misc\mysql\query("UPDATE `accounts` SET `balance` = ? WHERE `username` = ?", [$balance, $un]);
|
||||
die("Success: Reseller Balance Increased");
|
||||
}
|
||||
|
||||
?>
|
||||
1717
api/seller/index.php
Normal file
1717
api/seller/index.php
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user