static int tls_config_add_keypair_file_internal(struct tls_config *config, const char *cert_file, const char *key_file, const char *ocsp_file) { struct tls_keypair *keypair; if ((keypair = tls_keypair_new()) == NULL) return (-1); if (tls_keypair_set_cert_file(keypair, &config->error, cert_file) != 0) goto err; if (tls_keypair_set_key_file(keypair, &config->error, key_file) != 0) goto err; if (ocsp_file != NULL && tls_keypair_set_ocsp_staple_file(keypair, &config->error, ocsp_file) != 0) goto err; tls_config_keypair_add(config, keypair); return (0); err: tls_keypair_free(keypair); return (-1); }
static int tls_config_add_keypair_mem_internal(struct tls_config *config, const uint8_t *cert, size_t cert_len, const uint8_t *key, size_t key_len, const uint8_t *staple, size_t staple_len) { struct tls_keypair *keypair; if ((keypair = tls_keypair_new()) == NULL) return (-1); if (tls_keypair_set_cert_mem(keypair, &config->error, cert, cert_len) != 0) goto err; if (tls_keypair_set_key_mem(keypair, &config->error, key, key_len) != 0) goto err; if (staple != NULL && tls_keypair_set_ocsp_staple_mem(keypair, &config->error, staple, staple_len) != 0) goto err; tls_config_keypair_add(config, keypair); return (0); err: tls_keypair_free(keypair); return (-1); }
void tls_config_free(struct tls_config *config) { struct tls_keypair *kp, *nkp; if (config == NULL) return; if (--config->refcount > 0) return; for (kp = config->keypair; kp != NULL; kp = nkp) { nkp = kp->next; tls_keypair_free(kp); } free(config->error.msg); free(config->alpn); free((char *)config->ca_mem); free((char *)config->ca_path); free((char *)config->ciphers); free((char *)config->crl_mem); free(config->ecdhecurves); free(config); }
void tls_config_free(struct tls_config *config) { struct tls_keypair *kp, *nkp; if (config == NULL) return; for (kp = config->keypair; kp != NULL; kp = nkp) { nkp = kp->next; tls_keypair_free(kp); } free(config->error.msg); free((char *)config->ca_file); free((char *)config->ca_path); free((char *)config->ciphers); free(config); }