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