-
Notifications
You must be signed in to change notification settings - Fork 26
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
Doesn't work in Safari #44
Comments
Sounds like you didn't follow the steps in https://github.com/PeculiarVentures/webcrypto-liner#installation Specifically if your going to run in a browser that doesn't support ES6 you need to be sure to convert to ES2015 |
Ok, I now followed the steps, the error now occurs on a different line, but the error is the same "Unable to delete property".
Basically, if I would try to manually do: |
I tried this fix, and got past that error, diff --git a/src/shim.ts b/src/shim.ts
index d136bde..06b6dc2 100644
--- a/src/shim.ts
+++ b/src/shim.ts
@@ -10,8 +10,12 @@ if (nativeCrypto) {
Object.freeze(nativeCrypto.getRandomValues);
}
-delete (self as any).crypto;
-w.crypto = new Crypto();
+try {
+ delete (self as any).crypto;
+ w.crypto = new Crypto();
+} catch(e){
+ w.crypto.subtle = new Crypto().subtle;
+}
Object.freeze(w.crypto);
export const crypto = w.crypto; However, when I try to use the sample to "Sign", I get error from App.sign() call, that I tracked down to this line in file subtle.ts:
|
Works in Safari without code modification as we use it in several projects, ill have @microshine take a look when he gets online. |
Hi Ryan ,
Can you recommend something that I can use in Cordova to encrypt with AES-GCM on the mobile phone? Some Cordova plugin perhaps ?
Thanks ,
Boris
…On 2017-12-19 at 7:27 PM, "Ryan Hurst" ***@***.***> wrote:
Works in Safari without code modification as we use it in several
projects, ill have @microshine take a look when he gets online.
--
You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub:
https://github.com/PeculiarVentures/webcrypto-
liner/issues/44#issuecomment-352954831
|
Boris, I am not too familiar with cordova/phonegap but I understand you end up with JS also using this should work. Ryan |
@borisreitman Could you try https://github.com/PeculiarVentures/webcrypto-liner/blob/master/dist/webcrypto-liner.lib.js? This variant of webcrypto-liner doesn't delete native crypto object. This script uses global Example<script src="https://peculiarventures.github.io/pv-webcrypto-tests/src/asmcrypto.js"></script>
<script src="webcrypto-liner.lib.js"></script> liner.crypto.subtle.generateKey({name: "AES-GCM", length: 256}, false, ["encrypt"]).then((k) => {
console.log(k);
}) |
Yes, this version worked fine. Quick question: does liner work in a browser that has no native window.crypto at all ? |
@borisreitman Yes, it does. Examplefunction getRandomArbitrary(min, max)
{
return self.Math.random() * (max - min) + min;
}
function getRandomValues(buffer)
{
// TODO: seed random
const buf = new Uint8Array(buffer.buffer);
let i = 0;
while(i < buf.length)
buf[i++] = getRandomArbitrary(0, 255);
return buffer;
}
if(!self.crypto) {
self.crypto = { getRandomValues: getRandomValues };
Object.freeze(self.crypto);
} |
For anyone else who may benefit from reading this thread, here's a tip on where to get native random numbers in Cordova.
https://github.com/aerogear/aerogear-cordova-crypto EDIT: I just checked that both Android Webview and iOS Safari (and probably the iOS Webview) have window.crypto.getRandomValues() and the whole window.crypto.subtle suite. Someone has reported on StackOverflow that Android has no subtle, but it was his error. It's there, as long as user is using https:// to browse a website. And, it is there in the Cordova webview. |
I cloned the project, installed webpack, and ran webpack that generated files in dist/ directory.
However, when I try to run the example in examples/src/index.html on Safari, I get an error.
The first error I get is "unable to delete property" on line 3719:
When I actually try to use the sample, I get the error:
undefined is not an object (evaluating 'crypto.subtle.generateKey')
Safari version: Version 9.1.3 (11601.7.8) on a MacBook Pro, OSX version 10.11.6 (15G1004)
The text was updated successfully, but these errors were encountered: