Skip to content

Commit 3ba765b

Browse files
authored
Fix false positive in supports (#14)
Fix the case when e.g. `supports('deriveKey', 'PBKDF2', 'HKDF')` returns true because the length parameter from the "get key length" operation of HKDF (which returns null, which causes the "deriveKey" operation of PBKDF2 to throw) is not available. (The same is true for other combinations of PBKDF2 and HKDF.)
1 parent f655363 commit 3ba765b

File tree

1 file changed

+45
-30
lines changed

1 file changed

+45
-30
lines changed

index.html

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -772,16 +772,12 @@ <h4>The supports method</h4>
772772
</li>
773773
<li>
774774
<dl class="switch">
775-
<dt>If |operation| is "`deriveKey`":</dt>
775+
<dt>If |operation| is "`deriveKey`", "`unwrapKey`", "`encapsulateKey`" or "`decapsulateKey`":</dt>
776776
<dd>
777777
<p>
778778
If the result of [= check support for an algorithm | checking support for an algorithm =]
779779
with `op` set to "`importKey`"
780780
and `alg` set to |additionalAlgorithm|
781-
is false, or
782-
the result of [= check support for an algorithm | checking support for an algorithm =]
783-
with `op` set to "`get key length`"
784-
and `alg` set to |additionalAlgorithm|
785781
is false,
786782
return false.
787783
</p>
@@ -796,32 +792,56 @@ <h4>The supports method</h4>
796792
return false.
797793
</p>
798794
</dd>
799-
<dt>If |operation| is "`unwrapKey`":</dt>
800-
<dd>
801-
<p>
802-
If the result of [= check support for an algorithm | checking support for an algorithm =]
803-
with `op` set to "`importKey`"
804-
and `alg` set to |additionalAlgorithm|
805-
is false,
806-
return false.
807-
</p>
808-
</dd>
809-
<dt>If |operation| is "`encapsulateKey`" or "`decapsulateKey`":</dt>
795+
</dl>
796+
</li>
797+
<li>
798+
<p>
799+
Let |length| be null.
800+
</p>
801+
</li>
802+
<li>
803+
<dl class="switch">
804+
<dt>If |operation| is "`deriveKey`":</dt>
810805
<dd>
811-
<p>
812-
If the result of [= check support for an algorithm | checking support for an algorithm =]
813-
with `op` set to "`importKey`"
814-
and `alg` set to |additionalAlgorithm|
815-
is false,
816-
return false.
817-
</p>
806+
<ol>
807+
<li>
808+
<p>
809+
If the result of [= check support for an algorithm | checking support for an algorithm =]
810+
with `op` set to "`get key length`"
811+
and `alg` set to |additionalAlgorithm|
812+
is false,
813+
return false.
814+
</p>
815+
</li>
816+
<li>
817+
<p>
818+
Let |normalizedAdditionalAlgorithm| be the result of
819+
<a data-cite="webcrypto#dfn-normalize-an-algorithm">normalizing an algorithm</a>, with
820+
`alg` set to |additionalAlgorithm| and `op` set to
821+
"`get key length`".
822+
</p>
823+
</li>
824+
<li>
825+
<p>
826+
Let |length| be the result of performing the get key length
827+
algorithm specified by |additionalAlgorithm| using
828+
|normalizedAdditionalAlgorithm|.
829+
</p>
830+
</li>
831+
<li>
832+
<p>
833+
Set |operation| to "`deriveBits`".
834+
</p>
835+
</li>
836+
</ol>
818837
</dd>
819838
</dl>
820839
</li>
821840
<li>
822841
<p>
823842
Return the result of [= check support for an algorithm | checking support for an algorithm =],
824-
with `op` set to |operation| and `alg` set to |algorithm|.
843+
with `op` set to |operation|, `alg` set to |algorithm|,
844+
and `length` set to |length|.
825845
</p>
826846
</li>
827847
</ol>
@@ -834,15 +854,10 @@ <h3>Checking support for an algorithm</h3>
834854
The <dfn id="dfn-check-support-for-algorithm">check support for an algorithm</dfn> algorithm
835855
defines a process for checking whether the given algorithm is supported for the given operation.
836856
Its input is an operation name |op|, an {{AlgorithmIdentifier}} |alg|,
837-
and an optional |length| parameter. Its output is a boolean.
857+
and a |length| parameter. Its output is a boolean.
838858
It behaves as follows:
839859
</p>
840860
<ol>
841-
<li>
842-
<p>
843-
If |op| is "`deriveKey`", set |op| to "`deriveBits`".
844-
</p>
845-
</li>
846861
<li>
847862
<p>
848863
If |op| is "`encapsulateKey`" or "`encapsulateBits`", set |op| is "`encapsulate`".

0 commit comments

Comments
 (0)