Check-in [284eae926e]
Overview
Comment:Updated to free old data (not thread safe, but also not used at the moment) and minor cleanups for CVFS obsfucation
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:284eae926e2a6540726eebd459d4f9d5f1c52131
User & Date: rkeene on 2014-11-23 20:02:18
Other Links: manifest | tags
Context
2014-11-24
03:14
Added script to make kits for publishing check-in: f6757a3c22 user: rkeene tags: trunk
2014-11-23
20:02
Updated to free old data (not thread safe, but also not used at the moment) and minor cleanups for CVFS obsfucation check-in: 284eae926e user: rkeene tags: trunk
02:55
Documented obsfucated CVFS support check-in: ae6b7036ca user: rkeene tags: trunk
Changes

Modified kitsh/buildsrc/kitsh-0.0/cvfs_data.c from [981ef56829] to [010e908a77].

   162    162   
   163    163   	if (finfo == NULL) {
   164    164   		Tcl_SetResult(interp, "No such file or directory", TCL_STATIC);
   165    165   
   166    166   		return(TCL_ERROR);
   167    167   	}
   168    168   
   169         -	if (finfo->type == CVFS_FILETYPE_OBSFUCATED_FILE || finfo->type == CVFS_FILETYPE_ENCRYPTED_FILE) {
          169  +	if (finfo->type == CVFS_FILETYPE_ENCRYPTED_FILE) {
   170    170   		cmd_decryptFile = getCmdDecryptFile(hashkey);
   171    171   
   172    172   		if (cmd_decryptFile != NULL) {
   173    173   			cmd_decryptFile(file, finfo);
   174    174   		}
   175    175   	}
   176    176   

Modified kitsh/buildsrc/kitsh-0.0/dir2c.tcl from [a9768c9e59] to [18ee9a3f9a].

   120    120   
   121    121   	switch -- $key(method) {
   122    122   		"rotate_subst" {
   123    123   			switch -- $target {
   124    124   				"c" {
   125    125   					set retval ".type = CVFS_KEYTYPE_ROTATE_SUBST,\n"
   126    126   					append retval ".typedata.rotate_subst.rotate_length = $key(rotate_length),\n"
   127         -					append retval ".typedata.rotate_subst.subst         = [stringify $key(subst)]\n"
          127  +					append retval ".typedata.rotate_subst.subst         = (unsigned char *) [stringify $key(subst)]\n"
   128    128   
   129    129   					return $retval
   130    130   				}
   131    131   			}
   132    132   		}
   133    133   	}
   134    134   
................................................................................
   240    240   
   241    241   #  ifndef LOADED_CVFS_COMMON
   242    242   #    define LOADED_CVFS_COMMON 1
   243    243   
   244    244   typedef enum {
   245    245   	CVFS_FILETYPE_FILE            = 0,
   246    246   	CVFS_FILETYPE_DIR             = 1,
   247         -	CVFS_FILETYPE_OBSFUCATED_FILE = 2,
   248         -	CVFS_FILETYPE_ENCRYPTED_FILE  = 3,
          247  +	CVFS_FILETYPE_ENCRYPTED_FILE  = 2,
          248  +	CVFS_FILETYPE_COMPRESSED_FILE = 4,
   249    249   } cvfs_filetype_t;
   250    250   
   251    251   struct cvfs_data {
   252    252   	const char *             name;
   253    253   	unsigned long            index;
   254    254   	unsigned long            size;
   255    255   	cvfs_filetype_t          type;
   256    256   	const unsigned char *    data;
          257  +	int                      free;
   257    258   };
   258    259   
   259    260   typedef enum {
   260    261   	CVFS_KEYTYPE_ROTATE_SUBST     = 0,
   261    262   } cvfs_keytype_t;
   262    263   
   263    264   struct cvfs_key {
................................................................................
   281    282   		}
   282    283   		h &= ((~g) & 0xffffffffLU);
   283    284   	}
   284    285           
   285    286           return(h);
   286    287   }
   287    288   
   288         -#include <stdio.h>
   289    289   static int cvfs_decrypt(unsigned char *out, const unsigned char *in, unsigned long in_out_length, struct cvfs_key *key) {
   290    290   	unsigned long i;
   291    291   	unsigned char in_ch, out_ch;
   292    292   	int ch_idx;
   293    293   
   294    294   	for (i = 0; i < in_out_length; i++) {
   295    295   		in_ch = in[i];
................................................................................
   304    304   }
   305    305   
   306    306   #  endif /* !LOADED_CVFS_COMMON */}
   307    307   puts ""
   308    308   
   309    309   puts "static struct cvfs_data ${code_tag}_data\[\] = {"
   310    310   puts "\t{"
          311  +puts "\t\t/* Index 0 cannot be used because we use the value 0 to represent failure */"
   311    312   puts "\t\t.name  = NULL,"
   312    313   puts "\t\t.index = 0,"
   313    314   puts "\t\t.type  = 0,"
   314    315   puts "\t\t.size  = 0,"
   315    316   puts "\t\t.data  = NULL,"
          317  +puts "\t\t.free  = 0,"
   316    318   puts "\t},"
   317    319   for {set idx 1} {$idx < [llength $files]} {incr idx} {
   318    320   	set file [lindex $files $idx]
   319    321   	set shortfile [shorten_file $startdir $file]
   320    322   
   321    323   	unset -nocomplain finfo type
   322    324   	file stat $file finfo
................................................................................
   327    329   
   328    330   			set fd [open $file]
   329    331   			fconfigure $fd -translation binary
   330    332   			set data [read $fd]
   331    333   			close $fd
   332    334   
   333    335   			if {$obsfucate} {
   334         -				set type "CVFS_FILETYPE_OBSFUCATED_FILE"
          336  +				set type "CVFS_FILETYPE_ENCRYPTED_FILE"
   335    337   				set data "(unsigned char *) [stringify [encrypt $data $obsfucation_key]]"
   336    338   			} else {
   337    339   				set type "CVFS_FILETYPE_FILE"
   338    340   				set data "(unsigned char *) [stringify $data]"
   339    341   			}
   340    342   		}
   341    343   		"directory" {
................................................................................
   347    349   
   348    350   	puts "\t{"
   349    351   	puts "\t\t.name  = \"$shortfile\","
   350    352   	puts "\t\t.index = $idx,"
   351    353   	puts "\t\t.type  = $type,"
   352    354   	puts "\t\t.size  = $size,"
   353    355   	puts "\t\t.data  = $data,"
          356  +	puts "\t\t.free  = 0,"
   354    357   	puts "\t},"
   355    358   }
   356    359   puts "};"
   357    360   puts ""
   358    361   
   359    362   puts "static unsigned long ${code_tag}_lookup_index(const char *path) {"
   360    363   puts "\tswitch (cvfs_hash((unsigned char *) path)) {"
................................................................................
   502    505   puts "\treturn(num_children);"
   503    506   puts "}"
   504    507   puts ""
   505    508   
   506    509   if {$obsfucate} {
   507    510   	puts "static void ${code_tag}_decryptFile(const char *path, struct cvfs_data *finfo) {"
   508    511   	puts "\tstatic struct cvfs_key key = { [string map [list "\n" " "] [encrypt_key_export $obsfucation_key "c"]] };"
   509         -	puts "\tunsigned char *new_data;"
   510         -	puts "\tint decrypt_ret;"
          512  +	puts "\tunsigned char *new_data, *old_data;"
          513  +	puts "\tint decrypt_ret, free_old_data;"
   511    514   	puts ""
   512    515   	puts "\tnew_data = malloc(finfo->size);"
   513    516   	puts "\tdecrypt_ret = cvfs_decrypt(new_data, finfo->data, finfo->size, &key);"
   514    517   	puts "\tif (decrypt_ret != 0) {"
   515    518   	puts "\t\tfree(new_data);"
   516    519   	puts ""
   517    520   	puts "\t\treturn;"
   518    521   	puts "\t}"
          522  +	puts ""
          523  +	puts "\tfree_old_data = finfo->free;"
          524  +	puts "\told_data = (void *) finfo->data;"
          525  +	puts ""
   519    526   	puts "\tfinfo->data = new_data;"
          527  +	puts "\tfinfo->free = 1;"
   520    528   	puts "\tfinfo->type = CVFS_FILETYPE_FILE;"
          529  +	puts ""
          530  +	puts "\tif (free_old_data) {"
          531  +	puts "\t\tfree(old_data);"
          532  +	puts "\t}"
   521    533   	puts "\treturn;"
   522    534   	puts "}"
   523    535   	puts ""
   524    536   }
   525    537   
   526    538   puts "#  ifdef CVFS_MAKE_LOADABLE"
   527    539