You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-11-23 21:54:53 +02:00
avformat/tls_gnutls: cleanup the pointer name
Pure cleanup, no functional changes Unify local pointer names to `TLSContext *c` and `TLSShared *s` to reduce confusion from inconsistent names (e.g. p, s, c) Signed-off-by: Jack Lau <jacklau1222@qq.com>
This commit is contained in:
@@ -149,66 +149,66 @@ static ssize_t gnutls_url_push(gnutls_transport_ptr_t transport,
|
||||
|
||||
static int tls_open(URLContext *h, const char *uri, int flags, AVDictionary **options)
|
||||
{
|
||||
TLSContext *p = h->priv_data;
|
||||
TLSShared *c = &p->tls_shared;
|
||||
TLSContext *c = h->priv_data;
|
||||
TLSShared *s = &c->tls_shared;
|
||||
int ret;
|
||||
|
||||
ff_gnutls_init();
|
||||
|
||||
if ((ret = ff_tls_open_underlying(c, h, uri, options)) < 0)
|
||||
if ((ret = ff_tls_open_underlying(s, h, uri, options)) < 0)
|
||||
goto fail;
|
||||
|
||||
gnutls_init(&p->session, c->listen ? GNUTLS_SERVER : GNUTLS_CLIENT);
|
||||
if (!c->listen && !c->numerichost)
|
||||
gnutls_server_name_set(p->session, GNUTLS_NAME_DNS, c->host, strlen(c->host));
|
||||
gnutls_certificate_allocate_credentials(&p->cred);
|
||||
if (c->ca_file) {
|
||||
ret = gnutls_certificate_set_x509_trust_file(p->cred, c->ca_file, GNUTLS_X509_FMT_PEM);
|
||||
gnutls_init(&c->session, s->listen ? GNUTLS_SERVER : GNUTLS_CLIENT);
|
||||
if (!s->listen && !s->numerichost)
|
||||
gnutls_server_name_set(c->session, GNUTLS_NAME_DNS, s->host, strlen(s->host));
|
||||
gnutls_certificate_allocate_credentials(&c->cred);
|
||||
if (s->ca_file) {
|
||||
ret = gnutls_certificate_set_x509_trust_file(c->cred, s->ca_file, GNUTLS_X509_FMT_PEM);
|
||||
if (ret < 0)
|
||||
av_log(h, AV_LOG_ERROR, "%s\n", gnutls_strerror(ret));
|
||||
}
|
||||
#if GNUTLS_VERSION_NUMBER >= 0x030020
|
||||
else
|
||||
gnutls_certificate_set_x509_system_trust(p->cred);
|
||||
gnutls_certificate_set_x509_system_trust(c->cred);
|
||||
#endif
|
||||
gnutls_certificate_set_verify_flags(p->cred, c->verify ?
|
||||
gnutls_certificate_set_verify_flags(c->cred, s->verify ?
|
||||
GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRT : 0);
|
||||
if (c->cert_file && c->key_file) {
|
||||
ret = gnutls_certificate_set_x509_key_file(p->cred,
|
||||
c->cert_file, c->key_file,
|
||||
if (s->cert_file && s->key_file) {
|
||||
ret = gnutls_certificate_set_x509_key_file(c->cred,
|
||||
s->cert_file, s->key_file,
|
||||
GNUTLS_X509_FMT_PEM);
|
||||
if (ret < 0) {
|
||||
av_log(h, AV_LOG_ERROR,
|
||||
"Unable to set cert/key files %s and %s: %s\n",
|
||||
c->cert_file, c->key_file, gnutls_strerror(ret));
|
||||
s->cert_file, s->key_file, gnutls_strerror(ret));
|
||||
ret = AVERROR(EIO);
|
||||
goto fail;
|
||||
}
|
||||
} else if (c->cert_file || c->key_file)
|
||||
} else if (s->cert_file || s->key_file)
|
||||
av_log(h, AV_LOG_ERROR, "cert and key required\n");
|
||||
gnutls_credentials_set(p->session, GNUTLS_CRD_CERTIFICATE, p->cred);
|
||||
gnutls_transport_set_pull_function(p->session, gnutls_url_pull);
|
||||
gnutls_transport_set_push_function(p->session, gnutls_url_push);
|
||||
gnutls_transport_set_ptr(p->session, p);
|
||||
gnutls_set_default_priority(p->session);
|
||||
gnutls_credentials_set(c->session, GNUTLS_CRD_CERTIFICATE, c->cred);
|
||||
gnutls_transport_set_pull_function(c->session, gnutls_url_pull);
|
||||
gnutls_transport_set_push_function(c->session, gnutls_url_push);
|
||||
gnutls_transport_set_ptr(c->session, c);
|
||||
gnutls_set_default_priority(c->session);
|
||||
do {
|
||||
if (ff_check_interrupt(&h->interrupt_callback)) {
|
||||
ret = AVERROR_EXIT;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = gnutls_handshake(p->session);
|
||||
ret = gnutls_handshake(c->session);
|
||||
if (gnutls_error_is_fatal(ret)) {
|
||||
ret = print_tls_error(h, ret);
|
||||
goto fail;
|
||||
}
|
||||
} while (ret);
|
||||
p->need_shutdown = 1;
|
||||
if (c->verify) {
|
||||
c->need_shutdown = 1;
|
||||
if (s->verify) {
|
||||
unsigned int status, cert_list_size;
|
||||
gnutls_x509_crt_t cert;
|
||||
const gnutls_datum_t *cert_list;
|
||||
if ((ret = gnutls_certificate_verify_peers2(p->session, &status)) < 0) {
|
||||
if ((ret = gnutls_certificate_verify_peers2(c->session, &status)) < 0) {
|
||||
av_log(h, AV_LOG_ERROR, "Unable to verify peer certificate: %s\n",
|
||||
gnutls_strerror(ret));
|
||||
ret = AVERROR(EIO);
|
||||
@@ -219,19 +219,19 @@ static int tls_open(URLContext *h, const char *uri, int flags, AVDictionary **op
|
||||
ret = AVERROR(EIO);
|
||||
goto fail;
|
||||
}
|
||||
if (gnutls_certificate_type_get(p->session) != GNUTLS_CRT_X509) {
|
||||
if (gnutls_certificate_type_get(c->session) != GNUTLS_CRT_X509) {
|
||||
av_log(h, AV_LOG_ERROR, "Unsupported certificate type\n");
|
||||
ret = AVERROR(EIO);
|
||||
goto fail;
|
||||
}
|
||||
gnutls_x509_crt_init(&cert);
|
||||
cert_list = gnutls_certificate_get_peers(p->session, &cert_list_size);
|
||||
cert_list = gnutls_certificate_get_peers(c->session, &cert_list_size);
|
||||
gnutls_x509_crt_import(cert, cert_list, GNUTLS_X509_FMT_DER);
|
||||
ret = gnutls_x509_crt_check_hostname(cert, c->host);
|
||||
ret = gnutls_x509_crt_check_hostname(cert, s->host);
|
||||
gnutls_x509_crt_deinit(cert);
|
||||
if (!ret) {
|
||||
av_log(h, AV_LOG_ERROR,
|
||||
"The certificate's owner does not match hostname %s\n", c->host);
|
||||
"The certificate's owner does not match hostname %s\n", s->host);
|
||||
ret = AVERROR(EIO);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user