Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handling & base64 certificate support #24

Open
wants to merge 1 commit into
base: feature/FMA-79
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/common/services/proof.service.ts
Original file line number Diff line number Diff line change
@@ -100,7 +100,7 @@ export class ProofService {
try {
didDocument = await this.getDidWebDocument(did)
} catch (error) {
throw new ConflictException(`Could not load document for given did:web: "${did}"`)
throw new ConflictException(`Could not load document for given did:web: "${did}", reason:\n${error}`)
}
if (!didDocument?.verificationMethod || didDocument?.verificationMethod?.constructor !== Array) {
throw new ConflictException(`Could not load verificationMethods in did document at ${didDocument?.verificationMethod}`)
@@ -120,6 +120,17 @@ export class ProofService {

private async getDidWebDocument(did: string): Promise<DIDDocument> {
const doc = await resolver.resolve(did)
if (!doc.didDocument) {
const metaData = doc.didResolutionMetadata as Record<string, any>
let errorMsg = `Could not resolve ${did}`
if (metaData.error !== undefined) {
errorMsg += `, error: ${metaData.error}`
}
if (metaData.message !== undefined) {
errorMsg += `, message:\n ${metaData.message}`
}
throw new Error(errorMsg)
}

return doc.didDocument
}
23 changes: 17 additions & 6 deletions src/common/utils/public-key.utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import { writeFileSync } from 'fs'
import { join } from 'path'
import {writeFileSync} from 'fs'
import {join} from 'path'

function parseCertificate() {
const certificateData = process.env.X509_CERTIFICATE;

// Check if the certificate data contains "-----"
if (certificateData.includes("-----")) {
return certificateData;
} else {
return atob(certificateData);
}
}

export function importCertChain() {
if (!!process.env.X509_CERTIFICATE) {
const X509_CERTIFICATE_CHAIN_FILE_PATH = join(__dirname, '../../static/.well-known/x509CertificateChain.pem')
writeFileSync(X509_CERTIFICATE_CHAIN_FILE_PATH, process.env.X509_CERTIFICATE)
}
if (!!process.env.X509_CERTIFICATE) {
const X509_CERTIFICATE_CHAIN_FILE_PATH = join(__dirname, '../../static/.well-known/x509CertificateChain.pem')
writeFileSync(X509_CERTIFICATE_CHAIN_FILE_PATH, parseCertificate())
}
}