Setup
See first: Overview
Nodes will need a website on their own domain, and a database.
Below is an outline of what files and database tables you will need to set up.
Files will need to be uploaded to a https web server in the folder
Nodes will need a website on their own domain, and a database.
Below is an outline of what files and database tables you will need to set up.
Files will need to be uploaded to a https web server in the folder
/openmsg/
.
Settings
The settings file should be stored in
/openmsg/
(For example '/openmsg/openmsg_settings.php'
)
PHP
openmsg_settings.php
<?php
// ##### See: openmsg.io/docs/v1
// Connect to your database
/*
$DBhost = "localhost";
$DBuser = "username";
$DBpass = "password";
$DBName = "myDB";
$db = new mysqli($DBhost,$DBuser,$DBpass,$DBName);
if ($db -> connect_errno) {
//echo "Failed to connect to MySQL: " . $db -> connect_error;
echo "Failed to connect to database ";
exit();
}
//or
include "database_connection.php";
*/
// enter your domain here. This needs to be the domain used in your account addresses and where the /openmsg/ protocol folder is hosted
$my_openmsg_domain = "openmsg.io";
$sandbox = TRUE;
if($sandbox == TRUE) $sandbox_dir = "/sandbox"; // openmsg can be hosted at "/openmsg/sandbox/ for initial testing or testing new versions before going live
?>
Sending Component
Database Tables
The Sending Component will need the following tables:
openmsg_handshakes
openmsg_user_connections
openmsg_messages_outbox
openmsg_messages_sent
PHP
Create Tables
<?php
// ##### See: openmsg.io/docs/v1
// Always check any code before running on your server
// Connect to your database
require ($_SERVER["DOCUMENT_ROOT"]."/openmsg/openmsg_settings.php");
// Table to save User account data. You will need to add to this table
$query = "CREATE TABLE IF NOT EXISTS openmsg_users (
id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
self_openmsg_address VARCHAR(255) NOT NULL,
self_openmsg_name VARCHAR(40) NOT NULL,
password CHAR(255) NOT NULL,
password_salt CHAR(30) NOT NULL,
timestamp_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)";
$stmt = $db->prepare($query);
//$stmt->execute(); // To Do: Un-comment
$stmt->close();
// Create two test accounts... delete rows from table after testing.
$query = "INSERT INTO openmsg_users (
self_openmsg_address,
self_openmsg_address_name,
password,
password_salt) VALUES (?, ?, ?, ?)";
$stmt = $db->prepare($query);
for($i = 0; $i < 2; $i++){
$testAcc_address = "100000".$i."*".$my_openmsg_domain;
$testAcc_address_name = "Test Openmsg Account";
$testAcc_pw = rand(99999,9999999); // Note this is for the test account only. Not secure.
$testAcc_salt = rand(99999,9999999); // Note this is for the test account only. Not secure.
$testAcc_pw_hash = hash("sha256", $testAcc_pw.$testAcc_1_salt); // Note this is for the test account only. Not secure.
$stmt -> bind_param("ssss", $testAcc_address, $testAcc_address_name, $testAcc_pw_hash, $testAcc_salt);
//$stmt->execute(); // To Do: Un-comment
}
$stmt->close();
// Table to track handshakes that are in progress
$query = "CREATE TABLE openmsg_handshakes (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
other_openmsg_address VARCHAR(255) NOT NULL,
pass_code VARCHAR(6) NOT NULL,
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)";
$stmt = $db->prepare($query);
//$stmt->execute(); // To Do: Un-comment
$stmt->close();
// Table to save User data after a sucessful handshake
$query = "CREATE TABLE IF NOT EXISTS openmsg_user_connections (
id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
self_openmsg_address VARCHAR(255) NOT NULL,
other_openmsg_address VARCHAR(255) NOT NULL,
other_openmsg_address_name VARCHAR(40) NOT NULL,
other_acceptsMessages INT(1) NOT NULL,
auth_code VARCHAR(64) NOT NULL,
ident_code VARCHAR(64) NOT NULL,
message_crypt_key VARCHAR(64) NOT NULL,
timestamp_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)";
$stmt = $db->prepare($query);
//$stmt->execute(); // To Do: Un-comment
$stmt->close();
// Table to temporarily store an outbound message.
// The Receiving Node will make a curl request to verify the message came from the correct domain
$query = "CREATE TABLE IF NOT EXISTS openmsg_messages_outbox (
id INT(20) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
self_openmsg_address VARCHAR(255) NOT NULL,
ident_code VARCHAR(64) NOT NULL,
message_hash VARCHAR(64) NOT NULL,
message_nonce VARCHAR(32) NOT NULL,
message_text VARCHAR(2000) NOT NULL,
timestamp_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)";
$stmt = $db->prepare($query);
//$stmt->execute(); // To Do: Un-comment
$stmt->close();
// Table to save the sent message after the message has been accepted by the Receiving Node
$query = "CREATE TABLE IF NOT EXISTS openmsg_messages_sent (
id INT(20) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
self_openmsg_address VARCHAR(255) NOT NULL,
ident_code VARCHAR(64) NOT NULL,
message_hash VARCHAR(64) NOT NULL,
message_text VARCHAR(2000) NOT NULL,
timestamp_read INT (12),
timestamp_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)";
$stmt = $db->prepare($query);
//$stmt->execute(); // To Do: Un-comment
$stmt->close();
?>
Files
The Sending Component requires the following files:
Handshake:
See: Initial Handshake: Guide
Send Message:
See: Send Message: Guide
Handshake:
initiate-handshake.php
/openmsg/auth-confirm/index.php
See: Initial Handshake: Guide
Send Message:
send-message.php
/openmsg/message-confirm/index.php
See: Send Message: Guide
Receiving Component
Database Tables
The Receiving Component requires the following tables:
openmsg_passCodes
openmsg_user_connections
openmsg_messages_inbox
PHP
Create Tables
<?php
// ##### See: openmsg.io/docs/v1
// Always check any code before running on your server
// Connect to your database
require ($_SERVER["DOCUMENT_ROOT"]."/openmsg/openmsg_settings.php");
// Table to save pass_code that a User created // pass codes expire after 1 hour. Pass codes should be deleted after 1 hour or after use.
$query = "CREATE TABLE IF NOT EXISTS openmsg_passCodes (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
self_openmsg_address VARCHAR(255) NOT NULL,
pass_code VARCHAR(6) NOT NULL,
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)";
$stmt = $db->prepare($query);
//$stmt->execute(); // To Do: Un-comment
$stmt->close();
// Table to save the received message
$query = "CREATE TABLE IF NOT EXISTS openmsg_messages_inbox (
id INT(20) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
self_openmsg_address VARCHAR(255) NOT NULL,
ident_code VARCHAR(64) NOT NULL,
message_hash VARCHAR(64) NOT NULL,
message_text VARCHAR(2000) NOT NULL,
timestamp_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)";
$stmt = $db->prepare($query);
//$stmt->execute(); // To Do: Un-comment
$stmt->close();
?>
Files
The Receiving Component requires the following files:
Handshake:
See: Initial Handshake: Guide
Send Message:
See: Send Message: Guide
Handshake:
initiate-handshake.php
/openmsg/auth-confirm/index.php
See: Initial Handshake: Guide
Send Message:
send-message.php
/openmsg/message-confirm/index.php
See: Send Message: Guide
To Finish
Download
Download all the database setup files, and the protocol files. These are written in PHP / MySQL
Get from GitHub
Get from GitHub
Next