1 0fc65b37 2004-03-21 devnull #include <u.h>
2 0fc65b37 2004-03-21 devnull #include <libc.h>
3 0fc65b37 2004-03-21 devnull #include <auth.h>
4 0fc65b37 2004-03-21 devnull #include <mp.h>
5 0fc65b37 2004-03-21 devnull #include <libsec.h>
7 0fc65b37 2004-03-21 devnull static char*
8 0fc65b37 2004-03-21 devnull readfile(char *name)
14 0fc65b37 2004-03-21 devnull fd = open(name, OREAD);
15 0fc65b37 2004-03-21 devnull if(fd < 0)
16 0fc65b37 2004-03-21 devnull return nil;
17 0fc65b37 2004-03-21 devnull if((d = dirfstat(fd)) == nil)
18 0fc65b37 2004-03-21 devnull return nil;
19 0fc65b37 2004-03-21 devnull s = malloc(d->length + 1);
20 0fc65b37 2004-03-21 devnull if(s == nil || readn(fd, s, d->length) != d->length){
23 0fc65b37 2004-03-21 devnull close(fd);
24 0fc65b37 2004-03-21 devnull return nil;
26 0fc65b37 2004-03-21 devnull close(fd);
27 0fc65b37 2004-03-21 devnull s[d->length] = '\0';
29 0fc65b37 2004-03-21 devnull return s;
33 0fc65b37 2004-03-21 devnull readcert(char *filename, int *pcertlen)
35 0fc65b37 2004-03-21 devnull char *pem;
36 0fc65b37 2004-03-21 devnull uchar *binary;
38 0fc65b37 2004-03-21 devnull pem = readfile(filename);
39 0fc65b37 2004-03-21 devnull if(pem == nil){
40 0fc65b37 2004-03-21 devnull werrstr("can't read %s", filename);
41 0fc65b37 2004-03-21 devnull return nil;
43 1b1434eb 2004-12-26 devnull binary = decodepem(pem, "CERTIFICATE", pcertlen, nil);
44 0fc65b37 2004-03-21 devnull free(pem);
45 0fc65b37 2004-03-21 devnull if(binary == nil){
46 0fc65b37 2004-03-21 devnull werrstr("can't parse %s", filename);
47 0fc65b37 2004-03-21 devnull return nil;
49 0fc65b37 2004-03-21 devnull return binary;
53 1b1434eb 2004-12-26 devnull PEMChain *
54 1b1434eb 2004-12-26 devnull readcertchain(char *filename)
56 1b1434eb 2004-12-26 devnull char *chfile;
57 1b1434eb 2004-12-26 devnull PEMChain *chp;
59 1b1434eb 2004-12-26 devnull chfile = readfile(filename);
60 1b1434eb 2004-12-26 devnull if (chfile == nil) {
61 1b1434eb 2004-12-26 devnull werrstr("can't read %s", filename);
62 1b1434eb 2004-12-26 devnull return nil;
64 1b1434eb 2004-12-26 devnull chp = decodepemchain(chfile, "CERTIFICATE");
65 1b1434eb 2004-12-26 devnull return chp;