Skip to content

Commit

Permalink
fix: issue with sha256 and prod build #1120
Browse files Browse the repository at this point in the history
  • Loading branch information
manfredsteyer committed Aug 24, 2021
1 parent 2a9ec6a commit b44e19a
Show file tree
Hide file tree
Showing 12 changed files with 227 additions and 38 deletions.
38 changes: 31 additions & 7 deletions docs/classes/HashHandler.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ <h3 id="methods">

<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="11"
class="link-to-prism">projects/lib/src/token-validation/hash-handler.ts:11</a></div>
<div class="io-line">Defined in <a href="" data-line="12"
class="link-to-prism">projects/lib/src/token-validation/hash-handler.ts:12</a></div>
</td>
</tr>

Expand Down Expand Up @@ -207,28 +207,52 @@ <h3 id="methods">
<pre class="line-numbers compodoc-sourcecode"><code class="language-typescript">import { Injectable } from &#x27;@angular/core&#x27;;

import { factory } from &#x27;./js-sha256&#x27;;

const sha256 &#x3D; factory();

import fsha256 from &#x27;fast-sha256&#x27;;

/**
* Abstraction for crypto algorithms
*/
export abstract class HashHandler {
abstract calcHash(valueToHash: string, algorithm: string): Promise&lt;string&gt;;
}

function decodeUTF8(s) {
if (typeof s !&#x3D;&#x3D; &#x27;string&#x27;) throw new TypeError(&#x27;expected string&#x27;);
var i,
d &#x3D; s,
b &#x3D; new Uint8Array(d.length);
for (i &#x3D; 0; i &lt; d.length; i++) b[i] &#x3D; d.charCodeAt(i);
return b;
}

function encodeUTF8(arr) {
var i,
s &#x3D; [];
for (i &#x3D; 0; i &lt; arr.length; i++) s.push(String.fromCharCode(arr[i]));
return s.join(&#x27;&#x27;);
}

@Injectable()
export class DefaultHashHandler implements HashHandler {
async calcHash(valueToHash: string, algorithm: string): Promise&lt;string&gt; {
// const encoder &#x3D; new TextEncoder();
// const hashArray &#x3D; await window.crypto.subtle.digest(algorithm, data);
// const data &#x3D; encoder.encode(valueToHash);

const hashArray &#x3D; (sha256 as any).array(valueToHash);
// const hashString &#x3D; this.toHashString(hashArray);
const hashString &#x3D; this.toHashString2(hashArray);
// const fhash &#x3D; fsha256(valueToHash);

const candHash &#x3D; encodeUTF8(fsha256(decodeUTF8(valueToHash)));

// const hashArray &#x3D; (sha256 as any).array(valueToHash);
// // const hashString &#x3D; this.toHashString(hashArray);
// const hashString &#x3D; this.toHashString2(hashArray);

// console.debug(&#x27;hash orig - cand&#x27;, candHash, hashString);
// alert(1);

return hashString;
return candHash;
}

toHashString2(byteArray: number[]) {
Expand Down
2 changes: 2 additions & 0 deletions docs/dependencies.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
<b>base64-js</b> : ^1.5.1</li>
<li>
<b>bootstrap</b> : ^3.4.1</li>
<li>
<b>fast-sha256</b> : ^1.3.0</li>
<li>
<b>jsrsasign</b> : ^10.3.0</li>
<li>
Expand Down
46 changes: 35 additions & 11 deletions docs/injectables/DefaultHashHandler.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ <h3 id="methods">

<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="16"
class="link-to-prism">projects/lib/src/token-validation/hash-handler.ts:16</a></div>
<div class="io-line">Defined in <a href="" data-line="33"
class="link-to-prism">projects/lib/src/token-validation/hash-handler.ts:33</a></div>
</td>
</tr>

Expand Down Expand Up @@ -207,8 +207,8 @@ <h3 id="methods">

<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="36"
class="link-to-prism">projects/lib/src/token-validation/hash-handler.ts:36</a></div>
<div class="io-line">Defined in <a href="" data-line="60"
class="link-to-prism">projects/lib/src/token-validation/hash-handler.ts:60</a></div>
</td>
</tr>

Expand Down Expand Up @@ -275,8 +275,8 @@ <h3 id="methods">

<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="28"
class="link-to-prism">projects/lib/src/token-validation/hash-handler.ts:28</a></div>
<div class="io-line">Defined in <a href="" data-line="52"
class="link-to-prism">projects/lib/src/token-validation/hash-handler.ts:52</a></div>
</td>
</tr>

Expand Down Expand Up @@ -332,28 +332,52 @@ <h3 id="methods">
<pre class="line-numbers compodoc-sourcecode"><code class="language-typescript">import { Injectable } from &#x27;@angular/core&#x27;;

import { factory } from &#x27;./js-sha256&#x27;;

const sha256 &#x3D; factory();

import fsha256 from &#x27;fast-sha256&#x27;;

/**
* Abstraction for crypto algorithms
*/
export abstract class HashHandler {
abstract calcHash(valueToHash: string, algorithm: string): Promise&lt;string&gt;;
}

function decodeUTF8(s) {
if (typeof s !&#x3D;&#x3D; &#x27;string&#x27;) throw new TypeError(&#x27;expected string&#x27;);
var i,
d &#x3D; s,
b &#x3D; new Uint8Array(d.length);
for (i &#x3D; 0; i &lt; d.length; i++) b[i] &#x3D; d.charCodeAt(i);
return b;
}

function encodeUTF8(arr) {
var i,
s &#x3D; [];
for (i &#x3D; 0; i &lt; arr.length; i++) s.push(String.fromCharCode(arr[i]));
return s.join(&#x27;&#x27;);
}

@Injectable()
export class DefaultHashHandler implements HashHandler {
async calcHash(valueToHash: string, algorithm: string): Promise&lt;string&gt; {
// const encoder &#x3D; new TextEncoder();
// const hashArray &#x3D; await window.crypto.subtle.digest(algorithm, data);
// const data &#x3D; encoder.encode(valueToHash);

const hashArray &#x3D; (sha256 as any).array(valueToHash);
// const hashString &#x3D; this.toHashString(hashArray);
const hashString &#x3D; this.toHashString2(hashArray);
// const fhash &#x3D; fsha256(valueToHash);

const candHash &#x3D; encodeUTF8(fsha256(decodeUTF8(valueToHash)));

// const hashArray &#x3D; (sha256 as any).array(valueToHash);
// // const hashString &#x3D; this.toHashString(hashArray);
// const hashString &#x3D; this.toHashString2(hashArray);

// console.debug(&#x27;hash orig - cand&#x27;, candHash, hashString);
// alert(1);

return hashString;
return candHash;
}

toHashString2(byteArray: number[]) {
Expand Down
4 changes: 2 additions & 2 deletions docs/js/search/search_index.js

Large diffs are not rendered by default.

110 changes: 110 additions & 0 deletions docs/miscellaneous/functions.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ <h3 id="index">Index</h3>
<li>
<a href="#createDefaultStorage" title="projects/lib/src/factories.ts" ><b>createDefaultStorage</b>&nbsp;&nbsp;&nbsp;(projects/.../factories.ts)</a>
</li>
<li>
<a href="#decodeUTF8" title="projects/lib/src/token-validation/hash-handler.ts" ><b>decodeUTF8</b>&nbsp;&nbsp;&nbsp;(projects/.../hash-handler.ts)</a>
</li>
<li>
<a href="#encodeUTF8" title="projects/lib/src/token-validation/hash-handler.ts" ><b>encodeUTF8</b>&nbsp;&nbsp;&nbsp;(projects/.../hash-handler.ts)</a>
</li>
</ul>
</td>
</tr>
Expand Down Expand Up @@ -232,6 +238,110 @@ <h3></h3> <table class="table table-sm table-bordered">



</tbody>
</table>
</section> <h3>projects/lib/src/token-validation/hash-handler.ts</h3>
<section>
<h3></h3> <table class="table table-sm table-bordered">
<tbody>
<tr>
<td class="col-md-4">
<a name="decodeUTF8"></a>
<span class="name">
<span ><b>decodeUTF8</b></span>
<a href="#decodeUTF8"><span class="icon ion-ios-link"></span></a>
</span>
</td>
</tr>
<tr>
<td class="col-md-4">
<code>decodeUTF8(s)</code>
</td>
</tr>




<tr>
<td class="col-md-4">

<div class="io-description">
<b>Parameters :</b>
<table class="params">
<thead>
<tr>
<td>Name</td>
<td>Optional</td>
</tr>
</thead>
<tbody>
<tr>
<td>s</td>

<td>
No
</td>


</tr>
</tbody>
</table>
</div>
<div>
</div>
</td>
</tr>
</tbody>
</table>
<table class="table table-sm table-bordered">
<tbody>
<tr>
<td class="col-md-4">
<a name="encodeUTF8"></a>
<span class="name">
<span ><b>encodeUTF8</b></span>
<a href="#encodeUTF8"><span class="icon ion-ios-link"></span></a>
</span>
</td>
</tr>
<tr>
<td class="col-md-4">
<code>encodeUTF8(arr)</code>
</td>
</tr>




<tr>
<td class="col-md-4">

<div class="io-description">
<b>Parameters :</b>
<table class="params">
<thead>
<tr>
<td>Name</td>
<td>Optional</td>
</tr>
</thead>
<tbody>
<tr>
<td>arr</td>

<td>
No
</td>


</tr>
</tbody>
</table>
</div>
<div>
</div>
</td>
</tr>
</tbody>
</table>
</section>
Expand Down
7 changes: 6 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"angular-oauth2-oidc-jwks": "^9.0.0",
"base64-js": "^1.5.1",
"bootstrap": "^3.4.1",
"fast-sha256": "^1.3.0",
"jsrsasign": "^10.3.0",
"ngx-semantic-version": "^2.3.0",
"rxjs": "^6.5.3",
Expand Down
2 changes: 1 addition & 1 deletion projects/lib/ng-package.prod.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"entryFile": "src/public_api.ts"
},
"allowedNonPeerDependencies": [
"js-sha256"
"js-sha256", "fast-sha256"
]
}
5 changes: 3 additions & 2 deletions projects/lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
"author": {
"name": "Manfred Steyer"
},
"version": "12.0.2-issue.1120",
"version": "12.0.2-issue.1120.2",
"repository": "manfredsteyer/angular-oauth2-oidc",
"peerDependencies": {
"@angular/common": ">=12.0.0",
"@angular/core": ">=12.0.0"
},
"dependencies": {
"tslib": "^2.0.0"
"tslib": "^2.0.0",
"fast-sha256": "^1.3.0"
}
}
Loading

0 comments on commit b44e19a

Please sign in to comment.