def load(self, value): # load the raw data and info from the given value self._data = value info, key = PNG.getChunk(value, _infoType), PNG.getChunk(value, _keyType) if not info: raise Exception('cannot read card information') off = 0 while off < len(info): name, off = _readUTF(info, off); value, off = _readUTF(info, off) if name in _infoNames: self.__dict__[name] = value else: break if self.keywords: self.keywords = map(unicode.strip, self.keywords.split(';')) if key: if self.title == 'Private Login Card': self.Ks = crypto.load(key) elif self.title == 'Internet Visiting Card': self.Kp = crypto.load(key) else: raise ValueError('Neither a Private Login Card nor a Internet Visiting Card. title=%r'%(self.title))
def create(query): try: if 'logincard' not in query or 'visitingcard' not in query: raise Exception('missing logincard or visitingcard to create') logincard, visitingcard = vcard.Card(b64decode(query.get('logincard')[0])), vcard.Card(b64decode(query.get('visitingcard')[0])) if _debug: print 'input is', len(logincard.data), len(visitingcard.data) loginSent = visitingSent = False # whether emails could be sent successfully or not? if not logincard.Ks: # create private key if needed vcard.Card.createKeys(logincard, visitingcard) try: sendmail([logincard.email], _loginEmailSubject, _loginEmailText, _admin, [('loginCard.png', logincard.data)]) loginSent = True except: traceback and traceback.print_exc() # raise Exception('could not send login card in email to ' + logincard.email) global _masterKey Ks = crypto.load(_masterKey) visitingcard.sign(Ks) try: sendmail([visitingcard.email], _visitingEmailSubject(visitingcard), _visitingEmailText(visitingcard), _admin, [('visitingCard.png', visitingcard.data)]) visitingSent = True except: traceback and traceback.print_exc() # raise Exception('could not send visiting card in email to ' + visitingcard.email) param=dict(code='success') # add more parameters if we didn't send email correctly if not loginSent: param['logincard'] = b64encode(logincard.data) if not visitingSent: param['visitingcard'] = b64encode(visitingcard.data) return _result(**param) except Exception, e: traceback and traceback.print_exc(); return _error(e)