Skip to content

Commit

Permalink
set cert expiration from service or recovery (#85)
Browse files Browse the repository at this point in the history
Co-authored-by: Gordon Grund <[email protected]>
  • Loading branch information
ggrund-tsi and ggrund-tsi authored Jun 2, 2021
1 parent 648f870 commit 5606236
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
13 changes: 7 additions & 6 deletions src/components/record-recovery-cert-data.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {

Expand Down Expand Up @@ -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'>
Expand Down Expand Up @@ -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'>
Expand All @@ -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
/>
Expand All @@ -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
/>
Expand Down
20 changes: 15 additions & 5 deletions src/misc/edgcProcessor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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[]);
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 5606236

Please sign in to comment.