-rw-r--r-- | backend/python/src/clipperz.py | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/backend/python/src/clipperz.py b/backend/python/src/clipperz.py index bd5d030..5476b4b 100644 --- a/backend/python/src/clipperz.py +++ b/backend/python/src/clipperz.py | |||
@@ -1,117 +1,115 @@ | |||
1 | # | 1 | # |
2 | #Copyright 2008-2011 Clipperz Srl | 2 | #Copyright 2008-2013 Clipperz Srl |
3 | # | 3 | # |
4 | #This file is part of Clipperz Community Edition. | 4 | #This file is part of Clipperz, the online password manager. |
5 | #Clipperz Community Edition is an online password manager. | ||
6 | #For further information about its features and functionalities please | 5 | #For further information about its features and functionalities please |
7 | #refer to http://www.clipperz.com. | 6 | #refer to http://www.clipperz.com. |
8 | # | 7 | # |
9 | #* Clipperz Community Edition is free software: you can redistribute | 8 | #* Clipperz is free software: you can redistribute it and/or modify it |
10 | # it and/or modify it under the terms of the GNU Affero General Public | 9 | # under the terms of the GNU Affero General Public License as published |
11 | # License as published by the Free Software Foundation, either version | 10 | # by the Free Software Foundation, either version 3 of the License, or |
12 | # 3 of the License, or (at your option) any later version. | 11 | # (at your option) any later version. |
13 | # | 12 | # |
14 | #* Clipperz Community Edition is distributed in the hope that it will | 13 | #* Clipperz is distributed in the hope that it will be useful, but |
15 | # be useful, but WITHOUT ANY WARRANTY; without even the implied | 14 | # WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | # See the GNU Affero General Public License for more details. | 16 | # See the GNU Affero General Public License for more details. |
18 | # | 17 | # |
19 | #* You should have received a copy of the GNU Affero General Public | 18 | #* You should have received a copy of the GNU Affero General Public |
20 | # License along with Clipperz Community Edition. If not, see | 19 | # License along with Clipperz. If not, see http://www.gnu.org/licenses/. |
21 | # <http://www.gnu.org/licenses/>. | ||
22 | # | 20 | # |
23 | 21 | ||
24 | import os | 22 | import os |
25 | import cgi | 23 | import cgi |
26 | import wsgiref.handlers | 24 | import wsgiref.handlers |
27 | 25 | ||
28 | import datetime | 26 | import datetime |
29 | import uuid | 27 | import uuid |
30 | import random | 28 | import random |
31 | import hashlib | 29 | import hashlib |
32 | 30 | ||
33 | import logging | 31 | import logging |
34 | 32 | ||
35 | from google.appengine.api import users | 33 | from google.appengine.api import users |
36 | from google.appengine.ext import webapp | 34 | from google.appengine.ext import webapp |
37 | from google.appengine.ext import db | 35 | from google.appengine.ext import db |
38 | from google.appengine.ext.webapp import template | 36 | from google.appengine.ext.webapp import template |
39 | 37 | ||
40 | from django.utils import simplejson | 38 | from django.utils import simplejson |
41 | 39 | ||
42 | #============================================================================== | 40 | #============================================================================== |
43 | 41 | ||
44 | sessionTimeout = datetime.timedelta(minutes=-2) | 42 | sessionTimeout = datetime.timedelta(minutes=-2) |
45 | 43 | ||
46 | def randomSeed(): | 44 | def randomSeed(): |
47 | return hex(random.getrandbits(32*8))[2:-1] | 45 | return hex(random.getrandbits(32*8))[2:-1] |
48 | 46 | ||
49 | def clipperzHash(aString): | 47 | def clipperzHash(aString): |
50 | #logging.info(">>> string: " + aString) | 48 | #logging.info(">>> string: " + aString) |
51 | firstRound = hashlib.sha256() | 49 | firstRound = hashlib.sha256() |
52 | firstRound.update(aString) | 50 | firstRound.update(aString) |
53 | #logging.info("firstRound: " + firstRound.hexdigest() + " - " + firstRound.digest()) | 51 | #logging.info("firstRound: " + firstRound.hexdigest() + " - " + firstRound.digest()) |
54 | result = hashlib.sha256() | 52 | result = hashlib.sha256() |
55 | result.update(firstRound.digest()) | 53 | result.update(firstRound.digest()) |
56 | #logging.info("<<< finalResul: " + result.hexdigest()) | 54 | #logging.info("<<< finalResul: " + result.hexdigest()) |
57 | 55 | ||
58 | return result.hexdigest() | 56 | return result.hexdigest() |
59 | 57 | ||
60 | #============================================================================== | 58 | #============================================================================== |
61 | 59 | ||
62 | class User(db.Model): | 60 | class User(db.Model): |
63 | username= db.StringProperty() | 61 | username= db.StringProperty() |
64 | srp_s = db.StringProperty() | 62 | srp_s = db.StringProperty() |
65 | srp_v = db.StringProperty() | 63 | srp_v = db.StringProperty() |
66 | header = db.TextProperty() | 64 | header = db.TextProperty() |
67 | statistics= db.TextProperty() | 65 | statistics= db.TextProperty() |
68 | auth_version= db.StringProperty() | 66 | auth_version= db.StringProperty() |
69 | version = db.StringProperty() | 67 | version = db.StringProperty() |
70 | lock = db.StringProperty() | 68 | lock = db.StringProperty() |
71 | 69 | ||
72 | def updateCredentials(self, someCredentials): | 70 | def updateCredentials(self, someCredentials): |
73 | self.username = someCredentials['C'] | 71 | self.username = someCredentials['C'] |
74 | self.srp_s = someCredentials['s'] | 72 | self.srp_s = someCredentials['s'] |
75 | self.srp_v = someCredentials['v'] | 73 | self.srp_v = someCredentials['v'] |
76 | self.auth_version= someCredentials['version'] | 74 | self.auth_version= someCredentials['version'] |
77 | 75 | ||
78 | def update(self, someData): | 76 | def update(self, someData): |
79 | self.header = someData['header'] | 77 | self.header = someData['header'] |
80 | self.statistics= someData['statistics'] | 78 | self.statistics= someData['statistics'] |
81 | self.version= someData['version'] | 79 | self.version= someData['version'] |
82 | self.lock = someData['lock'] | 80 | self.lock = someData['lock'] |
83 | 81 | ||
84 | #------------------------------------------------------------------------------ | 82 | #------------------------------------------------------------------------------ |
85 | 83 | ||
86 | class Record(db.Model): | 84 | class Record(db.Model): |
87 | user = db.ReferenceProperty(User) | 85 | user = db.ReferenceProperty(User) |
88 | reference = db.StringProperty() | 86 | reference = db.StringProperty() |
89 | data = db.TextProperty() | 87 | data = db.TextProperty() |
90 | version = db.StringProperty() | 88 | version = db.StringProperty() |
91 | creation_date= db.DateTimeProperty(auto_now_add=True) | 89 | creation_date= db.DateTimeProperty(auto_now_add=True) |
92 | update_date = db.DateTimeProperty(auto_now_add=True) | 90 | update_date = db.DateTimeProperty(auto_now_add=True) |
93 | access_date = db.DateTimeProperty(auto_now_add=True) | 91 | access_date = db.DateTimeProperty(auto_now_add=True) |
94 | 92 | ||
95 | #------------------------------------------------------------------------------ | 93 | #------------------------------------------------------------------------------ |
96 | 94 | ||
97 | class RecordVersion(db.Model): | 95 | class RecordVersion(db.Model): |
98 | record = db.ReferenceProperty(Record) | 96 | record = db.ReferenceProperty(Record) |
99 | reference = db.StringProperty() | 97 | reference = db.StringProperty() |
100 | header = db.TextProperty() | 98 | header = db.TextProperty() |
101 | data = db.TextProperty() | 99 | data = db.TextProperty() |
102 | version = db.StringProperty() | 100 | version = db.StringProperty() |
103 | previousVersionKey= db.StringProperty() | 101 | previousVersionKey= db.StringProperty() |
104 | previousVersion = db.SelfReferenceProperty() | 102 | previousVersion = db.SelfReferenceProperty() |
105 | creation_date = db.DateTimeProperty(auto_now_add=True) | 103 | creation_date = db.DateTimeProperty(auto_now_add=True) |
106 | update_date = db.DateTimeProperty(auto_now_add=True) | 104 | update_date = db.DateTimeProperty(auto_now_add=True) |
107 | access_date = db.DateTimeProperty(auto_now_add=True) | 105 | access_date = db.DateTimeProperty(auto_now_add=True) |
108 | 106 | ||
109 | def update(self, someData): | 107 | def update(self, someData): |
110 | recordData = someData['record']; | 108 | recordData = someData['record']; |
111 | self.parent().reference =recordData['reference'] | 109 | self.parent().reference =recordData['reference'] |
112 | self.parent().data = recordData['data'] | 110 | self.parent().data = recordData['data'] |
113 | self.parent().version = recordData['version'] | 111 | self.parent().version = recordData['version'] |
114 | self.parent().update_date =datetime.datetime.now() | 112 | self.parent().update_date =datetime.datetime.now() |
115 | 113 | ||
116 | recordVersionData = someData['currentRecordVersion']; | 114 | recordVersionData = someData['currentRecordVersion']; |
117 | self.reference = recordVersionData ['reference'] | 115 | self.reference = recordVersionData ['reference'] |