Commit a35d68db authored by Joey Salazar's avatar Joey Salazar
Browse files

git: Add HTTPS support to Git Protocol

Richard Sharpe's patch adds git dissectors for pack advertisement and
upload result. This commit adds a pack upload request dissector.
Proper parsing of the Advertisement, Request, and Result blobs is pending

Related to #17093
parent 1546a0af
Pipeline #242276582 passed with stages
in 54 minutes and 13 seconds
......@@ -23,15 +23,22 @@ void proto_register_git(void);
void proto_reg_handoff_git(void);
static dissector_handle_t git_handle;
static dissector_handle_t git_upload_pack_req_handle;
static dissector_handle_t git_upload_pack_adv_handle;
static dissector_handle_t git_upload_pack_res_handle;
static int proto_git = -1;
static gint ett_git = -1;
static gint hf_git_protocol_version = -1;
static gint hf_git_packet_len = -1;
static gint hf_git_packet_data = -1;
static gint hf_git_packet_terminator = -1;
static gint hf_git_sideband_control_code = -1;
static gint hf_git_upload_pack_req = -1;
static gint hf_git_upload_pack_adv = -1;
static gint hf_git_upload_pack_res = -1;
#define PNAME "Git Smart Protocol"
#define PSNAME "Git"
......@@ -39,6 +46,14 @@ static gint hf_git_sideband_control_code = -1;
#define TCP_PORT_GIT 9418
#define GIT_VERSION_ONE 49
#define GIT_VERSION_TWO 50
static const value_string version_vals[] = {
{ GIT_VERSION_ONE, "Git protocol version 1" },
{ GIT_VERSION_TWO, "Git protocol version 2" },
{ 0, NULL }
};
#define SIDEBAND_PACKFILE_DATA 0x01
#define SIDEBAND_PROGRESS_INFO 0x02
#define SIDEBAND_ERROR_INFO 0x03
......@@ -106,6 +121,20 @@ dissect_git_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data
offset += 4;
plen -= 4;
/*
* Parse out the version of the Git Protocol
*
* This change will be sent in a separate MR, is being included here for Joey
* since it's easier to spot the git version than the sideband version
*
* Size parsing when tvb is passed http -> git stops before the string is found
*/
if (plen >= 8 && !strncmp(tvb_get_ptr(tvb, offset, plen), "version ", 8)) {
int protocol_version = tvb_get_guint8(tvb, offset + 6);
proto_tree_add_uint(git_tree, hf_git_protocol_version, tvb, offset, plen, protocol_version);
}
/*
* Parse out the sideband control code.
*
......@@ -128,6 +157,75 @@ dissect_git_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data
return tvb_captured_length(tvb);
}
static int
dissect_git_upload_pack_req(tvbuff_t *tvb, packet_info *pinfo,
proto_tree *tree, void *data _U_)
{
proto_tree *git_tree;
proto_item *ti;
int offset = 0;
col_set_str(pinfo->cinfo, COL_PROTOCOL, PSNAME);
col_set_str(pinfo->cinfo, COL_INFO, PNAME);
ti = proto_tree_add_item(tree, proto_git, tvb, offset, -1, ENC_NA);
git_tree = proto_item_add_subtree(ti, ett_git);
proto_tree_add_item(git_tree, hf_git_upload_pack_req, tvb, offset,
tvb_captured_length(tvb), ENC_NA);
dissect_git_pdu(tvb, pinfo, tree, data);
return tvb_captured_length(tvb);
}
static int
dissect_git_upload_pack_adv(tvbuff_t *tvb, packet_info *pinfo,
proto_tree *tree, void *data _U_)
{
proto_tree *git_tree;
proto_item *ti;
int offset = 0;
col_set_str(pinfo->cinfo, COL_PROTOCOL, PSNAME);
col_set_str(pinfo->cinfo, COL_INFO, PNAME);
ti = proto_tree_add_item(tree, proto_git, tvb, offset, -1, ENC_NA);
git_tree = proto_item_add_subtree(ti, ett_git);
proto_tree_add_item(git_tree, hf_git_upload_pack_adv, tvb, offset,
tvb_captured_length(tvb), ENC_NA);
dissect_git_pdu(tvb, pinfo, tree, data);
return tvb_captured_length(tvb);
}
static int
dissect_git_upload_pack_res(tvbuff_t *tvb, packet_info *pinfo,
proto_tree *tree, void *data _U_)
{
proto_tree *git_tree;
proto_item *ti;
int offset = 0;
col_set_str(pinfo->cinfo, COL_PROTOCOL, PSNAME);
col_set_str(pinfo->cinfo, COL_INFO, PNAME);
ti = proto_tree_add_item(tree, proto_git, tvb, offset, -1, ENC_NA);
git_tree = proto_item_add_subtree(ti, ett_git);
proto_tree_add_item(git_tree, hf_git_upload_pack_res, tvb, offset,
tvb_captured_length(tvb), ENC_NA);
dissect_git_pdu(tvb, pinfo, tree, data);
return tvb_captured_length(tvb);
}
static int
dissect_git(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
{
......@@ -140,6 +238,10 @@ void
proto_register_git(void)
{
static hf_register_info hf[] = {
{ &hf_git_protocol_version,
{ "Git Protocol Version", "git.version", FT_UINT8, BASE_DEC, VALS(version_vals),
0, NULL, HFILL },
},
{ &hf_git_packet_len,
{ "Packet length", "git.length", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL },
},
......@@ -153,6 +255,18 @@ proto_register_git(void)
{ "Sideband control code", "git.sideband_control_code", FT_UINT8,
BASE_HEX, VALS(sideband_vals), 0, NULL, HFILL },
},
{ &hf_git_upload_pack_req,
{ "Upload Pack Request", "git.upload_pack_request",
FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL },
},
{ &hf_git_upload_pack_adv,
{ "Upload Pack Advertisement", "git.upload_pack_advertisement",
FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL },
},
{ &hf_git_upload_pack_res,
{ "Upload Pack Result", "git.upload_pack_result",
FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL },
},
};
static gint *ett[] = {
......@@ -174,12 +288,47 @@ proto_register_git(void)
"Whether the GIT dissector should reassemble messages spanning multiple TCP segments."
" To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
&git_desegment);
/*
* Register dissectors for GIT over HTTP
*/
git_upload_pack_req_handle = register_dissector("git_upload_pack_req",
dissect_git_upload_pack_req,
proto_git);
git_upload_pack_adv_handle = register_dissector("git-upload-pack-adv",
dissect_git_upload_pack_adv,
proto_git);
git_upload_pack_res_handle = register_dissector("git-upload-pack-res",
dissect_git_upload_pack_res,
proto_git);
}
void
proto_reg_handoff_git(void)
{
static gboolean inited = FALSE;
dissector_add_uint_with_preference("tcp.port", TCP_PORT_GIT, git_handle);
/*
* Add the dissectors for GIT over HTTP
*
* Ref Documentation/technical/http-protocol.txt for info
*/
if (!inited) {
dissector_add_string("media_type",
"application/x-git-upload-pack-request",
git_upload_pack_req_handle);
dissector_add_string("media_type",
"application/x-git-upload-pack-advertisement",
git_upload_pack_adv_handle);
dissector_add_string("media_type",
"application/x-git-upload-pack-result",
git_upload_pack_res_handle);
inited = TRUE;
}
}
/*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment