From 5a24ec69761915549fdca00968cfa49863b994a7 Mon Sep 17 00:00:00 2001 From: John Chadwick <86682572+johnwchadwick@users.noreply.github.com> Date: Thu, 22 Jul 2021 21:12:08 -0700 Subject: [PATCH] feat: support curl_blob options Fixes #253. --- lib/Curl.ts | 8 + lib/generated/CurlInfo.ts | 10 +- lib/generated/CurlOption.ts | 548 ++++++++++++++++++++++++- lib/generated/MultiOption.ts | 2 +- lib/types/EasyNativeBinding.ts | 8 + scripts/build-constants.js | 3 +- scripts/data/options.js | 9 + scripts/utils/createSetOptOverloads.js | 5 + scripts/utils/curlOptionsBlacklist.js | 8 - src/Curl.cc | 11 + src/Curl.h | 1 + src/Easy.cc | 32 ++ test/curl/setOpt.spec.ts | 5 + 13 files changed, 630 insertions(+), 20 deletions(-) diff --git a/lib/Curl.ts b/lib/Curl.ts index 493fbcd54..145c9802e 100644 --- a/lib/Curl.ts +++ b/lib/Curl.ts @@ -28,6 +28,7 @@ import { DataCallbackOptions, ProgressCallbackOptions, StringListOptions, + BlobListOptions, CurlOptionName, SpecificOptions, CurlOptionValueType, @@ -1226,6 +1227,13 @@ interface Curl { * Official libcurl documentation: [`curl_easy_setopt()`](http://curl.haxx.se/libcurl/c/curl_easy_setopt.html) */ setOpt(option: StringListOptions, value: string[] | null): this + /** + * Use {@link "Curl".Curl.option|`Curl.option`} for predefined constants. + * + * + * Official libcurl documentation: [`curl_easy_setopt()`](http://curl.haxx.se/libcurl/c/curl_easy_setopt.html) + */ + setOpt(option: BlobListOptions, value: Buffer | string | null): this /** * Use {@link "Curl".Curl.option|`Curl.option`} for predefined constants. * diff --git a/lib/generated/CurlInfo.ts b/lib/generated/CurlInfo.ts index e206aa0ee..1158cd308 100644 --- a/lib/generated/CurlInfo.ts +++ b/lib/generated/CurlInfo.ts @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ -// This file was generated by scripts/build-constants.js on 2020-10-11T15:59:27.934Z +// This file was generated by scripts/build-constants.js on 2021-07-23T03:53:26.721Z // Do not edit manually /** @@ -305,6 +305,13 @@ export interface CurlInfo { */ readonly REDIRECT_URL: 'REDIRECT_URL' + /** + * Referrer header. See CURLINFO_REFERER(3) + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLINFO_REFERER.html](https://curl.haxx.se/libcurl/c/CURLINFO_REFERER.html) + */ + readonly REFERER: 'REFERER' + /** * Number of bytes sent in the issued HTTP requests. * @@ -520,6 +527,7 @@ export type CurlInfoName = | 'REDIRECT_TIME' | 'REDIRECT_TIME_T' | 'REDIRECT_URL' + | 'REFERER' | 'REQUEST_SIZE' | 'RESPONSE_CODE' | 'RETRY_AFTER' diff --git a/lib/generated/CurlOption.ts b/lib/generated/CurlOption.ts index 2fcbcf52c..c8d4cbbeb 100644 --- a/lib/generated/CurlOption.ts +++ b/lib/generated/CurlOption.ts @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ -// This file was generated by scripts/build-constants.js on 2020-10-11T15:59:26.976Z +// This file was generated by scripts/build-constants.js on 2021-07-23T03:53:25.898Z // Do not edit manually import { CurlChunk } from '../enum/CurlChunk' @@ -89,6 +89,13 @@ export interface CurlOption { */ readonly AUTOREFERER: 'AUTOREFERER' + /** + * AWS HTTP V4 Signature. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_AWS_SIGV4.html](https://curl.haxx.se/libcurl/c/CURLOPT_AWS_SIGV4.html) + */ + readonly AWS_SIGV4: 'AWS_SIGV4' + /** * Ask for alternate buffer size. * @@ -103,6 +110,13 @@ export interface CurlOption { */ readonly CAINFO: 'CAINFO' + /** + * CA cert bundle memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_CAINFO_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_CAINFO_BLOB.html) + */ + readonly CAINFO_BLOB: 'CAINFO_BLOB' + /** * Path to CA cert bundle. * @@ -293,7 +307,28 @@ export interface CurlOption { readonly DNS_USE_GLOBAL_CACHE: 'DNS_USE_GLOBAL_CACHE' /** - * Use this DOH server for name resolves. + * Verify the host name in the DoH (DNS-over-HTTPS) SSL certificate. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_DOH_SSL_VERIFYHOST.html](https://curl.haxx.se/libcurl/c/CURLOPT_DOH_SSL_VERIFYHOST.html) + */ + readonly DOH_SSL_VERIFYHOST: 'DOH_SSL_VERIFYHOST' + + /** + * Verify the DoH (DNS-over-HTTPS) SSL certificate. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_DOH_SSL_VERIFYPEER.html](https://curl.haxx.se/libcurl/c/CURLOPT_DOH_SSL_VERIFYPEER.html) + */ + readonly DOH_SSL_VERIFYPEER: 'DOH_SSL_VERIFYPEER' + + /** + * Verify the DoH (DNS-over-HTTPS) SSL certificate's status. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_DOH_SSL_VERIFYSTATUS.html](https://curl.haxx.se/libcurl/c/CURLOPT_DOH_SSL_VERIFYSTATUS.html) + */ + readonly DOH_SSL_VERIFYSTATUS: 'DOH_SSL_VERIFYSTATUS' + + /** + * Use this DoH server for name resolves. * * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_DOH_URL.html](https://curl.haxx.se/libcurl/c/CURLOPT_DOH_URL.html) */ @@ -481,6 +516,48 @@ export interface CurlOption { */ readonly HEADEROPT: 'HEADEROPT' + /** + * Set HSTS cache file. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_HSTS.html](https://curl.haxx.se/libcurl/c/CURLOPT_HSTS.html) + */ + readonly HSTS: 'HSTS' + + /** + * Enable HSTS. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_HSTS_CTRL.html](https://curl.haxx.se/libcurl/c/CURLOPT_HSTS_CTRL.html) + */ + readonly HSTS_CTRL: 'HSTS_CTRL' + + /** + * Pass pointer to the HSTS read callback. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_HSTSREADDATA.html](https://curl.haxx.se/libcurl/c/CURLOPT_HSTSREADDATA.html) + */ + readonly HSTSREADDATA: 'HSTSREADDATA' + + /** + * Set HSTS read callback. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_HSTSREADFUNCTION.html](https://curl.haxx.se/libcurl/c/CURLOPT_HSTSREADFUNCTION.html) + */ + readonly HSTSREADFUNCTION: 'HSTSREADFUNCTION' + + /** + * Pass pointer to the HSTS write callback. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_HSTSWRITEDATA.html](https://curl.haxx.se/libcurl/c/CURLOPT_HSTSWRITEDATA.html) + */ + readonly HSTSWRITEDATA: 'HSTSWRITEDATA' + + /** + * Set HSTS write callback. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_HSTSWRITEFUNCTION.html](https://curl.haxx.se/libcurl/c/CURLOPT_HSTSWRITEFUNCTION.html) + */ + readonly HSTSWRITEFUNCTION: 'HSTSWRITEFUNCTION' + /** * Disable Content decoding. * @@ -580,7 +657,7 @@ export interface CurlOption { readonly INTERFACE: 'INTERFACE' /** - * IP version to resolve to. + * IP version to use. * * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_IPRESOLVE.html](https://curl.haxx.se/libcurl/c/CURLOPT_IPRESOLVE.html) */ @@ -593,6 +670,13 @@ export interface CurlOption { */ readonly ISSUERCERT: 'ISSUERCERT' + /** + * Issuer certificate memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_ISSUERCERT_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_ISSUERCERT_BLOB.html) + */ + readonly ISSUERCERT_BLOB: 'ISSUERCERT_BLOB' + /** * Keep sending on HTTP \>= 300 errors. * @@ -908,6 +992,13 @@ export interface CurlOption { */ readonly PROXY_CAINFO: 'PROXY_CAINFO' + /** + * Proxy CA cert bundle memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_CAINFO_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_CAINFO_BLOB.html) + */ + readonly PROXY_CAINFO_BLOB: 'PROXY_CAINFO_BLOB' + /** * Path to proxy CA cert bundle. * @@ -985,6 +1076,20 @@ export interface CurlOption { */ readonly PROXY_SSL_VERIFYPEER: 'PROXY_SSL_VERIFYPEER' + /** + * Proxy client cert. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLCERT.html](https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLCERT.html) + */ + readonly PROXY_SSLCERT: 'PROXY_SSLCERT' + + /** + * Proxy client cert memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLCERT_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLCERT_BLOB.html) + */ + readonly PROXY_SSLCERT_BLOB: 'PROXY_SSLCERT_BLOB' + /** * Proxy client cert type. * @@ -999,6 +1104,13 @@ export interface CurlOption { */ readonly PROXY_SSLKEY: 'PROXY_SSLKEY' + /** + * Proxy client key. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLKEY_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLKEY_BLOB.html) + */ + readonly PROXY_SSLKEY_BLOB: 'PROXY_SSLKEY_BLOB' + /** * Proxy client key type. * @@ -1398,6 +1510,13 @@ export interface CurlOption { */ readonly SSLCERT: 'SSLCERT' + /** + * Client cert memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_SSLCERT_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_SSLCERT_BLOB.html) + */ + readonly SSLCERT_BLOB: 'SSLCERT_BLOB' + /** * Client cert type. * @@ -1426,6 +1545,13 @@ export interface CurlOption { */ readonly SSLKEY: 'SSLKEY' + /** + * Client key memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_SSLKEY_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_SSLKEY_BLOB.html) + */ + readonly SSLKEY_BLOB: 'SSLKEY_BLOB' + /** * Client key type. * @@ -1750,6 +1876,13 @@ export const CurlOptionCamelCaseMap = { */ autoReferer: 'AUTOREFERER', + /** + * AWS HTTP V4 Signature. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_AWS_SIGV4.html](https://curl.haxx.se/libcurl/c/CURLOPT_AWS_SIGV4.html) + */ + awsSigv4: 'AWS_SIGV4', + /** * Ask for alternate buffer size. * @@ -1764,6 +1897,13 @@ export const CurlOptionCamelCaseMap = { */ caInfo: 'CAINFO', + /** + * CA cert bundle memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_CAINFO_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_CAINFO_BLOB.html) + */ + caInfoBlob: 'CAINFO_BLOB', + /** * Path to CA cert bundle. * @@ -1954,7 +2094,28 @@ export const CurlOptionCamelCaseMap = { dnsUseGlobalCache: 'DNS_USE_GLOBAL_CACHE', /** - * Use this DOH server for name resolves. + * Verify the host name in the DoH (DNS-over-HTTPS) SSL certificate. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_DOH_SSL_VERIFYHOST.html](https://curl.haxx.se/libcurl/c/CURLOPT_DOH_SSL_VERIFYHOST.html) + */ + dohSslVerifyHost: 'DOH_SSL_VERIFYHOST', + + /** + * Verify the DoH (DNS-over-HTTPS) SSL certificate. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_DOH_SSL_VERIFYPEER.html](https://curl.haxx.se/libcurl/c/CURLOPT_DOH_SSL_VERIFYPEER.html) + */ + dohSslVerifyPeer: 'DOH_SSL_VERIFYPEER', + + /** + * Verify the DoH (DNS-over-HTTPS) SSL certificate's status. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_DOH_SSL_VERIFYSTATUS.html](https://curl.haxx.se/libcurl/c/CURLOPT_DOH_SSL_VERIFYSTATUS.html) + */ + dohSslVerifyStatus: 'DOH_SSL_VERIFYSTATUS', + + /** + * Use this DoH server for name resolves. * * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_DOH_URL.html](https://curl.haxx.se/libcurl/c/CURLOPT_DOH_URL.html) */ @@ -2142,6 +2303,48 @@ export const CurlOptionCamelCaseMap = { */ headerOpt: 'HEADEROPT', + /** + * Set HSTS cache file. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_HSTS.html](https://curl.haxx.se/libcurl/c/CURLOPT_HSTS.html) + */ + hsts: 'HSTS', + + /** + * Enable HSTS. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_HSTS_CTRL.html](https://curl.haxx.se/libcurl/c/CURLOPT_HSTS_CTRL.html) + */ + hstsCtrl: 'HSTS_CTRL', + + /** + * Pass pointer to the HSTS read callback. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_HSTSREADDATA.html](https://curl.haxx.se/libcurl/c/CURLOPT_HSTSREADDATA.html) + */ + hstsreadData: 'HSTSREADDATA', + + /** + * Set HSTS read callback. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_HSTSREADFUNCTION.html](https://curl.haxx.se/libcurl/c/CURLOPT_HSTSREADFUNCTION.html) + */ + hstsreadFunction: 'HSTSREADFUNCTION', + + /** + * Pass pointer to the HSTS write callback. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_HSTSWRITEDATA.html](https://curl.haxx.se/libcurl/c/CURLOPT_HSTSWRITEDATA.html) + */ + hstswriteData: 'HSTSWRITEDATA', + + /** + * Set HSTS write callback. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_HSTSWRITEFUNCTION.html](https://curl.haxx.se/libcurl/c/CURLOPT_HSTSWRITEFUNCTION.html) + */ + hstswriteFunction: 'HSTSWRITEFUNCTION', + /** * Disable Content decoding. * @@ -2241,7 +2444,7 @@ export const CurlOptionCamelCaseMap = { interface: 'INTERFACE', /** - * IP version to resolve to. + * IP version to use. * * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_IPRESOLVE.html](https://curl.haxx.se/libcurl/c/CURLOPT_IPRESOLVE.html) */ @@ -2254,6 +2457,13 @@ export const CurlOptionCamelCaseMap = { */ issuerCert: 'ISSUERCERT', + /** + * Issuer certificate memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_ISSUERCERT_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_ISSUERCERT_BLOB.html) + */ + issuerCertBlob: 'ISSUERCERT_BLOB', + /** * Keep sending on HTTP \>= 300 errors. * @@ -2569,6 +2779,13 @@ export const CurlOptionCamelCaseMap = { */ proxyCaInfo: 'PROXY_CAINFO', + /** + * Proxy CA cert bundle memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_CAINFO_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_CAINFO_BLOB.html) + */ + proxyCaInfoBlob: 'PROXY_CAINFO_BLOB', + /** * Path to proxy CA cert bundle. * @@ -2646,6 +2863,20 @@ export const CurlOptionCamelCaseMap = { */ proxySslVerifyPeer: 'PROXY_SSL_VERIFYPEER', + /** + * Proxy client cert. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLCERT.html](https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLCERT.html) + */ + proxySslCert: 'PROXY_SSLCERT', + + /** + * Proxy client cert memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLCERT_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLCERT_BLOB.html) + */ + proxySslCertBlob: 'PROXY_SSLCERT_BLOB', + /** * Proxy client cert type. * @@ -2660,6 +2891,13 @@ export const CurlOptionCamelCaseMap = { */ proxySslKey: 'PROXY_SSLKEY', + /** + * Proxy client key. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLKEY_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLKEY_BLOB.html) + */ + proxySslKeyBlob: 'PROXY_SSLKEY_BLOB', + /** * Proxy client key type. * @@ -3059,6 +3297,13 @@ export const CurlOptionCamelCaseMap = { */ sslCert: 'SSLCERT', + /** + * Client cert memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_SSLCERT_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_SSLCERT_BLOB.html) + */ + sslCertBlob: 'SSLCERT_BLOB', + /** * Client cert type. * @@ -3087,6 +3332,13 @@ export const CurlOptionCamelCaseMap = { */ sslKey: 'SSLKEY', + /** + * Client key memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_SSLKEY_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_SSLKEY_BLOB.html) + */ + sslKeyBlob: 'SSLKEY_BLOB', + /** * Client key type. * @@ -3366,8 +3618,10 @@ export type CurlOptionName = | 'ALTSVC_CTRL' | 'APPEND' | 'AUTOREFERER' + | 'AWS_SIGV4' | 'BUFFERSIZE' | 'CAINFO' + | 'CAINFO_BLOB' | 'CAPATH' | 'CERTINFO' | 'CHUNK_BGN_FUNCTION' @@ -3395,6 +3649,9 @@ export type CurlOptionName = | 'DNS_SERVERS' | 'DNS_SHUFFLE_ADDRESSES' | 'DNS_USE_GLOBAL_CACHE' + | 'DOH_SSL_VERIFYHOST' + | 'DOH_SSL_VERIFYPEER' + | 'DOH_SSL_VERIFYSTATUS' | 'DOH_URL' | 'EGDSOCKET' | 'EXPECT_100_TIMEOUT_MS' @@ -3422,6 +3679,12 @@ export type CurlOptionName = | 'HEADER' | 'HEADERFUNCTION' | 'HEADEROPT' + | 'HSTS' + | 'HSTS_CTRL' + | 'HSTSREADDATA' + | 'HSTSREADFUNCTION' + | 'HSTSWRITEDATA' + | 'HSTSWRITEFUNCTION' | 'HTTP_CONTENT_DECODING' | 'HTTP_TRANSFER_DECODING' | 'HTTP_VERSION' @@ -3438,6 +3701,7 @@ export type CurlOptionName = | 'INTERFACE' | 'IPRESOLVE' | 'ISSUERCERT' + | 'ISSUERCERT_BLOB' | 'KEEP_SENDING_ON_ERROR' | 'KEYPASSWD' | 'KRBLEVEL' @@ -3483,6 +3747,7 @@ export type CurlOptionName = | 'PROTOCOLS' | 'PROXY' | 'PROXY_CAINFO' + | 'PROXY_CAINFO_BLOB' | 'PROXY_CAPATH' | 'PROXY_CRLFILE' | 'PROXY_ISSUERCERT' @@ -3494,8 +3759,11 @@ export type CurlOptionName = | 'PROXY_SSL_OPTIONS' | 'PROXY_SSL_VERIFYHOST' | 'PROXY_SSL_VERIFYPEER' + | 'PROXY_SSLCERT' + | 'PROXY_SSLCERT_BLOB' | 'PROXY_SSLCERTTYPE' | 'PROXY_SSLKEY' + | 'PROXY_SSLKEY_BLOB' | 'PROXY_SSLKEYTYPE' | 'PROXY_SSLVERSION' | 'PROXY_TLS13_CIPHERS' @@ -3553,10 +3821,12 @@ export type CurlOptionName = | 'SSL_VERIFYPEER' | 'SSL_VERIFYSTATUS' | 'SSLCERT' + | 'SSLCERT_BLOB' | 'SSLCERTTYPE' | 'SSLENGINE' | 'SSLENGINE_DEFAULT' | 'SSLKEY' + | 'SSLKEY_BLOB' | 'SSLKEYTYPE' | 'SSLVERSION' | 'SUPPRESS_CONNECT_HEADERS' @@ -3612,10 +3882,18 @@ export type StringListOptions = | 'QUOTE' | 'RESOLVE' | 'TELNETOPTIONS' +export type BlobListOptions = + | 'ISSUERCERT_BLOB' + | 'SSLKEY_BLOB' + | 'SSLCERT_BLOB' + | 'PROXY_SSLCERT_BLOB' + | 'PROXY_SSLCERT' + | 'PROXY_SSLKEY_BLOB' export type SpecificOptions = | DataCallbackOptions | ProgressCallbackOptions | StringListOptions + | BlobListOptions | 'CHUNK_BGN_FUNCTION' | 'CHUNK_END_FUNCTION' | 'DEBUGFUNCTION' @@ -3758,6 +4036,20 @@ export type CurlOptionValueType = { */ autoReferer?: string | number | boolean | null + /** + * AWS HTTP V4 Signature. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_AWS_SIGV4.html](https://curl.haxx.se/libcurl/c/CURLOPT_AWS_SIGV4.html) + */ + AWS_SIGV4?: string | number | boolean | null + + /** + * AWS HTTP V4 Signature. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_AWS_SIGV4.html](https://curl.haxx.se/libcurl/c/CURLOPT_AWS_SIGV4.html) + */ + awsSigv4?: string | number | boolean | null + /** * Ask for alternate buffer size. * @@ -3786,6 +4078,20 @@ export type CurlOptionValueType = { */ caInfo?: string | number | boolean | null + /** + * CA cert bundle memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_CAINFO_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_CAINFO_BLOB.html) + */ + CAINFO_BLOB?: string | number | boolean | null + + /** + * CA cert bundle memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_CAINFO_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_CAINFO_BLOB.html) + */ + caInfoBlob?: string | number | boolean | null + /** * Path to CA cert bundle. * @@ -4181,14 +4487,56 @@ export type CurlOptionValueType = { dnsUseGlobalCache?: string | number | boolean | null /** - * Use this DOH server for name resolves. + * Verify the host name in the DoH (DNS-over-HTTPS) SSL certificate. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_DOH_SSL_VERIFYHOST.html](https://curl.haxx.se/libcurl/c/CURLOPT_DOH_SSL_VERIFYHOST.html) + */ + DOH_SSL_VERIFYHOST?: string | number | boolean | null + + /** + * Verify the host name in the DoH (DNS-over-HTTPS) SSL certificate. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_DOH_SSL_VERIFYHOST.html](https://curl.haxx.se/libcurl/c/CURLOPT_DOH_SSL_VERIFYHOST.html) + */ + dohSslVerifyHost?: string | number | boolean | null + + /** + * Verify the DoH (DNS-over-HTTPS) SSL certificate. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_DOH_SSL_VERIFYPEER.html](https://curl.haxx.se/libcurl/c/CURLOPT_DOH_SSL_VERIFYPEER.html) + */ + DOH_SSL_VERIFYPEER?: string | number | boolean | null + + /** + * Verify the DoH (DNS-over-HTTPS) SSL certificate. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_DOH_SSL_VERIFYPEER.html](https://curl.haxx.se/libcurl/c/CURLOPT_DOH_SSL_VERIFYPEER.html) + */ + dohSslVerifyPeer?: string | number | boolean | null + + /** + * Verify the DoH (DNS-over-HTTPS) SSL certificate's status. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_DOH_SSL_VERIFYSTATUS.html](https://curl.haxx.se/libcurl/c/CURLOPT_DOH_SSL_VERIFYSTATUS.html) + */ + DOH_SSL_VERIFYSTATUS?: string | number | boolean | null + + /** + * Verify the DoH (DNS-over-HTTPS) SSL certificate's status. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_DOH_SSL_VERIFYSTATUS.html](https://curl.haxx.se/libcurl/c/CURLOPT_DOH_SSL_VERIFYSTATUS.html) + */ + dohSslVerifyStatus?: string | number | boolean | null + + /** + * Use this DoH server for name resolves. * * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_DOH_URL.html](https://curl.haxx.se/libcurl/c/CURLOPT_DOH_URL.html) */ DOH_URL?: string | number | boolean | null /** - * Use this DOH server for name resolves. + * Use this DoH server for name resolves. * * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_DOH_URL.html](https://curl.haxx.se/libcurl/c/CURLOPT_DOH_URL.html) */ @@ -4584,6 +4932,90 @@ export type CurlOptionValueType = { */ headerOpt?: CurlHeader | null + /** + * Set HSTS cache file. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_HSTS.html](https://curl.haxx.se/libcurl/c/CURLOPT_HSTS.html) + */ + HSTS?: string | number | boolean | null + + /** + * Set HSTS cache file. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_HSTS.html](https://curl.haxx.se/libcurl/c/CURLOPT_HSTS.html) + */ + hsts?: string | number | boolean | null + + /** + * Enable HSTS. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_HSTS_CTRL.html](https://curl.haxx.se/libcurl/c/CURLOPT_HSTS_CTRL.html) + */ + HSTS_CTRL?: string | number | boolean | null + + /** + * Enable HSTS. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_HSTS_CTRL.html](https://curl.haxx.se/libcurl/c/CURLOPT_HSTS_CTRL.html) + */ + hstsCtrl?: string | number | boolean | null + + /** + * Pass pointer to the HSTS read callback. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_HSTSREADDATA.html](https://curl.haxx.se/libcurl/c/CURLOPT_HSTSREADDATA.html) + */ + HSTSREADDATA?: string | number | boolean | null + + /** + * Pass pointer to the HSTS read callback. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_HSTSREADDATA.html](https://curl.haxx.se/libcurl/c/CURLOPT_HSTSREADDATA.html) + */ + hstsreadData?: string | number | boolean | null + + /** + * Set HSTS read callback. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_HSTSREADFUNCTION.html](https://curl.haxx.se/libcurl/c/CURLOPT_HSTSREADFUNCTION.html) + */ + HSTSREADFUNCTION?: string | number | boolean | null + + /** + * Set HSTS read callback. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_HSTSREADFUNCTION.html](https://curl.haxx.se/libcurl/c/CURLOPT_HSTSREADFUNCTION.html) + */ + hstsreadFunction?: string | number | boolean | null + + /** + * Pass pointer to the HSTS write callback. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_HSTSWRITEDATA.html](https://curl.haxx.se/libcurl/c/CURLOPT_HSTSWRITEDATA.html) + */ + HSTSWRITEDATA?: string | number | boolean | null + + /** + * Pass pointer to the HSTS write callback. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_HSTSWRITEDATA.html](https://curl.haxx.se/libcurl/c/CURLOPT_HSTSWRITEDATA.html) + */ + hstswriteData?: string | number | boolean | null + + /** + * Set HSTS write callback. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_HSTSWRITEFUNCTION.html](https://curl.haxx.se/libcurl/c/CURLOPT_HSTSWRITEFUNCTION.html) + */ + HSTSWRITEFUNCTION?: string | number | boolean | null + + /** + * Set HSTS write callback. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_HSTSWRITEFUNCTION.html](https://curl.haxx.se/libcurl/c/CURLOPT_HSTSWRITEFUNCTION.html) + */ + hstswriteFunction?: string | number | boolean | null + /** * Disable Content decoding. * @@ -4781,14 +5213,14 @@ export type CurlOptionValueType = { interface?: string | number | boolean | null /** - * IP version to resolve to. + * IP version to use. * * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_IPRESOLVE.html](https://curl.haxx.se/libcurl/c/CURLOPT_IPRESOLVE.html) */ IPRESOLVE?: CurlIpResolve | null /** - * IP version to resolve to. + * IP version to use. * * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_IPRESOLVE.html](https://curl.haxx.se/libcurl/c/CURLOPT_IPRESOLVE.html) */ @@ -4808,6 +5240,20 @@ export type CurlOptionValueType = { */ issuerCert?: string | number | boolean | null + /** + * Issuer certificate memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_ISSUERCERT_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_ISSUERCERT_BLOB.html) + */ + ISSUERCERT_BLOB?: string | number | boolean | null + + /** + * Issuer certificate memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_ISSUERCERT_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_ISSUERCERT_BLOB.html) + */ + issuerCertBlob?: string | number | boolean | null + /** * Keep sending on HTTP \>= 300 errors. * @@ -5454,6 +5900,20 @@ export type CurlOptionValueType = { */ proxyCaInfo?: string | number | boolean | null + /** + * Proxy CA cert bundle memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_CAINFO_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_CAINFO_BLOB.html) + */ + PROXY_CAINFO_BLOB?: string | number | boolean | null + + /** + * Proxy CA cert bundle memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_CAINFO_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_CAINFO_BLOB.html) + */ + proxyCaInfoBlob?: string | number | boolean | null + /** * Path to proxy CA cert bundle. * @@ -5608,6 +6068,34 @@ export type CurlOptionValueType = { */ proxySslVerifyPeer?: string | number | boolean | null + /** + * Proxy client cert. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLCERT.html](https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLCERT.html) + */ + PROXY_SSLCERT?: string | number | boolean | null + + /** + * Proxy client cert. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLCERT.html](https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLCERT.html) + */ + proxySslCert?: string | number | boolean | null + + /** + * Proxy client cert memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLCERT_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLCERT_BLOB.html) + */ + PROXY_SSLCERT_BLOB?: string | number | boolean | null + + /** + * Proxy client cert memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLCERT_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLCERT_BLOB.html) + */ + proxySslCertBlob?: string | number | boolean | null + /** * Proxy client cert type. * @@ -5636,6 +6124,20 @@ export type CurlOptionValueType = { */ proxySslKey?: string | number | boolean | null + /** + * Proxy client key. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLKEY_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLKEY_BLOB.html) + */ + PROXY_SSLKEY_BLOB?: string | number | boolean | null + + /** + * Proxy client key. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLKEY_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLKEY_BLOB.html) + */ + proxySslKeyBlob?: string | number | boolean | null + /** * Proxy client key type. * @@ -6452,6 +6954,20 @@ export type CurlOptionValueType = { */ sslCert?: string | number | boolean | null + /** + * Client cert memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_SSLCERT_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_SSLCERT_BLOB.html) + */ + SSLCERT_BLOB?: string | number | boolean | null + + /** + * Client cert memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_SSLCERT_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_SSLCERT_BLOB.html) + */ + sslCertBlob?: string | number | boolean | null + /** * Client cert type. * @@ -6508,6 +7024,20 @@ export type CurlOptionValueType = { */ sslKey?: string | number | boolean | null + /** + * Client key memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_SSLKEY_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_SSLKEY_BLOB.html) + */ + SSLKEY_BLOB?: string | number | boolean | null + + /** + * Client key memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_SSLKEY_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_SSLKEY_BLOB.html) + */ + sslKeyBlob?: string | number | boolean | null + /** * Client key type. * diff --git a/lib/generated/MultiOption.ts b/lib/generated/MultiOption.ts index 2e2aa819f..e09d4a37d 100644 --- a/lib/generated/MultiOption.ts +++ b/lib/generated/MultiOption.ts @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ -// This file was generated by scripts/build-constants.js on 2020-10-11T15:59:28.821Z +// This file was generated by scripts/build-constants.js on 2021-07-23T03:53:27.484Z // Do not edit manually /** diff --git a/lib/types/EasyNativeBinding.ts b/lib/types/EasyNativeBinding.ts index 4397fc3fe..75368ca03 100644 --- a/lib/types/EasyNativeBinding.ts +++ b/lib/types/EasyNativeBinding.ts @@ -9,6 +9,7 @@ import { CurlOptionName, DataCallbackOptions, ProgressCallbackOptions, + BlobListOptions, StringListOptions, SpecificOptions, } from '../generated/CurlOption' @@ -147,6 +148,13 @@ export declare class EasyNativeBinding { * Official libcurl documentation: [`curl_easy_setopt()`](http://curl.haxx.se/libcurl/c/curl_easy_setopt.html) */ setOpt(option: StringListOptions, value: string[] | null): CurlCode + /** + * Use {@link "Curl".Curl.option|`Curl.option`} for predefined constants. + * + * + * Official libcurl documentation: [`curl_easy_setopt()`](http://curl.haxx.se/libcurl/c/curl_easy_setopt.html) + */ + setOpt(option: BlobListOptions, value: ArrayBuffer | string | null): CurlCode /** * Use {@link "Curl".Curl.option|`Curl.option`} for predefined constants. * diff --git a/scripts/build-constants.js b/scripts/build-constants.js index fd092f544..04688fa44 100644 --- a/scripts/build-constants.js +++ b/scripts/build-constants.js @@ -106,7 +106,8 @@ const run = async () => { optionKindMap.progressCallback, )}`, `export type StringListOptions = ${union(optionKindMap.stringList)}`, - `export type SpecificOptions = DataCallbackOptions | ProgressCallbackOptions | StringListOptions | ${union( + `export type BlobListOptions = ${union(optionKindMap.blobList)}`, + `export type SpecificOptions = DataCallbackOptions | ProgressCallbackOptions | StringListOptions | BlobListOptions | ${union( optionKindMap.other, )}`, ] diff --git a/scripts/data/options.js b/scripts/data/options.js index 70e751df6..f46d0cc01 100644 --- a/scripts/data/options.js +++ b/scripts/data/options.js @@ -13,6 +13,14 @@ const optionKindMap = { 'RESOLVE', 'TELNETOPTIONS', ], + blobList: [ + 'ISSUERCERT_BLOB', + 'SSLKEY_BLOB', + 'SSLCERT_BLOB', + 'PROXY_SSLCERT_BLOB', + 'PROXY_SSLCERT', + 'PROXY_SSLKEY_BLOB', + ], other: [ 'CHUNK_BGN_FUNCTION', 'CHUNK_END_FUNCTION', @@ -50,6 +58,7 @@ const optionKindValueMap = { progressCallback: '((this: EasyNativeBinding, dltotal: number,dlnow: number,ultotal: number,ulnow: number) => number | CurlProgressFunc)', stringList: 'string[]', + blob: 'ArrayBuffer | Buffer | string', /* @TODO Add type definitions, they are on Curl.chunk */ CHUNK_BGN_FUNCTION: '((this: EasyNativeBinding, fileInfo: FileInfo, remains: number) => CurlChunk)', diff --git a/scripts/utils/createSetOptOverloads.js b/scripts/utils/createSetOptOverloads.js index 7c6ccc8a5..07d596f85 100644 --- a/scripts/utils/createSetOptOverloads.js +++ b/scripts/utils/createSetOptOverloads.js @@ -33,6 +33,11 @@ const createSetOptOverloads = (filePath, setOptReturnType = 'CurlCode') => { optionKindValueMap.stringList, setOptReturnType, ), + getSetOptDefinition( + 'BlobListOptions', + optionKindValueMap.blob, + setOptReturnType, + ), ] for (const specificOption of optionKindMap.other) { diff --git a/scripts/utils/curlOptionsBlacklist.js b/scripts/utils/curlOptionsBlacklist.js index 13381ac10..b817d3ec7 100644 --- a/scripts/utils/curlOptionsBlacklist.js +++ b/scripts/utils/curlOptionsBlacklist.js @@ -1,13 +1,5 @@ // This should be kept in sync with the options on src/Curl.cc curlOptionNotImplemented const curlOptionsBlacklist = [ - // TODO: add support for curl_blob - See https://github.com/JCMais/node-libcurl/issues/253 - 'CURLOPT_ISSUERCERT_BLOB', - 'CURLOPT_SSLKEY_BLOB', - 'CURLOPT_SSLCERT_BLOB', - 'CURLOPT_PROXY_SSLCERT_BLOB', - 'CURLOPT_PROXY_SSLCERT', - 'CURLOPT_PROXY_SSLKEY_BLOB', - // probably will be implemented at some time in the future? 'CURLOPT_STREAM_DEPENDS', 'CURLOPT_STREAM_DEPENDS_E', diff --git a/src/Curl.cc b/src/Curl.cc index 904a33f69..271f611dd 100644 --- a/src/Curl.cc +++ b/src/Curl.cc @@ -656,6 +656,16 @@ const std::vector curlInfoLinkedList = { {"CERTINFO", CURLINFO_CERTINFO}, }; +const std::vector curlOptionBlob = { +#if NODE_LIBCURL_VER_GE(7, 71, 0) + {"ISSUERCERT_BLOB", CURLOPT_ISSUERCERT_BLOB}, + {"PROXY_SSLCERT_BLOB", CURLOPT_PROXY_SSLCERT_BLOB}, + {"PROXY_SSLKEY_BLOB", CURLOPT_PROXY_SSLKEY_BLOB}, + {"SSLCERT_BLOB", CURLOPT_SSLCERT_BLOB}, + {"SSLKEY_BLOB", CURLOPT_SSLKEY_BLOB}, +#endif +}; + static void ExportConstants(v8::Local obj, const std::vector& optionGroup, v8::PropertyAttribute attributes) { @@ -688,6 +698,7 @@ NAN_MODULE_INIT(Initialize) { ExportConstants(optionsObj, curlOptionFunction, attributes); ExportConstants(optionsObj, curlOptionLinkedList, attributes); ExportConstants(optionsObj, curlOptionSpecific, attributes); + ExportConstants(optionsObj, curlOptionBlob, attributes); // export infos v8::Local infosObj = Nan::New(); diff --git a/src/Curl.h b/src/Curl.h index 940725499..3fa635b39 100644 --- a/src/Curl.h +++ b/src/Curl.h @@ -44,6 +44,7 @@ extern const std::vector curlOptionFunction; extern const std::vector curlOptionLinkedList; extern const std::vector curlOptionHttpPost; extern const std::vector curlOptionSpecific; +extern const std::vector curlOptionBlob; extern const std::vector curlInfoNotImplemented; extern const std::vector curlInfoString; diff --git a/src/Easy.cc b/src/Easy.cc index 3588a7372..d325eb816 100755 --- a/src/Easy.cc +++ b/src/Easy.cc @@ -1612,6 +1612,38 @@ NAN_METHOD(Easy::SetOpt) { break; } + + // check if option is a blob, and the value is correct + } else if ((optionId = IsInsideCurlConstantStruct(curlOptionBlob, opt))) { +#if NODE_LIBCURL_VER_GE(7, 71, 0) + if (value->IsNull()) { + setOptRetCode = curl_easy_setopt(obj->ch, static_cast(optionId), NULL); + } else if (value->IsString()) { + Nan::Utf8String value(value); + + size_t length = static_cast(value.length()); + + struct curl_blob blob; + blob.data = *value; + blob.len = length; + blob.flags = CURL_BLOB_COPY; + + setOptRetCode = curl_easy_setopt(obj->ch, static_cast(optionId), &blob); + } else if (node::Buffer::HasInstance(value)) { + struct curl_blob blob; + blob.data = node::Buffer::Data(value); + blob.len = node::Buffer::Length(value); + blob.flags = CURL_BLOB_COPY; + + setOptRetCode = curl_easy_setopt(obj->ch, static_cast(optionId), &blob); + } else { + Nan::ThrowTypeError("Option value must be a string or Buffer."); + return; + } +#else + Nan::ThrowError("Blob options require curl 7.71 or newer."); + return; +#endif } info.GetReturnValue().Set(setOptRetCode); diff --git a/test/curl/setOpt.spec.ts b/test/curl/setOpt.spec.ts index 913c7f06d..10f577689 100644 --- a/test/curl/setOpt.spec.ts +++ b/test/curl/setOpt.spec.ts @@ -57,6 +57,11 @@ describe('setOpt()', () => { curl.setOpt('WRITEFUNCTION', null) }) + it('should be able to set blob value back to null', () => { + curl.setOpt('SSLKEY_BLOB', Buffer.from([])) + curl.setOpt('SSLKEY_BLOB', null) + }) + it('should not accept invalid argument type', () => { const optionsToTest = [ ['URL', 0],