# Fwd: [PATCH] added: openssl_csr_subject()

- Thread: https://externals.io/message/13244
- Original archive: https://news-web.php.net/php.internals/13244
- Started by Greg MacLellan on 2004-10-08T19:48:34+00:00
- Messages: 5
- 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

---

## #13244 — Greg MacLellan — 2004-10-08T19:48:34+00:00

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

I apologize - it helps when I actually attach the patch.

---

## #13246 — Wez Furlong — 2004-10-08T20:22:26+00:00

URL: https://externals.io/message/13244#13246 · In reply to: #13244

Two or three comments:

- You leak the dynamically allocated buffer returned by X509_NAME_oneline()
- X509_NAME_oneline() man page says that its use is discouraged in
favour of smarter functions.  Is there a possibility that someone will
need that functionality?
- if you can solve/answer both of the above, please post a link to the patch

Thanks :)

--Wez.


On Fri, 08 Oct 2004 15:48:34 -0400, Greg MacLellan
<greg@gregmaclellan.com> wrote:
> I apologize - it helps when I actually attach the patch.

---

## #13284 — Greg MacLellan — 2004-10-12T18:47:05+00:00

URL: https://externals.io/message/13244#13284 · In reply to: #13246

Wez Furlong wrote:

>Two or three comments:
>
>- You leak the dynamically allocated buffer returned by X509_NAME_oneline()
>- X509_NAME_oneline() man page says that its use is discouraged in
>favour of smarter functions.  Is there a possibility that someone will
>need that functionality?
>- if you can solve/answer both of the above, please post a link to the patch
>  
>
Now uses X509_NAME_print_ex(), using the XN_FLAGS_RFC2253 option. The 
only other flags for X509_NAME_print_ex() control the output string. I 
was going to add options for the php function to select them, but I 
don't see the use as the RFC2253 output is easily parsable and the other 
options don't do much (reverse order, or spaces instead of commas as 
delimiters).

I also changed the prototype to be more like with the other openssl 
functions (returning bool):

bool openssl_csr_subject(mixed csr, string &out)

Now, I don't do very much C coding, and I'm pretty new to the zend API.. 
One thing I couldn't figure out was why (in php) openssl_csr_subject() 
won't put anything into $out if it's passed an undefined variable (where 
as openssl_csr_export, which is very similar, works).

For example (let's pretend $csr is a string containing a PEM-encoded CSR):

    function test($csr) {
        openssl_csr_subject($csr, $out);
        var_dump($out);
    }

will show "NULL", whereas:

    function test($csr) {
        openssl_csr_subject($csr, &$out);
        var_dump($out);
    }

and

    function test($csr) {
        $out = NULL;
        openssl_csr_subject($csr, $out);
        var_dump($out);
    }

both work fine, showing string (90) { 
"emailAddress=blah@php.net,OU=php...." }

It looks to me like it has something to do with $out not being set 
(though, with $out = `NULL` isset($out) still returns false), but I'm 
still not sure why passing $out by reference at call-time would work in 
that case.

---

## #13285 — Wez Furlong — 2004-10-12T19:31:30+00:00

URL: https://externals.io/message/13244#13285 · In reply to: #13284

On Tue, 12 Oct 2004 14:47:05 -0400, Greg MacLellan
<greg@gregmaclellan.com> wrote:
> Now uses X509_NAME_print_ex(), using the XN_FLAGS_RFC2253 option.

Looks much better now

> bool openssl_csr_subject(mixed csr, string &out)
> 
> Now, I don't do very much C coding, and I'm pretty new to the zend API..
> One thing I couldn't figure out was why (in php) openssl_csr_subject()
> won't put anything into $out if it's passed an undefined variable (where
> as openssl_csr_export, which is very similar, works).

>         PHP_FE(openssl_csr_export,                      arg2_force_ref)
> +       PHP_FE(openssl_csr_subject,                     NULL)

The answer is here; you need to mark the function entry as requiring the
second arg to be passed by ref by replacing that `NULL` with arg2_force_ref.

If you can make that change and then either put the diff online, or as
a regular MIME plain text attachment and not inlined, so that it is
easy to get at without it being mangled in the email, I will apply it
to CVS.

Thanks :)

--Wez.

---

## #13288 — Greg MacLellan — 2004-10-12T20:36:13+00:00

URL: https://externals.io/message/13244#13288 · In reply to: #13285

Wez Furlong wrote:

>If you can make that change and then either put the diff online, or as
>a regular MIME plain text attachment and not inlined, so that it is
>easy to get at without it being mangled in the email, I will apply it
>to CVS.
>  
>
Done.  It actually didn't come out mangled for me at all (mozilla 
thunderbird) .. but I threw it on the web anyway:

www.gregmaclellan.com/openssl.patch

ttyl, greg
