I'm looking at a software project where the GPG public keys of the maintainers are found on a website using HTTP. According to the GNU Privacy Handbook, "The signature is verified using the corresponding public key." So what I'm wondering is, can an attacker encrypt a malicious payload, using a MITM attack on the project website and serving their own public keys?

Don't the public keys used for verification have to be transmitted securely as well?

  • Not Required to transmit securely. He cant forge your signature even if he does MITM.
    – Sravan
    Mar 19, 2016 at 22:07
  • But, he can completely replace it - doesn't that nullify the signature's useful properties?
    – nc.
    Mar 19, 2016 at 22:25
  • Yes he can replace it with his own signature. But not of yours. Digital signatures cannot be copied from one document to other document. He cant even tamper successfully Have a look at en.wikipedia.org/wiki/Digital_signature#Integrity
    – Sravan
    Mar 20, 2016 at 3:07

2 Answers 2


No. The keys does not need to be transmitted securely, but of course you must transmit them in a such way so they can't be replaced or tampered with, if you want to protect against someone distributing malicious data.

So lets say you are hosting a software repository. Even if you sign a software with your key, if a hacker gains access to the repository, he could upload malicious software AND also replace the "correct" signing keys with her own public keys, so if a end user validates the software, it will come out as valid. That is what the OP is asking.

In the same way, a attacker could replace keys during transmission (MITM attack), so if a user does http://www.example.org/signing_key.asc the MITM can replace the response with his own public key.

So simple signing of software and publishing the key on the software vendor's site, is more aimed to protect against mirrors getting hacked and starting to distribute malicious data. Thats why some vendors just publish the SHA/MD5 hash of the software, thus the vendor does not need to completely rely on the security of the third-party mirror's.

Thats why its a good idea to transmit the keys using SSL, or have the key signed by a reputable origin (then it becomes a certificate, could be either a x509 one or a PGP one) if you also want to protect against malicious public key replacement.

Another way to protect against this, is that the end user does download and save the key during first interaction. Thus, if the repository later become compromised, the end user will have a saved "correct key", thus it does not matter if the key later become replaced, either during a MITM or hack attack.


Sebastian gave a great answer, but I also wanted to point out that your problem outlines exactly why you want to build a Web of Trust (https://en.m.wikipedia.org/wiki/Web_of_trust) signing other's PGP keys and having them sign yours.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .