MCPcopy Create free account
hub / github.com/adobe/Marinus / __parse_sct

Method __parse_sct

python3_cron_scripts/libs3/X509Parser.py:653–724  ·  view source on GitHub ↗

Parse the SCT signature record. The Python cryptography library provides some parsing functionality but it does not provide details on the signature itself. This method provides the complete details.

(self, asn1_sctList, sct_type)

Source from the content-addressed store, hash-verified

651 return buf[:count], buf[count:]
652
653 def __parse_sct(self, asn1_sctList, sct_type):
654 """
655 Parse the SCT signature record.
656
657 The Python cryptography library provides some parsing functionality but
658 it does not provide details on the signature itself. This method provides
659 the complete details.
660 """
661 header, header_data = self.__splitBytes(asn1_sctList, 2)
662 if header[1] ^ 0x80 == 1:
663 _, data = self.__splitBytes(header_data, 1)
664 elif header[1] ^ 0x80 == 2:
665 _, data = self.__splitBytes(header_data, 2)
666 else:
667 self._logger.error("Unexpected SCTS header length")
668 raise ValueError("Unexpected SCTS header length")
669 scts = []
670
671 # Length is an unsigned short
672 packed_len, data = self.__splitBytes(data, 2)
673 total_len = struct.unpack("!H", packed_len)[0]
674 if len(data) != total_len:
675 self._logger.error(
676 "SCT ERROR: data length: "
677 + str(len(data))
678 + " Total length: "
679 + str(total_len)
680 )
681 raise ValueError("Malformed length of SCT list")
682
683 bytes_read = 0
684
685 while bytes_read < total_len:
686 packed_len, data = self.__splitBytes(data, 2)
687 sct_len = struct.unpack("!H", packed_len)[0]
688
689 bytes_read += sct_len + 2
690 sct_data, data = self.__splitBytes(data, sct_len)
691 packed_vlt, sct_data = self.__splitBytes(sct_data, 41)
692 version, logid, timestamp = struct.unpack("!B32sQ", packed_vlt)
693 timestamp = datetime.fromtimestamp(timestamp / 1000.0)
694
695 packed_len, sct_data = self.__splitBytes(sct_data, 2)
696 ext_len = struct.unpack("!H", packed_len)[0]
697 extensions, sct_data = self.__splitBytes(sct_data, ext_len)
698
699 hash_alg, sig_alg, sig_len = struct.unpack("!BBH", sct_data[:4])
700 signature = sct_data[4:]
701 if len(signature) != sig_len:
702 raise ValueError(
703 ("SCT signature has incorrect length, " + "expected %d, got %d")
704 % (sig_len, len(signature))
705 )
706
707 scts.append(
708 {
709 "log_name": self.__find_ct_log_url_by_id(logid),
710 "log_id": base64.b64encode(logid).decode("utf-8"),

Callers

nothing calls this directly

Calls 3

__splitBytesMethod · 0.95

Tested by

no test coverage detected