Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,4 +1,81 @@
# Google C/C++ Code Style settings
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
# Author: Kehan Xue, kehan.xue (at) gmail.com

Language: Cpp
BasedOnStyle: Google
AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: None
AlignOperands: Align
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortIfStatementsOnASingleLine: true
AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterReturnType: None
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterStruct: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
ColumnLimit: 80
CompactNamespaces: false
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false # Make sure the * or & align on the left
EmptyLineBeforeAccessModifier: LogicalBlock
FixNamespaceComments: true
IncludeBlocks: Preserve
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 2
KeepEmptyLinesAtTheStartOfBlocks: true
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PointerAlignment: Left
ReflowComments: false
SeparateDefinitionBlocks: Always # Only support since clang-format 14
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: c++11
TabWidth: 4
UseTab: Never
26 changes: 26 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: CI

on: push

jobs:
lint:
name: 'Lint'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install clang-format
run: sudo apt-get update && sudo apt-get install -y clang-format
- name: Lint check
run: make lintcheck

build:
name: 'Build'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install build deps
run: sudo apt-get update && sudo apt-get install -y make gcc
- name: Check build
run: |
make all
make check
14 changes: 9 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ $(BUILD_DIR)/%.o: $(SRC_DIR)/%.c | $(BUILD_DIR)
$(BUILD_DIR):
@mkdir -p $(BUILD_DIR)

# === Run the built program ===
run: $(OUTPUT)
@echo "Running $(OUTPUT)..."
@./$(BUILD_DIR)/$(OUTPUT)
# === Check the built program ===
check: $(OUTPUT)
@echo "Checking $(OUTPUT)..."
@./$(BUILD_DIR)/$(OUTPUT) --help

# === Clean all build artifacts ===
clean:
Expand All @@ -45,4 +45,8 @@ clean:

# === Formats all files in include dir and src dir ===
format:
@clang-format -i $(SRC_DIR)/**/*.c -i $(INC_DIR)/**/*.h
@clang-format -i $(SRC_DIR)/**/*.c -i $(INC_DIR)/**/*.h

# === (CI) If linting fails, command fails ===
lintcheck:
@clang-format $(SRC_DIR)/**/*.c $(INC_DIR)/**/*.h --dry-run -Werror
16 changes: 4 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ new agent. This will setup the configuration directory (default is
`~/.transcodine` but can be changed via the `TRANSCODINE_CONFIG_PATH`
environment variable) which will store all the files tracked by the program. The
setup will require you enter a new password and remember it, otherwise the data
in the agent is unrecoverable! You can reset the password using
in the agent will become unrecoverable! You can reset the password using
`transcodine agent reset`, but only if you still remember your old password.

### Bin
Expand All @@ -99,11 +99,11 @@ individual state. Note that you should not directly tamper with the bins, as
even things like their names and locations are sensitive to changes, and leave
the bin in an unrecoverable state.

FOr example, the `transcodine bin create` command will add an entry in an
For example, the `transcodine bin create` command will add an entry in an
encrypted database pointing to the file name. These names are used to show
tracked bins in `transcodine bin ls`. Due to this reason, if you manually add a
bin to the configuration directory, it will be ignored. That doesn't mean you
can do tha, though. It is not recommended to manually interact with the
can do that, though. It is not recommended to manually interact with the
configuration directory. If you accidentally rename a bin, then the program will
exhibit undefined behaviour, and tampering with the encrypted contents will make
the file and all their contents unrecoverable!
Expand All @@ -116,7 +116,7 @@ encrypt the bins) produces high-entropy result, meaning each bit is equally
likely to be present. This reduces the efficacy of Huffman compression.

To unlock the bins, you also need a secret key per bin. This is usually stored
in your internal database, so nobody can view the data in the archive -- not
in your internal database, so nobody can view the data in the archive —— not
even you! To work around this, an encrypted database containing the relevant
keys is stitched with the archive, and a secret key is created at the time of
archive creation. This secret key will unlock the database and allow anyone to
Expand Down Expand Up @@ -259,11 +259,3 @@ entire contents of a compressed archive to a malicious actor.
memory impact, however that makes it weaker to GPU cracking. Thus, for hashes
which can be easily accessed by bad actors, using stronger hashing algorithms
like argon2 is recommended for production environments.

## Credits

This project can be found on
[GitHub](https://github.com/aryanjassal/transcodine).

Refer to [Polykey](https://github.com/MatrixAI/Polykey) for a complete and
production-ready implementation of this concept.
8 changes: 4 additions & 4 deletions include/auth/check.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @returns True if the password was correct, false otherwise
* @author Aryan Jassal
*/
bool prompt_password(buf_t *kek);
bool prompt_password(buf_t* kek);

/**
* Checks if the password is correct against the stored password.
Expand All @@ -20,20 +20,20 @@ bool prompt_password(buf_t *kek);
* @returns True if password is correct, false otherwise.
* @author Aryan Jassal
*/
bool check_password(buf_t *password, buf_t *kek);
bool check_password(buf_t* password, buf_t* kek);

/**
* Writes the auth details stored by the auth_t struct.
* @param auth
* @author Aryan Jassal
*/
void write_auth(const auth_t *auth);
void write_auth(const auth_t* auth);

/**
* Reads the auth details stored on disk into the auth_t struct.
* @param auth
* @author Aryan Jassal
*/
void read_auth(auth_t *auth);
void read_auth(auth_t* auth);

#endif
2 changes: 1 addition & 1 deletion include/auth/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
* @param hash The output hash
* @author Aryan Jassal
*/
void hash_password(const buf_t *password, const buf_t *salt, buf_t *hash);
void hash_password(const buf_t* password, const buf_t* salt, buf_t* hash);

#endif
21 changes: 12 additions & 9 deletions include/command/agent/agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@
#define __COMMAND_AGENT_AGENT_H__

/**
* This subcommand groups all the operations involving the agent.
* This command group provides utility functions for the agent or the node
* currently running. The command tree looks like this.
*
* A catch-all for the agent subcommand. This will dispatch the arguments to the
* relevant handlers as needed.
*
* @param argc
* @param argv
* @returns Exit code
* @author Alexandro Jauregui
* agent
* ├── setup
* └── reset
*/
int cmd_agent(int argc, char *argv[]);

#include "utils/args.h"

extern cmd_handler_t cmd_agent;
extern cmd_handler_t cmd_agent_setup;
extern cmd_handler_t cmd_agent_reset;
extern const int num_agent_commands;

#endif
9 changes: 8 additions & 1 deletion include/command/agent/reset.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
#ifndef __COMMAND_AGENT_RESET_H__
#define __COMMAND_AGENT_RESET_H__

#include "utils/args.h"

/**
* Resets the password of the agent. The password changing does not require a
* re-encryption of the encrypted systems.
* @param argc
* @param argv
* @param flagc
* @param flagv
* @param path The command path to this handler
* @param self The object for this handler
* @returns Exit code
* @author Aryan Jassal
*/
int cmd_agent_reset(int argc, char *argv[]);
int handler_agent_reset(int argc, char* argv[], int flagc, char* flagv[],
const char* path, cmd_handler_t* self);

#endif
12 changes: 10 additions & 2 deletions include/command/agent/setup.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
#ifndef __COMMAND_AGENT_SETUP_H__
#define __COMMAND_AGENT_SETUP_H__

#include "utils/args.h"

/**
* Command handler for setting up the agent. Will do nothing if the agent
* already exists.
* @param argc
* @param argv
* @author Alexandro Jauregui
* @param flagc
* @param flagv
* @param path The command path to this handler
* @param self The object for this handler
* @returns Exit code
* @author Aryan Jassal
*/
int cmd_agent_setup(int argc, char *argv[]);
int handler_agent_setup(int argc, char* argv[], int flagc, char* flagv[],
const char* path, cmd_handler_t* self);

#endif
29 changes: 20 additions & 9 deletions include/command/bin/bin.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,27 @@
#define __COMMAND_BIN_BIN_H__

/**
* This subcommand groups all the operations involving bins.
* This command group provides management functions for all bins. The command
* tree looks like this.
*
* A catch-all for the bin subcommand. This will dispatch the arguments to the
* relevant handlers as needed.
*
* @param argc
* @param argv
* @returns Exit code
* @author Aryan Jassal
* bin
* ├── create
* ├── rename
* ├── ls
* ├── rm
* ├── export
* └── import
*/
int cmd_bin(int argc, char *argv[]);

#include "utils/args.h"

extern cmd_handler_t cmd_bin;
extern cmd_handler_t cmd_bin_create;
extern cmd_handler_t cmd_bin_rename;
extern cmd_handler_t cmd_bin_ls;
extern cmd_handler_t cmd_bin_rm;
extern cmd_handler_t cmd_bin_export;
extern cmd_handler_t cmd_bin_import;
extern const int num_bin_commands;

#endif
9 changes: 8 additions & 1 deletion include/command/bin/create.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
#ifndef __COMMAND_BIN_CREATE_H__
#define __COMMAND_BIN_CREATE_H__

#include "utils/args.h"

/**
* Creates a new bin.
* @param argc
* @param argv
* @param flagc
* @param flagv
* @param path The command path to this handler
* @param self The object for this handler
* @returns Exit code
* @author Aryan Jassal
*/
int cmd_bin_create(int argc, char *argv[]);
int handler_bin_create(int argc, char* argv[], int flagc, char* flagv[],
const char* path, cmd_handler_t* self);

#endif
20 changes: 20 additions & 0 deletions include/command/bin/export.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef __COMMAND_BIN_EXPORT_H__
#define __COMMAND_BIN_EXPORT_H__

#include "utils/args.h"

/**
* Exports the specified bins to a single file.
* @param argc
* @param argv
* @param flagc
* @param flagv
* @param path The command path to this handler
* @param self The object for this handler
* @returns Exit code
* @author Aryan Jassal
*/
int handler_bin_export(int argc, char* argv[], int flagc, char* flagv[],
const char* path, cmd_handler_t* self);

#endif
20 changes: 20 additions & 0 deletions include/command/bin/import.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef __COMMAND_BIN_IMPORT_H__
#define __COMMAND_BIN_IMPORT_H__

#include "utils/args.h"

/**
* Imports saved bins from an exported file.
* @param argc
* @param argv
* @param flagc
* @param flagv
* @param path The command path to this handler
* @param self The object for this handler
* @returns Exit code
* @author Aryan Jassal
*/
int handler_bin_import(int argc, char* argv[], int flagc, char* flagv[],
const char* path, cmd_handler_t* self);

#endif
Loading