Bug 164868

Summary: CryptoKeyPair objects should be dictionaries - and not a distinct object type - making them structured cloneable
Product: WebKit Reporter: Jason Mei <jason.mei>
Component: WebCore Misc.Assignee: Nobody <webkit-unassigned>
Status: RESOLVED DUPLICATE    
Severity: Normal CC: ap, beidson, jason.mei, jiewen_tan, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: Safari Technology Preview   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 160880    
Attachments:
Description Flags
stand alone html that shows the problem none

Description Jason Mei 2016-11-17 08:09:49 PST
Created attachment 295050 [details]
stand alone html that shows the problem

There is a problem adding the CryptoKeyPair object into indexedDB.  I have attached a html test case that shows this problem.

This code works in Chrome and Firefox.  Neither browser returns a CryptoKeyPair, and instead returns a plain object.
Comment 1 Radar WebKit Bug Importer 2016-11-17 09:38:55 PST
<rdar://problem/29312605>
Comment 2 Brady Eidson 2016-11-17 11:21:00 PST
> This code works in Chrome and Firefox.

but then

> Neither browser returns a CryptoKeyPair, and instead returns a plain object.

This makes no sense to me.
If it truly works, it would have to also *return* a CryptoKeyPair.

Are you sure CryptoKeyPair is actually serializable WRT the structured clone algorithm?

(I haven't looked into it yet)
Comment 3 Brady Eidson 2016-11-17 11:22:30 PST
(In reply to comment #2)
> > This code works in Chrome and Firefox.
> 
> but then
> 
> > Neither browser returns a CryptoKeyPair, and instead returns a plain object.
> 
> This makes no sense to me.
> If it truly works, it would have to also *return* a CryptoKeyPair.
> 
> Are you sure CryptoKeyPair is actually serializable WRT the structured clone
> algorithm?
> 
> (I haven't looked into it yet)

The error we throw: DataCloneError "An object could not be cloned"

This strongly suggests that CryptoKeyPairs are not structured cloneable, and therefore are not allowed to be stored in IDB
Comment 4 Brady Eidson 2016-11-17 11:28:37 PST
Also, you state this is a regression, but it is not: Safari 9 also shows the DataCloneError
Comment 5 Brady Eidson 2016-11-17 11:38:17 PST
The current spec for WebCrypto:
https://w3c.github.io/webcrypto/Overview.html#cryptokey-interface-clone

Specifies the Structured Clone Algorithm for "CryptoKey" objects.

It does *not* specify the Structured Clone Algorithm for "CryptoKeyPair" objects.

Additionally, the WebCrypto spec explicitly calls out the fact that CryptoKeys should be storable in IndexedDB, but not CryptoKeyPairs.
Comment 6 Brady Eidson 2016-11-17 11:39:13 PST
Basically, until somebody finds a standard that specifies the Structured Clone Algorithm for CryptoKeyPair objects, they absolutely should not be storable in IndexedDB.
Comment 7 Brady Eidson 2016-11-17 11:44:06 PST
I believe the reason Chrome and Firefox allow the put is that they do not recognize the CryptoKeyPair as a "CryptoKeyPair" - They think it's an "Object"

And "Objects" are structured cloneable as long as each of their properties are.
Comment 8 Brady Eidson 2016-11-17 11:46:42 PST
(In reply to comment #7)
> I believe the reason Chrome and Firefox allow the put is that they do not
> recognize the CryptoKeyPair as a "CryptoKeyPair" - They think it's an
> "Object"
> 
> And "Objects" are structured cloneable as long as each of their properties
> are.

Got it.

At one point in the history of the spec, CryptoKeyPair objects were their own interface, therefore their own explicit object type.

Now they're just an object dictionary (https://w3c.github.io/webcrypto/Overview.html#keypair), which means they are an "Object", which means they are structured cloneable
Comment 9 Brady Eidson 2016-11-17 11:47:06 PST
(In reply to comment #8)
> (In reply to comment #7)
> > I believe the reason Chrome and Firefox allow the put is that they do not
> > recognize the CryptoKeyPair as a "CryptoKeyPair" - They think it's an
> > "Object"
> > 
> > And "Objects" are structured cloneable as long as each of their properties
> > are.
> 
> Got it.
> 
> At one point in the history of the spec, CryptoKeyPair objects were their
> own interface, therefore their own explicit object type.
> 
> Now they're just an object dictionary
> (https://w3c.github.io/webcrypto/Overview.html#keypair), which means they
> are an "Object", which means they are structured cloneable

Fixing this is just a matter of fixing our IDL situation for CryptoKeyPair.
Comment 10 Brady Eidson 2016-12-02 13:57:35 PST
This will be resolved as part of https://bugs.webkit.org/show_bug.cgi?id=163711

*** This bug has been marked as a duplicate of bug 163711 ***
Comment 11 Jiewen Tan 2016-12-02 15:33:50 PST
We need a specific hack for this as Bug 163711 will not be resolved in a short term.
Comment 12 Jiewen Tan 2016-12-07 11:41:27 PST

*** This bug has been marked as a duplicate of bug 165367 ***