web-pki 2.15.2 → 2.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -311,29 +311,7 @@ export declare class LacunaWebPKI {
311
311
  }): Promise<string>;
312
312
 
313
313
  /**************************************************************
314
- * Signs a batch of hashes with signer certificate private key.
315
- *
316
- * @returns A promise object that can register [[fail]] and [[success]] callbacks to be called when the operation completes. The [[success]] callback for this promise receives the (Base64 encoded) signature bytes array.
317
- *
318
- * Usage example (JavaScript)
319
- * ```javascript
320
- * var batch = [
321
- * 'f4OxZX/x/FO5LcGBSKHWXfwtSx+j1ncoSt3SABJtkGk=', // Base64 encoded SHA-256 of 'Hello World!'
322
- * 'f4OxZX/x/FO5LcGBSKHWXfwtSx+j1ncoSt3SABJtkGk=',
323
- * 'f4OxZX/x/FO5LcGBSKHWXfwtSx+j1ncoSt3SABJtkGk='
324
- * ];
325
- *
326
- * pki.signHashBatch({
327
- * certificateThumbprint: $('#certificateSelect').val(),
328
- * batch: batch,
329
- * digestAlgorithm: 'SHA-256'
330
- * }).success(function (result) {
331
- * // Use signatures array
332
- * var signatures = result.signatures;
333
- * });
334
- * ```
335
- *
336
- * JSFiddle live example: [Sign Hash Batch](https://jsfiddle.net/LacunaSoftware/1car2yjz)
314
+ * **OBSOLETE** Please use [[signHashes]]
337
315
  */
338
316
  signHashBatch(args: {
339
317
  /** The signer certificate thumbprint. Available in [[CertificateModel.thumbprint]] property returned by [[listCertificates]] method. */
@@ -346,6 +324,38 @@ export declare class LacunaWebPKI {
346
324
  usePreauthorizedSignatures?: boolean
347
325
  }): Promise<SignHashBatchResponse>;
348
326
 
327
+ // TODO: next version
328
+ // /**************************************************************
329
+ // * Signs a batch of hashes with signer certificate private key.
330
+ // *
331
+ // * @returns A promise object that can register [[fail]] and [[success]] callbacks to be called when the operation completes. The [[success]] callback for this promise receives the (Base64 encoded) signature bytes array.
332
+ // *
333
+ // * Usage example (JavaScript)
334
+ // * ```javascript
335
+ // * var hashes = [
336
+ // * { algorithm: 'SHA-256', value: 'f4OxZX/x/FO5LcGBSKHWXfwtSx+j1ncoSt3SABJtkGk=' }, // Base64 encoded SHA-256 of 'Hello World!'
337
+ // * { algorithm: 'SHA-256', value: 'f4OxZX/x/FO5LcGBSKHWXfwtSx+j1ncoSt3SABJtkGk=' },
338
+ // * { algorithm: 'SHA-256', value: 'f4OxZX/x/FO5LcGBSKHWXfwtSx+j1ncoSt3SABJtkGk=' }
339
+ // * ];
340
+ // *
341
+ // * pki.signHashes({
342
+ // * certificateThumbprint: $('#certificateSelect').val(),
343
+ // * hashes: hashes
344
+ // * }).success(function (result) {
345
+ // * // Use signatures array
346
+ // * var signatures = result.signatures;
347
+ // * });
348
+ // * ```
349
+ // *
350
+ // * JSFiddle live example: [Sign Hashes](https://jsfiddle.net/LacunaSoftware/1car2yjz)
351
+ // */
352
+ // signHashes(args: {
353
+ // /** The signer certificate thumbprint. Available in [[CertificateModel.thumbprint]] property returned by [[listCertificates]] method. */
354
+ // certificateThumbprint: string,
355
+ // /** The Array of [[Hash]] with the hash algorithm and value to be signed. */
356
+ // hashes: Hash[],
357
+ // }): Promise<SignHashesResponse>;
358
+
349
359
  /**************************************************************
350
360
  * Executes a document signature with Rest PKI (server-side) integration. See [Rest PKI documentation](https://docs.lacunasoftware.com/articles/rest-pki/) for more informations.
351
361
  *
@@ -529,6 +539,22 @@ export declare class LacunaWebPKI {
529
539
  /** If `true`, will not apply the `pdfMarks` in case PDF already has a signature. If `false`, any previous signature will be removed before the marks be applied. */
530
540
  bypassMarksIfSigned?: boolean,
531
541
 
542
+ // TODO: next version
543
+ // /** A signing reason */
544
+ // reason?: string,
545
+
546
+ // /** The signing location or address */
547
+ // location?: string,
548
+
549
+ // /** The signer name */
550
+ // signerName?: string,
551
+
552
+ // /** A custom signature field name. Signature field name must be unique for the PDF */
553
+ // customSignatureFieldName?: string,
554
+
555
+ // /** Any metadata to be added to the PDF */
556
+ // metadata?: { [key: string]: string; },
557
+
532
558
  /** The PDF signature policy. */
533
559
  policy: LacunaWebPKI.PadesPolicies,
534
560
 
@@ -569,15 +595,23 @@ export declare class LacunaWebPKI {
569
595
  /** Whether or not to remove the `policy` default trust arbitrator. If `true`, you must pass the `trustArbitrators` argument. */
570
596
  clearPolicyTrustArbitrators?: boolean,
571
597
 
572
- /** If you already have a CAdES file and a co-signature is intended, pass this argument instead of `fileId`. Optionally, you can use the `fileId` for CAdES signature file and enable the `autoDetectCosign`. */
598
+ /** If you already have a CAdES file and a co-signature is intended, pass this argument instead of `fileId` or `content`. Optionally, you can use the `fileId` for CAdES signature file and enable the `autoDetectCosign`. */
573
599
  cmsToCosignFileId?: string,
574
600
 
601
+ // TODO: next version
602
+ // /** If you already have a CAdES file and a co-signature is intended, pass this argument instead of `fileId` or `content`. Optionally, you can use the `fileId` for CAdES signature file and enable the `autoDetectCosign`. */
603
+ // cmsToCosignContent?: string,
604
+
575
605
  /** Whether or not to auto-detect a co-signature intention if the `fileId` passed is a CAdES signature file. */
576
606
  autoDetectCosign?: boolean,
577
607
 
578
608
  /** Whether or not to include the encapsulated content (the original document) in the resulting CAdES signature file. */
579
609
  includeEncapsulatedContent?: boolean,
580
610
 
611
+ // TODO: next version
612
+ // /** A signing description or reason */
613
+ // signingDescription?: string,
614
+
581
615
  /** The CAdES signature policy. */
582
616
  policy: LacunaWebPKI.CadesPolicies,
583
617
 
@@ -612,6 +646,10 @@ export declare class LacunaWebPKI {
612
646
  /** A XML content (UTF-8 string or Base64 encoded bytes) to sign can be passed optionally to `filedId`. */
613
647
  content?: string,
614
648
 
649
+ // TODO: next version
650
+ // /** A signing description or reason */
651
+ // signingDescription?: string,
652
+
615
653
  /** The XML signature policy. */
616
654
  policy: LacunaWebPKI.XmlPolicies,
617
655
 
@@ -667,6 +705,10 @@ export declare class LacunaWebPKI {
667
705
  /** A XML content (UTF-8 string or Base64 encoded) to sign can be passed optionally to `filedId`. */
668
706
  content?: string,
669
707
 
708
+ // TODO: next version
709
+ // /** A signing description or reason */
710
+ // signingDescription?: string,
711
+
670
712
  /** The XML signature policy. */
671
713
  policy: LacunaWebPKI.XmlPolicies,
672
714
 
@@ -724,8 +766,14 @@ export declare class LacunaWebPKI {
724
766
  /** The signed PDF content (Base64 encoded bytes) to open. It can be passed optionally to `signatureFileId`. */
725
767
  signatureContent?: string,
726
768
 
727
- /** The original file. Only applies if the passed `signatureFileId` does not have the encapsulated content. */
769
+ /** The original file. Only applies if the passed `signatureFileId` or `signatureContent` does not have the encapsulated content. */
728
770
  originalFileId?: string,
771
+
772
+ // TODO: next version
773
+ // /** The original file content (Base64 encoded bytes). Only applies if the passed `signatureFileId` or `signatureContent` does not have the encapsulated content. */
774
+ // originalContent?: string,
775
+ // /** Set to return the encapsulated content */
776
+ // returnEncapsulatedContent?: boolean,
729
777
 
730
778
  /** Whether or not to validate the CAdES sinatures. */
731
779
  validate: boolean,
@@ -819,7 +867,12 @@ export declare class LacunaWebPKI {
819
867
  /** A label for the generated keys objects in the token. If not set, a random Id is used. */
820
868
  keyLabel?: string,
821
869
  /** The RSA keys size to be genarated. Be sure that the selected device supports the requested key size on [[TokenModel.mechanisms]]. */
822
- keySize: number
870
+ keySize: number,
871
+
872
+ // TODO: next version
873
+ // /** Whether or not to auto enable the used PKCS#11 module after command success. The **default** is `true` */
874
+ // enableUsedPkcs11Module?: boolean
875
+
823
876
  }): Promise<GenerateTokenKeyPairResponse>;
824
877
 
825
878
  /**************************************************************
@@ -833,7 +886,9 @@ export declare class LacunaWebPKI {
833
886
  /** A subject name (DN) string for the generated CSR. E.g. `'CN=My Name, O=ACME Inc., C=BR'` */
834
887
  subjectName?: string,
835
888
  /** The RSA keys size to be genarated. */
836
- keySize: number
889
+ keySize: number,
890
+ /** Generates a non exportable key. Software generated non exportable keys are **only supported on Windows platform**. */
891
+ nonExportableKey?: boolean
837
892
  }): Promise<GenerateKeyPairResponse>;
838
893
 
839
894
  /**************************************************************
@@ -855,7 +910,12 @@ export declare class LacunaWebPKI {
855
910
  /** The digital certificate content (PEM or Base64 encoded DER bytes formats). */
856
911
  certificateContent: string,
857
912
  /** A label for the imported certificate object in the token. If not set, the same key Id is used. */
858
- certificateLabel?: string
913
+ certificateLabel?: string,
914
+
915
+ // TODO: next version
916
+ // /** Whether or not to auto enable the used PKCS#11 module after command success. The **default** is `true` */
917
+ // enableUsedPkcs11Module?: boolean
918
+
859
919
  }): Promise<ImportTokenCertificateResponse>;
860
920
 
861
921
  /**************************************************************
@@ -915,6 +975,54 @@ export declare class LacunaWebPKI {
915
975
  timeout?: number
916
976
  }): Promise<HttpResponseModel>;
917
977
 
978
+ /**********************************************************
979
+ * Encrypts data with selected certificate public key or generated public key.
980
+ *
981
+ * @returns A promise object that can register [[fail]] and [[success]] callbacks to be called when the operation completes. The [[success]] callback for this promise receives a [[EncryptResponse]] object.
982
+ *
983
+ * **Live Example**
984
+ *
985
+ * [Encrypt Sample](https://jsfiddle.net/LacunaSoftware/mo3p4g7x/): JSFiddle example for encrypting text with a selected certificate public key.
986
+ */
987
+ encrypt(args: {
988
+ /** A certificate thumbprint which public key will be used to encrypt data. Available in [[CertificateModel.thumbprint]] property returned by [[listCertificates]] method. */
989
+ certificateThumbprint?: string,
990
+ /** A public key content or PKCertificate content (PEM or DER base64 encoded) to encrypt data with */
991
+ publicKey?: string,
992
+ /** A private key Id returned in the generate key pair methods [[generateSoftwareRsaKeyPair]] or [[generateTokenRsaKeyPair]]. */
993
+ privateKeyId?: string,
994
+ /** The user crypto device returned from [[listTokens]]. This parameter ir mandatory if the privateKeyId is from a crypto device. */
995
+ token?: TokenModel
996
+ /** The encryption parameters and padding algorithm to be used */
997
+ parameters: LacunaWebPKI.EncryptionParamaters,
998
+ /** The Base64 encoded data to be encrypted. */
999
+ data: string,
1000
+
1001
+ }): Promise<EncryptResponse>;
1002
+
1003
+ /**********************************************************
1004
+ * Decrypts data with selected certificate private key or generated private key.
1005
+ *
1006
+ * @returns A promise object that can register [[fail]] and [[success]] callbacks to be called when the operation completes. The [[success]] callback for this promise receives a [[DecryptResponse]] object.
1007
+ *
1008
+ * **Live Example**
1009
+ *
1010
+ * [Decrypt Sample](https://jsfiddle.net/LacunaSoftware/068gnLmw/): JSFiddle example for decrypting text with a selected certificate private key.
1011
+ */
1012
+ decrypt(args: {
1013
+ /** A certificate thumbprint which private key will be used to decrypt data. Available in [[CertificateModel.thumbprint]] property returned by [[listCertificates]] method. */
1014
+ certificateThumbprint?: string,
1015
+ /** A private key Id returned in the generate key pair methods [[generateSoftwareRsaKeyPair]] or [[generateTokenRsaKeyPair]]. */
1016
+ privateKeyId?: string,
1017
+ /** The user crypto device returned from [[listTokens]]. This parameter ir mandatory if the privateKeyId is from a crypto device. */
1018
+ token?: TokenModel
1019
+ /** The encryption parameters and padding algorithm to be used */
1020
+ parameters: LacunaWebPKI.EncryptionParamaters,
1021
+ /** The Base64 encoded encrypted data to be decrypted. */
1022
+ data: string,
1023
+
1024
+ }): Promise<DecryptResponse>;
1025
+
918
1026
 
919
1027
 
920
1028
  }
@@ -943,7 +1051,8 @@ export namespace LacunaWebPKI {
943
1051
  v1_6 = '1.6.0',
944
1052
  v1_6_1 = '1.6.1',
945
1053
  v1_7_0 = '1.7.0',
946
- v1_7_2 = '1.7.2'
1054
+ v1_7_2 = '1.7.2',
1055
+ v1_8_0 = '1.8.0'
947
1056
  }
948
1057
 
949
1058
  /**************************************************************
@@ -974,6 +1083,8 @@ export namespace LacunaWebPKI {
974
1083
  COMMAND_PARAMETER_NOT_SET = 'command_parameter_not_set',
975
1084
  /** A command parameter is not valid. */
976
1085
  COMMAND_INVALID_PARAMETER = 'command_invalid_parameter',
1086
+ /** A command parameter is not supported on this platform */
1087
+ COMMAND_PARAMETER_NOT_SUPPORTED= 'command_parameter_not_supported',
977
1088
  /** The web extension failed to connect to native component. */
978
1089
  NATIVE_CONNECT_FAILURE = 'native_connect_failure',
979
1090
  /** The native component disconnected from web extension. */
@@ -1021,7 +1132,8 @@ export namespace LacunaWebPKI {
1021
1132
  MOBILE_NOT_AUTHORIZED = 'mobile_not_authorized',
1022
1133
  MOBILE_SEND_MESSAGE = 'mobile_send_message',
1023
1134
  COMMAND_DECRYPT_ERROR = 'command_decrypt_error',
1024
- BLOCKED_DOMAIN = 'blocked_domain'
1135
+ BLOCKED_DOMAIN = 'blocked_domain',
1136
+ INVALID_OPERATION = 'invalid_operation'
1025
1137
  }
1026
1138
 
1027
1139
  export const enum CertificateTypes {
@@ -1150,6 +1262,18 @@ export namespace LacunaWebPKI {
1150
1262
  TstInfo = 'TstInfo',
1151
1263
  }
1152
1264
 
1265
+ export const enum PdfAStandards {
1266
+ Unknown = 'Unknown',
1267
+ PdfA_1B = 'PdfA_1B',
1268
+ PdfA_1A = 'PdfA_1A',
1269
+ PdfA_2B = 'PdfA_2B',
1270
+ PdfA_2A = 'PdfA_2A',
1271
+ PdfA_2U = 'PdfA_2U',
1272
+ PdfA_3B = 'PdfA_3B',
1273
+ PdfA_3A = 'PdfA_3A',
1274
+ PdfA_3U = 'PdfA_3U',
1275
+ }
1276
+
1153
1277
  // visual representation
1154
1278
  export const enum PadesPaperSizes {
1155
1279
  Custom = 'custom',
@@ -1230,6 +1354,14 @@ export namespace LacunaWebPKI {
1230
1354
  Mutual = 'mutual'
1231
1355
  }
1232
1356
 
1357
+ export const enum EncryptionParamaters {
1358
+ RSAEncryptionPkcs1 = 'RSAEncryptionPkcs1',
1359
+ RSAEncryptionOaepSHA1 = 'RSAEncryptionOaepSHA1',
1360
+ RSAEncryptionOaepSHA256 = 'RSAEncryptionOaepSHA256',
1361
+ RSAEncryptionOaepSHA384 = 'RSAEncryptionOaepSHA384',
1362
+ RSAEncryptionOaepSHA512 = 'RSAEncryptionOaepSHA512'
1363
+ }
1364
+
1233
1365
 
1234
1366
 
1235
1367
  }
@@ -1299,6 +1431,8 @@ export interface CertificateModel {
1299
1431
  thumbprint: string,
1300
1432
  /** Object with boolean properties indicating wether each possible key usage is set on the certificate. */
1301
1433
  keyUsage: KeyUsagesModel,
1434
+ /** Object with boolean properties indicating wether each possible EXTENDED key usage is set on the certificate. If null, certificate does not have the ExtendedKeyUsage extension */
1435
+ extendedKeyUsage?: ExtendedKeyUsagesModel,
1302
1436
  /** Array with certificate policies info */
1303
1437
  certificatePolicies: CertificatePolicyModel[],
1304
1438
  /** Object with Brazil-specific fields. */
@@ -1331,6 +1465,19 @@ export interface KeyUsagesModel {
1331
1465
  nonRepudiation: boolean
1332
1466
  }
1333
1467
 
1468
+ export interface ExtendedKeyUsagesModel {
1469
+ clientAuth: boolean,
1470
+ serverAuth: boolean,
1471
+ codeSigning: boolean,
1472
+ emailProtection: boolean,
1473
+ timeStamping: boolean,
1474
+ ocspSigning: boolean,
1475
+ ipsecEndSystem: boolean,
1476
+ ipsecTunnel: boolean,
1477
+ ipsecUser: boolean,
1478
+ any: boolean
1479
+ }
1480
+
1334
1481
  /**************************************************************
1335
1482
  * Object with PKI Brazil specific fields.
1336
1483
  *
@@ -1599,30 +1746,49 @@ export interface SignerModel {
1599
1746
 
1600
1747
  export interface CadesSignerModel extends SignerModel {
1601
1748
  messageDigest: DigestModel,
1749
+ // TODO: next version
1750
+ // signingDescription?: string,
1602
1751
  }
1603
1752
 
1604
1753
  export interface PadesSignerModel extends SignerModel {
1605
1754
  messageDigest: DigestModel,
1606
1755
  isDocumentTimestamp: boolean,
1607
- signatureFieldName: string
1756
+ signatureFieldName: string,
1757
+ // TODO: next version
1758
+ // reason?: string,
1759
+ // location?: string,
1608
1760
  }
1609
1761
 
1610
1762
  export interface XmlSignerModel extends SignerModel {
1611
1763
  signatureElementId : string,
1612
1764
  type : LacunaWebPKI.XmlSignedEntityTypes,
1613
- signedElement : XmlElementModel
1765
+ signedElement : XmlElementModel,
1766
+ // TODO: next version
1767
+ // dataObjectFormat?: DataObjectFormatModel,
1614
1768
  }
1615
1769
 
1616
1770
  export interface CadesSignatureModel {
1617
1771
  encapsulatedContentType: LacunaWebPKI.CmsContentTypes,
1618
1772
  hasEncapsulatedContent: boolean,
1773
+ // TODO: next version
1774
+ // encapsulatedContent?: string,
1619
1775
  signers: CadesSignerModel[]
1620
1776
  }
1621
1777
 
1622
1778
  export interface PadesSignatureModel {
1779
+ // TODO: next version
1780
+ // pagesCount: number,
1781
+ // pdfAStandard?: LacunaWebPKI.PdfAStandards,
1782
+ // metadata?: { [key: string]: string; },
1623
1783
  signers: PadesSignerModel[]
1624
1784
  }
1625
1785
 
1786
+ export interface DataObjectFormatModel {
1787
+ description?: string,
1788
+ oid?: string,
1789
+ mimeType?: string,
1790
+ }
1791
+
1626
1792
  export interface XmlSignatureModel {
1627
1793
  signers: XmlSignerModel[]
1628
1794
  }
@@ -1747,6 +1913,11 @@ export interface SignHashBatchResponse {
1747
1913
  signatures: string[]
1748
1914
  }
1749
1915
 
1916
+ export interface SignHashesResponse {
1917
+ /** A Base64 encoded signatures array. */
1918
+ signatures: string[]
1919
+ }
1920
+
1750
1921
  // Visual Representation Types
1751
1922
 
1752
1923
  export interface VisualRepresentation {
@@ -1864,4 +2035,21 @@ export interface GeolocationInfo {
1864
2035
  timestamp: Date
1865
2036
  }
1866
2037
 
2038
+ export interface EncryptResponse {
2039
+ /** The encrypted data Base64 encoded */
2040
+ encrypted: string
2041
+ }
2042
+
2043
+ export interface DecryptResponse {
2044
+ /** The decrypted data Base64 encoded */
2045
+ decrypted: string
2046
+ }
2047
+
2048
+ export interface Hash {
2049
+ /** The hash algorithm name or OID */
2050
+ algorithm: string,
2051
+ /** The hash value in Base64 */
2052
+ value: string
2053
+ }
2054
+
1867
2055
 
package/lacuna-web-pki.js CHANGED
@@ -130,17 +130,17 @@ LacunaWebPKI = function (license) {
130
130
  $._edgeExtensionId = 'nedeegdmhlnmboboahchfpkmdnnemapd';
131
131
  $._edgeLegacyProductId = 'd2798a85-9698-425a-add7-3db79a39ca8a';
132
132
  $._chromeExtensionFirstVersionWithSelfUpdate = '2.0.20';
133
- $._jslibVersion = '2.15.2';
133
+ $._jslibVersion = '2.16.1';
134
134
  $._mobileSupported = 'true' === 'true';
135
135
  $._buildChannel = 'stable';
136
136
 
137
137
  // latest components version ----------------------
138
138
  $._extensionRequiredVersion = '2.16.0';
139
- $._chromeNativeWinRequiredVersion = '2.11.0';
140
- $._chromeNativeLinuxRequiredVersion = '2.12.1';
141
- $._chromeNativeMacRequiredVersion = '2.12.1';
142
- $._ieAddonRequiredVersion = '2.8.0';
143
- $._mobileRequiredVersion = '3.0.0';
139
+ $._chromeNativeWinRequiredVersion = '2.12.1';
140
+ $._chromeNativeLinuxRequiredVersion = '2.13.1';
141
+ $._chromeNativeMacRequiredVersion = '2.13.1';
142
+ $._ieAddonRequiredVersion = '2.9.1';
143
+ $._mobileRequiredVersion = '3.2.0';
144
144
  // ------------------------------------------------
145
145
 
146
146
  $._chromeInstallationStates = {
@@ -163,6 +163,19 @@ LacunaWebPKI = function (license) {
163
163
  nonRepudiation: 64
164
164
  };
165
165
 
166
+ $._certExtendedKeyUsages = {
167
+ clientAuth: 1,
168
+ serverAuth: 2,
169
+ codeSigning: 4,
170
+ emailProtection: 8,
171
+ timeStamping: 16,
172
+ ocspSigning: 32,
173
+ ipsecEndSystem: 64,
174
+ ipsecTunnel: 128,
175
+ ipsecUser: 256,
176
+ any: 512
177
+ };
178
+
166
179
  $.apiVersions = {
167
180
  v1_0: '1.0',
168
181
  v1_1: '1.1',
@@ -177,6 +190,8 @@ LacunaWebPKI = function (license) {
177
190
  v1_6_1: '1.6.1',
178
191
  v1_7_0: '1.7.0',
179
192
  v1_7_2: '1.7.2',
193
+ v1_8_0: '1.8.0',
194
+ v1_8_1: '1.8.1',
180
195
  latest: 'latest'
181
196
  };
182
197
 
@@ -203,6 +218,8 @@ LacunaWebPKI = function (license) {
203
218
  $._apiMap.nativeWin[$.apiVersions.v1_6_1] = '2.10.1';
204
219
  $._apiMap.nativeWin[$.apiVersions.v1_7_0] = '2.11.0';
205
220
  $._apiMap.nativeWin[$.apiVersions.v1_7_2] = '2.11.0';
221
+ $._apiMap.nativeWin[$.apiVersions.v1_8_0] = '2.12.0';
222
+ $._apiMap.nativeWin[$.apiVersions.v1_8_1] = '2.12.1';
206
223
 
207
224
  // IE
208
225
  $._apiMap.ieAddon[$.apiVersions.v1_0] = '2.0.4';
@@ -218,6 +235,8 @@ LacunaWebPKI = function (license) {
218
235
  $._apiMap.ieAddon[$.apiVersions.v1_6_1] = '2.7.2';
219
236
  $._apiMap.ieAddon[$.apiVersions.v1_7_0] = '2.8.0';
220
237
  $._apiMap.ieAddon[$.apiVersions.v1_7_2] = '2.8.0';
238
+ $._apiMap.ieAddon[$.apiVersions.v1_8_0] = '2.9.0';
239
+ $._apiMap.ieAddon[$.apiVersions.v1_8_1] = '2.9.1';
221
240
 
222
241
  // Linux
223
242
  $._apiMap.nativeLinux[$.apiVersions.v1_0] = '2.0.0';
@@ -233,6 +252,8 @@ LacunaWebPKI = function (license) {
233
252
  $._apiMap.nativeLinux[$.apiVersions.v1_6_1] = '2.10.0';
234
253
  $._apiMap.nativeLinux[$.apiVersions.v1_7_0] = '2.12.0';
235
254
  $._apiMap.nativeLinux[$.apiVersions.v1_7_2] = '2.12.1';
255
+ $._apiMap.nativeLinux[$.apiVersions.v1_8_0] = '2.13.0';
256
+ $._apiMap.nativeLinux[$.apiVersions.v1_8_1] = '2.13.1';
236
257
 
237
258
  // Mac
238
259
  $._apiMap.nativeMac[$.apiVersions.v1_0] = '2.3.0';
@@ -248,6 +269,8 @@ LacunaWebPKI = function (license) {
248
269
  $._apiMap.nativeMac[$.apiVersions.v1_6_1] = '2.10.0';
249
270
  $._apiMap.nativeMac[$.apiVersions.v1_7_0] = '2.12.0';
250
271
  $._apiMap.nativeMac[$.apiVersions.v1_7_2] = '2.12.1';
272
+ $._apiMap.nativeMac[$.apiVersions.v1_8_0] = '2.13.0';
273
+ $._apiMap.nativeMac[$.apiVersions.v1_8_1] = '2.13.1';
251
274
 
252
275
  // WebExtension
253
276
  $._apiMap.extension[$.apiVersions.v1_0] = '2.3.2';
@@ -263,6 +286,8 @@ LacunaWebPKI = function (license) {
263
286
  $._apiMap.extension[$.apiVersions.v1_6_1] = '2.15.0';
264
287
  $._apiMap.extension[$.apiVersions.v1_7_0] = '2.16.0';
265
288
  $._apiMap.extension[$.apiVersions.v1_7_2] = '2.16.0';
289
+ $._apiMap.extension[$.apiVersions.v1_8_0] = '2.16.0';
290
+ $._apiMap.extension[$.apiVersions.v1_8_1] = '2.16.0';
266
291
 
267
292
  // Mobile
268
293
  $._apiMap.mobile[$.apiVersions.v1_0] = '1.1.0';
@@ -278,6 +303,8 @@ LacunaWebPKI = function (license) {
278
303
  $._apiMap.mobile[$.apiVersions.v1_6_1] = '2.7.0';
279
304
  $._apiMap.mobile[$.apiVersions.v1_7_0] = '3.0.0';
280
305
  $._apiMap.mobile[$.apiVersions.v1_7_2] = '3.0.0';
306
+ $._apiMap.mobile[$.apiVersions.v1_8_0] = '3.2.0';
307
+ $._apiMap.mobile[$.apiVersions.v1_8_1] = '3.2.0';
281
308
 
282
309
  // All latest
283
310
  $._apiMap.nativeWin [$.apiVersions.latest] = $._chromeNativeWinRequiredVersion;
@@ -462,6 +489,14 @@ LacunaWebPKI = function (license) {
462
489
  browserIntegration: 'browserIntegration'
463
490
  };
464
491
 
492
+ $.encryptionParameters = {
493
+ rsaEncryptionPkcs1: 'RSAEncryptionPkcs1',
494
+ rsaEncryptionOaepSHA1: 'RSAEncryptionOaepSHA1',
495
+ rsaEncryptionOaepSHA256: 'RSAEncryptionOaepSHA256',
496
+ rsaEncryptionOaepSHA384: 'RSAEncryptionOaepSHA384',
497
+ rsaEncryptionOaepSHA512: 'RSAEncryptionOaepSHA512'
498
+ };
499
+
465
500
  $._parseDataUrl = function (url) {
466
501
  var match = /^data:(.+);base64,(.+)$/.exec(url);
467
502
  if (!match) {
@@ -536,6 +571,7 @@ LacunaWebPKI = function (license) {
536
571
  COMMAND_NOT_SUPPORTED: 'command_not_supported',
537
572
  COMMAND_PARAMETER_NOT_SET: 'command_parameter_not_set',
538
573
  COMMAND_INVALID_PARAMETER: 'command_invalid_parameter',
574
+ COMMAND_PARAMETER_NOT_SUPPORTED:'command_parameter_not_supported',
539
575
  NATIVE_CONNECT_FAILURE: 'native_connect_failure',
540
576
  NATIVE_DISCONNECTED: 'native_disconnected',
541
577
  NATIVE_NO_RESPONSE: 'native_no_response',
@@ -566,7 +602,8 @@ LacunaWebPKI = function (license) {
566
602
  MOBILE_NOT_AUTHORIZED: 'mobile_not_authorized',
567
603
  MOBILE_SEND_MESSAGE: 'mobile_send_message',
568
604
  COMMAND_DECRYPT_ERROR: 'command_decrypt_error',
569
- BLOCKED_DOMAIN: 'blocked_domain'
605
+ BLOCKED_DOMAIN: 'blocked_domain',
606
+ INVALID_OPERATION: 'invalid_operation'
570
607
  };
571
608
 
572
609
  // -------------------- "Private" static functions (no reference to 'this') --------------------
@@ -743,17 +780,22 @@ LacunaWebPKI = function (license) {
743
780
  return context.promise;
744
781
  };
745
782
 
783
+ $._processCertificate = function (cert) {
784
+ cert.validityStart = new Date(cert.validityStart);
785
+ cert.validityEnd = new Date(cert.validityEnd);
786
+ cert.keyUsage = $._processKeyUsage(cert.keyUsage);
787
+ cert.extendedKeyUsage = $._processExtendedKeyUsage(cert.extendedKeyUsage);
788
+ if (cert.pkiBrazil && cert.pkiBrazil.dateOfBirth) {
789
+ var s = cert.pkiBrazil.dateOfBirth;
790
+ cert.pkiBrazil.dateOfBirth = new Date(parseInt(s.slice(0, 4), 10), parseInt(s.slice(5, 7), 10) - 1, parseInt(s.slice(8, 10), 10));
791
+ }
792
+ };
793
+
746
794
  $._processCertificates = function (result, filter, selectId, selectOptionFormatter) {
747
795
  var toReturn = [];
748
796
  for (var i = 0; i < result.length; i++) {
749
797
  var cert = result[i];
750
- cert.validityStart = new Date(cert.validityStart);
751
- cert.validityEnd = new Date(cert.validityEnd);
752
- cert.keyUsage = $._processKeyUsage(cert.keyUsage);
753
- if (cert.pkiBrazil && cert.pkiBrazil.dateOfBirth) {
754
- var s = cert.pkiBrazil.dateOfBirth;
755
- cert.pkiBrazil.dateOfBirth = new Date(parseInt(s.slice(0, 4), 10), parseInt(s.slice(5, 7), 10) - 1, parseInt(s.slice(8, 10), 10));
756
- }
798
+ $._processCertificate(cert);
757
799
  if (filter) {
758
800
  if (filter(cert)) {
759
801
  toReturn.push(cert);
@@ -820,6 +862,73 @@ LacunaWebPKI = function (license) {
820
862
  };
821
863
  };
822
864
 
865
+ $._processExtendedKeyUsage = function (extendedKeyUsageValue) {
866
+ if (typeof extendedKeyUsageValue !== 'number') {
867
+ return null;
868
+ }
869
+ return {
870
+ clientAuth: (extendedKeyUsageValue & $._certExtendedKeyUsages.clientAuth) !== 0,
871
+ serverAuth: (extendedKeyUsageValue & $._certExtendedKeyUsages.serverAuth) !== 0,
872
+ codeSigning: (extendedKeyUsageValue & $._certExtendedKeyUsages.codeSigning) !== 0,
873
+ emailProtection: (extendedKeyUsageValue & $._certExtendedKeyUsages.emailProtection) !== 0,
874
+ timeStamping: (extendedKeyUsageValue & $._certExtendedKeyUsages.timeStamping) !== 0,
875
+ ocspSigning: (extendedKeyUsageValue & $._certExtendedKeyUsages.ocspSigning) !== 0,
876
+ ipsecEndSystem: (extendedKeyUsageValue & $._certExtendedKeyUsages.ipsecEndSystem) !== 0,
877
+ ipsecTunnel: (extendedKeyUsageValue & $._certExtendedKeyUsages.ipsecTunnel) !== 0,
878
+ ipsecUser: (extendedKeyUsageValue & $._certExtendedKeyUsages.ipsecUser) !== 0,
879
+ any: (extendedKeyUsageValue & $._certExtendedKeyUsages.any) !== 0
880
+ };
881
+ };
882
+
883
+ $._processSignResult = function (result) {
884
+ if (!result || !result.signatureInfo) {
885
+ return result;
886
+ }
887
+ if (result.signatureInfo.signerCertificate) {
888
+ $._processCertificate(result.signatureInfo.signerCertificate);
889
+ }
890
+ if (result.signatureInfo.signingTime) {
891
+ result.signatureInfo.signingTime = new Date(result.signatureInfo.signingTime);
892
+ }
893
+ return result;
894
+ };
895
+
896
+ $._processSignerModel = function (signer) {
897
+ if (!signer) {
898
+ return;
899
+ }
900
+ if (signer.certificate) {
901
+ $._processCertificate(signer.certificate);
902
+ }
903
+ if (signer.signingTime) {
904
+ signer.signingTime = new Date(signer.signingTime);
905
+ }
906
+ if (signer.certifiedDateReference) {
907
+ signer.certifiedDateReference = new Date(signer.certifiedDateReference);
908
+ }
909
+ if (signer.timestamps && signer.timestamps.length > 0) {
910
+ for (var i = 0; i < signer.timestamps.length; i++) {
911
+ var tst = signer.timestamps[i];
912
+ $._processOpenResult(tst);
913
+ }
914
+ }
915
+ };
916
+
917
+ $._processOpenResult = function (result) {
918
+ if (!result || !result.signers || result.signers.length <= 0) {
919
+ return result;
920
+ }
921
+ // case is a CadesTimestampModel
922
+ if (result.genTime) {
923
+ result.genTime = new Date(result.genTime);
924
+ }
925
+ for (var i = 0; i < result.signers.length; i++) {
926
+ var signer = result.signers[i];
927
+ $._processSignerModel(signer);
928
+ }
929
+ return result;
930
+ };
931
+
823
932
  $.filters = {
824
933
  isPkiBrazilPessoaFisica: function (cert) {
825
934
  if (typeof cert == 'undefined') {
@@ -1020,6 +1129,17 @@ LacunaWebPKI = function (license) {
1020
1129
  return context.promise;
1021
1130
  };
1022
1131
 
1132
+ // TODO: next version
1133
+ // $.signHashes = function (args) {
1134
+ // var context = this._createContext(args);
1135
+ // var request = {
1136
+ // certificateThumbprint: args.certificateThumbprint,
1137
+ // hashes: args.hashes
1138
+ // };
1139
+ // $._requestHandler.sendCommand(context, 'signHashes', request);
1140
+ // return context.promise;
1141
+ // };
1142
+
1023
1143
  $.preauthorizeSignatures = function (args) {
1024
1144
 
1025
1145
  if (!args) {
@@ -1165,14 +1285,31 @@ LacunaWebPKI = function (license) {
1165
1285
  request.visualRepresentation = args.visualRepresentation;
1166
1286
  request.pdfMarks = args.pdfMarks;
1167
1287
  request.bypassMarksIfSigned = args.bypassMarksIfSigned;
1288
+ request.reason = args.reason;
1289
+ request.location = args.location;
1290
+ request.signerName = args.signerName;
1291
+ request.customSignatureFieldName = args.customSignatureFieldName;
1292
+
1293
+ if (typeof args.metadata === 'object') {
1294
+ request.metadata = {};
1295
+ var metaKeys = Object.keys(args.metadata);
1296
+ for (var i=0; i<metaKeys.length; i++) {
1297
+ var curKey = metaKeys[i];
1298
+ // ensure string values only
1299
+ if (typeof args.metadata[curKey] != 'string') {
1300
+ throw 'Only string values allowed on metadata dictionary. Found type ' + typeof args.metadata[curKey] + ': ' + curKey + ':' + args.metadata[curKey];
1301
+ }
1302
+ request.metadata[curKey] = args.metadata[curKey];
1303
+ }
1304
+ }
1168
1305
 
1169
1306
  if (request.visualRepresentation && request.visualRepresentation.image && request.visualRepresentation.image.resource && !request.visualRepresentation.image.resource.content && request.visualRepresentation.image.resource.url && !/^(https?:)?\/\//.exec(request.visualRepresentation.image.resource.url)) {
1170
1307
  $._downloadResource(request.visualRepresentation.image.resource.url, function (resource) {
1171
1308
  request.visualRepresentation.image.resource = resource;
1172
- $._requestHandler.sendCommand(context, 'signPdf', request);
1309
+ $._requestHandler.sendCommand(context, 'signPdf', request, $._processSignResult);
1173
1310
  });
1174
1311
  } else {
1175
- $._requestHandler.sendCommand(context, 'signPdf', request);
1312
+ $._requestHandler.sendCommand(context, 'signPdf', request, $._processSignResult);
1176
1313
  }
1177
1314
  return context.promise;
1178
1315
  };
@@ -1181,10 +1318,12 @@ LacunaWebPKI = function (license) {
1181
1318
  var context = this._createContext(args);
1182
1319
  var request = $._createCommonSignerRequest(args);
1183
1320
  request.cmsToCosignFileId = args.cmsToCosignFileId;
1321
+ request.cmsToCosignContent = args.cmsToCosignContent;
1184
1322
  request.autoDetectCosign = args.autoDetectCosign;
1185
1323
  request.includeEncapsulatedContent = args.includeEncapsulatedContent === null || args.includeEncapsulatedContent === undefined ? true : args.includeEncapsulatedContent;
1324
+ request.signingDescription = args.signingDescription;
1186
1325
 
1187
- $._requestHandler.sendCommand(context, 'signCades', request);
1326
+ $._requestHandler.sendCommand(context, 'signCades', request, $._processSignResult);
1188
1327
  return context.promise;
1189
1328
  };
1190
1329
 
@@ -1212,6 +1351,7 @@ LacunaWebPKI = function (license) {
1212
1351
 
1213
1352
  $._signXmlCommon = function (args, request, context) {
1214
1353
  request.signatureElementId = args.signatureElementId;
1354
+ request.signingDescription = args.signingDescription;
1215
1355
 
1216
1356
  if (args.signatureElementLocation) {
1217
1357
  request.signatureElementLocation = {
@@ -1221,7 +1361,7 @@ LacunaWebPKI = function (license) {
1221
1361
  }
1222
1362
  request.namespaces = args.namespaces;
1223
1363
 
1224
- $._requestHandler.sendCommand(context, 'signXml', request);
1364
+ $._requestHandler.sendCommand(context, 'signXml', request, $._processSignResult);
1225
1365
  };
1226
1366
 
1227
1367
  $._createCommonOpenRequest = function(args) {
@@ -1240,7 +1380,7 @@ LacunaWebPKI = function (license) {
1240
1380
  var context = this._createContext(args);
1241
1381
  var request = $._createCommonOpenRequest(args);
1242
1382
 
1243
- $._requestHandler.sendCommand(context, 'openPades', request);
1383
+ $._requestHandler.sendCommand(context, 'openPades', request, $._processOpenResult);
1244
1384
  return context.promise;
1245
1385
  };
1246
1386
 
@@ -1250,8 +1390,9 @@ LacunaWebPKI = function (license) {
1250
1390
  request.originalFileId = args.originalFileId;
1251
1391
  request.originalContent = args.originalContent;
1252
1392
  request.acceptablePolicies = args.acceptablePolicies;
1393
+ request.returnEncapsulatedContent = args.returnEncapsulatedContent;
1253
1394
 
1254
- $._requestHandler.sendCommand(context, 'openCades', request);
1395
+ $._requestHandler.sendCommand(context, 'openCades', request, $._processOpenResult);
1255
1396
  return context.promise;
1256
1397
  };
1257
1398
 
@@ -1261,7 +1402,7 @@ LacunaWebPKI = function (license) {
1261
1402
  request.idResolutionTable = args.idResolutionTable;
1262
1403
  request.acceptablePolicies = args.acceptablePolicies;
1263
1404
 
1264
- $._requestHandler.sendCommand(context, 'openXmlSignature', request);
1405
+ $._requestHandler.sendCommand(context, 'openXmlSignature', request, $._processOpenResult);
1265
1406
  return context.promise;
1266
1407
  };
1267
1408
 
@@ -1282,7 +1423,8 @@ LacunaWebPKI = function (license) {
1282
1423
  subjectName: args.subjectName,
1283
1424
  tokenSerialNumber: args.tokenSerialNumber,
1284
1425
  keyLabel: args.keyLabel,
1285
- keySize: args.keySize
1426
+ keySize: args.keySize,
1427
+ enableUsedPkcs11Module: args.enableUsedPkcs11Module
1286
1428
  };
1287
1429
  $._handleP11ModulesArgs(args, request);
1288
1430
  $._requestHandler.sendCommand(context, 'generateTokenRsaKeyPair', request);
@@ -1293,7 +1435,8 @@ LacunaWebPKI = function (license) {
1293
1435
  var context = this._createContext(args);
1294
1436
  var request = {
1295
1437
  subjectName: args.subjectName,
1296
- keySize: args.keySize
1438
+ keySize: args.keySize,
1439
+ nonExportableKey: args.nonExportableKey
1297
1440
  };
1298
1441
  $._requestHandler.sendCommand(context, 'generateSoftwareRsaKeyPair', request);
1299
1442
  return context.promise;
@@ -1306,7 +1449,8 @@ LacunaWebPKI = function (license) {
1306
1449
  pkcs11Modules: $._getRequestOsP11Modules(args.pkcs11Modules),
1307
1450
  tokenSerialNumber: args.tokenSerialNumber,
1308
1451
  certificateContent: args.certificateContent,
1309
- certificateLabel: args.certificateLabel
1452
+ certificateLabel: args.certificateLabel,
1453
+ enableUsedPkcs11Module: args.enableUsedPkcs11Module
1310
1454
  };
1311
1455
  $._handleP11ModulesArgs(args, request);
1312
1456
  $._requestHandler.sendCommand(context, 'importTokenCertificate', request);
@@ -1348,6 +1492,37 @@ LacunaWebPKI = function (license) {
1348
1492
  return context.promise;
1349
1493
  };
1350
1494
 
1495
+ $.encrypt = function (args) {
1496
+ var token = typeof args.token === 'object' ? args.token : null;
1497
+ var context = this._createContext(args);
1498
+ var request = {
1499
+ certificateThumbprint: args.certificateThumbprint,
1500
+ publicKey: args.publicKey,
1501
+ privateKeyId: args.privateKeyId,
1502
+ tokenSerialNumber: token ? token.serialNumber : null,
1503
+ pkcs11Module: token ? token.pkcs11Module : null,
1504
+ parameters: args.parameters,
1505
+ data: args.data
1506
+ };
1507
+ $._requestHandler.sendCommand(context, 'encrypt', request);
1508
+ return context.promise;
1509
+ };
1510
+
1511
+ $.decrypt = function (args) {
1512
+ var token = typeof args.token === 'object' ? args.token : null;
1513
+ var context = this._createContext(args);
1514
+ var request = {
1515
+ certificateThumbprint: args.certificateThumbprint,
1516
+ privateKeyId: args.privateKeyId,
1517
+ tokenSerialNumber: token ? token.serialNumber : null,
1518
+ pkcs11Module: token ? token.pkcs11Module : null,
1519
+ parameters: args.parameters,
1520
+ data: args.data
1521
+ };
1522
+ $._requestHandler.sendCommand(context, 'decrypt', request);
1523
+ return context.promise;
1524
+ };
1525
+
1351
1526
 
1352
1527
  // -------------------- Browser detection --------------------
1353
1528
  // Based on http://stackoverflow.com/questions/2400935/browser-detection-in-javascript
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-pki",
3
- "version": "2.15.2",
3
+ "version": "2.16.1",
4
4
  "description": "The Lacuna Web PKI component enables web applications to interact with digital certificates through javascript, without the need of Java.",
5
5
  "main": "lacuna-web-pki.js",
6
6
  "types": "lacuna-web-pki.d.ts",