git: 9front

Download patch

ref: 17080fe7d5a3c256121c809577012044dffef8e0
parent: 1097e8eb4403141460b67a33872dcf13a2e2991b
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Thu Mar 16 18:06:31 EDT 2017

upas/fs: tls sni support for pop3/imap

--- a/sys/src/cmd/upas/fs/dat.h
+++ b/sys/src/cmd/upas/fs/dat.h
@@ -216,7 +216,7 @@
 char		*flagmessages(int, char**);
 void		digestmessage(Mailbox*, Message*);
 
-int		wraptls(int);
+int		wraptls(int, char*);
 
 void		eprint(char*, ...);
 void		iprint(char *, ...);
--- a/sys/src/cmd/upas/fs/imap.c
+++ b/sys/src/cmd/upas/fs/imap.c
@@ -802,7 +802,7 @@
 		port = "imap";
 	if((imap->fd = dial(netmkaddr(imap->host, "net", port), 0, 0, 0)) < 0)
 		return imaperrstr(imap->host, port);
-	if(imap->flags & Fssl && (imap->fd = wraptls(imap->fd)) < 0){
+	if(imap->flags & Fssl && (imap->fd = wraptls(imap->fd, imap->host)) < 0){
 		err = imaperrstr(imap->host, port);
 		imap4disconnect(imap);
 		return err;
--- a/sys/src/cmd/upas/fs/pop3.c
+++ b/sys/src/cmd/upas/fs/pop3.c
@@ -151,7 +151,7 @@
 			return s;
 		Bterm(&pop->bin);
 		Bterm(&pop->bout);
-		if((pop->fd = wraptls(pop->fd)) < 0)
+		if((pop->fd = wraptls(pop->fd, pop->host)) < 0)
 			return geterrstr();
 		pop->encrypted = 1;
 		Binit(&pop->bin, pop->fd, OREAD);
@@ -237,7 +237,7 @@
 
 	if((pop->fd = dial(netmkaddr(pop->host, "net", pop->needssl ? "pop3s" : "pop3"), 0, 0, 0)) < 0)
 		return geterrstr();
-	if(pop->needssl && (pop->fd = wraptls(pop->fd)) < 0)
+	if(pop->needssl && (pop->fd = wraptls(pop->fd, pop->host)) < 0)
 		return geterrstr();
 	pop->encrypted = pop->needssl;
 	Binit(&pop->bin, pop->fd, OREAD);
--- a/sys/src/cmd/upas/fs/tls.c
+++ b/sys/src/cmd/upas/fs/tls.c
@@ -4,7 +4,7 @@
 #include "dat.h"
 
 int
-wraptls(int ofd)
+wraptls(int ofd, char *host)
 {
 	uchar digest[SHA1dlen];
 	Thumbprint *thumb;
@@ -12,6 +12,7 @@
 	int fd;
 
 	memset(&conn, 0, sizeof conn);
+	conn.serverName = host;
 	fd = tlsClient(ofd, &conn);
 	if(fd < 0){
 		close(ofd);
--