Lines Matching refs:ctx

307     STACK_OF(OSSL_STORE_INFO) *ctx = *pctx;
309 if (ctx == NULL) {
349 if ((ctx = sk_OSSL_STORE_INFO_new_null()) != NULL) {
354 && sk_OSSL_STORE_INFO_push(ctx, osi_pkey) != 0)
363 && sk_OSSL_STORE_INFO_push(ctx, osi_cert) != 0)
373 && sk_OSSL_STORE_INFO_push(ctx, osi_ca) != 0)
386 sk_OSSL_STORE_INFO_pop_free(ctx, store_info_free);
387 ctx = NULL;
389 *pctx = ctx;
394 if (ctx == NULL)
399 store_info = sk_OSSL_STORE_INFO_shift(ctx);
405 STACK_OF(OSSL_STORE_INFO) *ctx = ctx_;
407 return ctx == NULL || sk_OSSL_STORE_INFO_num(ctx) == 0;
412 STACK_OF(OSSL_STORE_INFO) *ctx = *pctx;
414 sk_OSSL_STORE_INFO_pop_free(ctx, store_info_free);
885 OPENSSL_DIR_CTX *ctx;
912 static void OSSL_STORE_LOADER_CTX_free(OSSL_STORE_LOADER_CTX *ctx)
914 if (ctx == NULL)
917 OPENSSL_free(ctx->propq);
918 OPENSSL_free(ctx->uri);
919 if (ctx->type != is_dir) {
920 if (ctx->_.file.last_handler != NULL) {
921 ctx->_.file.last_handler->destroy_ctx(&ctx->_.file.last_handler_ctx);
922 ctx->_.file.last_handler_ctx = NULL;
923 ctx->_.file.last_handler = NULL;
926 OPENSSL_free(ctx);
929 static int file_find_type(OSSL_STORE_LOADER_CTX *ctx)
937 ctx->_.file.file = BIO_push(buff, ctx->_.file.file);
938 if (BIO_buffer_peek(ctx->_.file.file, peekbuf, sizeof(peekbuf) - 1) > 0) {
941 ctx->type = is_pem;
951 OSSL_STORE_LOADER_CTX *ctx = NULL;
1029 ctx = OPENSSL_zalloc(sizeof(*ctx));
1030 if (ctx == NULL) {
1034 ctx->uri = OPENSSL_strdup(uri);
1035 if (ctx->uri == NULL) {
1041 ctx->type = is_dir;
1042 ctx->_.dir.last_entry = OPENSSL_DIR_read(&ctx->_.dir.ctx, path);
1043 ctx->_.dir.last_errno = errno;
1044 if (ctx->_.dir.last_entry == NULL) {
1045 if (ctx->_.dir.last_errno != 0) {
1046 ERR_raise(ERR_LIB_SYS, ctx->_.dir.last_errno);
1049 ctx->_.dir.end_reached = 1;
1051 } else if ((ctx->_.file.file = BIO_new_file(path, "rb")) == NULL
1052 || !file_find_type(ctx)) {
1053 BIO_free_all(ctx->_.file.file);
1057 ctx->propq = OPENSSL_strdup(propq);
1058 if (ctx->propq == NULL) {
1063 ctx->libctx = libctx;
1065 return ctx;
1067 OSSL_STORE_LOADER_CTX_free(ctx);
1083 OSSL_STORE_LOADER_CTX *ctx = NULL;
1085 if ((ctx = OPENSSL_zalloc(sizeof(*ctx))) == NULL
1086 || (propq != NULL && (ctx->propq = OPENSSL_strdup(propq)) == NULL)) {
1088 OSSL_STORE_LOADER_CTX_free(ctx);
1091 ctx->libctx = libctx;
1092 ctx->flags |= FILE_FLAG_ATTACHED;
1093 ctx->_.file.file = bp;
1094 if (!file_find_type(ctx)) {
1096 ctx->_.file.file = NULL;
1099 return ctx;
1101 OSSL_STORE_LOADER_CTX_free(ctx);
1105 static int file_ctrl(OSSL_STORE_LOADER_CTX *ctx, int cmd, va_list args)
1116 ctx->flags &= ~FILE_FLAG_SECMEM;
1119 ctx->flags |= FILE_FLAG_SECMEM;
1135 static int file_expect(OSSL_STORE_LOADER_CTX *ctx, int expected)
1137 ctx->expected_type = expected;
1141 static int file_find(OSSL_STORE_LOADER_CTX *ctx,
1145 * If ctx == NULL, the library is looking to know if this loader supports
1152 if (ctx == NULL)
1155 if (ctx->type != is_dir) {
1162 BIO_snprintf(ctx->_.dir.search_name, sizeof(ctx->_.dir.search_name),
1167 if (ctx != NULL)
1172 static OSSL_STORE_INFO *file_load_try_decode(OSSL_STORE_LOADER_CTX *ctx,
1209 ui_method, ui_data, ctx->uri,
1210 ctx->libctx, ctx->propq);
1246 ctx->_.file.last_handler = matching_handlers[0];
1247 ctx->_.file.last_handler_ctx = handler_ctx;
1277 static OSSL_STORE_INFO *file_load_try_repeat(OSSL_STORE_LOADER_CTX *ctx,
1284 if (ctx->_.file.last_handler != NULL) {
1286 ctx->_.file.last_handler->try_decode(NULL, NULL, NULL, 0,
1287 &ctx->_.file.last_handler_ctx,
1289 ui_method, ui_data, ctx->uri,
1290 ctx->libctx, ctx->propq);
1293 ctx->_.file.last_handler->destroy_ctx(&ctx->_.file.last_handler_ctx);
1294 ctx->_.file.last_handler_ctx = NULL;
1295 ctx->_.file.last_handler = NULL;
1426 static int file_name_to_uri(OSSL_STORE_LOADER_CTX *ctx, const char *name,
1432 const char *pathsep = ossl_ends_with_dirsep(ctx->uri) ? "" : "/";
1433 long calculated_length = strlen(ctx->uri) + strlen(pathsep)
1442 OPENSSL_strlcat(*data, ctx->uri, calculated_length);
1449 static int file_name_check(OSSL_STORE_LOADER_CTX *ctx, const char *name)
1452 size_t len = strlen(ctx->_.dir.search_name);
1455 if (ctx->_.dir.search_name[0] == '\0')
1459 if (ctx->expected_type != 0
1460 && ctx->expected_type != OSSL_STORE_INFO_CERT
1461 && ctx->expected_type != OSSL_STORE_INFO_CRL)
1467 if (OPENSSL_strncasecmp(name, ctx->_.dir.search_name, len) != 0
1478 if (ctx->expected_type != 0
1479 && ctx->expected_type != OSSL_STORE_INFO_CRL)
1481 } else if (ctx->expected_type == OSSL_STORE_INFO_CRL) {
1511 static int file_eof(OSSL_STORE_LOADER_CTX *ctx);
1512 static int file_error(OSSL_STORE_LOADER_CTX *ctx);
1513 static OSSL_STORE_INFO *file_load(OSSL_STORE_LOADER_CTX *ctx,
1519 ctx->errcnt = 0;
1521 if (ctx->type == is_dir) {
1525 if (ctx->_.dir.last_entry == NULL) {
1526 if (!ctx->_.dir.end_reached) {
1527 assert(ctx->_.dir.last_errno != 0);
1528 ERR_raise(ERR_LIB_SYS, ctx->_.dir.last_errno);
1529 ctx->errcnt++;
1534 if (ctx->_.dir.last_entry[0] != '.'
1535 && file_name_check(ctx, ctx->_.dir.last_entry)
1536 && !file_name_to_uri(ctx, ctx->_.dir.last_entry, &newname))
1545 ctx->_.dir.last_entry = OPENSSL_DIR_read(&ctx->_.dir.ctx, ctx->uri);
1546 ctx->_.dir.last_errno = errno;
1547 if (ctx->_.dir.last_entry == NULL && ctx->_.dir.last_errno == 0)
1548 ctx->_.dir.end_reached = 1;
1556 } while (result == NULL && !file_eof(ctx));
1561 result = file_load_try_repeat(ctx, ui_method, ui_data);
1565 if (file_eof(ctx))
1575 if (ctx->type == is_pem) {
1576 if (!file_read_pem(ctx->_.file.file, &pem_name, &pem_header,
1577 &data, &len, ui_method, ui_data, ctx->uri,
1578 (ctx->flags & FILE_FLAG_SECMEM) != 0)) {
1579 ctx->errcnt++;
1583 if ((result = file_try_read_msblob(ctx->_.file.file,
1585 || (result = file_try_read_PVK(ctx->_.file.file,
1586 ui_method, ui_data, ctx->uri,
1590 if (!file_read_asn1(ctx->_.file.file, &data, &len)) {
1591 ctx->errcnt++;
1596 result = file_load_try_decode(ctx, pem_name, pem_header, data, len,
1607 ctx->errcnt++;
1625 ctx->errcnt++;
1628 pem_free_flag(pem_name, (ctx->flags & FILE_FLAG_SECMEM) != 0, 0);
1629 pem_free_flag(pem_header, (ctx->flags & FILE_FLAG_SECMEM) != 0, 0);
1630 pem_free_flag(data, (ctx->flags & FILE_FLAG_SECMEM) != 0, len);
1631 } while (matchcount == 0 && !file_eof(ctx) && !file_error(ctx));
1640 && ctx->expected_type != 0
1641 && ctx->expected_type != OSSL_STORE_INFO_get_type(result)) {
1650 static int file_error(OSSL_STORE_LOADER_CTX *ctx)
1652 return ctx->errcnt > 0;
1655 static int file_eof(OSSL_STORE_LOADER_CTX *ctx)
1657 if (ctx->type == is_dir)
1658 return ctx->_.dir.end_reached;
1660 if (ctx->_.file.last_handler != NULL
1661 && !ctx->_.file.last_handler->eof(ctx->_.file.last_handler_ctx))
1663 return BIO_eof(ctx->_.file.file);
1666 static int file_close(OSSL_STORE_LOADER_CTX *ctx)
1668 if ((ctx->flags & FILE_FLAG_ATTACHED) == 0) {
1669 if (ctx->type == is_dir)
1670 OPENSSL_DIR_end(&ctx->_.dir.ctx);
1672 BIO_free_all(ctx->_.file.file);
1678 BIO *buff = ctx->_.file.file;
1681 (void)BIO_pop(ctx->_.file.file);
1683 ctx->_.file.file = NULL;
1687 OSSL_STORE_LOADER_CTX_free(ctx);