aboutsummaryrefslogtreecommitdiffstats
path: root/src/sbearssl/sbearssl_cert_readfile.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2016-11-25 20:16:06 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2016-11-25 20:16:06 +0000
commit8d532683386121e70810b0d7c6642cc2c2b89cb0 (patch)
tree866010763c829a35b18603c5af58896bd14afd18 /src/sbearssl/sbearssl_cert_readfile.c
parent018025f0f36a4847df265c9948dbaf7073ed3245 (diff)
downloads6-networking-8d532683386121e70810b0d7c6642cc2c2b89cb0.tar.gz
Fix build bugs. It builds!
Two things remain to do: - how to pass SNI information to libtls - how to detect cert issuer key type for ECC in bearssl
Diffstat (limited to 'src/sbearssl/sbearssl_cert_readfile.c')
-rw-r--r--src/sbearssl/sbearssl_cert_readfile.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/sbearssl/sbearssl_cert_readfile.c b/src/sbearssl/sbearssl_cert_readfile.c
index 6090624..6cc78c1 100644
--- a/src/sbearssl/sbearssl_cert_readfile.c
+++ b/src/sbearssl/sbearssl_cert_readfile.c
@@ -10,7 +10,7 @@
#include <skalibs/djbunix.h>
#include <s6-networking/sbearssl.h>
-int sbearssl_cert_readfile (char const *fn, genalloc *certs, stralloc *sa) ;
+int sbearssl_cert_readfile (char const *fn, genalloc *certs, stralloc *sa)
{
char buf[BUFFER_INSIZE] ;
int fd = open_readb(fn) ;
@@ -18,12 +18,14 @@ int sbearssl_cert_readfile (char const *fn, genalloc *certs, stralloc *sa) ;
genalloc pems = GENALLOC_ZERO ;
sbearssl_pemobject *p ;
size_t certsbase = genalloc_len(sbearssl_cert, certs) ;
+ size_t sabase = sa->len ;
size_t n ;
size_t i = 0 ;
int certswasnull = !genalloc_s(sbearssl_cert, certs) ;
+ int sawasnull = !sa->s ;
int r ;
if (fd < 0) return -1 ;
- r = sbearssl_pem_decode_from_buffer(buf, n, &pems, sa) ;
+ r = sbearssl_pem_decode_from_buffer(&b, &pems, sa) ;
if (r) { fd_close(fd) ; return r ; }
fd_close(fd) ;
p = genalloc_s(sbearssl_pemobject, &pems) ;
@@ -46,7 +48,8 @@ int sbearssl_cert_readfile (char const *fn, genalloc *certs, stralloc *sa) ;
fail:
if (certswasnull) genalloc_free(sbearssl_cert, certs) ;
else genalloc_setlen(sbearssl_cert, certs, certsbase) ;
- stralloc_free(&sa) ;
- genalloc_free(sbearssl_pemobject, pems) ;
+ if (sawasnull) stralloc_free(sa) ;
+ else sa->len = sabase ;
+ genalloc_free(sbearssl_pemobject, &pems) ;
return r ;
}