|
23 | 23 | import aws_encryption_sdk |
24 | 24 | import six |
25 | 25 |
|
26 | | -from aws_encryption_sdk_cli.exceptions import ParameterParseError |
| 26 | +from aws_encryption_sdk_cli.exceptions import BadUserArgumentError, ParameterParseError |
27 | 27 | from aws_encryption_sdk_cli.internal.identifiers import ( |
28 | 28 | ALGORITHM_NAMES, |
29 | 29 | DEFAULT_MASTER_KEY_PROVIDER, |
|
57 | 57 | _LOGGER = logging.getLogger(LOGGER_NAME) |
58 | 58 |
|
59 | 59 |
|
| 60 | +def _is_decrypt_mode(mode): |
| 61 | + # type: (str) -> bool |
| 62 | + """ |
| 63 | + Determines whether the provided mode does decryption |
| 64 | +
|
| 65 | + :param str filepath: Full file path to file in question |
| 66 | + :rtype: bool |
| 67 | + """ |
| 68 | + if mode in ("decrypt", "decrypt-unsigned"): |
| 69 | + return True |
| 70 | + if mode == "encrypt": |
| 71 | + return False |
| 72 | + raise BadUserArgumentError("Mode {mode} has not been implemented".format(mode=mode)) |
| 73 | + |
| 74 | + |
60 | 75 | class CommentIgnoringArgumentParser(argparse.ArgumentParser): |
61 | 76 | """``ArgumentParser`` that ignores lines in ``fromfile_prefix_chars`` files which start with ``#``.""" |
62 | 77 |
|
@@ -202,6 +217,14 @@ def _build_parser(): |
202 | 217 | "-d", "--decrypt", dest="action", action="store_const", const="decrypt", help="Decrypt data" |
203 | 218 | ) |
204 | 219 | parser.add_dummy_redirect_argument("--decrypt") |
| 220 | + operating_action.add_argument( |
| 221 | + "--decrypt-unsigned", |
| 222 | + dest="action", |
| 223 | + action="store_const", |
| 224 | + const="decrypt-unsigned", |
| 225 | + help="Decrypt data and enforce messages are unsigned during decryption.", |
| 226 | + ) |
| 227 | + parser.add_dummy_redirect_argument("--decrypt-unsigned") |
205 | 228 |
|
206 | 229 | # For each argument added to this group, a dummy redirect argument must |
207 | 230 | # be added to the parent parser for each long form option string. |
@@ -284,6 +307,10 @@ def _build_parser(): |
284 | 307 | ), |
285 | 308 | ) |
286 | 309 |
|
| 310 | + parser.add_argument( |
| 311 | + "-b", "--buffer", action="store_true", help="Buffer result in memory before releasing to output" |
| 312 | + ) |
| 313 | + |
287 | 314 | parser.add_argument( |
288 | 315 | "-i", |
289 | 316 | "--input", |
@@ -341,6 +368,13 @@ def _build_parser(): |
341 | 368 | ), |
342 | 369 | ) |
343 | 370 |
|
| 371 | + parser.add_argument( |
| 372 | + "--max-encrypted-data-keys", |
| 373 | + type=int, |
| 374 | + action=UniqueStoreAction, |
| 375 | + help="Maximum number of encrypted data keys to wrap (during encryption) or to unwrap (during decryption)", |
| 376 | + ) |
| 377 | + |
344 | 378 | parser.add_argument( |
345 | 379 | "--suffix", |
346 | 380 | nargs="?", |
@@ -496,7 +530,7 @@ def _process_master_key_provider_configs( |
496 | 530 | :raises ParameterParseError: if no key values are provided |
497 | 531 | """ |
498 | 532 | if raw_keys is None: |
499 | | - if action == "decrypt": |
| 533 | + if _is_decrypt_mode(action): |
500 | 534 | # We allow not defining any master key provider configuration if decrypting with aws-kms. |
501 | 535 | _LOGGER.debug( |
502 | 536 | "No master key provider config provided on decrypt request. Using aws-kms with no master keys." |
@@ -529,7 +563,9 @@ def _process_master_key_provider_configs( |
529 | 563 | ) |
530 | 564 | parsed_args["provider"] = provider[0] # type: ignore |
531 | 565 |
|
532 | | - aws_kms_on_decrypt = parsed_args["provider"] in ("aws-kms", DEFAULT_MASTER_KEY_PROVIDER) and action == "decrypt" |
| 566 | + aws_kms_on_decrypt = parsed_args["provider"] in ("aws-kms", DEFAULT_MASTER_KEY_PROVIDER) and _is_decrypt_mode( |
| 567 | + action |
| 568 | + ) |
533 | 569 |
|
534 | 570 | if aws_kms_on_decrypt: |
535 | 571 | if "key" in parsed_args: |
@@ -559,7 +595,7 @@ def _process_wrapping_key_provider_configs( # noqa: C901 |
559 | 595 | :raises ParameterParseError: if no key values are provided |
560 | 596 | """ |
561 | 597 | if raw_keys is None: |
562 | | - if action == "decrypt": |
| 598 | + if _is_decrypt_mode(action): |
563 | 599 | # We allow not defining any wrapping key provider configuration if decrypting with aws-kms. |
564 | 600 | _LOGGER.debug( |
565 | 601 | "No wrapping key provider config provided on decrypt request. Using aws-kms with no wrapping keys." |
@@ -592,7 +628,7 @@ def _process_wrapping_key_provider_configs( # noqa: C901 |
592 | 628 | _process_discovery_args(parsed_args) |
593 | 629 |
|
594 | 630 | discovery = parsed_args["discovery"] |
595 | | - if provider_is_kms and action == "decrypt": |
| 631 | + if provider_is_kms and _is_decrypt_mode(action): |
596 | 632 | if "key" in parsed_args and discovery: |
597 | 633 | # Decrypt MUST fail without attempting any decryption if discovery mode is enabled |
598 | 634 | # and at least one key=<Key ARN> parameter value is provided |
@@ -713,15 +749,15 @@ def parse_args(raw_args=None): # noqa |
713 | 749 | raise ParameterParseError("You cannot specify both the --master-keys and --wrapping-keys parameters") |
714 | 750 | if parsed_args.wrapping_keys: |
715 | 751 | if not parsed_args.commitment_policy: |
716 | | - raise ParameterParseError('Commitment policy is required when specifying the --wrapping-keys parameter') |
| 752 | + raise ParameterParseError("Commitment policy is required when specifying the --wrapping-keys parameter") |
717 | 753 |
|
718 | 754 | parsed_args.wrapping_keys = _process_wrapping_key_provider_configs( |
719 | 755 | parsed_args.wrapping_keys, parsed_args.action |
720 | 756 | ) |
721 | 757 | else: |
722 | 758 | if parsed_args.commitment_policy: |
723 | 759 | raise ParameterParseError( |
724 | | - 'Commitment policy is only supported when using the --wrapping-keys parameter' |
| 760 | + "Commitment policy is only supported when using the --wrapping-keys parameter" |
725 | 761 | ) |
726 | 762 |
|
727 | 763 | _LOGGER.warning( |
|
0 commit comments