@@ -64,24 +64,30 @@ function dataid2discussionpath($dataid)
6464// False if format is incorrect.
6565function validSJCL ($ jsonstring )
6666{
67- $ accepted_keys =array ('iv ' ,'salt ' ,'ct ' );
67+ $ accepted_keys =array ('iv ' ,'v ' , ' iter ' , ' ks ' , ' ts ' , ' mode ' , ' adata ' , ' cipher ' , ' salt ' ,'ct ' );
6868
6969 // Make sure content is valid json
7070 $ decoded = json_decode ($ jsonstring );
7171 if ($ decoded ==null ) return false ;
7272 $ decoded = (array )$ decoded ;
7373
74- // Make sure required fields are present and that they are base64 data.
74+ // Make sure required fields are present
7575 foreach ($ accepted_keys as $ k )
7676 {
7777 if (!array_key_exists ($ k ,$ decoded )) { return false ; }
78- if (base64_decode ($ decoded [$ k ],$ strict =true )==null ) { return false ; }
7978 }
8079
80+ // Make sure some fields are base64 data
81+ if (base64_decode ($ decoded ['iv ' ],$ strict =true )==null ) { return false ; }
82+ if (base64_decode ($ decoded ['salt ' ],$ strict =true )==null ) { return false ; }
83+ if (base64_decode ($ decoded ['cipher ' ],$ strict =true )==null ) { return false ; }
84+
8185 // Make sure no additionnal keys were added.
82- if (count (array_intersect (array_keys ($ decoded ),$ accepted_keys ))!=3 ) { return false ; }
86+ if (count (array_intersect (array_keys ($ decoded ),$ accepted_keys ))!=10 ) { return false ; }
8387
84- // FIXME: Reject data if entropy is too low ?
88+ // Reject data if entropy is too low
89+ $ ct = base64_decode ($ decoded ['ct ' ], $ strict =true );
90+ if (strlen ($ ct ) > strlen (gzdeflate ($ ct ))) return false ;
8591
8692 // Make sure some fields have a reasonable size.
8793 if (strlen ($ decoded ['iv ' ])>24 ) return false ;
0 commit comments