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

オープン
#25,522 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
46/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
c, php
領域
backend, security

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
C
スター
41.8k
フォーク
8.6k
平均マージ
2日 15時間
マージ済み PR(30日)
125

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

php/php-src のほかの issue

php/php-src の issue をすべて見る

似ている issue

C の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。