Integrity Check using PGP for JMeter
Tags: performance, testing, java, security
Published: 2023-02-01 15:36:32

<!-- wp:paragraph -->
<p>This blog post is kind of back to basics. I have already clearly mentioned downloading JMeter and how to check its integrity using SHA512 algorithm in <a href="https://www.youtube.com/playlist?list=PLJ9A48W0kpRIjLkZ32Do9yDZXnnm7_uj_" target="_blank" rel="noreferrer noopener">this demo</a>. In this blog post, we are going to learn about integrity checks using PGP mechanism.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>What is PGP? </h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>PGP stands for Pretty Good Privacy. It is a popular data encryption and decryption computer program that provides cryptographic privacy and authentication for data communication. PGP was created by Phil Zimmermann in 1991, and it is widely used for secure email communication and file encryption. The term PGP is often used interchangeably with OpenPGP, which is the open standard that PGP is based on.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>How it works?</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>PGP is like a special secret code that you can use to protect your important messages and files. It makes sure that only the people you want to read your messages or see your files can do so. Think of it like a lock on a treasure box, only those with the key can open it. When you use PGP, you have a secret key that only you know, and you also have a key that you share with others. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>This way, people can send you messages and files that only you can read, and you can also show others that the messages and files you send are really from you.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>How it works?</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>PGP works by using a combination of public-key cryptography and symmetric-key cryptography to provide secure data communication and file encryption.</p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><!-- wp:list-item -->
<li>Key pair generation: It generates two keys, a public key and a private key. You share your public key with others, while you keep your private key secret.</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Encryption: When someone wants to send you an encrypted message or file, they use your public key to encrypt it. The encrypted message or file can only be decrypted with your private key.</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Decryption: You use your private key to decrypt the encrypted message or file and read its contents.</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Signing: You can also use your private key to "sign" a message or file, to prove that it came from you. Anyone can use your public key to verify the signature and confirm that the message or file was indeed sent by you.</li>
<!-- /wp:list-item --></ol>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>In short, PGP enables secure communication and file storage by encrypting them and making sure only the intended recipient can access them. The process of encryption, decryption, and signing is similar to that of GPG, as both PGP and GPG are based on the OpenPGP standard.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Focus on the point four <code>signing</code> part. Signing in PGP works by using your private key to create a digital signature for a message or file. The signature acts as a proof of authenticity, verifying that the message or file came from you and has not been altered.</p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><!-- wp:list-item -->
<li>Hash generation: A hash of the message or file is generated, which is a unique representation of its contents.</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Signing: Your private key is used to encrypt the hash, creating a digital signature. The signature is then attached to the message or file.</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Verification: The recipient of the signed message or file can use your public key to verify the signature by generating a new hash from the received message or file, and comparing it to the decrypted signature.</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Validation: If the generated hash and decrypted signature match, it means the message or file is authentic and has not been altered, and the signature is considered valid.</li>
<!-- /wp:list-item --></ol>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>In short, signing in PGP provides a way to verify the authenticity of a message or file by creating a digital signature with your private key that can be verified by others using your public key.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>JMeter GPG Keys</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Now, we have equipped ourselves with the basic knowledge about GPG and how it works. Let us see the GPG keys for JMeter.</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><!-- wp:list-item -->
<li>Head to https://jmeter.apache.org/download_jmeter.cgi</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Click on the <code><a href="https://downloads.apache.org/jmeter/KEYS" target="_blank" rel="noreferrer noopener">KEYS</a></code> link to view the official GPG keys.</li>
<!-- /wp:list-item --></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>The above key link will list out PGP keys of various developers. You can also see their email ID. There is no need to email them unless there is a need.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>You can also see their public key block and the PGP version.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Steps to check the integrity</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The following are the prerequisites which are required to verify the integrity of any file, in this case JMeter. </p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><!-- wp:list-item -->
<li>Download JMeter from the downloads page</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Import the official JMeter keys</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Install <code>gpg</code></li>
<!-- /wp:list-item --></ol>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>In this example, I have used my Linux system to demonstrate.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Install gpg using <code>sudo apt install gpg</code> </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Once it is installed, verify the installation using <code>gpg --version</code></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The next step is to download the JMeter file. Issue <code>wget https://dlcdn.apache.org//jmeter/binaries/apache-jmeter-5.5.tgz</code> in the terminal which will download JMeter 5.5 in the current directory.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>To import the PGP keys, issue the below command.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><code>wget https://downloads.apache.org/jmeter/KEYS -O - | gpg --import -</code></p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":9894,"sizeSlug":"large","linkDestination":"media"} -->
<figure class="wp-block-image aligncenter size-large"><a href="https://qainsights.com/wp-content/uploads/2023/01/image-3.png"><img src="https://qainsights.com/wp-content/uploads/2023/01/image-3-1024x379.png" alt="Download Keys" class="wp-image-9894"/></a><figcaption class="wp-element-caption">Download Keys</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Once the keys are imported, the next step is to download the PGP file from JMeter downloads page as shown below.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":9895,"sizeSlug":"full","linkDestination":"media"} -->
<figure class="wp-block-image aligncenter size-full"><a href="https://qainsights.com/wp-content/uploads/2023/01/image-4.png"><img src="https://qainsights.com/wp-content/uploads/2023/01/image-4.png" alt="Download PGP" class="wp-image-9895"/></a><figcaption class="wp-element-caption">Download PGP</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Or you can use the below command.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><code>wget https://www.apache.org/dist/jmeter/binaries/apache-jmeter-5.5.tgz.asc</code></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>To verify the JMeter PGP signature, cat it out.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><code>cat apache-jmeter-5.5.tgz.asc</code></p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":9896,"sizeSlug":"full","linkDestination":"media"} -->
<figure class="wp-block-image aligncenter size-full"><a href="https://qainsights.com/wp-content/uploads/2023/01/image-5.png"><img src="https://qainsights.com/wp-content/uploads/2023/01/image-5.png" alt="PGP Signature" class="wp-image-9896"/></a><figcaption class="wp-element-caption">PGP Signature</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>It is time to verify the integrity using PGP. Issue the below command to validate. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><code>gpg --verify apache-jmeter-5.5.tgz.asc apache-jmeter-5.5.tgz</code></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>You will see the below output stating that the key is not certified with a trusted signature.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":9897,"sizeSlug":"full","linkDestination":"media"} -->
<figure class="wp-block-image aligncenter size-full"><a href="https://qainsights.com/wp-content/uploads/2023/01/image-6.png"><img src="https://qainsights.com/wp-content/uploads/2023/01/image-6.png" alt="Not certified" class="wp-image-9897"/></a><figcaption class="wp-element-caption">Not certified</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>That is fine. Let us fix it. All you need is to edit the key and trust them. To edit the key, issue the below command.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><code>gpg --edit-key &lt;key_you_want_to_trust&gt;</code></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>In the https://downloads.apache.org/jmeter/KEYS, grab one of the keys from the trusted developers and add theirs into the above command.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><code>gpg --edit-key 0612B399</code></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><code>0612B399</code> key belongs to Milamber. Hit enter. You have to choose the developer who actually signed and from a trusted source. You will get the below options.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":9900,"sizeSlug":"full","linkDestination":"media"} -->
<figure class="wp-block-image aligncenter size-full"><a href="https://qainsights.com/wp-content/uploads/2023/01/image-9.png"><img src="https://qainsights.com/wp-content/uploads/2023/01/image-9.png" alt="Trust" class="wp-image-9900"/></a><figcaption class="wp-element-caption">Trust</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Enter <code>trust</code> and hit enter. Then, select the appropriate options. To complete trust, enter <code>5</code>, followed by <code>y</code> and then hit enter.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Type <code>quit</code> to exit out of the options.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Now, if you verify the integrity again, it will display the below details. The output must show <code>Good signature</code> and the Primay key fingerprint.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":9901,"sizeSlug":"full","linkDestination":"media"} -->
<figure class="wp-block-image aligncenter size-full"><a href="https://qainsights.com/wp-content/uploads/2023/01/image-10.png"><img src="https://qainsights.com/wp-content/uploads/2023/01/image-10.png" alt="" class="wp-image-9901"/></a><figcaption class="wp-element-caption">Integrity Check using PGP for JMeter</figcaption></figure>
<!-- /wp:image -->

<!-- wp:heading -->
<h2>Conclusion</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>It is vital to check the integrity in your CI/CD pipeline either using SHA512 sum or PGP for any software, not just JMeter. Always download from the trusted source and verify the primary key twice. Otherwise, rogue actors will exploit the system by installing back doors, and more.</p>
<!-- /wp:paragraph -->