3
$\begingroup$

I have been trying to use Go (I could post the code, but I think I posted enough already...) to generate a PGP RSA key. However every time I try to encrypt something with it, something fails. However, I can import it into gpg. I also have no idea what is failing as the error codes have not been completely helpful.

Here are the primes I used:

p=c8b177570fca7128d8631c350519c9bedd983fa3a8d044dd1671e9d9fe60af71fbf4c9bd5edb78d376aebb2e6b1fdf1909b75fffa4ccdc946d4f971df57b2f23e320b2a38c768f792987bae63ac8f45b3e294fc66beb9616cecf47964b2d2965f0187d37c972ff1fe28350962fdd46b77210e98e197dae0098059ad5d33621b9

and

q=cf32a7ecdf244114cec6837fe49dfe6f902decfd5076a18f25acf448a068d6119dec40e5a690c9bf61350655190b843813df74fd8dc49868ce4d33a774bbb564ee48c17b13bf7f42f0e97636b9eeb1f80d5fb1f5ec413432aad9035e1cc32a50d01a797cc213fb7191c359521809c2f7228a50906c564e768ccba67de05e90c1

Here is the key block

-----BEGIN PGP PUBLIC KEY BLOCK-----

xsBNBFVjnlIBCACibzXOLCiZiL2oyzYUaTOCkYnSUhymg3pdbfKtd4mpBa58xKBj
t1pTHVpw3Sk03wmzhM/Ndlt1AV2YhLv++83WKr+gAHFYFiCV/tnY8bx3HqvVoy8O
CfxWhw4QZK7+oYzVmJj8ZJm3ZjOC4pzuegNWlNLCUdZDx9OKlHVXLCX1iUbjdYWa
qKV6tdV8hZolkbyjedQgrpvoWyeSHHpwHF7yk4gNJWMMI5rpcssL7i6mMXb/sDzO
VaAtU5wiVducsOa01InRFf7QSTxoAm6Xy0PGv/k48M6xCALa9nY+BzlOv47jUT57
vilf4Szy9dKD0v9S0mQ+IHB+gNukWrnwtXx5ABEBAAHNFm5hbWUgKGNvbW1lbnQp
IDxlbUBpbD7CwHUEEwECACkFAlVjnlIJEINgJNgv009/AhsDAhkBBgsJCAcDAgYV
CAIJCgsEFgIDAQAAxqMIAFBHuBA8P1v8DtHonIK8Lx2qU23t8Mh68HBIkSjk2H7/
oO2cDWCw50jZ9D91PXOOyMPvBWV2IE3tARzCvnNGtzEFRtpIEtZ0cuctxeIF1id5
crfzdMDsmZyRHAOoZ9VtuD6mzj0ybQWMACb7eIHjZDCee3Slh3TVrLy06YRdq2I4
bjMOPePtK5xnIpHGpAXkB3IONxyITpSLKsA4hCeP7gVvm7r7TuQg1ygiUBlWbBYn
iE5ROzqZjG1s7dQNZK/riiU2umGqGuwAb2IPvNiyuGR3cIgRE4llXH/rLuUlspAp
o4nlxaz65VucmNbN1aMbDXLJVSqR1DuE00vEsL1AItI=
=XQoy
-----END PGP PUBLIC KEY BLOCK-----

Here is the output of pgpdump

New: Public Key Packet(tag 6)(269 bytes)
    Ver 4 - new
    Public key creation time - Mon May 25 15:12:34 PDT 2015
    Pub alg - RSA Encrypt or Sign(pub 1)
    RSA n(2048 bits) - ...
    RSA e(17 bits) - ...
New: User ID Packet(tag 13)(22 bytes)
    User ID - name (comment) <em@il>
New: Signature Packet(tag 2)(309 bytes)
    Ver 4 - new
    Sig type - Positive certification of a User ID and Public Key      packet(0x13).
    Pub alg - RSA Encrypt or Sign(pub 1)
    Hash alg - SHA1(hash 2)
    Hashed Sub: signature creation time(sub 2)(4 bytes)
            Time - Mon May 25 15:12:34 PDT 2015
    Hashed Sub: issuer key ID(sub 16)(8 bytes)
            Key ID - 0x836024D82FD34F7F
    Hashed Sub: key flags(sub 27)(1 bytes)
            Flag - This key may be used to certify other keys
            Flag - This key may be used to sign data
    Hashed Sub: primary User ID(sub 25)(1 bytes)
            Primary - Yes
    Hashed Sub: preferred symmetric algorithms(sub 11)(5 bytes)
            Sym alg - AES with 256-bit key(sym 9)
            Sym alg - AES with 192-bit key(sym 8)
            Sym alg - AES with 128-bit key(sym 7)
            Sym alg - CAST5(sym 3)
            Sym alg - Triple-DES(sym 2)
    Hashed Sub: preferred hash algorithms(sub 21)(5 bytes)
            Hash alg - SHA256(hash 8)
            Hash alg - SHA1(hash 2)
            Hash alg - SHA384(hash 9)
            Hash alg - SHA512(hash 10)
            Hash alg - SHA224(hash 11)
    Hashed Sub: preferred compression algorithms(sub 22)(3 bytes)
            Comp alg - ZLIB <RFC1950>(comp 2)
            Comp alg - BZip2(comp 3)
            Comp alg - ZIP <RFC1951>(comp 1)
    Hash left 2 bytes - c6 a3 
    RSA m^d mod n(2048 bits) - ...
            -> PKCS-1

Here is the error I get from gpg

gpg: name: skipped: unusable public key
gpg: msg: sign+encrypt failed: unusable public key

Here is a link to the PGP message format spec, OpenPGP Message Format.

Here is the pgpdump of a small key I made using gpg directly.

-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1

mI0EVWOihAEEALzwFAVWTrD0KiWCH5tX6q6QsGjlRn4IP2uj/xWsJZDNbCKm+JAe
1RvIootpW1+PNNMJlIInwUgtCjtJ9gZbGBpXeqwdSn0oYuj9X86ekXOUnZsRoPCj
RwS8kpbrvRVfhWN8hYuXFcXK2J2Ld0ZpVyJzkncpFdpAgzTPMfrO1HS5ABEBAAG0
GmdwZyBuYW1lIChjb21tZW50KSA8ZW1AaWw+iLgEEwECACIFAlVjooQCGwMGCwkI
BwMCBhUIAgkKCwQWAgMBAh4BAheAAAoJEBg8dTRwi4g5I40D/2+uUuQxa3uMrAeI
dXLaJWz3V0cl1rotfBP47apDUGbkm1HVgULJUo8Bo15Ii83ST8TUsyja3XcLutHb
IwYSWo41gEV48+NKoN6Oy3HwqBoHfH06bu0If75vdSjnZpB2dO/Ph7L9kz78gc4y
tZx4bE64MTlL2AYghZxyYpFyydjXuI0EVWOihAEEANE4UU+4iB2hMAXq93hiBzIh
AMtn/DlWbJkpdUgrjKOG6tILs28mrw9rI4PivmT7grkyNW8sa3ATsmWC1xChxGTN
T1guyh0Hhbc3Otfng2BFSWcBkPwUoNaOdrVFpP9J51IYrsQHsjbZlY45ghDBzM6t
sISfkmmFCsp0l7w/XAcvABEBAAGInwQYAQIACQUCVWOihAIbDAAKCRAYPHU0cIuI
OQ2BA/9KWqOhXZW75ac7CuJMfileZR7vRy9CkKyNG21cZtAlqftAX+m8FGdG0duU
jKHiPvjXhSfP3lmrQ7brja9LgSzkiBqQzvPW55G67nGQdUC+mqZNJNlRh+8atf9I
5nxg2i8zn6F5cLaNWz7cl27m1/mXKcH3gult1PLR4PiYLiC9aw==
=xw3e
-----END PGP PUBLIC KEY BLOCK-----

and the dump:

Old: Public Key Packet(tag 6)(141 bytes)
    Ver 4 - new
    Public key creation time - Mon May 25 15:30:28 PDT 2015
    Pub alg - RSA Encrypt or Sign(pub 1)
    RSA n(1024 bits) - ...
    RSA e(17 bits) - ...
Old: User ID Packet(tag 13)(26 bytes)
    User ID - gpg name (comment) <em@il>
Old: Signature Packet(tag 2)(184 bytes)
    Ver 4 - new
    Sig type - Positive certification of a User ID and Public Key packet(0x13).
    Pub alg - RSA Encrypt or Sign(pub 1)
    Hash alg - SHA1(hash 2)
    Hashed Sub: signature creation time(sub 2)(4 bytes)
            Time - Mon May 25 15:30:28 PDT 2015
    Hashed Sub: key flags(sub 27)(1 bytes)
            Flag - This key may be used to certify other keys
            Flag - This key may be used to sign data
    Hashed Sub: preferred symmetric algorithms(sub 11)(5 bytes)
            Sym alg - AES with 256-bit key(sym 9)
            Sym alg - AES with 192-bit key(sym 8)
            Sym alg - AES with 128-bit key(sym 7)
            Sym alg - CAST5(sym 3)
            Sym alg - Triple-DES(sym 2)
    Hashed Sub: preferred hash algorithms(sub 21)(5 bytes)
            Hash alg - SHA256(hash 8)
            Hash alg - SHA1(hash 2)
            Hash alg - SHA384(hash 9)
            Hash alg - SHA512(hash 10)
            Hash alg - SHA224(hash 11)
    Hashed Sub: preferred compression algorithms(sub 22)(3 bytes)
            Comp alg - ZLIB <RFC1950>(comp 2)
            Comp alg - BZip2(comp 3)
            Comp alg - ZIP <RFC1951>(comp 1)
    Hashed Sub: features(sub 30)(1 bytes)
            Flag - Modification detection (packets 18 and 19)
    Hashed Sub: key server preferences(sub 23)(1 bytes)
            Flag - No-modify
    Sub: issuer key ID(sub 16)(8 bytes)
            Key ID - 0x183C7534708B8839
    Hash left 2 bytes - 23 8d 
    RSA m^d mod n(1023 bits) - ...
            -> PKCS-1
Old: Public Subkey Packet(tag 14)(141 bytes)
    Ver 4 - new
    Public key creation time - Mon May 25 15:30:28 PDT 2015
    Pub alg - RSA Encrypt or Sign(pub 1)
    RSA n(1024 bits) - ...
    RSA e(17 bits) - ...
Old: Signature Packet(tag 2)(159 bytes)
    Ver 4 - new
    Sig type - Subkey Binding Signature(0x18).
    Pub alg - RSA Encrypt or Sign(pub 1)
    Hash alg - SHA1(hash 2)
    Hashed Sub: signature creation time(sub 2)(4 bytes)
            Time - Mon May 25 15:30:28 PDT 2015
    Hashed Sub: key flags(sub 27)(1 bytes)
            Flag - This key may be used to encrypt communications
            Flag - This key may be used to encrypt storage
    Sub: issuer key ID(sub 16)(8 bytes)
            Key ID - 0x183C7534708B8839
    Hash left 2 bytes - 0d 81 
    RSA m^d mod n(1023 bits) - ...
            -> PKCS-1

I tried making a new key in gpg and comparing the gpgdump. It seemed like the biggest difference is the order of the hashed packets (which from what I could tell from the spec doesn't matter) and the subkeys (which also seemed like it shouldn't matter from the spec).

I hope I am just missing something obvious from the spec and have been looking at the wrong things. If anyone knows anything about the PGP specification that I am missing it would be very appreciated.

$\endgroup$

1 Answer 1

5
$\begingroup$

I think your key doesn't work, because it is only a signature key. That's subpacket 27, for which pgpdump says:

Hashed Sub: key flags(sub 27)(1 bytes)
        Flag - This key may be used to certify other keys
        Flag - This key may be used to sign data

The corresponding output of gpg -vv mykey.pub is

:signature packet: algo 1, keyid 836024D82FD34F7F
        hashed subpkt 27 len 1 (key flags: 03)

RFC4880 section 5.2.3.21 states that for a key to be used as encryption key the 2nd or 3rd bits must be set, too:

0x04 - This key may be used to encrypt communications.
0x08 - This key may be used to encrypt storage.

and further notes that the definition of "communication" or "storage" is not part of the RFC, so that "This decision is left wholly up to the implementation". In practice, keys used for encryption by gpg usually have both set, a typical encryption subkey looks like this:

    hashed subpkt 27 len 1 (key flags: 0C)

Also, the default in gpg --gen-key is to create a signature key with 0x03 and an encryption subkey with 0x0C, an example you might want to follow.

$\endgroup$
1
  • $\begingroup$ Thanks for the detailed response! I knew I was missing something. Setting the flags worked. I will also look into using subkeys, but for my purpose I don't know if it's totally necessary. If I had more reputation I would give you an upvote. $\endgroup$
    – Travis
    May 29, 2015 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.