Skip to content
New issue

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

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

Already on GitHub? # to your account

Use pure js crypto provider instead of web crypto provider #256

Merged
merged 1 commit into from
Feb 10, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions schemaregistry/rules/encryption/tink/aes_siv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import {Aead} from './aead';

// @ts-expect-error miscreant does not have types
import {SIV, WebCryptoProvider} from "@hackbg/miscreant-esm";
import * as crypto from 'crypto';
import {SIV, SoftCryptoProvider} from "@hackbg/miscreant-esm";

/**
* Implementation of AES-SIV.
Expand All @@ -22,16 +21,16 @@ export class AesSiv extends Aead {
*/
async encrypt(plaintext: Uint8Array, associatedData?: Uint8Array):
Promise<Uint8Array> {
let key = await SIV.importKey(this.key, "AES-CMAC-SIV", new WebCryptoProvider(crypto));
return key.seal(plaintext, [associatedData]);
let key = await SIV.importKey(this.key, "AES-CMAC-SIV", new SoftCryptoProvider());
return key.seal(plaintext, associatedData != null ? [associatedData] : []);
}

/**
*/
async decrypt(ciphertext: Uint8Array, associatedData?: Uint8Array):
Promise<Uint8Array> {
let key = await SIV.importKey(this.key, "AES-CMAC-SIV", new WebCryptoProvider(crypto));
return key.open(ciphertext, [associatedData]);
let key = await SIV.importKey(this.key, "AES-CMAC-SIV", new SoftCryptoProvider());
return key.open(ciphertext, associatedData != null? [associatedData] : []);
}
}

Expand Down
13 changes: 6 additions & 7 deletions schemaregistry/serde/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,6 @@ export class JsonDeserializer extends Deserializer implements JsonSerde {
}

const info = await this.getSchema(topic, payload)
if ((this.conf as JsonSerdeConfig).validate) {
const validate = await this.toValidateFunction(info)
if (validate != null && !validate(JSON.parse(payload.subarray(5).toString()))) {
throw new SerializationError('Invalid message')
}

}
const subject = this.subjectName(topic, info)
const readerMeta = await this.getReaderSchema(subject)
let migrations: Migration[] = []
Expand All @@ -215,6 +208,12 @@ export class JsonDeserializer extends Deserializer implements JsonSerde {
target = info
}
msg = this.executeRules(subject, topic, RuleMode.READ, null, target, msg, null)
if ((this.conf as JsonSerdeConfig).validate) {
const validate = await this.toValidateFunction(info)
if (validate != null && !validate(JSON.parse(msg))) {
throw new SerializationError('Invalid message')
}
}
return msg
}

Expand Down
2 changes: 1 addition & 1 deletion schemaregistry/serde/serde.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export abstract class Serializer extends Serde {
async getId(topic: string, msg: any, info?: SchemaInfo, format?: string): Promise<[number, SchemaInfo]> {
let autoRegister = this.config().autoRegisterSchemas
let useSchemaId = this.config().useSchemaId
let useLatestWithMetadata = this.conf.useLatestWithMetadata
let useLatestWithMetadata = this.config().useLatestWithMetadata
let useLatest = this.config().useLatestVersion
let normalizeSchema = this.config().normalizeSchemas

Expand Down