int main(int argc, char *argv[]) { if(argc != 2) { fprintf(stderr,"Please specify a url!\n"); exit(EXIT_FAILURE); } http_download_file(argv[1],NULL); return 0; }
int est_load_cacerts(struct hs20_osu_client *ctx, const char *url) { char *buf, *resp; size_t buflen; unsigned char *pkcs7; size_t pkcs7_len, resp_len; int res; buflen = os_strlen(url) + 100; buf = os_malloc(buflen); if (buf == NULL) return -1; os_snprintf(buf, buflen, "%s/cacerts", url); wpa_printf(MSG_INFO, "Download EST cacerts from %s", buf); write_summary(ctx, "Download EST cacerts from %s", buf); ctx->no_osu_cert_validation = 1; http_ocsp_set(ctx->http, 1); res = http_download_file(ctx->http, buf, "Cert/est-cacerts.txt", ctx->ca_fname); http_ocsp_set(ctx->http, (ctx->workarounds & WORKAROUND_OCSP_OPTIONAL) ? 1 : 2); ctx->no_osu_cert_validation = 0; if (res < 0) { wpa_printf(MSG_INFO, "Failed to download EST cacerts from %s", buf); write_result(ctx, "Failed to download EST cacerts from %s", buf); os_free(buf); return -1; } os_free(buf); resp = os_readfile("Cert/est-cacerts.txt", &resp_len); if (resp == NULL) { wpa_printf(MSG_INFO, "Could not read Cert/est-cacerts.txt"); write_result(ctx, "Could not read EST cacerts"); return -1; } pkcs7 = base64_decode((unsigned char *) resp, resp_len, &pkcs7_len); if (pkcs7 && pkcs7_len < resp_len / 2) { wpa_printf(MSG_INFO, "Too short base64 decode (%u bytes; downloaded %u bytes) - assume this was binary", (unsigned int) pkcs7_len, (unsigned int) resp_len); os_free(pkcs7); pkcs7 = NULL; } if (pkcs7 == NULL) { wpa_printf(MSG_INFO, "EST workaround - Could not decode base64, assume this is DER encoded PKCS7"); pkcs7 = os_malloc(resp_len); if (pkcs7) { os_memcpy(pkcs7, resp, resp_len); pkcs7_len = resp_len; } } os_free(resp); if (pkcs7 == NULL) { wpa_printf(MSG_INFO, "Could not fetch PKCS7 cacerts"); write_result(ctx, "Could not fetch EST PKCS#7 cacerts"); return -1; } res = pkcs7_to_cert(ctx, pkcs7, pkcs7_len, "Cert/est-cacerts.pem", NULL); os_free(pkcs7); if (res < 0) { wpa_printf(MSG_INFO, "Could not parse CA certs from PKCS#7 cacerts response"); write_result(ctx, "Could not parse CA certs from EST PKCS#7 cacerts response"); return -1; } unlink("Cert/est-cacerts.txt"); return 0; }