diff --git a/html/inc/account_ownership.inc b/html/inc/account_ownership.inc
new file mode 100644
index 0000000000..cba6c8fe14
--- /dev/null
+++ b/html/inc/account_ownership.inc
@@ -0,0 +1,35 @@
+.
+
+require_once("../inc/boinc_db.inc");
+require_once("../inc/user.inc");
+require_once("../inc/util.inc");
+
+$temp_config = get_config();
+$temp_keydir = parse_config($temp_config, ""); // key directory can be customized
+
+$account_ownership_private_key_file_name = "account_ownership_private.pem"; // private key file name
+$account_ownership_private_key = "$temp_keydir/$account_ownership_private_key_file_name"; // for overwriting key
+$account_ownership_private_key_file_path = "file://$account_ownership_private_key"; // for checking file existence
+
+$account_ownership_public_key_file_name = "account_ownership_public.pem"; // public key file name
+$account_ownership_public_key = "$temp_keydir/$account_ownership_public_key_file_name"; // for overwriting key
+$account_ownership_public_key_file_path = "file://$account_ownership_public_key"; // for checking file existence
+
+?>
diff --git a/html/inc/user.inc b/html/inc/user.inc
index 668484e6f9..da5c5af40e 100644
--- a/html/inc/user.inc
+++ b/html/inc/user.inc
@@ -283,10 +283,16 @@ function show_user_info_private($user) {
tra("Account keys"),
"".tra("View").""
);
- row2(
- tra("Account Ownership"),
- "Generate ownership proof"
- );
+
+ require_once("../inc/account_ownership.inc");
+ if (file_exists($account_ownership_private_key_file_path)) {
+ // If the server has keys configured show the account ownership form
+ row2(
+ tra("Account Ownership"),
+ "Generate ownership proof"
+ );
+ }
+
}
}
diff --git a/html/ops/check_account_ownership_keys.php b/html/ops/check_account_ownership_keys.php
new file mode 100644
index 0000000000..4c02e93e21
--- /dev/null
+++ b/html/ops/check_account_ownership_keys.php
@@ -0,0 +1,39 @@
+.
+
+require_once("../inc/boinc_db.inc");
+require_once("../inc/user.inc");
+require_once("../inc/util.inc");
+require_once("../inc/account_ownership.inc");
+
+if (!file_exists($account_ownership_private_key_file_path)) {
+ echo "
The '$account_ownership_private_key_file_name' key doesn't exist. Please run the 'generate_account_ownership_keys.php' script from the BOINC web server command line.";
+} else {
+ echo "
The '$account_ownership_public_key_file_name' key doesn't exist. Please run the 'generate_account_ownership_keys.php' script from the BOINC web server command line.";
+} else {
+ echo "
The '$account_ownership_public_key_file_name' key exists.";
+}
+
+echo "
"));
+ }
+}
+
+function account_ownership_form($user) {
+ // GET request - the user has navigated to the page.
+ page_head(tra("Generate proof of account ownership"), null, null, null, boinc_recaptcha_get_head_extra());
+
+ if ($user) { // Verify the user is logged in
+ require_once("../inc/account_ownership.inc");
+
+ if (!file_exists($account_ownership_private_key_file_path)) {
+ // Check that the private key file exists where specified. If not, redirect to error page.
+ error_page(tra("The proof of account ownership feature is not set up properly. Contact the project administrator to resolve the issue."));
+ }
+
+ if (!file_exists($account_ownership_public_key_file_path)) {
+ // Check that the public key file exists where specified. If not, redirect to error page.
+ error_page(tra("The proof of account ownership feature is not set up properly. Contact the project administrator to resolve the issue."));
+ }
+
+ echo "
This tool is designed to create a proof of account ownership for external systems.
";
+
+ global $recaptcha_public_key;
+ if ($recaptcha_public_key) {
+ // Recaptcha configured
+ echo "
Enter a message with length less than 4096 characters into the input textbox below, solve the captcha then click the 'Generate' button.
Enter a message with length less than 4096 characters into the input textbox below then click the 'Generate' button.
";
+ }
+ echo "
A textbox will then appear which contains your proof of account ownership.";
+ echo "
";
+ } else {
+ // The user is not logged in!
+ echo "
You need to be logged in to use this functionality.
";
+ }
+
+ page_tail();
+}
+
+if ($_SERVER['REQUEST_METHOD'] === 'POST') {
+ account_ownership_action($user);
+} else {
+ account_ownership_form($user);
+}
+
+?>
diff --git a/html/user/account_ownership_action.php b/html/user/account_ownership_action.php
deleted file mode 100644
index 92850bad93..0000000000
--- a/html/user/account_ownership_action.php
+++ /dev/null
@@ -1,130 +0,0 @@
-.
-
-require_once("../inc/boinc_db.inc");
-require_once("../inc/user.inc");
-require_once("../inc/util.inc");
-require_once('../inc/recaptchalib.php');
-
-check_get_args(array("tnow", "ttok"));
-
-// Check the user is online
-$user = get_logged_in_user();
-check_tokens($user->authenticator);
-
-page_head(tra("Proof of account ownership results"), null, null, null, boinc_recaptcha_get_head_extra());
-
-global $recaptcha_private_key;
-if ($recaptcha_private_key) {
- // Recaptcha is enabled on the BOINC server
- if (!boinc_recaptcha_isValidated($recaptcha_private_key)) {
- // The user failed to solve the recaptcha prompt - redirect them to an error message!
- error_page(
- tra("Your reCAPTCHA response was not correct. Please try again.")
- );
- }
-}
-
-// Input is passed in from the openssl_sign_form
-$user_data = htmlentities(post_str("user_data", true), ENT_QUOTES, "UTF-8"); // Convert special characters to html equivelant
-
-if ((strlen($user_data) > 0) && (strlen($user_data) <= 4096)) {
- // The user data input is valid
- $config = get_config();
- $keydir = parse_config($config, "");
-
- /*
- How to generate required keys in /project/keys/ folder:
- openssl genpkey -algorithm RSA -out ownership_sign_private.pem -pkeyopt rsa_keygen_bits:2048
- openssl rsa -pubout -in ownership_sign_private.pem -out ownership_sign_public.pem
- chown -R boincadm:boincadm ext*
- chmod --reference upload_private ownership_sign_public.pem
- chmod --reference upload_private ownership_sign_private.pem
- */
-
- // If the following keys do not exist, then the users will be shown an error message.
- $private_key_path = "file://$keydir/ownership_sign_private.pem";
- $public_key_path = "file://$keydir/ownership_sign_public.pem";
-
- // Check that the private key file exists where specified. If not, redirect to error page.
- if (!file_exists($private_key_path)) {
- error_page(tra("The required private key doesn't exist. Contact the project administrator to resolve this issue."));
- }
-
- // Check that the public key file exists where specified. If not, redirect to error page.
- if (!file_exists($public_key_path)) {
- error_page(tra("The required public key doesn't exist. Contact the project administrator to resolve this issue."));
- }
-
- $privkey = fopen($private_key_path, "r"); // Opening private key file
- if (!isset($privkey) || empty($privkey)) {
- error_page(tra("Unable to access the required private key. Contact the project administrator to resolve this issue."));
- }
- $privkey_contents = fread($privkey, 8192); // Reading contents of private key into var
- fclose($privkey); // Closing private key file
-
- $userid = $user->id; // Retrieving the user's UserId
- $message_data = "$userid $user_data"; // Create the message which will be signed.
-
- $private_key_pem = openssl_pkey_get_private($privkey_contents); // Loading the private key into memory
- openssl_sign($message_data, $signature, $private_key_pem, OPENSSL_ALGO_SHA512); // Compute signature using SHA512
- openssl_free_key($private_key_pem); // Free the private key from memory for additional security
-
- $pubkey = fopen($public_key_path, "r"); // Open public key file
- if ((!isset($pubkey)) || empty($pubkey)) {
- error_page(tra("Unable to access the required public key. Contact the project administrator to resolve this issue."));
- }
- $pubkey_contents = fread($pubkey, 8192); // Read contents to var
- fclose($pubkey); // Close pub key file
-
- $base64_sig = base64_encode($signature); // Base64 encode the generated signature to enable safe output to text file.
- $decoded_sig = base64_decode($base64_sig); // Decode base64 sig for use in sig_verification
- $pubkeyid = openssl_pkey_get_public($pubkey_contents); // fetch public key into memory
- $sig_verification = openssl_verify($message_data, $decoded_sig, $pubkeyid, OPENSSL_ALGO_SHA512); // Verify that the generated signature against the original data, using the public key.
- openssl_free_key($pubkeyid); // Free the public key from memory
-
- // Check if signature was successfully validated
- if ($sig_verification == 1) {
- // The generated signature has been successfully verified using the public key.
- global $master_url; // Define global master_url variable for use in output
- echo "
Do not share this information with anyone other than the external system which has requested this proof of account ownership.
";
- echo "";
- echo " ";
- echo '';
- page_tail();
-
- } elseif ($sig_verification == 0) {
- // The generated signature has not been verified. The private/public keys do not match.
- error_page(tra("Signature verification failed. Try again at a later time."));
- } else {
- // Something has gone wrong & an error has occurred.
- error_page(tra("An error occured during the signature verification. Try again at a later time."));
- }
-} else {
- // User data input invalid
- error_page(tra("Invalid input. User input must have a length > 0 and < 4096. "));
-}
-
-?>
diff --git a/html/user/account_ownership_form.php b/html/user/account_ownership_form.php
deleted file mode 100644
index ff63acadf4..0000000000
--- a/html/user/account_ownership_form.php
+++ /dev/null
@@ -1,73 +0,0 @@
-.
-
-require_once("../inc/boinc_db.inc");
-require_once("../inc/user.inc");
-require_once("../inc/util.inc");
-require_once("../inc/countries.inc");
-require_once('../inc/recaptchalib.php');
-
-check_get_args(array("tnow", "ttok"));
-
-$user = get_logged_in_user();
-check_tokens($user->authenticator);
-
-page_head(tra("Generate proof of account ownership"), null, null, null, boinc_recaptcha_get_head_extra());
-
-// Verify the user is logged in
-if ($user) {
- // If the following keys do not exist, then the users will be shown an error message.
- $config = get_config();
- $keydir = parse_config($config, "");
- $private_key_path = "file://$keydir/ownership_sign_private.pem";
- $public_key_path = "file://$keydir/ownership_sign_public.pem";
-
- // Check that the private key file exists where specified. If not, redirect to error page.
- if (!file_exists($private_key_path)) {
- error_page(tra("The private key doesn't exist. Contact the project administrator to resolve this issue."));
- }
-
- // Check that the public key file exists where specified. If not, redirect to error page.
- if (!file_exists($public_key_path)) {
- error_page(tra("The public key doesn't exist. Contact the project administrator to resolve this issue."));
- }
-
- echo "
This tool is designed to create a proof of account ownership for external systems.
";
- echo "
Enter a message with length less than 4096 characters into the input textbox below, solve the captcha then click the 'Generate' button.
";
- echo "
A textbox will then appear which contains your proof of account ownership.";
- echo "
";
-} else {
- // The user is not logged in!
- echo "
You need to be logged in to use this functionality.