Skip to content

Commit

Permalink
Mention the new supported targets
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartatz committed May 21, 2024
1 parent a8eb346 commit 9016e7b
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,12 @@ install(
DESTINATION "${SHARED_LIBRARY_DIRECTORY}"
)

install(
FILES "${CMAKE_SOURCE_DIR}/submodules/cabundle/pem/cert.pem"
DESTINATION etc/tls
RENAME cert.pem
)

if (APPLE)
set(
names
Expand Down
2 changes: 1 addition & 1 deletion src/filesystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,7 @@ char* get_app_filename(void) {

wfilename = malloc((size_t) filenames);

if (wdirectory == NULL) {
if (wfilename == NULL) {
return NULL;
}

Expand Down
2 changes: 2 additions & 0 deletions src/m3u8errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ const char* m3u8err_getmessage(const int code) {
return "Could not write data to file";
case M3U8ERR_FSTREAM_READ_EMPTY_FILE:
return "Tried to read contents from an empty file";
case M3U8ERR_GET_APP_FILENAME_FAILURE:
return "Could not get app filename";
case M3U8ERR_ITEM_EMPTY:
return "This M3U8 tag must not contain empty items";
case M3U8ERR_ITEM_INVALID_BRANGE:
Expand Down
2 changes: 2 additions & 0 deletions src/m3u8errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
#define M3U8ERR_FSTREAM_WRITE_FAILURE -55 /* Could not write data to file */
#define M3U8ERR_FSTREAM_READ_EMPTY_FILE -900 /* Tried to read contents from an empty file */

#define M3U8ERR_GET_APP_FILENAME_FAILURE -1000 /* Could not get app filename */

#define M3U8ERR_ITEM_EMPTY -56 /* This M3U8 tag must not contain empty items */
#define M3U8ERR_ITEM_INVALID_BRANGE -57 /* The value of this M3U8 item is not a valid byte range */
#define M3U8ERR_ITEM_INVALID_DTIME -58 /* The value of this M3U8 item is not a valid ISO/IEC 8601:2004 date/time representation */
Expand Down
10 changes: 5 additions & 5 deletions src/path.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,15 @@ size_t get_parent_directory(const char* const source, char* const destination, c
characters written into the buffer (not including the null-terminator).
*/

ssize_t index = 0;
size_t index = 0;
size_t depth = 1;
size_t wsize = 0;

if (destination != NULL) {
destination[0] = '\0';
}

for (index = (ssize_t) strlen(source) - 1; index >= 0; index--) {
for (index = strlen(source) - 1; index-- > 0;) {
const char ch = source[index];

if (ch == PATHSEP[0] && depth++ == maxdepth) {
Expand All @@ -216,7 +216,7 @@ size_t get_parent_directory(const char* const source, char* const destination, c
memcpy(destination, source, size);
destination[size] = '\0';
} else {
strncat(destination, PATHSEP, 1);
strcat(destination, PATHSEP);
}
}

Expand Down Expand Up @@ -250,9 +250,9 @@ size_t get_parent_directory(const char* const source, char* const destination, c
int main() {
size_t sz = get_parent_directory("../system/etc/hosts", NULL, 8);
size_t sz = get_parent_directory("/../system/etc/hosts", NULL, 5);
char s[sz + 1];
get_parent_directory("../system/etc/hosts", s, 8);
get_parent_directory("/../system/etc/hosts", s, 5);
printf("%s -> %zu\n", s, sz);
Expand Down
43 changes: 41 additions & 2 deletions src/sslcerts.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
#include <curl/curl.h>

#include "fstream.h"
#include "filesystem.h"
#include "sslcerts.h"
#include "path.h"
#include "m3u8errors.h"

static const char* const SSL_CERTIFICATE_LOCATIONS[] = {
Expand Down Expand Up @@ -35,6 +37,13 @@ static const char* const SSL_CERTIFICATE_LOCATIONS[] = {
#endif
};

static const char BUILTIN_CA_CERT_LOCATION[] =
#if defined(_WIN32)
"\\etc\\tls\\cert.pem";
#else
"/etc/tls/cert.pem";
#endif

static struct curl_blob* cacerts = NULL;

static int sslcerts_load_file(const char* const name) {
Expand Down Expand Up @@ -113,6 +122,9 @@ int sslcerts_load_certificates(CURL* const curl) {

size_t index = 0;

char* app_filename = NULL;
char* name = NULL;

code = curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);

if (code != CURLE_OK) {
Expand All @@ -138,9 +150,9 @@ int sslcerts_load_certificates(CURL* const curl) {
}

for (index = 0; index < sizeof(SSL_CERTIFICATE_LOCATIONS) / sizeof(*SSL_CERTIFICATE_LOCATIONS); index++) {
const char* const name = SSL_CERTIFICATE_LOCATIONS[index];
const char* const location = SSL_CERTIFICATE_LOCATIONS[index];

err = sslcerts_load_file(name);
err = sslcerts_load_file(location);

if (err != M3U8ERR_SUCCESS) {
continue;
Expand All @@ -155,8 +167,35 @@ int sslcerts_load_certificates(CURL* const curl) {
goto end;
}

app_filename = get_app_filename();

if (app_filename == NULL) {
err = M3U8ERR_GET_APP_FILENAME_FAILURE;
goto end;
}

name = malloc(strlen(app_filename) + strlen(BUILTIN_CA_CERT_LOCATION) + 1);

if (name == NULL) {
err = M3U8ERR_MEMORY_ALLOCATE_FAILURE;
goto end;
}

get_parent_directory(app_filename, name, 2);

strcat(name, BUILTIN_CA_CERT_LOCATION);

err = sslcerts_load_file(name);

if (err != M3U8ERR_SUCCESS) {
goto end;
}

end:;

free(app_filename);
free(name);

return err;

}
Expand Down

0 comments on commit 9016e7b

Please sign in to comment.