pagr_drm
is a basic DRM module for Python programs that uses a single CD-key inspired system, connected to a PHP API with a MySQL Database.
Firstly, the pagr_drm
module is imported into the Python program. Most commonly, import lines will look like this:
from pagr_drm import pagr_drm
Ideally, the first function call in the program logic will be the following:
pagr_drm.Check(DRM_KEY)
Either place this before your main
function call, or the first statement inside your main
function. DRM_KEY should, of course, define the 64-bit key you want to use in your program:
DRM_KEY = "b96c5aace6c694daa2bb02601edf99b32148f3c4ec1bddecd3ab0e4eb9b979bc"
After the 64-bit key is added to the source program, upon initial key use, the key and unique hardware ID is POSTed to the PHP API, and checked with the database to ensure it exists in the "whitelist" database. If it doesn't, the user is immediately rejected, and a message is printed pinpointing that the key is invalid. If the key is valid, but no registrations are found, the hardware identifier is connected to the key, and added to the database. This counts as the first registration. A maximum of 3 (or user configurable) registrations can be created per key. This reduces piracy, and ensures that your binaries Python binaries aren't endlessly duplicated.
Example SQL database and table creation code goes as the following:
-- Create the DRM database
CREATE DATABASE IF NOT EXISTS pagr_drm;
USE pagr_drm;
-- Table to store DRM keys
CREATE TABLE drm_keys (
id INT AUTO_INCREMENT PRIMARY KEY,
drm_key VARCHAR(64) NOT NULL UNIQUE,
max_devices INT NOT NULL DEFAULT 1
);
-- Table to store device registrations
CREATE TABLE registrations (
id INT AUTO_INCREMENT PRIMARY KEY,
drm_key VARCHAR(64) NOT NULL,
hardware_id VARCHAR(64) NOT NULL,
registration_time DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (drm_key) REFERENCES drm_keys(drm_key)
);
-- Indexes for faster lookup
CREATE INDEX idx_drm_key ON registrations(drm_key);
CREATE INDEX idx_hardware_id ON registrations(hardware_id);
drm_keys
table is only used to store the DRM keys, and is the whitelist as mentioned above.
registrations
table is used to store the matching DRM key, hardware ID hash, and registration time. Registration time isn't really used to anything important, but just exists as a piece of metadata.
Incoming POST requests only process the DRM key and Hardware ID hash. A response is send back, which ranges from the following:
echo json_encode(["error" => "Invalid request"]);
echo json_encode(["error" => "Database connection failed"]);
echo json_encode(["error" => "Invalid DRM key"]);
echo json_encode(["message" => "Already registered", "status" => "approved"]);
echo json_encode(["error" => "Too many devices registered", "status" => "denied"]);
echo json_encode(["message" => "Registration complete", "status" => "approved"]);
echo json_encode(["error" => "Registration failed", "status" => "denied"]);