From 6e38068862936a6d377d45a4d4be3d231666239b Mon Sep 17 00:00:00 2001 From: Long Nguyen Date: Sun, 23 Apr 2023 23:12:43 +0700 Subject: [PATCH] init --- .../linux/flutter/generated_plugins.cmake | 8 + .../Flutter/GeneratedPluginRegistrant.swift | 2 +- .../example/pubspec.lock | 255 ++++++++++++++++++ .../windows/flutter/generated_plugins.cmake | 8 + packages/syncfusion_flutter_pdf/lib/pdf.dart | 5 +- .../forms/pdf_signature_field.dart | 255 +++++------------- .../digital_signature/pdf_certificate.dart | 1 + .../digital_signature/pdf_signature.dart | 1 + .../pdf_signature_dictionary.dart | 239 ++++++---------- packages/syncfusion_flutter_pdf/pubspec.lock | 220 +++++++++++++++ 10 files changed, 645 insertions(+), 349 deletions(-) create mode 100644 packages/syncfusion_flutter_pdf/example/pubspec.lock create mode 100644 packages/syncfusion_flutter_pdf/pubspec.lock diff --git a/packages/syncfusion_flutter_pdf/example/linux/flutter/generated_plugins.cmake b/packages/syncfusion_flutter_pdf/example/linux/flutter/generated_plugins.cmake index 51436ae8c..2e1de87a7 100644 --- a/packages/syncfusion_flutter_pdf/example/linux/flutter/generated_plugins.cmake +++ b/packages/syncfusion_flutter_pdf/example/linux/flutter/generated_plugins.cmake @@ -5,6 +5,9 @@ list(APPEND FLUTTER_PLUGIN_LIST ) +list(APPEND FLUTTER_FFI_PLUGIN_LIST +) + set(PLUGIN_BUNDLED_LIBRARIES) foreach(plugin ${FLUTTER_PLUGIN_LIST}) @@ -13,3 +16,8 @@ foreach(plugin ${FLUTTER_PLUGIN_LIST}) list(APPEND PLUGIN_BUNDLED_LIBRARIES $) list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) endforeach(plugin) + +foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) + add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin}) + list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) +endforeach(ffi_plugin) diff --git a/packages/syncfusion_flutter_pdf/example/macos/Flutter/GeneratedPluginRegistrant.swift b/packages/syncfusion_flutter_pdf/example/macos/Flutter/GeneratedPluginRegistrant.swift index 0d56f519c..e777c67df 100644 --- a/packages/syncfusion_flutter_pdf/example/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/packages/syncfusion_flutter_pdf/example/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,7 +5,7 @@ import FlutterMacOS import Foundation -import path_provider_macos +import path_provider_foundation func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) diff --git a/packages/syncfusion_flutter_pdf/example/pubspec.lock b/packages/syncfusion_flutter_pdf/example/pubspec.lock new file mode 100644 index 000000000..6ebe9fd1b --- /dev/null +++ b/packages/syncfusion_flutter_pdf/example/pubspec.lock @@ -0,0 +1,255 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + characters: + dependency: transitive + description: + name: characters + sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c + url: "https://pub.dev" + source: hosted + version: "1.2.1" + clock: + dependency: transitive + description: + name: clock + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" + source: hosted + version: "1.1.1" + collection: + dependency: transitive + description: + name: collection + sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0 + url: "https://pub.dev" + source: hosted + version: "1.17.0" + convert: + dependency: transitive + description: + name: convert + sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592" + url: "https://pub.dev" + source: hosted + version: "3.1.1" + crypto: + dependency: transitive + description: + name: crypto + sha256: aa274aa7774f8964e4f4f38cc994db7b6158dd36e9187aaceaddc994b35c6c67 + url: "https://pub.dev" + source: hosted + version: "3.0.2" + ffi: + dependency: transitive + description: + name: ffi + sha256: "13a6ccf6a459a125b3fcdb6ec73bd5ff90822e071207c663bfd1f70062d51d18" + url: "https://pub.dev" + source: hosted + version: "1.2.1" + file: + dependency: transitive + description: + name: file + sha256: "1b92bec4fc2a72f59a8e15af5f52cd441e4a7860b49499d69dfa817af20e925d" + url: "https://pub.dev" + source: hosted + version: "6.1.4" + flutter: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + intl: + dependency: transitive + description: + name: intl + sha256: "3bc132a9dbce73a7e4a21a17d06e1878839ffbf975568bc875c60537824b0c4d" + url: "https://pub.dev" + source: hosted + version: "0.18.1" + js: + dependency: transitive + description: + name: js + sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7" + url: "https://pub.dev" + source: hosted + version: "0.6.5" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724 + url: "https://pub.dev" + source: hosted + version: "0.2.0" + meta: + dependency: transitive + description: + name: meta + sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42" + url: "https://pub.dev" + source: hosted + version: "1.8.0" + open_file: + dependency: "direct main" + description: + name: open_file + sha256: "5cd0288033d613ee7908aa974b7ff00805ae55d253f64d311603cf2e30613ca8" + url: "https://pub.dev" + source: hosted + version: "3.2.1" + path: + dependency: transitive + description: + name: path + sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + url: "https://pub.dev" + source: hosted + version: "1.8.3" + path_provider: + dependency: "direct main" + description: + name: path_provider + sha256: c7edf82217d4b2952b2129a61d3ad60f1075b9299e629e149a8d2e39c2e6aad4 + url: "https://pub.dev" + source: hosted + version: "2.0.14" + path_provider_android: + dependency: transitive + description: + name: path_provider_android + sha256: da97262be945a72270513700a92b39dd2f4a54dad55d061687e2e37a6390366a + url: "https://pub.dev" + source: hosted + version: "2.0.25" + path_provider_foundation: + dependency: transitive + description: + name: path_provider_foundation + sha256: ad4c4d011830462633f03eb34445a45345673dfd4faf1ab0b4735fbd93b19183 + url: "https://pub.dev" + source: hosted + version: "2.2.2" + path_provider_linux: + dependency: transitive + description: + name: path_provider_linux + sha256: "2ae08f2216225427e64ad224a24354221c2c7907e448e6e0e8b57b1eb9f10ad1" + url: "https://pub.dev" + source: hosted + version: "2.1.10" + path_provider_platform_interface: + dependency: transitive + description: + name: path_provider_platform_interface + sha256: "57585299a729335f1298b43245842678cb9f43a6310351b18fb577d6e33165ec" + url: "https://pub.dev" + source: hosted + version: "2.0.6" + path_provider_windows: + dependency: transitive + description: + name: path_provider_windows + sha256: a34ecd7fb548f8e57321fd8e50d865d266941b54e6c3b7758cf8f37c24116905 + url: "https://pub.dev" + source: hosted + version: "2.0.7" + petitparser: + dependency: transitive + description: + name: petitparser + sha256: "49392a45ced973e8d94a85fdb21293fbb40ba805fc49f2965101ae748a3683b4" + url: "https://pub.dev" + source: hosted + version: "5.1.0" + platform: + dependency: transitive + description: + name: platform + sha256: "4a451831508d7d6ca779f7ac6e212b4023dd5a7d08a27a63da33756410e32b76" + url: "https://pub.dev" + source: hosted + version: "3.1.0" + plugin_platform_interface: + dependency: transitive + description: + name: plugin_platform_interface + sha256: "6a2128648c854906c53fa8e33986fc0247a1116122f9534dd20e3ab9e16a32bc" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + process: + dependency: transitive + description: + name: process + sha256: "53fd8db9cec1d37b0574e12f07520d582019cb6c44abf5479a01505099a34a09" + url: "https://pub.dev" + source: hosted + version: "4.2.4" + sky_engine: + dependency: transitive + description: flutter + source: sdk + version: "0.0.99" + syncfusion_flutter_core: + dependency: transitive + description: + name: syncfusion_flutter_core + sha256: "05b079cb1be26a8d5c1afe714172d2eed9178049f4a7dc773b2cbb8b053eff8d" + url: "https://pub.dev" + source: hosted + version: "21.1.41" + syncfusion_flutter_pdf: + dependency: "direct main" + description: + path: ".." + relative: true + source: path + version: "21.1.35" + typed_data: + dependency: transitive + description: + name: typed_data + sha256: "26f87ade979c47a150c9eaab93ccd2bebe70a27dc0b4b29517f2904f04eb11a5" + url: "https://pub.dev" + source: hosted + version: "1.3.1" + vector_math: + dependency: transitive + description: + name: vector_math + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + win32: + dependency: transitive + description: + name: win32 + sha256: c0e3a4f7be7dae51d8f152230b86627e3397c1ba8c3fa58e63d44a9f3edc9cef + url: "https://pub.dev" + source: hosted + version: "2.6.1" + xdg_directories: + dependency: transitive + description: + name: xdg_directories + sha256: ee1505df1426458f7f60aac270645098d318a8b4766d85fde75f76f2e21807d1 + url: "https://pub.dev" + source: hosted + version: "1.0.0" + xml: + dependency: transitive + description: + name: xml + sha256: "979ee37d622dec6365e2efa4d906c37470995871fe9ae080d967e192d88286b5" + url: "https://pub.dev" + source: hosted + version: "6.2.2" +sdks: + dart: ">=2.18.0 <3.0.0" + flutter: ">=3.3.0" diff --git a/packages/syncfusion_flutter_pdf/example/windows/flutter/generated_plugins.cmake b/packages/syncfusion_flutter_pdf/example/windows/flutter/generated_plugins.cmake index 4d10c2518..b93c4c30c 100644 --- a/packages/syncfusion_flutter_pdf/example/windows/flutter/generated_plugins.cmake +++ b/packages/syncfusion_flutter_pdf/example/windows/flutter/generated_plugins.cmake @@ -5,6 +5,9 @@ list(APPEND FLUTTER_PLUGIN_LIST ) +list(APPEND FLUTTER_FFI_PLUGIN_LIST +) + set(PLUGIN_BUNDLED_LIBRARIES) foreach(plugin ${FLUTTER_PLUGIN_LIST}) @@ -13,3 +16,8 @@ foreach(plugin ${FLUTTER_PLUGIN_LIST}) list(APPEND PLUGIN_BUNDLED_LIBRARIES $) list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) endforeach(plugin) + +foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) + add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin}) + list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) +endforeach(ffi_plugin) diff --git a/packages/syncfusion_flutter_pdf/lib/pdf.dart b/packages/syncfusion_flutter_pdf/lib/pdf.dart index eb5cdb8cd..238461371 100644 --- a/packages/syncfusion_flutter_pdf/lib/pdf.dart +++ b/packages/syncfusion_flutter_pdf/lib/pdf.dart @@ -217,11 +217,14 @@ export 'src/pdf/implementation/pdf_document/pdf_document_template.dart' show PdfDocumentTemplate, PdfStampCollection; export 'src/pdf/implementation/pdf_document/pdf_file_structure.dart' show PdfFileStructure; +export 'src/pdf/implementation/primitives/pdf_number.dart' show PdfNumber; +export 'src/pdf/implementation/primitives/pdf_string.dart' show PdfString; export 'src/pdf/implementation/security/digital_signature/pdf_certificate.dart' show PdfCertificate; export 'src/pdf/implementation/security/digital_signature/pdf_external_signer.dart'; export 'src/pdf/implementation/security/digital_signature/pdf_signature.dart' show PdfSignature; +export 'src/pdf/implementation/security/digital_signature/pdf_signature_dictionary.dart' show PdfSignatureDictionary; export 'src/pdf/implementation/security/enum.dart'; export 'src/pdf/implementation/security/pdf_security.dart' show PdfPermissions, PdfSecurity; @@ -276,4 +279,4 @@ export 'src/pdf/implementation/structured_elements/lists/pdf_list_layouter.dart' export 'src/pdf/implementation/structured_elements/lists/pdf_ordered_list.dart' show PdfOrderedList; export 'src/pdf/implementation/structured_elements/lists/pdf_unordered_list.dart' - show PdfUnorderedList; + show PdfUnorderedList; \ No newline at end of file diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_signature_field.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_signature_field.dart index 1404c512d..bb5ec54fd 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_signature_field.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_signature_field.dart @@ -31,29 +31,14 @@ import 'pdf_form.dart'; class PdfSignatureField extends PdfField { //Constructor /// Initializes a new instance of the [PdfSignatureField] class. - PdfSignatureField(PdfPage page, String name, - {Rect bounds = Rect.zero, - int borderWidth = 1, - PdfHighlightMode? highlightMode, - PdfSignature? signature, - String? tooltip}) { + PdfSignatureField(PdfPage page, String name, {Rect bounds = Rect.zero, int borderWidth = 1, PdfHighlightMode? highlightMode, PdfSignature? signature, String? tooltip}) { _helper = PdfSignatureFieldHelper(this); - _helper.internal(page, name, bounds, - borderWidth: borderWidth, - highlightMode: highlightMode, - tooltip: tooltip); + _helper.internal(page, name, bounds, borderWidth: borderWidth, highlightMode: highlightMode, tooltip: tooltip); form!.fieldAutoNaming - ? PdfAnnotationHelper.getHelper(_helper.widget!) - .dictionary! - .setProperty(PdfDictionaryProperties.ft, - PdfName(PdfDictionaryProperties.sig)) - : _helper.dictionary!.setProperty( - PdfDictionaryProperties.ft, PdfName(PdfDictionaryProperties.sig)); + ? PdfAnnotationHelper.getHelper(_helper.widget!).dictionary!.setProperty(PdfDictionaryProperties.ft, PdfName(PdfDictionaryProperties.sig)) + : _helper.dictionary!.setProperty(PdfDictionaryProperties.ft, PdfName(PdfDictionaryProperties.sig)); if (PdfPageHelper.getHelper(page).document != null) { - PdfFormHelper.getHelper(form!).signatureFlags = [ - SignatureFlags.signaturesExists, - SignatureFlags.appendOnly - ]; + PdfFormHelper.getHelper(form!).signatureFlags = [SignatureFlags.signaturesExists, SignatureFlags.appendOnly]; } if (signature != null) { this.signature = signature; @@ -108,63 +93,39 @@ class PdfSignatureField extends PdfField { if (value != null) { _signature = value; PdfSignatureHelper.getHelper(_signature!).page = page; - PdfSignatureHelper.getHelper(_signature!).document = - PdfPageHelper.getHelper( - PdfSignatureHelper.getHelper(_signature!).page!) - .document; - PdfSignatureHelper.getHelper(_signature!) - .checkAnnotationElementsContainsSignature(page!, name); + PdfSignatureHelper.getHelper(_signature!).document = PdfPageHelper.getHelper(PdfSignatureHelper.getHelper(_signature!).page!).document; + PdfSignatureHelper.getHelper(_signature!).checkAnnotationElementsContainsSignature(page!, name); PdfSignatureHelper.getHelper(_signature!).field = this; - PdfDocumentHelper.getHelper( - PdfSignatureHelper.getHelper(_signature!).document!) - .catalog - .beginSave = - PdfSignatureHelper.getHelper(_signature!).catalogBeginSave; + PdfDocumentHelper.getHelper(PdfSignatureHelper.getHelper(_signature!).document!).catalog.beginSave = PdfSignatureHelper.getHelper(_signature!).catalogBeginSave; _helper.dictionary!.beginSaveList ??= []; - _helper.dictionary!.beginSaveList! - .add(PdfSignatureHelper.getHelper(_signature!).dictionaryBeginSave); + _helper.dictionary!.beginSaveList!.add(PdfSignatureHelper.getHelper(_signature!).dictionaryBeginSave); + print('hello'); if (!_helper.skipKidsCertificate) { - final PdfDocument document = - PdfSignatureHelper.getHelper(_signature!).document!; - PdfSignatureHelper.getHelper(_signature!).signatureDictionary = - PdfSignatureDictionary(document, _signature!); - final PdfSignatureDictionary signatureDictionary = - PdfSignatureHelper.getHelper(_signature!).signatureDictionary!; - if (!PdfDocumentHelper.getHelper(document).isLoadedDocument || - document.fileStructure.incrementalUpdate != false) { + print('hello1'); + final PdfDocument document = PdfSignatureHelper.getHelper(_signature!).document!; + PdfSignatureHelper.getHelper(_signature!).signatureDictionary = PdfSignatureDictionary(document, _signature!); + final PdfSignatureDictionary signatureDictionary = PdfSignatureHelper.getHelper(_signature!).signatureDictionary!; + if (!PdfDocumentHelper.getHelper(document).isLoadedDocument || document.fileStructure.incrementalUpdate != false) { signatureDictionary.dictionary!.archive = false; - PdfDocumentHelper.getHelper(document) - .objects - .add(signatureDictionary.element); - PdfDocumentHelper.getHelper(document) - .objects[PdfDocumentHelper.getHelper(document).objects.count - 1] - .isModified = true; + PdfDocumentHelper.getHelper(document).objects.add(signatureDictionary.element); + PdfDocumentHelper.getHelper(document).objects[PdfDocumentHelper.getHelper(document).objects.count - 1].isModified = true; signatureDictionary.element!.position = -1; } if (_helper.isLoadedField) { - PdfFormHelper.getHelper(form!).signatureFlags = [ - SignatureFlags.signaturesExists, - SignatureFlags.appendOnly - ]; - final PdfDictionary widget = _helper.getWidgetAnnotation( - _helper.dictionary!, _helper.crossTable); - widget[PdfDictionaryProperties.v] = - PdfReferenceHolder(signatureDictionary); + PdfFormHelper.getHelper(form!).signatureFlags = [SignatureFlags.signaturesExists, SignatureFlags.appendOnly]; + final PdfDictionary widget = _helper.getWidgetAnnotation(_helper.dictionary!, _helper.crossTable); + widget[PdfDictionaryProperties.v] = PdfReferenceHolder(signatureDictionary); widget.modify(); _helper.changed = true; widget.setProperty(PdfDictionaryProperties.fieldFlags, PdfNumber(0)); signatureDictionary.dictionary!.archive = false; } else { - final PdfDictionary widget = - PdfAnnotationHelper.getHelper(_helper.widget!).dictionary!; - widget.setProperty(PdfDictionaryProperties.v, - PdfReferenceHolder(signatureDictionary)); + final PdfDictionary widget = PdfAnnotationHelper.getHelper(_helper.widget!).dictionary!; + widget.setProperty(PdfDictionaryProperties.v, PdfReferenceHolder(signatureDictionary)); widget.setProperty(PdfDictionaryProperties.fieldFlags, PdfNumber(0)); } } else { - PdfAnnotationHelper.getHelper(_helper.widget!) - .dictionary! - .setProperty(PdfDictionaryProperties.fieldFlags, PdfNumber(0)); + PdfAnnotationHelper.getHelper(_helper.widget!).dictionary!.setProperty(PdfDictionaryProperties.fieldFlags, PdfNumber(0)); } _helper.widget!.bounds = bounds; } @@ -172,17 +133,13 @@ class PdfSignatureField extends PdfField { void _setSignature(IPdfPrimitive? signature) { final PdfCrossTable? crossTable = _helper.crossTable; - if (signature is PdfReferenceHolder && - signature.object != null && - signature.object is PdfDictionary) { - final PdfDictionary signatureDictionary = - signature.object! as PdfDictionary; + if (signature is PdfReferenceHolder && signature.object != null && signature.object is PdfDictionary) { + final PdfDictionary signatureDictionary = signature.object! as PdfDictionary; _signature = PdfSignature(); PdfSignatureHelper.getHelper(_signature!).document = crossTable!.document; String? subFilterType = ''; if (signatureDictionary.containsKey(PdfDictionaryProperties.subFilter)) { - final IPdfPrimitive? filter = PdfCrossTable.dereference( - signatureDictionary[PdfDictionaryProperties.subFilter]); + final IPdfPrimitive? filter = PdfCrossTable.dereference(signatureDictionary[PdfDictionaryProperties.subFilter]); if (filter != null && filter is PdfName) { subFilterType = filter.name; } @@ -190,119 +147,72 @@ class PdfSignatureField extends PdfField { _signature!.cryptographicStandard = CryptographicStandard.cades; } } - if (crossTable.document != null && - !PdfDocumentHelper.getHelper(crossTable.document!).isLoadedDocument) { - if (signatureDictionary - .containsKey(PdfDictionaryProperties.reference)) { - final IPdfPrimitive? tempArray = - signatureDictionary[PdfDictionaryProperties.reference]; + if (crossTable.document != null && !PdfDocumentHelper.getHelper(crossTable.document!).isLoadedDocument) { + if (signatureDictionary.containsKey(PdfDictionaryProperties.reference)) { + final IPdfPrimitive? tempArray = signatureDictionary[PdfDictionaryProperties.reference]; if (tempArray != null && tempArray is PdfArray) { final IPdfPrimitive? tempDictionary = tempArray.elements[0]; if (tempDictionary != null && tempDictionary is PdfDictionary) { if (tempDictionary.containsKey(PdfDictionaryProperties.data)) { - final PdfMainObjectCollection mainObjectCollection = - PdfDocumentHelper.getHelper(crossTable.document!).objects; - IPdfPrimitive? tempReferenceHolder = - tempDictionary[PdfDictionaryProperties.data]; - if (tempReferenceHolder != null && - tempReferenceHolder is PdfReferenceHolder && - !mainObjectCollection - .containsReference(tempReferenceHolder.reference!)) { - final IPdfPrimitive? tempObject = mainObjectCollection - .objectCollection![ - tempReferenceHolder.reference!.objectCollectionIndex!] - .object; + final PdfMainObjectCollection mainObjectCollection = PdfDocumentHelper.getHelper(crossTable.document!).objects; + IPdfPrimitive? tempReferenceHolder = tempDictionary[PdfDictionaryProperties.data]; + if (tempReferenceHolder != null && tempReferenceHolder is PdfReferenceHolder && !mainObjectCollection.containsReference(tempReferenceHolder.reference!)) { + final IPdfPrimitive? tempObject = mainObjectCollection.objectCollection![tempReferenceHolder.reference!.objectCollectionIndex!].object; tempReferenceHolder = PdfReferenceHolder(tempObject); - tempDictionary.setProperty( - PdfDictionaryProperties.data, tempReferenceHolder); + tempDictionary.setProperty(PdfDictionaryProperties.data, tempReferenceHolder); } } } } } signatureDictionary.remove(PdfDictionaryProperties.byteRange); - PdfSignatureDictionary.fromDictionary( - crossTable.document!, signatureDictionary); + PdfSignatureDictionary.fromDictionary(crossTable.document!, signatureDictionary); _helper.dictionary!.remove(PdfDictionaryProperties.contents); _helper.dictionary!.remove(PdfDictionaryProperties.byteRange); } - if (signatureDictionary.containsKey(PdfDictionaryProperties.m) && - signatureDictionary[PdfDictionaryProperties.m] is PdfString) { - PdfSignatureHelper.getHelper(_signature!).dateOfSign = - _helper.dictionary!.getDateTime( - signatureDictionary[PdfDictionaryProperties.m]! as PdfString); + if (signatureDictionary.containsKey(PdfDictionaryProperties.m) && signatureDictionary[PdfDictionaryProperties.m] is PdfString) { + PdfSignatureHelper.getHelper(_signature!).dateOfSign = _helper.dictionary!.getDateTime(signatureDictionary[PdfDictionaryProperties.m]! as PdfString); } - if (signatureDictionary.containsKey(PdfDictionaryProperties.name) && - signatureDictionary[PdfDictionaryProperties.name] is PdfString) { - _signature!.signedName = - (signatureDictionary[PdfDictionaryProperties.name]! as PdfString) - .value; + if (signatureDictionary.containsKey(PdfDictionaryProperties.name) && signatureDictionary[PdfDictionaryProperties.name] is PdfString) { + _signature!.signedName = (signatureDictionary[PdfDictionaryProperties.name]! as PdfString).value; } if (signatureDictionary.containsKey(PdfDictionaryProperties.reason)) { - final IPdfPrimitive? reason = PdfCrossTable.dereference( - signatureDictionary[PdfDictionaryProperties.reason]); + final IPdfPrimitive? reason = PdfCrossTable.dereference(signatureDictionary[PdfDictionaryProperties.reason]); if (reason != null && reason is PdfString) { _signature!.reason = reason.value; } } if (signatureDictionary.containsKey(PdfDictionaryProperties.location)) { - final IPdfPrimitive? location = PdfCrossTable.dereference( - signatureDictionary[PdfDictionaryProperties.location]); + final IPdfPrimitive? location = PdfCrossTable.dereference(signatureDictionary[PdfDictionaryProperties.location]); if (location != null && location is PdfString) { _signature!.locationInfo = location.value; } } - if (signatureDictionary - .containsKey(PdfDictionaryProperties.contactInfo)) { - final IPdfPrimitive? contactInfo = PdfCrossTable.dereference( - signatureDictionary[PdfDictionaryProperties.contactInfo]); + if (signatureDictionary.containsKey(PdfDictionaryProperties.contactInfo)) { + final IPdfPrimitive? contactInfo = PdfCrossTable.dereference(signatureDictionary[PdfDictionaryProperties.contactInfo]); if (contactInfo != null && contactInfo is PdfString) { _signature!.contactInfo = contactInfo.value; } } if (signatureDictionary.containsKey(PdfDictionaryProperties.byteRange)) { - PdfSignatureHelper.getHelper(_signature!).byteRange = - signatureDictionary[PdfDictionaryProperties.byteRange] as PdfArray?; + PdfSignatureHelper.getHelper(_signature!).byteRange = signatureDictionary[PdfDictionaryProperties.byteRange] as PdfArray?; if (crossTable.documentCatalog != null) { final PdfDictionary catalog = crossTable.documentCatalog!; bool hasPermission = false; if (catalog.containsKey(PdfDictionaryProperties.perms)) { - final IPdfPrimitive? primitive = - catalog[PdfDictionaryProperties.perms]; - final IPdfPrimitive? catalogDictionary = - (primitive is PdfReferenceHolder) - ? primitive.object - : primitive; - if (catalogDictionary != null && - catalogDictionary is PdfDictionary && - catalogDictionary.containsKey(PdfDictionaryProperties.docMDP)) { - final IPdfPrimitive? docPermission = - catalogDictionary[PdfDictionaryProperties.docMDP]; - final IPdfPrimitive? permissionDictionary = - (docPermission is PdfReferenceHolder) - ? docPermission.object - : docPermission; - if (permissionDictionary != null && - permissionDictionary is PdfDictionary && - permissionDictionary - .containsKey(PdfDictionaryProperties.byteRange)) { - final IPdfPrimitive? byteRange = PdfCrossTable.dereference( - permissionDictionary[PdfDictionaryProperties.byteRange]); + final IPdfPrimitive? primitive = catalog[PdfDictionaryProperties.perms]; + final IPdfPrimitive? catalogDictionary = (primitive is PdfReferenceHolder) ? primitive.object : primitive; + if (catalogDictionary != null && catalogDictionary is PdfDictionary && catalogDictionary.containsKey(PdfDictionaryProperties.docMDP)) { + final IPdfPrimitive? docPermission = catalogDictionary[PdfDictionaryProperties.docMDP]; + final IPdfPrimitive? permissionDictionary = (docPermission is PdfReferenceHolder) ? docPermission.object : docPermission; + if (permissionDictionary != null && permissionDictionary is PdfDictionary && permissionDictionary.containsKey(PdfDictionaryProperties.byteRange)) { + final IPdfPrimitive? byteRange = PdfCrossTable.dereference(permissionDictionary[PdfDictionaryProperties.byteRange]); bool isValid = true; - if (byteRange != null && - byteRange is PdfArray && - _signature != null && - PdfSignatureHelper.getHelper(_signature!).byteRange != - null) { + if (byteRange != null && byteRange is PdfArray && _signature != null && PdfSignatureHelper.getHelper(_signature!).byteRange != null) { for (int i = 0; i < byteRange.count; i++) { final IPdfPrimitive? byteValue = byteRange[i]; - final IPdfPrimitive? signByte = - PdfSignatureHelper.getHelper(_signature!).byteRange![i]; - if (byteValue != null && - signByte != null && - byteValue is PdfNumber && - signByte is PdfNumber && - byteValue.value != signByte.value) { + final IPdfPrimitive? signByte = PdfSignatureHelper.getHelper(_signature!).byteRange![i]; + if (byteValue != null && signByte != null && byteValue is PdfNumber && signByte is PdfNumber && byteValue.value != signByte.value) { isValid = false; break; } @@ -312,35 +222,24 @@ class PdfSignatureField extends PdfField { } } } - if (hasPermission && - signatureDictionary - .containsKey(PdfDictionaryProperties.reference)) { - IPdfPrimitive? primitive = - signatureDictionary[PdfDictionaryProperties.reference]; + if (hasPermission && signatureDictionary.containsKey(PdfDictionaryProperties.reference)) { + IPdfPrimitive? primitive = signatureDictionary[PdfDictionaryProperties.reference]; if (primitive is PdfArray) { primitive = primitive.elements[0]; } - IPdfPrimitive? reference = (primitive is PdfReferenceHolder) - ? primitive.object - : primitive; - if (reference != null && - reference is PdfDictionary && - reference.containsKey('TransformParams')) { + IPdfPrimitive? reference = (primitive is PdfReferenceHolder) ? primitive.object : primitive; + if (reference != null && reference is PdfDictionary && reference.containsKey('TransformParams')) { primitive = reference['TransformParams']; if (primitive is PdfReferenceHolder) { reference = primitive.object as PdfDictionary?; } else if (primitive is PdfDictionary) { reference = primitive; } - if (reference is PdfDictionary && - reference.containsKey(PdfDictionaryProperties.p)) { - final IPdfPrimitive? permissionNumber = - PdfCrossTable.dereference( - reference[PdfDictionaryProperties.p]); + if (reference is PdfDictionary && reference.containsKey(PdfDictionaryProperties.p)) { + final IPdfPrimitive? permissionNumber = PdfCrossTable.dereference(reference[PdfDictionaryProperties.p]); if (permissionNumber != null && permissionNumber is PdfNumber) { - _signature!.documentPermissions = - PdfSignatureHelper.getHelper(_signature!) - .getCertificateFlags(permissionNumber.value! as int); + print('permissionNumber.value'); + _signature!.documentPermissions = PdfSignatureHelper.getHelper(_signature!).getCertificateFlags(permissionNumber.value!.toInt()); } } } @@ -365,8 +264,7 @@ class PdfSignatureFieldHelper extends PdfFieldHelper { } /// internal method - static PdfSignatureField loadSignatureField( - PdfDictionary dictionary, PdfCrossTable crossTable) { + static PdfSignatureField loadSignatureField(PdfDictionary dictionary, PdfCrossTable crossTable) { return PdfSignatureField._(dictionary, crossTable); } @@ -380,36 +278,28 @@ class PdfSignatureFieldHelper extends PdfFieldHelper { if (!isLoadedField) { super.draw(); if (PdfAnnotationHelper.getHelper(widget!).appearance != null) { - signatureField.page!.graphics.drawPdfTemplate( - widget!.appearance.normal, signatureField.bounds.topLeft); + signatureField.page!.graphics.drawPdfTemplate(widget!.appearance.normal, signatureField.bounds.topLeft); } } else if (flattenField) { if (dictionary![PdfDictionaryProperties.ap] != null) { - final IPdfPrimitive? tempDictionary = - dictionary![PdfDictionaryProperties.ap]; - final IPdfPrimitive? appearanceDictionary = - PdfCrossTable.dereference(tempDictionary); + final IPdfPrimitive? tempDictionary = dictionary![PdfDictionaryProperties.ap]; + final IPdfPrimitive? appearanceDictionary = PdfCrossTable.dereference(tempDictionary); PdfTemplate template; - if (appearanceDictionary != null && - appearanceDictionary is PdfDictionary) { - final IPdfPrimitive? appearanceRefHolder = - appearanceDictionary[PdfDictionaryProperties.n]; - final IPdfPrimitive? objectDictionary = - PdfCrossTable.dereference(appearanceRefHolder); + if (appearanceDictionary != null && appearanceDictionary is PdfDictionary) { + final IPdfPrimitive? appearanceRefHolder = appearanceDictionary[PdfDictionaryProperties.n]; + final IPdfPrimitive? objectDictionary = PdfCrossTable.dereference(appearanceRefHolder); if (objectDictionary != null && objectDictionary is PdfDictionary) { if (objectDictionary is PdfStream) { final PdfStream stream = objectDictionary; template = PdfTemplateHelper.fromPdfStream(stream); - signatureField.page!.graphics - .drawPdfTemplate(template, signatureField.bounds.topLeft); + signatureField.page!.graphics.drawPdfTemplate(template, signatureField.bounds.topLeft); } } } } else { //signature field without appearance dictionary final PdfBrush brush = PdfSolidBrush(getBackColor(true)); - final GraphicsProperties graphicsProperties = - GraphicsProperties(signatureField); + final GraphicsProperties graphicsProperties = GraphicsProperties(signatureField); final PaintParams paintingParameters = PaintParams( bounds: graphicsProperties.bounds, backBrush: brush, @@ -418,8 +308,7 @@ class PdfSignatureFieldHelper extends PdfFieldHelper { style: graphicsProperties.style, borderWidth: graphicsProperties.borderWidth, shadowBrush: graphicsProperties.shadowBrush); - FieldPainter() - .drawSignature(signatureField.page!.graphics, paintingParameters); + FieldPainter().drawSignature(signatureField.page!.graphics, paintingParameters); } } } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/security/digital_signature/pdf_certificate.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/security/digital_signature/pdf_certificate.dart index 249839a97..19a5b4cc6 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/security/digital_signature/pdf_certificate.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/security/digital_signature/pdf_certificate.dart @@ -52,6 +52,7 @@ class PdfCertificate { isContinue = false; } }); + print(certificateAlias); final X509Certificates entry = _pkcsCertificate.getCertificate(certificateAlias)!; _loadDetails(entry.certificate!); diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/security/digital_signature/pdf_signature.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/security/digital_signature/pdf_signature.dart index 7e634fc89..cf7deafc7 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/security/digital_signature/pdf_signature.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/security/digital_signature/pdf_signature.dart @@ -40,6 +40,7 @@ class PdfSignature { //Fields late PdfSignatureHelper _helper; + PdfSignatureHelper get helper => _helper; List>? _externalRootCert; //Properties diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/security/digital_signature/pdf_signature_dictionary.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/security/digital_signature/pdf_signature_dictionary.dart index 4a33ec0a9..ed17d7c2e 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/security/digital_signature/pdf_signature_dictionary.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/security/digital_signature/pdf_signature_dictionary.dart @@ -42,8 +42,7 @@ class PdfSignatureDictionary implements IPdfWrapper { _doc = doc; _sig = sig; if (PdfDocumentHelper.getHelper(doc).documentSavedList == null) { - PdfDocumentHelper.getHelper(doc).documentSavedList = - []; + PdfDocumentHelper.getHelper(doc).documentSavedList = []; } PdfDocumentHelper.getHelper(doc).documentSavedList!.add(_documentSaved); dictionary!.beginSaveList ??= []; @@ -54,8 +53,7 @@ class PdfSignatureDictionary implements IPdfWrapper { /// internal constructor PdfSignatureDictionary.fromDictionary(PdfDocument doc, this.dictionary) { _doc = doc; - List? documentSavedList = - PdfDocumentHelper.getHelper(doc).documentSavedList; + List? documentSavedList = PdfDocumentHelper.getHelper(doc).documentSavedList; documentSavedList ??= []; documentSavedList.add(_documentSaved); dictionary!.beginSaveList ??= []; @@ -79,10 +77,13 @@ class PdfSignatureDictionary implements IPdfWrapper { late List _range; List? _stream; + setStream(List dataStream) { + _stream = dataStream; + } + //Implementations void _dictionaryBeginSave(Object sender, SavePdfPrimitiveArgs? args) { - final bool state = - PdfSecurityHelper.getHelper(_doc.security).encryptor.encrypt; + final bool state = PdfSecurityHelper.getHelper(_doc.security).encryptor.encrypt; dictionary!.encrypt = state; if (_sig != null) { _addRequiredItems(); @@ -112,37 +113,29 @@ class PdfSignatureDictionary implements IPdfWrapper { void _addOptionalItems() { if (_sig != null) { if (_sig!.reason != null) { - dictionary!.setProperty( - PdfDictionaryProperties.reason, PdfString(_sig!.reason!)); + dictionary!.setProperty(PdfDictionaryProperties.reason, PdfString(_sig!.reason!)); } if (_sig!.locationInfo != null) { - dictionary!.setProperty( - PdfDictionaryProperties.location, PdfString(_sig!.locationInfo!)); + dictionary!.setProperty(PdfDictionaryProperties.location, PdfString(_sig!.locationInfo!)); } if (_sig!.contactInfo != null) { - dictionary!.setProperty( - PdfDictionaryProperties.contactInfo, PdfString(_sig!.contactInfo!)); + dictionary!.setProperty(PdfDictionaryProperties.contactInfo, PdfString(_sig!.contactInfo!)); } if (_sig!.signedName != null) { dictionary!.setString(PdfDictionaryProperties.name, _sig!.signedName); final PdfDictionary tempDictionary = PdfDictionary(); final PdfDictionary appDictionary = PdfDictionary(); - tempDictionary.setName( - PdfName(PdfDictionaryProperties.name), _sig!.signedName); + tempDictionary.setName(PdfName(PdfDictionaryProperties.name), _sig!.signedName); appDictionary.setProperty('App', PdfReferenceHolder(tempDictionary)); - dictionary!.setProperty( - PdfName('Prop_Build'), PdfReferenceHolder(appDictionary)); + dictionary!.setProperty(PdfName('Prop_Build'), PdfReferenceHolder(appDictionary)); } } } bool _allowMDP() { - final IPdfPrimitive? perms = PdfCrossTable.dereference( - PdfDocumentHelper.getHelper(_doc) - .catalog[PdfDictionaryProperties.perms]); + final IPdfPrimitive? perms = PdfCrossTable.dereference(PdfDocumentHelper.getHelper(_doc).catalog[PdfDictionaryProperties.perms]); if (perms != null && perms is PdfDictionary) { - final IPdfPrimitive? docMDP = - PdfCrossTable.dereference(perms[PdfDictionaryProperties.docMDP]); + final IPdfPrimitive? docMDP = PdfCrossTable.dereference(perms[PdfDictionaryProperties.docMDP]); final IPdfPrimitive dicSig = dictionary!; return dicSig == docMDP; } @@ -154,9 +147,7 @@ class PdfSignatureDictionary implements IPdfWrapper { final PdfDictionary reference = PdfDictionary(); final PdfArray array = PdfArray(); trans[PdfDictionaryProperties.v] = PdfName('1.2'); - trans[PdfDictionaryProperties.p] = PdfNumber( - PdfSignatureHelper.getHelper(_sig!) - .getCertificateFlagResult(_sig!.documentPermissions)); + trans[PdfDictionaryProperties.p] = PdfNumber(PdfSignatureHelper.getHelper(_sig!).getCertificateFlagResult(_sig!.documentPermissions)); trans[PdfDictionaryProperties.type] = PdfName(_transParam); reference[PdfDictionaryProperties.transformMethod] = PdfName(_docMdp); reference[PdfDictionaryProperties.type] = PdfName('SigRef'); @@ -185,46 +176,32 @@ class PdfSignatureDictionary implements IPdfWrapper { if (regionHours >= 0 && regionHours <= 9) { offsetHours = '0$offsetHours'; } - dictionary!.setProperty( - PdfDictionaryProperties.m, - PdfString( - "D:${dateFormat.format(dateTime)}+$offsetHours'$offsetMinutes'")); + dictionary!.setProperty(PdfDictionaryProperties.m, PdfString("D:${dateFormat.format(dateTime)}+$offsetHours'$offsetMinutes'")); } void _addFilter() { - dictionary! - .setName(PdfName(PdfDictionaryProperties.filter), 'Adobe.PPKLite'); + dictionary!.setName(PdfName(PdfDictionaryProperties.filter), 'Adobe.PPKLite'); } void _addSubFilter() { - dictionary!.setName( - PdfName(PdfDictionaryProperties.subFilter), - _sig!.cryptographicStandard == CryptographicStandard.cades - ? _cadasFilterType - : _cmsFilterType); + dictionary!.setName(PdfName(PdfDictionaryProperties.subFilter), _sig!.cryptographicStandard == CryptographicStandard.cades ? _cadasFilterType : _cmsFilterType); } void _addContents(IPdfWriter writer) { - writer.write(PdfOperators.slash + - PdfDictionaryProperties.contents + - PdfOperators.whiteSpace); + writer.write(PdfOperators.slash + PdfDictionaryProperties.contents + PdfOperators.whiteSpace); _firstRangeLength = writer.position; int length = _estimatedSize * 2; if (_sig != null && _cert != null) { length = _estimatedSize; } - final List contents = - List.filled(length * 2 + 2, 0, growable: true); + final List contents = List.filled(length * 2 + 2, 0, growable: true); writer.write(contents); _secondRangeIndex = writer.position; writer.write(PdfOperators.newLine); } void _addRange(IPdfWriter writer) { - writer.write(PdfOperators.slash + - PdfDictionaryProperties.byteRange + - PdfOperators.whiteSpace + - PdfArray.startMark); + writer.write(PdfOperators.slash + PdfDictionaryProperties.byteRange + PdfOperators.whiteSpace + PdfArray.startMark); _startPositionByteRange = writer.position; for (int i = 0; i < 32; i++) { writer.write(PdfOperators.whiteSpace); @@ -234,17 +211,14 @@ class PdfSignatureDictionary implements IPdfWrapper { void _addDigest(IPdfWriter? writer) { if (_allowMDP()) { - final PdfDictionary cat = - PdfDocumentHelper.getHelper(writer!.document!).catalog; + final PdfDictionary cat = PdfDocumentHelper.getHelper(writer!.document!).catalog; writer.write(PdfName(PdfDictionaryProperties.reference)); writer.write(PdfArray.startMark); writer.write('<<'); writer.write(PdfOperators.slash + _transParam); PdfDictionary trans = PdfDictionary(); trans[PdfDictionaryProperties.v] = PdfName('1.2'); - trans[PdfDictionaryProperties.p] = PdfNumber( - PdfSignatureHelper.getHelper(_sig!) - .getCertificateFlagResult(_sig!.documentPermissions)); + trans[PdfDictionaryProperties.p] = PdfNumber(PdfSignatureHelper.getHelper(_sig!).getCertificateFlagResult(_sig!.documentPermissions)); trans[PdfDictionaryProperties.type] = PdfName(_transParam); writer.write(trans); writer.write(PdfName(PdfDictionaryProperties.transformMethod)); @@ -254,8 +228,7 @@ class PdfSignatureDictionary implements IPdfWrapper { writer.write(PdfName('DigestValue')); int position = writer.position!; // _docDigestPosition = position; - writer - .write(PdfString.fromBytes(List.filled(16, 0, growable: true))); + writer.write(PdfString.fromBytes(List.filled(16, 0, growable: true))); PdfArray digestLocation = PdfArray(); digestLocation.add(PdfNumber(position)); digestLocation.add(PdfNumber(34)); @@ -285,8 +258,7 @@ class PdfSignatureDictionary implements IPdfWrapper { writer.write(PdfName('DigestValue')); position = writer.position!; // _fieldsDigestPosition = position; - writer - .write(PdfString.fromBytes(List.filled(16, 0, growable: true))); + writer.write(PdfString.fromBytes(List.filled(16, 0, growable: true))); digestLocation = PdfArray(); digestLocation.add(PdfNumber(position)); digestLocation.add(PdfNumber(34)); @@ -303,9 +275,12 @@ class PdfSignatureDictionary implements IPdfWrapper { } } + setRange(List inputRange) { + _range = inputRange; + } + void _documentSaved(Object sender, DocumentSavedArgs e) { - final bool enabled = - PdfSecurityHelper.getHelper(_doc.security).encryptor.encrypt; + final bool enabled = PdfSecurityHelper.getHelper(_doc.security).encryptor.encrypt; PdfSecurityHelper.getHelper(_doc.security).encryptor.encrypt = false; final PdfWriter writer = e.writer! as PdfWriter; final int number = e.writer!.length! - _secondRangeIndex!; @@ -320,17 +295,13 @@ class PdfSignatureDictionary implements IPdfWrapper { _range = [0, int.parse(str2), int.parse(str3), int.parse(str4)]; _stream = writer.buffer; final String text = PdfString.bytesToHex(getPkcs7Content()!); - _stream!.replaceRange( - _firstRangeLength!, _firstRangeLength! + 1, utf8.encode('<')); + _stream!.replaceRange(_firstRangeLength!, _firstRangeLength! + 1, utf8.encode('<')); final int newPos = _firstRangeLength! + 1 + text.length; _stream!.replaceRange(_firstRangeLength! + 1, newPos, utf8.encode(text)); final int num3 = (_secondRangeIndex! - newPos) ~/ 2; - final String emptyText = - PdfString.bytesToHex(List.generate(num3, (int i) => 0)); - _stream!.replaceRange( - newPos, newPos + emptyText.length, utf8.encode(emptyText)); - _stream!.replaceRange(newPos + emptyText.length, - newPos + emptyText.length + 1, utf8.encode('>')); + final String emptyText = PdfString.bytesToHex(List.generate(num3, (int i) => 0)); + _stream!.replaceRange(newPos, newPos + emptyText.length, utf8.encode(emptyText)); + _stream!.replaceRange(newPos + emptyText.length, newPos + emptyText.length + 1, utf8.encode('>')); PdfSecurityHelper.getHelper(_doc.security).encryptor.encrypt = enabled; } @@ -341,10 +312,8 @@ class PdfSignatureDictionary implements IPdfWrapper { List>? crlBytes; List? ocspByte; List? chain = []; - final IPdfExternalSigner? externalSigner = - PdfSignatureHelper.getHelper(_sig!).externalSigner; - if (externalSigner != null && - PdfSignatureHelper.getHelper(_sig!).externalChain != null) { + final IPdfExternalSigner? externalSigner = PdfSignatureHelper.getHelper(_sig!).externalSigner; + if (externalSigner != null && PdfSignatureHelper.getHelper(_sig!).externalChain != null) { chain = PdfSignatureHelper.getHelper(_sig!).externalChain; final String digest = getDigestAlgorithm(externalSigner.hashAlgorithm); final _SignaturePrivateKey pks = _SignaturePrivateKey(digest); @@ -352,54 +321,37 @@ class PdfSignatureDictionary implements IPdfWrapper { externalSignature = pks; } else { String certificateAlias = ''; - final List keys = PdfCertificateHelper.getPkcsCertificate(_cert!) - .getContentTable() - .keys - .toList(); + final List keys = PdfCertificateHelper.getPkcsCertificate(_cert!).getContentTable().keys.toList(); bool isContinue = true; // ignore: avoid_function_literals_in_foreach_calls keys.forEach((String key) { - if (isContinue && - PdfCertificateHelper.getPkcsCertificate(_cert!).isKey(key) && - PdfCertificateHelper.getPkcsCertificate(_cert!) - .getKey(key)! - .key! - .isPrivate!) { + if (isContinue && PdfCertificateHelper.getPkcsCertificate(_cert!).isKey(key) && PdfCertificateHelper.getPkcsCertificate(_cert!).getKey(key)!.key!.isPrivate!) { certificateAlias = key; isContinue = false; } }); - final KeyEntry pk = PdfCertificateHelper.getPkcsCertificate(_cert!) - .getKey(certificateAlias)!; - final List certificates = - PdfCertificateHelper.getPkcsCertificate(_cert!) - .getCertificateChain(certificateAlias)!; + final KeyEntry pk = PdfCertificateHelper.getPkcsCertificate(_cert!).getKey(certificateAlias)!; + final List certificates = PdfCertificateHelper.getPkcsCertificate(_cert!).getCertificateChain(certificateAlias)!; // ignore: avoid_function_literals_in_foreach_calls certificates.forEach((X509Certificates c) { chain!.add(c.certificate); + print(c.certificate!.getX509Extensions()); }); final RsaPrivateKeyParam? parameters = pk.key as RsaPrivateKeyParam?; - final String digest = _sig != null - ? getDigestAlgorithm(_sig!.digestAlgorithm) - : MessageDigestAlgorithms.secureHash256; + final String digest = _sig != null ? getDigestAlgorithm(_sig!.digestAlgorithm) : MessageDigestAlgorithms.secureHash256; final _SignaturePrivateKey pks = _SignaturePrivateKey(digest, parameters); hasalgorithm = pks.getHashAlgorithm(); externalSignature = pks; } - final _PdfCmsSigner pkcs7 = - _PdfCmsSigner(null, chain!, hasalgorithm!, false); + final _PdfCmsSigner pkcs7 = _PdfCmsSigner(null, chain!, hasalgorithm!, false); final IRandom source = getUnderlyingSource(); - final List sources = - List.generate(_range.length ~/ 2, (int i) => null); + final List sources = List.generate(_range.length ~/ 2, (int i) => null); for (int j = 0; j < _range.length; j += 2) { sources[j ~/ 2] = _WindowRandom(source, _range[j], _range[j + 1]); } final PdfStreamReader data = _RandomStream(_RandomGroup(sources)); final List hash = pkcs7._digestAlgorithm.digest(data, hasalgorithm)!; - final List? sh = pkcs7 - .getSequenceDataSet( - hash, ocspByte, crlBytes, _sig!.cryptographicStandard) - .getEncoded(Asn1.der); + final List? sh = pkcs7.getSequenceDataSet(hash, ocspByte, crlBytes, _sig!.cryptographicStandard).getEncoded(Asn1.der); List? extSignature; if (externalSigner != null) { final SignerResult? signerResult = externalSigner.sign(sh!); @@ -407,18 +359,15 @@ class PdfSignatureDictionary implements IPdfWrapper { extSignature = signerResult.signedData; } if (extSignature != null) { - pkcs7.setSignedData( - extSignature, null, externalSignature.getEncryptionAlgorithm()); + pkcs7.setSignedData(extSignature, null, externalSignature.getEncryptionAlgorithm()); } else { return List.filled(_estimatedSize, 0, growable: true); } } else { extSignature = externalSignature.sign(sh!); } - pkcs7.setSignedData( - extSignature!, null, externalSignature.getEncryptionAlgorithm()); - return pkcs7.sign(hash, null, null, ocspByte, crlBytes, - _sig!.cryptographicStandard, hasalgorithm); + pkcs7.setSignedData(extSignature!, null, externalSignature.getEncryptionAlgorithm()); + return pkcs7.sign(hash, null, null, ocspByte, crlBytes, _sig!.cryptographicStandard, hasalgorithm); } /// internal method @@ -449,8 +398,7 @@ class PdfSignatureDictionary implements IPdfWrapper { int _saveRangeItem(PdfWriter writer, String str, int startPosition) { final List date = utf8.encode(str); - writer.buffer! - .replaceRange(startPosition, startPosition + date.length, date); + writer.buffer!.replaceRange(startPosition, startPosition + date.length, date); return startPosition + str.length; } @@ -574,8 +522,7 @@ class MessageDigestAlgorithms { } else if (lower == 'md5' || lower == 'md-5' || lower == 'md_5') { result = md5; } else { - throw ArgumentError.value( - hashAlgorithm, 'hashAlgorithm', 'Invalid message digest algorithm'); + throw ArgumentError.value(hashAlgorithm, 'hashAlgorithm', 'Invalid message digest algorithm'); } return result; } @@ -721,18 +668,15 @@ class _SignerUtilities { } class _PdfCmsSigner { - _PdfCmsSigner(ICipherParameter? privateKey, List certChain, - String hashAlgorithm, bool hasRSAdata) { + _PdfCmsSigner(ICipherParameter? privateKey, List certChain, String hashAlgorithm, bool hasRSAdata) { _digestAlgorithm = MessageDigestAlgorithms(); _digestAlgorithmOid = _digestAlgorithm.getAllowedDigests(hashAlgorithm); if (_digestAlgorithmOid == null) { - throw ArgumentError.value( - hashAlgorithm, 'hashAlgorithm', 'Unknown Hash Algorithm'); + throw ArgumentError.value(hashAlgorithm, 'hashAlgorithm', 'Unknown Hash Algorithm'); } _version = 1; _signerVersion = 1; - _certificates = List.generate( - certChain.length, (int i) => certChain[i]); + _certificates = List.generate(certChain.length, (int i) => certChain[i]); _digestOid = {}; _digestOid[_digestAlgorithmOid] = null; _signCert = _certificates[0]; @@ -740,8 +684,7 @@ class _PdfCmsSigner { if (privateKey is RsaKeyParam) { _encryptionAlgorithmOid = _DigitalIdentifiers.rsa; } else { - throw ArgumentError.value( - privateKey, 'privateKey', 'Unknown key algorithm'); + throw ArgumentError.value(privateKey, 'privateKey', 'Unknown key algorithm'); } } if (hasRSAdata) { @@ -771,13 +714,11 @@ class _PdfCmsSigner { } //Implementation - DerSet getSequenceDataSet(List secondDigest, List? ocsp, - List>? crlBytes, CryptographicStandard? sigtype) { + DerSet getSequenceDataSet(List secondDigest, List? ocsp, List>? crlBytes, CryptographicStandard? sigtype) { final Asn1EncodeCollection attribute = Asn1EncodeCollection(); Asn1EncodeCollection v = Asn1EncodeCollection(); v.encodableObjects.add(DerObjectID(_DigitalIdentifiers.contentType)); - v.encodableObjects.add(DerSet( - array: [DerObjectID(_DigitalIdentifiers.pkcs7Data)])); + v.encodableObjects.add(DerSet(array: [DerObjectID(_DigitalIdentifiers.pkcs7Data)])); attribute.encodableObjects.add(DerSequence(collection: v)); v = Asn1EncodeCollection(); v.encodableObjects.add(DerObjectID(_DigitalIdentifiers.messageDigest)); @@ -785,31 +726,22 @@ class _PdfCmsSigner { attribute.encodableObjects.add(DerSequence(collection: v)); if (sigtype == CryptographicStandard.cades) { v = Asn1EncodeCollection(); - v.encodableObjects - .add(DerObjectID(_DigitalIdentifiers.aaSigningCertificateV2)); + v.encodableObjects.add(DerObjectID(_DigitalIdentifiers.aaSigningCertificateV2)); final Asn1EncodeCollection aaV2 = Asn1EncodeCollection(); final MessageDigestAlgorithms alg = MessageDigestAlgorithms(); - final String? sha256Oid = - alg.getAllowedDigests(MessageDigestAlgorithms.secureHash256); + final String? sha256Oid = alg.getAllowedDigests(MessageDigestAlgorithms.secureHash256); if (sha256Oid != _digestAlgorithmOid) { aaV2.encodableObjects.add(Algorithms(DerObjectID(_digestAlgorithmOid))); } - final List dig = alg - .getMessageDigest(hashAlgorithm!) - .convert(_signCert!.c!.getEncoded(Asn1.der)) - .bytes as List; + final List dig = alg.getMessageDigest(hashAlgorithm!).convert(_signCert!.c!.getEncoded(Asn1.der)).bytes as List; aaV2.encodableObjects.add(DerOctet(dig)); - v.encodableObjects.add(DerSet(array: [ - DerSequence.fromObject( - DerSequence.fromObject(DerSequence(collection: aaV2))) - ])); + v.encodableObjects.add(DerSet(array: [DerSequence.fromObject(DerSequence.fromObject(DerSequence(collection: aaV2)))])); attribute.encodableObjects.add(DerSequence(collection: v)); } return DerSet(collection: attribute); } - void setSignedData( - List digest, List? rsaData, String? digestEncryptionAlgorithm) { + void setSignedData(List digest, List? rsaData, String? digestEncryptionAlgorithm) { _signedData = digest; _signedRsaData = rsaData; if (digestEncryptionAlgorithm != null) { @@ -820,20 +752,12 @@ class _PdfCmsSigner { } else if (digestEncryptionAlgorithm == 'ECDSA') { _encryptionAlgorithmOid = _DigitalIdentifiers.ecdsa; } else { - throw ArgumentError.value( - digestEncryptionAlgorithm, 'algorithm', 'Invalid entry'); + throw ArgumentError.value(digestEncryptionAlgorithm, 'algorithm', 'Invalid entry'); } } } - List? sign( - List secondDigest, - dynamic server, - List? timeStampResponse, - List? ocsp, - List>? crls, - CryptographicStandard? sigtype, - String? hashAlgorithm) { + List? sign(List secondDigest, dynamic server, List? timeStampResponse, List? ocsp, List>? crls, CryptographicStandard? sigtype, String? hashAlgorithm) { if (_signedData != null) { _digest = _signedData; if (_rsaData != null) { @@ -859,26 +783,20 @@ class _PdfCmsSigner { v = Asn1EncodeCollection(); // ignore: avoid_function_literals_in_foreach_calls _certificates.forEach((X509Certificate? xcert) { - v.encodableObjects.add( - Asn1Stream(PdfStreamReader(xcert!.c!.getEncoded(Asn1.der))) - .readAsn1()); + v.encodableObjects.add(Asn1Stream(PdfStreamReader(xcert!.c!.getEncoded(Asn1.der))).readAsn1()); }); final DerSet dercertificates = DerSet(collection: v); final Asn1EncodeCollection signerinfo = Asn1EncodeCollection(); - signerinfo.encodableObjects - .add(DerInteger(bigIntToBytes(BigInt.from(_signerVersion)))); + signerinfo.encodableObjects.add(DerInteger(bigIntToBytes(BigInt.from(_signerVersion)))); v = Asn1EncodeCollection(); - v.encodableObjects - .add(getIssuer(_signCert!.c!.tbsCertificate!.getEncoded(Asn1.der))); - v.encodableObjects - .add(DerInteger(bigIntToBytes(_signCert!.c!.serialNumber!.value))); + v.encodableObjects.add(getIssuer(_signCert!.c!.tbsCertificate!.getEncoded(Asn1.der))); + v.encodableObjects.add(DerInteger(bigIntToBytes(_signCert!.c!.serialNumber!.value))); signerinfo.encodableObjects.add(DerSequence(collection: v)); v = Asn1EncodeCollection(); v.encodableObjects.add(DerObjectID(_digestAlgorithmOid)); v.encodableObjects.add(DerNull.value); signerinfo.encodableObjects.add(DerSequence(collection: v)); - signerinfo.encodableObjects.add(DerTag( - 0, getSequenceDataSet(secondDigest, ocsp, crls, sigtype), false)); + signerinfo.encodableObjects.add(DerTag(0, getSequenceDataSet(secondDigest, ocsp, crls, sigtype), false)); v = Asn1EncodeCollection(); v.encodableObjects.add(DerObjectID(_encryptionAlgorithmOid)); v.encodableObjects.add(DerNull.value); @@ -889,11 +807,9 @@ class _PdfCmsSigner { body.encodableObjects.add(DerSet(collection: digestAlgorithms)); body.encodableObjects.add(contentinfo); body.encodableObjects.add(DerTag(0, dercertificates, false)); - body.encodableObjects - .add(DerSet(array: [DerSequence(collection: signerinfo)])); + body.encodableObjects.add(DerSet(array: [DerSequence(collection: signerinfo)])); final Asn1EncodeCollection whole = Asn1EncodeCollection(); - whole.encodableObjects - .add(DerObjectID(_DigitalIdentifiers.pkcs7SignedData)); + whole.encodableObjects.add(DerObjectID(_DigitalIdentifiers.pkcs7SignedData)); whole.encodableObjects.add(DerTag(0, DerSequence(collection: body))); final Asn1DerStream dout = Asn1DerStream([]); dout.writeObject(DerSequence(collection: whole)); @@ -901,8 +817,7 @@ class _PdfCmsSigner { } Asn1? getIssuer(List? data) { - final Asn1Sequence seq = - Asn1Stream(PdfStreamReader(data)).readAsn1()! as Asn1Sequence; + final Asn1Sequence seq = Asn1Stream(PdfStreamReader(data)).readAsn1()! as Asn1Sequence; return seq[seq[0] is Asn1Tag ? 3 : 2] as Asn1?; } } @@ -1069,8 +984,7 @@ class _SourceEntry { } class _RandomStream extends PdfStreamReader { - _RandomStream(IRandom source) - : super(List.generate(source.length!, (int i) => 0)) { + _RandomStream(IRandom source) : super(List.generate(source.length!, (int i) => 0)) { _random = source; } //Fields @@ -1200,15 +1114,12 @@ class _NistObjectIds { static DerObjectID dsaWithSHA256 = DerObjectID('${dsaWithSHA2.id!}.2'); static DerObjectID tttAlgorithm = DerObjectID('1.3.36.3'); static DerObjectID ripeMD160 = DerObjectID('${tttAlgorithm.id!}.2.1'); - static DerObjectID tttRsaSignatureAlgorithm = - DerObjectID('${tttAlgorithm.id!}.3.1'); - static DerObjectID rsaSignatureWithRipeMD160 = - DerObjectID('${tttRsaSignatureAlgorithm.id!}.2'); + static DerObjectID tttRsaSignatureAlgorithm = DerObjectID('${tttAlgorithm.id!}.3.1'); + static DerObjectID rsaSignatureWithRipeMD160 = DerObjectID('${tttRsaSignatureAlgorithm.id!}.2'); } /// internal type definition -typedef DocumentSavedHandler = void Function( - Object sender, DocumentSavedArgs args); +typedef DocumentSavedHandler = void Function(Object sender, DocumentSavedArgs args); /// internal class class DocumentSavedArgs { diff --git a/packages/syncfusion_flutter_pdf/pubspec.lock b/packages/syncfusion_flutter_pdf/pubspec.lock new file mode 100644 index 000000000..1a164d224 --- /dev/null +++ b/packages/syncfusion_flutter_pdf/pubspec.lock @@ -0,0 +1,220 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + async: + dependency: transitive + description: + name: async + sha256: bfe67ef28df125b7dddcea62755991f807aa39a2492a23e1550161692950bbe0 + url: "https://pub.dev" + source: hosted + version: "2.10.0" + boolean_selector: + dependency: transitive + description: + name: boolean_selector + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + characters: + dependency: transitive + description: + name: characters + sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c + url: "https://pub.dev" + source: hosted + version: "1.2.1" + clock: + dependency: transitive + description: + name: clock + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" + source: hosted + version: "1.1.1" + collection: + dependency: transitive + description: + name: collection + sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0 + url: "https://pub.dev" + source: hosted + version: "1.17.0" + convert: + dependency: "direct main" + description: + name: convert + sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592" + url: "https://pub.dev" + source: hosted + version: "3.1.1" + crypto: + dependency: "direct main" + description: + name: crypto + sha256: aa274aa7774f8964e4f4f38cc994db7b6158dd36e9187aaceaddc994b35c6c67 + url: "https://pub.dev" + source: hosted + version: "3.0.2" + fake_async: + dependency: transitive + description: + name: fake_async + sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" + url: "https://pub.dev" + source: hosted + version: "1.3.1" + flutter: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + flutter_test: + dependency: "direct dev" + description: flutter + source: sdk + version: "0.0.0" + intl: + dependency: "direct main" + description: + name: intl + sha256: "3bc132a9dbce73a7e4a21a17d06e1878839ffbf975568bc875c60537824b0c4d" + url: "https://pub.dev" + source: hosted + version: "0.18.1" + js: + dependency: transitive + description: + name: js + sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7" + url: "https://pub.dev" + source: hosted + version: "0.6.5" + matcher: + dependency: transitive + description: + name: matcher + sha256: "16db949ceee371e9b99d22f88fa3a73c4e59fd0afed0bd25fc336eb76c198b72" + url: "https://pub.dev" + source: hosted + version: "0.12.13" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724 + url: "https://pub.dev" + source: hosted + version: "0.2.0" + meta: + dependency: transitive + description: + name: meta + sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42" + url: "https://pub.dev" + source: hosted + version: "1.8.0" + path: + dependency: transitive + description: + name: path + sha256: db9d4f58c908a4ba5953fcee2ae317c94889433e5024c27ce74a37f94267945b + url: "https://pub.dev" + source: hosted + version: "1.8.2" + petitparser: + dependency: transitive + description: + name: petitparser + sha256: "49392a45ced973e8d94a85fdb21293fbb40ba805fc49f2965101ae748a3683b4" + url: "https://pub.dev" + source: hosted + version: "5.1.0" + sky_engine: + dependency: transitive + description: flutter + source: sdk + version: "0.0.99" + source_span: + dependency: transitive + description: + name: source_span + sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250 + url: "https://pub.dev" + source: hosted + version: "1.9.1" + stack_trace: + dependency: transitive + description: + name: stack_trace + sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 + url: "https://pub.dev" + source: hosted + version: "1.11.0" + stream_channel: + dependency: transitive + description: + name: stream_channel + sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + string_scanner: + dependency: transitive + description: + name: string_scanner + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" + source: hosted + version: "1.2.0" + syncfusion_flutter_core: + dependency: "direct main" + description: + name: syncfusion_flutter_core + sha256: "05b079cb1be26a8d5c1afe714172d2eed9178049f4a7dc773b2cbb8b053eff8d" + url: "https://pub.dev" + source: hosted + version: "21.1.41" + term_glyph: + dependency: transitive + description: + name: term_glyph + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" + source: hosted + version: "1.2.1" + test_api: + dependency: transitive + description: + name: test_api + sha256: ad540f65f92caa91bf21dfc8ffb8c589d6e4dc0c2267818b4cc2792857706206 + url: "https://pub.dev" + source: hosted + version: "0.4.16" + typed_data: + dependency: transitive + description: + name: typed_data + sha256: "26f87ade979c47a150c9eaab93ccd2bebe70a27dc0b4b29517f2904f04eb11a5" + url: "https://pub.dev" + source: hosted + version: "1.3.1" + vector_math: + dependency: transitive + description: + name: vector_math + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + xml: + dependency: "direct main" + description: + name: xml + sha256: "979ee37d622dec6365e2efa4d906c37470995871fe9ae080d967e192d88286b5" + url: "https://pub.dev" + source: hosted + version: "6.2.2" +sdks: + dart: ">=2.18.0 <3.0.0"