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

Update crypto.ts because of this.container.session.slot.getMechanisms() only gets "ECDSA" so set some cases to "ECDSA" #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/mechs/ec/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,15 @@ export class EcCrypto implements types.IContainer {

public getAlgorithm(p11AlgorithmName: string | number) {
const mechanisms = this.container.session.slot.getMechanisms();
switch (p11AlgorithmName) {
case "ECDSA":
case "ECDSA_SHA1":
case "ECDSA_SHA256":
case "ECDSA_SHA384":
case "ECDSA_SHA512":
p11AlgorithmName = "ECDSA";
break;
}
Comment on lines +142 to +150
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This switch..case forces ECDSA with hash to primitive ECDSA mechanism. What if token doesn't implement ECDSA mechanism and uses ECDSA with hash only?

getAlgorithm function must filter ECDSA mechanisms and select ECDSA with hash if it's possible or use ECDSA without hash

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use the Fortify App and get an Error from this function see => PeculiarVentures/fortify#497

It says "Cannot get PKCS11 EC mechanism by name 'ECDSA_SHA384' ". We're using an Atos Smart Card from D-Trust.

At the moment, the this.container.session.slot.getMechanisms() returns an array where all ECDSA_*** Were Replaced by ECDSA Without Hash.

I found out algName in Array is only "ECDSA", but mechanism.name === p11AlgorithmName (https://github.com/PeculiarVentures/node-webcrypto-p11/blob/master/src/mechs/ec/crypto.ts#L145) is never true than.

So please review my Issue from PeculiarVentures/fortify#497 to understand my problem there.

let EC: string | undefined;
for (let i = 0; i < mechanisms.length; i++) {
const mechanism = mechanisms.tryGetItem(i);
Expand Down