php / php/php-src

Include JS WebCrypto raw format for openssl_get_publicKey

Ouverte
#13,995 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Extension: openssl Feature Status: Needs Triage
Langage dominant
C
Étoiles
40.4k
Forks
8.1k
Merge moyen
2 j 13 h
PR mergées (30 j)
96

Description

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.

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par les points d’entrée openssl_get_publicKey et openssl_pkey_get_public et examinez comment les clés publiques OpenSSL sont actuellement acceptées. Déterminez comment les entrées brutes de clés publiques EC WebCrypto doivent être reconnues et prises en charge, y compris l’exemple P-256 indiqué ; le travail est considéré comme terminé lorsque l’entrée brute peut produire un OpenSSLAsymmetricKey sans encapsulation manuelle en ASN.1 ou PEM.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
javascript, php
Domaine
cryptography
Type d'issue
Fonctionnalité
Difficulté
5/5
Temps estimé
Plus d'une semaine
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
30/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.