# Ext/OpenSSL patch

- Thread: https://externals.io/message/31349
- Original archive: https://news-web.php.net/php.internals/31349
- Started by Dmitry Stogov on 2007-08-01T08:56:47+00:00
- Messages: 6
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #31349 — Dmitry Stogov — 2007-08-01T08:56:47+00:00

URL: https://externals.io/message/31349#31349

Hi,

I propose a patch for ext/openssl that extends support for crypto API.
- it provides access to openSSL digest functions
	function `openssl_get_md_methods()`;
	function openssl_digest(string $data, string $method [, bool $raw]);
- it provides access to openSSL digest functions
	function `openssl_get_cipher_methods()`;
	function openssl_encrypt(string $data, string $method, $string
$password [, bool $raw]);
	function openssl_decrypt(string $data, string $method, $string
$password [, bool $raw]);
- It extends existing functions `openssl_pkey_new()` and
 `openssl_pkey_get_details()` to access internal values of DSA, RSA and DH
keys. For example you can create DH key and then access its internal values
using the following code:
	<?php
		$dh = openssl_pkey_new(array('dh' => array(
			'p' => pack('H*', 'dcf93a0b883972ec'),
			'g' => pack(H*', '02')));
		$details = openssl_pkey_get_details($dh);
		var_dump(base64_encode($deteils['dh']['p']));
		var_dump(base64_encode($deteils['dh']['g']));
		var_dump(base64_encode($deteils['dh']['priv_key']));
		var_dump(base64_encode($deteils['dh']['pub_key']));
	?>
- it provides new function that computes shared secret for two DH keys
	function openssl_dh_compute_key(string $pub_key, resource $dh)
- it also extend some functions to support string name of crypto algorith in
addition to numeric constants.

This patch was written to implement OpenID protocol in PHP.
It is similar to patch by Wez
http://netevil.org/blog/2007/feb/openid-and-typekey-using-native-openssl-fun
ctions-in-php
but it provides less additional functions and works with big numbers as with
strings (instead of resources).

I would like to commit the path to PHP_5_2 and HEAD.
Any objections?

Thanks. Dmitry.

---

## #31350 — Jani Taskinen — 2007-08-01T09:36:06+00:00

URL: https://externals.io/message/31349#31350 · In reply to: #31349

You just wasted time posting this here, just commit it. :)

--Jani


> Hi,
> 
> I propose a patch for ext/openssl that extends support for crypto API.
> - it provides access to openSSL digest functions
> 	function `openssl_get_md_methods()`;
> 	function openssl_digest(string $data, string $method [, bool $raw]);
> - it provides access to openSSL digest functions
> 	function `openssl_get_cipher_methods()`;
> 	function openssl_encrypt(string $data, string $method, $string
> $password [, bool $raw]);
> 	function openssl_decrypt(string $data, string $method, $string
> $password [, bool $raw]);
> - It extends existing functions `openssl_pkey_new()` and
> `openssl_pkey_get_details()` to access internal values of DSA, RSA and DH
> keys. For example you can create DH key and then access its internal values
> using the following code:
> 	<?php
> 		$dh = openssl_pkey_new(array('dh' => array(
> 			'p' => pack('H*', 'dcf93a0b883972ec'),
> 			'g' => pack(H*', '02')));
> 		$details = openssl_pkey_get_details($dh);
> 		var_dump(base64_encode($deteils['dh']['p']));
> 		var_dump(base64_encode($deteils['dh']['g']));
> 		var_dump(base64_encode($deteils['dh']['priv_key']));
> 		var_dump(base64_encode($deteils['dh']['pub_key']));
> 	?>
> - it provides new function that computes shared secret for two DH keys
> 	function openssl_dh_compute_key(string $pub_key, resource $dh)
> - it also extend some functions to support string name of crypto algorith in
> addition to numeric constants.
> 
> This patch was written to implement OpenID protocol in PHP.
> It is similar to patch by Wez
> http://netevil.org/blog/2007/feb/openid-and-typekey-using-native-openssl-fun
> ctions-in-php
> but it provides less additional functions and works with big numbers as with
> strings (instead of resources).
> 
> I would like to commit the path to PHP_5_2 and HEAD.
> Any objections?
> 
> Thanks. Dmitry.

---

## #31351 — Pierre — 2007-08-01T09:41:48+00:00

URL: https://externals.io/message/31349#31351 · In reply to: #31350

> You just wasted time posting this here, just commit it. :)

Thanks for this patch, so far my favourite until now! It does not
bring more inconsistencies to the openssl API and easy to understand.

I agree with Jani, you can commit it to HEAD so we can start to play
with it and see what can/should/could be improved or added. I have
played with my own patches to add similar features and met a couple of
annoyances, once it is in HEAD we can start to discuss and fix them if
any :)

Cheers,
--Pierre

---

## #31352 — Rob Richards — 2007-08-01T12:11:35+00:00

URL: https://externals.io/message/31349#31352 · In reply to: #31349

Hi Dmitry,

Dmitry Stogov wrote:
> Hi,
> 
> I propose a patch for ext/openssl that extends support for crypto API.
> - it provides access to openSSL digest functions
> 	function `openssl_get_md_methods()`;
> 	function openssl_digest(string $data, string $method [, bool $raw]);
> - it provides access to openSSL digest functions
> 	function `openssl_get_cipher_methods()`;
> 	function openssl_encrypt(string $data, string $method, $string
> $password [, bool $raw]);
> 	function openssl_decrypt(string $data, string $method, $string
> $password [, bool $raw]);
> - It extends existing functions `openssl_pkey_new()` and
> `openssl_pkey_get_details()` to access internal values of DSA, RSA and DH
> keys. For example you can create DH key and then access its internal values
> using the following code:

...

I would like to see this committed. I really could use this for some XML 
Sec functionality.

Rob

---

## #31353 — David Coallier — 2007-08-01T13:35:42+00:00

URL: https://externals.io/message/31349#31353 · In reply to: #31352

> Hi Dmitry,
>
> Dmitry Stogov wrote:
> > […]
>
> ...
>
> I would like to see this committed. I really could use this for some XML
> Sec functionality.
>
> Rob
>
> --
> 
> 
>
>

Awesome work Dmitry, thanks! :)

-- 
David Coallier,
Founder & Software Architect,
Agora Production (http://agoraproduction.com)
51.42.06.70.18

---

## #31386 — Stanislav Malyshev — 2007-08-02T23:18:42+00:00

URL: https://externals.io/message/31349#31386 · In reply to: #31349

Sounds good. Couple of notes:

1. Functions seem to lack prototypes except for encrypt which says:
"Returns an array of the fields/values of the CERT" - obviously it's 
some mistake :)

2. openssl_encrypt says "Unknown signature algorithm." when it should be 
encryption algorithm I guess... And the final period isn't needed I 
think. The same for decrypt.
-- 
Stanislav Malyshev, Zend Software Architect
stas@zend.com   http://www.zend.com/
(408)253-8829   MSN: stas@zend.com
