Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Zend/Optimizer/zend_func_infos.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ static const func_info_t func_infos[] = {
F1("openssl_get_curve_names", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING|MAY_BE_FALSE),
#endif
F1("openssl_get_cert_locations", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_STRING),
F1("openssl_oid_lookup", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_STRING|MAY_BE_FALSE),
FN("pcntl_signal_get_handler", MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING|MAY_BE_ARRAY_OF_OBJECT|MAY_BE_OBJECT|MAY_BE_LONG),
FN("preg_replace", MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_STRING|MAY_BE_NULL),
FN("preg_filter", MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_STRING|MAY_BE_NULL),
Expand Down
80 changes: 80 additions & 0 deletions ext/openssl/openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -4588,3 +4588,83 @@ PHP_FUNCTION(openssl_random_pseudo_bytes)
}
}
/* }}} */

/* {{{ Given an Object ID, or object short or long name, return an associative
array containing any known OID, short name, and long name, or false if the
object is not known.

Example:

var_dump( openssl_oid_lookup( "CN" ) );
var_dump( openssl_oid_lookup( "unstructuredAddress" ) );
var_dump( openssl_oid_lookup( "1.2.3.4.5" ) );
var_dump( openssl_oid_lookup( "junk" ) );

Produces;

array(3) {
["oid"]=>
string(7) "2.5.4.3"
["lname"]=>
string(10) "commonName"
["sname"]=>
string(2) "CN"
}

array(2) {
["oid"]=>
string(20) "1.2.840.113549.1.9.8"
["lname"]=>
string(19) "unstructuredAddress"
}

array(1) {
["oid"]=>
string(9) "1.2.3.4.5"
}

bool(false)

*/
PHP_FUNCTION(openssl_oid_lookup)
{
zend_string * txt;
ASN1_OBJECT *obj;
char buf[1024];
int nid;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &txt) == FAILURE) {
return;
}

obj = OBJ_txt2obj(ZSTR_VAL(txt), 0);
if (obj == NULL) {
RETURN_FALSE;
}

OBJ_obj2txt(buf, sizeof(buf)-1, obj, 1);
if (*buf == '\0') {
RETURN_FALSE;
}

array_init(return_value);
add_assoc_string(return_value, "oid", buf);

if ((nid = OBJ_obj2nid(obj)) != NID_undef) {
const char *l;
const char *s;

l = OBJ_nid2ln(nid);
if (l != NULL) {
add_assoc_string(return_value, "lname", (char *) l);
}

s = OBJ_nid2sn(nid);
if (s != NULL && (l == NULL || strcmp(s,l) != 0)) {
add_assoc_string(return_value, "sname", (char *) s);
}
}

ASN1_OBJECT_free(obj);
}
/* }}} */
6 changes: 6 additions & 0 deletions ext/openssl/openssl.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -699,3 +699,9 @@ function openssl_get_cert_locations(): array {}
function openssl_password_hash(string $algo, #[\SensitiveParameter] string $password, array $options = []): string {}
function openssl_password_verify(string $algo, #[\SensitiveParameter] string $password, string $hash): bool {}
#endif

/**
* @return array<string, string>|false
* @refcount 1
*/
function openssl_oid_lookup(string $txt): array|false {}
8 changes: 7 additions & 1 deletion ext/openssl/openssl_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions ext/openssl/tests/openssl_oid_lookup_basic.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
--TEST--
openssl_csr_new() attributes setting tests
--EXTENSIONS--
openssl
--FILE--
<?php
var_dump(openssl_oid_lookup("CN"));
var_dump(openssl_oid_lookup("unstructuredAddress"));
var_dump(openssl_oid_lookup("1.2.3.4.5"));
var_dump(openssl_oid_lookup("junk"));
?>
--EXPECTF--
array(3) {
["oid"]=>
string(7) "2.5.4.3"
["lname"]=>
string(10) "commonName"
["sname"]=>
string(2) "CN"
}
array(2) {
["oid"]=>
string(20) "1.2.840.113549.1.9.8"
["lname"]=>
string(19) "unstructuredAddress"
}
array(1) {
["oid"]=>
string(9) "1.2.3.4.5"
}
bool(false)