GithubHelp home page GithubHelp logo

rusakovichma / authenticated-persistence-poc Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 82 KB

Spring Boot anti-tampering persistence PoC application using AES-GCM

Java 100.00%
tampering-detection spring-boot java authenticated-encryption integration-tests unit-test tampering-attack aes-gcm

authenticated-persistence-poc's Introduction

Spring Boot Authenticated encryption persistence PoC

The PoC how to defend against tampering of encrypted data at persistence layer

Attack example

An encryption is used to prevent information disclosure at DB layer, but it is not prevents sensitive data tampering. Lets imagine the following table structure:

ID | First Name | Last Name | Email | Position | Salary (Encrypted)
1, 'John', 'Smith', '[email protected]', 'CEO', 'ZHNmNDNnYWRmZzQ1MjR2NDJmMjRm'
....
999, 'Joe', 'Doe', '[email protected]', 'Software Engineer', 'HNdrmQ2NMjRDNZqQ1RD8eRtCerWm'

Suppose, the encrypted employee salary field value were tampered with another employee salary (for example, with CEO salary encrypted value) stored in the same table.

ID | First Name | Last Name | Email | Position | Salary (Encrypted)
1, 'John', 'Smith', '[email protected]', 'CEO', 'ZHNmNDNnYWRmZzQ1MjR2NDJmMjRm'
....
999, 'Joe', 'Doe', '[email protected]', 'Software Engineer', 'ZHNmNDNnYWRmZzQ1MjR2NDJmMjRm' <-- Tampered with CEO salary

Result: Now the employee has the salary as the CEO has.

PoC

The solution is to use authenticated encryption. Demonstration and PoC of the solution may be found here: https://github.com/rusakovichma/authenticated-persistence-poc/blob/master/src/test/java/com/github/rusakovichma/persistance/authenticated/poc/controller/PersistenceSalaryTamperingAttack.java

        @Sql({"classpath:schema_h2_cleaning.sql", "classpath:schema_h2_salary_tampering.sql"})
        @Test
        public void testGetEmployee() {
            Employee ceoEmployee = restTemplate.getForObject(String.format("http://localhost:%d/employees/1", port), Employee.class);
            assertEquals(99999, (int) ceoEmployee.getSalary());
            assertNull(ceoEmployee.getSalaryEncrypted());
            assertNull(ceoEmployee.getNonce());

            ResponseEntity<Employee> devEmployee = restTemplate.getForEntity(String.format("http://localhost:%d/employees/999", port), Employee.class);
            //Tampering detected -> INTERNAL_SERVER_ERROR
            assertEquals(HttpStatus.INTERNAL_SERVER_ERROR.value(), devEmployee.getStatusCodeValue());
        }

authenticated-persistence-poc's People

Contributors

rusakovichma avatar

Watchers

 avatar  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.