Exemple #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
     }
Exemple #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
     }
Exemple #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.'
         )
Exemple #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
Exemple #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
    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)
    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)
Exemple #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'])
    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']
        )
Exemple #10
0
 def caveat_id(self):
     return convert_to_string(self._caveat_id)
 def signifier(self):
     return convert_to_string(self._signifier)
 def signifier(self):
     return convert_to_string(self._signifier)
Exemple #13
0
 def signature(self):
     return convert_to_string(self._signature)
Exemple #14
0
 def location(self):
     return convert_to_string(self._location)
Exemple #15
0
 def _signatures_match(self, macaroon_signature, computed_signature):
     return constant_time_compare(convert_to_string(macaroon_signature),
                                  convert_to_string(computed_signature))
 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)
Exemple #17
0
 def location(self):
     return convert_to_string(self._location)
Exemple #18
0
 def verification_key_id(self):
     return convert_to_string(self._verification_key_id)
Exemple #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
Exemple #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
Exemple #21
0
 def satisfy_exact(self, predicate):
     if predicate is None:
         raise TypeError('Predicate cannot be none.')
     self.predicates.append(convert_to_string(predicate))
Exemple #22
0
 def verification_key_id(self):
     return convert_to_string(self._verification_key_id)
Exemple #23
0
 def _signatures_match(self, macaroon_signature, computed_signature):
     return constant_time_compare(
         convert_to_string(macaroon_signature),
         convert_to_string(computed_signature)
     )
Exemple #24
0
 def identifier(self):
     return convert_to_string(self._identifier)
Exemple #25
0
 def signature(self):
     return convert_to_string(self._signature)
Exemple #26
0
 def satisfy_exact(self, predicate):
     if predicate is None:
         raise TypeError('Predicate cannot be none.')
     self.predicates.append(convert_to_string(predicate))
Exemple #27
0
 def caveat_id(self):
     return convert_to_string(self._caveat_id)
 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)
Exemple #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)
Exemple #30
0
 def identifier(self):
     if self.version == MACAROON_V1:
         return convert_to_string(self._identifier)
     return self._identifier
 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)
Exemple #32
0
 def identifier(self):
     return convert_to_string(self._identifier)
Exemple #33
0
 def identifier(self):
     if self.version == MACAROON_V1:
         return convert_to_string(self._identifier)
     return self._identifier