def sharesMail(data): ''' Create Bitcoin Address and Shares Send Email ''' note, share, addr, part, email, use_gpg = data print "Got work, sending to email %s" % email if part.lower() == 'escrower': body = TEMPLATE_ESCROWER % (addr, share) elif part.lower() == 'buyer': body = TEMPLATE_BUYER % (addr, share) elif part.lower() == 'seller': body = TEMPLATE_SELLER % (addr, share) else: body = TEMPLATE_BASE % {'part': part, 'fromwhere': PATH, 'msg': """ The address %s was generated for this process and it is expected that any funds are sent to it. This is a custom n-m split and it is assumed that you know your role in the process. Your key: %s """ % (addr, share)} if int(use_gpg): body_new, err = gpg.encrypt(body, email) if err: print "GPG failed, sending in plain text: %s" % err else: body = body_new subject = SUBJECT return send(email, note, body, subject)
def encrypt(self, gpg, keys): if self.is_encrypted() or self.is_signed(): return if self._message.get_content_type() == "text/plain": self._message.set_payload(gpg.encrypt(self.__content, keys)) set_header(self._message, "Content-Transfer-Encoding", None) set_header(self._message, "X-GPGIt", "true") else: payload = email.message.Message() payload.set_type(self._message.get_content_type()) payload.set_charset(self._message.get_content_charset()) payload.set_payload(self._message.get_payload()) set_header(payload, "Content-Transfer-Encoding", self._message.get("Content-Transfer-Encoding")) set_header(payload, "MIME-Version", None) self._mime_encrypt(payload.as_string(), gpg, keys)
def post_handler(data, request): ''' returns a json response with error messages etc ''' emails = (['Escrower',data['escrower'],data['encypt_emails']], ['Buyer',data['buyer'], data['encypt_emails']], ['Seller',data['sender'],data['encypt_emails']] ) note = '' if data['note']: note = data.get('note', u'').encode('utf8') result = {} if len(emails) == 3: # Test GPG. using_gpg = False for item in emails: recipient, use_gpg = item[1], item[2] if not use_gpg: continue using_gpg = True _, failed = gpg.encrypt('test', recipient) #if failed: #result['error'] = 'Failed to obtain public for key %s' %recipient #messages.error(request, 'Failed to obtain public for key %s' %recipient); if using_gpg: gpg_note = ('If GPG fails for whatever reason, one or more emails ' 'will be sent in plain text.') else: gpg_note = '' # Generate a new private key, and a bitcoin address from it. pk, wif_pk = bitcoin.privatekey() addr = bitcoin.address(pk) # Split the private key in m parts. shares = ssss.split(wif_pk, 2, 3) # Send the shares by email for share, email in zip(shares, emails): message = "%s" %share result = True print email result = mailer.sharesMail([note, share, addr, email[0], email[1], str(int(email[2]))] ) return result
def message(self): msg=super(EmailPGP, self).message() encoding = self.encoding or settings.DEFAULT_CHARSET del msg['From'] del msg['Subject'] del msg['To'] del msg['Date'] if self.signed: tmp = SafeMIMEMultipart(_subtype=self.signed_subtype, encoding=encoding) tmp.attach(msg) attachment = MIMEBase('application', 'pgp-signature') #We don't want base64 enconding attachment.set_payload(detach_sign(msg.as_string(), self.from_email)) attachment.add_header('Content-Disposition', 'attachment', filename='signature.asc') tmp.attach(attachment) msg=tmp if self.encrypted: tmp = SafeMIMEMultipart(_subtype=self.encrypted_subtype, encoding=encoding) tmp.attach(self._create_attachment('', '', 'application/pgp-encrypted')) attachment = MIMEBase('application', 'octet-stream') #We don't want base64 enconding attachment.set_payload(encrypt(msg.as_string(), self.to)) attachment.add_header('Content-Disposition', 'inline', filename='msg.asc') tmp.attach(attachment) msg=tmp msg['Subject'] = self.subject msg['From'] = self.extra_headers.get('From', self.from_email) msg['To'] = self.extra_headers.get('To', ', '.join(self.to)) if self.cc: msg['Cc'] = ', '.join(self.cc) # Email header names are case-insensitive (RFC 2045), so we have to # accommodate that when doing comparisons. header_names = [key.lower() for key in self.extra_headers] if 'date' not in header_names: msg['Date'] = formatdate() if 'message-id' not in header_names: msg['Message-ID'] = make_msgid() for name, value in self.extra_headers.items(): if name.lower() in ('from', 'to'): # From and To are already handled continue msg[name] = value return msg
def post_handler(data, request): ''' returns a json response with error messages etc ''' emails = (['Escrower', data['escrower'], data['encypt_emails'] ], ['Buyer', data['buyer'], data['encypt_emails']], ['Seller', data['sender'], data['encypt_emails']]) note = '' if data['note']: note = data.get('note', u'').encode('utf8') result = {} if len(emails) == 3: # Test GPG. using_gpg = False for item in emails: recipient, use_gpg = item[1], item[2] if not use_gpg: continue using_gpg = True _, failed = gpg.encrypt('test', recipient) #if failed: #result['error'] = 'Failed to obtain public for key %s' %recipient #messages.error(request, 'Failed to obtain public for key %s' %recipient); if using_gpg: gpg_note = ('If GPG fails for whatever reason, one or more emails ' 'will be sent in plain text.') else: gpg_note = '' # Generate a new private key, and a bitcoin address from it. pk, wif_pk = bitcoin.privatekey() addr = bitcoin.address(pk) # Split the private key in m parts. shares = ssss.split(wif_pk, 2, 3) # Send the shares by email for share, email in zip(shares, emails): message = "%s" % share result = True print email result = mailer.sharesMail( [note, share, addr, email[0], email[1], str(int(email[2]))]) return result
def _mime_encrypt(self, payload, gpg, keys): payload = gpg.encrypt(payload, keys) self._message.set_type("multipart/encrypted"); self._message.set_param("protocol", "application/pgp-encrypted"); self._message.del_param("micalg"); set_header(self._message, "Content-Transfer-Encoding", None) set_header(self._message, "X-GPGIt", "true") self._message.preamble = "" self._message.set_payload(None) pgp_encrypted = MIMEApplication("Version: 1", "pgp-encrypted", email.encoders.encode_7or8bit) set_header(pgp_encrypted, "Content-Disposition", "attachment") set_header(pgp_encrypted, "MIME-Version", None) self._message.attach(pgp_encrypted) octet_stream = MIMEApplication(payload, "octet-stream", email.encoders.encode_7or8bit) set_header(octet_stream, "Content-Disposition", "inline", filename="msg.asc") set_header(octet_stream, "MIME-Version", None) self._message.attach(octet_stream)
def main(): ctx = zmq.Context.instance() sock = ctx.socket(zmq.PULL) sock.bind(webcfg.zmqemail) while True: print "Waiting for work" note, share, addr, part, email, use_gpg = sock.recv_multipart() print "Got work, sending to email %s" % email if part.lower() == 'escrower': body = TEMPLATE_ESCROWER % (addr, share) elif part.lower() == 'buyer': body = TEMPLATE_BUYER % (addr, share) elif part.lower() == 'seller': body = TEMPLATE_SELLER % (addr, share) else: body = TEMPLATE_BASE % {'part': part, 'fromwhere': PATH, 'msg': """ The address %s was generated for this process and it is expected that any funds are sent to it. This is a custom n-m split and it is assumed that you know your role in the process. Your key: %s """ % (addr, share)} if int(use_gpg): body_new, err = gpg.encrypt(body, email) if err: print "GPG failed, sending in plain text: %s" % err else: body = body_new send(email, note, body)
print "Invalid email: %s" % e self.write(INVALID) return note = data.get('note', u'').encode('utf8') if len(note) > MAX_FIELD_LEN: self.write(INVALID) return # Test GPG. using_gpg = False for item in data['email']: recipient, use_gpg = item[1], item[2] if not use_gpg: continue using_gpg = True _, failed = gpg.encrypt('test', recipient) if failed: reply = {'error': 'Failed to obtain public for key %s' % recipient} self.write(json.dumps(reply)) return if using_gpg: gpg_note = ('If GPG fails for whatever reason, one or more emails ' 'will be sent in plain text.') else: gpg_note = '' # Generate a new private key, and a bitcoin address from it. pk, wif_pk = bitcoin.privatekey() addr = bitcoin.address(pk) # Split the private key in m parts.
def test_gpg_encyption(self): _, failed = gpg.encrypt('test', "*****@*****.**") self.assertEqual(False, failed)
def test_gpg_encyption(self): _, failed = gpg.encrypt('test',"*****@*****.**") self.assertEqual(False,failed)
def encrypt(self, gpg, keys): payload = gpg.encrypt(self.plaintext, keys) self._message.set_payload(payload) set_header(self._message, "Content-Transfer-Encoding", None) set_header(self._message, "X-GPGIt-Wrapped", "true")