Exemple #1
0
 def loadCertificates(self):
     certfile = "server.pem"
     if not os.path.isfile(certfile):
         import certificate
         certificate.create_self_signed_cert(certfile)
     os.chmod(certfile, 0o600)
     with open(certfile, 'r') as data:
         self.cert = ssl.PrivateCertificate.loadPEM(data.read()).options()
Exemple #2
0
	def loadCertificates(self):
		certfile = "server.pem"
		if not os.path.isfile(certfile):
			import certificate
			certificate.create_self_signed_cert(certfile)
		os.chmod(certfile, 0o600)
		with open(certfile, 'r') as data:
			self.cert = ssl.PrivateCertificate.loadPEM(data.read()).options()
Exemple #3
0
    def test_create_self_signed_certificate_nonexisting_file(self):
        key = "%s/%s" % (self.testing_dir, self.testing_key)
        crt = "%s/%s" % (self.testing_dir, self.testing_crt)

        certificate.create_self_signed_cert(self.testing_dir, self.testing_crt, self.testing_key)

        self.assertTrue(os.path.isfile(key), "Key was not created.")
        self.assertTrue(os.path.isfile(crt), "Certificate was not created.")
Exemple #4
0
    def test_create_self_signed_certificate_nonexisting_file(self):
        key = "%s/%s" % (self.testing_dir, self.testing_key)
        crt = "%s/%s" % (self.testing_dir, self.testing_crt)

        certificate.create_self_signed_cert(self.testing_dir, self.testing_crt,
                                            self.testing_key)

        self.assertTrue(os.path.isfile(key), "Key was not created.")
        self.assertTrue(os.path.isfile(crt), "Certificate was not created.")
Exemple #5
0
	def loadCertificates(self):
		certfile = "server.pem"
		if not os.path.isfile(certfile):
			import certificate
			certificate.create_self_signed_cert(certfile)
		os.chmod(certfile, 0o600)
		f = open(certfile, "r")
		self.cert = ssl.PrivateCertificate.loadPEM(f.read()).options()
		f.close()
Exemple #6
0
    def test_create_self_signed_certificate_existing_file(self):
        key = "%s/%s" % (self.testing_dir, self.testing_key)
        crt = "%s/%s" % (self.testing_dir, self.testing_crt)

        key_file = open(key, 'w')
        crt_file = open(crt, 'w')

        kc, cc = os.path.getmtime(key), os.path.getmtime(crt)

        certificate.create_self_signed_cert(self.testing_dir, self.testing_crt, self.testing_key)

        kcm, ccm = os.path.getmtime(key), os.path.getmtime(crt)

        self.assertEquals(kc, kcm, "File modified times do not match, they should.")
        self.assertEquals(cc, ccm, "File modified times do not match, they should.")

        key_file.close()
        crt_file.close()
def main():

    continua = True

    certificate.create_self_signed_cert()

    f = open("selfsigned.crt")
    cert_buffer = f.read()
    f.close()

    cert = X509.load_cert_string(cert_buffer, X509.FORMAT_PEM)
    pub_key = cert.get_pubkey()
    rsa_key = pub_key.get_rsa()

    ReadRSA = RSA.load_key('private.key')

    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect((sys.argv[1], 10009))

    while (continua == True):

        order = raw_input("Next Order:")
        orders = order.split(" ")
        send_data(sock, orders[0])

        if (orders[0] == "DIRSEARCH"):
            send_data(sock, orders[1])
            print recv_data(sock)

        if (orders[0] == "DOWNLOAD"):
            send_data(sock, orders[1])
            receive_file_contents(orders[1], sock, ReadRSA)

        if (orders[0] == "UPLOAD"):
            send_data(sock, orders[1])
            send_file_contents(orders[1], sock, rsa_key)

        if (orders[0] == "CLOSE"):
            continua = False

    return
Exemple #8
0
    def test_create_self_signed_certificate_existing_file(self):
        key = "%s/%s" % (self.testing_dir, self.testing_key)
        crt = "%s/%s" % (self.testing_dir, self.testing_crt)

        key_file = open(key, 'w')
        crt_file = open(crt, 'w')

        kc, cc = os.path.getmtime(key), os.path.getmtime(crt)

        certificate.create_self_signed_cert(self.testing_dir, self.testing_crt,
                                            self.testing_key)

        kcm, ccm = os.path.getmtime(key), os.path.getmtime(crt)

        self.assertEquals(kc, kcm,
                          "File modified times do not match, they should.")
        self.assertEquals(cc, ccm,
                          "File modified times do not match, they should.")

        key_file.close()
        crt_file.close()