#include <grpc/support/port_platform.h>
#include "src/core/tsi/alts/frame_protector/alts_frame_protector.h"
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/lib/gpr/useful.h"
#include "src/core/tsi/alts/crypt/gsec.h"
#include "src/core/tsi/alts/frame_protector/alts_crypter.h"
#include "src/core/tsi/alts/frame_protector/frame_handler.h"
#include "src/core/tsi/transport_security.h"
Go to the source code of this file.
Classes | |
struct | alts_frame_protector |
Functions | |
tsi_result | alts_create_frame_protector (const uint8_t *key, size_t key_size, bool is_client, bool is_rekey, size_t *max_protected_frame_size, tsi_frame_protector **self) |
static void | alts_destroy (tsi_frame_protector *self) |
static tsi_result | alts_protect (tsi_frame_protector *self, const unsigned char *unprotected_bytes, size_t *unprotected_bytes_size, unsigned char *protected_output_frames, size_t *protected_output_frames_size) |
static tsi_result | alts_protect_flush (tsi_frame_protector *self, unsigned char *protected_output_frames, size_t *protected_output_frames_size, size_t *still_pending_size) |
static tsi_result | alts_unprotect (tsi_frame_protector *self, const unsigned char *protected_frames_bytes, size_t *protected_frames_bytes_size, unsigned char *unprotected_bytes, size_t *unprotected_bytes_size) |
static grpc_status_code | create_alts_crypters (const uint8_t *key, size_t key_size, bool is_client, bool is_rekey, alts_frame_protector *impl, char **error_details) |
static void | ensure_buffer_size (alts_frame_protector *impl) |
static size_t | max_encrypted_payload_bytes (alts_frame_protector *impl) |
static tsi_result | seal (alts_frame_protector *impl) |
static tsi_result | unseal (alts_frame_protector *impl) |
Variables | |
static const tsi_frame_protector_vtable | alts_frame_protector_vtable |
constexpr size_t | kAltsRecordProtocolFrameLimit = 5 |
constexpr size_t | kAltsRecordProtocolRekeyFrameLimit = 8 |
constexpr size_t | kDefaultFrameLength = 16 * 1024 |
constexpr size_t | kMaxFrameLength = 1024 * 1024 |
constexpr size_t | kMinFrameLength = 1024 |
tsi_result alts_create_frame_protector | ( | const uint8_t * | key, |
size_t | key_size, | ||
bool | is_client, | ||
bool | is_rekey, | ||
size_t * | max_protected_frame_size, | ||
tsi_frame_protector ** | self | ||
) |
TODO: Add a parameter to the interface to support the use of different record protocols within a frame protector.
This method creates a frame protector.
This method returns TSI_OK on success and TSI_INTERNAL_ERROR otherwise.
Set maximum frame size to be used by a frame protector. If it is nullptr, a default frame size will be used. Otherwise, the provided frame size will be adjusted (if not falling into a valid frame range) and used.
Definition at line 363 of file alts_frame_protector.cc.
|
static |
Definition at line 314 of file alts_frame_protector.cc.
|
static |
If more payload can be buffered, we buffer it as much as possible to in_place_protect_buffer.
If a full frame has been buffered, we output it. If the first condition holds, then there exists an unencrypted full frame. If the second condition holds, then there exists a full frame that has already been encrypted.
Definition at line 142 of file alts_frame_protector.cc.
|
static |
If there's nothing to flush (i.e., in_place_protect_buffer is empty), we're done.
If a new frame can start being processed, we encrypt the payload and reset the frame writer to point to in_place_protect_buffer that holds the newly sealed frame.
Write the sealed frame as much as possible to protected_output_frames. It's possible a frame will not be written out completely by a single flush (i.e., still_pending_size != 0), in which case the flush should be called iteratively until a complete frame has been written out.
If the current frame has been finished processing (i.e., sealed and written out completely), we empty in_place_protect_buffer.
Definition at line 82 of file alts_frame_protector.cc.
|
static |
If a new frame can start being processed, we reset the frame reader to point to in_place_unprotect_buffer that will be used to hold deframed result.
If a full frame has not yet been read, we read more bytes from protected_frames_bytes until a full frame has been read. We also need to make sure in_place_unprotect_buffer is large enough to hold a complete frame.
If a full frame has been read, we unseal it, and write out the deframed result to unprotected_bytes.
Definition at line 234 of file alts_frame_protector.cc.
|
static |
Definition at line 330 of file alts_frame_protector.cc.
|
static |
Check if we need to resize in_place_unprotect_buffer in order to hold remaining bytes of a full frame.
Definition at line 210 of file alts_frame_protector.cc.
|
static |
Definition at line 78 of file alts_frame_protector.cc.
|
static |
Definition at line 62 of file alts_frame_protector.cc.
|
static |
Definition at line 195 of file alts_frame_protector.cc.
|
static |
Definition at line 327 of file alts_frame_protector.cc.
|
constexpr |
Definition at line 43 of file alts_frame_protector.cc.
|
constexpr |
Definition at line 42 of file alts_frame_protector.cc.
|
constexpr |
Definition at line 38 of file alts_frame_protector.cc.
|
constexpr |
Definition at line 39 of file alts_frame_protector.cc.
|
constexpr |
Definition at line 37 of file alts_frame_protector.cc.