Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format code and enforce code style on PR #527

Merged
merged 2 commits into from
Feb 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"prettier"
],
"rules": {
"no-console": "warn",
"prettier/prettier": "warn"
"no-console": "warn"
}
}
8 changes: 4 additions & 4 deletions .github/ISSUE_TEMPLATE/bug-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ name: Bug report
about: Create a report to help us improve
title: "[BUG]"
labels: bug
assignees: ''

assignees: ""
---

<!--
Expand Down Expand Up @@ -39,5 +38,6 @@ Steps to reproduce the behavior. Ideally, expressesd through an automated test.
A clear and concise description of what you expected to happen.

**Environment**
- Node.js version:
- passport-saml version:

- Node.js version:
- passport-saml version:
3 changes: 1 addition & 2 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ name: Feature request
about: Suggest an idea for this project
title: "[ENHANCE]"
labels: enhancement
assignees: ''

assignees: ""
---

<!--
Expand Down
8 changes: 4 additions & 4 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ _Please include tests._ Doing so will ensure that the changes made in this PR ar

# Checklist:

- Issue Addressed: [ ]
- Link to SAML spec: [ ]
- Tests included? [ ]
- Documentation updated? [ ]
- Issue Addressed: [ ]
- Link to SAML spec: [ ]
- Tests included? [ ]
- Documentation updated? [ ]
20 changes: 9 additions & 11 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,19 @@ on: [push]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [10.x, 12.x, 14.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm run lint
- run: npm test
env:
CI: true
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm test
env:
CI: true
4 changes: 3 additions & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{}
{
"printWidth": 100
}
184 changes: 96 additions & 88 deletions README.md

Large diffs are not rendered by default.

71 changes: 35 additions & 36 deletions docs/adfs/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Active Directory Federation Services
====================================
# Active Directory Federation Services

This document attempts to describe a complete solution for integrating with AD FS.

Expand All @@ -11,13 +10,13 @@ Download [mellon_create_metadata.sh](https://github.com/UNINETT/mod_auth_mellon/

Create a new key, certificate and relying party XML as follows:

./mellon_create_metadata.sh acme_tools_com https://acme_tools.com/adfs/postResponse
./mellon_create_metadata.sh acme_tools_com https://acme_tools.com/adfs/postResponse

## Retrieve AD FS Certificate

Use retrieve_adfs_certificate.sh to get your AD FS server's signing certificate:

./retrieve_adfs_certificate.sh https://adfs.acme_tools.com/ > adfs.acme_tools.com.crt
./retrieve_adfs_certificate.sh https://adfs.acme_tools.com/ > adfs.acme_tools.com.crt

# Create Relying Party

Expand All @@ -30,44 +29,43 @@ This example assumes you will pass in the UPN.
Create a separate file for passport configuration (assumed to be config/passport.js).

```javascript
var
fs = require('fs')
, passport = require('passport')
, SamlStrategy = require('passport-saml').Strategy
;

passport.serializeUser(function(user, done) {
var fs = require("fs"),
passport = require("passport"),
SamlStrategy = require("passport-saml").Strategy;
passport.serializeUser(function (user, done) {
done(null, user);
});
passport.deserializeUser(function(user, done) {
passport.deserializeUser(function (user, done) {
done(null, user);
});

passport.use(new SamlStrategy(
{
entryPoint: 'https://adfs.acme_tools.com/adfs/ls/',
issuer: 'acme_tools_com',
callbackUrl: 'https://acme_tools.com/adfs/postResponse',
privateCert: fs.readFileSync('/path/to/acme_tools_com.key', 'utf-8'),
cert: fs.readFileSync('/path/to/adfs.acme_tools.com.crt', 'utf-8'),
// other authn contexts are available e.g. windows single sign-on
authnContext: 'http://schemas.microsoft.com/ws/2008/06/identity/authenticationmethod/password',
// not sure if this is necessary?
acceptedClockSkewMs: -1,
identifierFormat: null,
// this is configured under the Advanced tab in AD FS relying party
signatureAlgorithm: 'sha256',
RACComparison: 'exact', // default to exact RequestedAuthnContext Comparison Type
},
function(profile, done) {
return done(null,
{
upn: profile['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn'],
passport.use(
new SamlStrategy(
{
entryPoint: "https://adfs.acme_tools.com/adfs/ls/",
issuer: "acme_tools_com",
callbackUrl: "https://acme_tools.com/adfs/postResponse",
privateCert: fs.readFileSync("/path/to/acme_tools_com.key", "utf-8"),
cert: fs.readFileSync("/path/to/adfs.acme_tools.com.crt", "utf-8"),
// other authn contexts are available e.g. windows single sign-on
authnContext:
"http://schemas.microsoft.com/ws/2008/06/identity/authenticationmethod/password",
// not sure if this is necessary?
acceptedClockSkewMs: -1,
identifierFormat: null,
// this is configured under the Advanced tab in AD FS relying party
signatureAlgorithm: "sha256",
RACComparison: "exact", // default to exact RequestedAuthnContext Comparison Type
},
function (profile, done) {
return done(null, {
upn: profile["http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn"],
// e.g. if you added a Group claim
group: profile['http://schemas.xmlsoap.org/claims/Group']
});
}
));
group: profile["http://schemas.xmlsoap.org/claims/Group"],
});
}
)
);

module.exports = passport;
```
Expand Down Expand Up @@ -110,6 +108,7 @@ module.exports = passport;

var server = http.createServer(app);
```

# Troubleshooting

## ADFS 2016
Expand Down
54 changes: 30 additions & 24 deletions docs/xml-signing-example.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,47 @@
// This will help generate signing info for test cases.
// Simply fill in the data and run it to get <DigestValue /> and <SignatureValue />.

const crypto = require('crypto')
const crypto = require("crypto");

const private_key = `-----BEGIN PRIVATE KEY-----

-----END PRIVATE KEY-----
`
`;

const cert = `-----BEGIN CERTIFICATE-----

-----END CERTIFICATE-----
`
`;

const saml_message = ``
const saml_message = ``;

const signed_info = `<SignedInfo...</SignedInfo>`
const signed_info = `<SignedInfo...</SignedInfo>`;

const signer = crypto.createSign('RSA-SHA1');
const signer = crypto.createSign("RSA-SHA1");
signer.update(signed_info);
signer.end();

const signature = signer.sign(private_key)
const signature_b64 = signature.toString('base64')

const verifier = crypto.createVerify('RSA-SHA1')
verifier.update(signed_info)
verifier.end()

const verified = verifier.verify(cert, signature)

const hash = crypto.createHash('RSA-SHA1')
hash.update(saml_message, 'utf8')
const digest_b64 = hash.digest('base64')

console.log(JSON.stringify({
signature: signature_b64,
digest: digest_b64,
verified: verified,
}, null, 2))
const signature = signer.sign(private_key);
const signature_b64 = signature.toString("base64");

const verifier = crypto.createVerify("RSA-SHA1");
verifier.update(signed_info);
verifier.end();

const verified = verifier.verify(cert, signature);

const hash = crypto.createHash("RSA-SHA1");
hash.update(saml_message, "utf8");
const digest_b64 = hash.digest("base64");

console.log(
JSON.stringify(
{
signature: signature_b64,
digest: digest_b64,
verified: verified,
},
null,
2
)
);
4 changes: 2 additions & 2 deletions multiSamlStrategy.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import * as MultiSAMLStrategy from './lib/passport-saml/multiSamlStrategy';
export = MultiSAMLStrategy;
import * as MultiSAMLStrategy from "./lib/passport-saml/multiSamlStrategy";
export = MultiSAMLStrategy;
2 changes: 1 addition & 1 deletion multiSamlStrategy.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
const MultiSamlStrategy = require('./lib/passport-saml/multiSamlStrategy.js');
const MultiSamlStrategy = require("./lib/passport-saml/multiSamlStrategy.js");
module.exports = MultiSamlStrategy;
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@
"build": "tsc",
"changelog": "gren changelog --override --generate",
"lint": "eslint --ext .ts src",
"lint-watch": "onchange 'src/**/*.ts' -- eslint {{file}}",
"lint-watch": "onchange -k -p 100 \"**/*.ts\" -- eslint {{file}}",
"lint:fix": "eslint --ext .ts --fix src",
"prepare": "tsc",
"prettier-check": "prettier --config .prettierrc.json --check .",
"prettier-format": "prettier --config .prettierrc.json --write .",
"prettier-watch": "onchange 'src/**/*.ts' -- prettier --write {{file}}",
"test": "npm run lint && npm run tsc && mocha",
"prettier-watch": "onchange -k -p 100 \".\" -- prettier --config .prettierrc.json --write {{file}}",
"test": "npm run prettier-check && npm run lint && npm run tsc && mocha",
"tsc": "tsc",
"tsc-watch": "tsc && tsc --watch",
"tsc-watch": "tsc --watch",
"watch": "concurrently --kill-others \"npm:*-watch\""
},
"dependencies": {
Expand All @@ -69,6 +69,7 @@
"@typescript-eslint/eslint-plugin": "^4.9.1",
"@typescript-eslint/parser": "^4.9.1",
"body-parser": "^1.19.0",
"choma": "^1.2.1",
"concurrently": "^5.3.0",
"eslint": "^7.15.0",
"eslint-config-prettier": "^7.0.0",
Expand Down
44 changes: 22 additions & 22 deletions src/passport-saml/algorithms.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
import * as crypto from 'crypto';
import * as crypto from "crypto";

export function getSigningAlgorithm (shortName: string): string {
switch(shortName) {
case 'sha256':
return 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256';
case 'sha512':
return 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha512';
export function getSigningAlgorithm(shortName: string): string {
switch (shortName) {
case "sha256":
return "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256";
case "sha512":
return "http://www.w3.org/2001/04/xmldsig-more#rsa-sha512";
default:
return 'http://www.w3.org/2000/09/xmldsig#rsa-sha1';
return "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
}
}

export function getDigestAlgorithm (shortName: string): string {
switch(shortName) {
case 'sha256':
return 'http://www.w3.org/2001/04/xmlenc#sha256';
case 'sha512':
return 'http://www.w3.org/2001/04/xmlenc#sha512';
export function getDigestAlgorithm(shortName: string): string {
switch (shortName) {
case "sha256":
return "http://www.w3.org/2001/04/xmlenc#sha256";
case "sha512":
return "http://www.w3.org/2001/04/xmlenc#sha512";
default:
return 'http://www.w3.org/2000/09/xmldsig#sha1';
return "http://www.w3.org/2000/09/xmldsig#sha1";
}
}

export function getSigner (shortName: string): crypto.Signer {
switch(shortName) {
case 'sha256':
return crypto.createSign('RSA-SHA256');
case 'sha512':
return crypto.createSign('RSA-SHA512');
export function getSigner(shortName: string): crypto.Signer {
switch (shortName) {
case "sha256":
return crypto.createSign("RSA-SHA256");
case "sha512":
return crypto.createSign("RSA-SHA512");
default:
return crypto.createSign('RSA-SHA1');
return crypto.createSign("RSA-SHA1");
}
}