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

🐛 aes-128-cbc not in CipherCCMTypes in createCipheriv function #386

Closed
3 of 4 tasks
Miigaarino opened this issue Jul 24, 2024 · 6 comments
Closed
3 of 4 tasks

Comments

@Miigaarino
Copy link

What's happening?

After upgrading from 0.6.1 to 0.7.1 function createCipheriv shows type error saying
Argument of type '"aes-128-cbc"' is not assignable to parameter of type 'CipherGCMTypes'
image

Reproducible Code

import { Buffer } from "@craftzdog/react-native-buffer";
import crypto from "react-native-quick-crypto";

const KEY = ...
const IV = ...

const cipher = crypto.createCipheriv("aes-128-cbc", Buffer.from(KEY, "utf8"), Buffer.from(IV, "utf8"));

Relevant log output

Argument of type '"aes-128-cbc"' is not assignable to parameter of type 'CipherGCMTypes'.

Device

Iphone 11

QuickCrypto Version

0.7.1

Can you reproduce this issue in the QuickCrypto Example app?

Yes, I can reproduce the same issue in the Example app here

Additional information

@boorad
Copy link
Collaborator

boorad commented Aug 14, 2024

@Miigaarino,

Are you sure that algorithm is allowed in Node crypto? I don't see it in @node/types here.

@shamilovtim made the types a bit stronger than any in #247 by using @node/types.

See if you can find somewhere online where createCipheriv() should support aes-128-cbc 🙏

@blluv
Copy link

blluv commented Aug 31, 2024

In the implementation file (src/Cipher.ts), the createCipheriv function accepts algorithm strings:
https://github.com/margelo/react-native-quick-crypto/blob/v0.7.3/src/Cipher.ts#L345-L356

However, in the type definition file (node_modules/react-native-quick-crypto/lib/typescript/Cipher.d.ts), the algorithm parameter is restricted to CipherCCM, CipherOCB, CipherGCM.

export declare function createCipheriv(algorithm: CipherCCMTypes, key: BinaryLikeNode, iv: BinaryLike, options: CipherCCMOptions): CipherCCM;
export declare function createCipheriv(algorithm: CipherOCBTypes, key: BinaryLikeNode, iv: BinaryLike, options: CipherOCBOptions): CipherOCB;
export declare function createCipheriv(algorithm: CipherGCMTypes, key: BinaryLikeNode, iv: BinaryLike, options?: CipherGCMOptions): CipherGCM;
image

@shamilovtim
Copy link
Contributor

In the implementation file (src/Cipher.ts), the createCipheriv function accepts algorithm strings: https://github.com/margelo/react-native-quick-crypto/blob/v0.7.3/src/Cipher.ts#L345-L356

However, in the type definition file (node_modules/react-native-quick-crypto/lib/typescript/Cipher.d.ts), the algorithm parameter is restricted to CipherCCM, CipherOCB, CipherGCM.

export declare function createCipheriv(algorithm: CipherCCMTypes, key: BinaryLikeNode, iv: BinaryLike, options: CipherCCMOptions): CipherCCM;
export declare function createCipheriv(algorithm: CipherOCBTypes, key: BinaryLikeNode, iv: BinaryLike, options: CipherOCBOptions): CipherOCB;
export declare function createCipheriv(algorithm: CipherGCMTypes, key: BinaryLikeNode, iv: BinaryLike, options?: CipherGCMOptions): CipherGCM;
image

That's just one of the overloads. Above it you'll see the other overloads that narrow the algorithm based on the combination of params passed.

@shamilovtim
Copy link
Contributor

@Miigaarino @blluv if this is a bug in this case the bug is in @node/types. Consider opening this issue or a PR in https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/crypto.d.ts#L677-L679 and following up there with either an issue or a PR.

@boorad
Copy link
Collaborator

boorad commented Sep 1, 2024

I think I've handled this a bit better in #419

@boorad
Copy link
Collaborator

boorad commented Sep 1, 2024

My ask above was for someone to validate if Node supports this. Actually I did handle it in #419 but might not have gotten aes-128-cbc. I'll add a test for all of them soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants