-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtls.c
More file actions
56 lines (50 loc) · 1.13 KB
/
Copy pathtls.c
File metadata and controls
56 lines (50 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <u.h>
#include <libc.h>
#include <mp.h>
#include <libsec.h>
#include "dat.h"
#include "fns.h"
int
istrusted(uchar* cert, int certlen)
{
uchar digest[SHA1dlen];
Thumbprint *table;
fmtinstall('H', encodefmt);
if(cert==nil || certlen <= 0) {
werrstr("server did not provide TLS certificate");
return 0;
}
sha1(cert, certlen, digest, nil);
table = initThumbprints("/sys/lib/tls/rdp", "/sys/lib/tls/rdp.exclude");
if(!table || !okThumbprint(digest, table)){
werrstr("server certificate not recognized");
fprint(2, "verify server certificate %.*H \n", SHA1dlen, digest);
fprint(2, "add thumbprint after verification\n");
fprint(2, "\techo 'x509 sha1=%.*H' >> %q\n", SHA1dlen, digest, "/sys/lib/tls/rdp");
return 0;
}
freeThumbprints(table);
return 1;
}
/* lifted from /sys/src/cmd/upas/fs/imap4.c:/^starttls */
int
starttls(Rdp* r)
{
TLSconn c;
int fd, sfd;
fd = r->fd;
memset(&c, 0, sizeof c);
sfd = tlsClient(fd, &c);
if(sfd < 0){
werrstr("tlsClient: %r");
return -1;
}
if(!istrusted(c.cert, c.certlen)){
close(sfd);
return -1;
}
/* BUG: free c.cert? */
close(r->fd);
r->fd = sfd;
return sfd;
}