Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:5299 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 82687 invoked by uid 1010); 6 Nov 2003 16:21:07 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 82663 invoked from network); 6 Nov 2003 16:21:06 -0000 Received: from unknown (HELO mwinf0601.wanadoo.fr) (193.252.22.25) by pb1.pair.com with SMTP; 6 Nov 2003 16:21:06 -0000 Received: from enolas.laposte.net (AMontsouris-108-1-26-92.w81-48.abo.wanadoo.fr [81.48.243.92]) by mwinf0601.wanadoo.fr (SMTP Server) with ESMTP id 4E340340023F; Thu, 6 Nov 2003 17:21:05 +0100 (CET) Message-ID: <6.0.0.22.1.20031106164010.01aded88@pop.laposte.net> X-Sender: e.colinet@pop.laposte.net (Unverified) X-Mailer: QUALCOMM Windows Eudora Version 6.0.0.22 Date: Thu, 06 Nov 2003 17:19:20 +0100 To: "Richard Burton" , internals@lists.php.net In-Reply-To: References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=====================_11430376==_" Subject: Re: [PHP-DEV] [PATCH] openssl_pkcs7_encrypt to/from variable or file From: e.colinet@laposte.net (Eric COLINET) --=====================_11430376==_ Content-Type: text/plain; charset="us-ascii"; format=flowed Hi ! Richard, I understand very well the benefit of using only one function to do the same work, but they are already 2 function that does the same for private keys and for consistency i think i had to submit 2 function to do the same job for public keys. Of course the best way is to have only too function to do the job (one for public and one for private keys) but i just can't decide myself to break compatibility. So i submit my two little functions. Sorry this is not a patch. Regards, Eric At 16:59 05/11/2003, Richard Burton wrote: >Eric, > >Might I suggest that if you submit a patch for this, you add just one >function and check for a "file://" prefix to determine if the user want to >work with a file or variable? This is the way certificates are handled at >present, and I used this method for my patch to try and be consistent with it. > >I'm a big fan of consistency, but I know others' views differ. I guess >it's over to Wez for guidence, since it's his extension? > >Richard. > > >>From: Eric COLINET >>To: >>CC: >>Subject: Re: [PHP-DEV] [PATCH] openssl_pkcs7_encrypt to/from variable or >>file >>Date: Wed, 05 Nov 2003 12:57:20 +0100 >> >>Hi ! >> >>In the same series .. >> >>I have no patch to provide but i've written two functions related to >>php_openssl: >> openssl_pubkey_export >> openssl_pubkey_export_to_file >> >>That simply allow the export of public keys that seems to be not possible >>before. >> >>I there is no special reason for that i can submit them (they are small >>modification of openssl_pkey_export & openssl_pkey_export_to_file) >> >> >>Eric > >_________________________________________________________________ >Tired of 56k? Get a FREE BT Broadband connection >http://www.msn.co.uk/specials/btbroadband > >-- >PHP Internals - PHP Runtime Development Mailing List >To unsubscribe, visit: http://www.php.net/unsub.php --=====================_11430376==_ Content-Type: text/plain; charset="us-ascii" Content-Disposition: attachment; filename="pkey_public_export.c" /* {{{ proto bool openssl_pkey_public_export_to_file(mixed key, string outfilename) Gets an exportable representation of a public key into a file */ PHP_FUNCTION(openssl_pkey_public_export_to_file) { struct php_x509_request req; zval * zpkey; char * filename = NULL; long filename_len = 0; long key_resource = -1; EVP_PKEY * key; BIO * bio_out = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zs", &zpkey, &filename, &filename_len ) == FAILURE) return; RETVAL_FALSE; key = php_openssl_evp_from_zval(&zpkey, 1, NULL, 0, &key_resource TSRMLS_CC); if (key == NULL) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot get key from parameter 1"); RETURN_FALSE; } if (php_openssl_safe_mode_chk(filename TSRMLS_CC)) { RETURN_FALSE; } PHP_SSL_REQ_INIT(&req); bio_out = BIO_new_file(filename, "w"); if (PEM_write_bio_PUBKEY(bio_out, key)) { /* Success! */ RETVAL_TRUE; } PHP_SSL_REQ_DISPOSE(&req); if (key_resource == -1 && key) { EVP_PKEY_free(key); } if (bio_out) BIO_free(bio_out); } /* }}} */ /* {{{ proto bool openssl_pkey_public_export(mixed key, &mixed out) Gets an exportable representation of a public key into a string */ PHP_FUNCTION(openssl_pkey_public_export) { struct php_x509_request req; zval * zpkey, *out; long key_resource = -1; EVP_PKEY * key; BIO * bio_out = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &zpkey, &out) == FAILURE) return; RETVAL_FALSE; key = php_openssl_evp_from_zval(&zpkey, 1, NULL, 0, &key_resource TSRMLS_CC); if (key == NULL) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot get key from parameter 1"); RETURN_FALSE; } PHP_SSL_REQ_INIT(&req); bio_out = BIO_new(BIO_s_mem()); if (PEM_write_bio_PUBKEY(bio_out, key)) { /* Success! * If returning the output as a string, do so now */ char * bio_mem_ptr; long bio_mem_len; RETVAL_TRUE; bio_mem_len = BIO_get_mem_data(bio_out, &bio_mem_ptr); ZVAL_STRINGL(out, bio_mem_ptr, bio_mem_len, 1); } PHP_SSL_REQ_DISPOSE(&req); if (key_resource == -1 && key) { EVP_PKEY_free(key); } if (bio_out) BIO_free(bio_out); } /* }}} */ --=====================_11430376==_--