API Security: Keeping Data Private but Accessible
API Security: Keeping Data Private but Accessible
Nial Darbey discusses methods of how we can keep data private and protect it from being compromised while making it accessible anytime.
Join the DZone community and get the full member experience.Join For Free
The State of API Integration 2018: Get Cloud Elements’ report for the most comprehensive breakdown of the API integration industry’s past, present, and future.
This post is part two of three of my ultimate guide to API security best practices series. In this post, I will be discussing confidentiality, integrity, and availability of data. In essence, methods of how we can keep data private and protect it from being compromised while making it accessible anytime.
2. Confidentiality, Integrity, and Availability
2.1 Message Integrity
Message Integrity goes beyond the authentication of the app and the user and includes the verification that the Message was not compromised mid-flight by a malicious third party. In other words, the Message received by your API is verified as being exactly the one sent by the app. The same goes for when your API acts as Client to a Server.
2.1.1 Digital Signatures
We humans sign all kinds of documents when it matters in the civil, legal, and even personal transactions in which we partake. It is a mechanism that we use to record the authenticity of the transaction. The digital world mimics this with its use of Digital Signatures. The idea is for the app to produce a signature by using some algorithm and a secret code. Your API should apply the same algorithm with a secret code to produce its own signature and compare the incoming signature against this. If the two match, the API has effectively completed authentication by guaranteeing not only that this message was sent by a known app (only a known app could have produced a recognizable signature), but that it has maintained its integrity because it was not modified by a third party while in transit. As an added benefit for when it matters with third party apps, the mechanism also brings non-repudiation into the equation because neither the app nor the user can claim not to have sent the signed message.
2.1.2 Message Safety
Even when you know that your API has been invoked by an authenticated app and user and the message has arrived with its integrity guaranteed, you still need to protect against any potentially harmful data in the request. These attacks often come in the form of huge XML documents with multiple levels of nested elements. JSON documents may also contain huge nested objects and arrays.
2.2 Message Confidentiality
It is all very well to rest assured with the integrity of a message sent by a known app, but the journey from app to API may have been witnessed by some unwelcome spies who got to see all of those potentially very private details inside the message! Thus, it is necessary to hide those details from the point of delivery by the app to the reception by the server. An agreement is needed between the app and API in order to be able to hide the details of the message in a way that allows only the API to uncover them and vice versa.
2.2.1 Public Key Cryptography
The age old practice of cryptography has made a science of the art of hiding things! IT has adopted this science and can produce an encryption of the message that is practically impossible to decrypt without a corresponding key to do so. It is as if the Client had the ability to lock a message inside some imaginary box with a special key, hiding it from prying eyes until the server unlocks the box with its own special key. Digital signing, discussed above, produces signatures in this very way. Cryptography comes in two forms: symmetric, when both client and server share the same key to encrypt and decrypt the message; and asymmetric, when the server issues a public key to the client allowing the client to encrypt the message, but keeps a private key which is the only one that can decrypt the message: one key to lock the message and another key to unlock it!
2.2.2 Digital Certificates
Digital Certificates are a means to facilitate the secure transport-level communication (TLS) between a client and a server over a network in such a way that the server can authenticate itself to the client. This is made possible because the certificate binds information about the server with information about the business which owns the server and the certificate is digitally signed by a certificate authority which the client trusts.
2.2.3 Mutual Authentication with Digital Certificates
In most cases, it is the server that authenticates itself with the client. However, there are also scenarios in which the server demands the authentication of the client. The server requests the client certificate during the TLS handshake over the network. One thing to keep in mind is that the server controls whether client authentication occurs; a client cannot ask to be authenticated.
Mutual authentication with TLS certificates is ideally suited to the type of system to system communication that you see when your API acts as a client to a server, whether the server is another API or a database or any other system entity. Missing from this sort of communication is the human user. Hence, the security credentials exchanged between the two parties are far easier to manage.
By utilizing TLS, your API can expose itself over HTTPS and guarantee both message integrity and confidentiality at the same time. Public keys are emitted on certificates which have been digitally signed by independent and trusted certificate authorities, thus guaranteeing that the public key was issued by your API. Once the initial handshake has been completed with the app by the exchange of messages using public and private keys, the communication switches to the more efficient symmetric form using a shared key generated just for the duration of the communication, all of which occurs transparently.
2.4 API Availability
Your API must guarantee that it is always available to respond to calls and that once it begins execution on the call, that it can finish handling the received message right the way through to completion without losing data. This can be achieved by horizontally scaling the API across multiple servers and by handing off the processing of the message to a message broker which will hold the message till the API has completed its processing. The understanding in this latter scenario is that another process is subscribed to this message publication and thus continues the processing asynchronously.
Thus it is clear that reliability is a step beyond mere availability. While an API may (through horizontal scale-out) be available to respond to all calls because a load-balancer in front of the API can propagate calls to the correct hosting server when any of the other servers are down, this still may not be enough because the API may fail mid-way through processing. In a reliable architecture, the API would receive the call and then leave a message on a message-broker queue (JMS or AMQP for example). Even when the service which has subscribed to the queue is down, the broker can hold onto the message for later consumption when the service comes back online again.
What to Expect at the End of the API Security Series
The next post will show how MuleSoft’s Anypoint Platform can ensure that your API is accessible while completely secure. You will understand the majority of security concerns and the methods to address those concerns. You will then become an expert on the topic and with MuleSoft’s Anypoint Platform to execute on these ideas and insights.
If you want to read ahead and learn more in detail about API Security, you can download the full Protect Your APIs white paper.
Published at DZone with permission of Nial Darbey , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.