-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from hauketoenjes/main
Transition to C# backend
- Loading branch information
Showing
7 changed files
with
104 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export default function handler(req, res) { | ||
// Return the API_BASE_URL. This Endpoint allows us to access the env Variable in client javascript | ||
res.status(200).json({ apiBaseUrl: process.env.API_BASE_URL }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
exports.BASE_URL = 'https://raw.githubusercontent.com/ehn-dcc-development/ehn-dcc-valuesets/main/' | ||
exports.API_BASE_URL = 'https://api.covidpass.marvinsextro.de/' | ||
exports.VALUE_SET_BASE_URL = 'https://raw.githubusercontent.com/ehn-dcc-development/ehn-dcc-valuesets/main/' | ||
exports.VALUE_TYPES = { | ||
medicalProducts: 'vaccine-medicinal-product.json', | ||
countryCodes: 'country-2-codes.json', | ||
manufacturers: 'vaccine-mah-manf.json', | ||
medicalProducts: 'vaccine-medicinal-product.json', | ||
countryCodes: 'country-2-codes.json', | ||
manufacturers: 'vaccine-mah-manf.json', | ||
} | ||
exports.COLORS = { | ||
white: 'rgb(255, 255, 255)', | ||
black: 'rgb(0, 0, 0)', | ||
grey: 'rgb(33, 33, 33)', | ||
green: 'rgb(27, 94, 32)', | ||
indigo: 'rgb(26, 35, 126)', | ||
blue: 'rgb(1, 87, 155)', | ||
purple: 'rgb(74, 20, 140)', | ||
teal: 'rgb(0, 77, 64)', | ||
white: 'rgb(255, 255, 255)', | ||
black: 'rgb(0, 0, 0)', | ||
grey: 'rgb(33, 33, 33)', | ||
green: 'rgb(27, 94, 32)', | ||
indigo: 'rgb(26, 35, 126)', | ||
blue: 'rgb(1, 87, 155)', | ||
purple: 'rgb(74, 20, 140)', | ||
teal: 'rgb(0, 77, 64)', | ||
} | ||
exports.NAME = 'CovidPass' | ||
exports.PASS_IDENTIFIER = 'pass.de.marvinsextro.covidpass' // WELL KNOWN | ||
exports.TEAM_IDENTIFIER = 'X8Q7Q2RLTD' // WELL KNOWN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,37 @@ | ||
'use strict'; | ||
|
||
const consts = require('./constants') | ||
const constants = require('./constants') | ||
const utils = require('./utils') | ||
const img = require('./img') | ||
|
||
const { Payload } = require('./payload') | ||
const { toBuffer } = require('do-not-zip') | ||
const crypto = require('crypto') | ||
|
||
exports.createPass = async function(data) { | ||
async function getJSONfromURL(url) { | ||
return await (await fetch(url)).json() | ||
} | ||
|
||
function getBufferHash(buffer) { | ||
// creating hash | ||
const sha = crypto.createHash('sha1'); | ||
sha.update(buffer); | ||
return sha.digest('hex'); | ||
} | ||
|
||
async function signPassWithRemote(pass, payload) { | ||
// From pass-js | ||
// https://github.com/walletpass/pass-js/blob/2b6475749582ca3ea742a91466303cb0eb01a13a/src/pass.ts | ||
|
||
// Creating new Zip file | ||
const zip = [] | ||
|
||
// Adding required files | ||
// Create pass.json | ||
zip.push({ path: 'pass.json', data: Buffer.from(JSON.stringify(pass)) }) | ||
|
||
const passHash = getBufferHash(Buffer.from(JSON.stringify(pass))) | ||
|
||
zip.push({ path: 'icon.png', data: payload.img1x }) | ||
zip.push({ path: '[email protected]', data: payload.img2x }) | ||
zip.push({ path: 'logo.png', data: payload.img1x }) | ||
zip.push({ path: '[email protected]', data: payload.img2x }) | ||
|
||
// adding manifest | ||
// Construct manifest here | ||
const manifestJson = JSON.stringify( | ||
|
@@ -48,30 +44,34 @@ exports.createPass = async function(data) { | |
), | ||
); | ||
zip.push({ path: 'manifest.json', data: manifestJson }); | ||
|
||
const response = await fetch(consts.API_BASE_URL + 'sign_manifest', { | ||
|
||
// Load API_BASE_URL form nextjs backend | ||
const configResponse = await fetch('/api/config') | ||
const apiBaseUrl = (await configResponse.json()).apiBaseUrl | ||
|
||
const response = await fetch(`${apiBaseUrl}/sign`, { | ||
method: 'POST', | ||
headers: { | ||
'Accept': 'application/octet-stream', | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify({ | ||
manifest: manifestJson | ||
PassJsonHash: passHash, | ||
}) | ||
}) | ||
if (response.status != 200) { | ||
|
||
if (response.status !== 200) { | ||
return undefined | ||
} | ||
|
||
const manifestSignature = await response.arrayBuffer() | ||
|
||
zip.push({ path: 'signature', data: Buffer.from(manifestSignature) }); | ||
|
||
// finished! | ||
return toBuffer(zip); | ||
} | ||
|
||
let valueSets | ||
|
||
try { | ||
|
@@ -87,8 +87,6 @@ exports.createPass = async function(data) { | |
} catch (e) { | ||
return undefined | ||
} | ||
|
||
let signingIdentity = await getJSONfromURL(consts.API_BASE_URL + 'signing_identity') | ||
|
||
const qrCode = { | ||
message: payload.raw, | ||
|
@@ -97,14 +95,14 @@ exports.createPass = async function(data) { | |
} | ||
|
||
const pass = { | ||
passTypeIdentifier: signingIdentity['pass_identifier'], | ||
teamIdentifier: signingIdentity['pass_team_id'], | ||
passTypeIdentifier: constants.PASS_IDENTIFIER, | ||
teamIdentifier: constants.TEAM_IDENTIFIER, | ||
sharingProhibited: true, | ||
voided: false, | ||
formatVersion: 1, | ||
logoText: consts.NAME, | ||
organizationName: consts.NAME, | ||
description: consts.NAME, | ||
logoText: constants.NAME, | ||
organizationName: constants.NAME, | ||
description: constants.NAME, | ||
labelColor: payload.labelColor, | ||
foregroundColor: payload.foregroundColor, | ||
backgroundColor: payload.backgroundColor, | ||
|
@@ -113,75 +111,74 @@ exports.createPass = async function(data) { | |
barcode: qrCode, | ||
generic: { | ||
headerFields: [ | ||
{ | ||
key: "type", | ||
label: "Certificate Type", | ||
value: payload.certificateType | ||
{ | ||
key: "type", | ||
label: "Certificate Type", | ||
value: payload.certificateType | ||
} | ||
], | ||
primaryFields: [ | ||
{ | ||
key: "name", | ||
label: "Name", | ||
value: payload.name | ||
{ | ||
key: "name", | ||
label: "Name", | ||
value: payload.name | ||
} | ||
], | ||
secondaryFields: [ | ||
{ | ||
key: "dose", | ||
label: "Dose", | ||
value: payload.dose | ||
{ | ||
key: "dose", | ||
label: "Dose", | ||
value: payload.dose | ||
}, | ||
{ | ||
key: "dov", | ||
label: "Date of Vaccination", | ||
value: payload.dateOfVaccination, | ||
{ | ||
key: "dov", | ||
label: "Date of Vaccination", | ||
value: payload.dateOfVaccination, | ||
textAlignment: "PKTextAlignmentRight" | ||
} | ||
], | ||
auxiliaryFields: [ | ||
{ | ||
key: "vaccine", | ||
label: "Vaccine", | ||
value: payload.vaccineName | ||
{ | ||
key: "vaccine", | ||
label: "Vaccine", | ||
value: payload.vaccineName | ||
}, | ||
{ | ||
key: "dob", | ||
label: "Date of Birth", value: | ||
payload.dateOfBirth, | ||
{ | ||
key: "dob", | ||
label: "Date of Birth", value: | ||
payload.dateOfBirth, | ||
textAlignment: "PKTextAlignmentRight" | ||
} | ||
], | ||
backFields: [ | ||
{ | ||
key: "uvci", | ||
label: "Unique Certificate Identifier (UVCI)", | ||
{ | ||
key: "uvci", | ||
label: "Unique Certificate Identifier (UVCI)", | ||
value: payload.uvci | ||
}, | ||
{ | ||
key: "issuer", | ||
label: "Certificate Issuer", | ||
value: payload.certificateIssuer | ||
{ | ||
key: "issuer", | ||
label: "Certificate Issuer", | ||
value: payload.certificateIssuer | ||
}, | ||
{ | ||
key: "country", | ||
label: "Country of Vaccination", | ||
{ | ||
key: "country", | ||
label: "Country of Vaccination", | ||
value: payload.countryOfVaccination | ||
}, | ||
{ | ||
key: "manufacturer", | ||
label: "Manufacturer", | ||
value: payload.manufacturer | ||
{ | ||
key: "manufacturer", | ||
label: "Manufacturer", | ||
value: payload.manufacturer | ||
}, | ||
{ | ||
key: "disclaimer", | ||
label: "Disclaimer", | ||
{ | ||
key: "disclaimer", | ||
label: "Disclaimer", | ||
value: "This certificate is only valid in combination with the ID card of the certificate holder and expires one year + 14 days after the last dose. The validity of this certificate was not checked by CovidPass." | ||
} | ||
] | ||
} | ||
}; | ||
|
||
let buf = await signPassWithRemote(pass, payload) | ||
return buf | ||
return await signPassWithRemote(pass, payload) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters