improve signature structure, more tests
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2020-12-13 13:37:11 +01:00
parent 68c06b6742
commit 170eb8a743
7 changed files with 118 additions and 24 deletions

View File

@ -1,3 +1,10 @@
/*
* Copyright (C) Sapphirecode - All Rights Reserved
* This file is part of Auth-Server-Helper which is released under MIT.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, December 2020
*/
interface Signature {
hash: string;
iat: Date;

View File

@ -1,7 +1,11 @@
import {
get_signature_info,
verify_signature
} from '@sapphirecode/crypto-helper';
/*
* Copyright (C) Sapphirecode - All Rights Reserved
* This file is part of Auth-Server-Helper which is released under MIT.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, December 2020
*/
import { verify_signature_get_info } from '@sapphirecode/crypto-helper';
import { run_regex } from '@sapphirecode/utilities';
import keystore from './KeyStore';
import blacklist from './Blacklist';
@ -38,6 +42,8 @@ class GatewayClass {
}
private get_cookie_auth (req: Request): string | null {
if (typeof this._options.cookie_name === 'undefined')
return null;
let auth = null;
run_regex (
/[\^;](?<name>[^;=]+)=(?<value>[^;]+)/gu,
@ -57,17 +63,15 @@ class GatewayClass {
if (auth === null)
return false;
const data = get_signature_info (auth);
const key = keystore.get_key (data.iat / 1000);
const valid = verify_signature (
const data = verify_signature_get_info (
auth,
key,
data.obj.valid_for * 1000
) === null;
(info) => keystore.get_key (info.iat),
(info) => info.valid_for * 1000
);
return valid
&& data.obj.type === 'access_token'
&& blacklist.is_valid (data.obj.id);
return data !== null
&& data.type === 'access_token'
&& blacklist.is_valid (data.id);
}
public process_request (

View File

@ -1,3 +1,10 @@
/*
* Copyright (C) Sapphirecode - All Rights Reserved
* This file is part of Auth-Server-Helper which is released under MIT.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, December 2020
*/
import { create_salt } from '@sapphirecode/crypto-helper';
class KeyStore {