mirror of https://github.com/grpc/grpc.git
commit
d95877ba97
23 changed files with 665 additions and 157 deletions
@ -0,0 +1,132 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2019 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
#include <string> |
||||
|
||||
#include <gtest/gtest.h> |
||||
|
||||
#include <grpc/support/string_util.h> |
||||
#include "src/core/lib/surface/server.h" |
||||
#include "test/core/bad_client/bad_client.h" |
||||
|
||||
#define HEADER_FRAME_ID_1 \ |
||||
"\x00\x00\xc9\x01\x05\x00\x00\x00\x01" /* headers: generated from \
|
||||
simple_request.headers in this \
|
||||
directory */ \
|
||||
"\x10\x05:path\x08/foo/bar" \
|
||||
"\x10\x07:scheme\x04http" \
|
||||
"\x10\x07:method\x04POST" \
|
||||
"\x10\x0a:authority\x09localhost" \
|
||||
"\x10\x0c" \
|
||||
"content-type\x10" \
|
||||
"application/grpc" \
|
||||
"\x10\x14grpc-accept-encoding\x15" \
|
||||
"deflate,identity,gzip" \
|
||||
"\x10\x02te\x08trailers" \
|
||||
"\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" |
||||
|
||||
#define HEADER_FRAME_ID_2 \ |
||||
"\x00\x00\xc9\x01\x05\x00\x00\x00\x02" /* headers: generated from \
|
||||
simple_request.headers in this \
|
||||
directory */ \
|
||||
"\x10\x05:path\x08/foo/bar" \
|
||||
"\x10\x07:scheme\x04http" \
|
||||
"\x10\x07:method\x04POST" \
|
||||
"\x10\x0a:authority\x09localhost" \
|
||||
"\x10\x0c" \
|
||||
"content-type\x10" \
|
||||
"application/grpc" \
|
||||
"\x10\x14grpc-accept-encoding\x15" \
|
||||
"deflate,identity,gzip" \
|
||||
"\x10\x02te\x08trailers" \
|
||||
"\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" |
||||
|
||||
#define HEADER_FRAME_ID_3 \ |
||||
"\x00\x00\xc9\x01\x05\x00\x00\x00\x03" /* headers: generated from \
|
||||
simple_request.headers in this \
|
||||
directory */ \
|
||||
"\x10\x05:path\x08/foo/bar" \
|
||||
"\x10\x07:scheme\x04http" \
|
||||
"\x10\x07:method\x04POST" \
|
||||
"\x10\x0a:authority\x09localhost" \
|
||||
"\x10\x0c" \
|
||||
"content-type\x10" \
|
||||
"application/grpc" \
|
||||
"\x10\x14grpc-accept-encoding\x15" \
|
||||
"deflate,identity,gzip" \
|
||||
"\x10\x02te\x08trailers" \
|
||||
"\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" |
||||
|
||||
namespace { |
||||
|
||||
void verifier(grpc_server* server, grpc_completion_queue* cq, |
||||
void* registered_method) { |
||||
while (grpc_server_has_open_connections(server)) { |
||||
GPR_ASSERT(grpc_completion_queue_next( |
||||
cq, grpc_timeout_milliseconds_to_deadline(20), nullptr) |
||||
.type == GRPC_QUEUE_TIMEOUT); |
||||
} |
||||
} |
||||
|
||||
TEST(BadStreamingId, RegularHeader) { |
||||
grpc_bad_client_arg args[2]; |
||||
args[0] = connection_preface_arg; |
||||
args[1].client_validator = nullptr; |
||||
args[1].client_payload = HEADER_FRAME_ID_1; |
||||
args[1].client_payload_length = sizeof(HEADER_FRAME_ID_1) - 1; |
||||
grpc_run_bad_client_test(verifier, args, 2, GRPC_BAD_CLIENT_DISCONNECT); |
||||
} |
||||
|
||||
TEST(BadStreamingId, NonClientStreamId) { |
||||
grpc_bad_client_arg args[2]; |
||||
args[0] = connection_preface_arg; |
||||
// send a header frame with non-client stream id 2
|
||||
args[1].client_validator = nullptr; |
||||
args[1].client_payload = HEADER_FRAME_ID_2; |
||||
args[1].client_payload_length = sizeof(HEADER_FRAME_ID_2) - 1; |
||||
grpc_run_bad_client_test(verifier, args, 2, GRPC_BAD_CLIENT_DISCONNECT); |
||||
} |
||||
|
||||
TEST(BadStreamingId, ClosedStreamId) { |
||||
grpc_bad_client_arg args[4]; |
||||
args[0] = connection_preface_arg; |
||||
// send a header frame with stream id 1
|
||||
args[1].client_validator = nullptr; |
||||
args[1].client_payload = HEADER_FRAME_ID_1; |
||||
args[1].client_payload_length = sizeof(HEADER_FRAME_ID_1) - 1; |
||||
// send a header frame with stream id 3
|
||||
args[2].client_validator = nullptr; |
||||
args[2].client_payload = HEADER_FRAME_ID_3; |
||||
args[2].client_payload_length = sizeof(HEADER_FRAME_ID_3) - 1; |
||||
// send a header frame with closed stream id 1 again
|
||||
args[3].client_validator = nullptr; |
||||
args[3].client_payload = HEADER_FRAME_ID_1; |
||||
args[3].client_payload_length = sizeof(HEADER_FRAME_ID_1) - 1; |
||||
grpc_run_bad_client_test(verifier, args, 4, GRPC_BAD_CLIENT_DISCONNECT); |
||||
} |
||||
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char** argv) { |
||||
grpc_init(); |
||||
grpc::testing::TestEnvironment env(argc, argv); |
||||
::testing::InitGoogleTest(&argc, argv); |
||||
int retval = RUN_ALL_TESTS(); |
||||
grpc_shutdown(); |
||||
return retval; |
||||
} |
@ -0,0 +1,112 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2019 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
#include <string> |
||||
|
||||
#include <gtest/gtest.h> |
||||
|
||||
#include <grpc/support/string_util.h> |
||||
#include "src/core/lib/surface/server.h" |
||||
#include "test/core/bad_client/bad_client.h" |
||||
|
||||
#define APPEND_BUFFER(string, to_append) \ |
||||
((string).append((to_append), sizeof(to_append) - 1)) |
||||
|
||||
namespace { |
||||
|
||||
void verifier(grpc_server* server, grpc_completion_queue* cq, |
||||
void* registered_method) { |
||||
while (grpc_server_has_open_connections(server)) { |
||||
GPR_ASSERT(grpc_completion_queue_next( |
||||
cq, grpc_timeout_milliseconds_to_deadline(20), nullptr) |
||||
.type == GRPC_QUEUE_TIMEOUT); |
||||
} |
||||
} |
||||
|
||||
void FrameVerifier(const std::string& attack_vector) { |
||||
grpc_bad_client_arg args[2]; |
||||
args[0] = connection_preface_arg; |
||||
args[1].client_validator = nullptr; |
||||
args[1].client_payload = attack_vector.c_str(); |
||||
args[1].client_payload_length = attack_vector.size(); |
||||
grpc_run_bad_client_test(verifier, args, 2, GRPC_BAD_CLIENT_DISCONNECT); |
||||
} |
||||
|
||||
TEST(OutOfBounds, MaxFrameSizeDataFrame) { |
||||
std::string out_of_bounds_data; |
||||
// Send a data frame larger than 2^14
|
||||
APPEND_BUFFER(out_of_bounds_data, "\x01\x00\x00\x00\x00\x00\x00\x00\x01"); |
||||
out_of_bounds_data.append(1 << 16, 'a'); |
||||
FrameVerifier(out_of_bounds_data); |
||||
} |
||||
|
||||
TEST(OutOfBounds, BadSizePriorityFrame) { |
||||
std::string bad_size_priority_frame; |
||||
// Priority Frame should be a length of 5 octets
|
||||
APPEND_BUFFER(bad_size_priority_frame, |
||||
"\x00\x00\x03\x02\x00\x00\x00\x00\x01" |
||||
"\x11\x11\x12"); |
||||
FrameVerifier(bad_size_priority_frame); |
||||
} |
||||
|
||||
TEST(OutOfBounds, BadSizeRstStream) { |
||||
std::string bad_size_rst_stream; |
||||
// Rst Stream Frame should have a length of 4 octets
|
||||
APPEND_BUFFER(bad_size_rst_stream, |
||||
"\x00\x00\x02\x03\x00\x00\x00\x00\x01" |
||||
"\x11\x11"); |
||||
FrameVerifier(bad_size_rst_stream); |
||||
} |
||||
|
||||
TEST(OutOfBounds, BadSizeSettings) { |
||||
std::string bad_size_settings; |
||||
// Settings Frame should have a length which is a multiple of 6 octets
|
||||
APPEND_BUFFER(bad_size_settings, |
||||
"\x00\x00\x05\x04\x00\x00\x00\x00\x00" |
||||
"\x11\x11\x11\x11\x11"); |
||||
FrameVerifier(bad_size_settings); |
||||
} |
||||
|
||||
TEST(OutOfBounds, BadSizePing) { |
||||
std::string bad_size_ping; |
||||
// Rst Stream Frame should have a length of 8 octets
|
||||
APPEND_BUFFER(bad_size_ping, |
||||
"\x00\x00\x05\x06\x00\x00\x00\x00\x00" |
||||
"\x11\x11\x11\x11\x11"); |
||||
FrameVerifier(bad_size_ping); |
||||
} |
||||
|
||||
TEST(OutOfBounds, WindowUpdate) { |
||||
std::string bad_size_window_update; |
||||
// Window Update Frame should have a length of 4 octets
|
||||
APPEND_BUFFER(bad_size_window_update, |
||||
"\x00\x00\x01\x08\x00\x00\x00\x00\x00" |
||||
"\x11"); |
||||
FrameVerifier(bad_size_window_update); |
||||
} |
||||
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char** argv) { |
||||
grpc_init(); |
||||
grpc::testing::TestEnvironment env(argc, argv); |
||||
::testing::InitGoogleTest(&argc, argv); |
||||
int retval = RUN_ALL_TESTS(); |
||||
grpc_shutdown(); |
||||
return retval; |
||||
} |
@ -1,40 +0,0 @@ |
||||
# Copyright 2015 gRPC authors. |
||||
# |
||||
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||
# you may not use this file except in compliance with the License. |
||||
# You may obtain a copy of the License at |
||||
# |
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
# |
||||
# Unless required by applicable law or agreed to in writing, software |
||||
# distributed under the License is distributed on an "AS IS" BASIS, |
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
# See the License for the specific language governing permissions and |
||||
# limitations under the License. |
||||
|
||||
FROM debian:jessie |
||||
|
||||
# Install Git and basic packages. |
||||
RUN apt-get update && apt-get install -y \ |
||||
curl \ |
||||
gcc && apt-get clean |
||||
|
||||
#================== |
||||
# Ruby dependencies |
||||
|
||||
# Install rvm |
||||
RUN gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB |
||||
RUN \curl -sSL https://get.rvm.io | bash -s stable |
||||
|
||||
# Install Ruby 2.2 |
||||
RUN /bin/bash -l -c "rvm install ruby-2.2.10" |
||||
RUN /bin/bash -l -c "rvm use --default ruby-2.2.10" |
||||
RUN /bin/bash -l -c "echo 'gem: --no-document' > ~/.gemrc" |
||||
RUN /bin/bash -l -c "echo 'export PATH=/usr/local/rvm/bin:$PATH' >> ~/.bashrc" |
||||
RUN /bin/bash -l -c "echo 'rvm --default use ruby-2.2.10' >> ~/.bashrc" |
||||
RUN /bin/bash -l -c "gem install bundler -v 1.17.3 --no-document" |
||||
|
||||
RUN mkdir /var/local/jenkins |
||||
|
||||
# Define the default command. |
||||
CMD ["bash"] |
Loading…
Reference in new issue