web-pki 2.15.1 → 2.16.0

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
  }
@@ -942,7 +1050,9 @@ export namespace LacunaWebPKI {
942
1050
  v1_5_2 = '1.5.2',
943
1051
  v1_6 = '1.6.0',
944
1052
  v1_6_1 = '1.6.1',
945
- v1_7_0 = '1.7.0'
1053
+ v1_7_0 = '1.7.0',
1054
+ v1_7_2 = '1.7.2',
1055
+ v1_8_0 = '1.8.0'
946
1056
  }
947
1057
 
948
1058
  /**************************************************************
@@ -973,6 +1083,8 @@ export namespace LacunaWebPKI {
973
1083
  COMMAND_PARAMETER_NOT_SET = 'command_parameter_not_set',
974
1084
  /** A command parameter is not valid. */
975
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',
976
1088
  /** The web extension failed to connect to native component. */
977
1089
  NATIVE_CONNECT_FAILURE = 'native_connect_failure',
978
1090
  /** The native component disconnected from web extension. */
@@ -1020,7 +1132,8 @@ export namespace LacunaWebPKI {
1020
1132
  MOBILE_NOT_AUTHORIZED = 'mobile_not_authorized',
1021
1133
  MOBILE_SEND_MESSAGE = 'mobile_send_message',
1022
1134
  COMMAND_DECRYPT_ERROR = 'command_decrypt_error',
1023
- BLOCKED_DOMAIN = 'blocked_domain'
1135
+ BLOCKED_DOMAIN = 'blocked_domain',
1136
+ INVALID_OPERATION = 'invalid_operation'
1024
1137
  }
1025
1138
 
1026
1139
  export const enum CertificateTypes {
@@ -1149,6 +1262,18 @@ export namespace LacunaWebPKI {
1149
1262
  TstInfo = 'TstInfo',
1150
1263
  }
1151
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
+
1152
1277
  // visual representation
1153
1278
  export const enum PadesPaperSizes {
1154
1279
  Custom = 'custom',
@@ -1229,6 +1354,14 @@ export namespace LacunaWebPKI {
1229
1354
  Mutual = 'mutual'
1230
1355
  }
1231
1356
 
1357
+ export const enum EncryptionParamaters {
1358
+ RSAEncryptionPkcs1 = 'RSAEncryptionPkcs1',
1359
+ RSAEncryptionOaepSHA1 = 'RSAEncryptionOaepSHA1',
1360
+ RSAEncryptionOaepSHA256 = 'RSAEncryptionOaepSHA256',
1361
+ RSAEncryptionOaepSHA384 = 'RSAEncryptionOaepSHA384',
1362
+ RSAEncryptionOaepSHA512 = 'RSAEncryptionOaepSHA512'
1363
+ }
1364
+
1232
1365
 
1233
1366
 
1234
1367
  }
@@ -1298,6 +1431,8 @@ export interface CertificateModel {
1298
1431
  thumbprint: string,
1299
1432
  /** Object with boolean properties indicating wether each possible key usage is set on the certificate. */
1300
1433
  keyUsage: KeyUsagesModel,
1434
+ /** Object with boolean properties indicating wether each possible EXTENDED key usage is set on the certificate. */
1435
+ extendedKeyUsage: ExtendedKeyUsagesModel,
1301
1436
  /** Array with certificate policies info */
1302
1437
  certificatePolicies: CertificatePolicyModel[],
1303
1438
  /** Object with Brazil-specific fields. */
@@ -1330,6 +1465,19 @@ export interface KeyUsagesModel {
1330
1465
  nonRepudiation: boolean
1331
1466
  }
1332
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
+
1333
1481
  /**************************************************************
1334
1482
  * Object with PKI Brazil specific fields.
1335
1483
  *
@@ -1598,30 +1746,49 @@ export interface SignerModel {
1598
1746
 
1599
1747
  export interface CadesSignerModel extends SignerModel {
1600
1748
  messageDigest: DigestModel,
1749
+ // TODO: next version
1750
+ // signingDescription?: string,
1601
1751
  }
1602
1752
 
1603
1753
  export interface PadesSignerModel extends SignerModel {
1604
1754
  messageDigest: DigestModel,
1605
1755
  isDocumentTimestamp: boolean,
1606
- signatureFieldName: string
1756
+ signatureFieldName: string,
1757
+ // TODO: next version
1758
+ // reason?: string,
1759
+ // location?: string,
1607
1760
  }
1608
1761
 
1609
1762
  export interface XmlSignerModel extends SignerModel {
1610
1763
  signatureElementId : string,
1611
1764
  type : LacunaWebPKI.XmlSignedEntityTypes,
1612
- signedElement : XmlElementModel
1765
+ signedElement : XmlElementModel,
1766
+ // TODO: next version
1767
+ // dataObjectFormat?: DataObjectFormatModel,
1613
1768
  }
1614
1769
 
1615
1770
  export interface CadesSignatureModel {
1616
1771
  encapsulatedContentType: LacunaWebPKI.CmsContentTypes,
1617
1772
  hasEncapsulatedContent: boolean,
1773
+ // TODO: next version
1774
+ // encapsulatedContent?: string,
1618
1775
  signers: CadesSignerModel[]
1619
1776
  }
1620
1777
 
1621
1778
  export interface PadesSignatureModel {
1779
+ // TODO: next version
1780
+ // pagesCount: number,
1781
+ // pdfAStandard?: LacunaWebPKI.PdfAStandards,
1782
+ // metadata?: { [key: string]: string; },
1622
1783
  signers: PadesSignerModel[]
1623
1784
  }
1624
1785
 
1786
+ export interface DataObjectFormatModel {
1787
+ description?: string,
1788
+ oid?: string,
1789
+ mimeType?: string,
1790
+ }
1791
+
1625
1792
  export interface XmlSignatureModel {
1626
1793
  signers: XmlSignerModel[]
1627
1794
  }
@@ -1746,6 +1913,11 @@ export interface SignHashBatchResponse {
1746
1913
  signatures: string[]
1747
1914
  }
1748
1915
 
1916
+ export interface SignHashesResponse {
1917
+ /** A Base64 encoded signatures array. */
1918
+ signatures: string[]
1919
+ }
1920
+
1749
1921
  // Visual Representation Types
1750
1922
 
1751
1923
  export interface VisualRepresentation {
@@ -1863,4 +2035,21 @@ export interface GeolocationInfo {
1863
2035
  timestamp: Date
1864
2036
  }
1865
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
+
1866
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.1';
133
+ $._jslibVersion = '2.16.0';
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.0';
141
- $._chromeNativeMacRequiredVersion = '2.12.0';
142
- $._ieAddonRequiredVersion = '2.8.0';
143
- $._mobileRequiredVersion = '3.0.0';
139
+ $._chromeNativeWinRequiredVersion = '2.12.0';
140
+ $._chromeNativeLinuxRequiredVersion = '2.13.0';
141
+ $._chromeNativeMacRequiredVersion = '2.13.0';
142
+ $._ieAddonRequiredVersion = '2.9.0';
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',
@@ -176,6 +189,8 @@ LacunaWebPKI = function (license) {
176
189
  v1_6: '1.6.0',
177
190
  v1_6_1: '1.6.1',
178
191
  v1_7_0: '1.7.0',
192
+ v1_7_2: '1.7.2',
193
+ v1_8_0: '1.8.0',
179
194
  latest: 'latest'
180
195
  };
181
196
 
@@ -201,6 +216,8 @@ LacunaWebPKI = function (license) {
201
216
  $._apiMap.nativeWin[$.apiVersions.v1_6] = '2.10.0';
202
217
  $._apiMap.nativeWin[$.apiVersions.v1_6_1] = '2.10.1';
203
218
  $._apiMap.nativeWin[$.apiVersions.v1_7_0] = '2.11.0';
219
+ $._apiMap.nativeWin[$.apiVersions.v1_7_2] = '2.11.0';
220
+ $._apiMap.nativeWin[$.apiVersions.v1_8_0] = '2.12.0';
204
221
 
205
222
  // IE
206
223
  $._apiMap.ieAddon[$.apiVersions.v1_0] = '2.0.4';
@@ -215,6 +232,8 @@ LacunaWebPKI = function (license) {
215
232
  $._apiMap.ieAddon[$.apiVersions.v1_6] = '2.7.0';
216
233
  $._apiMap.ieAddon[$.apiVersions.v1_6_1] = '2.7.2';
217
234
  $._apiMap.ieAddon[$.apiVersions.v1_7_0] = '2.8.0';
235
+ $._apiMap.ieAddon[$.apiVersions.v1_7_2] = '2.8.0';
236
+ $._apiMap.ieAddon[$.apiVersions.v1_8_0] = '2.9.0';
218
237
 
219
238
  // Linux
220
239
  $._apiMap.nativeLinux[$.apiVersions.v1_0] = '2.0.0';
@@ -229,6 +248,8 @@ LacunaWebPKI = function (license) {
229
248
  $._apiMap.nativeLinux[$.apiVersions.v1_6] = '2.10.0';
230
249
  $._apiMap.nativeLinux[$.apiVersions.v1_6_1] = '2.10.0';
231
250
  $._apiMap.nativeLinux[$.apiVersions.v1_7_0] = '2.12.0';
251
+ $._apiMap.nativeLinux[$.apiVersions.v1_7_2] = '2.12.1';
252
+ $._apiMap.nativeLinux[$.apiVersions.v1_8_0] = '2.13.0';
232
253
 
233
254
  // Mac
234
255
  $._apiMap.nativeMac[$.apiVersions.v1_0] = '2.3.0';
@@ -243,6 +264,8 @@ LacunaWebPKI = function (license) {
243
264
  $._apiMap.nativeMac[$.apiVersions.v1_6] = '2.10.0';
244
265
  $._apiMap.nativeMac[$.apiVersions.v1_6_1] = '2.10.0';
245
266
  $._apiMap.nativeMac[$.apiVersions.v1_7_0] = '2.12.0';
267
+ $._apiMap.nativeMac[$.apiVersions.v1_7_2] = '2.12.1';
268
+ $._apiMap.nativeMac[$.apiVersions.v1_8_0] = '2.13.0';
246
269
 
247
270
  // WebExtension
248
271
  $._apiMap.extension[$.apiVersions.v1_0] = '2.3.2';
@@ -257,6 +280,8 @@ LacunaWebPKI = function (license) {
257
280
  $._apiMap.extension[$.apiVersions.v1_6] = '2.15.0';
258
281
  $._apiMap.extension[$.apiVersions.v1_6_1] = '2.15.0';
259
282
  $._apiMap.extension[$.apiVersions.v1_7_0] = '2.16.0';
283
+ $._apiMap.extension[$.apiVersions.v1_7_2] = '2.16.0';
284
+ $._apiMap.extension[$.apiVersions.v1_8_0] = '2.16.0';
260
285
 
261
286
  // Mobile
262
287
  $._apiMap.mobile[$.apiVersions.v1_0] = '1.1.0';
@@ -271,6 +296,8 @@ LacunaWebPKI = function (license) {
271
296
  $._apiMap.mobile[$.apiVersions.v1_6] = '2.7.0';
272
297
  $._apiMap.mobile[$.apiVersions.v1_6_1] = '2.7.0';
273
298
  $._apiMap.mobile[$.apiVersions.v1_7_0] = '3.0.0';
299
+ $._apiMap.mobile[$.apiVersions.v1_7_2] = '3.0.0';
300
+ $._apiMap.mobile[$.apiVersions.v1_8_0] = '3.2.0';
274
301
 
275
302
  // All latest
276
303
  $._apiMap.nativeWin [$.apiVersions.latest] = $._chromeNativeWinRequiredVersion;
@@ -455,6 +482,14 @@ LacunaWebPKI = function (license) {
455
482
  browserIntegration: 'browserIntegration'
456
483
  };
457
484
 
485
+ $.encryptionParameters = {
486
+ rsaEncryptionPkcs1: 'RSAEncryptionPkcs1',
487
+ rsaEncryptionOaepSHA1: 'RSAEncryptionOaepSHA1',
488
+ rsaEncryptionOaepSHA256: 'RSAEncryptionOaepSHA256',
489
+ rsaEncryptionOaepSHA384: 'RSAEncryptionOaepSHA384',
490
+ rsaEncryptionOaepSHA512: 'RSAEncryptionOaepSHA512'
491
+ };
492
+
458
493
  $._parseDataUrl = function (url) {
459
494
  var match = /^data:(.+);base64,(.+)$/.exec(url);
460
495
  if (!match) {
@@ -529,6 +564,7 @@ LacunaWebPKI = function (license) {
529
564
  COMMAND_NOT_SUPPORTED: 'command_not_supported',
530
565
  COMMAND_PARAMETER_NOT_SET: 'command_parameter_not_set',
531
566
  COMMAND_INVALID_PARAMETER: 'command_invalid_parameter',
567
+ COMMAND_PARAMETER_NOT_SUPPORTED:'command_parameter_not_supported',
532
568
  NATIVE_CONNECT_FAILURE: 'native_connect_failure',
533
569
  NATIVE_DISCONNECTED: 'native_disconnected',
534
570
  NATIVE_NO_RESPONSE: 'native_no_response',
@@ -559,7 +595,8 @@ LacunaWebPKI = function (license) {
559
595
  MOBILE_NOT_AUTHORIZED: 'mobile_not_authorized',
560
596
  MOBILE_SEND_MESSAGE: 'mobile_send_message',
561
597
  COMMAND_DECRYPT_ERROR: 'command_decrypt_error',
562
- BLOCKED_DOMAIN: 'blocked_domain'
598
+ BLOCKED_DOMAIN: 'blocked_domain',
599
+ INVALID_OPERATION: 'invalid_operation'
563
600
  };
564
601
 
565
602
  // -------------------- "Private" static functions (no reference to 'this') --------------------
@@ -736,17 +773,22 @@ LacunaWebPKI = function (license) {
736
773
  return context.promise;
737
774
  };
738
775
 
776
+ $._processCertificate = function (cert) {
777
+ cert.validityStart = new Date(cert.validityStart);
778
+ cert.validityEnd = new Date(cert.validityEnd);
779
+ cert.keyUsage = $._processKeyUsage(cert.keyUsage);
780
+ cert.extendedKeyUsage = $._processExtendedKeyUsage(cert.extendedKeyUsage || 0);
781
+ if (cert.pkiBrazil && cert.pkiBrazil.dateOfBirth) {
782
+ var s = cert.pkiBrazil.dateOfBirth;
783
+ cert.pkiBrazil.dateOfBirth = new Date(parseInt(s.slice(0, 4), 10), parseInt(s.slice(5, 7), 10) - 1, parseInt(s.slice(8, 10), 10));
784
+ }
785
+ };
786
+
739
787
  $._processCertificates = function (result, filter, selectId, selectOptionFormatter) {
740
788
  var toReturn = [];
741
789
  for (var i = 0; i < result.length; i++) {
742
790
  var cert = result[i];
743
- cert.validityStart = new Date(cert.validityStart);
744
- cert.validityEnd = new Date(cert.validityEnd);
745
- cert.keyUsage = $._processKeyUsage(cert.keyUsage);
746
- if (cert.pkiBrazil && cert.pkiBrazil.dateOfBirth) {
747
- var s = cert.pkiBrazil.dateOfBirth;
748
- cert.pkiBrazil.dateOfBirth = new Date(parseInt(s.slice(0, 4), 10), parseInt(s.slice(5, 7), 10) - 1, parseInt(s.slice(8, 10), 10));
749
- }
791
+ $._processCertificate(cert);
750
792
  if (filter) {
751
793
  if (filter(cert)) {
752
794
  toReturn.push(cert);
@@ -813,6 +855,70 @@ LacunaWebPKI = function (license) {
813
855
  };
814
856
  };
815
857
 
858
+ $._processExtendedKeyUsage = function (extendedKeyUsageValue) {
859
+ return {
860
+ clientAuth: (extendedKeyUsageValue & $._certExtendedKeyUsages.clientAuth) !== 0,
861
+ serverAuth: (extendedKeyUsageValue & $._certExtendedKeyUsages.serverAuth) !== 0,
862
+ codeSigning: (extendedKeyUsageValue & $._certExtendedKeyUsages.codeSigning) !== 0,
863
+ emailProtection: (extendedKeyUsageValue & $._certExtendedKeyUsages.emailProtection) !== 0,
864
+ timeStamping: (extendedKeyUsageValue & $._certExtendedKeyUsages.timeStamping) !== 0,
865
+ ocspSigning: (extendedKeyUsageValue & $._certExtendedKeyUsages.ocspSigning) !== 0,
866
+ ipsecEndSystem: (extendedKeyUsageValue & $._certExtendedKeyUsages.ipsecEndSystem) !== 0,
867
+ ipsecTunnel: (extendedKeyUsageValue & $._certExtendedKeyUsages.ipsecTunnel) !== 0,
868
+ ipsecUser: (extendedKeyUsageValue & $._certExtendedKeyUsages.ipsecUser) !== 0,
869
+ any: (extendedKeyUsageValue & $._certExtendedKeyUsages.any) !== 0
870
+ };
871
+ };
872
+
873
+ $._processSignResult = function (result) {
874
+ if (!result || !result.signatureInfo) {
875
+ return result;
876
+ }
877
+ if (result.signatureInfo.signerCertificate) {
878
+ $._processCertificate(result.signatureInfo.signerCertificate);
879
+ }
880
+ if (result.signatureInfo.signingTime) {
881
+ result.signatureInfo.signingTime = new Date(result.signatureInfo.signingTime);
882
+ }
883
+ return result;
884
+ };
885
+
886
+ $._processSignerModel = function (signer) {
887
+ if (!signer) {
888
+ return;
889
+ }
890
+ if (signer.certificate) {
891
+ $._processCertificate(signer.certificate);
892
+ }
893
+ if (signer.signingTime) {
894
+ signer.signingTime = new Date(signer.signingTime);
895
+ }
896
+ if (signer.certifiedDateReference) {
897
+ signer.certifiedDateReference = new Date(signer.certifiedDateReference);
898
+ }
899
+ if (signer.timestamps && signer.timestamps.length > 0) {
900
+ for (var i = 0; i < signer.timestamps.length; i++) {
901
+ var tst = signer.timestamps[i];
902
+ $._processOpenResult(tst);
903
+ }
904
+ }
905
+ };
906
+
907
+ $._processOpenResult = function (result) {
908
+ if (!result || !result.signers || result.signers.length <= 0) {
909
+ return result;
910
+ }
911
+ // case is a CadesTimestampModel
912
+ if (result.genTime) {
913
+ result.genTime = new Date(result.genTime);
914
+ }
915
+ for (var i = 0; i < result.signers.length; i++) {
916
+ var signer = result.signers[i];
917
+ $._processSignerModel(signer);
918
+ }
919
+ return result;
920
+ };
921
+
816
922
  $.filters = {
817
923
  isPkiBrazilPessoaFisica: function (cert) {
818
924
  if (typeof cert == 'undefined') {
@@ -1013,6 +1119,17 @@ LacunaWebPKI = function (license) {
1013
1119
  return context.promise;
1014
1120
  };
1015
1121
 
1122
+ // TODO: next version
1123
+ // $.signHashes = function (args) {
1124
+ // var context = this._createContext(args);
1125
+ // var request = {
1126
+ // certificateThumbprint: args.certificateThumbprint,
1127
+ // hashes: args.hashes
1128
+ // };
1129
+ // $._requestHandler.sendCommand(context, 'signHashes', request);
1130
+ // return context.promise;
1131
+ // };
1132
+
1016
1133
  $.preauthorizeSignatures = function (args) {
1017
1134
 
1018
1135
  if (!args) {
@@ -1158,14 +1275,31 @@ LacunaWebPKI = function (license) {
1158
1275
  request.visualRepresentation = args.visualRepresentation;
1159
1276
  request.pdfMarks = args.pdfMarks;
1160
1277
  request.bypassMarksIfSigned = args.bypassMarksIfSigned;
1278
+ request.reason = args.reason;
1279
+ request.location = args.location;
1280
+ request.signerName = args.signerName;
1281
+ request.customSignatureFieldName = args.customSignatureFieldName;
1282
+
1283
+ if (typeof args.metadata === 'object') {
1284
+ request.metadata = {};
1285
+ var metaKeys = Object.keys(args.metadata);
1286
+ for (var i=0; i<metaKeys.length; i++) {
1287
+ var curKey = metaKeys[i];
1288
+ // ensure string values only
1289
+ if (typeof args.metadata[curKey] != 'string') {
1290
+ throw 'Only string values allowed on metadata dictionary. Found type ' + typeof args.metadata[curKey] + ': ' + curKey + ':' + args.metadata[curKey];
1291
+ }
1292
+ request.metadata[curKey] = args.metadata[curKey];
1293
+ }
1294
+ }
1161
1295
 
1162
1296
  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)) {
1163
1297
  $._downloadResource(request.visualRepresentation.image.resource.url, function (resource) {
1164
1298
  request.visualRepresentation.image.resource = resource;
1165
- $._requestHandler.sendCommand(context, 'signPdf', request);
1299
+ $._requestHandler.sendCommand(context, 'signPdf', request, $._processSignResult);
1166
1300
  });
1167
1301
  } else {
1168
- $._requestHandler.sendCommand(context, 'signPdf', request);
1302
+ $._requestHandler.sendCommand(context, 'signPdf', request, $._processSignResult);
1169
1303
  }
1170
1304
  return context.promise;
1171
1305
  };
@@ -1174,10 +1308,12 @@ LacunaWebPKI = function (license) {
1174
1308
  var context = this._createContext(args);
1175
1309
  var request = $._createCommonSignerRequest(args);
1176
1310
  request.cmsToCosignFileId = args.cmsToCosignFileId;
1311
+ request.cmsToCosignContent = args.cmsToCosignContent;
1177
1312
  request.autoDetectCosign = args.autoDetectCosign;
1178
1313
  request.includeEncapsulatedContent = args.includeEncapsulatedContent === null || args.includeEncapsulatedContent === undefined ? true : args.includeEncapsulatedContent;
1314
+ request.signingDescription = args.signingDescription;
1179
1315
 
1180
- $._requestHandler.sendCommand(context, 'signCades', request);
1316
+ $._requestHandler.sendCommand(context, 'signCades', request, $._processSignResult);
1181
1317
  return context.promise;
1182
1318
  };
1183
1319
 
@@ -1205,6 +1341,7 @@ LacunaWebPKI = function (license) {
1205
1341
 
1206
1342
  $._signXmlCommon = function (args, request, context) {
1207
1343
  request.signatureElementId = args.signatureElementId;
1344
+ request.signingDescription = args.signingDescription;
1208
1345
 
1209
1346
  if (args.signatureElementLocation) {
1210
1347
  request.signatureElementLocation = {
@@ -1214,7 +1351,7 @@ LacunaWebPKI = function (license) {
1214
1351
  }
1215
1352
  request.namespaces = args.namespaces;
1216
1353
 
1217
- $._requestHandler.sendCommand(context, 'signXml', request);
1354
+ $._requestHandler.sendCommand(context, 'signXml', request, $._processSignResult);
1218
1355
  };
1219
1356
 
1220
1357
  $._createCommonOpenRequest = function(args) {
@@ -1233,7 +1370,7 @@ LacunaWebPKI = function (license) {
1233
1370
  var context = this._createContext(args);
1234
1371
  var request = $._createCommonOpenRequest(args);
1235
1372
 
1236
- $._requestHandler.sendCommand(context, 'openPades', request);
1373
+ $._requestHandler.sendCommand(context, 'openPades', request, $._processOpenResult);
1237
1374
  return context.promise;
1238
1375
  };
1239
1376
 
@@ -1243,8 +1380,9 @@ LacunaWebPKI = function (license) {
1243
1380
  request.originalFileId = args.originalFileId;
1244
1381
  request.originalContent = args.originalContent;
1245
1382
  request.acceptablePolicies = args.acceptablePolicies;
1383
+ request.returnEncapsulatedContent = args.returnEncapsulatedContent;
1246
1384
 
1247
- $._requestHandler.sendCommand(context, 'openCades', request);
1385
+ $._requestHandler.sendCommand(context, 'openCades', request, $._processOpenResult);
1248
1386
  return context.promise;
1249
1387
  };
1250
1388
 
@@ -1254,7 +1392,7 @@ LacunaWebPKI = function (license) {
1254
1392
  request.idResolutionTable = args.idResolutionTable;
1255
1393
  request.acceptablePolicies = args.acceptablePolicies;
1256
1394
 
1257
- $._requestHandler.sendCommand(context, 'openXmlSignature', request);
1395
+ $._requestHandler.sendCommand(context, 'openXmlSignature', request, $._processOpenResult);
1258
1396
  return context.promise;
1259
1397
  };
1260
1398
 
@@ -1275,7 +1413,8 @@ LacunaWebPKI = function (license) {
1275
1413
  subjectName: args.subjectName,
1276
1414
  tokenSerialNumber: args.tokenSerialNumber,
1277
1415
  keyLabel: args.keyLabel,
1278
- keySize: args.keySize
1416
+ keySize: args.keySize,
1417
+ enableUsedPkcs11Module: args.enableUsedPkcs11Module
1279
1418
  };
1280
1419
  $._handleP11ModulesArgs(args, request);
1281
1420
  $._requestHandler.sendCommand(context, 'generateTokenRsaKeyPair', request);
@@ -1286,7 +1425,8 @@ LacunaWebPKI = function (license) {
1286
1425
  var context = this._createContext(args);
1287
1426
  var request = {
1288
1427
  subjectName: args.subjectName,
1289
- keySize: args.keySize
1428
+ keySize: args.keySize,
1429
+ nonExportableKey: args.nonExportableKey
1290
1430
  };
1291
1431
  $._requestHandler.sendCommand(context, 'generateSoftwareRsaKeyPair', request);
1292
1432
  return context.promise;
@@ -1299,7 +1439,8 @@ LacunaWebPKI = function (license) {
1299
1439
  pkcs11Modules: $._getRequestOsP11Modules(args.pkcs11Modules),
1300
1440
  tokenSerialNumber: args.tokenSerialNumber,
1301
1441
  certificateContent: args.certificateContent,
1302
- certificateLabel: args.certificateLabel
1442
+ certificateLabel: args.certificateLabel,
1443
+ enableUsedPkcs11Module: args.enableUsedPkcs11Module
1303
1444
  };
1304
1445
  $._handleP11ModulesArgs(args, request);
1305
1446
  $._requestHandler.sendCommand(context, 'importTokenCertificate', request);
@@ -1341,6 +1482,37 @@ LacunaWebPKI = function (license) {
1341
1482
  return context.promise;
1342
1483
  };
1343
1484
 
1485
+ $.encrypt = function (args) {
1486
+ var token = typeof args.token === 'object' ? args.token : null;
1487
+ var context = this._createContext(args);
1488
+ var request = {
1489
+ certificateThumbprint: args.certificateThumbprint,
1490
+ publicKey: args.publicKey,
1491
+ privateKeyId: args.privateKeyId,
1492
+ tokenSerialNumber: token ? token.serialNumber : null,
1493
+ pkcs11Module: token ? token.pkcs11Module : null,
1494
+ parameters: args.parameters,
1495
+ data: args.data
1496
+ };
1497
+ $._requestHandler.sendCommand(context, 'encrypt', request);
1498
+ return context.promise;
1499
+ };
1500
+
1501
+ $.decrypt = function (args) {
1502
+ var token = typeof args.token === 'object' ? args.token : null;
1503
+ var context = this._createContext(args);
1504
+ var request = {
1505
+ certificateThumbprint: args.certificateThumbprint,
1506
+ privateKeyId: args.privateKeyId,
1507
+ tokenSerialNumber: token ? token.serialNumber : null,
1508
+ pkcs11Module: token ? token.pkcs11Module : null,
1509
+ parameters: args.parameters,
1510
+ data: args.data
1511
+ };
1512
+ $._requestHandler.sendCommand(context, 'decrypt', request);
1513
+ return context.promise;
1514
+ };
1515
+
1344
1516
 
1345
1517
  // -------------------- Browser detection --------------------
1346
1518
  // 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.1",
3
+ "version": "2.16.0",
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",