web-pki 2.15.2 → 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
  }
@@ -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. */
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.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.1';
141
- $._chromeNativeMacRequiredVersion = '2.12.1';
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',
@@ -177,6 +190,7 @@ 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',
180
194
  latest: 'latest'
181
195
  };
182
196
 
@@ -203,6 +217,7 @@ LacunaWebPKI = function (license) {
203
217
  $._apiMap.nativeWin[$.apiVersions.v1_6_1] = '2.10.1';
204
218
  $._apiMap.nativeWin[$.apiVersions.v1_7_0] = '2.11.0';
205
219
  $._apiMap.nativeWin[$.apiVersions.v1_7_2] = '2.11.0';
220
+ $._apiMap.nativeWin[$.apiVersions.v1_8_0] = '2.12.0';
206
221
 
207
222
  // IE
208
223
  $._apiMap.ieAddon[$.apiVersions.v1_0] = '2.0.4';
@@ -218,6 +233,7 @@ LacunaWebPKI = function (license) {
218
233
  $._apiMap.ieAddon[$.apiVersions.v1_6_1] = '2.7.2';
219
234
  $._apiMap.ieAddon[$.apiVersions.v1_7_0] = '2.8.0';
220
235
  $._apiMap.ieAddon[$.apiVersions.v1_7_2] = '2.8.0';
236
+ $._apiMap.ieAddon[$.apiVersions.v1_8_0] = '2.9.0';
221
237
 
222
238
  // Linux
223
239
  $._apiMap.nativeLinux[$.apiVersions.v1_0] = '2.0.0';
@@ -233,6 +249,7 @@ LacunaWebPKI = function (license) {
233
249
  $._apiMap.nativeLinux[$.apiVersions.v1_6_1] = '2.10.0';
234
250
  $._apiMap.nativeLinux[$.apiVersions.v1_7_0] = '2.12.0';
235
251
  $._apiMap.nativeLinux[$.apiVersions.v1_7_2] = '2.12.1';
252
+ $._apiMap.nativeLinux[$.apiVersions.v1_8_0] = '2.13.0';
236
253
 
237
254
  // Mac
238
255
  $._apiMap.nativeMac[$.apiVersions.v1_0] = '2.3.0';
@@ -248,6 +265,7 @@ LacunaWebPKI = function (license) {
248
265
  $._apiMap.nativeMac[$.apiVersions.v1_6_1] = '2.10.0';
249
266
  $._apiMap.nativeMac[$.apiVersions.v1_7_0] = '2.12.0';
250
267
  $._apiMap.nativeMac[$.apiVersions.v1_7_2] = '2.12.1';
268
+ $._apiMap.nativeMac[$.apiVersions.v1_8_0] = '2.13.0';
251
269
 
252
270
  // WebExtension
253
271
  $._apiMap.extension[$.apiVersions.v1_0] = '2.3.2';
@@ -263,6 +281,7 @@ LacunaWebPKI = function (license) {
263
281
  $._apiMap.extension[$.apiVersions.v1_6_1] = '2.15.0';
264
282
  $._apiMap.extension[$.apiVersions.v1_7_0] = '2.16.0';
265
283
  $._apiMap.extension[$.apiVersions.v1_7_2] = '2.16.0';
284
+ $._apiMap.extension[$.apiVersions.v1_8_0] = '2.16.0';
266
285
 
267
286
  // Mobile
268
287
  $._apiMap.mobile[$.apiVersions.v1_0] = '1.1.0';
@@ -278,6 +297,7 @@ LacunaWebPKI = function (license) {
278
297
  $._apiMap.mobile[$.apiVersions.v1_6_1] = '2.7.0';
279
298
  $._apiMap.mobile[$.apiVersions.v1_7_0] = '3.0.0';
280
299
  $._apiMap.mobile[$.apiVersions.v1_7_2] = '3.0.0';
300
+ $._apiMap.mobile[$.apiVersions.v1_8_0] = '3.2.0';
281
301
 
282
302
  // All latest
283
303
  $._apiMap.nativeWin [$.apiVersions.latest] = $._chromeNativeWinRequiredVersion;
@@ -462,6 +482,14 @@ LacunaWebPKI = function (license) {
462
482
  browserIntegration: 'browserIntegration'
463
483
  };
464
484
 
485
+ $.encryptionParameters = {
486
+ rsaEncryptionPkcs1: 'RSAEncryptionPkcs1',
487
+ rsaEncryptionOaepSHA1: 'RSAEncryptionOaepSHA1',
488
+ rsaEncryptionOaepSHA256: 'RSAEncryptionOaepSHA256',
489
+ rsaEncryptionOaepSHA384: 'RSAEncryptionOaepSHA384',
490
+ rsaEncryptionOaepSHA512: 'RSAEncryptionOaepSHA512'
491
+ };
492
+
465
493
  $._parseDataUrl = function (url) {
466
494
  var match = /^data:(.+);base64,(.+)$/.exec(url);
467
495
  if (!match) {
@@ -536,6 +564,7 @@ LacunaWebPKI = function (license) {
536
564
  COMMAND_NOT_SUPPORTED: 'command_not_supported',
537
565
  COMMAND_PARAMETER_NOT_SET: 'command_parameter_not_set',
538
566
  COMMAND_INVALID_PARAMETER: 'command_invalid_parameter',
567
+ COMMAND_PARAMETER_NOT_SUPPORTED:'command_parameter_not_supported',
539
568
  NATIVE_CONNECT_FAILURE: 'native_connect_failure',
540
569
  NATIVE_DISCONNECTED: 'native_disconnected',
541
570
  NATIVE_NO_RESPONSE: 'native_no_response',
@@ -566,7 +595,8 @@ LacunaWebPKI = function (license) {
566
595
  MOBILE_NOT_AUTHORIZED: 'mobile_not_authorized',
567
596
  MOBILE_SEND_MESSAGE: 'mobile_send_message',
568
597
  COMMAND_DECRYPT_ERROR: 'command_decrypt_error',
569
- BLOCKED_DOMAIN: 'blocked_domain'
598
+ BLOCKED_DOMAIN: 'blocked_domain',
599
+ INVALID_OPERATION: 'invalid_operation'
570
600
  };
571
601
 
572
602
  // -------------------- "Private" static functions (no reference to 'this') --------------------
@@ -743,17 +773,22 @@ LacunaWebPKI = function (license) {
743
773
  return context.promise;
744
774
  };
745
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
+
746
787
  $._processCertificates = function (result, filter, selectId, selectOptionFormatter) {
747
788
  var toReturn = [];
748
789
  for (var i = 0; i < result.length; i++) {
749
790
  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
- }
791
+ $._processCertificate(cert);
757
792
  if (filter) {
758
793
  if (filter(cert)) {
759
794
  toReturn.push(cert);
@@ -820,6 +855,70 @@ LacunaWebPKI = function (license) {
820
855
  };
821
856
  };
822
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
+
823
922
  $.filters = {
824
923
  isPkiBrazilPessoaFisica: function (cert) {
825
924
  if (typeof cert == 'undefined') {
@@ -1020,6 +1119,17 @@ LacunaWebPKI = function (license) {
1020
1119
  return context.promise;
1021
1120
  };
1022
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
+
1023
1133
  $.preauthorizeSignatures = function (args) {
1024
1134
 
1025
1135
  if (!args) {
@@ -1165,14 +1275,31 @@ LacunaWebPKI = function (license) {
1165
1275
  request.visualRepresentation = args.visualRepresentation;
1166
1276
  request.pdfMarks = args.pdfMarks;
1167
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
+ }
1168
1295
 
1169
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)) {
1170
1297
  $._downloadResource(request.visualRepresentation.image.resource.url, function (resource) {
1171
1298
  request.visualRepresentation.image.resource = resource;
1172
- $._requestHandler.sendCommand(context, 'signPdf', request);
1299
+ $._requestHandler.sendCommand(context, 'signPdf', request, $._processSignResult);
1173
1300
  });
1174
1301
  } else {
1175
- $._requestHandler.sendCommand(context, 'signPdf', request);
1302
+ $._requestHandler.sendCommand(context, 'signPdf', request, $._processSignResult);
1176
1303
  }
1177
1304
  return context.promise;
1178
1305
  };
@@ -1181,10 +1308,12 @@ LacunaWebPKI = function (license) {
1181
1308
  var context = this._createContext(args);
1182
1309
  var request = $._createCommonSignerRequest(args);
1183
1310
  request.cmsToCosignFileId = args.cmsToCosignFileId;
1311
+ request.cmsToCosignContent = args.cmsToCosignContent;
1184
1312
  request.autoDetectCosign = args.autoDetectCosign;
1185
1313
  request.includeEncapsulatedContent = args.includeEncapsulatedContent === null || args.includeEncapsulatedContent === undefined ? true : args.includeEncapsulatedContent;
1314
+ request.signingDescription = args.signingDescription;
1186
1315
 
1187
- $._requestHandler.sendCommand(context, 'signCades', request);
1316
+ $._requestHandler.sendCommand(context, 'signCades', request, $._processSignResult);
1188
1317
  return context.promise;
1189
1318
  };
1190
1319
 
@@ -1212,6 +1341,7 @@ LacunaWebPKI = function (license) {
1212
1341
 
1213
1342
  $._signXmlCommon = function (args, request, context) {
1214
1343
  request.signatureElementId = args.signatureElementId;
1344
+ request.signingDescription = args.signingDescription;
1215
1345
 
1216
1346
  if (args.signatureElementLocation) {
1217
1347
  request.signatureElementLocation = {
@@ -1221,7 +1351,7 @@ LacunaWebPKI = function (license) {
1221
1351
  }
1222
1352
  request.namespaces = args.namespaces;
1223
1353
 
1224
- $._requestHandler.sendCommand(context, 'signXml', request);
1354
+ $._requestHandler.sendCommand(context, 'signXml', request, $._processSignResult);
1225
1355
  };
1226
1356
 
1227
1357
  $._createCommonOpenRequest = function(args) {
@@ -1240,7 +1370,7 @@ LacunaWebPKI = function (license) {
1240
1370
  var context = this._createContext(args);
1241
1371
  var request = $._createCommonOpenRequest(args);
1242
1372
 
1243
- $._requestHandler.sendCommand(context, 'openPades', request);
1373
+ $._requestHandler.sendCommand(context, 'openPades', request, $._processOpenResult);
1244
1374
  return context.promise;
1245
1375
  };
1246
1376
 
@@ -1250,8 +1380,9 @@ LacunaWebPKI = function (license) {
1250
1380
  request.originalFileId = args.originalFileId;
1251
1381
  request.originalContent = args.originalContent;
1252
1382
  request.acceptablePolicies = args.acceptablePolicies;
1383
+ request.returnEncapsulatedContent = args.returnEncapsulatedContent;
1253
1384
 
1254
- $._requestHandler.sendCommand(context, 'openCades', request);
1385
+ $._requestHandler.sendCommand(context, 'openCades', request, $._processOpenResult);
1255
1386
  return context.promise;
1256
1387
  };
1257
1388
 
@@ -1261,7 +1392,7 @@ LacunaWebPKI = function (license) {
1261
1392
  request.idResolutionTable = args.idResolutionTable;
1262
1393
  request.acceptablePolicies = args.acceptablePolicies;
1263
1394
 
1264
- $._requestHandler.sendCommand(context, 'openXmlSignature', request);
1395
+ $._requestHandler.sendCommand(context, 'openXmlSignature', request, $._processOpenResult);
1265
1396
  return context.promise;
1266
1397
  };
1267
1398
 
@@ -1282,7 +1413,8 @@ LacunaWebPKI = function (license) {
1282
1413
  subjectName: args.subjectName,
1283
1414
  tokenSerialNumber: args.tokenSerialNumber,
1284
1415
  keyLabel: args.keyLabel,
1285
- keySize: args.keySize
1416
+ keySize: args.keySize,
1417
+ enableUsedPkcs11Module: args.enableUsedPkcs11Module
1286
1418
  };
1287
1419
  $._handleP11ModulesArgs(args, request);
1288
1420
  $._requestHandler.sendCommand(context, 'generateTokenRsaKeyPair', request);
@@ -1293,7 +1425,8 @@ LacunaWebPKI = function (license) {
1293
1425
  var context = this._createContext(args);
1294
1426
  var request = {
1295
1427
  subjectName: args.subjectName,
1296
- keySize: args.keySize
1428
+ keySize: args.keySize,
1429
+ nonExportableKey: args.nonExportableKey
1297
1430
  };
1298
1431
  $._requestHandler.sendCommand(context, 'generateSoftwareRsaKeyPair', request);
1299
1432
  return context.promise;
@@ -1306,7 +1439,8 @@ LacunaWebPKI = function (license) {
1306
1439
  pkcs11Modules: $._getRequestOsP11Modules(args.pkcs11Modules),
1307
1440
  tokenSerialNumber: args.tokenSerialNumber,
1308
1441
  certificateContent: args.certificateContent,
1309
- certificateLabel: args.certificateLabel
1442
+ certificateLabel: args.certificateLabel,
1443
+ enableUsedPkcs11Module: args.enableUsedPkcs11Module
1310
1444
  };
1311
1445
  $._handleP11ModulesArgs(args, request);
1312
1446
  $._requestHandler.sendCommand(context, 'importTokenCertificate', request);
@@ -1348,6 +1482,37 @@ LacunaWebPKI = function (license) {
1348
1482
  return context.promise;
1349
1483
  };
1350
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
+
1351
1516
 
1352
1517
  // -------------------- Browser detection --------------------
1353
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.2",
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",