From: Timo Rothenpieler <timo@rothenpieler.org> To: ffmpeg-devel@ffmpeg.org Cc: Timo Rothenpieler <timo@rothenpieler.org> Subject: [FFmpeg-devel] [PATCH v2 7/8] avformat/tls_schannel: add option to load server certificate from store Date: Sun, 6 Jul 2025 20:36:28 +0200 Message-ID: <20250706183634.38579-8-timo@rothenpieler.org> (raw) In-Reply-To: <20250706183634.38579-1-timo@rothenpieler.org> --- libavformat/tls_schannel.c | 47 ++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/libavformat/tls_schannel.c b/libavformat/tls_schannel.c index b985576b72..90d5765a80 100644 --- a/libavformat/tls_schannel.c +++ b/libavformat/tls_schannel.c @@ -502,6 +502,32 @@ end: return ret; } +static int tls_cert_from_store(void *logctx, const char *cert_store_name, const char *cert_subj, PCCERT_CONTEXT *crtctx) +{ + HCERTSTORE cert_store = NULL; + int ret = 0; + + cert_store = CertOpenStore(CERT_STORE_PROV_SYSTEM_A, 0, 0, CERT_SYSTEM_STORE_CURRENT_USER, cert_store_name); + if (!cert_store) { + av_log(logctx, AV_LOG_ERROR, "Opening user cert store %s failed\n", cert_store_name); + ret = AVERROR_EXTERNAL; + goto end; + } + + *crtctx = CertFindCertificateInStore(cert_store, X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, 0, CERT_FIND_SUBJECT_STR_A, cert_subj, NULL); + if (!*crtctx) { + av_log(logctx, AV_LOG_ERROR, "Could not find certificate in store\n"); + ret = AVERROR_EXTERNAL; + goto end; + } + +end: + if (cert_store) + CertCloseStore(cert_store, 0); + + return ret; +} + static int tls_load_key_cert(char *key_url, char *cert_url, NCRYPT_KEY_HANDLE *key, PCCERT_CONTEXT *crtctx) { AVBPrint key_bp, cert_bp; @@ -561,6 +587,9 @@ typedef struct TLSContext { const AVClass *class; TLSShared tls_shared; + char *cert_store_subject; + char *cert_store_name; + CredHandle cred_handle; TimeStamp cred_timestamp; @@ -1047,21 +1076,20 @@ static int tls_open(URLContext *h, const char *uri, int flags, AVDictionary **op schannel_cred.dwVersion = SCHANNEL_CRED_VERSION; if (s->listen) { - if (s->key_buf && s->cert_buf) { + if (c->cert_store_name && c->cert_store_subject) { + ret = tls_cert_from_store(h, c->cert_store_name, c->cert_store_subject, &crtctx); + } else if (s->key_buf && s->cert_buf) { ret = tls_import_key_cert(s->key_buf, s->cert_buf, &key, &crtctx); - if (ret < 0) - goto fail; } else if (s->key_file && s->cert_file) { ret = tls_load_key_cert(s->key_file, s->cert_file, &key, &crtctx); - if (ret < 0) - goto fail; } else { av_log(h, AV_LOG_VERBOSE, "No server certificate provided, using self-signed\n"); ret = tls_gen_self_signed(&key, &crtctx); - if (ret < 0) - goto fail; } + if (ret < 0) + goto fail; + schannel_cred.cCreds = 1; schannel_cred.paCred = &crtctx; @@ -1353,8 +1381,13 @@ static int tls_get_short_seek(URLContext *h) return ffurl_get_short_seek(s->is_dtls ? s->udp : s->tcp); } +#define OFFSET(x) offsetof(TLSContext, x) static const AVOption options[] = { TLS_COMMON_OPTIONS(TLSContext, tls_shared), + { "cert_store_subject", "Load certificate (and associated key) from users keystore by subject", + OFFSET(cert_store_subject), AV_OPT_TYPE_STRING, .flags = TLS_OPTFL }, + { "cert_store_name", "Name of the specific cert store to search in (for cert_store_subject)", + OFFSET(cert_store_name), AV_OPT_TYPE_STRING, { .str = "MY" }, .flags = TLS_OPTFL }, { NULL } }; -- 2.49.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2025-07-06 18:38 UTC|newest] Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2025-07-06 18:36 [FFmpeg-devel] [PATCH v2 0/8] WHIP + TLS + UDP fixes and SChannel DTLS support Timo Rothenpieler 2025-07-06 18:36 ` [FFmpeg-devel] [PATCH v2 1/8] avformat/tls: move whip specific init out of generic tls code Timo Rothenpieler 2025-07-07 6:30 ` Jack Lau 2025-07-06 18:36 ` [FFmpeg-devel] [PATCH v2 2/8] avformat/udp: make recv addr of each packet available Timo Rothenpieler 2025-07-07 8:03 ` Jack Lau 2025-07-06 18:36 ` [FFmpeg-devel] [PATCH v2 3/8] avformat/udp: separate rx and tx fifo Timo Rothenpieler 2025-07-06 18:36 ` [FFmpeg-devel] [PATCH v2 4/8] avformat/udp: add function to set remote address directly Timo Rothenpieler 2025-07-06 18:36 ` [FFmpeg-devel] [PATCH v2 5/8] avformat/tls: make passing an external socket universal Timo Rothenpieler 2025-07-06 18:36 ` [FFmpeg-devel] [PATCH v2 6/8] avformat/tls_schannel: add DTLS support Timo Rothenpieler 2025-07-06 18:36 ` Timo Rothenpieler [this message] 2025-07-06 18:36 ` [FFmpeg-devel] [PATCH v2 8/8] avformat/tls_schannel: fix non-blocking write breaking TLS sessions Timo Rothenpieler
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20250706183634.38579-8-timo@rothenpieler.org \ --to=timo@rothenpieler.org \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git