certificate-parser.js 824 B

12345678910111213141516171819202122232425
  1. 'use strict';
  2. const { calculatePartialFingerprintOfEscapedPemCertificate } = require('../../modules/certificate');
  3. module.exports = async (req, res, next) => {
  4. if (req.headers['ssl_client_s_dn_cn'] && req.headers['ssl_client_s_dn_cn'] !== 'no_client_cert') {
  5. req.clientCertificateCn = req.headers['ssl_client_s_dn_cn'];
  6. } else {
  7. const err = new Error('Unauthorized');
  8. err.status = 403;
  9. return next(err);
  10. }
  11. if (req.headers['ssl_client_certificate']) {
  12. const pemCertificateEscaped = req.headers['ssl_client_certificate'];
  13. const fingerprint = calculatePartialFingerprintOfEscapedPemCertificate(pemCertificateEscaped);
  14. req.clientCertificateFingerprint = fingerprint;
  15. } else {
  16. const err = new Error('Unauthorized');
  17. err.status = 403;
  18. return next(err);
  19. }
  20. return next();
  21. };