def test_data(self):
        self.assertEqual(
            self._TEST_DTE_1_SIGNATURE_VALUE,
            b'~\xc6\x0f\xe6\x9f\xe55\xfa\x1f\x03?\x0f9(k&:\x97t\x14\xcd6\xdb\xef\xe3\xf4\xd6'
            b'\x0b\x16\xef\xc12\x00^\xbe\xc1.\xb9o_p\xbf\x1e\x97\xe8\xe2\xf8\xaak\x14\xae\xd4'
            b'\xe1\x85\x80\xf9\xe4u\xd0\xc8\x17\x08\xfff\xc5]m\xd0~2\x1aJ\x93(Z\xf3tq\x84\x9a'
            b'X\x05PX\xdd\xcf\xb2\xf4\x9e\xa81\xf7Ht\xc0\x18^\x11$\x17\x0f0\xebr\x87\xca\x17_'
            b'\xd8O]\x9d\xb2\xa2\xc2\xa4\xb1\r\xc6#M>\xaf^\xc2\xcf\xad\x99')
        self.assertEqual(
            self._TEST_DTE_2_SIGNATURE_VALUE,
            b"\xc3\x03\x8cB\xe1jk\xa79\x836\x12'\x93\xd6~\x8d\x0e\x88\x07\xfe\xc8\xd7\t+\xac1"
            b"\xe3\x12wT\xd7\xa1\x94\x07\x0c\xad@v\xab\xea\xca\xfc0\xe1\n\xf8\xf1\x02\x85\xf87"
            b"\x10@\n!C2\xb4\xcc!\xfb\xf1\xaf\x05\xe3-\xddh_~\xe5HS\xad\xb1e\xfa'\x12\xf4I_"
            b"\xad,^\xea\xbd`\xae\xd5\x8c\xf0\xf3*T\x7f\xb1\x83\x91\xbc\xa6&J\x13`1}$Q|\x91"
            b"\x858\x15\xd56\xc2\xdbb\xc2w\xbd\\\x7f\x10\x14x\x17\xb2\x87\n?\xf6\xb2\x83\x08"
            b"\x8exj\xa25\x7fh\xfc\xeeWKa\x96\xa6\xdf\x8a3m#\xae\xfbX\x9f\xb5\x050@\xff\xdd"
            b"\xa3\xdap&\xf5\x18\x00b\xce\xbf&\x95Q\x19\x82\x06`&\xe9\xcc\x0c(i\x15\x0c\x84"
            b"\x8a\x04\x970\xaeH\xef~\xc0s\xc0\xf6o\x0e\xd6\x07\x8e\xd6\x8fU\x81/{\x02\x15\x10"
            b"\xe5]E\xed\x9c\xcb\xc2\x84\x15i\xd0tT]\x8b\x8a\x1f'\xe9\x0b:\x88\x05|\xa0b\xb2"
            b"\x19{\x1cW\x80\xe4\xa7*\xef\xf2\x1a")

        self.assertEqual(
            crypto_utils.x509_cert_pem_to_der(self.dte_clean_xml_1_cert_pem_bytes),
            self.dte_clean_xml_1_cert_der)
        self.assertEqual(
            crypto_utils.x509_cert_pem_to_der(self.dte_clean_xml_2_cert_pem_bytes),
            self.dte_clean_xml_2_cert_der)
예제 #2
0
 def test_x509_cert_pem_to_der_valuetype_error(self) -> None:
     with self.assertRaises(ValueError) as cm:
         x509_cert_pem_to_der(b'hello')
     self.assertEqual(cm.exception.args, (
         "Input is not a valid base64 value.",
         "Invalid base64-encoded string: number of data characters (5) cannot be 1 more "
         "than a multiple of 4",
     ))
예제 #3
0
    def test_x509_cert_der_to_pem_pem_to_der_ok_3(self) -> None:
        cert_der_bytes = utils.read_test_file_bytes(
            'test_data/sii-crypto/prueba-sii-cert.der')
        cert_pem_bytes = utils.read_test_file_bytes(
            'test_data/sii-crypto/prueba-sii-cert.pem')

        # note: we test the function with a double call because the input PEM data
        #   may have different line lengths and different line separators.
        self.assertEqual(
            x509_cert_pem_to_der(x509_cert_der_to_pem(cert_der_bytes)),
            x509_cert_pem_to_der(cert_pem_bytes))
예제 #4
0
    def test_data(self):
        self.assertEqual(
            self._TEST_DTE_1_SIGNATURE_VALUE,
            b'~\xc6\x0f\xe6\x9f\xe55\xfa\x1f\x03?\x0f9(k&:\x97t\x14\xcd6\xdb\xef\xe3\xf4\xd6'
            b'\x0b\x16\xef\xc12\x00^\xbe\xc1.\xb9o_p\xbf\x1e\x97\xe8\xe2\xf8\xaak\x14\xae\xd4'
            b'\xe1\x85\x80\xf9\xe4u\xd0\xc8\x17\x08\xfff\xc5]m\xd0~2\x1aJ\x93(Z\xf3tq\x84\x9a'
            b'X\x05PX\xdd\xcf\xb2\xf4\x9e\xa81\xf7Ht\xc0\x18^\x11$\x17\x0f0\xebr\x87\xca\x17_'
            b'\xd8O]\x9d\xb2\xa2\xc2\xa4\xb1\r\xc6#M>\xaf^\xc2\xcf\xad\x99')
        self.assertEqual(
            self._TEST_DTE_2_SIGNATURE_VALUE,
            b"\xc3\x03\x8cB\xe1jk\xa79\x836\x12'\x93\xd6~\x8d\x0e\x88\x07\xfe\xc8\xd7\t+\xac1"
            b"\xe3\x12wT\xd7\xa1\x94\x07\x0c\xad@v\xab\xea\xca\xfc0\xe1\n\xf8\xf1\x02\x85\xf87"
            b"\x10@\n!C2\xb4\xcc!\xfb\xf1\xaf\x05\xe3-\xddh_~\xe5HS\xad\xb1e\xfa'\x12\xf4I_"
            b"\xad,^\xea\xbd`\xae\xd5\x8c\xf0\xf3*T\x7f\xb1\x83\x91\xbc\xa6&J\x13`1}$Q|\x91"
            b"\x858\x15\xd56\xc2\xdbb\xc2w\xbd\\\x7f\x10\x14x\x17\xb2\x87\n?\xf6\xb2\x83\x08"
            b"\x8exj\xa25\x7fh\xfc\xeeWKa\x96\xa6\xdf\x8a3m#\xae\xfbX\x9f\xb5\x050@\xff\xdd"
            b"\xa3\xdap&\xf5\x18\x00b\xce\xbf&\x95Q\x19\x82\x06`&\xe9\xcc\x0c(i\x15\x0c\x84"
            b"\x8a\x04\x970\xaeH\xef~\xc0s\xc0\xf6o\x0e\xd6\x07\x8e\xd6\x8fU\x81/{\x02\x15\x10"
            b"\xe5]E\xed\x9c\xcb\xc2\x84\x15i\xd0tT]\x8b\x8a\x1f'\xe9\x0b:\x88\x05|\xa0b\xb2"
            b"\x19{\x1cW\x80\xe4\xa7*\xef\xf2\x1a")
        self.assertEqual(
            self._TEST_DTE_3_SIGNATURE_VALUE,
            b"&{\x924\xcd\x80\xe9\xc2\x89pN9\x1ec\xf9\x8b&,\xec\xc8\x08\xa6[\x8ajo\xad\xed"
            b"\x84_US+\xb57\x89\x997\xc5~\xd7#\xf25C\xa8\xa1\x06\xb4\xd0*\x15\x0b\xe3i[\x9b"
            b"\x9b\x1a\x9c\xfclb\x10\x86o\xdb\xb5\x91|\x1c\x03\xefV\xcb\xf4]\x82\x82<p\xeb"
            b"\xeb\xad\x0e\x069\xd5\xb7\xba\xbcy\x0c<\xfd\xcc\tE\xff\xb8\x1f\x99\xd5\x99\xfd"
            b"\x8c\xce\x14\xfd\x11\xb3\x9cO5\xed\xa68kc\xd4\x16\xa7zoU.\x13A\xca\xa3\xf4p@\x07"
            b"\x06\xb3\x16W\x1a\x89Y\xdeu\x05\xe3\x8d\xd0\x88\xbe\xab\x89\x1f\x9e\xf0\xc6\x92H"
            b"\x92\xc9lg2\x90\x99G\x87\x8e\x0c4&\x11b\x86\x1b\xc2\xe0)\xea` \xe6\x1f6\xcf\xc1"
            b"\x1a\xce/\x05\xf8-\x12f\xf4\n!0\xa0wWh\xf8f`4e\t\x07T\x1a+\xf29\xacN\xd6\r\xf8k"
            b"\xe6\x83\xb0\xaaMEy\x03\x08/\xf4\x19\xa8s\x91x\x8c\xa8\x1e\xbe\xd6Ur)5\x06\x8e"
            b"\xfcr\xa5W\x8e\x9dJ\xe5\xb3d")

        self.assertEqual(
            crypto_utils.x509_cert_pem_to_der(
                self.dte_clean_xml_1_cert_pem_bytes),
            self.dte_clean_xml_1_cert_der)
        self.assertEqual(
            crypto_utils.x509_cert_pem_to_der(
                self.dte_clean_xml_2_cert_pem_bytes),
            self.dte_clean_xml_2_cert_der)
        self.assertEqual(
            crypto_utils.x509_cert_pem_to_der(
                self.dte_clean_xml_3_cert_pem_bytes),
            self.dte_clean_xml_3_cert_der)
예제 #5
0
 def test_x509_cert_pem_to_der_type_error(self) -> None:
     with self.assertRaises(TypeError) as cm:
         x509_cert_pem_to_der(1)
     self.assertEqual(cm.exception.args, ("Value must be bytes.", ))