Monday, 29 November 2010

Python Lab - Sending Email using Python script and Gmail SMTP server

When we need to generate an alert from our program, most likely we will send it by EMAIL or SMS. Today, I am going to do it in a cheapest way: Gmail + Python.

The things that we need to do is to replace the highlighted values.

*************************************************************************************
import smtplib

def send(subject="", msg=""):

    # recipient
    rcpt_to = 'recipient@gmail.com'
   
    # login parameter
    gmail_username = 'sender@gmail.com'
    gmail_password = 'password'
   
    # login sever
    gmail_server = smtplib.SMTP("smtp.gmail.com",587)
    gmail_server.ehlo()
    gmail_server.starttls()
    gmail_server.ehlo
    gmail_server.login(gmail_username, gmail_password)

    # Email header
    sendhead = 'From: Sender <' + gmail_username + '>\n'
    rcpthead = 'To: Recipient <' + rcpt_to + '>\n'
    subject = 'Subject:' + subject + '\n'
    msg = sendhead + rcpthead + subject + '\n' + msg + '\n\n'
   
    gmail_server.sendmail(gmail_username, to, msg)
    gmail_server.close()

if __name__ =='__main__':

        msg = raw_input("Please enter the msg: ")
        subject = "Testing Alert"
        send(subject,msg)

Thursday, 18 November 2010

Diffie-Hellman (DH)

It is used as key agreement protocol, aka exponential key agreement, which allows 2 users to exchange a secret key over an insecure medium without exchange prior secrets.

Key exchange is vulnerable to a man-in-the-middle attack

Normal
A ------------------------- B

MITM
A --------- M ----------- B

The main drawback is that DH does not authenticate both the parties.

For non-repudiation purpose, we will need to consider using digital signatures.

Reference: Official (ISC)2 Guide to the CISSP CBK, Second Edition ((ISC)2 Press)