Classes | Functions | Variables
alts_frame_protector.cc File Reference
#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"
Include dependency graph for alts_frame_protector.cc:

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
 

Function Documentation

◆ alts_create_frame_protector()

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.

  • key: a symmetric key used to seal/unseal frames.
  • key_size: the size of symmetric key.
  • is_client: a flag indicating if the frame protector will be used at client (is_client = true) or server (is_client = false) side.
  • is_rekey: a flag indicating if the frame protector will use an AEAD with rekeying.
  • max_protected_frame_size: an in/out parameter indicating max frame size to be used by the frame protector. If it is nullptr, the default frame size will be used. Otherwise, the provided frame size will be adjusted (if not falling into a valid frame range) and used.
  • self: a pointer to the frame protector returned from the method.

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.

◆ alts_destroy()

static void alts_destroy ( tsi_frame_protector self)
static

Definition at line 314 of file alts_frame_protector.cc.

◆ alts_protect()

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

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.

◆ alts_protect_flush()

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

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.

◆ alts_unprotect()

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

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.

◆ create_alts_crypters()

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

Definition at line 330 of file alts_frame_protector.cc.

◆ ensure_buffer_size()

static void ensure_buffer_size ( alts_frame_protector impl)
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.

◆ max_encrypted_payload_bytes()

static size_t max_encrypted_payload_bytes ( alts_frame_protector impl)
static

Definition at line 78 of file alts_frame_protector.cc.

◆ seal()

static tsi_result seal ( alts_frame_protector impl)
static

Definition at line 62 of file alts_frame_protector.cc.

◆ unseal()

static tsi_result unseal ( alts_frame_protector impl)
static

Definition at line 195 of file alts_frame_protector.cc.

Variable Documentation

◆ alts_frame_protector_vtable

const tsi_frame_protector_vtable alts_frame_protector_vtable
static
Initial value:

Definition at line 327 of file alts_frame_protector.cc.

◆ kAltsRecordProtocolFrameLimit

constexpr size_t kAltsRecordProtocolFrameLimit = 5
constexpr

Definition at line 43 of file alts_frame_protector.cc.

◆ kAltsRecordProtocolRekeyFrameLimit

constexpr size_t kAltsRecordProtocolRekeyFrameLimit = 8
constexpr

Definition at line 42 of file alts_frame_protector.cc.

◆ kDefaultFrameLength

constexpr size_t kDefaultFrameLength = 16 * 1024
constexpr

Definition at line 38 of file alts_frame_protector.cc.

◆ kMaxFrameLength

constexpr size_t kMaxFrameLength = 1024 * 1024
constexpr

Definition at line 39 of file alts_frame_protector.cc.

◆ kMinFrameLength

constexpr size_t kMinFrameLength = 1024
constexpr

Definition at line 37 of file alts_frame_protector.cc.

alts_unprotect
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)
Definition: alts_frame_protector.cc:234
alts_protect_flush
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)
Definition: alts_frame_protector.cc:82
alts_protect
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)
Definition: alts_frame_protector.cc:142
alts_destroy
static void alts_destroy(tsi_frame_protector *self)
Definition: alts_frame_protector.cc:314


grpc
Author(s):
autogenerated on Fri May 16 2025 03:01:02