shithub: riscv

Download patch

ref: 3d052eb2ea48a7ab6e0169077a3f5b133c7121df
parent: cb1dc365c292e82a17b2e0a231b248b84773a14c
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);