Initial Commit

This commit is contained in:
Netkas 2023-06-04 14:23:51 -04:00
parent 93a0b9be02
commit 6e599b2c0c
No known key found for this signature in database
GPG key ID: 5DAF58535614062B
99 changed files with 10836 additions and 4 deletions

View file

@ -0,0 +1,23 @@
create table anomaly_tracking
(
tracking_id varchar(36) default uuid() not null comment 'The UUID V4 Tracking ID for the anomaly'
primary key,
target_peer varchar(256) not null comment 'The target peer to which this anomaly is being tracked to',
event_type varchar(32) not null comment 'The event type that''s being tracked for the target peer',
usage_data mediumblob null comment 'The usage data of the event from the past 48 hours',
last_updated bigint default unix_timestamp() not null comment 'The Unix Timestamp for when this record was last updated',
created_timestamp bigint default unix_timestamp() not null comment 'The Unix Timestamp for when this record was first created',
constraint anomaly_tracking_event_type_target_peer_uindex
unique (event_type, target_peer),
constraint anomaly_tracking_target_peer_uindex
unique (target_peer),
constraint anomaly_tracking_tracking_id_uindex
unique (tracking_id),
constraint anomaly_tracking_peers_federated_address_fk
foreign key (target_peer) references peers (federated_address)
)
comment 'This table is used for tracking anomalies for events';
create index anomaly_tracking_event_type_index
on anomaly_tracking (event_type);

29
database/associations.sql Normal file
View file

@ -0,0 +1,29 @@
create table associations
(
child_peer varchar(256) not null comment 'The child peer',
parent_peer varchar(256) not null comment 'The parent peer',
type varchar(32) not null comment 'The association type between the parent peer to the child peer',
client_uuid varchar(36) not null comment 'The client UUID that made the association between the two peers',
timestamp bigint default unix_timestamp() not null comment 'The Unix Timestamp for when this assoication was made',
constraint associations_child_peer_parent_peer_uindex
unique (child_peer, parent_peer),
constraint associations_child_peer_type_parent_peer_uindex
unique (child_peer, type, parent_peer),
constraint associations_clients_uuid_fk
foreign key (client_uuid) references clients (uuid),
constraint associations_discovered_peers_federated_address_fk
foreign key (child_peer) references peers (federated_address),
constraint associations_discovered_peers_federated_address_fk2
foreign key (parent_peer) references peers (federated_address)
)
comment 'A table used for housing associations detected between peers';
create index associations_child_peer_index
on associations (child_peer);
create index associations_client_uuid_index
on associations (client_uuid);
create index associations_parent_peer_index
on associations (parent_peer);

34
database/clients.sql Normal file
View file

@ -0,0 +1,34 @@
create table clients
(
uuid varchar(36) default uuid() not null comment 'The UUID v4 ID for the client, null for anonymous users.',
enabled tinyint(1) default 1 not null comment 'Indicates if this client is enabled or not',
name text collate utf8mb4_unicode_ci not null comment 'Optional. Name of the client',
description text collate utf8mb4_unicode_ci null comment 'The optional description of the client',
secret_totp varchar(32) null comment 'The secret TOTP key used to generated authorization tokens for each request, if null then the client is not required to authenticate via providing generated authorization tokens',
query_permission tinyint(1) default 1 null comment 'The permission level set for the query permission
0 = Cannot query the database for content analysis
1 = Can query the database for content analysis
2 = Can query for additional sensitive information
3 = Can query and upate metadata',
update_permission tinyint(1) default 0 null comment 'The permission level set for the update permission
0 = Cannot update the database in anyway whatsoever
1 = Can update entity metadata
2 = Can submit evidence
3 = Can change entity flags & change entity association id',
flags varchar(255) null comment 'Comma separated flags associated with the client',
created_timestamp bigint default unix_timestamp() not null comment 'The Unix Timestamp for when this client was first registered into the database',
updated_timestamp bigint default unix_timestamp() not null comment 'The Unix Timestamp for when this client record was last updated in the database',
seen_timestamp bigint default unix_timestamp() not null comment 'The Unix Timestamp for when this client was last seen by the database',
constraint clients_uuid_uindex
unique (uuid)
)
comment 'A table for housing registered users/clients that can access the database';
create index clients_created_timestamp_seen_timestamp_updated_timestamp_index
on clients (created_timestamp, seen_timestamp, updated_timestamp)
comment 'Index for the client''s timestamps indicators';
create index clients_enabled_index
on clients (enabled)
comment 'Index for the client''s enabled state';

35
database/events.sql Normal file
View file

@ -0,0 +1,35 @@
create table events
(
uuid varchar(36) default uuid() not null comment 'The unique universal identifier for the event'
primary key,
code varchar(36) default 'GENERIC' not null comment 'A short-code event name that represents the event that has occured, the message field will contain more details in regards to the event code used.',
type varchar(36) default 'INFO' not null comment 'The event type, can be INFO, WARN, or ERR',
client_uuid varchar(36) null comment 'The client that created/caused the event',
peer varchar(256) null comment 'Optional. The peer that is associated with this event',
message text null comment 'The event details',
exception blob null comment 'The optional exeception details in a serialized format (MSGPACK)',
timestamp bigint default unix_timestamp() not null comment 'The Unix Timestamp for the record',
constraint events_uuid_uindex
unique (uuid),
constraint events_clients_uuid_fk
foreign key (client_uuid) references clients (uuid),
constraint events_peers_federated_address_fk
foreign key (peer) references peers (federated_address)
)
comment 'A table for housing event logs created by FederationLib in regards to Database changes.';
create index events_client_uuid_index
on events (client_uuid);
create index events_code_index
on events (code);
create index events_peer_index
on events (peer);
create index events_timestamp_index
on events (timestamp);
create index events_type_index
on events (type);

29
database/peers.sql Normal file
View file

@ -0,0 +1,29 @@
create table peers
(
federated_address varchar(256) not null comment 'The standard federated address of the peer'
primary key,
client_first_seen varchar(36) not null comment 'The UUID of the client that first discovered the peer',
client_last_seen varchar(36) not null comment 'The UUID of the client that last saw this peer',
active_restriction varchar(36) null comment 'Optional. The UUID of the restriction that is currently active on the peer',
discovered_timestamp bigint default unix_timestamp() not null comment 'The Unix Timestamp for when this peer was first discovered',
seen_timestamp bigint default unix_timestamp() not null comment 'The Unix Timestamp for when this peer was last seen',
constraint discovered_peers_federated_address_uindex
unique (federated_address),
constraint discovered_peers_clients_uuid_fk
foreign key (client_first_seen) references clients (uuid),
constraint discovered_peers_clients_uuid_fk2
foreign key (client_last_seen) references clients (uuid),
constraint peers_restrictions_uuid_fk
foreign key (active_restriction) references restrictions (uuid)
)
comment 'The table for housing all the discovered peers';
create index discovered_peers_client_first_seen_index
on peers (client_first_seen);
create index discovered_peers_client_last_seen_index
on peers (client_last_seen);
create index peers_active_restriction_index
on peers (active_restriction);

View file

@ -0,0 +1,23 @@
create table peers_telegram_chat
(
federated_address varchar(255) not null comment 'A federated internet standard ID for this Telegram chat'
primary key,
id bigint not null comment 'Unique identifier for this chat. This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this identifier.',
type varchar(32) not null comment 'The type of chat, Type of chat, can be either “group”, “supergroup” or "channel". "private" is not accepted',
title varchar(255) collate utf8mb4_unicode_ci null comment 'Optional. Title, for supergroups, channels and group chats',
username varchar(255) null comment 'Optional. Username, for private chats, supergroups and channels if available',
is_forum tinyint(1) default 0 not null comment 'Optional. True, if the supergroup chat is a forum (has topics enabled)',
constraint telegram_chat_federated_address_uindex
unique (federated_address),
constraint telegram_chat_id_uindex
unique (id),
constraint telegram_chat_pk2
unique (id),
constraint telegram_chat_discovered_peers_federated_address_fk
foreign key (federated_address) references peers (federated_address)
)
comment 'A table for housing telegram chats for channel references';
create index telegram_chat_username_index
on peers_telegram_chat (username);

View file

@ -0,0 +1,23 @@
create table peers_telegram_user
(
federated_address varchar(255) default concat(`id`, 'u@telegram.org') not null comment 'A federated Internet Standard ID for this entity'
primary key,
id bigint not null comment 'Unique identifier for this user or bot. This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a 64-bit integer or double-precision float type are safe for storing this identifier.',
is_bot tinyint(1) default 0 not null comment 'True, if this user is a bot',
first_name varchar(255) collate utf8mb4_unicode_ci null comment 'Optional. User''s or bot''s last name',
last_name varchar(255) collate utf8mb4_unicode_ci null comment 'Optional. User''s or bot''s last name',
username varchar(255) collate utf8mb4_unicode_ci null comment 'Optional. User''s or bot''s username',
language_code tinyint(2) null comment 'Optional. IETF language tag of the user''s language',
is_premium tinyint(1) default 0 not null comment 'Optional. True, if this user is a Telegram Premium user',
constraint telegram_user_federated_id_uindex
unique (federated_address),
constraint telegram_user_pk2
unique (id),
constraint telegram_user_discovered_peers_federated_address_fk
foreign key (federated_address) references peers (federated_address)
)
comment 'The table for housing Telegram user entity references';
create index telegram_user_username_index
on peers_telegram_user (username);

View file

@ -0,0 +1,47 @@
create table query_documents
(
document_id varchar(26) not null comment 'The unique reference ID of the document (UUID v4)'
primary key,
subject_type varchar(32) default 'RECON' not null comment 'The subject type of the query document',
client_id varchar(36) not null comment 'The ID of the client that submitted the document',
client_signature varchar(36) null comment 'The authorization token signed with the document by the client',
channel_peer varchar(256) null comment 'Optional. The channel that the content was sent on',
from_peer varchar(256) null comment 'Optional. The peer that sent the content',
to_peer varchar(256) null comment 'Optional. The peer that is the intended reciever of the content',
proxy_peer varchar(256) null comment 'Optional. The proxy peer used to send the content, may indicates "from_peer" is the original sender.',
retain tinyint default 0 not null comment 'Indicates if this record should be retained or not',
timestamp bigint default unix_timestamp() not null comment 'The Unix Timestamp of the document''s submission (based off the authorization token)',
constraint query_documents_document_id_uindex
unique (document_id),
constraint query_documents_discovered_peers_federated_address_fk
foreign key (channel_peer) references peers (federated_address),
constraint query_documents_discovered_peers_federated_address_fk2
foreign key (from_peer) references peers (federated_address),
constraint query_documents_discovered_peers_federated_address_fk3
foreign key (to_peer) references peers (federated_address),
constraint query_documents_peers_federated_address_fk
foreign key (proxy_peer) references peers (federated_address)
)
comment 'An archive of all the submitted query documents the database received';
create index query_documents_channel_peer_index
on query_documents (channel_peer);
create index query_documents_client_id_index
on query_documents (client_id);
create index query_documents_from_peer_index
on query_documents (from_peer);
create index query_documents_proxy_peer_index
on query_documents (proxy_peer);
create index query_documents_retain_index
on query_documents (retain);
create index query_documents_subject_type_index
on query_documents (subject_type);
create index query_documents_to_peer_index
on query_documents (to_peer);

45
database/reports.sql Normal file
View file

@ -0,0 +1,45 @@
create table reports
(
report_id varchar(36) default uuid() not null comment 'The UUID V4 for the report''s ID'
primary key,
type varchar(32) default 'OTHER' not null comment 'The standard report type',
client_uuid varchar(36) not null comment 'The Client UUID responsible for submitting the report to the database',
reporting_peer varchar(256) null comment 'The peer that submitted the report, if empty will assume the client is the reporter.',
target_peer varchar(36) not null comment 'The target peer that the report is against at',
automated tinyint default 0 not null comment 'Indicates if the report was automated or not',
confidence_score float null comment 'The confidence score of the scanner if the report was automated',
reference_document varchar(36) not null comment 'The reference document to which this report came from',
scan_mode varchar(32) null comment 'The scan mode that was used to conduct the automated report',
reason text null comment 'The reason for the report',
submission_timestamp bigint default unix_timestamp() null comment 'The Unix Timestamp for when this report was submitted to the database',
constraint reports_report_id_uindex
unique (report_id),
constraint reports_clients_uuid_fk
foreign key (client_uuid) references clients (uuid),
constraint reports_discovered_peers_federated_address_fk
foreign key (reporting_peer) references peers (federated_address),
constraint reports_discovered_peers_federated_address_fk2
foreign key (target_peer) references peers (federated_address),
constraint reports_query_documents_document_id_fk
foreign key (reference_document) references query_documents (document_id)
)
comment 'The table for storing reports made against peers';
create index reports_client_uuid_index
on reports (client_uuid);
create index reports_reference_document_index
on reports (reference_document);
create index reports_reporting_peer_index
on reports (reporting_peer);
create index reports_submission_timestamp_index
on reports (submission_timestamp);
create index reports_target_peer_index
on reports (target_peer);
create index reports_type_index
on reports (type);

28
database/restrictions.sql Normal file
View file

@ -0,0 +1,28 @@
create table restrictions
(
uuid varchar(36) default uuid() not null comment 'The Unique UUID V4 for the restriction record'
primary key,
peer varchar(256) not null comment 'The standard federated address of the peer',
client_uuid varchar(36) null comment 'Optional. The Client UUID that placed the restriction on the peer, if empty then it was an automated restriction placed by the system.',
reason varchar(64) not null comment 'The reason for the restriction that was applied to the peer',
automated tinyint default 0 not null comment 'Indicates if this restriction was automated',
type varchar(32) null comment 'The restriction type that was applied to the peer',
created bigint default unix_timestamp() not null comment 'The Unix Timestamp for when the restriction was created',
expires bigint not null comment 'The Unix Timestamp for when the restriction expires',
constraint restrictions_peer_uindex
unique (peer) comment 'The main unique index for the primary key "peer"',
constraint restrictions_uuid_uindex
unique (uuid),
constraint restrictions_clients_uuid_fk
foreign key (client_uuid) references clients (uuid),
constraint restrictions_peers_federated_address_fk
foreign key (peer) references peers (federated_address)
)
comment 'Archive of past restrictions placed on peers';
create index restrictions_automated_index
on restrictions (automated);
create index restrictions_client_uuid_index
on restrictions (client_uuid);