-
Notifications
You must be signed in to change notification settings - Fork 275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
php-wasm/web : Explore composer usage #1712
Comments
php.cli()
method not working
I successfully tested compiling |
I take this "issue" to go further : In my quest to make the composer phar file work. I made the use of the php proxy server on
Unfortunately : the proxy handles only This is the
@adamziel I know this is not a priority but if you have any insights about how to handle CONNECT properly, this can become really interesting. |
I decided to go further on making composer phar work. I modified the current proxy server to run without the use of I additionnally upgraded Here is a Gist with the proxy.php file I run with The result is as follows when running
I didn't find today why there was a timeout. I know that this is due to a connection not made within the 10 seconds from line
And my proxy blocking during these 10 seconds on line
I decided to run the HTTPS request separately with
In the same spirit. Result : And it works...Composer's behavior seems strange. I feel like I'm missing something important. @adamziel @brandonpayton @bgrgicak — Is this something relevant? Should I continue investigating this? |
I finally managed to make things work on browser. Unfortunately a dynamic CAPem is needed and a TODO has been added by @adamziel months ago in #1093. The next step would be to dynamically export a CAPem made with the correct For the screenshot, I manually modified these lines : // @TODO: Create these certificates in FetchWebsocketConstructor based on the requested host
const { certificate, privateKey } = createCertificate({
- commonName: 'downloads.wordpress.org', //wsUrl.searchParams.get('host') || ''
+ commonName: 'repo.packagist.org',
});
const CAPair = { certificate, privateKey };
// const CAPair = createCertificate({
// commonName: ''
// });
export const CAPem = forge.pki.certificateToPem(CAPair.certificate);
But if I want this to work with dynamic domains I will have to overwrite the certificate based on the
But for now, only the original certificate is sent to
I still tried
This looks like Something similar occurs when using Composer v2. But this is probably linked with the fact that v2 uses curl requests under the hood and these are not intercepted by the websocket. |
php.cli()
method not working
Oh, this is such a great work @mho22! Generatic a dynamic ca.pem sounds like the best thing we can do, thank you for exploring that! The CORS part will get easier once we host a generic CORS proxy (that will happen) and open it up to all URLs (that may or may not happen). Actually, shipping a nice API for generating those certificates would unblock #1093 as that's the part we're missing. Forge JS can be quite slow and block the entire UI for a good few seconds. I was thinking about the following two ways of speeding it up:
|
I would be absolutely delighted to help complete task #1093, but I am not yet well informed about how the different steps work. So, I will need to dig deeper. I am trying to make the commands
Is "trying to make |
I think so! I've heard contributors asking about using composer in the browser. This could be interesting for the larger PHP community as well and would get us a composer playground for free. Once we integrate XTerm.js with the Playground UI, we could expose |
Interesting! Is that with #1093 applied? It should capture all network calls, it's weird if it doesn't. I remember installing composer packages in the past using |
I got this from Claude, it's probably incorrect but it's fast :D It may or may not be a good starting point for CA cert generation: /**
* Generate a CA.pem certificate pair dynamically in the browser with no dependencies
* using just the Browser-native crypto API.
*/
async function generateCaPem() {
const certInfo = {
serialNumber: '1',
validity: {
notBefore: new Date(),
notAfter: new Date(Date.now() + 1000 * 60 * 60 * 24 * 365),
},
subject: {
commonName: 'Root CA',
},
issuer: {
commonName: 'Root CA',
},
extensions: {
basicConstraints: {
critical: true,
cA: true,
},
keyUsage: {
digitalSignature: true,
keyCertSign: true,
},
},
};
const crypto = window.crypto;
const encoder = new TextEncoder();
const decoder = new TextDecoder();
const caKey = await crypto.subtle.generateKey(
{
name: 'RSASSA-PKCS1-v1_5',
modulusLength: 2048,
publicExponent: new Uint8Array([1, 0, 1]),
hash: 'SHA-256',
},
true,
['sign', 'verify']
);
// Create a simple ASN.1 structure for the certificate
const tbs = encoder.encode(JSON.stringify({
version: 3,
serialNumber: certInfo.serialNumber,
issuer: certInfo.issuer,
subject: certInfo.subject,
validity: {
notBefore: certInfo.validity.notBefore.toISOString(),
notAfter: certInfo.validity.notAfter.toISOString(),
},
extensions: certInfo.extensions,
}));
const signature = await crypto.subtle.sign(
{
name: 'RSASSA-PKCS1-v1_5',
},
caKey.privateKey,
tbs
);
// Combine TBS and signature into a simple certificate structure
const cert = encoder.encode(JSON.stringify({
tbsCertificate: decoder.decode(tbs),
signatureAlgorithm: 'sha256WithRSAEncryption',
signatureValue: btoa(String.fromCharCode(...new Uint8Array(signature))),
}));
const caPem = `-----BEGIN CERTIFICATE-----\n${btoa(decoder.decode(cert))}\n-----END CERTIFICATE-----`;
const caKeyPem = await exportKeyToPem(caKey.privateKey);
return { caPem, caKeyPem };
}
async function exportKeyToPem(key) {
const exported = await crypto.subtle.exportKey('pkcs8', key);
const exportedAsBase64 = btoa(String.fromCharCode(...new Uint8Array(exported)));
return `-----BEGIN PRIVATE KEY-----\n${exportedAsBase64}\n-----END PRIVATE KEY-----`;
}
generateCaPem().then(({ caPem, caKeyPem }) => {
console.log({ caPem, caKeyPem });
}); |
I’ve applied all the code changes from #1093. I also successfully installed composer packages using I recall setting Anyway, thanks for your insights and help. Back to work for me! |
It was indeed related to |
curl :( |
Solving #1093 would allow enabling curl in the browser! |
I couldn't resist and tried @adamziel new #1926 from this morning, and I managed to retrieve the first data from composer ! Unfortunately it doesn't work exactly as expected... With Composer 2 : But as you can see : There is still something not working when trying to decode data from Edit > Next step : transform these FAIL into OK |
Some weird things happen when running HTTP : According to Composer, the HTTP request failed...But I got the correct content. HTTPS : Same here, HTTPS request failed... But I got the correct content... Maybe the problem comes from my proxy... P.S.: Sorry for the screenshots flood. |
16 seconds for a unique composer package CowsayPHP for a basic test :
|
Nice @mho22! I wonder if that previous test would be faster now that we have curl 🤔 |
@adamziel Unfortunetaly, these processes are actually made with curl enabled. I echoed So the previous 12 minutes test was with curl enabled. I maybe missed something, because I admit the two chronos are pretty slow. I need to try it again on the |
@adamziel My bad, I retried with the First one : it reduced from 12 minutes to 7 minutes Looks promising ! I will investigate to find if this time can be even more reduced. |
I discovered that the
php.cli
method is accessible with@php-wasm/universal
throughPHP
, and I wanted to test it in the browser usingloadWebRuntime
.However, it appears that the C function
_wasm_add_cli_args
cannot be found. This function comes from theWITH_CLI_SAPI
option, which is only available inphp-wasm/node
.I’m trying to understand what might be missing:
WITH_CLI_SAPI
option inweb-kitchen-sink
php.cli
method in the web environmentFYI : Here is the error I encountered when running
php.cli
:I’m not sure if this is a real issue. I look forward to any insights you can provide.
The text was updated successfully, but these errors were encountered: