1

Is it possible to read entity details like name/comment and email from a given armored private / public key using golang openpgp package ?

The following code implements a test that generate a new armored key pair, it then tries to get entity details from it.

However the resulting entity does not contain any identity information.

package main

import (
    "log"
    "testing"

    "github.com/jchavannes/go-pgp/pgp"
    "golang.org/x/crypto/openpgp"
)

func TestID(t *testing.T) {
    keypair, err := pgp.GenerateKeyPair("test", "tst comment", "test@email.com")
    if err != nil {
        t.Fatalf("failed to generate keypair: %s", err)
    }
    var entity *openpgp.Entity
    entity, err = pgp.GetEntity([]byte(keypair.PublicKey), []byte(keypair.PrivateKey))
    if err != nil {
        t.Fatalf("failed to read entity: %s", err)
    }
    log.Printf("%#v\n", entity.Identities)
}

outputs

2019/05/19 00:02:54 map[string]*openpgp.Identity{"":(*openpgp.Identity)(0xc00006edc0)}

It was expected that entity.Identities contains test (tst comment) <test@email.com>.

  • I figured out that the function [createEntityFromKeys](https://github.com/jchavannes/go-pgp/blob/master/pgp/entity.go#L27) needs to be written to read all packets available within the public/private key armor [block body](https://github.com/jchavannes/go-pgp/blob/master/pgp/key.go#L22). Using the packetReader i should find a [UserID packet](https://godoc.org/golang.org/x/crypo/openpgp/packet#UserId) [see also rfc](https://tools.ietf.org/html/rfc4880#section-5.11) There is more to figure out because some packet.Signature attached to the identity are to be identified and set appropriately too. –  May 19 '19 at 00:02
  • see also https://davesteele.github.io/gpg/2014/09/20/anatomy-of-a-gpg-key/ –  May 19 '19 at 00:07
  • The difficulty is now to find how to reassemble the packets of userids ans signatures correctly. [reading the source code](https://github.com/jchavannes/go-pgp/blob/master/pgp/entity.go#L50) it is not clear how the selfsignature packet can be identified and linked to the userid packet. Same for the subkey, im unclear about the how&why. UserID's packets can easily be retrieved and inserted into the entity instance being constructed, but the final result is probably unsafe for advanced usage. –  May 19 '19 at 10:59
  • The library must require that information *somewhere* in the process, right? Possibly download and search the source code? – Maarten Bodewes May 19 '19 at 13:42

0 Answers0