Skip to content

Commit

Permalink
Merge branch 'rsa_verif' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-rabet committed Sep 26, 2022
2 parents 9cc87aa + 0811106 commit b87b721
Show file tree
Hide file tree
Showing 33 changed files with 677 additions and 202 deletions.
16 changes: 15 additions & 1 deletion .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,25 @@
"${workspaceFolder}/**",
"${workspaceFolder}/include"
],
"defines": [],
"defines": ["_XOPEN_SOURCE"],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++17",
"intelliSenseMode": "linux-gcc-x64"
},
{
"name": "Linux - GCC GNU",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/include"
],
"defines": [
"_ISOC11_SOURCE",
"_XOPEN_SOURCE"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu99",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
Expand Down
35 changes: 35 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,48 @@
],
"preLaunchTask": "make formater"
},
{
"name": "mount",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/mount",
"args": [
"${input:mountDevice}",
"${input:mountPath}"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/build",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Activer l'impression en mode Pretty pour gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
],
"preLaunchTask": "make mount"
},
],
"inputs": [
{
"id": "formatArg",
"description": "Fichier à formater",
"type": "promptString",
"default": "test.cfs"
},
{
"id": "mountDevice",
"description": "Disque à monter",
"type": "promptString",
"default": "test.cfs"
},
{
"id": "mountPath",
"description": "Point de montage",
"type": "promptString",
"default": "mnt"
}
]
}
12 changes: 11 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@
"array": "c",
"assert.h": "c",
"cerrno": "c",
"passphrase.h": "c"
"passphrase.h": "c",
"err.h": "c",
"cryptofuse.h": "c",
"fstream": "c",
"fuse.h": "c",
"stdbool.h": "c",
"core_names.h": "c",
"bitset": "c",
"string_view": "c",
"initializer_list": "c",
"utility": "c"
}
}
12 changes: 12 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@
"cwd": "${workspaceFolder}"
}
},
{
"label": "make mount",
"type": "shell",
"command": "/usr/bin/make",
"args": [
"mount",
"-j",
],
"options": {
"cwd": "${workspaceFolder}"
}
},
{
"label": "make test_main",
"type": "shell",
Expand Down
14 changes: 11 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,30 @@ CC = gcc
CFLAGS = -Wall -Wextra -Werror -Iinclude -g -std=gnu99 -D_ISOC11_SOURCE
LDFLAGS = -lm -lcrypto $(FSANITIZE)

SRC = $(shell find $(SRC_CORE_DIR) -name '*.c')
SRC = $(shell find $(FS_CORE_DIR) -name '*.c')
OBJ = $(subst $(PROJECT_DIR),$(BUILD_DIR),$(SRC:.c=.o))

TESTS_SRC = $(shell find $(TESTS_DIR) -name '*.c')
TESTS_OBJ = $(subst $(PROJECT_DIR),$(BUILD_DIR),$(TESTS_SRC:.c=.o))

FORMAT_SRC = $(SRC_CODE_DIR)/formater.c
FORMAT_SRC = $(SRC_DIR)/formater.c
FORMAT_OBJ = $(subst $(PROJECT_DIR),$(BUILD_DIR),$(FORMAT_SRC:.c=.o))

all : formater
MOUNT_SRC = $(SRC_DIR)/mount_fuse.c
MOUNT_OBJ = $(subst $(PROJECT_DIR),$(BUILD_DIR),$(MOUNT_SRC:.c=.o))

all : formater mount

formater: $(BUILD_DIR)/formater $(OBJ)

mount: $(BUILD_DIR)/mount $(OBJ)

$(BUILD_DIR)/formater: $(FORMAT_OBJ) $(OBJ)
$(CC) $(CFLAGS) $^ -o $(BUILD_DIR)/formater $(LDFLAGS)

$(BUILD_DIR)/mount: $(MOUNT_OBJ) $(OBJ)
$(CC) $(CFLAGS) $^ -o $(BUILD_DIR)/mount $(LDFLAGS)

$(BUILD_DIR)/%.o: $(PROJECT_DIR)/%.c
mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@ $(LDFLAGS)
Expand Down
35 changes: 0 additions & 35 deletions code/core/security/crypto_disk.c

This file was deleted.

60 changes: 0 additions & 60 deletions code/formater.c

This file was deleted.

5 changes: 3 additions & 2 deletions global.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ PROJECT_DIR ?= $(shell false) # MUST BE SET BEFORE INCLUDING THIS FILE
BUILD_DIR = $(PROJECT_DIR)/build
TESTS_DIR = $(PROJECT_DIR)/tests/criterion

SRC_CODE_DIR = $(PROJECT_DIR)/code
SRC_CORE_DIR = $(SRC_CODE_DIR)/core
SRC_DIR = $(PROJECT_DIR)/src
FS_CORE_DIR = $(SRC_DIR)/fs
FUSE_CORE_DIR = $(SRC_DIR)/fuse

10 changes: 6 additions & 4 deletions include/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <stddef.h>
#include <stdint.h>

typedef size_t block_t;

/**
* @brief Set the device path global variable.
*
Expand Down Expand Up @@ -42,7 +44,7 @@ uint32_t get_block_size();
*
* @return 0 on success, -1 on error.
*/
int read_blocks(size_t start_block, size_t nb_blocks, void *buffer);
int read_blocks(block_t start_block, size_t nb_blocks, void *buffer);

/**
* @brief Write blocks to the device.
Expand All @@ -53,7 +55,7 @@ int read_blocks(size_t start_block, size_t nb_blocks, void *buffer);
*
* @return 0 on success, -1 on error.
*/
int write_blocks(size_t start_block, size_t nb_blocks, void *buffer);
int write_blocks(block_t start_block, size_t nb_blocks, void *buffer);

/**
* @brief Read a block from the device and decrypt it.
Expand All @@ -64,7 +66,7 @@ int write_blocks(size_t start_block, size_t nb_blocks, void *buffer);
* @param buffer The buffer to fill with the blocks.
* @return int 0 on success, -1 on error.
*/
int read_blocks_with_decryption(unsigned char *aes_key, size_t start_block,
int read_blocks_with_decryption(unsigned char *aes_key, block_t start_block,
size_t nb_blocks, void *buffer);

/**
Expand All @@ -76,7 +78,7 @@ int read_blocks_with_decryption(unsigned char *aes_key, size_t start_block,
* @param buffer The buffer containing the blocks.
* @return int 0 on success, -1 on error.
*/
int write_blocks_with_encryption(unsigned char *aes_key, size_t start_block,
int write_blocks_with_encryption(unsigned char *aes_key, block_t start_block,
size_t nb_blocks, void *buffer);

#endif /* BLOCK_H */
10 changes: 10 additions & 0 deletions include/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,14 @@ EVP_PKEY *load_rsa_keypair_from_disk(const char *public_key_path,
const char *private_key_path,
char *passphrase);

/**
* @brief Loads the RSA private and public keys from the current user's home
* directory.
*
* @param passphrase Gets filled with the passphrase the user enters if he
* decides to.
* @return EVP_PKEY* The loaded RSA keypair.
*/
EVP_PKEY *load_rsa_keypair_from_home(char **passphrase);

#endif /* CRYPTO_H */
50 changes: 50 additions & 0 deletions include/cryptofuse.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#ifndef CRYPTOFUSE_H

#define FUSE_USE_VERSION 30

#include <fuse/fuse.h>

void *cryptfs_init(struct fuse_conn_info *info);
void cryptfs_destroy(void *ptr);
int cryptfs_statfs(const char *path, struct statvfs *stats);

int cryptfs_mkdir(const char *path, mode_t mode);
int cryptfs_mknod(const char *path, mode_t mode, dev_t num);

int cryptfs_rmdir(const char *path);

int cryptfs_getattr(const char *path, struct stat *st);
int cryptfs_open(const char *path, struct fuse_file_info *file);
int cryptfs_read(const char *path, char *buf, size_t sz, off_t offset,
struct fuse_file_info *file);
int cryptfs_write(const char *path, const char *buf, size_t sz, off_t offset,
struct fuse_file_info *file);
int cryptfs_write_buf(const char *path, struct fuse_bufvec *buf, off_t off,
struct fuse_file_info *file);
int cryptfs_read_buf(const char *path, struct fuse_bufvec **bufp,
size_t size, off_t off, struct fuse_file_info *file);
int cryptfs_opendir(const char *path, struct fuse_file_info *file);
int cryptfs_readdir(const char *path, void *data, fuse_fill_dir_t callback, off_t offset,
struct fuse_file_info *file);
int cryptfs_release(const char *path, struct fuse_file_info *file);
int cryptfs_releasedir(const char *path, struct fuse_file_info *file);
int cryptfs_create(const char *path, mode_t mode, struct fuse_file_info *file);
int cryptfs_ftruncate(const char *path, off_t offset, struct fuse_file_info *file);
int cryptfs_access(const char *path, int mode);

int cryptfs_flush(const char *path, struct fuse_file_info *file);
int cryptfs_fsync(const char *path, int, struct fuse_file_info *file);
int cryptfs_fsyncdir(const char *path, int, struct fuse_file_info *file);

int cryptfs_chmod(const char *path, mode_t mod);
int cryptfs_chown(const char *path, uid_t uid, gid_t gid);
int cryptfs_rename(const char *path, const char *name);

int cryptfs_fallocate(const char *path, int, off_t, off_t,
struct fuse_file_info *file);

static struct fuse_operations cryptfs_ops = { .init = cryptfs_init,
.open = cryptfs_open,
.read = cryptfs_read };

#endif /* CRYPTOFUSE_H */
Loading

0 comments on commit b87b721

Please sign in to comment.