Activate web crypto api (still fails tests)
* Remove api support for safari * Fix error handling
This commit is contained in:
parent
cbe4a17ccb
commit
85d2199971
|
@ -139,9 +139,7 @@ function RSA() {
|
||||||
// Native RSA keygen using Web Crypto
|
// Native RSA keygen using Web Crypto
|
||||||
//
|
//
|
||||||
|
|
||||||
if (false && typeof window !== 'undefined' && window.crypto && (window.crypto.subtle || window.crypto.webkitSubtle)) {
|
if (typeof window !== 'undefined' && window.crypto && window.crypto.subtle) {
|
||||||
var subtle = window.crypto.subtle || window.crypto.webkitSubtle;
|
|
||||||
|
|
||||||
var keyGenOpt = {
|
var keyGenOpt = {
|
||||||
name: 'RSASSA-PKCS1-v1_5',
|
name: 'RSASSA-PKCS1-v1_5',
|
||||||
modulusLength: B, // the specified keysize in bits
|
modulusLength: B, // the specified keysize in bits
|
||||||
|
@ -153,17 +151,21 @@ function RSA() {
|
||||||
|
|
||||||
var extractable = true; // make generated key extractable
|
var extractable = true; // make generated key extractable
|
||||||
|
|
||||||
subtle.generateKey(keyGenOpt, extractable, ['sign', 'verify'])
|
window.crypto.subtle.generateKey(keyGenOpt, extractable, ['sign', 'verify'])
|
||||||
.then(onGenerated, callback)
|
.then(onGenerated, onError)
|
||||||
.then(onExported, callback);
|
.then(onExported, onError);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onError() {
|
||||||
|
callback(new Error('Generating key failed!'));
|
||||||
|
}
|
||||||
|
|
||||||
function onGenerated(key) {
|
function onGenerated(key) {
|
||||||
// export the generated keys as JsonWebKey (JWK)
|
// export the generated keys as JsonWebKey (JWK)
|
||||||
// https://tools.ietf.org/html/draft-ietf-jose-json-web-key-33
|
// https://tools.ietf.org/html/draft-ietf-jose-json-web-key-33
|
||||||
return subtle.exportKey('jwk', key.privateKey);
|
return window.crypto.subtle.exportKey('jwk', key.privateKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onExported(jwk) {
|
function onExported(jwk) {
|
||||||
|
|
|
@ -272,7 +272,7 @@ function useWorker(callback) {
|
||||||
* Check for WebCrypto support
|
* Check for WebCrypto support
|
||||||
*/
|
*/
|
||||||
function useWebCrypto() {
|
function useWebCrypto() {
|
||||||
return typeof window !== 'undefined' && window.crypto && (window.crypto.subtle || window.crypto.webkitSubtle);
|
return typeof window !== 'undefined' && window.crypto && window.crypto.subtle;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user