bartek
2008-02-19 09:53:46 UTC
Hello
I was thining how to store a value in a python object in such a way it
can be used for processing, but can not be retrieved as is, even using
pdb prompt. And I came up with the following:
class PrivateStorage(object):
"""
A class for storing and using variable in such a way that it can
not be retrieved as is, even by someone able to modify source code
or use a pdb prompt.
"""
value = ''
def __get__(self, container, cls):
"""
Return result of processing stored value.
"""
return self.process(container)
def __set__(self, container, value):
self.value = value
def process(self, container):
"""
Implementation method for processing stored value
also using containter attributes.
"""
return self.value == container.v
class Test(object):
priv = PrivateStorage()
v = ''
def main():
t = Test()
t.priv = 'aaa'
print t.priv
print t.__dict__
t.v = 'abc'
print t.priv
t.v = 'aaa'
print t.priv
Do you think it is secure, or is there a way to hack it?
Bartek
I was thining how to store a value in a python object in such a way it
can be used for processing, but can not be retrieved as is, even using
pdb prompt. And I came up with the following:
class PrivateStorage(object):
"""
A class for storing and using variable in such a way that it can
not be retrieved as is, even by someone able to modify source code
or use a pdb prompt.
"""
value = ''
def __get__(self, container, cls):
"""
Return result of processing stored value.
"""
return self.process(container)
def __set__(self, container, value):
self.value = value
def process(self, container):
"""
Implementation method for processing stored value
also using containter attributes.
"""
return self.value == container.v
class Test(object):
priv = PrivateStorage()
v = ''
def main():
t = Test()
t.priv = 'aaa'
print t.priv
print t.__dict__
t.v = 'abc'
print t.priv
t.v = 'aaa'
print t.priv
Do you think it is secure, or is there a way to hack it?
Bartek
--
"feelings affect productivity. (...) unhappy people write worse
software, and less of it."
Karl Fogel, "Producing Open Source Software"
"feelings affect productivity. (...) unhappy people write worse
software, and less of it."
Karl Fogel, "Producing Open Source Software"