| 1234567891011121314151617181920212223242526272829303132 |
- 'use strict';
- const {
- calculatePartialFingerprintOfEscapedPemCertificate,
- } = require('../../modules/certificate');
- module.exports = async (req, res, next) => {
- if (
- req.headers['ssl_client_s_dn_cn'] &&
- req.headers['ssl_client_s_dn_cn'] !== 'no_client_cert'
- ) {
- req.clientCertificateCn = req.headers['ssl_client_s_dn_cn'];
- } else {
- const err = new Error('Unauthorized');
- err.status = 403;
- return next(err);
- }
- if (req.headers['ssl_client_certificate']) {
- const pemCertificateEscaped = req.headers['ssl_client_certificate'];
- const fingerprint = calculatePartialFingerprintOfEscapedPemCertificate(
- pemCertificateEscaped,
- );
- req.clientCertificateFingerprint = fingerprint;
- } else {
- const err = new Error('Unauthorized');
- err.status = 403;
- return next(err);
- }
- return next();
- };
|