/usr/lib/gdesklets/utils/pwstore.py is in gdesklets 0.36.1-7.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | #
# Module for storing confidential data like passwords.
#
# This was modeled after the mozilla password storage system with some security
# improvements; in fact it looks totally different.
#
# This one uses a prefix where to store the key file. Don't ever let somebody
# read your key file!
# The keys are worthless without the key file and vice versa.
#
import utils
import random
import os
import base64
def _init_store(prefix):
l = os.listdir(prefix)
l.sort()
if (not (l and l[0].startswith(".!pwstore"))):
_create_store(prefix)
def _create_store(prefix):
r1 = random.randrange(0xffffffL, 0x7fffffffL)
r2 = random.randrange(0xffffffL, 0x7fffffffL)
fname1 = ".!pwstore" + str(r1)
fname2 = ".!" + str(r2)
utils.makedirs(os.path.join(prefix, fname1))
path = os.path.join(prefix, fname1, fname2)
# is this equivalent to the commented code below? i think so
# chars = [chr(a) for a in range(256)*16 if a!=26]
# better :D
chars = [chr(a) for a in range(256) if a!=26] * 16
#chars = []
#for i in xrange(4096):
# a = i % 256
# if (a == 26): continue
# chars.append(chr(a))
#end for
data = ""
while chars:
index = random.randrange(len(chars))
c = chars.pop(index)
data += c
#end while
fd = open(path, "w")
fd.write(data)
fd.close()
os.chmod(path, 0400)
def _open_store(prefix):
try:
l = os.listdir(prefix)
l.sort()
fname1 = l[0]
l = os.listdir(os.path.join(prefix, fname1))
fname2 = l[0]
path = os.path.join(prefix, fname1, fname2)
data = open(path).read()
return data
except OSError:
return
#
# Stores the given value and returns a key for retrieval.
#
def store(prefix, value):
_init_store(prefix)
data = _open_store(prefix)
v64 = base64.encodestring(repr(value))
key = u""
for c in v64:
index = data.index(c)
key += unichr(index)
#end for
return repr(key)
#
# Returns the value for the given key.
#
def retrieve(prefix, key):
if (not key): return ""
_init_store(prefix)
data = _open_store(prefix)
try:
v64 = ""
for c in eval(key):
v64 += data[ord(c)]
#end for
value = eval(base64.decodestring(v64))
return value
except base64.binascii.Error:
return ""
|