alts_iovec_record_protocol_test.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 #include <grpc/support/log.h>
23 
25 
26 constexpr size_t kMaxDataSize = 1024;
27 constexpr size_t kMaxSlices = 10;
28 constexpr size_t kSealRepeatTimes = 5;
29 constexpr size_t kTagLength = 16;
30 
31 /* Test fixtures for each test cases. */
37 };
38 
39 /* Test variables for protect/unprotect operations. */
42  size_t header_length;
45  size_t tag_length;
49  size_t data_length;
55 };
56 
57 /* --- Test utility functions. --- */
58 
59 static void randomly_slice(uint8_t* input, size_t input_length,
60  iovec_t** output, size_t* output_length) {
61  if (input_length == 0) {
62  *output = nullptr;
63  *output_length = 0;
64  return;
65  }
66  *output_length = gsec_test_bias_random_uint32(kMaxSlices) + 1;
67  *output = static_cast<iovec_t*>(gpr_malloc(*output_length * sizeof(iovec_t)));
68  for (size_t i = 0; i < *output_length - 1; i++) {
69  size_t slice_length =
70  gsec_test_bias_random_uint32(static_cast<uint32_t>(input_length));
71  iovec_t slice = {input, slice_length};
72  (*output)[i] = slice;
73  input += slice_length;
74  input_length -= slice_length;
75  }
76  iovec_t slice = {input, input_length};
77  (*output)[*output_length - 1] = slice;
78 }
79 
80 static size_t alter_random_byte(uint8_t* buf, size_t buf_length) {
81  GPR_ASSERT(buf != nullptr);
83  gsec_test_bias_random_uint32(static_cast<uint32_t>(buf_length));
84  (*(buf + offset))++;
85  return offset;
86 }
87 
88 static void revert_back_alter(uint8_t* buf, size_t offset) {
89  GPR_ASSERT(buf != nullptr);
90  (*(buf + offset))--;
91 }
92 
95  bool integrity_only) {
99  size_t overflow_size = 8;
100  size_t key_length = rekey ? kAes128GcmRekeyKeyLength : kAes128GcmKeyLength;
101  uint8_t* key;
102  gsec_test_random_array(&key, key_length);
103  gsec_aead_crypter* crypter = nullptr;
104  /* Create client record protocol for protect. */
106  key, key_length, kAesGcmNonceLength, kAesGcmTagLength, rekey,
107  &crypter, nullptr) == GRPC_STATUS_OK);
109  crypter, overflow_size, /*is_client=*/true, integrity_only,
110  /*is_protect=*/true, &fixture->client_protect,
111  nullptr) == GRPC_STATUS_OK);
112  /* Create client record protocol for unprotect. */
114  key, key_length, kAesGcmNonceLength, kAesGcmTagLength, rekey,
115  &crypter, nullptr) == GRPC_STATUS_OK);
117  crypter, overflow_size, /*is_client=*/true, integrity_only,
118  /*is_protect=*/false, &fixture->client_unprotect,
119  nullptr) == GRPC_STATUS_OK);
120  /* Create server record protocol for protect. */
122  key, key_length, kAesGcmNonceLength, kAesGcmTagLength, rekey,
123  &crypter, nullptr) == GRPC_STATUS_OK);
125  crypter, overflow_size, /*is_client=*/false, integrity_only,
126  /*is_protect=*/true, &fixture->server_protect,
127  nullptr) == GRPC_STATUS_OK);
128  /* Create server record protocol for unprotect. */
130  key, key_length, kAesGcmNonceLength, kAesGcmTagLength, rekey,
131  &crypter, nullptr) == GRPC_STATUS_OK);
133  crypter, overflow_size, /*is_client=*/false, integrity_only,
134  /*is_protect=*/false, &fixture->server_unprotect,
135  nullptr) == GRPC_STATUS_OK);
136 
137  gpr_free(key);
138  return fixture;
139 }
140 
143  if (fixture == nullptr) {
144  return;
145  }
147  alts_iovec_record_protocol_destroy(fixture->client_unprotect);
149  alts_iovec_record_protocol_destroy(fixture->server_unprotect);
150  gpr_free(fixture);
151 }
152 
155  auto* var = static_cast<alts_iovec_record_protocol_test_var*>(
157  /* Sets header buffer. */
159  var->header_buf = static_cast<uint8_t*>(gpr_malloc(var->header_length));
160  var->header_iovec.iov_base = var->header_buf;
161  var->header_iovec.iov_len = var->header_length;
162  /* Sets tag buffer. */
163  var->tag_length = kTagLength;
164  var->tag_buf = static_cast<uint8_t*>(gpr_malloc(var->tag_length));
165  var->tag_iovec.iov_base = var->tag_buf;
166  var->tag_iovec.iov_len = var->tag_length;
167  /* Randomly sets data buffer and duplicates to dup_buf. */
168  var->data_length = gsec_test_bias_random_uint32(kMaxDataSize) + 1;
169  var->data_buf = static_cast<uint8_t*>(gpr_malloc(var->data_length));
170  gsec_test_random_bytes(var->data_buf, var->data_length);
171  gsec_test_copy(var->data_buf, &var->dup_buf, var->data_length);
172  var->data_iovec = nullptr;
173  var->data_iovec_length = 0;
174  randomly_slice(var->data_buf, var->data_length, &var->data_iovec,
175  &var->data_iovec_length);
176  /* Sets protected iovec. */
177  size_t protected_buf_length =
178  var->header_length + var->data_length + var->tag_length;
179  var->protected_buf = static_cast<uint8_t*>(gpr_malloc(protected_buf_length));
180  var->protected_iovec.iov_base = var->protected_buf;
181  var->protected_iovec.iov_len = protected_buf_length;
182  /* Unprotected iovec points to data_buf. */
183  var->unprotected_iovec.iov_base = var->data_buf;
184  var->unprotected_iovec.iov_len = var->data_length;
185  return var;
186 }
187 
190  if (var == nullptr) {
191  return;
192  }
193  gpr_free(var->header_buf);
194  gpr_free(var->tag_buf);
195  gpr_free(var->data_buf);
196  gpr_free(var->dup_buf);
197  gpr_free(var->data_iovec);
198  gpr_free(var->protected_buf);
199  gpr_free(var);
200 }
201 
202 /* --- Integrity-only protect/unprotect tests. --- */
203 
206  for (size_t i = 0; i < kSealRepeatTimes; i++) {
209  /* Seals and then unseals. */
211  sender, var->data_iovec, var->data_iovec_length, var->header_iovec,
212  var->tag_iovec, nullptr);
214  gpr_free(var->data_iovec);
215  /* Randomly slices data buffer again. */
216  randomly_slice(var->data_buf, var->data_length, &var->data_iovec,
217  &var->data_iovec_length);
219  receiver, var->data_iovec, var->data_iovec_length, var->header_iovec,
220  var->tag_iovec, nullptr);
222  /* Makes sure data buffer has not been modified during
223  * seal/unseal. */
224  GPR_ASSERT(memcmp(var->data_buf, var->dup_buf, var->data_length) == 0);
226  }
227 }
228 
231  for (size_t i = 0; i < kSealRepeatTimes; i++) {
234  /* Seals and then unseals empty payload. */
236  sender, nullptr, 0, var->header_iovec, var->tag_iovec, nullptr);
239  receiver, nullptr, 0, var->header_iovec, var->tag_iovec, nullptr);
242  }
243 }
244 
247  /* Seals once. */
251  sender, var->data_iovec, var->data_iovec_length, var->header_iovec,
252  var->tag_iovec, nullptr);
255  /* Seals again. */
258  sender, var->data_iovec, var->data_iovec_length, var->header_iovec,
259  var->tag_iovec, nullptr);
261  /* Unseals the second frame. */
262  char* error_message = nullptr;
264  receiver, var->data_iovec, var->data_iovec_length, var->header_iovec,
265  var->tag_iovec, &error_message);
267  status, GRPC_STATUS_INTERNAL, error_message,
268  "Frame tag verification failed."));
269  gpr_free(error_message);
271 }
272 
275  /* Seals the data first. */
279  sender, var->data_iovec, var->data_iovec_length, var->header_iovec,
280  var->tag_iovec, nullptr);
282  /* Alter frame length field. */
283  char* error_message = nullptr;
284  size_t offset =
287  receiver, var->data_iovec, var->data_iovec_length, var->header_iovec,
288  var->tag_iovec, &error_message);
290  status, GRPC_STATUS_INTERNAL, error_message, "Bad frame length."));
291  gpr_free(error_message);
293  /* Alter message type field. */
297  receiver, var->data_iovec, var->data_iovec_length, var->header_iovec,
298  var->tag_iovec, &error_message);
300  status, GRPC_STATUS_INTERNAL, error_message,
301  "Unsupported message type."));
302  gpr_free(error_message);
304  /* Alter data. */
307  receiver, var->data_iovec, var->data_iovec_length, var->header_iovec,
308  var->tag_iovec, &error_message);
310  status, GRPC_STATUS_INTERNAL, error_message,
311  "Frame tag verification failed."));
312  gpr_free(error_message);
314  /* Alter tag. */
317  receiver, var->data_iovec, var->data_iovec_length, var->header_iovec,
318  var->tag_iovec, &error_message);
320  status, GRPC_STATUS_INTERNAL, error_message,
321  "Frame tag verification failed."));
322  gpr_free(error_message);
324  /* Reverted protected data should be verified correctly. */
326  receiver, var->data_iovec, var->data_iovec_length, var->header_iovec,
327  var->tag_iovec, nullptr);
329  GPR_ASSERT(memcmp(var->data_buf, var->dup_buf, var->data_length) == 0);
331 }
332 
336  char* error_message = nullptr;
337  /* Header buffer is nullptr. */
338  iovec_t header_iovec = {nullptr, var->header_length};
340  rp, var->data_iovec, var->data_iovec_length, header_iovec, var->tag_iovec,
341  &error_message);
343  status, GRPC_STATUS_INVALID_ARGUMENT, error_message,
344  "Header is nullptr."));
345  gpr_free(error_message);
346  /* Header buffer length is 0. */
347  header_iovec.iov_base = var->header_buf;
348  header_iovec.iov_len = 0;
350  rp, var->data_iovec, var->data_iovec_length, header_iovec, var->tag_iovec,
351  &error_message);
353  status, GRPC_STATUS_INVALID_ARGUMENT, error_message,
354  "Header length is incorrect."));
355  gpr_free(error_message);
356  /* Tag buffer is nullptr. */
357  iovec_t tag_iovec = {nullptr, var->tag_length};
359  rp, var->data_iovec, var->data_iovec_length, var->header_iovec, tag_iovec,
360  &error_message);
362  status, GRPC_STATUS_INVALID_ARGUMENT, error_message, "Tag is nullptr."));
363  gpr_free(error_message);
364  /* Tag buffer length is 0. */
365  tag_iovec.iov_base = var->tag_buf;
366  tag_iovec.iov_len = 0;
368  rp, var->data_iovec, var->data_iovec_length, var->header_iovec, tag_iovec,
369  &error_message);
371  status, GRPC_STATUS_INVALID_ARGUMENT, error_message,
372  "Tag length is incorrect."));
373  gpr_free(error_message);
375 }
376 
381  char* error_message = nullptr;
382  /* Header buffer is nullptr. */
383  iovec_t header_iovec = {nullptr, var->header_length};
385  rp, var->data_iovec, var->data_iovec_length, header_iovec, var->tag_iovec,
386  &error_message);
388  status, GRPC_STATUS_INVALID_ARGUMENT, error_message,
389  "Header is nullptr."));
390  gpr_free(error_message);
391  /* Header buffer length is 0. */
392  header_iovec.iov_base = var->header_buf;
393  header_iovec.iov_len = 0;
395  rp, var->data_iovec, var->data_iovec_length, header_iovec, var->tag_iovec,
396  &error_message);
398  status, GRPC_STATUS_INVALID_ARGUMENT, error_message,
399  "Header length is incorrect."));
400  gpr_free(error_message);
401  /* Tag buffer is nullptr. */
402  iovec_t tag_iovec = {nullptr, var->tag_length};
404  rp, var->data_iovec, var->data_iovec_length, var->header_iovec, tag_iovec,
405  &error_message);
407  status, GRPC_STATUS_INVALID_ARGUMENT, error_message, "Tag is nullptr."));
408  gpr_free(error_message);
409  /* Tag buffer length is 0. */
410  tag_iovec.iov_base = var->tag_buf;
411  tag_iovec.iov_len = 0;
413  rp, var->data_iovec, var->data_iovec_length, var->header_iovec, tag_iovec,
414  &error_message);
416  status, GRPC_STATUS_INVALID_ARGUMENT, error_message,
417  "Tag length is incorrect."));
418  gpr_free(error_message);
420 }
421 
422 /* --- Privacy-integrity protect/unprotect tests. --- */
423 
426  for (size_t i = 0; i < kSealRepeatTimes; i++) {
429  /* Seals and then unseals. */
432  sender, var->data_iovec, var->data_iovec_length,
433  var->protected_iovec, nullptr);
435  iovec_t header_iovec = {var->protected_buf, var->header_length};
436  gpr_free(var->data_iovec);
437  /* Randomly slices protected buffer, excluding the header. */
439  var->data_length + var->tag_length, &var->data_iovec,
440  &var->data_iovec_length);
442  receiver, header_iovec, var->data_iovec, var->data_iovec_length,
443  var->unprotected_iovec, nullptr);
445  /* Makes sure unprotected data are the same as the original. */
446  GPR_ASSERT(memcmp(var->data_buf, var->dup_buf, var->data_length) == 0);
448  }
449 }
450 
455  size_t empty_payload_frame_size = var->header_length + var->tag_length;
456  auto* protected_buf =
457  static_cast<uint8_t*>(gpr_malloc(empty_payload_frame_size));
458  for (size_t i = 0; i < kSealRepeatTimes; i++) {
459  iovec_t protected_iovec = {protected_buf, empty_payload_frame_size};
460  iovec_t unprotected_iovec = {nullptr, 0};
461  iovec_t data_iovec = {protected_buf + var->header_length, var->tag_length};
462  /* Seals and then unseals empty payload. */
465  sender, nullptr, 0, protected_iovec, nullptr);
467  iovec_t header_iovec = {protected_buf, var->header_length};
469  receiver, header_iovec, &data_iovec, 1, unprotected_iovec, nullptr);
471  }
472  gpr_free(protected_buf);
474 }
475 
478  /* Seals once. */
483  sender, var->data_iovec, var->data_iovec_length, var->protected_iovec,
484  nullptr);
487  /* Seals again. */
490  sender, var->data_iovec, var->data_iovec_length, var->protected_iovec,
491  nullptr);
493  /* Unseals the second frame. */
494  char* error_message = nullptr;
495  iovec_t header_iovec = {var->protected_buf, var->header_length};
496  iovec_t protected_iovec = {var->protected_buf + var->header_length,
497  var->data_length + var->tag_length};
499  receiver, header_iovec, &protected_iovec, 1, var->unprotected_iovec,
500  &error_message);
502  status, GRPC_STATUS_INTERNAL, error_message, "Frame decryption failed."));
503  gpr_free(error_message);
505 }
506 
509  /* Seals the data first. */
514  sender, var->data_iovec, var->data_iovec_length, var->protected_iovec,
515  nullptr);
517  char* error_message = nullptr;
518  uint8_t* header_buf = var->protected_buf;
519  size_t header_length = var->header_length;
520  iovec_t header_iovec = {header_buf, header_length};
521  /* The following protected_buf and protected_length excludes header. */
522  uint8_t* protected_buf = var->protected_buf + var->header_length;
523  size_t protected_length = var->data_length + var->tag_length;
524  iovec_t protected_iovec = {protected_buf, protected_length};
525  /* Alter frame length field. */
528  receiver, header_iovec, &protected_iovec, 1, var->unprotected_iovec,
529  &error_message);
531  status, GRPC_STATUS_INTERNAL, error_message, "Bad frame length."));
532  gpr_free(error_message);
533  revert_back_alter(header_buf, offset);
534  /* Alter message type field. */
538  receiver, header_iovec, &protected_iovec, 1, var->unprotected_iovec,
539  &error_message);
541  status, GRPC_STATUS_INTERNAL, error_message,
542  "Unsupported message type."));
543  gpr_free(error_message);
545  /* Alter protected data. */
546  offset = alter_random_byte(protected_buf, protected_length);
548  receiver, header_iovec, &protected_iovec, 1, var->unprotected_iovec,
549  &error_message);
551  status, GRPC_STATUS_INTERNAL, error_message, "Frame decryption failed."));
552  gpr_free(error_message);
553  revert_back_alter(protected_buf, offset);
554  /* Reverted protected data should be verified correctly. */
556  receiver, header_iovec, &protected_iovec, 1, var->unprotected_iovec,
557  nullptr);
559  GPR_ASSERT(memcmp(var->data_buf, var->dup_buf, var->data_length) == 0);
561 }
562 
567  char* error_message = nullptr;
568  /* Protected output buffer is nullptr. */
569  iovec_t protected_iovec = {nullptr, var->protected_iovec.iov_len};
572  rp, var->data_iovec, var->data_iovec_length, protected_iovec,
573  &error_message);
575  status, GRPC_STATUS_INVALID_ARGUMENT, error_message,
576  "Protected frame is nullptr."));
577  gpr_free(error_message);
578  /* Protected output buffer length incorrect. */
579  protected_iovec.iov_base = var->protected_buf;
580  protected_iovec.iov_len = var->header_length + var->data_length;
582  rp, var->data_iovec, var->data_iovec_length, protected_iovec,
583  &error_message);
585  status, GRPC_STATUS_INVALID_ARGUMENT, error_message,
586  "Protected frame size is incorrect."));
587  gpr_free(error_message);
589 }
590 
595  char* error_message = nullptr;
596  /* Header buffer is nullptr. */
597  iovec_t header_iovec = {var->protected_buf, var->header_length};
598  iovec_t protected_iovec = {var->protected_buf + var->header_length,
599  var->data_length + var->tag_length};
600  header_iovec.iov_base = nullptr;
603  rp, header_iovec, &protected_iovec, 1, var->unprotected_iovec,
604  &error_message);
606  status, GRPC_STATUS_INVALID_ARGUMENT, error_message,
607  "Header is nullptr."));
608  gpr_free(error_message);
609  header_iovec.iov_base = var->protected_buf;
610  /* Header buffer length is 0. */
611  header_iovec.iov_len = 0;
613  rp, header_iovec, &protected_iovec, 1, var->unprotected_iovec,
614  &error_message);
616  status, GRPC_STATUS_INVALID_ARGUMENT, error_message,
617  "Header length is incorrect."));
618  gpr_free(error_message);
619  header_iovec.iov_len = var->header_length;
620  /* Unprotected output buffer length is incorrect. */
621  iovec_t unprotected_iovec = {var->data_buf, var->data_length - 1};
623  rp, header_iovec, &protected_iovec, 1, unprotected_iovec, &error_message);
625  status, GRPC_STATUS_INVALID_ARGUMENT, error_message,
626  "Unprotected data size is incorrect."));
627  gpr_free(error_message);
629 }
630 
631 /* --- Integrity-only and privacy-integrity mixed. --- */
632 
634  alts_iovec_record_protocol* integrity_only_protect_rp,
635  alts_iovec_record_protocol* integrity_only_unprotect_rp,
636  alts_iovec_record_protocol* privacy_integrity_protect_rp,
637  alts_iovec_record_protocol* privacy_integrity_unprotect_rp) {
641  char* error_message = nullptr;
642  /* Call integrity-only protect on privacy-integrity record protocol. */
644  privacy_integrity_protect_rp, var->data_iovec, var->data_iovec_length,
645  var->header_iovec, var->tag_iovec, &error_message);
647  status, GRPC_STATUS_FAILED_PRECONDITION, error_message,
648  "Integrity-only operations are not allowed for this object."));
649  gpr_free(error_message);
650  /* Call integrity-only unprotect on privacy-integrity record protocol. */
652  privacy_integrity_unprotect_rp, var->data_iovec, var->data_iovec_length,
653  var->header_iovec, var->tag_iovec, &error_message);
655  status, GRPC_STATUS_FAILED_PRECONDITION, error_message,
656  "Integrity-only operations are not allowed for this object."));
657  gpr_free(error_message);
658  /* Call privacy-integrity protect on integrity-only record protocol. */
660  integrity_only_protect_rp, var->data_iovec, var->data_iovec_length,
661  var->protected_iovec, &error_message);
663  status, GRPC_STATUS_FAILED_PRECONDITION, error_message,
664  "Privacy-integrity operations are not allowed for this object."));
665  gpr_free(error_message);
666  /* Call privacy-integrity unprotect on integrity-only record protocol. */
668  integrity_only_unprotect_rp, var->header_iovec, var->data_iovec,
669  var->data_iovec_length, var->unprotected_iovec, &error_message);
671  status, GRPC_STATUS_FAILED_PRECONDITION, error_message,
672  "Privacy-integrity operations are not allowed for this object."));
673  gpr_free(error_message);
675 }
676 
678  alts_iovec_record_protocol* integrity_only_sender,
679  alts_iovec_record_protocol* privacy_integrity_receiver) {
683  char* error_message = nullptr;
684  /* Seals with integrity-only protect. */
686  integrity_only_sender, var->data_iovec, var->data_iovec_length,
687  var->header_iovec, var->tag_iovec, nullptr);
689  /* Unseal with privacy-integrity unprotect. */
690  memcpy(var->protected_buf, var->data_buf, var->data_length);
691  memcpy(var->protected_buf + var->data_length, var->tag_buf, var->tag_length);
692  iovec_t protected_iovec = {var->protected_buf,
693  var->data_length + var->tag_length};
695  privacy_integrity_receiver, var->header_iovec, &protected_iovec, 1,
696  var->unprotected_iovec, &error_message);
698  status, GRPC_STATUS_INTERNAL, error_message, "Frame decryption failed."));
699  gpr_free(error_message);
701 }
702 
704  alts_iovec_record_protocol* privacy_integrity_sender,
705  alts_iovec_record_protocol* integrity_only_receiver) {
709  char* error_message = nullptr;
710  /* Seals with privacy-integrity protect. */
712  privacy_integrity_sender, var->data_iovec, var->data_iovec_length,
713  var->protected_iovec, nullptr);
715  /* Unseal with integrity-only unprotect. */
716  iovec_t header_iovec = {var->protected_buf, var->header_length};
717  iovec_t data_iovec = {var->protected_buf + var->header_length,
718  var->data_length};
719  iovec_t tag_iovec = {
720  var->protected_buf + var->header_length + var->data_length,
721  var->tag_length};
723  integrity_only_receiver, &data_iovec, 1, header_iovec, tag_iovec,
724  &error_message);
726  status, GRPC_STATUS_INTERNAL, error_message,
727  "Frame tag verification failed."));
728  gpr_free(error_message);
730 }
731 
732 /* --- Test cases. --- */
733 
737  /*rekey=*/false, /*integrity_only=*/true);
739  fixture->server_unprotect);
741  fixture->client_unprotect);
743 
745  /*rekey=*/true, /*integrity_only=*/true);
747  fixture->server_unprotect);
749  fixture->client_unprotect);
751 
753  /*rekey=*/false, /*integrity_only=*/false);
755  fixture->server_unprotect);
757  fixture->client_unprotect);
759 
761  /*rekey=*/true, /*integrity_only=*/false);
763  fixture->server_unprotect);
765  fixture->client_unprotect);
767 }
768 
772  /*rekey=*/false, /*integrity_only=*/true);
774  fixture->server_unprotect);
776  fixture->client_unprotect);
778 
780  /*rekey=*/true, /*integrity_only=*/true);
782  fixture->server_unprotect);
784  fixture->client_unprotect);
786 
788  /*rekey=*/false, /*integrity_only=*/false);
790  fixture->server_unprotect);
792  fixture->client_unprotect);
794 
796  /*rekey=*/true, /*integrity_only=*/false);
798  fixture->server_unprotect);
800  fixture->client_unprotect);
802 }
803 
807  /*rekey=*/false, /*integrity_only=*/true);
809  fixture->server_unprotect);
811  fixture->client_unprotect);
813 
815  /*rekey=*/true, /*integrity_only=*/true);
817  fixture->server_unprotect);
819  fixture->client_unprotect);
821 
823  /*rekey=*/false, /*integrity_only=*/false);
825  fixture->server_unprotect);
827  fixture->client_unprotect);
829 
831  /*rekey=*/true, /*integrity_only=*/false);
833  fixture->server_unprotect);
835  fixture->client_unprotect);
837 }
838 
842  /*rekey=*/false, /*integrity_only=*/true);
843  integrity_only_corrupted_data(fixture->client_protect,
844  fixture->server_unprotect);
845  integrity_only_corrupted_data(fixture->server_protect,
846  fixture->client_unprotect);
848 
850  /*rekey=*/true, /*integrity_only=*/true);
851  integrity_only_corrupted_data(fixture->client_protect,
852  fixture->server_unprotect);
853  integrity_only_corrupted_data(fixture->server_protect,
854  fixture->client_unprotect);
856 
858  /*rekey=*/false, /*integrity_only=*/false);
860  fixture->server_unprotect);
862  fixture->client_unprotect);
864 
866  /*rekey=*/true, /*integrity_only=*/false);
868  fixture->server_unprotect);
870  fixture->client_unprotect);
872 }
873 
877  /*rekey=*/false, /*integrity_only=*/true);
881 
883  /*rekey=*/true, /*integrity_only=*/true);
887 
889  /*rekey=*/false, /*integrity_only=*/false);
893 
895  /*rekey=*/true, /*integrity_only=*/false);
899 }
900 
904  /*rekey=*/false, /*integrity_only=*/true);
907  /*rekey=*/false, /*integrity_only=*/false);
908 
910  fixture_1->client_protect, fixture_1->client_unprotect,
911  fixture_2->client_protect, fixture_2->client_unprotect);
913  fixture_2->server_unprotect);
915  fixture_1->server_unprotect);
916 
919 }
920 
921 int main(int /*argc*/, char** /*argv*/) {
928  return 0;
929 }
record_protocol_wrong_mode
static void record_protocol_wrong_mode(alts_iovec_record_protocol *integrity_only_protect_rp, alts_iovec_record_protocol *integrity_only_unprotect_rp, alts_iovec_record_protocol *privacy_integrity_protect_rp, alts_iovec_record_protocol *privacy_integrity_unprotect_rp)
Definition: alts_iovec_record_protocol_test.cc:633
log.h
main
int main(int, char **)
Definition: alts_iovec_record_protocol_test.cc:921
integrity_only_corrupted_data
static void integrity_only_corrupted_data(alts_iovec_record_protocol *sender, alts_iovec_record_protocol *receiver)
Definition: alts_iovec_record_protocol_test.cc:273
gsec_test_bias_random_uint32
uint32_t gsec_test_bias_random_uint32(uint32_t max_length)
Definition: gsec_test_util.cc:43
integrity_only_random_seal_unseal
static void integrity_only_random_seal_unseal(alts_iovec_record_protocol *sender, alts_iovec_record_protocol *receiver)
Definition: alts_iovec_record_protocol_test.cc:204
alts_iovec_record_protocol_test_var::unprotected_iovec
iovec_t unprotected_iovec
Definition: alts_iovec_record_protocol_test.cc:54
integrity_seal_privacy_unseal
static void integrity_seal_privacy_unseal(alts_iovec_record_protocol *integrity_only_sender, alts_iovec_record_protocol *privacy_integrity_receiver)
Definition: alts_iovec_record_protocol_test.cc:677
integrity_only_unsync_seal_unseal
static void integrity_only_unsync_seal_unseal(alts_iovec_record_protocol *sender, alts_iovec_record_protocol *receiver)
Definition: alts_iovec_record_protocol_test.cc:245
alts_iovec_record_protocol_test_fixture::server_unprotect
alts_iovec_record_protocol * server_unprotect
Definition: alts_iovec_record_protocol_test.cc:36
alts_iovec_record_protocol_test_fixture_destroy
static void alts_iovec_record_protocol_test_fixture_destroy(alts_iovec_record_protocol_test_fixture *fixture)
Definition: alts_iovec_record_protocol_test.cc:141
alts_iovec_record_protocol_test_var::data_iovec_length
size_t data_iovec_length
Definition: alts_iovec_record_protocol_test.cc:51
alts_iovec_record_protocol_test_var::protected_buf
uint8_t * protected_buf
Definition: alts_iovec_record_protocol_test.cc:52
alts_iovec_record_protocol
Definition: alts_iovec_record_protocol.cc:31
buf
voidpf void * buf
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
gpr_free
GPRAPI void gpr_free(void *ptr)
Definition: alloc.cc:51
alts_iovec_record_protocol_empty_seal_unseal_tests
static void alts_iovec_record_protocol_empty_seal_unseal_tests()
Definition: alts_iovec_record_protocol_test.cc:769
privacy_integrity_empty_seal_unseal
static void privacy_integrity_empty_seal_unseal(alts_iovec_record_protocol *sender, alts_iovec_record_protocol *receiver)
Definition: alts_iovec_record_protocol_test.cc:451
grpc_status_code
grpc_status_code
Definition: include/grpc/impl/codegen/status.h:28
alts_iovec_record_protocol_integrity_only_protect
grpc_status_code alts_iovec_record_protocol_integrity_only_protect(alts_iovec_record_protocol *rp, const iovec_t *unprotected_vec, size_t unprotected_vec_length, iovec_t header, iovec_t tag, char **error_details)
Definition: alts_iovec_record_protocol.cc:188
alts_iovec_record_protocol_test_var::dup_buf
uint8_t * dup_buf
Definition: alts_iovec_record_protocol_test.cc:48
gpr_malloc
GPRAPI void * gpr_malloc(size_t size)
Definition: alloc.cc:29
alts_iovec_record_protocol_destroy
void alts_iovec_record_protocol_destroy(alts_iovec_record_protocol *rp)
Definition: alts_iovec_record_protocol.cc:472
alts_iovec_record_protocol_corrupted_data_tests
static void alts_iovec_record_protocol_corrupted_data_tests()
Definition: alts_iovec_record_protocol_test.cc:839
gsec_test_random_array
void gsec_test_random_array(uint8_t **bytes, size_t length)
Definition: gsec_test_util.cc:33
status
absl::Status status
Definition: rls.cc:251
alts_iovec_record_protocol_test_fixture::server_protect
alts_iovec_record_protocol * server_protect
Definition: alts_iovec_record_protocol_test.cc:35
alts_iovec_record_protocol_test_fixture
Definition: alts_iovec_record_protocol_test.cc:32
gsec_aes_gcm_aead_crypter_create
grpc_status_code gsec_aes_gcm_aead_crypter_create(const uint8_t *key, size_t key_length, size_t nonce_length, size_t tag_length, bool rekey, gsec_aead_crypter **crypter, char **error_details)
Definition: aes_gcm.cc:633
GRPC_STATUS_INVALID_ARGUMENT
@ GRPC_STATUS_INVALID_ARGUMENT
Definition: include/grpc/impl/codegen/status.h:46
gsec_test_copy
void gsec_test_copy(const uint8_t *src, uint8_t **des, size_t source_len)
Definition: gsec_test_util.cc:49
uint8_t
unsigned char uint8_t
Definition: stdint-msvc2008.h:78
alts_iovec_record_protocol_test_var
Definition: alts_iovec_record_protocol_test.cc:40
kTagLength
constexpr size_t kTagLength
Definition: alts_iovec_record_protocol_test.cc:29
alts_iovec_record_protocol.h
privacy_integrity_protect_input_check
static void privacy_integrity_protect_input_check(alts_iovec_record_protocol *rp)
Definition: alts_iovec_record_protocol_test.cc:563
gpr_zalloc
GPRAPI void * gpr_zalloc(size_t size)
Definition: alloc.cc:40
privacy_integrity_unsync_seal_unseal
static void privacy_integrity_unsync_seal_unseal(alts_iovec_record_protocol *sender, alts_iovec_record_protocol *receiver)
Definition: alts_iovec_record_protocol_test.cc:476
uint32_t
unsigned int uint32_t
Definition: stdint-msvc2008.h:80
alts_iovec_record_protocol_test_var::tag_iovec
iovec_t tag_iovec
Definition: alts_iovec_record_protocol_test.cc:46
alter_random_byte
static size_t alter_random_byte(uint8_t *buf, size_t buf_length)
Definition: alts_iovec_record_protocol_test.cc:80
kZeroCopyFrameMessageTypeFieldSize
constexpr size_t kZeroCopyFrameMessageTypeFieldSize
Definition: alts_iovec_record_protocol.h:30
revert_back_alter
static void revert_back_alter(uint8_t *buf, size_t offset)
Definition: alts_iovec_record_protocol_test.cc:88
alts_iovec_record_protocol_test_var::header_length
size_t header_length
Definition: alts_iovec_record_protocol_test.cc:42
privacy_integrity_corrupted_data
static void privacy_integrity_corrupted_data(alts_iovec_record_protocol *sender, alts_iovec_record_protocol *receiver)
Definition: alts_iovec_record_protocol_test.cc:507
memcpy
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
integrity_only_unprotect_input_check
static void integrity_only_unprotect_input_check(alts_iovec_record_protocol *rp)
Definition: alts_iovec_record_protocol_test.cc:377
kMaxDataSize
constexpr size_t kMaxDataSize
Definition: alts_iovec_record_protocol_test.cc:26
kAesGcmNonceLength
const size_t kAesGcmNonceLength
Definition: gsec.h:47
alts_iovec_record_protocol_privacy_integrity_protect
grpc_status_code alts_iovec_record_protocol_privacy_integrity_protect(alts_iovec_record_protocol *rp, const iovec_t *unprotected_vec, size_t unprotected_vec_length, iovec_t protected_frame, char **error_details)
Definition: alts_iovec_record_protocol.cc:291
alts_iovec_record_protocol_privacy_integrity_unprotect
grpc_status_code alts_iovec_record_protocol_privacy_integrity_unprotect(alts_iovec_record_protocol *rp, iovec_t header, const iovec_t *protected_vec, size_t protected_vec_length, iovec_t unprotected_data, char **error_details)
Definition: alts_iovec_record_protocol.cc:357
alts_iovec_record_protocol_test_var::tag_length
size_t tag_length
Definition: alts_iovec_record_protocol_test.cc:45
GRPC_STATUS_OK
@ GRPC_STATUS_OK
Definition: include/grpc/impl/codegen/status.h:30
alts_iovec_record_protocol_unsync_seal_unseal_tests
static void alts_iovec_record_protocol_unsync_seal_unseal_tests()
Definition: alts_iovec_record_protocol_test.cc:804
GPR_ASSERT
#define GPR_ASSERT(x)
Definition: include/grpc/impl/codegen/log.h:94
integrity_only_empty_seal_unseal
static void integrity_only_empty_seal_unseal(alts_iovec_record_protocol *sender, alts_iovec_record_protocol *receiver)
Definition: alts_iovec_record_protocol_test.cc:229
fixture
static const char fixture[]
Definition: test-fs-copyfile.c:36
alts_iovec_record_protocol_random_seal_unseal_tests
static void alts_iovec_record_protocol_random_seal_unseal_tests()
Definition: alts_iovec_record_protocol_test.cc:734
alts_iovec_record_protocol_test_var::tag_buf
uint8_t * tag_buf
Definition: alts_iovec_record_protocol_test.cc:44
alts_iovec_record_protocol_test_var::protected_iovec
iovec_t protected_iovec
Definition: alts_iovec_record_protocol_test.cc:53
gmock_output_test.output
output
Definition: bloaty/third_party/googletest/googlemock/test/gmock_output_test.py:175
kAes128GcmRekeyKeyLength
const size_t kAes128GcmRekeyKeyLength
Definition: gsec.h:54
alts_iovec_record_protocol_test_var::data_buf
uint8_t * data_buf
Definition: alts_iovec_record_protocol_test.cc:47
slice
grpc_slice slice
Definition: src/core/lib/surface/server.cc:467
randomly_slice
static void randomly_slice(uint8_t *input, size_t input_length, iovec_t **output, size_t *output_length)
Definition: alts_iovec_record_protocol_test.cc:59
kMaxSlices
constexpr size_t kMaxSlices
Definition: alts_iovec_record_protocol_test.cc:27
gsec_test_util.h
privacy_integrity_unprotect_input_check
static void privacy_integrity_unprotect_input_check(alts_iovec_record_protocol *rp)
Definition: alts_iovec_record_protocol_test.cc:591
alts_iovec_record_protocol_get_header_length
size_t alts_iovec_record_protocol_get_header_length()
Definition: alts_iovec_record_protocol.cc:165
alts_iovec_record_protocol_test_fixture::client_unprotect
alts_iovec_record_protocol * client_unprotect
Definition: alts_iovec_record_protocol_test.cc:34
alts_iovec_record_protocol_integrity_only_unprotect
grpc_status_code alts_iovec_record_protocol_integrity_only_unprotect(alts_iovec_record_protocol *rp, const iovec_t *protected_vec, size_t protected_vec_length, iovec_t header, iovec_t tag, char **error_details)
Definition: alts_iovec_record_protocol.cc:243
alts_iovec_record_protocol_test_var::header_buf
uint8_t * header_buf
Definition: alts_iovec_record_protocol_test.cc:41
kSealRepeatTimes
constexpr size_t kSealRepeatTimes
Definition: alts_iovec_record_protocol_test.cc:28
iovec
Definition: gsec.h:33
key
const char * key
Definition: hpack_parser_table.cc:164
alts_iovec_record_protocol_test_fixture_create
static alts_iovec_record_protocol_test_fixture * alts_iovec_record_protocol_test_fixture_create(bool rekey, bool integrity_only)
Definition: alts_iovec_record_protocol_test.cc:94
iovec::iov_len
size_t iov_len
Definition: gsec.h:35
alts_iovec_record_protocol_test_var_create
static alts_iovec_record_protocol_test_var * alts_iovec_record_protocol_test_var_create()
Definition: alts_iovec_record_protocol_test.cc:154
alloc.h
alts_iovec_record_protocol_test_var::data_iovec
iovec_t * data_iovec
Definition: alts_iovec_record_protocol_test.cc:50
alts_iovec_record_protocol_mix_operations_tests
static void alts_iovec_record_protocol_mix_operations_tests()
Definition: alts_iovec_record_protocol_test.cc:901
alts_iovec_record_protocol_create
grpc_status_code alts_iovec_record_protocol_create(gsec_aead_crypter *crypter, size_t overflow_size, bool is_client, bool is_integrity_only, bool is_protect, alts_iovec_record_protocol **rp, char **error_details)
Definition: alts_iovec_record_protocol.cc:429
alts_iovec_record_protocol_input_check_tests
static void alts_iovec_record_protocol_input_check_tests()
Definition: alts_iovec_record_protocol_test.cc:874
privacy_seal_integrity_unseal
static void privacy_seal_integrity_unseal(alts_iovec_record_protocol *privacy_integrity_sender, alts_iovec_record_protocol *integrity_only_receiver)
Definition: alts_iovec_record_protocol_test.cc:703
alts_iovec_record_protocol_test_fixture::client_protect
alts_iovec_record_protocol * client_protect
Definition: alts_iovec_record_protocol_test.cc:33
alts_iovec_record_protocol_test_var::data_length
size_t data_length
Definition: alts_iovec_record_protocol_test.cc:49
gsec_test_expect_compare_code_and_substr
int gsec_test_expect_compare_code_and_substr(grpc_status_code status1, grpc_status_code status2, const char *msg1, const char *msg2)
Definition: gsec_test_util.cc:77
input
std::string input
Definition: bloaty/third_party/protobuf/src/google/protobuf/io/tokenizer_unittest.cc:197
GRPC_STATUS_FAILED_PRECONDITION
@ GRPC_STATUS_FAILED_PRECONDITION
Definition: include/grpc/impl/codegen/status.h:97
alts_iovec_record_protocol_test_var::header_iovec
iovec_t header_iovec
Definition: alts_iovec_record_protocol_test.cc:43
gsec_aead_crypter
Definition: gsec.h:178
privacy_integrity_random_seal_unseal
static void privacy_integrity_random_seal_unseal(alts_iovec_record_protocol *sender, alts_iovec_record_protocol *receiver)
Definition: alts_iovec_record_protocol_test.cc:424
GRPC_STATUS_INTERNAL
@ GRPC_STATUS_INTERNAL
Definition: include/grpc/impl/codegen/status.h:129
gsec_test_random_bytes
void gsec_test_random_bytes(uint8_t *bytes, size_t length)
Definition: gsec_test_util.cc:25
iovec::iov_base
void * iov_base
Definition: gsec.h:34
kZeroCopyFrameLengthFieldSize
constexpr size_t kZeroCopyFrameLengthFieldSize
Definition: alts_iovec_record_protocol.h:29
kAes128GcmKeyLength
const size_t kAes128GcmKeyLength
Definition: gsec.h:49
alts_iovec_record_protocol_test_var_destroy
static void alts_iovec_record_protocol_test_var_destroy(alts_iovec_record_protocol_test_var *var)
Definition: alts_iovec_record_protocol_test.cc:188
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
offset
voidpf uLong offset
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:142
kAesGcmTagLength
const size_t kAesGcmTagLength
Definition: gsec.h:48
integrity_only_protect_input_check
static void integrity_only_protect_input_check(alts_iovec_record_protocol *rp)
Definition: alts_iovec_record_protocol_test.cc:333


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