From 1f09de0c882deb20a23c5681ecb6ee063f04f35e Mon Sep 17 00:00:00 2001 From: Kiran Date: Mon, 21 Feb 2022 18:45:17 +0530 Subject: [PATCH] wip --- data/{x509cert.txt => idp-private-key.txt} | 0 data/idp-public-key.txt | 0 data/saml-response.xml | 58 ---------------- utils/index.ts | 81 +++++++++++----------- 4 files changed, 42 insertions(+), 97 deletions(-) rename data/{x509cert.txt => idp-private-key.txt} (100%) create mode 100644 data/idp-public-key.txt delete mode 100644 data/saml-response.xml diff --git a/data/x509cert.txt b/data/idp-private-key.txt similarity index 100% rename from data/x509cert.txt rename to data/idp-private-key.txt diff --git a/data/idp-public-key.txt b/data/idp-public-key.txt new file mode 100644 index 0000000..e69de29 diff --git a/data/saml-response.xml b/data/saml-response.xml deleted file mode 100644 index 391b2b0..0000000 --- a/data/saml-response.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - idp_entity_id - - - - - - - - - - - xPMc7SSHhFSWGljyk1L8mRE1M6otu0qlukR42E6QdiQ= - - - VXlnv1pN3BsHvfbwkugYfsgcjoiXzsbm8OiWczkbNQcadaYTHgIOPf9mNLLJXq1vSfBVLyDY+1Xq - - - ST=California,C=US,OU=Google For Work,CN=Google,L=Mountain View,O=Google Inc. - MIIDdDCCAlygAwIBAgIGAXo6K+u/MA0GCSqGSIb3DQEBCwUAMHsxFDASBgNVBAoTC0dvb2dsZSBJ - - - - - - - - idp_entity_id - - user_email - - - - - - - https://saml.boxyhq.com - - - - - user_email - - - user_firstName - - - user_lastName - - - - - urn:oasis:names:tc:SAML:2.0:ac:classes:unspecified - - - - \ No newline at end of file diff --git a/utils/index.ts b/utils/index.ts index 5d39dec..baea3c9 100644 --- a/utils/index.ts +++ b/utils/index.ts @@ -56,7 +56,7 @@ const createIdPMetadataXML = async ({ }; const createCertificate = async () => { - const certificateFilePath = path.join('data', 'x509cert.txt'); + const certificateFilePath = path.join('data', 'idp-public-key.txt'); return await fs.readFile(certificateFilePath, 'utf8'); }; @@ -85,9 +85,44 @@ const createSAMLResponseXML = async (params: { authDate.setMinutes(authDate.getMinutes() + 10); const notAfter = authDate.toISOString(); - const inResponseTo = '_dde944f3d9cb96238b0c' + const inResponseTo = '_1234' const responseId = crypto.randomBytes(10).toString('hex'); + const attributeStatement = { + '@xmlns:xs': 'http://www.w3.org/2001/XMLSchema', + '@xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', + 'saml:Attribute' : [ + { + '@Name': 'id', + '@NameFormat': 'urn:oasis:names:tc:SAML:2.0:attrname-format:basic', + 'saml:AttributeValue': { + '#text': user.id, + } + }, + { + '@Name': 'email', + '@NameFormat': 'urn:oasis:names:tc:SAML:2.0:attrname-format:basic', + 'saml:AttributeValue': { + '#text': user.email, + } + }, + { + '@Name': 'firstName', + '@NameFormat': 'urn:oasis:names:tc:SAML:2.0:attrname-format:basic', + 'saml:AttributeValue': { + '#text': user.firstName, + } + }, + { + '@Name': 'lastName', + '@NameFormat': 'urn:oasis:names:tc:SAML:2.0:attrname-format:basic', + 'saml:AttributeValue': { + '#text': user.lastName, + } + }, + ] + } + const nodes = { 'samlp:Response':{ '@xmlns:samlp': 'urn:oasis:names:tc:SAML:2.0:protocol', @@ -137,49 +172,17 @@ const createSAMLResponseXML = async (params: { } } }, - 'saml:AttributeStatement': { - '@xmlns:xs': 'http://www.w3.org/2001/XMLSchema', - '@xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', - 'saml:Attribute': [ - { - '@Name': 'id', - '@NameFormat': 'urn:oasis:names:tc:SAML:2.0:attrname-format:basic', - 'saml:AttributeValue': { - '#text': user.id, - } - }, - { - '@Name': 'email', - '@NameFormat': 'urn:oasis:names:tc:SAML:2.0:attrname-format:basic', - 'saml:AttributeValue': { - '#text': user.email, - } - }, - { - '@Name': 'firstName', - '@NameFormat': 'urn:oasis:names:tc:SAML:2.0:attrname-format:basic', - 'saml:AttributeValue': { - '#text': user.firstName, - } - }, - { - '@Name': 'lastName', - '@NameFormat': 'urn:oasis:names:tc:SAML:2.0:attrname-format:basic', - 'saml:AttributeValue': { - '#text': user.lastName, - } - }, - ] - } - } + 'saml:AttributeStatement': attributeStatement, + }, } } return xmlbuilder.create(nodes).end({ pretty: true}); }; -// Add DigestValue -// Add X509Certificate +const signResponseXML = (xml: string, signingKey: any, publicKey: any): string => { + return xml; +} // Create the HTML form to submit the response export const createResponseForm = (relayState: string, encodedSamlResponse: string, acsUrl: string) => {