April 8, 2015
Matthew Hall

Secure Credential and Certificate Management for Data Pipelines

<p><strong><em>Authors:  Matthew Hall, Brian Waskiewicz, and Mike Forgione</em></strong></p><p>Threat intelligence feeds and other sensitive data pipelines found in many contexts make use various different Authentication methods to protect data when transferred or at rest.</p><p>Some examples of these methods are:</p><ol><li><p>Totally Unauthenticated</p></li><li><p>Unique / Secret HTTP file path</p></li><li><p>Proprietary HTTP Headers</p></li><li><p>Proprietary Login APIs</p></li><li><p>HTTPS with HTTP Basic Authentication</p></li><li><p>HTTPS / SSL/TLS with Client Certificate (and Private Key)</p></li><li><p>SSH / SCP / SFTP / RSYNC Private Keys</p></li></ol><p>The wide range of authentication complicates the secure software development process. One must consider the TLP (Traffic Light Protocol) restrictions, cryptographic best practices (such as PCI or FIPS requirements), and system hardening (such as NIST recommendations), to create a secure solution.</p><h2>Secure Credential Storage</h2><p>The most secure methods for accessing sensitive data, such as HTTP Basic Authentication and TLS Client Certificates, or SSH infrastructure, require secure credential storage to allow automated access to a data pipeline.</p><p>Secure credential storage consists of:</p><ol><li><p>a keystore, which is an encrypted file or database managed by a security library. A FIPS-compliant keystore does not allow direct access to keying material to protect the credentials during use.</p></li><li><p>a passphrase, which is stored in a separate location from the keystore, itself, to protect the credentials at rest.</p></li></ol><p>When these requirements are met, it greatly complicates the process of credential exposure and/or exfiltration, or in the case of a hardware implementation, can potentially guarantee exfiltration is impossible.</p><h2>Common Implementation Issues</h2><p>Sadly, most popular software development reference sites, such as StackOverflow, Github projects, open-source code, programing language API guides, etc. recommend some or all of a series of common unsafe practices, which will increase the risk of compromise as well as making it difficult to certify for PCI and FIPS compliance:</p><ol><li><p>Storing credentials in source control or source code repositories: adversary groups regularly take advantage of credentials and certificates located in source code checked out on compromised endpoints, and use it to fan out and infiltrate critical security and operations infrastructure at large target organizations.</p><p>Database credentials were stolen from a GitHub repository and used to exfiltrate personal information regarding 50,000 Uber drivers:</p><p><a href="http://arstechnica.com/security/2015/03/in-major-goof-uber-stored-sensitive-database-key-on-public-github-page/">Uber Database Credential Theft</a></p><p>An Adobe code signing certificate was stolen and used to sign malware. Users were tricked into installing the malware, because it appeared to come from Adobe:</p><p><a href="http://blogs.adobe.com/security/2012/09/inappropriate-use-of-adobe-code-signing-certificate.html">Adobe Code Signing Certificate Theft</a></p></li><li><p>Passing credentials as command line arguments: credentials in command lines are accessible to anyone who can execute "ps auxww" on a system, including the cracker that happened to find a shell-injection attack against your web server or web stack, and any other unexpected unprivileged users.</p><p>There are a few programs which overwrite the arguments or retitle themselves with <code>setproctitle()</code> after reading the credentials, but it isn&#39;t a complete guarantee since a patient adversary can still catch them in the clear early in the process&#39;s life, or by disrupting or slowing the process during launch.</p></li><li><p>Storing certificates and private keys in unsafe formats: unprotected certificates and private keys are easily accessible to anyone who can read them from the filesystem. Many daemons load them as root before dropping privileges, but often retain access after privileges are dropped, to use them during processing, where an attacker can access them if the daemon is exploitable.</p><p>This happens often in HTTPS servers and SSH environments.</p><p>Most of the classic HTTPS servers don&#39;t support keystores, or require entering passwords during boot, which is cumbersome. SSH agents are hard to configure, and don&#39;t have good support for headlessly entering the passphrases needed for automated access.</p><p>For SSH at least, one can use some special extensions to the <code>authorized_keys</code> file format to restrict the purpose and scope of headless SSH keys to prevent misuse. This is explained in the <code>sshd(8)</code> man page section, <code>AUTHORIZED_KEYS FILE FORMAT</code>.</p><p><a href="http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man8/sshd.8"><code>sshd(8)</code> man page</a></p></li><li><p>Disabling critical SSL/TLS protections for data in transit: most widely-available example code and a lot of open-source code disables SSL/TLS hostname verification and SSL/TLS certificate path validation, as defined in RFC 5280, which should never be disabled in production systems. Data that transfers through unvalidated connections is vulnerable to MITM attacks, thus it cannot be trusted anymore:</p><p><a href="http://www.rfc-editor.org/rfc/rfc5280.txt">RFC 5280: PKIX (Public Key Infrastructure for X.509)</a></p></li></ol><h2>Mitigating the Risks</h2><p>Running software that relies upon unsafe code is a security risk and a liability risk, as well as a business risk. It also cannot be sold to the US Government and many highly-security-conscious organizations. Fortunately, the industry developed a small number of platform-independent techniques for secure credential storage to mitigate these risks:</p><ol><li><p><code>libnss</code> with <code>nss-db</code> and <code>libsecmod</code>: this is the only popular open-source multi-language multi-platform cryptography and SSL/TLS library with an integrated FIPS-compliant keystore. OpenSSL, GnuTLS and most other libraries do not offer much assistance with these requirements. Because of this <code>libnss</code> is widely used in browsers.</p><p><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS">NSS Library Home Page</a></p><p>Several technology vendors have banded together to ensure libnss is FIPS-validated:</p><p><a href="https://wiki.mozilla.org/FIPS_Validation">NSS Library FIPS Validation</a> <a href="http://csrc.nist.gov/groups/STM/cmvp/documents/140-1/140crt/140crt1280.pdf">NSS Library FIPS Certificate</a></p><p>Developers can also use NSS bindings available for Java (see below) and Python. We would love to know if anyone is aware of additional bindings.</p></li><li><p>Java <code>PKCS#11</code> provider (includes support for NSS and smartcard / HSM): this is the gold standard for high-security operations in Java. This includes any of the following:</p><ul><li>Tomcat, JBoss, Glassfish, Grizzly, or other J2EE servers</li><li>JCE, JSSE, Bouncy Castle and other popular cryptographic frameworks</li><li>any other JVM-based environments (Groovy, Scala, Jython, JRuby, etc.)</li></ul><p><a href="http://docs.oracle.com/javase/8/docs/technotes/guides/security/p11guide.html">Oracle Java 8 PKCS#11 Guide</a></p><p>Developers can use this adapter with NSS or another FIPS-certified <code>PKCS#11</code> device to get a FIPS-certified solution.</p></li><li><p><code>PKCS#12</code> cryptographic archive file format: this format is not necessarily as heavily-secured and feature-rich as the other formats, but still provides great protection and works in the widest range of environments, because it has been around the longest.</p></li></ol><h2>Practical Example</h2><p>Recently, we needed to access a data pipeline which used a <code>PKCS#12</code> containing an SSL/TLS Client Certificate and Private Key, from inside of a Python application.</p><p>We decided to use <code>pycurl</code> because we had existing products that used it, so it was simpler than using NSS, and it provided sufficient security for the type of data pipeline we were building.</p><p>Fortunately, <code>pycurl</code> can be configured to access a <code>PKCS#12</code> keystore with a passphrase protecting the Client Certificate and Private Key. However the configuration and troubleshooting process was somewhat difficult due to a usability bug in <code>libcurl</code> itself, which we fixed and released to the community:</p><p><a href="https://github.com/bagder/curl/pull/208"><code>curl</code> pull request to improve <code>PKCS#12</code> errors</a></p><p>When troubleshooting our code sample sample below, we found that three different failure points in the <code>PKCS#12</code> load process used the same non-specific error message, <code>unable to use client certificate (no key found or wrong pass phrase?)</code>. This made it difficult to determine the true cause of a failure in the <code>PKCS#12</code> initialization process. In our patch we added separate messages for each, and logic to retrieve a more detailed error from inside OpenSSL itself for more detail.</p><p>This code sample loads a <code>PKCS#12</code> file in <code>pycurl</code>, and uses the credentials to access a target URL:</p><pre> <code>import cStringIO import pycurl request = pycurl.Curl() response = cStringIO.StringIO() request.setopt(pycurl.URL, request_url) request.setopt(pycurl.SSLCERTTYPE, "P12") request.setopt(pycurl.SSLCERT, pkcs12_file_path) request.setopt(pycurl.SSLKEY, pkcs12_file_path) request.setopt(pycurl.SSLKEYPASSWD, pkcs12_file_passphrase) request.setopt(pycurl.WRITEFUNCTION, response.write) request.perform() </code></pre><h2>Conclusion</h2><p>We encourage everyone to take a little time to think about the sensitive data in a system while it is in transit, in use, or at rest. We enjoy working with the security and technology industry to set good examples, and educate developers about safe ways to handle sensitive credentials. We will keep encouraging everyone to build data pipelines that are secure by default.</p>

Get the Latest Anomali Updates and Cybersecurity News – Straight To Your Inbox

Become a subscriber to the Anomali Newsletter
Receive a monthly summary of our latest threat intelligence content, research, news, events, and more.