redrabbit / git.limo

A Git source code management tool powered by Elixir with easy installation & high extensibility.
https://git.limo
MIT License
497 stars 42 forks source link

FunctionClauseError when importing some gpg keys #67

Closed skwerlman closed 4 years ago

skwerlman commented 5 years ago

when importing one of my gpg keys, i recieve the following stack trace:

[error] #PID<0.1030.0> running GitGud.Web.Endpoint (connection #PID<0.1029.0>, stream id 1) terminated
Server: localhost:4000 (http)
Request: POST /settings/gpg
** (exit) an exception was raised:
    ** (FunctionClauseError) no function clause matching in GitGud.GPGKey.parse_packet_sig_sub/2
        (gitgud) lib/gitgud/schemas/gpg_key.ex:301: GitGud.GPGKey.parse_packet_sig_sub(<<234, 181, 57, 48, 101, 239, 190, 190, 59, 20, 53, 159, 47, 64, 117, 159, 239, 112, 20, 93, 223, 181, 78, 10, 148, 227, 16, 156, 239, 234, 222, 72, 35, 126, 243, 218, 62, 173, 62, 50, 179, 14, 79, 96, 31, 203, 197, 46, 168, 18, ...>>, [undefined: <<4, 25, 1, 10, 0, 6, 5, 2, 86, 248, 157, 251, 0, 10, 9, 16, 180, 161, 89, 71, 196, 130, 147, 242, 222, 42, 32, 0, 154, 162, 57, 228, 42, 35, 170, 127, 217, 219, 40, 35, 223, 232, 162, 55, 208, 80, 116, 57, 40, ...>>, issuer: <<134, 40, 35, 137, 154, 194, 228, 69>>])
        (gitgud) lib/gitgud/schemas/gpg_key.ex:285: GitGud.GPGKey.parse_packet_tag/2
        (gitgud) lib/gitgud/schemas/gpg_key.ex:260: GitGud.GPGKey.parse_packet/2
        (gitgud) lib/gitgud/schemas/gpg_key.ex:243: GitGud.GPGKey.put_data/1
        (gitgud) lib/gitgud/schemas/gpg_key.ex:203: GitGud.GPGKey.changeset/2
        (gitgud) lib/gitgud/schemas/gpg_key.ex:168: GitGud.GPGKey.create/1
        (gitgud_web) lib/gitgud_web/controllers/gpg_key_controller.ex:42: GitGud.Web.GPGKeyController.create/2
        (gitgud_web) lib/gitgud_web/controllers/gpg_key_controller.ex:1: GitGud.Web.GPGKeyController.action/2
        (gitgud_web) lib/gitgud_web/controllers/gpg_key_controller.ex:1: GitGud.Web.GPGKeyController.phoenix_controller_pipeline/2
        (phoenix) lib/phoenix/router.ex:288: Phoenix.Router.__call__/2
        (gitgud_web) lib/gitgud_web/endpoint.ex:1: GitGud.Web.Endpoint.plug_builder_call/2
        (gitgud_web) lib/plug/debugger.ex:122: GitGud.Web.Endpoint."call (overridable 3)"/2
        (gitgud_web) lib/gitgud_web/endpoint.ex:1: GitGud.Web.Endpoint.call/2
        (phoenix) lib/phoenix/endpoint/cowboy2_handler.ex:42: Phoenix.Endpoint.Cowboy2Handler.init/4
        (cowboy) /mnt/code/gitgud/deps/cowboy/src/cowboy_handler.erl:41: :cowboy_handler.execute/2
        (cowboy) /mnt/code/gitgud/deps/cowboy/src/cowboy_stream_h.erl:296: :cowboy_stream_h.execute/3
        (cowboy) /mnt/code/gitgud/deps/cowboy/src/cowboy_stream_h.erl:274: :cowboy_stream_h.request_process/3
        (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3

for testing, this is the key i tried to import: 5D9DF29E62C5C2E2951ADC69862823899AC2E445

my guess is that it has something to do with either the type 17 tags on this key, or the fact that its a very large rsa key (8192b)

redrabbit commented 5 years ago

Hi @skwerlman and thank for reporting this.

I've implemented the PGP parser by partially implementing the RFC4880 (see #40). I've not put too much efforts in parsing attributes that I did not require (key-ids, sub-keys, email) but getting a runtime error when these fields are parsed is definitely not wanted.

Will investigate with your key and try to fix this.

redrabbit commented 4 years ago

I've tried with you key and traced down the function clause error. Added a function for skipping unknown subs. The required fields are still parsed correctly.

skwerlman commented 4 years ago

tested and confirmed working. thanks!