Pushing technology the hard way (Part4)

This blog is about creating a demo application using the open-source data database immudb. As described in previous blog series our backend is running on kubernetes. The huge advantage of immudb is combining immutability with scalability. It is capable to process up to 1,6 Mio writes per second with verification. A great use case should take advantage of that.

Finding a use case in organizations

Large organization have a lot of guide lines in place that will restrict the project quite a bit. For example you get some specific recommendations for the technology that you should use to develop your app. In this case spring boot is the standard for developing backend services. Luckily immudb has integrations for almost all widely used programming languages. Building our app will be much easier using the immudb integration immudb4j. Simply add the dependency to your pom.xml:

<dependency>  
 <groupId>io.codenotary</groupId>  
 <artifactId>immudb4j</artifactId>  
 <version>0.9.0.6</version>  
</dependency>

Now that we know our technology stack, we have to look out for a proper use case. While looking into the services for tax consultants I found something interesting. Tax consultants are uploading receipts, many thousands receipts. They have to be processed up to a certain deadline and should never be changed/manipulated. immudb would be the perfect database for that.

What do we need

To replicate that service we need to be able to upload files and store them or their hash in immudb. The app has to support uploading, file metadata extraction, notarization and a verification service.

Technical Details

Uploading files is very good described at this example: Uploading files with Spring MVC. It is almost exactly what we need. We just have to add hash generation for the file metadata.

File file = new File(url);  
MessageDigest shaDigest = MessageDigest.getInstance("SHA-256");  
this.shaChecksum = getFileChecksum(shaDigest, file);

Now the filename and the hash as a key has to be saved in immudb. While working on a slow lab system, we found out about session pooling. Using immudb4j we can create gRPC Sessions. Our app will create some sessions and assign them to requests. The requests are giving their sessions back into the pool when they are finished. That boosted performance quite a bit. The session pooling was developed by following this guide.

public class ImmudbConnectionPool
implements ConnectionPool {

    private String url;
    private String user;
    private String password;
    private List < ImmuClient > connectionPool;
    private List < ImmuClient > usedConnections = new ArrayList < > ();
    private static int INITIAL_POOL_SIZE = 2;
    private static int MAX_POOL_SIZE = 20;

    private ImmudbConnectionPool(String url, String user, String password, List < ImmuClient > pool) {
        this.connectionPool = pool;
        this.url = url;
        this.user = user;
        this.password = password;
    }

    public static ImmudbConnectionPool create(
        String url, String user,
        String password) throws IOException {
        List < ImmuClient > pool = new ArrayList < > (INITIAL_POOL_SIZE);
        for (int i = 0; i < INITIAL_POOL_SIZE; i++) {
            pool.add(createConnection(url, user, password));
        }
        return new ImmudbConnectionPool(url, user, password, pool); //url, user, password, pool  
    }

Using sessions from the pool will be invoked by requests from the home controller of our Spring Boot app. We will save the hash of the file as key and the name as value. Of Course we could add more information in the value section but that’s it for the demo:

// Obtaining a connection
ImmuClient attestClient = connectionPool.getConnection();  
attestClient.useDatabase("test");
// Setting (adding) a key-value.  
attestClient.set(key, name.getBytes());  
// Getting it back, by key (in a verified way  
// that reports any tampering if it happened).  
Entry entry = attestClient.verifiedGet(key);
// Releasing a connection
connectionPool.releaseConnection(attestClient);

The tax receipts hash is now stored immutably in immudb and they can be verified by querying with the hash of a file. Changes made to the receipts can be immediately recognized. Manipulating immudb in order to hide evidence is not possible without detection either.

Summary

This is the final of the Pushing technology blogs. We started a project to promote innovation. Installed the fastest immutable database in kubernetes. Created a demo application and presented the project. Here are the things learned from it: essentially fellow employees in your rank will always be the most skeptical. It takes a lot of courage to promote something you believe in. It is a long and hard way with slim chances of quick results. Atleast most executives will appreciate initiative and courage in their staff. Timing is very important for innovation. Even if your project isn’t an immediate success, it might be in some weeks, months or years.

RELATED ARTICLES

CNIL Metrics & Logs

Self-Hosted performance monitoring and compliant log analysis for VMware vSphere, container and much more.

immudb

Built on the fastest immutable ledger technology. Open Source and easy to use and integrate into existing application.

Codenotary Cloud

Trusted CI/CD, SBOM and artifact
protection with cryptographic proof.
One CLI to manage all.

Subscribe to Our Newsletter

Get the latest product updates, company news, and special offers delivered right to your inbox.
Share on twitter
Share on linkedin
Share on facebook
Share on email

Subscribe to our newsletter

White Paper — Registration

We will also send you the research paper
via email.

CodeNotary — Webinar

White Paper — Registration

Please let us know where we can send the whitepaper on CodeNotary Trusted Software Supply Chain. 

Become a partner

Start Your Trial

Please enter contact information to receive an email with the virtual appliance download instructions.

Start Free Trial

Please enter contact information to receive an email with the free trial details.