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:
committed by
Adam Langley
parent
84f97f92d0
commit
2da167fbbe
@@ -7,6 +7,7 @@
|
||||
package packet
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"code.google.com/p/go.crypto/cast5"
|
||||
"code.google.com/p/go.crypto/openpgp/errors"
|
||||
"crypto/aes"
|
||||
@@ -338,10 +339,23 @@ func Read(r io.Reader) (p Packet, err error) {
|
||||
se.MDC = true
|
||||
p = se
|
||||
default:
|
||||
err = errors.UnknownPacketTypeError(tag)
|
||||
p = new(OpaquePacket)
|
||||
}
|
||||
if p != nil {
|
||||
err = p.parse(contents)
|
||||
backup := bytes.NewBuffer(nil)
|
||||
// FIXME: this causes large packets to be buffered in memory.
|
||||
// Ideally we would like a better solution here so that huge,
|
||||
// encrypted files could still be handled in a streaming
|
||||
// fashion. Perhaps the encrypted data packet could call a
|
||||
// method on backup that causes it to stop recording.
|
||||
tee := io.TeeReader(contents, backup)
|
||||
err = p.parse(tee)
|
||||
switch err.(type) {
|
||||
case errors.UnsupportedError, errors.UnknownPacketTypeError:
|
||||
p = &OpaquePacket{Tag: uint8(tag), Reason: err}
|
||||
err = nil
|
||||
err = p.parse(io.MultiReader(backup, contents))
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
consumeAll(contents)
|
||||
|
||||
Reference in New Issue
Block a user