diff --git a/command/command.go b/command/command.go index 208d211..df9581e 100644 --- a/command/command.go +++ b/command/command.go @@ -3,6 +3,7 @@ package command import "fmt" import "errors" + import "github.com/Heisenberk/goshield/structure" import "github.com/Heisenberk/goshield/crypto" diff --git a/command/command_test.go b/command/command_test.go index d720532..391c178 100644 --- a/command/command_test.go +++ b/command/command_test.go @@ -2,7 +2,7 @@ package command import "testing" -//import "io/ioutil" + import "github.com/Heisenberk/goshield/structure" // TestSansArgument teste la commande "./goshield" diff --git a/crypto/decrypt.go b/crypto/decrypt.go index ea30c8e..000bbbc 100644 --- a/crypto/decrypt.go +++ b/crypto/decrypt.go @@ -1,3 +1,4 @@ +// Package crypto contenant les fonctions de chiffrement/déchiffrement. package crypto import "crypto/aes" @@ -18,13 +19,13 @@ func DecryptBlocAES(iv []byte, key []byte, input []byte) ([]byte, error){ // Si la taille de l'entrée est invalide on lance une erreur. if len(input)%aes.BlockSize != 0 { - return output, errors.New("Failure Decryption : Taille du bloc invalide.") + return output, errors.New("\033[31mFailure Decryption\033[0m : Taille du bloc invalide.") } // Preparation du bloc qui sera chiffré. block, err := aes.NewCipher(key) if err != nil { - return output, errors.New("Failure Decryption : Erreur lors du déchiffrement d'un bloc.") + return output, errors.New("\033[31mFailure Decryption\033[0m : Erreur lors du déchiffrement d'un bloc.") } // Chiffrement AES avec le mode opératoire CBC. @@ -40,13 +41,13 @@ func DecryptFileAES(pathFile string, doc *structure.Documents) error{ // ouverture du fichier à déchiffrer inputFile, err1 := os.Open(pathFile) if err1 != nil { - var texteError string = "Failure Decryption : Impossible d'ouvrir le fichier à déchiffrer "+pathFile+". " + var texteError string = "\033[31mFailure Decryption\033[0m : Impossible d'ouvrir le fichier à déchiffrer "+pathFile+". " return errors.New(texteError) } // renvoie une erreur si l'extension n'est pas la bonne if pathFile[(len(pathFile)-4):]!= ".gsh"{ - var texteError string = "Failure Decryption : L'extension de "+pathFile+" est invalide (doit être \".gsh\"). " + var texteError string = "\033[31mFailure Decryption\033[0m : L'extension de "+pathFile+" est invalide (doit être \".gsh\"). " return errors.New(texteError) } @@ -54,7 +55,7 @@ func DecryptFileAES(pathFile string, doc *structure.Documents) error{ signature := make([]byte, 8) _, err2 := inputFile.Read(signature) if err2 != nil { - var texteError string = "Failure Decryption : Format du fichier à déchiffrer "+pathFile+" invalide. " + var texteError string = "\033[31mFailure Decryption\033[0m : Format du fichier à déchiffrer "+pathFile+" invalide. " return errors.New(texteError) } @@ -62,7 +63,7 @@ func DecryptFileAES(pathFile string, doc *structure.Documents) error{ salt := make([]byte, 15) _, err22 := inputFile.Read(salt) if err22 != nil { - var texteError string = "Failure Decryption : Impossible de lire le salt du fichier chiffré "+pathFile+". " + var texteError string = "\033[31mFailure Decryption\033[0m : Impossible de lire le salt du fichier chiffré "+pathFile+". " return errors.New(texteError) } doc.Salt=salt @@ -72,7 +73,7 @@ func DecryptFileAES(pathFile string, doc *structure.Documents) error{ IV := make([]byte, 16) _, err23 := inputFile.Read(IV) if err23 != nil { - var texteError string = "Failure Decryption : Impossible de lire la valeur d'initialisation du fichier chiffré "+pathFile+". " + var texteError string = "\033[31mFailure Decryption\033[0m : Impossible de lire la valeur d'initialisation du fichier chiffré "+pathFile+". " return errors.New(texteError) } @@ -80,13 +81,13 @@ func DecryptFileAES(pathFile string, doc *structure.Documents) error{ lengthTab := make([]byte, 1) _, err24 := inputFile.Read(lengthTab) if err24 != nil { - var texteError string = "Failure Decryption : Impossible de lire la taille du dernier bloc du fichier chiffré "+pathFile+". " + var texteError string = "\033[31mFailure Decryption\033[0m : Impossible de lire la taille du dernier bloc du fichier chiffré "+pathFile+". " return errors.New(texteError) } stat, err2 := inputFile.Stat() if err2 != nil { - var texteError string = "Failure Decryption : Impossible d'interpréter le fichier à déchiffrer "+pathFile+". " + var texteError string = "\033[31mFailure Decryption\033[0m : Impossible d'interpréter le fichier à déchiffrer "+pathFile+". " return errors.New(texteError) } @@ -94,7 +95,7 @@ func DecryptFileAES(pathFile string, doc *structure.Documents) error{ var division int = (int)((stat.Size()-8-15-16-1)/aes.BlockSize) var iterations int = division if (int)(stat.Size()-8-15-16-1)%aes.BlockSize != 0 { - var texteError string = "Failure Decryption : Fichier" + pathFile +" non conforme pour le déchiffrement AES. " + var texteError string = "\033[31mFailure Decryption\033[0m : Fichier" + pathFile +" non conforme pour le déchiffrement AES. " return errors.New(texteError) } @@ -102,17 +103,13 @@ func DecryptFileAES(pathFile string, doc *structure.Documents) error{ var nameOutput string=pathFile[:(len(pathFile)-4)] outputFile, err3 := os.Create(nameOutput) if err3 != nil { - var texteError string = "Failure Decryption : Impossible d'écrire le fichier chiffré "+nameOutput+". " + var texteError string = "\033[31mFailure Decryption\033[0m : Impossible d'écrire le fichier chiffré "+nameOutput+". " return errors.New(texteError) } input := make([]byte, 16) var cipherBlock []byte temp := make([]byte, 16) - - fmt.Println(iterations) - fmt.Println(lengthTab) - fmt.Println("coucou") for i:=0 ; i