Skip to content

Commit

Permalink
Add function extractSignature with jose utility generate_key_pair #11
Browse files Browse the repository at this point in the history
Signed-off-by: Sarah Julia Kriesch <sarah.j.kriesch@fau.de>
  • Loading branch information
skriesch committed Jun 28, 2022
1 parent a041e9e commit 05827c1
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/token/token.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as qs from 'qs';
import { DiscoveryService } from '../discovery/discovery.service';
import * as fs from 'fs';
import { GetKeyFunction } from 'jose/dist/types/types';
import { generateKeyPair } from 'jose/util/generate_key_pair';
import { SettingsService } from '../settings/settings.service';
import { HelperService } from '../helper/helper.service';

Expand Down Expand Up @@ -152,7 +153,8 @@ export class TokenService {

const header = this.decodeBase64EncodedString(tokenParts[0]);
const body = this.decodeBase64EncodedString(tokenParts[1]);
const signature = this.decodeBase64EncodedString(tokenParts[2]);
const signature = this.extractSignature(tokenParts[2]);


return [header, body, signature];
}
Expand All @@ -161,6 +163,26 @@ export class TokenService {
return JSON.parse(new TextDecoder().decode(jose.base64url.decode(input)));
}

private async extractSignature(
algorithm: string,
filepath: string,
publicKey: KeyObject,
privateKey: KeyObject
): Promise<GenerateKeyPairResult> {
let message = '';
let isValid = true;
try {
const keyMaterial = await this.getFileKeyMaterial (algorithm, filepath);
const { publicKey, privateKey } = await generateKeyPair(keyMaterial.algorithm);

return [algorithm, privateKey, publicKey];
} catch (error) {
isValid = false;
message = `The signature is invalid: ${error}`;
}

}

private async validateTokenStringWithExternalKeys(
tokenString: string,
issuer: string,
Expand Down

0 comments on commit 05827c1

Please sign in to comment.