Skip to content

Commit

Permalink
Merge 6190ddc into 51c0ffb
Browse files Browse the repository at this point in the history
  • Loading branch information
privacyguard committed Sep 11, 2022
2 parents 51c0ffb + 6190ddc commit 3af4d98
Show file tree
Hide file tree
Showing 28 changed files with 744 additions and 44 deletions.
4 changes: 2 additions & 2 deletions packages/cms/src/attribute.ts
@@ -1,14 +1,14 @@
import { AsnProp, AsnPropTypes } from "@peculiar/asn1-schema";

/**
* ```
* ```asn
* AttributeValue ::= ANY
* ```
*/
export type AttributeValue = ArrayBuffer;

/**
* ```
* ```asn
* Attribute ::= SEQUENCE {
* attrType OBJECT IDENTIFIER,
* attrValues SET OF AttributeValue }
Expand Down
4 changes: 2 additions & 2 deletions packages/cms/src/attributes.ts
Expand Up @@ -5,15 +5,15 @@ import { SignerInfo } from "./signer_info";
export type MessageDigest = ArrayBuffer;

/**
* ```
* ```asn
* SigningTime ::= Time
* ```
*/
@AsnType({ type: AsnTypeTypes.Choice })
export class SigningTime extends Time { }

/**
* ```
* ```asn
* Countersignature ::= SignerInfo
* ```
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/cms/src/attributes/counter_signature.ts
Expand Up @@ -2,15 +2,15 @@ import { AsnType, AsnTypeTypes } from "@peculiar/asn1-schema";
import { SignerInfo } from "../signer_info";

/**
* ```
* ```asn
* id-countersignature OBJECT IDENTIFIER ::= { iso(1) member-body(2)
* us(840) rsadsi(113549) pkcs(1) pkcs9(9) 6 }
* ```
*/
export const id_counterSignature = "1.2.840.113549.1.9.6";

/**
* ```
* ```asn
* SigningTime ::= Time
* ```
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/cms/src/attributes/index.ts
Expand Up @@ -3,7 +3,7 @@ export * from "./message_digest";
export * from "./signing_time";

/**
* ```
* ```asn
* id-contentType OBJECT IDENTIFIER ::= { iso(1) member-body(2)
* us(840) rsadsi(113549) pkcs(1) pkcs9(9) 3 }
* ```
Expand Down
4 changes: 2 additions & 2 deletions packages/cms/src/attributes/message_digest.ts
@@ -1,15 +1,15 @@
import { OctetString } from "@peculiar/asn1-schema";

/**
* ```
* ```asn
* id-messageDigest OBJECT IDENTIFIER ::= { iso(1) member-body(2)
* us(840) rsadsi(113549) pkcs(1) pkcs9(9) 4 }
* ```
*/
export const id_messageDigest = "1.2.840.113549.1.9.4";

/**
* ```
* ```asn
* MessageDigest ::= OCTET STRING
* ```
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/cms/src/attributes/signing_time.ts
Expand Up @@ -2,15 +2,15 @@ import { Time } from "@peculiar/asn1-x509";
import { AsnTypeTypes, AsnType } from "@peculiar/asn1-schema";

/**
* ```
* ```asn
* id-signingTime OBJECT IDENTIFIER ::= { iso(1) member-body(2)
* us(840) rsadsi(113549) pkcs(1) pkcs9(9) 5 }
* ```
*/
export const id_signingTime = "1.2.840.113549.1.9.5";

/**
* ```
* ```asn
* SigningTime ::= Time
* ```
*/
Expand Down
6 changes: 3 additions & 3 deletions packages/cms/src/certificate_choices.ts
Expand Up @@ -2,7 +2,7 @@ import { AsnType, AsnTypeTypes, AsnProp, AsnPropTypes, AsnArray } from "@peculia
import { Certificate } from "@peculiar/asn1-x509";
import { AttributeCertificate } from '@peculiar/asn1-x509-attr';
/**
* ```
* ```asn
* OtherCertificateFormat ::= SEQUENCE {
* otherCertFormat OBJECT IDENTIFIER,
* otherCert ANY DEFINED BY otherCertFormat }
Expand All @@ -22,7 +22,7 @@ export class OtherCertificateFormat {
}

/**
* ```
* ```asn
* CertificateChoices ::= CHOICE {
* certificate Certificate,
* extendedCertificate [0] IMPLICIT ExtendedCertificate, -- Obsolete
Expand Down Expand Up @@ -57,7 +57,7 @@ export class CertificateChoices {
}

/**
* ```
* ```asn
* CertificateSet ::= SET OF CertificateChoices
* ```
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/cms/src/content_info.ts
Expand Up @@ -2,7 +2,7 @@ import { AsnProp, AsnPropTypes } from "@peculiar/asn1-schema";
import { ContentType } from "./types";

/**
* ```
* ```asn
* ContentInfo ::= SEQUENCE {
* contentType ContentType,
* content [0] EXPLICIT ANY DEFINED BY contentType }
Expand Down
2 changes: 1 addition & 1 deletion packages/cms/src/encapsulated_content_info.ts
Expand Up @@ -17,7 +17,7 @@ export class EncapsulatedContent {
}

/**
* ```
* ```asn
* EncapsulatedContentInfo ::= SEQUENCE {
* eContentType ContentType,
* eContent [0] EXPLICIT OCTET STRING OPTIONAL }
Expand Down
84 changes: 84 additions & 0 deletions packages/cms/src/encrypted_content_info.ts
@@ -0,0 +1,84 @@
import { AsnProp, AsnPropTypes, AsnType, AsnTypeTypes, OctetString } from "@peculiar/asn1-schema";
import { ContentType, ContentEncryptionAlgorithmIdentifier } from "./types";

/**
* ```asn
* EncryptedContent ::= OCTET STRING
* ```
*/
export type PrimitiveEncryptedContent = OctetString;

/**
* ```asn
* EncryptedContent ::= OCTET STRING
* ```
*/
@AsnType({ type: AsnTypeTypes.Choice })
export class EncryptedContent {

@AsnProp({ type: OctetString })
public single?: OctetString;

@AsnProp({ type: AsnPropTypes.Any })
public any?: ArrayBuffer;

constructor(params: Partial<EncryptedContent> = {}) {
Object.assign(this, params);
}
}

export class ImplicitEncryptedContentInfo {

@AsnProp({ type: AsnPropTypes.ObjectIdentifier })
public contentType: ContentType = "";

@AsnProp({ type: ContentEncryptionAlgorithmIdentifier })
public contentEncryptionAlgorithm = new ContentEncryptionAlgorithmIdentifier();

@AsnProp({ type: OctetString, context: 0, implicit: true, optional: true })
public encryptedContent?: PrimitiveEncryptedContent;

constructor(params: Partial<ImplicitEncryptedContentInfo> = {}) {
Object.assign(this, params);
}
}

export class ExplicitEncryptedContentInfo {

@AsnProp({ type: AsnPropTypes.ObjectIdentifier })
public contentType: ContentType = "";

@AsnProp({ type: ContentEncryptionAlgorithmIdentifier })
public contentEncryptionAlgorithm = new ContentEncryptionAlgorithmIdentifier();

@AsnProp({ type: EncryptedContent, context: 0, optional: true })
public encryptedContent?: EncryptedContent;

constructor(params: Partial<ExplicitEncryptedContentInfo> = {}) {
Object.assign(this, params);
}
}

/**
* ```asn
* EncryptedContentInfo ::= SEQUENCE {
* contentType ContentType,
* contentEncryptionAlgorithm ContentEncryptionAlgorithmIdentifier,
* encryptedContent [0] IMPLICIT EncryptedContent OPTIONAL }
* ```
*/
@AsnType({ type: AsnTypeTypes.Choice })
export class EncryptedContentInfo {

// RFC compliant
@AsnProp({ type: ImplicitEncryptedContentInfo, optional: true })
public implicitEncryptedContentInfo?: ImplicitEncryptedContentInfo;

// !!! Non RFC compliant but used by modern crypto libraries
@AsnProp({ type: ExplicitEncryptedContentInfo, optional: true })
public explicitEncryptedContentInfo?: ExplicitEncryptedContentInfo;

constructor(params: Partial<EncryptedContentInfo> = {}) {
Object.assign(this, params);
}
}
54 changes: 54 additions & 0 deletions packages/cms/src/enveloped_data.ts
@@ -0,0 +1,54 @@
import { AsnProp, AsnPropTypes, AsnArray, AsnType, AsnTypeTypes } from "@peculiar/asn1-schema";
import { CMSVersion } from "./types";
import { Attribute } from "./attribute";
import { RecipientInfos } from "./recipient_infos";
import { OriginatorInfo } from "./originator_info";
import { EncryptedContentInfo } from "./encrypted_content_info";

/**
* ```asn
* UnprotectedAttributes ::= SET SIZE (1..MAX) OF Attribute
* ```
*/
@AsnType({ type: AsnTypeTypes.Set, itemType: Attribute })
export class UnprotectedAttributes extends AsnArray<Attribute> {

constructor(items?: Attribute[]) {
super(items);

// Set the prototype explicitly.
Object.setPrototypeOf(this, UnprotectedAttributes.prototype);
}
}

/**
* ```asn
* EnvelopedData ::= SEQUENCE {
* version CMSVersion,
* originatorInfo [0] IMPLICIT OriginatorInfo OPTIONAL,
* recipientInfos RecipientInfos,
* encryptedContentInfo EncryptedContentInfo,
* unprotectedAttrs [1] IMPLICIT UnprotectedAttributes OPTIONAL }
* ```
*/
export class EnvelopedData {

@AsnProp({ type: AsnPropTypes.Integer })
public version: CMSVersion = CMSVersion.v0;

@AsnProp({ type: OriginatorInfo, context: 0, implicit: true, optional: true })
public originatorInfo?: OriginatorInfo;

@AsnProp({ type: RecipientInfos })
public recipientInfos = new RecipientInfos();

@AsnProp({ type: EncryptedContentInfo })
public encryptedContentInfo = new EncryptedContentInfo();

@AsnProp({ type: UnprotectedAttributes, context: 1, implicit: true, optional: true })
public unprotectedAttrs?: UnprotectedAttributes;

constructor(params: Partial<EnvelopedData> = {}) {
Object.assign(this, params);
}
}
9 changes: 9 additions & 0 deletions packages/cms/src/index.ts
Expand Up @@ -2,8 +2,17 @@ export * from "./attribute";
export * from "./certificate_choices";
export * from "./content_info";
export * from "./encapsulated_content_info";
export * from "./encrypted_content_info";
export * from "./enveloped_data";
export * from "./issuer_and_serial_number";
export * from "./kek_recipient_info";
export * from "./key_agree_recipient_info";
export * from "./key_trans_recipient_info";
export * from "./object_identifiers";
export * from "./originator_info";
export * from "./password_recipient_info";
export * from "./recipient_info";
export * from "./recipient_infos";
export * from "./revocation_info_choice";
export * from "./signed_data";
export * from "./signer_identifier";
Expand Down
4 changes: 2 additions & 2 deletions packages/cms/src/issuer_and_serial_number.ts
Expand Up @@ -2,7 +2,7 @@ import { AsnProp, AsnPropTypes, AsnIntegerArrayBufferConverter } from "@peculiar
import { Name } from "@peculiar/asn1-x509";

/**
* ```
* ```asn
* IssuerAndSerialNumber ::= SEQUENCE {
* issuer Name,
* serialNumber CertificateSerialNumber }
Expand All @@ -21,7 +21,7 @@ export class IssuerAndSerialNumber {
}

/**
* ```
* ```asn
* CertificateSerialNumber ::= INTEGER
* ```
*/
Expand Down
55 changes: 55 additions & 0 deletions packages/cms/src/kek_recipient_info.ts
@@ -0,0 +1,55 @@
import { AsnProp, AsnPropTypes, OctetString } from "@peculiar/asn1-schema";
import { OtherKeyAttribute } from "./other_key_attribute";
import { CMSVersion, EncryptedKey, KeyEncryptionAlgorithmIdentifier } from "./types";

/**
* ```asn
* KEKIdentifier ::= SEQUENCE {
* keyIdentifier OCTET STRING,
* date GeneralizedTime OPTIONAL,
* other OtherKeyAttribute OPTIONAL }
* ```
*/
export class KEKIdentifier {

@AsnProp({ type: OctetString })
public keyIdentifier = new OctetString();

@AsnProp({ type: AsnPropTypes.GeneralizedTime, optional: true })
public date?: Date;

@AsnProp({ type: OtherKeyAttribute, optional: true })
public other?: OtherKeyAttribute;

constructor(params: Partial<KEKIdentifier> = {}) {
Object.assign(this, params);
}
}

/**
* ```asn
* KEKRecipientInfo ::= SEQUENCE {
* version CMSVersion, -- always set to 4
* kekid KEKIdentifier,
* keyEncryptionAlgorithm KeyEncryptionAlgorithmIdentifier,
* encryptedKey EncryptedKey }
* ```
*/
export class KEKRecipientInfo {

@AsnProp({ type: AsnPropTypes.Integer })
public version: CMSVersion = CMSVersion.v4;

@AsnProp({ type: KEKIdentifier })
public kekid = new KEKIdentifier();

@AsnProp({ type: KeyEncryptionAlgorithmIdentifier })
public keyEncryptionAlgorithm = new KeyEncryptionAlgorithmIdentifier();

@AsnProp({ type: OctetString })
public encryptedKey: EncryptedKey = new OctetString();

constructor(params: Partial<KEKRecipientInfo> = {}) {
Object.assign(this, params);
}
}

0 comments on commit 3af4d98

Please sign in to comment.