php / php/php-src

Include JS WebCrypto raw format for openssl_get_publicKey

Đang mở
#13,995 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Extension: openssl Feature Status: Needs Triage
Ngôn ngữ chính
C
Star
40.4k
Fork
8.2k
Merge trung bình
2 ngày 13 giờ
Pull request đã merge (30 ngày)
96

Mô tả

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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu từ các entry point openssl_get_publicKey và openssl_pkey_get_public, rồi xem xét cách các khóa công khai OpenSSL hiện đang được chấp nhận. Xác định cách nhận diện và hỗ trợ đầu vào khóa công khai EC thô của WebCrypto, bao gồm ví dụ P-256 đã nêu; được xem là hoàn tất khi đầu vào thô có thể tạo ra một OpenSSLAsymmetricKey mà không cần bọc thủ công bằng ASN.1 hoặc PEM.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript, php
Lĩnh vực
cryptography
Loại issue
Tính năng
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
30/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.