php / php/php-src

Include JS WebCrypto raw format for openssl_get_publicKey

Offen
#13,995 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Extension: openssl Feature Status: Needs Triage
Vorherrschende Sprache
C
Sterne
40.4k
Forks
8.1k
Ø Merge
2 T. 13 Std.
Gemergte PRs (30 T.)
96

Beschreibung

Description

With the inclusion of JS WebCrypto API, I believe it is necessary to support the exported raw format when client sends their own public EC keys to the server.


const { publicKey } = await crypto.subtle.generateKey({
  name : 'ECDH',  
  namedCurve : 'P-256'
}, true, ['deriveBits'])

const exported_key = new Uint8Array(await crypto.subtle.exportKey('raw', publicKey))

fetch('key.php', {
  method : 'post', 
  body :  btoa(String.fromCharCode(...exported_key))
}).then(e=>e.text())

However, openssl_pkey_get_public only accepts PEM formatted string. This would mean a whole lot of concatenating to do before we are able to get the public OpenSSLAsymmetricKey

$raw_format = base64_decode(file_get_content("php://input"));
// This header is only for P-256
$asn_1_header = pack('C*', ...[48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7, 3, 66, 0]);

var_dump(openssl_get_publicKey("-----BEGIN PUBLIC KEY-----\n".base64_encode($asn_1_header.$raw_format)."\n-----END PUBLIC KEY-----"));

It would be pretty cool to simplify it so that it becomes the following.

openssl_get_publicKey($raw_format);

I think alternatively we can make a new function for openssl to load what JS Web Crypto generated as "raw" type.

Note

I know that WebCrypto API does allow exporting SPKI key but that is besides the point. To add to this, when you subscribe to pushmanager, a p256dh is given in "raw" format as defined by WebCrypto API.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne bei den Einstiegspunkten openssl_get_publicKey und openssl_pkey_get_public und prüfe, wie öffentliche OpenSSL-Schlüssel derzeit akzeptiert werden. Ermittle, wie rohe WebCrypto-Eingaben für EC-öffentliche Schlüssel erkannt und unterstützt werden sollten, einschließlich des genannten P-256-Beispiels; abgeschlossen ist die Aufgabe, wenn die rohe Eingabe ohne manuelles ASN.1- oder PEM-Wrapping einen OpenSSLAsymmetricKey erzeugen kann.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, php
Bereich
cryptography
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
30/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.