<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>164868</bug_id>
          
          <creation_ts>2016-11-17 08:09:49 -0800</creation_ts>
          <short_desc>CryptoKeyPair objects should be dictionaries - and not a distinct object type - making them structured cloneable</short_desc>
          <delta_ts>2016-12-07 11:41:27 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebCore Misc.</component>
          <version>Safari Technology Preview</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>165367</dup_id>
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>160880</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Jason Mei">jason.mei</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ap</cc>
    
    <cc>beidson</cc>
    
    <cc>jason.mei</cc>
    
    <cc>jiewen_tan</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1252294</commentid>
    <comment_count>0</comment_count>
      <attachid>295050</attachid>
    <who name="Jason Mei">jason.mei</who>
    <bug_when>2016-11-17 08:09:49 -0800</bug_when>
    <thetext>Created attachment 295050
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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1252313</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2016-11-17 09:38:55 -0800</bug_when>
    <thetext>&lt;rdar://problem/29312605&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1252350</commentid>
    <comment_count>2</comment_count>
    <who name="Brady Eidson">beidson</who>
    <bug_when>2016-11-17 11:21:00 -0800</bug_when>
    <thetext>&gt; This code works in Chrome and Firefox.

but then

&gt; 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&apos;t looked into it yet)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1252353</commentid>
    <comment_count>3</comment_count>
    <who name="Brady Eidson">beidson</who>
    <bug_when>2016-11-17 11:22:30 -0800</bug_when>
    <thetext>(In reply to comment #2)
&gt; &gt; This code works in Chrome and Firefox.
&gt; 
&gt; but then
&gt; 
&gt; &gt; Neither browser returns a CryptoKeyPair, and instead returns a plain object.
&gt; 
&gt; This makes no sense to me.
&gt; If it truly works, it would have to also *return* a CryptoKeyPair.
&gt; 
&gt; Are you sure CryptoKeyPair is actually serializable WRT the structured clone
&gt; algorithm?
&gt; 
&gt; (I haven&apos;t looked into it yet)

The error we throw: DataCloneError &quot;An object could not be cloned&quot;

This strongly suggests that CryptoKeyPairs are not structured cloneable, and therefore are not allowed to be stored in IDB</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1252354</commentid>
    <comment_count>4</comment_count>
    <who name="Brady Eidson">beidson</who>
    <bug_when>2016-11-17 11:28:37 -0800</bug_when>
    <thetext>Also, you state this is a regression, but it is not: Safari 9 also shows the DataCloneError</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1252367</commentid>
    <comment_count>5</comment_count>
    <who name="Brady Eidson">beidson</who>
    <bug_when>2016-11-17 11:38:17 -0800</bug_when>
    <thetext>The current spec for WebCrypto:
https://w3c.github.io/webcrypto/Overview.html#cryptokey-interface-clone

Specifies the Structured Clone Algorithm for &quot;CryptoKey&quot; objects.

It does *not* specify the Structured Clone Algorithm for &quot;CryptoKeyPair&quot; objects.

Additionally, the WebCrypto spec explicitly calls out the fact that CryptoKeys should be storable in IndexedDB, but not CryptoKeyPairs.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1252371</commentid>
    <comment_count>6</comment_count>
    <who name="Brady Eidson">beidson</who>
    <bug_when>2016-11-17 11:39:13 -0800</bug_when>
    <thetext>Basically, until somebody finds a standard that specifies the Structured Clone Algorithm for CryptoKeyPair objects, they absolutely should not be storable in IndexedDB.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1252377</commentid>
    <comment_count>7</comment_count>
    <who name="Brady Eidson">beidson</who>
    <bug_when>2016-11-17 11:44:06 -0800</bug_when>
    <thetext>I believe the reason Chrome and Firefox allow the put is that they do not recognize the CryptoKeyPair as a &quot;CryptoKeyPair&quot; - They think it&apos;s an &quot;Object&quot;

And &quot;Objects&quot; are structured cloneable as long as each of their properties are.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1252378</commentid>
    <comment_count>8</comment_count>
    <who name="Brady Eidson">beidson</who>
    <bug_when>2016-11-17 11:46:42 -0800</bug_when>
    <thetext>(In reply to comment #7)
&gt; I believe the reason Chrome and Firefox allow the put is that they do not
&gt; recognize the CryptoKeyPair as a &quot;CryptoKeyPair&quot; - They think it&apos;s an
&gt; &quot;Object&quot;
&gt; 
&gt; And &quot;Objects&quot; are structured cloneable as long as each of their properties
&gt; 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&apos;re just an object dictionary (https://w3c.github.io/webcrypto/Overview.html#keypair), which means they are an &quot;Object&quot;, which means they are structured cloneable</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1252379</commentid>
    <comment_count>9</comment_count>
    <who name="Brady Eidson">beidson</who>
    <bug_when>2016-11-17 11:47:06 -0800</bug_when>
    <thetext>(In reply to comment #8)
&gt; (In reply to comment #7)
&gt; &gt; I believe the reason Chrome and Firefox allow the put is that they do not
&gt; &gt; recognize the CryptoKeyPair as a &quot;CryptoKeyPair&quot; - They think it&apos;s an
&gt; &gt; &quot;Object&quot;
&gt; &gt; 
&gt; &gt; And &quot;Objects&quot; are structured cloneable as long as each of their properties
&gt; &gt; are.
&gt; 
&gt; Got it.
&gt; 
&gt; At one point in the history of the spec, CryptoKeyPair objects were their
&gt; own interface, therefore their own explicit object type.
&gt; 
&gt; Now they&apos;re just an object dictionary
&gt; (https://w3c.github.io/webcrypto/Overview.html#keypair), which means they
&gt; are an &quot;Object&quot;, which means they are structured cloneable

Fixing this is just a matter of fixing our IDL situation for CryptoKeyPair.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1255869</commentid>
    <comment_count>10</comment_count>
    <who name="Brady Eidson">beidson</who>
    <bug_when>2016-12-02 13:57:35 -0800</bug_when>
    <thetext>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 ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1255933</commentid>
    <comment_count>11</comment_count>
    <who name="Jiewen Tan">jiewen_tan</who>
    <bug_when>2016-12-02 15:33:50 -0800</bug_when>
    <thetext>We need a specific hack for this as Bug 163711 will not be resolved in a short term.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1257291</commentid>
    <comment_count>12</comment_count>
    <who name="Jiewen Tan">jiewen_tan</who>
    <bug_when>2016-12-07 11:41:27 -0800</bug_when>
    <thetext>

*** This bug has been marked as a duplicate of bug 165367 ***</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>295050</attachid>
            <date>2016-11-17 08:09:49 -0800</date>
            <delta_ts>2016-11-17 08:09:49 -0800</delta_ts>
            <desc>stand alone html that shows the problem</desc>
            <filename>crypto-safari-test.html</filename>
            <type>text/html</type>
            <size>3725</size>
            <attacher name="Jason Mei">jason.mei</attacher>
            
              <data encoding="base64">PCFET0NUWVBFIGh0bWw+DQo8aHRtbCBsYW5nPSJlbiI+DQo8aGVhZD4NCiAgICA8bWV0YSBjaGFy
c2V0PSJVVEYtOCI+DQogICAgPHRpdGxlPlN0b3JlIFJTQSBrZXlwYWlyIGluIEluZGV4ZWREQjwv
dGl0bGU+DQogICAgPHNjcmlwdD4NCiAgICAgICAgdmFyIF9pZGIgPSB3aW5kb3cuaW5kZXhlZERC
Ow0KICAgICAgICB2YXIgX2RiID0gbnVsbDsNCiAgICAgICAgdmFyIF90ZXN0REIgPSAiUlNBX1Rl
c3REQiI7DQogICAgICAgIHZhciBfdGVzdFN0b3JlID0gInJzYWtleXMiOw0KDQogICAgICAgIHZh
ciBDID0gZnVuY3Rpb24oKSB7DQogICAgICAgICAgICBpZiAoIWNyeXB0bykgew0KICAgICAgICAg
ICAgICAgIGFsZXJ0KCJDcnlwdG8gbm90IHN1cHBvcnRlZCIpOw0KICAgICAgICAgICAgfQ0KICAg
ICAgICAgICAgaWYgKGNyeXB0by53ZWJraXRTdWJ0bGUpIHsNCiAgICAgICAgICAgICAgICByZXR1
cm4gY3J5cHRvLndlYmtpdFN1YnRsZTsNCiAgICAgICAgICAgIH0NCiAgICAgICAgICAgIGVsc2Ug
ew0KICAgICAgICAgICAgICAgIHJldHVybiBjcnlwdG8uc3VidGxlOw0KICAgICAgICAgICAgfQ0K
ICAgICAgICB9Ow0KDQogICAgICAgIGZ1bmN0aW9uIGdlbmVyYXRlS2V5UGFpcigpIHsNCiAgICAg
ICAgICAgIHZhciBhbGdvID0gew0KICAgICAgICAgICAgICAgIG5hbWU6ICJSU0EtT0FFUCIsDQog
ICAgICAgICAgICAgICAgbW9kdWx1c0xlbmd0aDogMjA0OCwNCiAgICAgICAgICAgICAgICBwdWJs
aWNFeHBvbmVudDogbmV3IFVpbnQ4QXJyYXkoWzB4MDEsIDB4MDAsIDB4MDFdKSwNCiAgICAgICAg
ICAgICAgICBoYXNoOiB7bmFtZTogIlNIQS0xIn0NCiAgICAgICAgICAgIH07DQoNCiAgICAgICAg
ICAgIHZhciBnZW5lcmF0ZSA9IGZ1bmN0aW9uIChyZXNvbHZlLCByZWplY3QpIHsNCiAgICAgICAg
ICAgICAgICBDKCkuZ2VuZXJhdGVLZXkoYWxnbywgZmFsc2UsIFsiZW5jcnlwdCIsICJkZWNyeXB0
Il0pLnRoZW4oZnVuY3Rpb24gKGtleVBhaXIpIHsNCiAgICAgICAgICAgICAgICAgICAgcmVzb2x2
ZShrZXlQYWlyKTsNCiAgICAgICAgICAgICAgICB9KS5jYXRjaChmdW5jdGlvbiAoZXJyb3IpIHsN
CiAgICAgICAgICAgICAgICAgICAgcmVqZWN0KGVycm9yKTsNCiAgICAgICAgICAgICAgICB9KTsN
CiAgICAgICAgICAgIH07DQogICAgICAgICAgICByZXR1cm4gbmV3IFByb21pc2UoZ2VuZXJhdGUp
Ow0KICAgICAgICB9DQoNCiAgICAgICAgZnVuY3Rpb24gb3BlbkRCKHJlc29sdmUsIHJlamVjdCkg
ew0KICAgICAgICAgICAgaWYgKF9kYikgew0KICAgICAgICAgICAgICAgIHJlc29sdmUodHJ1ZSk7
DQogICAgICAgICAgICB9DQoNCiAgICAgICAgICAgIHZhciByZXEgPSBfaWRiLm9wZW4oX3Rlc3RE
QiwgMSk7DQogICAgICAgICAgICByZXEub25zdWNjZXNzID0gZnVuY3Rpb24gKGV2ZW50KSB7DQog
ICAgICAgICAgICAgICAgX2RiID0gZXZlbnQudGFyZ2V0LnJlc3VsdDsNCiAgICAgICAgICAgICAg
ICByZXNvbHZlKHRydWUpOw0KICAgICAgICAgICAgfTsNCiAgICAgICAgICAgIHJlcS5vbmVycm9y
ID0gZnVuY3Rpb24gKCkgew0KICAgICAgICAgICAgICAgIHJlamVjdChyZXEuZXJyb3IpOw0KICAg
ICAgICAgICAgfTsNCg0KICAgICAgICAgICAgcmVxLm9uYmxvY2tlZCA9IGZ1bmN0aW9uICgpIHsN
CiAgICAgICAgICAgICAgICByZWplY3QobmV3IEVycm9yKCJEQiBpcyBibG9ja2VkLCB1bmFibGUg
dG8gb3BlbiAiKSk7DQogICAgICAgICAgICB9Ow0KDQogICAgICAgICAgICByZXEub251cGdyYWRl
bmVlZGVkID0gZnVuY3Rpb24oZXZlbnQpIHsNCiAgICAgICAgICAgICAgICBfZGIgPSBldmVudC50
YXJnZXQucmVzdWx0Ow0KICAgICAgICAgICAgICAgIHZhciBvcHRzID0gew0KICAgICAgICAgICAg
ICAgICAgICBrZXlQYXRoOiAia2V5IiwNCiAgICAgICAgICAgICAgICAgICAgYXV0b0luY3JlbWVu
dDogZmFsc2UNCiAgICAgICAgICAgICAgICB9Ow0KDQogICAgICAgICAgICAgICAgdmFyIHN0b3Jl
ID0gX2RiLmNyZWF0ZU9iamVjdFN0b3JlKF90ZXN0U3RvcmUsIG9wdHMpOw0KICAgICAgICAgICAg
ICAgIGlmICghc3RvcmUpIHsNCiAgICAgICAgICAgICAgICAgICAgLy9ub2luc3BlY3Rpb24gRXhj
ZXB0aW9uQ2F1Z2h0TG9jYWxseUpTDQogICAgICAgICAgICAgICAgICAgIHRocm93IG5ldyBFcnJv
cigiU3RvcmUgY3JlYXRpb24gcmV0dXJuZWQgbnVsbCIpOw0KICAgICAgICAgICAgICAgIH0NCiAg
ICAgICAgICAgICAgICByZXNvbHZlKHRydWUpOw0KICAgICAgICAgICAgfQ0KICAgICAgICB9DQoN
CiAgICAgICAgZnVuY3Rpb24gcHV0KGtleVBhaXIpIHsNCiAgICAgICAgICAgIHZhciBzdG9yZUtl
eVBhaXIgPSBmdW5jdGlvbihyZXNvbHZlLCByZWplY3QpIHsNCiAgICAgICAgICAgICAgICB2YXIg
dHggPSBfZGIudHJhbnNhY3Rpb24oW190ZXN0U3RvcmVdLCAicmVhZHdyaXRlIik7DQogICAgICAg
ICAgICAgICAgdHgub25jb21wbGV0ZSA9IGZ1bmN0aW9uICgpIHsNCiAgICAgICAgICAgICAgICAg
ICAgcmVzb2x2ZSh0cnVlKTsNCiAgICAgICAgICAgICAgICB9Ow0KICAgICAgICAgICAgICAgIHR4
Lm9uYWJvcnQgPSBmdW5jdGlvbiAoKSB7DQogICAgICAgICAgICAgICAgICAgIHJlamVjdCh0eC5l
cnJvcik7DQogICAgICAgICAgICAgICAgfTsNCiAgICAgICAgICAgICAgICB0eC5vbmVycm9yID0g
ZnVuY3Rpb24gKCkgew0KICAgICAgICAgICAgICAgICAgICByZWplY3QodHguZXJyb3IpOw0KICAg
ICAgICAgICAgICAgIH07DQoNCiAgICAgICAgICAgICAgICB2YXIgc3RvcmUgPSB0eC5vYmplY3RT
dG9yZShfdGVzdFN0b3JlKTsNCiAgICAgICAgICAgICAgICBrZXlQYWlyLmtleT0xOw0KICAgICAg
ICAgICAgICAgIC8qcmV0dXJuIHN0b3JlLnB1dCh7DQogICAgICAgICAgICAgICAgICAgIGtleSA6
IDEsDQogICAgICAgICAgICAgICAgICAgIHB1YmtleSA6IGtleVBhaXIucHVibGljS2V5LA0KICAg
ICAgICAgICAgICAgICAgICBwcml2a2V5IDoga2V5UGFpci5wcml2YXRlS2V5DQogICAgICAgICAg
ICAgICAgfSk7Ki8NCg0KICAgICAgICAgICAgICAgIHJldHVybiBzdG9yZS5wdXQoa2V5UGFpcik7
DQogICAgICAgICAgICB9Ow0KDQogICAgICAgICAgICByZXR1cm4gbmV3IFByb21pc2Uoc3RvcmVL
ZXlQYWlyKTsNCiAgICAgICAgfQ0KDQogICAgICAgIGZ1bmN0aW9uIHRlc3QoKSB7DQogICAgICAg
ICAgICByZXR1cm4gbmV3IFByb21pc2Uob3BlbkRCKS50aGVuKGZ1bmN0aW9uKCkgew0KICAgICAg
ICAgICAgICAgIHJldHVybiBnZW5lcmF0ZUtleVBhaXIoKTsNCiAgICAgICAgICAgIH0pLnRoZW4o
ZnVuY3Rpb24oa2V5cGFpcikgew0KICAgICAgICAgICAgICAgIHJldHVybiBwdXQoa2V5cGFpcik7
DQogICAgICAgICAgICB9KS50aGVuKGZ1bmN0aW9uKCkgew0KICAgICAgICAgICAgICAgIGFsZXJ0
KCJ3b3JrcyEiKTsNCiAgICAgICAgICAgIH0pLmNhdGNoKGZ1bmN0aW9uKGVycm9yKSB7DQogICAg
ICAgICAgICAgICAgYWxlcnQoImZhaWxzIHdpdGggZXJyb3IgIiArIChlcnJvciA/IGVycm9yLm1l
c3NhZ2UgfHwgZXJyb3IubmFtZSB8fCBlcnJvciA6ICIodW5rbm93bikiKSk7DQogICAgICAgICAg
ICB9KTsNCiAgICAgICAgfQ0KICAgIDwvc2NyaXB0Pg0KPC9oZWFkPg0KPGJvZHk+DQo8YnV0dG9u
IGlkPSJ0ZXN0IiBvbmNsaWNrPSJ0ZXN0KCkiPlRlc3QgUlNBIGFuZCBJbmRleGVkREI8L2J1dHRv
bj4NCjwvYm9keT4NCjwvaHRtbD4=
</data>

          </attachment>
      

    </bug>

</bugzilla>