alts_unseal_privacy_integrity_crypter.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2018 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
20 
21 #include <grpc/support/alloc.h>
22 
26 
27 static void maybe_copy_error_msg(const char* src, char** dst) {
28  if (dst != nullptr && src != nullptr) {
29  *dst = static_cast<char*>(gpr_malloc(strlen(src) + 1));
30  memcpy(*dst, src, strlen(src) + 1);
31  }
32 }
33 
34 /* Perform input santity check. */
35 static grpc_status_code unseal_check(alts_crypter* c, const unsigned char* data,
36  size_t /*data_allocated_size*/,
37  size_t data_size, size_t* output_size,
38  char** error_details) {
39  /* Do common input sanity check. */
41  reinterpret_cast<const alts_record_protocol_crypter*>(c), data,
42  output_size, error_details);
43  if (status != GRPC_STATUS_OK) {
44  return status;
45  }
46  /* Do unseal-specific input check. */
47  size_t num_overhead_bytes =
48  alts_crypter_num_overhead_bytes(reinterpret_cast<const alts_crypter*>(c));
49  if (num_overhead_bytes > data_size) {
50  const char error_msg[] = "data_size is smaller than num_overhead_bytes.";
51  maybe_copy_error_msg(error_msg, error_details);
53  }
54  return GRPC_STATUS_OK;
55 }
56 
58  alts_crypter* c, unsigned char* data, size_t data_allocated_size,
59  size_t data_size, size_t* output_size, char** error_details) {
60  grpc_status_code status = unseal_check(c, data, data_allocated_size,
61  data_size, output_size, error_details);
62  if (status != GRPC_STATUS_OK) {
63  return status;
64  }
65  /* Do AEAD decryption. */
66  alts_record_protocol_crypter* rp_crypter =
67  reinterpret_cast<alts_record_protocol_crypter*>(c);
69  rp_crypter->crypter, alts_counter_get_counter(rp_crypter->ctr),
70  alts_counter_get_size(rp_crypter->ctr), nullptr /* aad */,
71  0 /* aad_length */, data, data_size, data, data_allocated_size,
72  output_size, error_details);
73  if (status != GRPC_STATUS_OK) {
74  return status;
75  }
76  /* Increment the crypter counter. */
77  return increment_counter(rp_crypter, error_details);
78 }
79 
80 static const alts_crypter_vtable vtable = {
84 
86  bool is_client,
87  size_t overflow_size,
88  alts_crypter** crypter,
89  char** error_details) {
90  if (crypter == nullptr) {
91  const char error_msg[] = "crypter is nullptr.";
92  maybe_copy_error_msg(error_msg, error_details);
94  }
95  alts_record_protocol_crypter* rp_crypter =
96  alts_crypter_create_common(gc, is_client, overflow_size, error_details);
97  if (rp_crypter == nullptr) {
99  }
100  rp_crypter->base.vtable = &vtable;
101  *crypter = &rp_crypter->base;
102  return GRPC_STATUS_OK;
103 }
dst
static const char dst[]
Definition: test-fs-copyfile.c:37
alts_counter_get_counter
unsigned char * alts_counter_get_counter(alts_counter *crypter_counter)
Definition: alts_counter.cc:106
alts_record_protocol_crypter_common.h
alts_counter.h
unseal_check
static grpc_status_code unseal_check(alts_crypter *c, const unsigned char *data, size_t, size_t data_size, size_t *output_size, char **error_details)
Definition: alts_unseal_privacy_integrity_crypter.cc:35
alts_crypter_create_common
alts_record_protocol_crypter * alts_crypter_create_common(gsec_aead_crypter *crypter, bool is_client, size_t overflow_size, char **error_details)
Definition: alts_record_protocol_crypter_common.cc:90
grpc_status_code
grpc_status_code
Definition: include/grpc/impl/codegen/status.h:28
alts_record_protocol_crypter
Definition: alts_record_protocol_crypter_common.h:38
alts_crypter_vtable
Definition: alts_crypter.h:124
gpr_malloc
GPRAPI void * gpr_malloc(size_t size)
Definition: alloc.cc:29
status
absl::Status status
Definition: rls.cc:251
alts_crypter.h
alts_crypter_num_overhead_bytes
size_t alts_crypter_num_overhead_bytes(const alts_crypter *crypter)
Definition: alts_crypter.cc:50
GRPC_STATUS_INVALID_ARGUMENT
@ GRPC_STATUS_INVALID_ARGUMENT
Definition: include/grpc/impl/codegen/status.h:46
maybe_copy_error_msg
static void maybe_copy_error_msg(const char *src, char **dst)
Definition: alts_unseal_privacy_integrity_crypter.cc:27
alts_counter_get_size
size_t alts_counter_get_size(alts_counter *crypter_counter)
Definition: alts_counter.cc:99
alts_unseal_crypter_create
grpc_status_code alts_unseal_crypter_create(gsec_aead_crypter *gc, bool is_client, size_t overflow_size, alts_crypter **crypter, char **error_details)
Definition: alts_unseal_privacy_integrity_crypter.cc:85
alts_record_protocol_crypter::crypter
gsec_aead_crypter * crypter
Definition: alts_record_protocol_crypter_common.h:40
increment_counter
grpc_status_code increment_counter(alts_record_protocol_crypter *rp_crypter, char **error_details)
Definition: alts_record_protocol_crypter_common.cc:48
memcpy
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
c
void c(T a)
Definition: miscompile_with_no_unique_address_test.cc:40
GRPC_STATUS_OK
@ GRPC_STATUS_OK
Definition: include/grpc/impl/codegen/status.h:30
alts_record_protocol_crypter_destruct
void alts_record_protocol_crypter_destruct(alts_crypter *c)
Definition: alts_record_protocol_crypter_common.cc:81
alts_record_protocol_crypter_num_overhead_bytes
size_t alts_record_protocol_crypter_num_overhead_bytes(const alts_crypter *c)
Definition: alts_record_protocol_crypter_common.cc:66
data
char data[kBufferLength]
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1006
alts_crypter
Definition: alts_crypter.h:135
gc
void gc(uv_timer_t *handle)
Definition: libuv/docs/code/ref-timer/main.c:9
alts_record_protocol_crypter::base
alts_crypter base
Definition: alts_record_protocol_crypter_common.h:39
alloc.h
alts_crypter::vtable
const alts_crypter_vtable * vtable
Definition: alts_crypter.h:136
alts_record_protocol_crypter::ctr
alts_counter * ctr
Definition: alts_record_protocol_crypter_common.h:41
GRPC_STATUS_FAILED_PRECONDITION
@ GRPC_STATUS_FAILED_PRECONDITION
Definition: include/grpc/impl/codegen/status.h:97
gsec_aead_crypter
Definition: gsec.h:178
vtable
static const alts_crypter_vtable vtable
Definition: alts_unseal_privacy_integrity_crypter.cc:80
alts_unseal_crypter_process_in_place
static grpc_status_code alts_unseal_crypter_process_in_place(alts_crypter *c, unsigned char *data, size_t data_allocated_size, size_t data_size, size_t *output_size, char **error_details)
Definition: alts_unseal_privacy_integrity_crypter.cc:57
gsec_aead_crypter_decrypt
grpc_status_code gsec_aead_crypter_decrypt(gsec_aead_crypter *crypter, const uint8_t *nonce, size_t nonce_length, const uint8_t *aad, size_t aad_length, const uint8_t *ciphertext_and_tag, size_t ciphertext_and_tag_length, uint8_t *plaintext, size_t plaintext_length, size_t *bytes_written, char **error_details)
Definition: gsec.cc:78
port_platform.h
input_sanity_check
grpc_status_code input_sanity_check(const alts_record_protocol_crypter *rp_crypter, const unsigned char *data, size_t *output_size, char **error_details)
Definition: alts_record_protocol_crypter_common.cc:32


grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:41