How Do I Get an OSX Folder Checksum in Objective C? -


in objective c, how checksum osx folder , contents (which may have several subfolders)? preferably, i'd sha512 value.

in bash, can so:

find /tmp/examplefolder -type f -print | xargs cat | shasum -a 512

...however, 1 can replace shasum command own version , undo i'm trying do.

background:

i'm using native osx webkit widget gui of osx application. pulls file:// out of folder called myapp.app/resources/html. resist virus maliciously hacking myapp.app, plan have info.plist sha512 value in (that encrypted of course). when application boots, calculate sha512 value of myapp.app/resources/html, encrypt in same way info.plist value, , compare 2 values see if identical. if not, application has been compromised. i'll alert user dialog box , shut down application.

questions answered

q1. won't have encrypted in way prevent tampering saved value in info.plist? – mipadi

a1. yes, before storing in info.plist, encrypted. said above. can handle encryption step using crypto library.

q2. files in app (resource directory) not have write permissions. if encrypt save encryption key? – zaph

a2. @ time of compilation, in compilation steps, have bash script calculate sha512 checksum, encrypt it, , update info.plist.

q3. if files in application can't written to, what's point of checksum @ all? – mipadi

a3. application won't write resources/html folder. store session state using typical user settings strategy apple encourages applications. instead, fear virus infects resources/html folder, replacing bad stuff, , causes application appear normal doing harmful in background. checksum can -- can prevent tampering after application installation.

q4. assumed asker not using code signing (for reason), since code signing cover this. – mipadi

a4. if you're asking why don't rely on code signing -- it's because after application marked trusted, virus can resources/html folder , cause havoc. why need checksum mechanism on application boot.

you use filemanager method:

- (nsdirectoryenumerator<nsurl *> *)enumeratoraturl:(nsurl *)url includingpropertiesforkeys:(nsarray<nsstring *> *)keys options:(nsdirectoryenumerationoptions)mask errorhandler:(bool (^)(nsurl *url, nserror *error))handler 

see apple documentation example code.
or

- (nsarray<nsstring *> *)subpathsofdirectoryatpath:(nsstring *)path error:(nserror *)error 

to enumerator files in path.

create sha512 instance common crypto function:

cc_sha512_init(cc_sha256_ctx *c) 

for each file enumerated update:

cc_sha512_update(cc_sha256_ctx *c, const void *data, cc_long len) 

complete with:

cc_sha512_final(unsigned char *md, cc_sha256_ctx *c) 

there no need encrypt sha512 output since sha one-way function.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -