I am currently working on a web application with sensitive data to store (personal medical data). The app is on the very first stages of conception and I am to quickly produce a beta version that would be used, while on a very narrowed scale, in production, with real people's data. Following a few month of beta testing and refining, the app will hit production on a larger scale.
My goal, once the beta is ended, is to hire a professional to review the security of the app, and performs some pentests. But unfortunately this is out of the way right now, for business and financial reasons. I'm primarily a web developer and even though I know more or less advanced basics in security, I am in no way a security professional, so the situation is far from ideal but I don't have any other options right now. Even if those data are medical, they are not extremely sensitive, but I would like to secure them the best I can.
For the beta, the global project is as following : My back end consists of a node.js server serving the static files to access the webapp on desktop, and of an api accessing and serving the data. My front end will primarily be an android app on tablet. The whole thing is setup on-premises on a local network with, in the worst case scenario, no access at all to external ressources, which prevents me of using any cloud-based key management system or anything alike.
I have one database for the customer, accessed by several users trough their tablets or desktops computers.
As the tablets may end up being offline and the whole database will be relatively small, the goal is to download the whole database on the tablet, and sync back every modified data later on. I would like that the most sensitive data stay most of the time encrypted on the tablet, and be decrypted only when necessary. If a modification is made, the data would then be encrypted back on the tablet, before sending it back to the server.
Currently what I'm planning to do is to have every sensitive data encrypted in database (with a key "K1"). To avoid storing both the encrypted data and the encryption key on the server, that key would be itself encrypted with a key "K2". That way, the encrypted K1 could be stored on the tablet (hardcoded in the app sources), while the other key would be stored on the server and sent to the tablet when necessary. The main goal being that an attacker gaining access to the server would not have access to both the encrypted data and the encryption key, and that if a tablet were to be stolen, the encryption key K1 would not be as easily divulged.
This solution in itself may still be weak, I'm working on it as much as I can, but it has anyway one major drawback : I can't have an hardcoded client-side key when accessing the webapp trough a browser, unless I have a specific desktop app installed (which I could have, but it would add a lot more complexity and time consuming tasks to the project). Every solution I think of end-up with having both the encrypted data and the encryption key on the same server, which as far as I know is a major flaw that I would like to avoid.
So here is my question : would there be a - if not perfectly secure, at least not totally flawed - way to have this encryption key sent from the server to any web client, alongside the encrypted data ? Or would there be a way to decrypt the data on the front-side, and still avoid the server to ever have access to the encryption key ?
Any comments on the solution I described would also be appreciated, especially if it is to tell me that it is absolutely terrible. Thanks !