GithubHelp home page GithubHelp logo

securenotes's Introduction

SecureNotes

Welcome to SecureNotes.

SecureNotes lets the user store text notes securely. All notes are encrypted with AES-GCM 256 before being stored in the database.

The key to decrypt notes is formed by the user's password; therefore, only the user can decrypt the saved notes.

Demo

Click on image below for the product video demo.

SecureNotes Demo

Supported platforms & Set up

  • iOS 13 and later.
  • Xcode 12 and later.

Set up

The Cocoapods dependency manager is required to set up the project dependencies.

If Cocoapods is already available, then download the SecureNotes project from Github and run the below command.

cd SecureNotes
pod install

Features & Cryptography

Cryptography Used

  • AES-GCM
  • AES-CBC
  • SHA256
  • SHA512
  • eciesEncryptionCofactorVariableIVX963SHA256AESGCM

Register, Key forming

salt = random(32 bytes) // To be encrypted by ecies and stored in db
data = Data(salt+username+pin)
iv = random(32 bytes) // To be encrypted by ecies and stored in db
key = data.sha256()
aes = AES-GCM(key, iv)

hash = data.sha512() // To be encrypted by ecies and stored in db

For demonstration purposes, sha256 is used to derive the key. However, PBKDF2 should be used to protect against brute force.

After successful login/registering, the AES-GCM key will be formed and stay encrypted in the memory during the active session by Secure Enclave eciesEncryptionCofactorVariableIVX963SHA256AESGCM (EC*). It acts as a caching algorithm to be re-used multiple times without additional login from the user. If the application is transitioned to background or is terminated, the encrypted EC(AES-GCM key, IV) will be wiped out from memory.

SecureEnclave.generateKeyPair()
// Caching keys in memory
encrypted = SecureEnclave.encrypt(key)
encrypted = SecureEncalve.encrypt(IV)

Login with username + pin

encryptedSalt = datbase(encryptedSalt)
salt = SecureEnclave.decrypt(encryptedSalt)

encryptedHash = datbase(encryptedHash)
hash = SecureEnclave.decrypt(encryptedHash)

data = Data(salt+username+pin)
loginHash = data.sha512()

if loginHash == hash {
    key = data.sha256()
    encryptedKey = SecureEnclave.encrypt(key)
    encryptedIV = Database(encryptedIV)
} else {
    //Wrong Username or Password
}

Enable Biometric

The biometric authentication mode is not activated by default.

The EC(AES-GCM key) will need to be securely stored in the database if the user wants to use the 'login with the Biometric' feature

First, the system generates a new random AES-CBC symmetric key.

Once the new AES-CBC key is created, the EC(AES-GCM key) will be encrypted with AES-CBC key

The final AES-CBC(EC(AES-GCM key)) will be stored in the database for later access.

The new AES-CBC symmetric key to decrypt the AES-CBC(EC(AES-GCM key)) will be locked inside Keychain and only be accessible with the user's presence (Biometrics authentication)

bioIV = random(16 bytes) // To be encrypted by ecies and stored in db
bioKey = random(16 bytes)
bioServiceId = random(32 bytes) // To be encrypted by ecies and stored in db

// Store AES-CBC key to the keychain that requires user's presence
KeyChainBiometric.add(bioKey, serviceId: bioServiceId)

aes = AES-CBC(bioIV, bioKey)
encryptedMasterKey = aes.encrypt(encryptedKey) // To store in db

Login with Biometric

encryptedBioServiceId = Database(encryptedBioServiceId)
bioServiceId = SecureEnclave.decrypt(encryptedBioServiceId)

encryptedBioIV = Database(encryptedBioIV)
bioIV = SecureEnclave.decrypt(encryptedBioIV)

// This key requires the user's presence to read
bioKey = KeyChainBiometric.read(bioServiceId)

aes = AES-CBC(bioIV, bioKey)
encryptedMasterKey = Database(encryptedMasterKey)

// Caching keys in memory
encryptedKey = aes.decrypt(encryptedMasterKey)
encryptedIV = Database(encryptedIV)

Sequence Diagram

Sequence Diagram

Security Discussion:

The application has been enforced by some security protections in the RELEASE build:

  • Show warning to jailbreak devices
  • Anti-debug for some important functions
  • Anti-hook for some important functions

Below methods can be implemented for the application's further protection:

  • Hide hardcoded strings, add more control flows and rename sensitive functions/variables to hide attack points during static analysis.
  • Add a secure keypad to protect the pin against the keyboard logger.
  • Add anti-tampering.
  • Use MEDL and Zcrambler to implement RASP.

Testing

Because of the time constraints, automatic tests are not included.

securenotes's People

Contributors

hoangifp avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.