Unverified Commit 56062362 authored by ggrund-tsi's avatar ggrund-tsi Committed by GitHub
Browse files

set cert expiration from service or recovery (#85)


Co-authored-by: default avatarGordon Grund <gordon.grund@outlook.de>
parent 648f8705
......@@ -42,6 +42,7 @@ import { PersonInputs, IPersonData, FormGroupInput, FormGroupValueSetSelect, For
import CardFooter from './modules/card-footer.component';
const validator = new Validator();
const expirationMilSeconds = 60 * 60 * 24 * 180 * 1000;
const RecordRecoveryCertData = (props: any) => {
......@@ -207,7 +208,7 @@ const RecordRecoveryCertData = (props: any) => {
<hr />
{/* Date of First Positive Test Result */}
<Form.Group as={Row} controlId='formLastDateInput'className='pb-3 mb-0'>
<Form.Group as={Row} controlId='formLastDateInput' className='pb-3 mb-0'>
<Form.Label className='input-label ' column xs='5' sm='3'>{t('translation:first-positive-test-date') + '*'}</Form.Label>
<Col xs='7' sm='9' className='d-flex'>
......@@ -248,7 +249,7 @@ const RecordRecoveryCertData = (props: any) => {
/>
{/* Date: Certificate Valid From - To */}
<Form.Group as={Row} controlId='formDateOfBirthInput'className='pb-3 mb-0'>
<Form.Group as={Row} controlId='formDateOfBirthInput' className='pb-3 mb-0'>
<Form.Label className='input-label ' column xs='5' sm='3'>{t('translation:cert-valid-from-to') + '*'}</Form.Label>
<Col xs='7' sm='9' className='d-flex'>
......@@ -264,8 +265,8 @@ const RecordRecoveryCertData = (props: any) => {
showYearDropdown
dropdownMode="select"
//TODO: possibly calculate dat min and max
maxDate={new Date()}
minDate={new Date(2020, 10)}
maxDate={dateValidTo ? dateValidTo : new Date()}
minDate={dateValidTo ? new Date(dateValidTo.getTime() - expirationMilSeconds) : new Date(Date.now() - expirationMilSeconds)}
openToDate={new Date()}
required
/>
......@@ -282,8 +283,8 @@ const RecordRecoveryCertData = (props: any) => {
showYearDropdown
dropdownMode="select"
//TODO: calculate date min and max
maxDate={new Date(2099, 12)}
minDate={new Date()}
maxDate={dateValidFrom ? new Date(dateValidFrom.getTime() + expirationMilSeconds) : new Date(Date.now() + expirationMilSeconds)}
minDate={dateValidFrom ? dateValidFrom : new Date()}
openToDate={new Date()}
required
/>
......
......@@ -24,9 +24,8 @@ import base45 from './wbase45'
import CryptoJS from 'crypto-js';
import zlib from 'browserify-zlib'
import { EUDGC } from '../generated-files/dgc-combined-schema';
const expiredSeconds = 60 * 60 * 24 * 364;
const edgcPrefix = 'HC1:'
export interface CertificateMetaData {
......@@ -43,13 +42,14 @@ export interface SignService {
(hash: string): Promise<string>;
}
const encodeCBOR = (certData: any, certMetaData: CertificateMetaData): Buffer => {
const encodeCBOR = (certData: EUDGC, certMetaData: CertificateMetaData): Buffer => {
const cborMap = new cbor.Map();
const issuedAtSec = Date.now() / 1000 | 0;
const expiration = getExpiration(certData, certMetaData);
// expiration
cborMap.set((4 as number), issuedAtSec + expiredSeconds);
cborMap.set((4 as number), expiration);
// issued at
cborMap.set((6 as number), issuedAtSec);
// issuer country code
......@@ -61,6 +61,16 @@ const encodeCBOR = (certData: any, certMetaData: CertificateMetaData): Buffer =>
return cbor.encodeOne(cborMap, { omitUndefinedProperties: true });
}
const getExpiration = (certData: EUDGC, certMetaData: CertificateMetaData) => {
let result = certMetaData.expired;
if (certData && certData.r && certData.r[0]) {
result = new Date(certData.r[0].du).getTime() / 1000 | 0;
}
return result;
}
const computeCOSEHash = (coseSigData: Buffer): string => {
// console.log("data to sig: "+coseSigData.toString('base64'));
const wordArray = CryptoJS.lib.WordArray.create((coseSigData as unknown) as number[]);
......@@ -115,7 +125,7 @@ const dataPrefix = (data: string): string => {
}
export const createCertificateQRData = (certData: any, certMetaData: CertificateMetaData, signService: SignService): Promise<string> => {
export const createCertificateQRData = (certData: EUDGC, certMetaData: CertificateMetaData, signService: SignService): Promise<string> => {
let cbor = encodeCBOR(certData, certMetaData);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment