diff --git a/src/components/record-recovery-cert-data.component.tsx b/src/components/record-recovery-cert-data.component.tsx
index ab6f5f3..3dd4bc6 100644
--- a/src/components/record-recovery-cert-data.component.tsx
+++ b/src/components/record-recovery-cert-data.component.tsx
@@ -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) => {
{/* Date of First Positive Test Result */}
-
+
{t('translation:first-positive-test-date') + '*'}
@@ -248,7 +249,7 @@ const RecordRecoveryCertData = (props: any) => {
/>
{/* Date: Certificate Valid From - To */}
-
+
{t('translation:cert-valid-from-to') + '*'}
@@ -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
/>
diff --git a/src/misc/edgcProcessor.tsx b/src/misc/edgcProcessor.tsx
index ac8600b..8cd608d 100644
--- a/src/misc/edgcProcessor.tsx
+++ b/src/misc/edgcProcessor.tsx
@@ -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;
}
-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 => {
+export const createCertificateQRData = (certData: EUDGC, certMetaData: CertificateMetaData, signService: SignService): Promise => {
let cbor = encodeCBOR(certData, certMetaData);