1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- /*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
- #include <u.h>
- #include <libc.h>
- #include <mp.h>
- #include <libsec.h>
- static int8_t*
- readfile(int8_t *name)
- {
- int fd;
- int8_t *s;
- Dir *d;
- fd = open(name, OREAD);
- if(fd < 0)
- return nil;
- if((d = dirfstat(fd)) == nil)
- return nil;
- s = malloc(d->length + 1);
- if(s == nil || readn(fd, s, d->length) != d->length){
- free(s);
- free(d);
- close(fd);
- return nil;
- }
- close(fd);
- s[d->length] = '\0';
- free(d);
- return s;
- }
- uint8_t*
- readcert(int8_t *filename, int *pcertlen)
- {
- int8_t *pem;
- uint8_t *binary;
- pem = readfile(filename);
- if(pem == nil){
- werrstr("can't read %s", filename);
- return nil;
- }
- binary = decodepem(pem, "CERTIFICATE", pcertlen);
- free(pem);
- if(binary == nil){
- werrstr("can't parse %s", filename);
- return nil;
- }
- return binary;
- }
|