Decrypt and return the data contained in cipher. :param key: the key to use for decryption :param key_usage_number: (optional) specify the key usage number. Guessed otherwise :param cls: (optional) the class of the decrypted payload
(self, key, key_usage_number=None, cls=None)
| 425 | ) |
| 426 | |
| 427 | def decrypt(self, key, key_usage_number=None, cls=None): |
| 428 | """ |
| 429 | Decrypt and return the data contained in cipher. |
| 430 | |
| 431 | :param key: the key to use for decryption |
| 432 | :param key_usage_number: (optional) specify the key usage number. |
| 433 | Guessed otherwise |
| 434 | :param cls: (optional) the class of the decrypted payload |
| 435 | Guessed otherwise (or bytes) |
| 436 | """ |
| 437 | if key_usage_number is None: |
| 438 | key_usage_number, cls = self.get_usage() |
| 439 | d = key.decrypt(key_usage_number, self.cipher.val) |
| 440 | if cls: |
| 441 | try: |
| 442 | return cls(d) |
| 443 | except BER_Decoding_Error: |
| 444 | if cls == EncASRepPart: |
| 445 | # https://datatracker.ietf.org/doc/html/rfc4120#section-5.4.2 |
| 446 | # "Compatibility note: Some implementations unconditionally send an |
| 447 | # encrypted EncTGSRepPart (application tag number 26) in this field |
| 448 | # regardless of whether the reply is a AS-REP or a TGS-REP. In the |
| 449 | # interest of compatibility, implementors MAY relax the check on the |
| 450 | # tag number of the decrypted ENC-PART." |
| 451 | try: |
| 452 | res = EncTGSRepPart(d) |
| 453 | # https://github.com/krb5/krb5/blob/48ccd81656381522d1f9ccb8705c13f0266a46ab/src/lib/krb5/asn.1/asn1_k_encode.c#L1128 |
| 454 | # This is a bug because as the RFC clearly says above, we're |
| 455 | # perfectly in our right to be strict on this. (MAY) |
| 456 | log_runtime.warning( |
| 457 | "Implementation bug detected. This looks like MIT Kerberos." |
| 458 | ) |
| 459 | return res |
| 460 | except BER_Decoding_Error: |
| 461 | pass |
| 462 | raise |
| 463 | return d |
| 464 | |
| 465 | def encrypt(self, key, text, confounder=None, key_usage_number=None): |
| 466 | """ |
no test coverage detected