Skip to content

Commit 811415b

Browse files
authored
Support GSS encrypt request decoding as part of psql 14.15 client (#1361)
1 parent 063d7cb commit 811415b

File tree

9 files changed

+315
-5
lines changed

9 files changed

+315
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#
2+
# Copyright 2021-2024 Aklivity Inc
3+
#
4+
# Licensed under the Aklivity Community License (the "License"); you may not use
5+
# this file except in compliance with the License. You may obtain a copy of the
6+
# License at
7+
#
8+
# https://www.aklivity.io/aklivity-community-license/
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
# WARRANTIES OF ANY KIND, either express or implied. See the License for the
13+
# specific language governing permissions and limitations under the License.
14+
#
15+
16+
connect "zilla://streams/app0"
17+
option zilla:window 8192
18+
option zilla:transmission "duplex"
19+
20+
write zilla:begin.ext ${pgsql:beginEx()
21+
.typeId(zilla:id("pgsql"))
22+
.parameter("user", "root")
23+
.parameter("database", "dev")
24+
.parameter("application_name", "psql")
25+
.parameter("client_encoding", "UTF8")
26+
.build()}
27+
28+
connected
29+
30+
read closed
31+
write close
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#
2+
# Copyright 2021-2024 Aklivity Inc
3+
#
4+
# Licensed under the Aklivity Community License (the "License"); you may not use
5+
# this file except in compliance with the License. You may obtain a copy of the
6+
# License at
7+
#
8+
# https://www.aklivity.io/aklivity-community-license/
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
# WARRANTIES OF ANY KIND, either express or implied. See the License for the
13+
# specific language governing permissions and limitations under the License.
14+
#
15+
16+
property serverAddress "zilla://streams/app0"
17+
18+
accept ${serverAddress}
19+
option zilla:window 8192
20+
option zilla:transmission "duplex"
21+
22+
accepted
23+
24+
read zilla:begin.ext ${pgsql:beginEx()
25+
.typeId(zilla:id("pgsql"))
26+
.parameter("user", "root")
27+
.parameter("database", "dev")
28+
.parameter("application_name", "psql")
29+
.parameter("client_encoding", "UTF8")
30+
.build()}
31+
32+
connected
33+
34+
write close
35+
read closed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#
2+
# Copyright 2021-2024 Aklivity Inc
3+
#
4+
# Licensed under the Aklivity Community License (the "License"); you may not use
5+
# this file except in compliance with the License. You may obtain a copy of the
6+
# License at
7+
#
8+
# https://www.aklivity.io/aklivity-community-license/
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
# WARRANTIES OF ANY KIND, either express or implied. See the License for the
13+
# specific language governing permissions and limitations under the License.
14+
#
15+
16+
property networkConnectWindow 8192
17+
18+
connect "zilla://streams/net0"
19+
option zilla:window ${networkConnectWindow}
20+
option zilla:transmission "duplex"
21+
option zilla:byteorder "network"
22+
23+
connected
24+
25+
write 8 # length
26+
[0x04 0xd2 0x16 0x30] # gss encrypt request code
27+
28+
read [0x4e]
29+
30+
write 8 # length
31+
[0x04 0xd2 0x16 0x2f] # ssl request code
32+
33+
read [0x4e]
34+
35+
write 75 # length
36+
3s # major version
37+
0s # minor version
38+
"user" [0x00] # name
39+
"root" [0x00] # value
40+
"database" [0x00] # name
41+
"dev" [0x00] # value
42+
"application_name" [0x00] # name
43+
"psql" [0x00] # value
44+
"client_encoding" [0x00] # name
45+
"UTF8" [0x00] # value
46+
[0x00] # end of parameters
47+
48+
read [0x52] # type R
49+
8 # length
50+
0 # authentication type
51+
52+
read [0x4b] # type K
53+
12 # length
54+
0 # pid
55+
0 # key
56+
57+
read [0x53] # type S
58+
25 # length
59+
"client_encoding" [0x00] # name
60+
"UTF8" [0x00] # value
61+
62+
read [0x53] # type S
63+
35 # length
64+
"standard_conforming_strings" [0x00] # name
65+
[0x6f 0x6e 0x00] # value
66+
67+
read [0x53] # type S
68+
25 # length
69+
"server_version" [0x00] # name
70+
"9.1.0" [0x00] # value
71+
72+
read [0x53] # type S
73+
27 # length
74+
"application_name" [0x00] # name
75+
"zilla" [0x00] # value
76+
77+
read [0x5a] # type Z
78+
5 # length
79+
[0x49] # status
80+
81+
read [0x58] # type X
82+
4 # length
83+
84+
read closed
85+
write close
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#
2+
# Copyright 2021-2024 Aklivity Inc
3+
#
4+
# Licensed under the Aklivity Community License (the "License"); you may not use
5+
# this file except in compliance with the License. You may obtain a copy of the
6+
# License at
7+
#
8+
# https://www.aklivity.io/aklivity-community-license/
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
# WARRANTIES OF ANY KIND, either express or implied. See the License for the
13+
# specific language governing permissions and limitations under the License.
14+
#
15+
16+
property networkAcceptWindow 8192
17+
18+
accept "zilla://streams/net0"
19+
option zilla:window ${networkAcceptWindow}
20+
option zilla:transmission "duplex"
21+
option zilla:byteorder "network"
22+
23+
accepted
24+
25+
connected
26+
27+
read 8 # length
28+
[0x04 0xd2 0x16 0x30] # gss encrypt request code
29+
30+
write [0x4e]
31+
32+
read 8 # length
33+
[0x04 0xd2 0x16 0x2f] # ssl request code
34+
35+
write [0x4e]
36+
37+
read 75 # length
38+
3s # major version
39+
0s # minor version
40+
"user" [0x00] # name
41+
"root" [0x00] # value
42+
"database" [0x00] # name
43+
"dev" [0x00] # value
44+
"application_name" [0x00] # name
45+
"psql" [0x00] # value
46+
"client_encoding" [0x00] # name
47+
"UTF8" [0x00] # value
48+
[0x00] # end of parameters
49+
50+
write [0x52] # type R
51+
8 # length
52+
0 # authentication type
53+
54+
write [0x4b] # type K
55+
12 # length
56+
0 # pid
57+
0 # key
58+
59+
write [0x53] # type S
60+
25 # length
61+
"client_encoding" [0x00] # name
62+
"UTF8" [0x00] # value
63+
64+
write [0x53] # type S
65+
35 # length
66+
"standard_conforming_strings" [0x00] # name
67+
[0x6f 0x6e 0x00] # value
68+
69+
write [0x53] # type S
70+
25 # length
71+
"server_version" [0x00] # name
72+
"9.1.0" [0x00] # value
73+
74+
write [0x53] # type S
75+
27 # length
76+
"application_name" [0x00] # name
77+
"zilla" [0x00] # value
78+
79+
write [0x5a] # type Z
80+
5 # length
81+
[0x49] # status
82+
83+
write [0x58] # type X
84+
4 # length
85+
86+
write close
87+
read closed

incubator/binding-pgsql.spec/src/test/java/io/aklivity/zilla/specs/binding/pgsql/streams/ApplicationIT.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ public void shouldHandleFragmentedCreateTable() throws Exception
101101
k3po.finish();
102102
}
103103

104+
@Test
105+
@Specification({
106+
"${app}/gss.encrypt.request/client",
107+
"${app}/gss.encrypt.request/server" })
108+
public void shouldHandleGssEncryptRequest() throws Exception
109+
{
110+
k3po.finish();
111+
}
112+
104113
@Test
105114
@Specification({
106115
"${app}/ssl.request/client",

incubator/binding-pgsql.spec/src/test/java/io/aklivity/zilla/specs/binding/pgsql/streams/NetworkIT.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ public void shouldHandleSslRequest() throws Exception
8383
k3po.finish();
8484
}
8585

86+
@Test
87+
@Specification({
88+
"${net}/gss.encrypt.request/client",
89+
"${net}/gss.encrypt.request/server" })
90+
public void shouldHandleGssEncryptRequest() throws Exception
91+
{
92+
k3po.finish();
93+
}
94+
8695
@Test
8796
@Specification({
8897
"${net}/client.sent.write.abort/client",

incubator/binding-pgsql/src/main/java/io/aklivity/zilla/runtime/binding/pgsql/internal/stream/PgsqlServerFactory.java

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
import io.aklivity.zilla.runtime.binding.pgsql.internal.types.codec.PgsqlAuthenticationMessageFW;
3939
import io.aklivity.zilla.runtime.binding.pgsql.internal.types.codec.PgsqlBackendKeyMessageFW;
4040
import io.aklivity.zilla.runtime.binding.pgsql.internal.types.codec.PgsqlCancelRequestMessageFW;
41+
import io.aklivity.zilla.runtime.binding.pgsql.internal.types.codec.PgsqlGssEncryptRequestFW;
42+
import io.aklivity.zilla.runtime.binding.pgsql.internal.types.codec.PgsqlGssEncryptResponseFW;
4143
import io.aklivity.zilla.runtime.binding.pgsql.internal.types.codec.PgsqlMessageFW;
4244
import io.aklivity.zilla.runtime.binding.pgsql.internal.types.codec.PgsqlSslRequestFW;
4345
import io.aklivity.zilla.runtime.binding.pgsql.internal.types.codec.PgsqlSslResponseFW;
@@ -79,6 +81,7 @@ public final class PgsqlServerFactory implements PgsqlStreamFactory
7981
private static final Byte MESSAGE_TYPE_PARAMETER_STATUS = 'S';
8082

8183
private static final int SSL_REQUEST_CODE = 80877103;
84+
private static final int GSS_ENCRYPT_REQUEST_CODE = 80877104;
8285
private static final int CANCEL_REQUEST_CODE = 80877102;
8386
private static final int END_OF_FIELD = 0x00;
8487

@@ -122,11 +125,13 @@ public final class PgsqlServerFactory implements PgsqlStreamFactory
122125

123126
private final PgsqlMessageFW messageRO = new PgsqlMessageFW();
124127
private final PgsqlSslRequestFW sslRequestRO = new PgsqlSslRequestFW();
128+
private final PgsqlGssEncryptRequestFW gssRequestRO = new PgsqlGssEncryptRequestFW();
125129
private final PgsqlStartupMessageFW startupMessageRO = new PgsqlStartupMessageFW();
126130
private final PgsqlCancelRequestMessageFW cancelReqMessageRO = new PgsqlCancelRequestMessageFW();
127131

128132
private final PgsqlMessageFW.Builder messageRW = new PgsqlMessageFW.Builder();
129133
private final PgsqlSslResponseFW.Builder sslResponseRW = new PgsqlSslResponseFW.Builder();
134+
private final PgsqlGssEncryptResponseFW.Builder gssResponseRW = new PgsqlGssEncryptResponseFW.Builder();
130135
private final PgsqlAuthenticationMessageFW.Builder authMessageRW = new PgsqlAuthenticationMessageFW.Builder();
131136
private final PgsqlBackendKeyMessageFW.Builder backendKeyMessageRW = new PgsqlBackendKeyMessageFW.Builder();
132137

@@ -146,6 +151,7 @@ public final class PgsqlServerFactory implements PgsqlStreamFactory
146151
private final int pgsqlTypeId;
147152

148153
private final PgsqlServerDecoder decodePgsqlInitial = this::decodePgsqlInitial;
154+
private final PgsqlServerDecoder decodePgsqlGssRequest = this::decodePgsqlGssEncryptRequest;
149155
private final PgsqlServerDecoder decodePgsqlSslRequest = this::decodePgsqlSslRequest;
150156
private final PgsqlServerDecoder decodePgsqlStartupMessage = this::decodePgsqlStartupMessage;
151157
private final PgsqlServerDecoder decodePgsqlCancelRequest = this::decodePgsqlCancelRequest;
@@ -605,6 +611,14 @@ public void onDecodeSslRequest(
605611
doNetworkData(traceId, authorization, FLAGS_COMP, 0L, messageBuffer, 0, sslResponse.limit());
606612
}
607613

614+
public void onDecodeGssEncryptRequest(
615+
long traceId,
616+
long authorization)
617+
{
618+
PgsqlGssEncryptResponseFW gssResponse = gssResponseRW.wrap(messageBuffer, 0, messageBuffer.capacity()).build();
619+
doNetworkData(traceId, authorization, FLAGS_COMP, 0L, messageBuffer, 0, gssResponse.limit());
620+
}
621+
608622
public void onDecodeCancelRequest(
609623
long traceId,
610624
long authorization,
@@ -1493,10 +1507,16 @@ private int decodePgsqlInitial(
14931507
int limit)
14941508
{
14951509
final PgsqlSslRequestFW pgsqlSslRequest = sslRequestRO.tryWrap(buffer, offset, limit);
1510+
final PgsqlGssEncryptRequestFW pgsqlGssRequest = gssRequestRO.tryWrap(buffer, offset, limit);
14961511
final PgsqlCancelRequestMessageFW cancelRequest = cancelReqMessageRO.tryWrap(buffer, offset, limit);
14971512
final PgsqlStartupMessageFW startupMessage = startupMessageRO.tryWrap(buffer, offset, limit);
14981513

1499-
if (pgsqlSslRequest != null &&
1514+
if (pgsqlGssRequest != null &&
1515+
pgsqlGssRequest.code() == GSS_ENCRYPT_REQUEST_CODE)
1516+
{
1517+
server.decoder = decodePgsqlGssRequest;
1518+
}
1519+
else if (pgsqlSslRequest != null &&
15001520
pgsqlSslRequest.code() == SSL_REQUEST_CODE)
15011521
{
15021522
server.decoder = decodePgsqlSslRequest;
@@ -1510,10 +1530,6 @@ else if (startupMessage != null)
15101530
{
15111531
server.decoder = decodePgsqlStartupMessage;
15121532
}
1513-
else
1514-
{
1515-
server.decoder = decodePgsqlIgnoreAll;
1516-
}
15171533

15181534
return offset;
15191535
}
@@ -1535,6 +1551,23 @@ private int decodePgsqlSslRequest(
15351551
return sslRequest.limit();
15361552
}
15371553

1554+
private int decodePgsqlGssEncryptRequest(
1555+
PgsqlServer server,
1556+
long traceId,
1557+
long authorization,
1558+
long budgetId,
1559+
DirectBuffer buffer,
1560+
int offset,
1561+
int limit)
1562+
{
1563+
PgsqlGssEncryptRequestFW gssRequest = gssRequestRO.wrap(buffer, offset, limit);
1564+
1565+
server.onDecodeGssEncryptRequest(traceId, authorization);
1566+
server.decoder = decodePgsqlInitial;
1567+
1568+
return gssRequest.limit();
1569+
}
1570+
15381571
private int decodePgsqlStartupMessage(
15391572
PgsqlServer server,
15401573
long traceId,

incubator/binding-pgsql/src/main/zilla/protocol.idl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ scope protocol
2929
uint8 answer = 78;
3030
}
3131

32+
struct PgsqlGssEncryptRequest
33+
{
34+
int32 length = 4;
35+
int32 code = 80877104;
36+
}
37+
38+
struct PgsqlGssEncryptResponse
39+
{
40+
uint8 answer = 78;
41+
}
42+
3243
struct PgsqlStartupMessage
3344
{
3445
int32 length;

0 commit comments

Comments
 (0)