[Autocrypt] How to create the "raw key" part from an RSA key

Bjoern b44treader at googlemail.com
Wed May 17 16:39:17 EDT 2017


Hi Daniel,

thank you very much, this helped me.

In fact, OpenSSL does not support PGP directly, but with a little bit
of code around, it works, see http://www.netpgp.com/ from BSD -
unfortunately, the project seems to be dead.

Regarding the key:

OpenSSL's PEM_write_bio_PUBKEY() returns ASCII-key as

-----BEGIN PUBLIC KEY-----
base64, typically starting with "MIIB"
-----END PUBLIC KEY-----

while PGP want the ASCII-key as

-----BEGIN PGP PUBLIC KEY BLOCK-----
Vesion ...

base64, same as above plus a little header, starting eg. with "mQI"
 -----END PGP PUBLIC KEY BLOCK-----

Autocrypt expects the base64 stuff only then.

Which Net::PGP do you mean? In fact, it is not easy to find a
_library_ for the PGP stuff. PEP is mainly based upon PGPME which is
based upon GnuPG ... and GnuPG is an app, no library. So, lots of
technical problems. But there are also GnuPG licencing problems, see
eg. https://lists.gt.net/gnupg/users/52980#52980 ...


On Wed, May 17, 2017 at 4:57 AM, Daniel Kahn Gillmor
<dkg at fifthhorseman.net> wrote:
> Hi Bjoern--
>
> On Tue 2017-05-16 13:13:01 +0200, Bjoern wrote:
>> I'm just about to add AutoCrypt to Delta Chat.
>
> great!
>
>> I'm creating the key pair using the following code:
>>
>>     // generate key
>>     BIGNUM*       e   = BN_new();
>>     RSA*          rsa = RSA_new();
>>
>>     BN_set_word(e, 65537);
>>     if( RSA_generate_key_ex(rsa, 2024, e, 0) != 1 ) {
>>         goto cleanup;
>>     }
>>
>>     //  convert RSA key to PUBLIC KEY
>>     EVP_PKEY* pkey = EVP_PKEY_new();
>>     EVP_PKEY_set1_RSA(pkey, rsa);
>>
>> now I can get the keys as `-----BEGIN PUBLIC KEY----- ...` and
>> `-----BEGIN RSA PRIVATE KEY----- ...` using
>>
>> PEM_write_bio_PUBKEY(bio1, pkey);
>>
>> and
>>
>> PEM_write_bio_RSAPrivateKey(bio2, rsa, NULL, NULL, 0, NULL, NULL);
>
>
> these forms are for "raw" public keys or private keys.  the autocrypt
> type=p (the only defined type) is an OpenPGP certificate, which means:
>
>  * it has two keys involved -- a primary and a subkey, which are bound
>    to one another cryptographically
>  * it has a user ID associated with (and cryptographically bound to) the
>    primary key
>  * it has some structure and framing around it
>
> (all these details are described in detail in RFC 4880).
>
> I don't think that OpenSSL supports any OpenPGP framing natively.
> However, i think that Net::PGP is a layer on top of OpenSSL which ought
> to be able to build the associated packets.  this is what PEP is using,
> i think, though i don't really understand their licensing model (i've
> asked Hernani from PEP about the interaction between the OpenSSL license
> and the GPL license that they intend to use for Net::PGP, and never got
> a clear response).
>
> Also, it looks like you're asking for a 2024-bit key -- we recommend
> 2048-bit or higher!
>
>          --dkg



More information about the Autocrypt mailing list