Creating Apple pass in lambda (nodejs) with walletpass/pass-js. Cannot add the certificate

1.2k Views Asked by At

I'm able to use this code in my PC but when I use lambda I get an error. I'm trying to add the certificate to the template. The certificate is obtained from s3 and there's no issue. The part where I add it to the template results in the error. This is done with the library walletpass/pass-js.

exports.handler = async (event) => {
    // TODO implement
   const s3file = await s3
      .getObject({
        Bucket: bucketName,
        Key: "template.zip"
      })
      .promise();
    var template = await Template.fromBuffer(s3file.Body);
    //console.log(template)
    
    const s3fileCert = await s3
      .getObject({
        Bucket: bucketName,
        Key: "template/PassCertificates.pem"
      })
      .promise();
    var cert = s3fileCert.Body.toString();
    console.log('cert', cert);

    await template.loadCertificate(
      cert,
      "Something852"
    ). then((response) => {
        console.log("response", response)
    })


}

this is the error I get from Lambda

2020-10-04T16:21:25.271+08:00

Copy
2020-10-04T08:21:25.271Z    590ccac3-1c67-4c17-8846-3205d7c1de59    ERROR   Invoke Error    
{
    "errorType": "Error",
    "errorMessage": "ENAMETOOLONG: name too long, open 'Bag Attributes\n    friendlyName: Pass Type ID: pass.example.com\n    localKeyID: AA 07 69 E8 B2 E8 0D 20 E8 63 81 C9 54 9B 25 A9 1B 1B 38 0B   \nsubject=/UID=pass.example.com/CN=Pass Type ID: pass.example.com/OU=855EF5E

"code": "ENAMETOOLONG",
    "errno": -36,
    "syscall": "open",
1

There are 1 best solutions below

0
On

The problem here is that you seem to have passed in the actual certificate as a string where in fact the first argument is looking for the path to the certificate:

Example:

await template.loadCertificate(
  "/etc/passbook/certificate_and_key.pem",
  "secret"
);

Instead you should try using the setCertificate method mentioned in their docs: https://github.com/walletpass/pass-js

template.setCertificate(cert);