80 Commits

Author SHA1 Message Date
Mukundan Kavanur Kidambi
c6ccb4b9a3 Addressing feedback 2022-04-02 18:58:59 -05:00
Mukundan Kavanur Kidambi
e145003288 Addressing feedback 2022-04-02 18:58:59 -05:00
Mukundan Kavanur Kidambi
1d7886b012 Adding UTs 2022-04-02 18:58:59 -05:00
Mukundan Kavanur Kidambi
fa2b096400 fix: Adding overall format before appending ColumnFormatCodes 2022-04-02 18:58:59 -05:00
Martin Ashby
40ecac487c Remove unimplemented JSON marshalling for FunctionCall type. 2021-11-06 16:39:43 -05:00
Martin Ashby
3d9a54f092 Fix unit test, it should return after any error is returned from Decode
function whether expected or not, rather than continue and try to
compare invalid decoded results.

Extend the unit test slightly to check the header.

Remove go-test/deep dependency in favour of standard library reflect
package.
2021-11-06 16:39:43 -05:00
Martin Ashby
9275da562f Added FunctionCall support
Added support for FunctionCall message as per
https://www.postgresql.org/docs/11/protocol-message-formats.html

Adds unit test for Encode / Decode cycle and invalid message format
errors.

Fixes https://github.com/jackc/pgproto3/issues/23
2021-11-06 16:39:43 -05:00
Yuli Khodorkovskiy
5c447ff35d Fix JSON output for SASL{Response,InitialResponse}
Hex encoding the Data field in the SASL responses made debugging SCRAM
more difficult than actually helping.

Before:

F{"Type":"SASLResponse","Data":"633d655377732c723d4d4d4e4e6d666b536f5862694a68385833466d324f2b4d77787354692f4550753052414157484b7a306b7376336c5747392f4d4a5267504d2c703d616742664b533164383937674b4f4a6d4c7171626c49326b6b4a506f2b58354359516c63473458357657343d"}
F{"Type":"SASLInitialResponse","AuthMechanism":"SCRAM-SHA-256","Data":"792c2c6e3d2c723d4d4d4e4e6d666b536f5862694a68385833466d324f2b4d77"}

After:

F{"Type":"SASLResponse","Data":"c=eSws,r=9dR43UQLL1KbrKKl4/QbxjqgVjZYR9mqnx3rFBiI7R/1pp5oeVYMGhXj,p=b2hmuvTvWn2xN0fclm+O4TwLAarRM8xoHSN7jsKDHAU="}
F{"Type":"SASLInitialResponse","AuthMechanism":"SCRAM-SHA-256","Data":"y,,n=,r=9dR43UQLL1KbrKKl4/Qbxjqg"}
2021-10-30 09:08:58 -05:00
Yuli Khodorkovskiy
033ca7d47f Fix unexpected EOF failure for StartupMessage 2021-07-07 18:10:44 -05:00
Jack Christensen
6bce4a1878
Merge pull request #19 from gitstashpop/backend-unexpected-eof
Extend handling of unexpected EOF to the backend
2021-07-06 20:08:14 -05:00
Jack Christensen
aaef9bbc35
Merge branch 'master' into backend-unexpected-eof 2021-07-06 20:07:55 -05:00
Yuli Khodorkovskiy
2d3823838e Perform StartupMessage length validation
PG provides a maximum size for a StartupMessage:
https://doxygen.postgresql.org/pqcomm_8h.html#a4c50c668c551887ac3a49872130349e3

Limiting the size ensures a malicious user doesn't send an
overwhelmingly large StartupMessage which could DOS a Go binary that
uses pgproto3.
2021-07-06 20:01:33 -05:00
Yuli Khodorkovskiy
10c6c50ac9
Extend handling of unexpected EOF to the backend
In the original issue [1] and commit [2], support for unexpected EOF was
added to the frontend to detect when a connection was closed abruptly.
Additionally, this allows us to differentiate normal io.EOF errors with
unexpected errors in the backend.

[1] https://github.com/jackc/pgx/issues/662/
[2] 595780be0f
2021-07-01 17:53:14 -04:00
Yuli Khodorkovskiy
7c9e840726 Add support for identifying authentication messages
The pgprotocol overloads 'p' messages with PasswordMessage,
SASLInitialResponse, SASLResponse, and GSSResponse. This patch allows
contextual identification of the message by setting the authType in the
frontend and then setting this value in the backend when a
AuthenticationResponseMessage is received.
2021-06-12 13:54:34 -05:00
Yuli Khodorkovskiy
28c20e93c0 Fix json marshal/unmarshal implementations
Fix marshal/unmarshal for:
- authentication_{cleartext_password, md5_password, ok, sasl, sasl_continue, sasl_final}
- error_response
2021-05-29 11:06:05 -05:00
Henrique Vicente
9c2c389e06 json: fix implementation of json Unmarshalers.
* AuthenticationMD5Password was wrong and is not needed
* Bind was wrong
* ErrorResponse is not needed
* Minor improvements for reliability
2021-05-22 11:34:25 -05:00
Henrique Vicente
ba924e5715 json: Implement json.Unmarshaler for messages.
This will allow using pgmockproxy output as ingestion data for pgmock.
2021-05-22 11:34:25 -05:00
Yuli Khodorkovskiy
1213b69774 Add support to ErrorResponse for unlocalized severity
Add missing 'V' field for unlocalized severity added in PG versions 9.6
and greater. See https://www.postgresql.org/docs/current/protocol-error-fields.html
2020-12-28 10:22:55 -06:00
Roman Tkachenko
88b6398594 Add CopyData and CopyDone messages support to Backend 2020-11-17 16:57:05 -06:00
Jack Christensen
c34a8731b6 Data row value slices need to be capacity limited
Otherwise, appending to a slice that came from a data row could
overwrite adjacent memory.
2020-11-03 19:15:07 -06:00
Jack Christensen
835cf1b068 Fix: Bind.MarshalJSON when ParameterFormatCodes is nil or single element
refs #10
2020-09-17 17:03:30 -05:00
Jack Christensen
fede0ce5d6 Document that received messages are only valid until the next receive. 2020-09-05 11:30:23 -05:00
Yuli Khodorkovskiy
08088ecf9a Fix notification response
Notification response was missing the PID in the Encode function
2020-08-31 17:09:20 -05:00
Jack Christensen
6677e2430f
Merge pull request #4 from yulicrunchy/fix-malformed-sasl
Fix malformed SASL messages
2020-08-28 16:49:24 -05:00
Jack Christensen
5847a2671a
Merge pull request #3 from yulicrunchy/gss
Add missing GSSEncRequest
2020-08-28 16:48:40 -05:00
Jack Christensen
72288731fc
Merge pull request #8 from mjibson/patch-1
mark CopyDone as frontend too
2020-08-01 05:46:49 -05:00
Matt Jibson
2799a6e9a6
mark CopyDone as frontend too 2020-07-31 16:13:23 -06:00
Jack Christensen
3443d78a73
Merge pull request #7 from mjibson/patch-1
correctly encode CopyInResponse's format field
2020-07-31 17:02:15 -05:00
Matt Jibson
6d0b4c45e4
correctly encode CopyInResponse's format field 2020-07-31 15:42:06 -06:00
Jack Christensen
7746f223e0
Merge pull request #1 from felixge/fix-auth-md5
fix: AuthenticationMD5Password AuthType
2020-05-18 08:52:34 -05:00
Jack Christensen
595780be0f Map io.EOF errors to io.ErrUnexpectedEOF
io.EOF is never expected during valid usage. In addition, database/sql
uses io.EOF as a sentinal value that all rows from a query have been
received.

See https://github.com/jackc/pgx/issues/662.
2020-01-17 16:55:05 -06:00
Yuli Khodorkovskiy
1c20e7d36e Fix malformed SASL messages
Per the PG documentation [0], an AuthenticationSASLContinue message has:

    AuthenticationSASLContinue (B)
	Byte1('R')
	    Identifies the message as an authentication request.
	Int32
	    Length of message contents in bytes, including self.
	Int32(11)
	    Specifies that this message contains a SASL challenge.
	Byten
	    SASL data, specific to the SASL mechanism being used.

The current implementation was mistakenly adding the lengh of msg bytes
in between the Int32(11) and Byten. There was a similar issue for
AuthenticationSASLFinal.

[0] https://www.postgresql.org/docs/current/protocol-message-formats.html
2019-12-17 20:28:01 -05:00
Yuli Khodorkovskiy
e6b823d649 Add missing GSSEncRequest 2019-12-17 20:21:57 -05:00
Felix Geisendörfer
a90ef7ed5b fix: AuthenticationMD5Password AuthType 2019-09-08 17:29:06 +02:00
Jack Christensen
eca1e51822 Add more pgfortune output 2019-09-07 11:41:31 -05:00
Jack Christensen
80f2cbce25 Add pgfortune example 2019-09-07 11:37:43 -05:00
Jack Christensen
4c03ce451f Add MarshalJSON for FieldDescription 2019-08-31 16:00:41 -05:00
Jack Christensen
0d1ceed7a6 Refactor authentication message handling 2019-08-31 15:43:07 -05:00
Jack Christensen
439ea11d47 NewFrontend and NewBackend cannot fail 2019-08-31 14:49:55 -05:00
Jack Christensen
2bc8f2e6af Remove pkg/errors package 2019-08-31 11:53:26 -05:00
Jack Christensen
1ba5dcbe01 Support SSLRequest and CancelRequest 2019-08-31 11:48:01 -05:00
Jack Christensen
76538434cf MarshalJSON should be defined on T not *T
Otherwise "%v" format would be used by json.Marshal(T).
2019-08-27 21:13:45 -05:00
Jack Christensen
432c2951c7 Add a lot of documentation 2019-06-08 19:38:34 -05:00
Jack Christensen
bf3a27ae3f Update to github.com/jackc/chunkreader/v2 2019-06-08 18:34:35 -05:00
Jack Christensen
18e7e777be Import PortalSuspended from pgx v3
0ab6f80f9929384a8cf6cfc299b43233534eb705
2019-06-08 10:26:26 -05:00
Jack Christensen
a340d5f15f CopyFail should be frontend message 2019-05-17 13:27:11 -05:00
Jack Christensen
4acc0f54c6 Import fixes from pgx/pgproto3
Import and adapt commit: fbb8cce
2019-05-03 14:07:55 -05:00
Jack Christensen
c116219b62 Update tests to use v2 2019-04-20 13:01:11 -05:00
Jack Christensen
9b6a681f50 Update go.mod version 2019-04-18 23:15:44 -05:00
Jack Christensen
76e904a5a4 CommandComplete.CommandTag is now []byte
Avoid allocation
2019-04-18 23:12:18 -05:00