openssl_csr_new(): string_mask from one config applies to later calls

Đang mở
#25,522 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
46/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
c, php
Lĩnh vực
backend, security

Hướng nghiên cứu

Start by tracing openssl_csr_new() and how it parses the config option, then inspect the OpenSSL string mask API used in that path. Reproduce the three-call sequence from the issue on PHP 8.7-dev and check existing OpenSSL CSR tests for a suitable place to cover it. Done means a config with string_mask no longer changes the result of a later call without that option, including across FPM requests.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Bug Status: Needs Triage
Description

string_mask in a CSR config sets the mask process-wide, with ASN1_STRING_set_default_mask_asc(). Nothing restores it. So a later openssl_csr_new() whose config has no string_mask uses the old one. With FPM it also carries over to the next requests of the worker.

<?php
$dir = sys_get_temp_dir();
file_put_contents("$dir/set.cnf", "[ req ]\ndistinguished_name = dn\nstring_mask = nombstr\n[ dn ]\n");
file_put_contents("$dir/plain.cnf", "[ req ]\ndistinguished_name = dn\n[ dn ]\n");

function csr(string $config, string $cn): bool {
    $opts = ['config' => $config];
    $key = openssl_pkey_new(['private_key_type' => OPENSSL_KEYTYPE_EC, 'curve_name' => 'prime256v1'] + $opts);
    return @openssl_csr_new(['commonName' => $cn], $key, $opts) !== false;
}

var_dump(csr("$dir/plain.cnf", 'Łódź'));
var_dump(csr("$dir/set.cnf", 'example'));
var_dump(csr("$dir/plain.cnf", 'Łódź'));

Resulted in this output:

bool(true)
bool(true)
bool(false)

But I expected this output instead:

bool(true)
bool(true)
bool(true)

The last call fails because nombstr doesn't allow the UTF8String the common name needs.

I'm opening a PR that saves the mask before the config is parsed and restores it after the call. oid_section and oid_file are similar: OBJ_create() adds to the global OID table and nothing removes the entries. I'm not sure that one needs fixing.

PHP Version
PHP 8.7.0-dev (master). The same code is in 8.3, 8.4, 8.5 and 8.6.
Operating System

Ubuntu 26.04, OpenSSL 3.5.5

Ngôn ngữ chính
C
Star
41.8k
Fork
8.6k
Merge trung bình
2 ngày 15 giờ
Pull request đã merge (30 ngày)
125

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của php/php-src

Tất cả issue của php/php-src

Issue tương tự

Thêm issue về C

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.