0
$\begingroup$

Introduction part

I'm writing an application that requires authentication to be used, specifically the database and config file can only be read an authenticated user. However this authentication is done locally only as it must work without internet connection.

Here's how it's implemented currently:

The user types its login and password, which is given in a KDF (Scrypt) with an added random salt. The derived key's hash is compared with the expected hash stored on the disk. If correct, the user is "logged in" and can proceed to decrypt a second key using the derived key (not the hash). If the decryption of the second key is correct the user can use it decrypt the database and config files.

Login diagram Note, those AES blocks work in GCM mode so we have integrity checks as well.

I know that some attacks are possible, you could tamper with those files to prevent a user to log in or access his data but there are mitigations for that. You could also modify the hash of the key to "log in" but you wouldn't be able to decrypt the second round key so it's pointless.

I believe that this part is safe and only users have an account can access their data. (But if you see something wrong with it let me know)

Now on to the question

On top of this system I now need to have a specific account that would have elevated privileges once logged into the application for maintenance purposes. I tried working out something that would allow a user to prove he's admin but I always find ways for another user to impersonate the admin.

Can you think of a way to achieve that ? Or is a third party required ? I can definitely see it being done with a certificate that must be validated by a server but I can't figure out if it's possible without a server.

Any help is appreciated, thanks !

Edit: To maybe help clarify, here's an example of something that wouldn't work

Add a special file, let's call it admin.bin, encrypted in AES-GCM with the admin's K2, containing some data. On login if the user can decrypt the file correctly we give him admin rights. But then any user could just regenerate this file with their own K2 to get admin rights. It would work if we put a server signed certificate in the file, so we need to be able to decrypt the file AND have the server validate the certificate.

$\endgroup$
6
  • $\begingroup$ We may need to migrate this question to Information Security. I'm not entirely sure how the keys are derived from the password or what you mean with the "something" that can be impersonated. Generally user accounts have privileges associated with them, why wouldn't that work here? $\endgroup$
    – Maarten Bodewes
    Commented Apr 22 at 10:17
  • $\begingroup$ @MaartenBodewes Oh thanks, I didn't even know there was this substack. I do feel like it's a crypto question tho, I'm looking for some cryptographic method to give specific permissions for user without any 3rd party. You mean the OS user accounts ? That won't really work because we can have multiple app users from a single OS account $\endgroup$
    – Nifil
    Commented Apr 22 at 11:07
  • $\begingroup$ No I meant storing a policy or similar in a DB, possibly the DB where you also store the salt. $\endgroup$
    – Maarten Bodewes
    Commented Apr 22 at 11:44
  • $\begingroup$ @MaartenBodewes There's one DB per user and they are all local so each user could just grand themselves rights by making the right SQL queries. (For more context, those DB contain medical data and each user is a doctor, so each doctor has access to his patients but no other doctors'). The salt use by Scrypt is simply stored on the disk as a binary file $\endgroup$
    – Nifil
    Commented Apr 22 at 11:48
  • $\begingroup$ I'm afraid you need to hire a security professional for this. There is no way that we can have a full oversight of the systems without doing an interview to establish the complete protocol it seems. Answers should take procedural security in account (etc.) which is why I think that Security.SE would be a better place. However, they'd run into the same issues regarding the protocol. $\endgroup$
    – Maarten Bodewes
    Commented Apr 22 at 12:03

1 Answer 1

0
$\begingroup$

Ok I think I found a way. (Or rather, found an argument to why it's not possible)

Create a file called admin.bin, encrypt it with the admin's account K2 The file contains a certificate signed by a secret key, the public key to this secret key is hardcoded in the executable. On login, the app can verify that the user can 1) decrypt the admin file, 2) the certificate is valid.

I think the only way to attack this is to modify the executable to change the public key that's hardcoded in the app. So it's not really safe, but probably the only way to do without a 3rd party.

This comforts to me the idea that the only way to do this is to have a 3rd party sadly.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.