openpgp: improve parser resilience & flexibility, add PublicKey.BitLength()

These are improvements I've made as necessary to develop Hockeypuck,
an OpenPGP keyserver (https://launchpad.net/hockeypuck).

The max armor line length was increased to 96 because some keyservers (SKS)
will output armor with lines greater than 64 (the prior max).

I've exposed packet.ReadEntity to support stream-parsing, useful for
large SKS dump files.

ReadKeyRing attempts to recover in the event of malformed data.

Because many packet types are not yet supported, I added OpaquePacket to
capture unsupported types for offline storage and later reparsing.

R=agl
CC=golang-dev
https://golang.org/cl/6927044
This commit is contained in:
Casey Marshall
2012-12-15 14:30:05 -05:00
committed by Adam Langley
parent 84f97f92d0
commit 2da167fbbe
5 changed files with 183 additions and 6 deletions
+8 -3
View File
@@ -199,11 +199,16 @@ func ReadKeyRing(r io.Reader) (el EntityList, err error) {
for {
var e *Entity
e, err = readEntity(packets)
e, err = ReadEntity(packets)
if err != nil {
// TODO: warn about skipped unsupported/unreadable keys
if _, ok := err.(errors.UnsupportedError); ok {
lastUnsupportedError = err
err = readToNextPublicKey(packets)
} else if _, ok := err.(errors.StructuralError); ok {
// Skip unreadable, badly-formatted keys
lastUnsupportedError = err
err = readToNextPublicKey(packets)
}
if err == io.EOF {
err = nil
@@ -249,9 +254,9 @@ func readToNextPublicKey(packets *packet.Reader) (err error) {
panic("unreachable")
}
// readEntity reads an entity (public key, identities, subkeys etc) from the
// ReadEntity reads an entity (public key, identities, subkeys etc) from the
// given Reader.
func readEntity(packets *packet.Reader) (*Entity, error) {
func ReadEntity(packets *packet.Reader) (*Entity, error) {
e := new(Entity)
e.Identities = make(map[string]*Identity)