Categorygithub.com/google/gitprotocolio
modulepackage
0.0.0-20210704173409-b5a56823ae52
Repository: https://github.com/google/gitprotocolio.git
Documentation: pkg.go.dev

# README

gitprotocolio

A Git protocol parser written in Go.

This is more like an experimental project to better understand the protocol.

This is not an official Google product (i.e. a 20% project).

Background

Git protocol is defined in Documentation/technical/pack-protocol.txt. This is not a complete definition. Also, a transport specific spec Documentation/technical/http-protocol.txt is not complete. This project was started so that these upstream protocol spec becomes more accurate. To verify the written syntax is accurate, this project includes a Git protocol parser written in Go, and have end-to-end test suites.

This makes it easy to write a test case for Git client. Currently the test cases are run against the canonical Git implementation, but this can be extended to run against JGit, etc.. Also it makes it easy to test an attack case. With this library, one can write an attack case like git-bomb against Git protocol by producing a request that is usually not produced by a sane Git client. Protocol properties can also be checked. For example, it's possible to write a test to check valid request/response's prefixes are not a valid request/response. This property makes sure a client won't process an incomplete response thinking it's complete.

TODOs

  • Protocol semantics is not defined.

    The syntax is relatively complete. The semantics is not even mentioned. One idea is to define the semantics by treating the request/response as an operation to modify Git repositories. This perspective makes it possible to define a formal protocol semantics in a same way as programming language formal semantics.

    Defining a simple git-push semantics seems easy. Defining a pack negotiation semantics for shallow cloned repositories seems difficult.

  • Upstream pack-protocol.txt is not updated.

    The initial purpose, create a complete pack-protocol.txt, is not yet done. We can start from a minor fix (e.g. capability separator in some places is space not NUL). Also relationship between Git protocol and network transports (HTTPS, SSH, Git wire) are good to be mentioned.

  • Bidi-transports are not tested and defined.

    Git's bidi-transports, SSH and Git-wire protocol, are not tested with this project and the protocol syntax is also not defined. The majority of the syntax is same, but there's a slight difference. Go has an SSH library, so it's easy to run a test SSH server.

# Packages

No description provided by the author

# Functions

No description provided by the author
NewInfoRefsResponse returns a new InfoRefsResponse to read from rd.
NewPacketScanner returns a new PacketScanner to read from r.
NewProtocolV1ReceivePackRequest returns a new ProtocolV1ReceivePackRequest to read from rd.
NewProtocolV1ReceivePackResponse returns a new ProtocolV1ReceivePackResponse to read from rd.
NewProtocolV1UploadPackRequest returns a new ProtocolV1UploadPackRequest to read from rd.
NewProtocolV1UploadPackResponse returns a new ProtocolV1UploadPackResponse to read from rd.
NewProtocolV2Request returns a new ProtocolV2Request to read from rd.
NewProtocolV2Response returns a new ProtocolV2Response to read from rd.
ParseSideBandPacket parses the BytesPacket as a sideband packet.

# Structs

DelimPacket is the delim packet ("0001").
FlushPacket is the flush packet ("0000").
InfoRefsResponse provides an interface for reading an /info/refs response.
InfoRefsResponseChunk is a chunk of an /info/refs response.
PacketScanner provides an interface for reading packet line data.
PackFileIndicatorPacket is the indicator of the beginning of the pack file ("PACK").
ProtocolV1ReceivePackRequest provides an interface for reading a protocol v1 git-receive-pack request.
ProtocolV1ReceivePackRequestChunk is a chunk of a protocol v1 git-receive-pack request.
ProtocolV1ReceivePackResponse provides an interface for reading a protocol v1 git-receive-pack response.
ProtocolV1ReceivePackResponseChunk is a chunk of a protocol v1 git-receive-pack response.
ProtocolV1UploadPackRequest provides an interface for reading a protocol v1 git-upload-pack request.
ProtocolV1UploadPackRequestChunk is a chunk of a protocol v1 git-upload-pack request.
ProtocolV1UploadPackResponse provides an interface for reading a protocol v1 git-upload-pack response.
ProtocolV1UploadPackResponseChunk is a chunk of a protocol v1 git-upload-pack response.
ProtocolV2Request provides an interface for reading a protocol v2 request.
ProtocolV2RequestChunk is a chunk of a protocol v2 request.
ProtocolV2Response provides an interface for reading a protocol v2 response.
ProtocolV2ResponseChunk is a chunk of a protocol v2 response.

# Interfaces

BytePayloadPacket is the interface of Packets that the payload is []byte.
Packet is the interface that wraps a packet line.
No description provided by the author

# Type aliases

BytesPacket is a packet with a content.
ErrorPacket is a packet that indicates an error.
PackFilePacket is a chunk of the pack file.
SideBandErrorPacket is a sideband packet for the error stream (0x03).
SideBandMainPacket is a sideband packet for the main stream (0x01).
SideBandReportPacket is a sideband packet for the report stream (0x02).
SyntaxError is an error returned when the parser cannot parse the input.