<?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>196181</bug_id>
          
          <creation_ts>2019-03-23 16:22:20 -0700</creation_ts>
          <short_desc>crypto.subtle.importKey fails for for RSA keys with p &lt; q</short_desc>
          <delta_ts>2022-02-12 22:48:44 -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>WebKit Misc.</component>
          <version>Safari 12</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>WONTFIX</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Major</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Soma Lucz">webkit-bugzilla</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>bfulgham</cc>
    
    <cc>jiewen_tan</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1520640</commentid>
    <comment_count>0</comment_count>
    <who name="Soma Lucz">webkit-bugzilla</who>
    <bug_when>2019-03-23 16:22:20 -0700</bug_when>
    <thetext>In Safari 12 crypto.subtle.importKey fails for RSA keys with p &lt; q. Although generating such keys is against conventions and the efficiency of the CRT application, it is not invalid. Microsoft Edge generates such keys in ~50% of the time.

This is a very inconvenient issue for web applications relying on RSA cryptography used in a cross-browser environment.

Example good key (with p &gt; q, importKey succeeds in Safari):

const goodKey = {
  n: &quot;wOwKgOpYOpKmVUd8XA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,
  dp: &quot;ypiEwyiJWYlMh246zi_6HB1b53KYJEPd5T2Ayx0h_M7-8jSLTPsYMzY3iMvyJGzDpJ81p2kNMvgsY7ra_1O4KhjAtRyV5keHk2RAKKBHofncz7AfTMpCnftZ3NDbCCm6Xg5YRZdy-PldFsb4C6Ex8E8h7OAEYH3deoaAf6OnYbE&quot;,
  dq: &quot;jmsr6mI_9qhfKMo9PUbDD9ksI9OxHNQmCfH1Rn2ydLfEgcrTuATGdnC8JuAKieTahjH_J7fauA8wrh9tVwe1NOpaay7b532yGFxjo__ChT4JEzsR_ePyO17tfBSbIzUlnqgIHbWwXcKgeYPR3KdxZQ7qO3vQGJKO2IOpMZfVmrs&quot;,
  qi: &quot;ISX6LmvGioKbqgek9vy85DyFEdd_2Xksxg1MBcIOOlaCEydqShgZ2DtQ-ORHGk2D7apH44NvicPfPrAUS5Cbdo1xFnjgQT6LGAzqzQ7Y01SSxFQJIUXWaEGj5m8LVa8xa8PE6plGsIGCX9RL5aQDssc4CYn8YuDacsHca_--JUY&quot;,
  kty: &quot;RSA&quot;
};
crypto.subtle
  .importKey(
    &quot;jwk&quot;,
    goodKey,
    { name: &quot;RSA-OAEP&quot;, hash: { name: &quot;SHA-1&quot; } },
    false,
    [&quot;decrypt&quot;]
  )
  .then(() =&gt; console.log(&quot;goodKey success&quot;))
  .catch(() =&gt; console.log(&quot;goodKey error&quot;));

Example bad key (with p &lt; q, importKey fails in Safari):

const badKey = {
  n: &quot;0ZsZ2wOsJfDReOnhGvv2aphndsGYem9-L9hf4ALARZTfePkZbUQwk_z97HnA1UhBz-70kf1kTRPsO1MEtlFh2l2YVhZP6TQ13mKQpwMNoqN8E3BchvZQvSX-GhR1NxHOgFPvEF9q98ruXOvzhz4LCFgMR2SyGQopUPPpEiMsWO91YUyTwsw02gW_l5BcBis0r1xT3I0V9KEs8DMvBfOqnLeQLwzJ7lCXS-_uirTUyfe_VfMuVMIXDuAdVkcQR8YYm44ySmC-N5e2tmBNT8xc6dRizydS_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n5Z3PdNrEoMK9mQnRXloX3ImfGSYpIUf6cQTtYGtPPf-AkfZXtoIt5XVhYHuV3-Q57GHCop62jD_RK_miVQsy9ML28PE&quot;,
  qi: &quot;KcfzhX3UaSnJfeMg1rG5UBw6y9SG7WM78jmjaaGB4y9tfhiYXska8mG3yh2ahnia8qUDh5y3ZQ8iSD6Cnk2yPql0XxnTb-HBv5SKL2kESGd5PawaET5qABrGkHN4P-bNlWYDQF_VjL-9DxZB6sPgIsTNSaqjGeFCX8Cvqj57KXk&quot;,
  kty: &quot;RSA&quot;
};
crypto.subtle
  .importKey(
    &quot;jwk&quot;,
    badKey,
    { name: &quot;RSA-OAEP&quot;, hash: { name: &quot;SHA-1&quot; } },
    false,
    [&quot;decrypt&quot;]
  )
  .then(() =&gt; console.log(&quot;badKey success&quot;))
  .catch(() =&gt; console.log(&quot;badKey error&quot;));

Running the above two in Safari, I get:

goodKey success
badKey error

The symmetric Microsoft Edge bug I submitted: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/20950190/

Please sort this out in a way that makes the two browsers compatible in this matter.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1521015</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2019-03-25 14:21:00 -0700</bug_when>
    <thetext>&lt;rdar://problem/49228962&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1521027</commentid>
    <comment_count>2</comment_count>
    <who name="Jiewen Tan">jiewen_tan</who>
    <bug_when>2019-03-25 14:28:59 -0700</bug_when>
    <thetext>CommonCrypto is investigating this bug. CommonCrypto is the crypto services WebKit&apos;s WebCrypto API calls.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1840951</commentid>
    <comment_count>3</comment_count>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2022-02-12 22:48:44 -0800</bug_when>
    <thetext>Note: This implementation is in a different OS component, which has this fix now.

No WebKit Changes will be made for this issue.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>