Ejemplo n.º 1
0
    def test_to_certificate_model_v2(self):
        with open('data/2.0/bbba8553-8ec1-445f-82c9-a57251dd731c.json',
                  'rb') as cert_file:
            certificate_bytes = cert_file.read()
            certificate_json = helpers.certificate_bytes_to_json(
                certificate_bytes)
            certificate_model = model.to_certificate_model(certificate_json)
            self.assertEquals(certificate_model.version, BlockcertVersion.V2)
            self.assertEquals(
                certificate_model.issuer.id,
                'https://www.blockcerts.org/samples/2.0/issuer-testnet.json')
            self.assertEquals(
                certificate_model.txid,
                'd75b7a5bdb3d5244b753e6b84e987267cfa4ffa7a532a2ed49ad3848be1d82f8'
            )
            self.assertEquals(certificate_model.title,
                              'Certificate of Accomplishment')
            self.assertEquals(
                certificate_model.description,
                'Lorem ipsum dolor sit amet, mei docendi concludaturque ad, cu nec partem graece. Est aperiam consetetur cu, expetenda moderatius neglegentur ei nam, suas dolor laudem eam an.'
            )
            self.assertEquals(certificate_model.uid,
                              'urn:uuid:bbba8553-8ec1-445f-82c9-a57251dd731c')
            self.assertEquals(certificate_model.subtitle, None)
            self.assertEquals(certificate_model.expires, None)

            self.assertEquals(certificate_model.issuer.name,
                              'University of Learning')
            self.assertEquals(certificate_model.recipient_public_key,
                              'mtr98kany9G1XYNU74pRnfBQmaCg2FZLmc')
            self.assertEquals(certificate_model.issued_on,
                              parse_date('2017-06-29T14:58:57.461422+00:00'))
Ejemplo n.º 2
0
    def test_to_certificate_model_v2_alpha(self):
        with open('data/2.0-alpha/8e0b8a28-beff-43de-a72c-820bc360db3d.json',
                  'rb') as cert_file:
            certificate_bytes = cert_file.read()
            certificate_json = helpers.certificate_bytes_to_json(
                certificate_bytes)
            certificate_model = model.to_certificate_model(certificate_json)
            self.assertEquals(certificate_model.version,
                              BlockcertVersion.V2_ALPHA)
            self.assertEquals(
                certificate_model.issuer.id,
                'https://www.blockcerts.org/blockcerts_v2_alpha/samples/issuer_testnet.json'
            )
            self.assertEquals(
                certificate_model.txid,
                '08e205566662b97f149ad677649bbb94ebc2f46c0ac72bc7c9b57d2d207015f4'
            )
            self.assertEquals(certificate_model.title,
                              'This is the certificate title')
            self.assertEquals(
                certificate_model.description,
                'This is the display description of the certificate.')
            self.assertEquals(certificate_model.uid,
                              'urn:uuid:8e0b8a28-beff-43de-a72c-820bc360db3d')
            self.assertEquals(certificate_model.subtitle, None)
            self.assertEquals(certificate_model.expires, None)

            self.assertEquals(certificate_model.issuer.name,
                              'Issuer Institution Name')
            self.assertEquals(certificate_model.recipient_public_key,
                              'mkwntSiQmc14H65YxwckLenxY3DsEpvFbe')
            self.assertEquals(certificate_model.issued_on,
                              parse_date('2017-05-01 00:00:00+00:00'))
Ejemplo n.º 3
0
 def test_detect_version_v1_1(self):
     with open('data/1.1/sample_signed_cert-1.1.json', 'rb') as cert_file:
         certificate_bytes = cert_file.read()
         certificate_json = helpers.certificate_bytes_to_json(
             certificate_bytes)
         version = model.detect_version(certificate_json)
         self.assertEquals(version, BlockcertVersion.V1_1)
Ejemplo n.º 4
0
    def get_certificate(self, certificate_uid):
        """
        Returns certificate as byte array. We need this for v1 certs, which compute a binary hash. Raises
        KeyError if not found
        :param certificate_uid:
        :return:
        """
        logging.debug('Retrieving certificate for uid=%s', certificate_uid)

        is_v1_uid = model.is_v1_uid(certificate_uid)
        if not is_v1_uid:
            return super(V1AwareCertificateStore,
                         self).get_certificate(certificate_uid)

        # else it's V1.1 (if not valid, it will throw)
        certificate = self._find_certificate_metadata(uid=certificate_uid)
        if certificate:
            certificate_bytes = self._get_certificate_raw(certificate_uid)
            certificate_json = helpers.certificate_bytes_to_json(
                certificate_bytes)
            return model.to_certificate_model(certificate_json,
                                              certificate['txid'],
                                              certificate_bytes)

        message = 'Certificate metadata not found for certificate uid=%s' % certificate_uid
        logging.error(message)
        raise KeyError(message)
Ejemplo n.º 5
0
 def test_detect_version_v1_2(self):
     with open('data/1.2/609c2989-275f-4f4c-ab02-b245cfb09017.json',
               'rb') as cert_file:
         certificate_bytes = cert_file.read()
         certificate_json = helpers.certificate_bytes_to_json(
             certificate_bytes)
         version = model.detect_version(certificate_json)
         self.assertEquals(version, BlockcertVersion.V1_2)
Ejemplo n.º 6
0
    def get_certificate_json(self, certificate_uid):
        """
        Returns certificate as json. Propagates KeyError if key isn't found
        :param certificate_uid:
        :return:
        """

        if certificate_uid.startswith(URN_UUID_PREFIX):
            uid = certificate_uid[len(URN_UUID_PREFIX):]
        elif certificate_uid.startswith('http'):
            last_slash = certificate_uid.rindex('/')
            uid = certificate_uid[last_slash + 1:]
        else:
            uid = certificate_uid
        logging.debug('Retrieving certificate for uid=%s', uid)
        certificate_bytes = self._get_certificate_raw(uid)
        logging.debug('Found certificate for uid=%s', uid)
        certificate_json = helpers.certificate_bytes_to_json(certificate_bytes)
        return certificate_json
Ejemplo n.º 7
0
    def test_to_certificate_model_v1_1(self):
        with open('data/1.1/sample_signed_cert-1.1.json', 'rb') as cert_file:
            certificate_bytes = cert_file.read()
            certificate_json = helpers.certificate_bytes_to_json(
                certificate_bytes)
            txid = '1703d2f5d706d495c1c65b40a086991ab755cc0a02bef51cd4aff9ed7a8586aa'
            certificate_model = model.to_certificate_model(
                certificate_json, txid, certificate_bytes)
            self.assertEquals(
                certificate_model.issuer.id,
                'http://www.blockcerts.org/mockissuer/issuer/got-issuer.json')
            self.assertEquals(
                certificate_model.txid,
                '1703d2f5d706d495c1c65b40a086991ab755cc0a02bef51cd4aff9ed7a8586aa'
            )
            self.assertEquals(certificate_model.title,
                              'Game of Thrones Character')
            self.assertEquals(
                certificate_model.description,
                'This certifies that the named character is an official Game of Thrones character.'
            )
            self.assertEquals(certificate_model.uid,
                              '75857d18-0e1c-4933-b4c8-33484396e06b')
            self.assertEquals(certificate_model.subtitle, None)
            self.assertEquals(certificate_model.expires, None)

            self.assertEquals(certificate_model.issuer.name,
                              'Game of thrones characters')
            self.assertEquals(certificate_model.recipient_public_key,
                              'mgCNaPM3TFhh8Yn6U6VcEM9jWLhQbizy1x')
            self.assertEquals(certificate_model.issued_on,
                              parse_date('2016-08-29 00:00:00+00:00'))
            # self.assertEquals(certificate_model.blockcert_signature, None)
            self.assertIsNotNone(certificate_model.signature_image[0].image)

            self.assertEquals(certificate_model.signatures[0].signature_type,
                              SignatureType.signed_content)
            self.assertEquals(certificate_model.signatures[1].signature_type,
                              SignatureType.signed_transaction)
            self.assertIsNone(certificate_model.signatures[1].merkle_proof)
Ejemplo n.º 8
0
    def test_to_certificate_model_v1_2(self):
        """
        Note this is a mainnet certificate with different uid
        :return:
        """
        with open('data/1.2/609c2989-275f-4f4c-ab02-b245cfb09017.json',
                  'rb') as cert_file:
            certificate_bytes = cert_file.read()
            certificate_json = helpers.certificate_bytes_to_json(
                certificate_bytes)
            certificate_model = model.to_certificate_model(certificate_json)
            self.assertEquals(certificate_model.version, BlockcertVersion.V1_2)
            self.assertEquals(
                certificate_model.issuer.id,
                'http://www.blockcerts.org/mockissuer/issuer/got-issuer_live.json'
            )
            self.assertEquals(
                certificate_model.txid,
                '8623beadbc7877a9e20fb7f83eda6c1a1fc350171f0714ff6c6c4054018eb54d'
            )
            self.assertEquals(certificate_model.title,
                              'Game of Thrones Character')
            self.assertEquals(
                certificate_model.description,
                'This certifies that the named character is an official Game of Thrones character.'
            )
            self.assertEquals(certificate_model.uid,
                              '609c2989-275f-4f4c-ab02-b245cfb09017')
            self.assertEquals(certificate_model.subtitle, None)
            self.assertEquals(certificate_model.expires, None)

            self.assertEquals(certificate_model.issuer.name,
                              'Game of thrones issuer')
            self.assertEquals(certificate_model.recipient_public_key,
                              '1AAGG6jirbu9XwikFpkHokbbiYpjVtFe1G')
            self.assertEquals(certificate_model.issued_on,
                              parse_date('2016-10-03 00:00:00+00:00'))
            self.assertIsNotNone(certificate_model.signature_image[0].image)