PHP 8.3.4 Released!

openssl_csr_get_subject

(PHP 5 >= 5.2.0, PHP 7, PHP 8)

openssl_csr_get_subjectBir CSR'nin öznesini döndürür

Açıklama

openssl_csr_get_subject(OpenSSLCertificateSigningRequest|string $csr, bool $kısa_ad = true): array|false

openssl_csr_get_subject() commonName (CN), organizationName (O), countryName (C) vb. alanlar dahil olmak üzere csr'de kodlanmış konu ayırt edici ad bilgilerini döndürür.

Bağımsız Değişkenler

csr

Geçerli değerler Anahtar/Sertifika Bağımsız değişkenleri sayfasında bulunabilir.

kısa_ad

kısa_ad verinin dizi içinde nasıl indisleneceğini belirler - kısa_adtrue (öntanımlı) ise alanlar kısa isimlerle indislenir, aksi takdirde uzun isimler kullanılır. Örneğin, commonName için kısa isim CN'dir.

Dönen Değerler

Konuyu açıklayan ilişkisel bir dizi, başarısızlık durumunda false döner.

Sürüm Bilgisi

Sürüm: Açıklama
8.0.0 csr artık OpenSSLCertificateSigningRequest örneği kabul ediyor; evvelce OpenSSL X.509 CSR türünde bir özkaynak kabul ederdi.

Örnekler

Örnek 1 - openssl_csr_get_subject() örneği

<?php
$subject
= array(
"countryName" => "CA",
"stateOrProvinceName" => "Alberta",
"localityName" => "Calgary",
"organizationName" => "XYZ Widgets Inc",
"organizationalUnitName" => "PHP Documentation Team",
"commonName" => "Wez Furlong",
"emailAddress" => "wez@example.com",
);
$private_key = openssl_pkey_new(array(
"private_key_bits" => 2048,
"private_key_type" => OPENSSL_KEYTYPE_RSA,
));
$configargs = array(
'digest_alg' => 'sha512WithRSAEncryption'
);
$csr = openssl_csr_new($subject, $privkey, $configargs);
print_r(openssl_csr_get_subject($csr));
?>

Yukarıdaki örnek şuna benzer bir çıktı üretir:

Array
(
    [C] => CA
    [ST] => Alberta
    [L] => Calgary
    [O] => XYZ Widgets Inc
    [OU] => PHP Documentation Team
    [CN] => Wez Furlong
    [emailAddress] => wez@example.com
)

Ayrıca Bakınız

add a note

User Contributed Notes 4 notes

up
2
pdm at wp dot pl
8 years ago
openssl_csr_get_subject('somedomain.com',false);
return
array(7) {
["countryName"]=> string "XX"
["stateOrProvinceName"]=> string "xxxxxxxxx"
["localityName"]=> string "xxxxxxxx"
["organizationName"]=> string "xxxxxxxxx"
["organizationalUnitName"]=>string "xxxx"
["commonName"]=>string "xxx"
["emailAddress"]=>string "xxx"
}

openssl_csr_get_subject('somedomain.com',true);
return
array(7) {
["C"]=> string "XX"
["ST"]=> string "xxxxxxxxx"
["L"]=> string "xxxxxxxx"
["O"]=> string "xxxxxxxxx"
["OU"]=>string "xxxx"
["CN"]=>string "xxx"
["emailAddress"]=>string "xxx"
}
up
1
mikko koivu
13 years ago
this function does not yet return SANs (subject alternative names) fields for UC certificates like those used in exchange 2007.
up
0
Steve
7 years ago
This function may not return name fields in the order they appear in the certificate. For example, this CSR:

-----BEGIN CERTIFICATE REQUEST-----
MIHsMIGUAgEAMDIxEDAOBgNVBAsMB3VuaXQgIzExDDAKBgNVBAoMA29yZzEQMA4G
A1UECwwHdW5pdCAjMjBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABGvZnFxGuVzJ
hOKPs5RNxZBS4vY6ERaqm5tKMGOhxLSfv/dpjDtNNdSHkIGNjYxclHYhxG0ku7BY
PA5uPIjng1SgADAKBggqhkjOPQQDAgNHADBEAiB4GXhhbEU1UFTCe0dwJnKHTQuI
xzYL5FnyhmKdixN/0gIgBXSm9S8L/oJ6rBxemin/V/xKv5jy4TEZuz84nnshxQQ=
-----END CERTIFICATE REQUEST-----

When processed by 'openssl -noout -subject' gives this:

subject=/OU=unit #1/O=org/OU=unit #2

On the other hand, 'var_dump( openssl_csr_get_subject( "..." ) )' will produce this:

csr = array(2) {
["OU"]=>
array(2) {
[0]=>
string(7) "unit #1"
[1]=>
string(7) "unit #2"
}
["O"]=>
string(3) "org"
}

As you can see, ordering information (which may be important for some applications) is lost.
up
-2
stephan[at]strato-rz[dot]de
15 years ago
The returning assoziative array is indexed with the fields
in the subject so you should have a array key named CN,OU and so on.
To Top