Пример #1
0
 def to_dict(self):
     try:
         cid = convert_to_string(self.caveat_id)
     except UnicodeEncodeError:
         cid = convert_to_string(standard_b64encode(self.caveat_id_bytes))
     return {
         'cid':
         cid,
         'vid': (standard_b64encode(self.verification_key_id)
                 if self.verification_key_id else None),
         'cl':
         self.location
     }
Пример #2
0
 def to_dict(self):
     try:
         cid = convert_to_string(self.caveat_id)
     except UnicodeEncodeError:
         cid = convert_to_string(standard_b64encode(self.caveat_id_bytes))
     return {
         'cid': cid,
         'vid': (
             standard_b64encode(self.verification_key_id)
             if self.verification_key_id else None
         ),
         'cl': self.location
     }
Пример #3
0
 def deserialize(cls, serialized, serializer=None):
     serialized = convert_to_string(serialized)
     serializer = serializer or BinarySerializer()
     if serialized:
         return serializer.deserialize(serialized)
     else:
         raise MacaroonInitException(
             'Must supply serialized macaroon.'
         )
Пример #4
0
 def inspect(self):
     combined = 'location {loc}\n'.format(loc=self.location)
     try:
         combined += 'identifier {id}\n'.format(id=self.identifier)
     except UnicodeEncodeError:
         combined += 'identifier64 {id}\n'.format(id=convert_to_string(
             standard_b64encode(self.identifier_bytes)))
     for caveat in self.caveats:
         try:
             combined += 'cid {cid}\n'.format(
                 cid=convert_to_string(caveat.caveat_id))
         except UnicodeEncodeError:
             combined += 'cid64 {cid}\n'.format(cid=convert_to_string(
                 standard_b64encode(caveat.caveat_id_bytes)))
         if caveat.verification_key_id and caveat.location:
             vid = convert_to_string(
                 standard_b64encode(caveat.verification_key_id))
             combined += 'vid {vid}\n'.format(vid=vid)
             combined += 'cl {cl}\n'.format(cl=caveat.location)
     combined += 'signature {sig}'.format(sig=self.signature)
     return combined
Пример #5
0
 def inspect(self):
     combined = 'location {loc}\n'.format(loc=self.location)
     combined += 'identifier {id}\n'.format(id=self.identifier)
     for caveat in self.caveats:
         combined += 'cid {cid}\n'.format(cid=caveat.caveat_id)
         if caveat.verification_key_id and caveat.location:
             vid = convert_to_string(
                 standard_b64encode(caveat.verification_key_id)
             )
             combined += 'vid {vid}\n'.format(vid=vid)
             combined += 'cl {cl}\n'.format(cl=caveat.location)
     combined += 'signature {sig}'.format(sig=self.signature)
     return combined
Пример #6
0
    def _serialize_v1(self, macaroon):
        '''Serialize the macaroon in JSON format v1.

        @param macaroon the macaroon to serialize.
        @return JSON macaroon.
        '''
        serialized = {
            'identifier': utils.convert_to_string(macaroon.identifier),
            'signature': macaroon.signature,
        }
        if macaroon.location:
            serialized['location'] = macaroon.location
        if macaroon.caveats:
            serialized['caveats'] = [
                _caveat_v1_to_dict(caveat) for caveat in macaroon.caveats
            ]
        return json.dumps(serialized)
Пример #7
0
    def _serialize_v1(self, macaroon):
        '''Serialize the macaroon in JSON format v1.

        @param macaroon the macaroon to serialize.
        @return JSON macaroon.
        '''
        serialized = {
            'identifier': utils.convert_to_string(macaroon.identifier),
            'signature': macaroon.signature,
        }
        if macaroon.location:
            serialized['location'] = macaroon.location
        if macaroon.caveats:
            serialized['caveats'] = [
                _caveat_v1_to_dict(caveat) for caveat in macaroon.caveats
            ]
        return json.dumps(serialized)
Пример #8
0
    def deserialize(self, serialized):
        from pymacaroons.macaroon import Macaroon
        from pymacaroons.caveat import Caveat

        caveats = []
        deserialized = json.loads(convert_to_string(serialized))

        for c in deserialized['caveats']:
            caveat = Caveat(caveat_id=c['cid'],
                            verification_key_id=(standard_b64decode(c['vid'])
                                                 if c['vid'] else None),
                            location=c['cl'])
            caveats.append(caveat)

        return Macaroon(location=deserialized['location'],
                        identifier=deserialized['identifier'],
                        caveats=caveats,
                        signature=deserialized['signature'])
Пример #9
0
    def deserialize(self, serialized):
        from pymacaroons.macaroon import Macaroon
        from pymacaroons.caveat import Caveat

        caveats = []
        deserialized = json.loads(convert_to_string(serialized))

        for c in deserialized['caveats']:
            caveat = Caveat(
                caveat_id=c['cid'],
                verification_key_id=(
                    standard_b64decode(c['vid']) if c['vid'] else None
                ),
                location=c['cl']
            )
            caveats.append(caveat)

        return Macaroon(
            location=deserialized['location'],
            identifier=deserialized['identifier'],
            caveats=caveats,
            signature=deserialized['signature']
        )
Пример #10
0
 def caveat_id(self):
     return convert_to_string(self._caveat_id)
Пример #11
0
 def signifier(self):
     return convert_to_string(self._signifier)
 def signifier(self):
     return convert_to_string(self._signifier)
Пример #13
0
 def signature(self):
     return convert_to_string(self._signature)
Пример #14
0
 def location(self):
     return convert_to_string(self._location)
Пример #15
0
 def _signatures_match(self, macaroon_signature, computed_signature):
     return constant_time_compare(convert_to_string(macaroon_signature),
                                  convert_to_string(computed_signature))
Пример #16
0
 def deserialize(self, serialized):
     if len(serialized) == 0:
         raise ValueError('empty macaroon')
     serialized = convert_to_string(serialized)
     decoded = raw_b64decode(serialized)
     return self.deserialize_raw(decoded)
Пример #17
0
 def location(self):
     return convert_to_string(self._location)
Пример #18
0
 def verification_key_id(self):
     return convert_to_string(self._verification_key_id)
Пример #19
0
 def caveat_id(self):
     from pymacaroons.macaroon import MACAROON_V1
     if self._version == MACAROON_V1:
         return convert_to_string(self._caveat_id)
     return self._caveat_id
Пример #20
0
 def caveat_id(self):
     from pymacaroons.macaroon import MACAROON_V1
     if self._version == MACAROON_V1:
         return convert_to_string(self._caveat_id)
     return self._caveat_id
Пример #21
0
 def satisfy_exact(self, predicate):
     if predicate is None:
         raise TypeError('Predicate cannot be none.')
     self.predicates.append(convert_to_string(predicate))
Пример #22
0
 def verification_key_id(self):
     return convert_to_string(self._verification_key_id)
Пример #23
0
 def _signatures_match(self, macaroon_signature, computed_signature):
     return constant_time_compare(
         convert_to_string(macaroon_signature),
         convert_to_string(computed_signature)
     )
Пример #24
0
 def identifier(self):
     return convert_to_string(self._identifier)
Пример #25
0
 def signature(self):
     return convert_to_string(self._signature)
Пример #26
0
 def satisfy_exact(self, predicate):
     if predicate is None:
         raise TypeError('Predicate cannot be none.')
     self.predicates.append(convert_to_string(predicate))
Пример #27
0
 def caveat_id(self):
     return convert_to_string(self._caveat_id)
Пример #28
0
 def decrypt(self, signature, field_data):
     key = truncate_or_pad(signature)
     box = SecretBox(key=key)
     encoded = convert_to_bytes(field_data[len(self.signifier):])
     decrypted = box.decrypt(standard_b64decode(encoded))
     return convert_to_string(decrypted)
Пример #29
0
 def deserialize(self, serialized):
     if len(serialized) == 0:
         raise ValueError('empty macaroon')
     serialized = convert_to_string(serialized)
     decoded = raw_b64decode(serialized)
     return self.deserialize_raw(decoded)
Пример #30
0
 def identifier(self):
     if self.version == MACAROON_V1:
         return convert_to_string(self._identifier)
     return self._identifier
Пример #31
0
 def decrypt(self, signature, field_data):
     key = truncate_or_pad(signature)
     box = SecretBox(key=key)
     encoded = convert_to_bytes(field_data[len(self.signifier):])
     decrypted = box.decrypt(standard_b64decode(encoded))
     return convert_to_string(decrypted)
Пример #32
0
 def identifier(self):
     return convert_to_string(self._identifier)
Пример #33
0
 def identifier(self):
     if self.version == MACAROON_V1:
         return convert_to_string(self._identifier)
     return self._identifier