self signed certificate in certificate chain error when calling /ews/exchange.asmx

446 views Asked by At

I have moved my Outlook web addin logic to a nodejs backend like suggested here.

Now, I get this error when I call exch.GetUserAvailability function:

self signed certificate in certificate chain

Which is weird because it is not a self signed certificate. It is a certificate that has our company Root CA at the top of its certification path.

What can I do to fix this issue?

Thanks

For reference, here are an extract of my code:

const express = require("express");
const EwsJS = require("ews-javascript-api");
        
...
    
router.post("/", async (req, res, next) => {
  try {
    const { ewsUrl, token, appointmentDates, selectedRoomEmails } = req.body;

    if (ewsUrl && token && appointmentDates?.length === 2 && selectedRoomEmails?.length > 0) {
      const rooms = await fetchFreeBusy(ewsUrl, token, appointmentDates, selectedRoomEmails);
      res.status(200).json(rooms);
    } else {
      res.status(400).json({ error: "Bad arguments!" });
    }
  } catch (error) {
    next(error);
  }
});

const fetchFreeBusy = async (ewsUrl, token, appointmentDates, selectedRoomEmails) => {
    const exch = new EwsJS.ExchangeService(EwsJS.ExchangeVersion.Exchange2016);
    exch.Credentials = new EwsJS.OAuthCredentials(token);
    exch.Url = new EwsJS.Uri(ewsUrl);
            
    ...
            
    return await new Promise((resolve, reject) => {
    // error happens after this: self signed certificate in certificate chain
    exch.GetUserAvailability(selectedRoomEmails, timeWindow, EwsJS.AvailabilityData.FreeBusyAndSuggestions).then(
        function (availabilityResponse) {
            resolve(availabilityResponse);
        },
        function (errors) {
            reject(errors);
        });
    });
};

and the detailed error message:

2022-04-06T16:46:26: SoapFaultDetails {
2022-04-06T16:46:26:   message: 'self signed certificate in certificate chain',
2022-04-06T16:46:26:   InnerException: null,
2022-04-06T16:46:26:   faultCode: null,
2022-04-06T16:46:26:   faultString: null,
2022-04-06T16:46:26:   faultActor: null,
2022-04-06T16:46:26:   responseCode: 127,
2022-04-06T16:46:26:   errorCode: 0,
2022-04-06T16:46:26:   exceptionType: null,
2022-04-06T16:46:26:   lineNumber: 0,
2022-04-06T16:46:26:   positionWithinLine: 0,
2022-04-06T16:46:26:   errorDetails: DictionaryWithStringKey {
2022-04-06T16:46:26:     keys: [],
2022-04-06T16:46:26:     keysToObjs: {},
2022-04-06T16:46:26:     objects: {},
2022-04-06T16:46:26:     keyPicker: [Function (anonymous)]
2022-04-06T16:46:26:   },
2022-04-06T16:46:26:   HttpStatusCode: 0
2022-04-06T16:46:26: }
1

There are 1 answers

0
Yuri On

Fixed by adding this line before instanciating the exchange service:

  EwsJS.ConfigurationApi.SetXHROptions({rejectUnauthorized : false});
  const exch = new EwsJS.ExchangeService(EwsJS.ExchangeVersion.Exchange2016);