This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Communeguy's profile picture

Credential Mismatch/Unexpected If-Statement Behaviour.

Started by Communeguy, 26 November 2014 - 12:38 PM
Communeguy #1
Posted 26 November 2014 - 01:38 PM
I swear to god, this project is going to get me banned from this forum.

As part of the ongoing project to create a credentials-sharing "standard" for me to use as a framework across a number of other applications, I've been troubleshooting problems in the Admin program, which is used to modify the tables on the server side. I'm sure this isn't the most elegant or simple solution, but it's the solution I coded and after four or five days now of studying, planning, building, and debugging I'm reluctant to have to start over.

Anyway, after hunting down most of the bugs (with your help in a few cases), I now have a working administration program in all but one respect - it won't save the changes to the server.

CGClear Admin v 0.0.4 (4th Alpha Build) - http://pastebin.com/k1u5zTd4
CGClear Server v 0.0.2 (2nd Alpha Build) - http://pastebin.com/U4YGWCVh

According to the program design, the administrator and the server confirm each other's identity with a "trust" variable (I'm having a hard time thinking of a real-life computing equivalent. Certificate maybe?), before the server accepts the new data. The admin program initiates this process at Admin:322 as part of the SAVE command beginning from Admin:317. The server then looks at the message from the admin and should be handling it from Server:268 onward.

Admin is NOT accepting the credentials from the server, even though the relevant variable, trust, is set to "anything" in both sets of code. It instead falsely executes the error handling code from Admin:337 onward.

I know that at the very least, the Admin is directly verifying itself, as the server correctly displays "Receiving Credentials Update" (Server:268), and that the Admin is identifying itself correctly, as the server does NOT list its error code, and instead gets stuck in the receiving loop, and responds to no further modem inputs.

I also know that the Admin and the Server trust variables are identical, which means that the programs SHOULD talk to each other.

I'm at wits end and honestly have no idea what's going on. As near as I can tell, the if/else from Admin:322-339 is simply doing the opposite of what it should.

Once this last problem with the interaction is solved, the "standard" is technically fully developed. I'll be adding everyone who helped in both threads related to it to an acknowledgement section in the docs.
Edited on 26 November 2014 - 12:39 PM
Nemisis #2
Posted 26 November 2014 - 07:07 PM
I wish I could be more sure about this.

I am just starting out with Lua but have experience in old school basic programming. (8-bit from back in the day)
So bear with me if I am not following this block properly.

Line 321 sets a false ID as default while
line 327 also sets a false ID after a successful transmission.
Should line 327 be made to set the ID to true.

Keep in mind, I know little about Lua and am just trying to help.
Also what Lua editor do you use? I am using notepad++ and would like something better any suggestions?



(From your code)

321					  local access = false
...
...
...
...
326					 print("Transmission Successful.")
327					 access = false
...
...

(Should it be?)
326					 print("Transmission Successful.")
327					 access = true
KingofGamesYami #3
Posted 26 November 2014 - 07:31 PM
Also what Lua editor do you use? I am using notepad++ and would like something better any suggestions?

I use sublime text 2 with a computercraft package (It's on the forums somewhere), or the limited editor on Mimic
ElvishJerricco #4
Posted 26 November 2014 - 08:29 PM

(From your code)

321					  local access = false
...
...
...
...
326					 print("Transmission Successful.")
327					 access = false
...
...

(Should it be?)
326					 print("Transmission Successful.")
327					 access = true

I find that usually when a control statement is giving me unexpected results, it almost always comes down to something like this, where I assigned a value incorrectly, or forgot to declare something as local, or something to that effect. You end up having to check over every single relevant line for the mistake. Super frustrating.

And yea Sublime Text is nice. There's a beta for version 3 out. Not sure what the differences are.
Communeguy #5
Posted 27 November 2014 - 12:23 AM
I believe, if I've written things properly, it SHOULD be setting access to false, because it's supposed to be closing out the access variable to close out the program. I believe. I'm going to have to go over the code with a comb and see if that could possibly be the problem.

Personally, I'm using notepad++. The only feature I find it lacking is auto-detecting my many syntax errors.

Edit: I've commented out the variables - which weren't being checked for anyway - and regardless, the system still thinks the server isn't properly credentialed even though it is.
Edited on 26 November 2014 - 11:37 PM
Dragon53535 #6
Posted 27 November 2014 - 02:10 AM
Just to confirm, on your server, you've actually set mside to a side and it's not just "direction"
Communeguy #7
Posted 27 November 2014 - 02:14 AM
Right. Top, as it happens.
Dragon53535 #8
Posted 27 November 2014 - 03:27 AM
It looks to me like you're never initially sending the trust variable to the server.
Your first transmission to the server is

modem.transmit(reqChan, downChan, sha256(input))
yet in both of your if statements on your server you're checking

if message == sha256(trust) then
Perhaps sending a trust message first should allow you to have it work?
Communeguy #9
Posted 27 November 2014 - 12:51 PM
I couldn't see how that affected things (the line you're referring to is inside a chunk of code that grabs the original tables, not the save block that's causing the crash, which beings on line 322), but just to be sure I changed the afflicted line back. The error was not resolved.
Nemisis #10
Posted 27 November 2014 - 04:14 PM
Just looked into Sublime 3.
It is exactly what I am looking for.

Good luck on your gremlin hunt.

Thanks
Dragon53535 #11
Posted 27 November 2014 - 05:09 PM

modem.transmit(userChan, downChan, textutils.serialize(userHash))
modem.transmit(passChan, downChan, textutils.serialize(passHash))
modem.transmit(credChan, downChan, textutils.serialize(userHash))
modem.transmit(saltChan, downChan, textutils.serialize(tableSalt))
These are all your modem.transmits in the save section.

modem.open(reqChan)
modem.open(keyChan)
These are all the modem.opens on your server. See a problem?
You've never opened the correct channels and so the server doesn't receive a thing.
Communeguy #12
Posted 27 November 2014 - 05:25 PM
Derp derp.

The channels are now open. It looks like the tables ARE sending correctly, but I'm still getting the admin program returning that the server's invalid. Which makes me wonder if it would even work with an invalid server.
Edited on 27 November 2014 - 04:58 PM