Mercurial > libervia-web
comparison src/browser/sat_browser/otrjs_wrapper.py @ 537:cd492c18b366
browser_side (plugin OTR): manage the plain text messages ourselves rather than leaving it to otr.js
author | souliane <souliane@mailoo.org> |
---|---|
date | Sun, 07 Sep 2014 19:28:27 +0200 |
parents | 1fa173107fde |
children | cd56f2b0e85b |
comparison
equal
deleted
inserted
replaced
536:048ae7314156 | 537:cd492c18b366 |
---|---|
51 STATUS_AKE_SUCCESS = None | 51 STATUS_AKE_SUCCESS = None |
52 STATUS_END_OTR = None | 52 STATUS_END_OTR = None |
53 STATE_PLAINTEXT = None | 53 STATE_PLAINTEXT = None |
54 STATE_ENCRYPTED = None | 54 STATE_ENCRYPTED = None |
55 STATE_FINISHED = None | 55 STATE_FINISHED = None |
56 OTR_TAG = None | |
56 OTR_VERSION_2 = None | 57 OTR_VERSION_2 = None |
57 OTR_VERSION_3 = None | 58 OTR_VERSION_3 = None |
59 WHITESPACE_TAG = None | |
60 WHITESPACE_TAG_V2 = None | |
61 WHITESPACE_TAG_V3 = None | |
58 | 62 |
59 JS(""" | 63 JS(""" |
60 $cls_definition['STATUS_SEND_QUERY'] = OTR.CONST.STATUS_SEND_QUERY; | 64 $cls_definition['STATUS_SEND_QUERY'] = OTR.CONST.STATUS_SEND_QUERY; |
61 $cls_definition['STATUS_AKE_INIT'] = OTR.CONST.STATUS_AKE_INIT; | 65 $cls_definition['STATUS_AKE_INIT'] = OTR.CONST.STATUS_AKE_INIT; |
62 $cls_definition['STATUS_AKE_SUCCESS'] = OTR.CONST.STATUS_AKE_SUCCESS; | 66 $cls_definition['STATUS_AKE_SUCCESS'] = OTR.CONST.STATUS_AKE_SUCCESS; |
63 $cls_definition['STATUS_END_OTR'] = OTR.CONST.STATUS_END_OTR; | 67 $cls_definition['STATUS_END_OTR'] = OTR.CONST.STATUS_END_OTR; |
64 $cls_definition['STATE_PLAINTEXT'] = OTR.CONST.MSGSTATE_PLAINTEXT; | 68 $cls_definition['STATE_PLAINTEXT'] = OTR.CONST.MSGSTATE_PLAINTEXT; |
65 $cls_definition['STATE_ENCRYPTED'] = OTR.CONST.MSGSTATE_ENCRYPTED; | 69 $cls_definition['STATE_ENCRYPTED'] = OTR.CONST.MSGSTATE_ENCRYPTED; |
66 $cls_definition['STATE_FINISHED'] = OTR.CONST.MSGSTATE_FINISHED; | 70 $cls_definition['STATE_FINISHED'] = OTR.CONST.MSGSTATE_FINISHED; |
71 $cls_definition['OTR_TAG'] = OTR.CONST.OTR_TAG; | |
67 $cls_definition['OTR_VERSION_2'] = OTR.CONST.OTR_VERSION_2; | 72 $cls_definition['OTR_VERSION_2'] = OTR.CONST.OTR_VERSION_2; |
68 $cls_definition['OTR_VERSION_3'] = OTR.CONST.OTR_VERSION_3; | 73 $cls_definition['OTR_VERSION_3'] = OTR.CONST.OTR_VERSION_3; |
74 $cls_definition['WHITESPACE_TAG'] = OTR.CONST.WHITESPACE_TAG; | |
75 $cls_definition['WHITESPACE_TAG_V2'] = OTR.CONST.WHITESPACE_TAG_V2; | |
76 $cls_definition['WHITESPACE_TAG_V3'] = OTR.CONST.WHITESPACE_TAG_V3; | |
69 """) | 77 """) |
70 | 78 |
71 class UnencryptedMessage(Exception): | 79 class UnencryptedMessage(Exception): |
72 pass | 80 pass |
73 | 81 |
227 | 235 |
228 def parsePrivateKey(self, key): | 236 def parsePrivateKey(self, key): |
229 JS("""return DSA.parsePrivate(key);""") | 237 JS("""return DSA.parsePrivate(key);""") |
230 | 238 |
231 | 239 |
240 class proto(object): | |
241 | |
242 @classmethod | |
243 def checkForOTR(cls, body): | |
244 """Helper method to check if the message contains OTR starting tag or whitespace | |
245 | |
246 @return: | |
247 - context.OTR_TAG if the message starts with it | |
248 - context.WHITESPACE_TAG if the message contains OTR whitespaces | |
249 - None otherwise | |
250 """ | |
251 if body.startswith(context.OTR_TAG): | |
252 return context.OTR_TAG | |
253 index = body.find(context.WHITESPACE_TAG) | |
254 if index < 0: | |
255 return False | |
256 tags = [body[i:i + 8] for i in range(index, len(body), 8)] | |
257 if [True for tag in tags if tag in (context.WHITESPACE_TAG_V2, context.WHITESPACE_TAG_V3)]: | |
258 return context.WHITESPACE_TAG | |
259 return None | |
260 | |
261 | |
232 # serialazePrivateKey is the method name in potr | 262 # serialazePrivateKey is the method name in potr |
233 JS("""DSA.serializePrivateKey = DSA.packPrivate;""") | 263 JS("""DSA.serializePrivateKey = DSA.packPrivate;""") |