Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
19cdb35a
Commit
19cdb35a
authored
10 years ago
by
jboeuf
Browse files
Options
Downloads
Plain Diff
Merge pull request #83 from ctiller/fix
Compile fix
parents
a6b4186e
be5c6e5e
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/core/tsi/fake_transport_security.c
+31
-30
31 additions, 30 deletions
src/core/tsi/fake_transport_security.c
src/core/tsi/fake_transport_security.h
+1
-1
1 addition, 1 deletion
src/core/tsi/fake_transport_security.h
with
32 additions
and
31 deletions
src/core/tsi/fake_transport_security.c
+
31
−
30
View file @
19cdb35a
...
@@ -37,6 +37,7 @@
...
@@ -37,6 +37,7 @@
#include
<string.h>
#include
<string.h>
#include
<grpc/support/log.h>
#include
<grpc/support/log.h>
#include
<grpc/support/port_platform.h>
#include
"src/core/tsi/transport_security.h"
#include
"src/core/tsi/transport_security.h"
/* --- Constants. ---*/
/* --- Constants. ---*/
...
@@ -52,9 +53,9 @@
...
@@ -52,9 +53,9 @@
the data encoded in little endian on 4 bytes. */
the data encoded in little endian on 4 bytes. */
typedef
struct
{
typedef
struct
{
unsigned
char
*
data
;
unsigned
char
*
data
;
uint32
_t
size
;
size
_t
size
;
uint32
_t
allocated_size
;
size
_t
allocated_size
;
uint32
_t
offset
;
size
_t
offset
;
int
needs_draining
;
int
needs_draining
;
}
tsi_fake_frame
;
}
tsi_fake_frame
;
...
@@ -80,7 +81,7 @@ typedef struct {
...
@@ -80,7 +81,7 @@ typedef struct {
tsi_frame_protector
base
;
tsi_frame_protector
base
;
tsi_fake_frame
protect_frame
;
tsi_fake_frame
protect_frame
;
tsi_fake_frame
unprotect_frame
;
tsi_fake_frame
unprotect_frame
;
uint32
_t
max_frame_size
;
size
_t
max_frame_size
;
}
tsi_fake_frame_protector
;
}
tsi_fake_frame_protector
;
/* --- Utils. ---*/
/* --- Utils. ---*/
...
@@ -110,12 +111,12 @@ static tsi_result tsi_fake_handshake_message_from_string(
...
@@ -110,12 +111,12 @@ static tsi_result tsi_fake_handshake_message_from_string(
return
TSI_DATA_CORRUPTED
;
return
TSI_DATA_CORRUPTED
;
}
}
static
uint32
_t
load32_little_endian
(
const
unsigned
char
*
buf
)
{
static
gpr_
uint32
load32_little_endian
(
const
unsigned
char
*
buf
)
{
return
((
uint32
_t
)(
buf
[
0
])
|
(
uint32
_t
)(
buf
[
1
]
<<
8
)
|
return
((
gpr_
uint32
)(
buf
[
0
])
|
(
gpr_
uint32
)(
buf
[
1
]
<<
8
)
|
(
uint32
_t
)(
buf
[
2
]
<<
16
)
|
(
uint32
_t
)(
buf
[
3
]
<<
24
));
(
gpr_
uint32
)(
buf
[
2
]
<<
16
)
|
(
gpr_
uint32
)(
buf
[
3
]
<<
24
));
}
}
static
void
store32_little_endian
(
uint32
_t
value
,
unsigned
char
*
buf
)
{
static
void
store32_little_endian
(
gpr_
uint32
value
,
unsigned
char
*
buf
)
{
buf
[
3
]
=
(
unsigned
char
)(
value
>>
24
)
&
0xFF
;
buf
[
3
]
=
(
unsigned
char
)(
value
>>
24
)
&
0xFF
;
buf
[
2
]
=
(
unsigned
char
)(
value
>>
16
)
&
0xFF
;
buf
[
2
]
=
(
unsigned
char
)(
value
>>
16
)
&
0xFF
;
buf
[
1
]
=
(
unsigned
char
)(
value
>>
8
)
&
0xFF
;
buf
[
1
]
=
(
unsigned
char
)(
value
>>
8
)
&
0xFF
;
...
@@ -149,10 +150,10 @@ static int tsi_fake_frame_ensure_size(tsi_fake_frame* frame) {
...
@@ -149,10 +150,10 @@ static int tsi_fake_frame_ensure_size(tsi_fake_frame* frame) {
/* This method should not be called if frame->needs_framing is not 0. */
/* This method should not be called if frame->needs_framing is not 0. */
static
tsi_result
fill_frame_from_bytes
(
const
unsigned
char
*
incoming_bytes
,
static
tsi_result
fill_frame_from_bytes
(
const
unsigned
char
*
incoming_bytes
,
uint32
_t
*
incoming_bytes_size
,
size
_t
*
incoming_bytes_size
,
tsi_fake_frame
*
frame
)
{
tsi_fake_frame
*
frame
)
{
uint32
_t
available_size
=
*
incoming_bytes_size
;
size
_t
available_size
=
*
incoming_bytes_size
;
uint32
_t
to_read_size
=
0
;
size
_t
to_read_size
=
0
;
const
unsigned
char
*
bytes_cursor
=
incoming_bytes
;
const
unsigned
char
*
bytes_cursor
=
incoming_bytes
;
if
(
frame
->
needs_draining
)
return
TSI_INTERNAL_ERROR
;
if
(
frame
->
needs_draining
)
return
TSI_INTERNAL_ERROR
;
...
@@ -197,9 +198,9 @@ static tsi_result fill_frame_from_bytes(const unsigned char* incoming_bytes,
...
@@ -197,9 +198,9 @@ static tsi_result fill_frame_from_bytes(const unsigned char* incoming_bytes,
/* This method should not be called if frame->needs_framing is 0. */
/* This method should not be called if frame->needs_framing is 0. */
static
tsi_result
drain_frame_to_bytes
(
unsigned
char
*
outgoing_bytes
,
static
tsi_result
drain_frame_to_bytes
(
unsigned
char
*
outgoing_bytes
,
uint32
_t
*
outgoing_bytes_size
,
size
_t
*
outgoing_bytes_size
,
tsi_fake_frame
*
frame
)
{
tsi_fake_frame
*
frame
)
{
uint32
_t
to_write_size
=
frame
->
size
-
frame
->
offset
;
size
_t
to_write_size
=
frame
->
size
-
frame
->
offset
;
if
(
!
frame
->
needs_draining
)
return
TSI_INTERNAL_ERROR
;
if
(
!
frame
->
needs_draining
)
return
TSI_INTERNAL_ERROR
;
if
(
*
outgoing_bytes_size
<
to_write_size
)
{
if
(
*
outgoing_bytes_size
<
to_write_size
)
{
memcpy
(
outgoing_bytes
,
frame
->
data
+
frame
->
offset
,
*
outgoing_bytes_size
);
memcpy
(
outgoing_bytes
,
frame
->
data
+
frame
->
offset
,
*
outgoing_bytes_size
);
...
@@ -212,7 +213,7 @@ static tsi_result drain_frame_to_bytes(unsigned char* outgoing_bytes,
...
@@ -212,7 +213,7 @@ static tsi_result drain_frame_to_bytes(unsigned char* outgoing_bytes,
return
TSI_OK
;
return
TSI_OK
;
}
}
static
tsi_result
bytes_to_frame
(
unsigned
char
*
bytes
,
uint32
_t
bytes_size
,
static
tsi_result
bytes_to_frame
(
unsigned
char
*
bytes
,
size
_t
bytes_size
,
tsi_fake_frame
*
frame
)
{
tsi_fake_frame
*
frame
)
{
frame
->
offset
=
0
;
frame
->
offset
=
0
;
frame
->
size
=
bytes_size
+
TSI_FAKE_FRAME_HEADER_SIZE
;
frame
->
size
=
bytes_size
+
TSI_FAKE_FRAME_HEADER_SIZE
;
...
@@ -231,15 +232,15 @@ static void tsi_fake_frame_destruct(tsi_fake_frame* frame) {
...
@@ -231,15 +232,15 @@ static void tsi_fake_frame_destruct(tsi_fake_frame* frame) {
static
tsi_result
fake_protector_protect
(
static
tsi_result
fake_protector_protect
(
tsi_frame_protector
*
self
,
const
unsigned
char
*
unprotected_bytes
,
tsi_frame_protector
*
self
,
const
unsigned
char
*
unprotected_bytes
,
uint32
_t
*
unprotected_bytes_size
,
unsigned
char
*
protected_output_frames
,
size
_t
*
unprotected_bytes_size
,
unsigned
char
*
protected_output_frames
,
uint32
_t
*
protected_output_frames_size
)
{
size
_t
*
protected_output_frames_size
)
{
tsi_result
result
=
TSI_OK
;
tsi_result
result
=
TSI_OK
;
tsi_fake_frame_protector
*
impl
=
(
tsi_fake_frame_protector
*
)
self
;
tsi_fake_frame_protector
*
impl
=
(
tsi_fake_frame_protector
*
)
self
;
unsigned
char
frame_header
[
TSI_FAKE_FRAME_HEADER_SIZE
];
unsigned
char
frame_header
[
TSI_FAKE_FRAME_HEADER_SIZE
];
tsi_fake_frame
*
frame
=
&
impl
->
protect_frame
;
tsi_fake_frame
*
frame
=
&
impl
->
protect_frame
;
uint32
_t
saved_output_size
=
*
protected_output_frames_size
;
size
_t
saved_output_size
=
*
protected_output_frames_size
;
uint32
_t
drained_size
=
0
;
size
_t
drained_size
=
0
;
uint32
_t
*
num_bytes_written
=
protected_output_frames_size
;
size
_t
*
num_bytes_written
=
protected_output_frames_size
;
*
num_bytes_written
=
0
;
*
num_bytes_written
=
0
;
/* Try to drain first. */
/* Try to drain first. */
...
@@ -262,7 +263,7 @@ static tsi_result fake_protector_protect(
...
@@ -262,7 +263,7 @@ static tsi_result fake_protector_protect(
if
(
frame
->
needs_draining
)
return
TSI_INTERNAL_ERROR
;
if
(
frame
->
needs_draining
)
return
TSI_INTERNAL_ERROR
;
if
(
frame
->
size
==
0
)
{
if
(
frame
->
size
==
0
)
{
/* New frame, create a header. */
/* New frame, create a header. */
uint32
_t
written_in_frame_size
=
0
;
size
_t
written_in_frame_size
=
0
;
store32_little_endian
(
impl
->
max_frame_size
,
frame_header
);
store32_little_endian
(
impl
->
max_frame_size
,
frame_header
);
written_in_frame_size
=
TSI_FAKE_FRAME_HEADER_SIZE
;
written_in_frame_size
=
TSI_FAKE_FRAME_HEADER_SIZE
;
result
=
fill_frame_from_bytes
(
frame_header
,
&
written_in_frame_size
,
frame
);
result
=
fill_frame_from_bytes
(
frame_header
,
&
written_in_frame_size
,
frame
);
...
@@ -291,7 +292,7 @@ static tsi_result fake_protector_protect(
...
@@ -291,7 +292,7 @@ static tsi_result fake_protector_protect(
static
tsi_result
fake_protector_protect_flush
(
static
tsi_result
fake_protector_protect_flush
(
tsi_frame_protector
*
self
,
unsigned
char
*
protected_output_frames
,
tsi_frame_protector
*
self
,
unsigned
char
*
protected_output_frames
,
uint32
_t
*
protected_output_frames_size
,
uint32
_t
*
still_pending_size
)
{
size
_t
*
protected_output_frames_size
,
size
_t
*
still_pending_size
)
{
tsi_result
result
=
TSI_OK
;
tsi_result
result
=
TSI_OK
;
tsi_fake_frame_protector
*
impl
=
(
tsi_fake_frame_protector
*
)
self
;
tsi_fake_frame_protector
*
impl
=
(
tsi_fake_frame_protector
*
)
self
;
tsi_fake_frame
*
frame
=
&
impl
->
protect_frame
;
tsi_fake_frame
*
frame
=
&
impl
->
protect_frame
;
...
@@ -311,14 +312,14 @@ static tsi_result fake_protector_protect_flush(
...
@@ -311,14 +312,14 @@ static tsi_result fake_protector_protect_flush(
static
tsi_result
fake_protector_unprotect
(
static
tsi_result
fake_protector_unprotect
(
tsi_frame_protector
*
self
,
const
unsigned
char
*
protected_frames_bytes
,
tsi_frame_protector
*
self
,
const
unsigned
char
*
protected_frames_bytes
,
uint32
_t
*
protected_frames_bytes_size
,
unsigned
char
*
unprotected_bytes
,
size
_t
*
protected_frames_bytes_size
,
unsigned
char
*
unprotected_bytes
,
uint32
_t
*
unprotected_bytes_size
)
{
size
_t
*
unprotected_bytes_size
)
{
tsi_result
result
=
TSI_OK
;
tsi_result
result
=
TSI_OK
;
tsi_fake_frame_protector
*
impl
=
(
tsi_fake_frame_protector
*
)
self
;
tsi_fake_frame_protector
*
impl
=
(
tsi_fake_frame_protector
*
)
self
;
tsi_fake_frame
*
frame
=
&
impl
->
unprotect_frame
;
tsi_fake_frame
*
frame
=
&
impl
->
unprotect_frame
;
uint32
_t
saved_output_size
=
*
unprotected_bytes_size
;
size
_t
saved_output_size
=
*
unprotected_bytes_size
;
uint32
_t
drained_size
=
0
;
size
_t
drained_size
=
0
;
uint32
_t
*
num_bytes_written
=
unprotected_bytes_size
;
size
_t
*
num_bytes_written
=
unprotected_bytes_size
;
*
num_bytes_written
=
0
;
*
num_bytes_written
=
0
;
/* Try to drain first. */
/* Try to drain first. */
...
@@ -373,7 +374,7 @@ static const tsi_frame_protector_vtable frame_protector_vtable = {
...
@@ -373,7 +374,7 @@ static const tsi_frame_protector_vtable frame_protector_vtable = {
/* --- tsi_handshaker methods implementation. ---*/
/* --- tsi_handshaker methods implementation. ---*/
static
tsi_result
fake_handshaker_get_bytes_to_send_to_peer
(
static
tsi_result
fake_handshaker_get_bytes_to_send_to_peer
(
tsi_handshaker
*
self
,
unsigned
char
*
bytes
,
uint32
_t
*
bytes_size
)
{
tsi_handshaker
*
self
,
unsigned
char
*
bytes
,
size
_t
*
bytes_size
)
{
tsi_fake_handshaker
*
impl
=
(
tsi_fake_handshaker
*
)
self
;
tsi_fake_handshaker
*
impl
=
(
tsi_fake_handshaker
*
)
self
;
tsi_result
result
=
TSI_OK
;
tsi_result
result
=
TSI_OK
;
if
(
impl
->
needs_incoming_message
||
impl
->
result
==
TSI_OK
)
{
if
(
impl
->
needs_incoming_message
||
impl
->
result
==
TSI_OK
)
{
...
@@ -408,7 +409,7 @@ static tsi_result fake_handshaker_get_bytes_to_send_to_peer(
...
@@ -408,7 +409,7 @@ static tsi_result fake_handshaker_get_bytes_to_send_to_peer(
}
}
static
tsi_result
fake_handshaker_process_bytes_from_peer
(
static
tsi_result
fake_handshaker_process_bytes_from_peer
(
tsi_handshaker
*
self
,
const
unsigned
char
*
bytes
,
uint32
_t
*
bytes_size
)
{
tsi_handshaker
*
self
,
const
unsigned
char
*
bytes
,
size
_t
*
bytes_size
)
{
tsi_result
result
=
TSI_OK
;
tsi_result
result
=
TSI_OK
;
tsi_fake_handshaker
*
impl
=
(
tsi_fake_handshaker
*
)
self
;
tsi_fake_handshaker
*
impl
=
(
tsi_fake_handshaker
*
)
self
;
int
expected_msg
=
impl
->
next_message_to_send
-
1
;
int
expected_msg
=
impl
->
next_message_to_send
-
1
;
...
@@ -463,7 +464,7 @@ static tsi_result fake_handshaker_extract_peer(tsi_handshaker* self,
...
@@ -463,7 +464,7 @@ static tsi_result fake_handshaker_extract_peer(tsi_handshaker* self,
}
}
static
tsi_result
fake_handshaker_create_frame_protector
(
static
tsi_result
fake_handshaker_create_frame_protector
(
tsi_handshaker
*
self
,
uint32
_t
*
max_protected_frame_size
,
tsi_handshaker
*
self
,
size
_t
*
max_protected_frame_size
,
tsi_frame_protector
**
protector
)
{
tsi_frame_protector
**
protector
)
{
*
protector
=
tsi_create_fake_protector
(
max_protected_frame_size
);
*
protector
=
tsi_create_fake_protector
(
max_protected_frame_size
);
if
(
*
protector
==
NULL
)
return
TSI_OUT_OF_RESOURCES
;
if
(
*
protector
==
NULL
)
return
TSI_OUT_OF_RESOURCES
;
...
@@ -500,7 +501,7 @@ tsi_handshaker* tsi_create_fake_handshaker(int is_client) {
...
@@ -500,7 +501,7 @@ tsi_handshaker* tsi_create_fake_handshaker(int is_client) {
}
}
tsi_frame_protector
*
tsi_create_fake_protector
(
tsi_frame_protector
*
tsi_create_fake_protector
(
uint32
_t
*
max_protected_frame_size
)
{
size
_t
*
max_protected_frame_size
)
{
tsi_fake_frame_protector
*
impl
=
calloc
(
1
,
sizeof
(
tsi_fake_frame_protector
));
tsi_fake_frame_protector
*
impl
=
calloc
(
1
,
sizeof
(
tsi_fake_frame_protector
));
if
(
impl
==
NULL
)
return
NULL
;
if
(
impl
==
NULL
)
return
NULL
;
impl
->
max_frame_size
=
(
max_protected_frame_size
==
NULL
)
impl
->
max_frame_size
=
(
max_protected_frame_size
==
NULL
)
...
...
This diff is collapsed.
Click to expand it.
src/core/tsi/fake_transport_security.h
+
1
−
1
View file @
19cdb35a
...
@@ -52,7 +52,7 @@ tsi_handshaker* tsi_create_fake_handshaker(int is_client);
...
@@ -52,7 +52,7 @@ tsi_handshaker* tsi_create_fake_handshaker(int is_client);
/* Creates a protector directly without going through the handshake phase. */
/* Creates a protector directly without going through the handshake phase. */
tsi_frame_protector
*
tsi_create_fake_protector
(
tsi_frame_protector
*
tsi_create_fake_protector
(
uint32
_t
*
max_protected_frame_size
);
size
_t
*
max_protected_frame_size
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment