Skip to content

DarwinSSL + iOS / CFStringGetCString 128 char buffer too small for Asian locale #1823

@bsergean

Description

@bsergean

I did this

We are getting an error downloading a page through SSL with libcurl in our iOS app. This only happen when we hit a certain page with a certain certificate, and on Asian locales (simplified Chinese, Japanese).

The error message is "SSL: invalid CA certificate subject", which come from this block of code:

    /* Check if cacert is valid. */
    CFStringRef subject = CopyCertSubject(cacert);
    if(subject) {
      char subject_cbuf[128];
      memset(subject_cbuf, 0, 128);
      if(!CFStringGetCString(subject,
                            subject_cbuf,
                            128,
                            kCFStringEncodingUTF8)) {
        CFRelease(cacert);
        failf(data, "SSL: invalid CA certificate subject");
        return CURLE_SSL_CACERT;
      }

If I bump 128 to 256 everywhere in this file, the error goes away.

  1. Does a certificate subjects needs to be less than 128 bytes in utf-8 ?
  2. Is it "good enough" to bump that value a little higher to 256. Or maybe to 128 * max number of bytes in a utf-8 char (5 ?) if we only ever expect 128 characters in a subject ?
  3. Should we make that code work with arbitrary length ?

I expected the following

I should be able to download that page through SSL.

curl/libcurl version

curl-7.54.1

operating system

iOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions