Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

SSK2: Documentation error in secure_load
Started by graham07 Dec 02 2017 05:49 AM

2 replies to this topic
ssk2
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

graham07

[GLOBAL: userInfoPane.html]
graham07
  • Contributor

  • 256 posts
  • Corona SDK

Ed,

  I believe there is a small error in the documentation.

Page link: https://roaminggamer.github.io/RGDocs/pages/SSK2/extensions/

Subsection: Tables

 

secure_load( theTable, fileName [ , base ] ) Equivalent to load(), but uses ssk.security.* to obfuscate save.

I believe should read

 

 

secure_load( fileName [ , base ] ) Equivalent to load(), but uses ssk.security.* to obfuscate save.

 

 

For those who may arrive here via a forum search...

 

The line would be:

encodedTable = table.secure_load("secure_save_data.json")

Cheers.

Graham



[TOPIC: post.html]
#2

graham07

[GLOBAL: userInfoPane.html]
graham07
  • Contributor

  • 256 posts
  • Corona SDK

One extra question....

 

I'm using this feature to store login info so a user doesn't have to login all the time. 

After I got it all working, I deleted my table to test -relogin, if you do a secure_load and the file doesn't exist, you get a lua crash.

 

Lights/ssk2/security.lua:43: bad argument #1 to 'pairs' (table expected, got nil)

stack traceback:

[C]: in function 'pairs'

Lights/ssk2/security.lua:43: in function 'encode'

Lights/ssk2/security.lua:74: in function 'getKeyString'

Lights/ssk2/extensions/table.lua:256: in function 'secure_load'

Lights/mainLogin.lua:50: in function '?'

?: in function 'dispatchEvent'

?: in function '_nextTransition'

?: in function <?:1494>

?: in function 'gotoScene'

Lights/main.lua:18: in main chunk

 

I did try to circumvent it by putting a 'test = security.loadkey command, and I was going to check if test was false (so it the key isn't there, I would assume the secure table wasn't) but I noticed it doesn't return a value either.

 

​While I can put in another few lines to check if the file exists I'd thought I'd mention it as returning nil on a non-existent file when using table.secure_load would be awesome :)

 

** Edit 

I do see that you also have 

 

  • exists( path ) - Returns true if the file at path exists. Returns false otherwise.

So this edit wrapped around it should work fine.

if ssk.files.util.exists(system.pathForFile( "setup.json", system.DocumentsDirectory )) == true then
print( "File Exists" )
else
print( "File missing" )
end
 

** Edit End

 

The code I use is pretty much your example, but to pre-empt the question should it be asked...

        local security = ssk.security

        local encoded2 = {}
        
        test= security.loadKey( "key.json")
        encoded2 = table.secure_load("setup.json")
        local decodedEmail = security.decode( encoded2.Email )
        local decodedPw = security.decode( encoded2.Pw )

As an aside, credit to you. While it isn't intended to be a huge security protocol, its a great way to store local information and deter the casual hacker. The usage is so easy (as you can see above)!



[TOPIC: post.html]
#3

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,544 posts
  • Corona SDK

@graham07

 

1. Just fixed documentation error.

 

2. I missed your second post entirely.  I put this on my back burner and didn't watch for updates to it since the title was about a docs bug.

 

Note: It is always better to post questions in their own threads.  That said, I think you got this all worked out. :)




[topic_controls]
[/topic_controls]