Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use alternative methods for base64 encoding/decoding in order to support BoringSSL #67

Closed
cpapazian opened this issue Jan 5, 2021 · 1 comment

Comments

@cpapazian
Copy link
Contributor

cpapazian commented Jan 5, 2021

sxg_codec.c uses BIO_f_base64 for base 64 encoding, but BoringSSL lists this function as deprecated:

// Deprecated functions.
  |  
  | // BIO_f_base64 returns a filter \|BIO\| that base64-encodes data written into
  | // it, and decodes data read from it. \|BIO_gets\| is not supported. Call
  | // \|BIO_flush\| when done writing, to signal that no more data are to be
  | // encoded. The flag \|BIO_FLAGS_BASE64_NO_NL\| may be set to encode all the data
  | // on one line.
  | //
  | // Use \|EVP_EncodeBlock\| and \|EVP_DecodeBase64\| instead.
  | OPENSSL_EXPORT const BIO_METHOD *BIO_f_base64(void);

Any chance we could replace the calls in libsxg with EVP_EncodeBlock/EVP_DecodeBase64 as the comments in BoringSSL suggest?

cc @twifkak @rgs1

@cpapazian
Copy link
Contributor Author

was able to implement a version of sxg_base64encode_bytes with EVP_EncodeBlock that passes tests:

bool sxg_base64encode_bytes(const uint8_t* src, size_t length,
  size_t ol;
  // note that the length calcualted by EVP_EncodedLength includes the trailing 
  // null byte, but the value returned by EVP_EncodeBlock does not.
  return EVP_EncodedLength(&ol, length) &&
         sxg_buffer_resize(ol - 1, dst) &&
         EVP_EncodeBlock(dst->data, src, length) == ol - 1;
}

issue is that OpenSSL doesn't seem to have EV_EncodedLength and its version of EVP_EncodeBlock returns an int, so if we wanted to have a single implementation for both versions of OpenSSL, we would need to work around the inconsistencies. This is easy enough, since the openssl docs describe the algorithm used by EV_EncodedLength, and length can be cast to the write type for comparison.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants