sphragis 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/.DS_Store +0 -0
  3. data/.rubocop.yml +61 -0
  4. data/CHANGELOG.md +76 -0
  5. data/README.md +378 -0
  6. data/Rakefile +8 -0
  7. data/app/assets/javascripts/sphragis/application.js +270 -0
  8. data/app/assets/stylesheets/sphragis/application.css +2 -0
  9. data/app/controllers/sphragis/documents_controller.rb +89 -0
  10. data/app/views/sphragis/documents/preview.html.erb +244 -0
  11. data/config/routes.rb +17 -0
  12. data/doc/BROWSER_SIGNING_ARCHITECTURE.md +704 -0
  13. data/doc/FORTIFY_WEBCRYPTO.md +394 -0
  14. data/doc/LICENSING_SUMMARY.md +310 -0
  15. data/doc/LOGO.md +276 -0
  16. data/doc/LOGO_FILES.md +125 -0
  17. data/doc/MULTIPLE_PROVIDERS.md +451 -0
  18. data/doc/PROJECT_OVERVIEW.md +300 -0
  19. data/doc/PROVIDERS.md +332 -0
  20. data/doc/SETUP.md +275 -0
  21. data/doc/SUMMARY.md +314 -0
  22. data/lib/sphragis/configuration.rb +83 -0
  23. data/lib/sphragis/engine.rb +17 -0
  24. data/lib/sphragis/hardware_token.rb +91 -0
  25. data/lib/sphragis/pdf_signer.rb +156 -0
  26. data/lib/sphragis/provider_factory.rb +81 -0
  27. data/lib/sphragis/providers/base_provider.rb +61 -0
  28. data/lib/sphragis/providers/fortify_provider.rb +94 -0
  29. data/lib/sphragis/providers/fortify_webcrypto_provider.rb +259 -0
  30. data/lib/sphragis/providers/harica_provider.rb +159 -0
  31. data/lib/sphragis/providers/itsme_provider.rb +181 -0
  32. data/lib/sphragis/version.rb +5 -0
  33. data/lib/sphragis.rb +13 -0
  34. data/media/logo-banner.svg +72 -0
  35. data/media/logo-dark.svg +44 -0
  36. data/media/logo-favicon.svg +16 -0
  37. data/media/logo-horizontal.svg +33 -0
  38. data/media/logo-monochrome.svg +36 -0
  39. data/media/logo-simple.svg +16 -0
  40. data/media/logo.svg +44 -0
  41. data/sig/sphragis.rbs +4 -0
  42. metadata +246 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c42aaaa6c03beb1f59d52fb1199d1d2e698cedc948c1090fd15ab220380d66c5
4
+ data.tar.gz: af16ca3d9aa7dbad982c4cf996bbda71bf42400ddd81b5598d25150e2723aa58
5
+ SHA512:
6
+ metadata.gz: 3ad587b5f0a3bfdb3ee7f24ea1ba193d09f42896042eeacfdb61222ca1f3decafb0144f41f696291707ab68c0cf05a34cc379be9929acd8db5c09f10995853e4
7
+ data.tar.gz: 4578175283a882a5fc14e53b1951cc9bd8e8a141db71d262d317f529c96f706fc6d7c6f182f897533d12706d379c83337722d30bb2f4d08e9738b81109ba76e1
data/.DS_Store ADDED
Binary file
data/.rubocop.yml ADDED
@@ -0,0 +1,61 @@
1
+ # Sphragis RuboCop Configuration
2
+
3
+ require:
4
+ - rubocop-rails
5
+ - rubocop-minitest
6
+
7
+ AllCops:
8
+ TargetRubyVersion: 3.2
9
+ NewCops: enable
10
+ Exclude:
11
+ - 'bin/**/*'
12
+ - 'db/**/*'
13
+ - 'config/**/*'
14
+ - 'node_modules/**/*'
15
+ - 'vendor/**/*'
16
+ - 'tmp/**/*'
17
+
18
+ # Metrics
19
+ Metrics/MethodLength:
20
+ Max: 25
21
+ Exclude:
22
+ - 'test/**/*'
23
+
24
+ Metrics/ClassLength:
25
+ Max: 150
26
+ Exclude:
27
+ - 'test/**/*'
28
+
29
+ Metrics/BlockLength:
30
+ Exclude:
31
+ - 'test/**/*'
32
+ - '*.gemspec'
33
+
34
+ Metrics/AbcSize:
35
+ Max: 20
36
+ Exclude:
37
+ - 'test/**/*'
38
+
39
+ # Style
40
+ Style/Documentation:
41
+ Enabled: false
42
+
43
+ Style/StringLiterals:
44
+ EnforcedStyle: double_quotes
45
+
46
+ Style/FrozenStringLiteralComment:
47
+ Enabled: true
48
+
49
+ # Layout
50
+ Layout/LineLength:
51
+ Max: 120
52
+ Exclude:
53
+ - 'test/**/*'
54
+
55
+ # Rails
56
+ Rails/ApplicationController:
57
+ Enabled: false
58
+
59
+ # Minitest
60
+ Minitest/MultipleAssertions:
61
+ Max: 10
data/CHANGELOG.md ADDED
@@ -0,0 +1,76 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ### Added
11
+ - Initial release of Sphragis (Σφραγίς) - Digital PDF Signatures for Rails
12
+ - Multi-provider architecture supporting:
13
+ - Fortify WebCrypto (FREE open-source, hardware tokens)
14
+ - Harica (FREE for Greek academic institutions, eIDAS qualified)
15
+ - Itsme (template for free e-signature services)
16
+ - Rails Engine with interactive PDF signature placement
17
+ - PDF.js-based viewer with drag-and-drop signature positioning
18
+ - Provider factory pattern for easy extension
19
+ - Configuration system with environment variable support
20
+ - Comprehensive documentation suite
21
+ - Logo design inspired by ancient Greek σφραγιδόλιθοι (sealstones)
22
+ - Complete test suite (Minitest)
23
+ - RuboCop code quality checks
24
+ - Bundler-audit security scanning
25
+
26
+ ### Documentation
27
+ - README.md with quick start guide
28
+ - PROVIDERS.md for provider comparison
29
+ - FORTIFY_WEBCRYPTO.md for Fortify setup
30
+ - LICENSING_SUMMARY.md for cost breakdown
31
+ - MULTIPLE_PROVIDERS.md for multi-provider usage
32
+ - LOGO.md for branding guidelines
33
+ - LOGO_FILES.md for logo assets reference
34
+
35
+ ## Notes
36
+
37
+ ### Breaking Changes Policy
38
+ Major version bumps (1.0.0, 2.0.0, etc.) will include breaking changes.
39
+ Minor version bumps (0.2.0, 0.3.0, etc.) add features in a backwards-compatible manner.
40
+ Patch version bumps (0.1.1, 0.1.2, etc.) are backwards-compatible bug fixes.
41
+
42
+ ### Migration Guides
43
+ When breaking changes occur, migration guides will be provided in the changelog entry.
44
+
45
+ ### Free for Greek Academic Institutions
46
+ This gem provides **FREE** integration with Harica for Greek academic institutions (.gr.ac domains).
47
+ See README.md for details on FREE eIDAS qualified certificates.
48
+
49
+ ---
50
+
51
+ **Legend**:
52
+ - `Added` - New features
53
+ - `Changed` - Changes in existing functionality
54
+ - `Deprecated` - Soon-to-be removed features
55
+ - `Removed` - Removed features
56
+ - `Fixed` - Bug fixes
57
+ - `Security` - Security fixes and improvements
58
+ - `Documentation` - Documentation changes
59
+
60
+ ### Disclaimer
61
+
62
+ > **⚠️ EARLY DEVELOPMENT VERSION**
63
+ >
64
+ > This gem is in early development and has not been thoroughly tested in production environments.
65
+ > Use at your own risk and test extensively before deploying to production.
66
+
67
+ **Sphragis is an independent open-source project.** We are NOT affiliated with, endorsed by, or sponsored by Peculiar Ventures (Fortify), Harica, Yubico, Nitrokey, ItsMe, OpenSC Project, or any other third-party service or product mentioned in this project. All trademarks are property of their respective owners.
68
+
69
+ ### Credits
70
+
71
+ - **[Fortify by Peculiar Ventures](https://github.com/PeculiarVentures/fortify)** - FREE WebCrypto bridge (MIT License)
72
+ - **[HARICA](https://www.harica.gr)** - Greek Academic CA (FREE for academic institutions)
73
+ - **[Prawn PDF](https://github.com/prawnpdf/prawn)** - Ruby PDF generation (GPL/Commercial)
74
+ - **[PDF.js](https://mozilla.github.io/pdf.js/)** - JavaScript PDF rendering (Apache 2.0)
75
+ - **[OpenSC](https://github.com/OpenSC/OpenSC)** - PKCS#11 middleware (LGPL)
76
+ - Ancient Greek craftsmen who created the original σφραγιδόλιθοι (sealstones)
data/README.md ADDED
@@ -0,0 +1,378 @@
1
+ ![Sphragis Banner](media/logo-banner.svg)
2
+
3
+ # Sphragis (Σφραγίς)
4
+
5
+ > **⚠️ EARLY DEVELOPMENT VERSION**
6
+ >
7
+ > This gem is in early development and has not been thoroughly tested in production environments.
8
+ > Use at your own risk and test extensively before deploying to production.
9
+
10
+ **Digital PDF Signatures for Rails Applications**
11
+
12
+ Sphragis (Σφραγίς - Greek for "seal") is a Rails Engine that provides multi-provider PDF digital signatures with interactive placement preview. Perfect for academic institutions and commercial use.
13
+
14
+ ```ruby
15
+ gem 'sphragis'
16
+ ```
17
+
18
+ ## Features
19
+
20
+ - **🔐 Multi-Provider Support**: Hardware tokens (Fortify WebCrypto), cloud e-signatures (Harica), and more
21
+ - **🎯 Interactive Placement**: Drag-and-drop signature placement with PDF.js preview
22
+ - **🏛️ Greek Academic Focus**: FREE integration with Harica for Greek universities
23
+ - **💰 Cost-Effective**: Multiple FREE and low-cost options (€0-50)
24
+ - **🔒 High Security**: Support for qualified electronic signatures (eIDAS)
25
+ - **🎨 Rails Engine**: Drop-in integration with existing Rails apps
26
+ - **⚡ Simple API**: Easy programmatic and UI-based signing
27
+
28
+ ## Quick Start
29
+
30
+ ### Installation
31
+
32
+ Add to your `Gemfile`:
33
+
34
+ ```ruby
35
+ gem 'sphragis'
36
+ ```
37
+
38
+ Run:
39
+
40
+ ```bash
41
+ bundle install
42
+ rails sphragis:install:migrations
43
+ rails db:migrate
44
+ ```
45
+
46
+ Mount the engine in `config/routes.rb`:
47
+
48
+ ```ruby
49
+ mount Sphragis::Engine, at: "/signatures"
50
+ ```
51
+
52
+ ### Configuration
53
+
54
+ Create `config/initializers/sphragis.rb`:
55
+
56
+ ```ruby
57
+ Sphragis.configure do |config|
58
+ # Choose your provider
59
+ config.default_provider = :harica # or :fortify_webcrypto, :itsme
60
+
61
+ # Harica configuration (FREE for Greek academic institutions)
62
+ config.harica_username = Rails.application.credentials.dig(:harica, :username)
63
+ config.harica_password = Rails.application.credentials.dig(:harica, :password)
64
+ config.harica_api_key = Rails.application.credentials.dig(:harica, :api_key)
65
+
66
+ # OR Fortify WebCrypto (FREE software + ~€50 hardware token)
67
+ # config.fortify_url = "https://localhost:31337"
68
+ # config.fortify_certificate_id = "your_cert_id"
69
+ end
70
+ ```
71
+
72
+ ### Basic Usage
73
+
74
+ ```ruby
75
+ # Programmatic signing
76
+ signer = Sphragis::PdfSigner.new("document.pdf", {
77
+ provider: :harica,
78
+ reason: "Official approval",
79
+ location: "University of Aegean",
80
+ contact: "admin@aegean.gr"
81
+ })
82
+ signed_path = signer.sign
83
+
84
+ # Interactive UI
85
+ redirect_to sphragis.preview_path(path: "document.pdf")
86
+ ```
87
+
88
+ ## Supported Providers
89
+
90
+ | Provider | Software Cost | Hardware Cost | Total Cost | Security Level |
91
+ |----------|---------------|---------------|------------|----------------|
92
+ | **Harica (Academic)** | FREE | €0 | **€0** | Qualified (eIDAS) |
93
+ | **Fortify WebCrypto** | FREE | €50 (one-time) | **€50** | Qualified* |
94
+ | **Itsme (Template)** | FREE | €0 | **€0** | Simple |
95
+
96
+ *With qualified certificate from CA like Harica
97
+
98
+ ### 1. Harica - FREE for Greek Academia
99
+
100
+ Perfect for Greek universities and research institutions:
101
+
102
+ ```ruby
103
+ config.default_provider = :harica
104
+ config.harica_username = "you@aegean.gr"
105
+ config.harica_password = Rails.application.credentials.dig(:harica, :password)
106
+ ```
107
+
108
+ - ✅ **Cost**: €0 for .gr.ac domains
109
+ - ✅ **Security**: eIDAS qualified electronic signatures
110
+ - ✅ **Setup time**: 15 minutes
111
+ - 📚 **Documentation**: [PROVIDERS.md](doc/PROVIDERS.md)
112
+
113
+ ### 2. Fortify WebCrypto - FREE Software + Hardware
114
+
115
+ For maximum security with hardware tokens:
116
+
117
+ ```ruby
118
+ config.default_provider = :fortify_webcrypto
119
+ config.fortify_url = "https://localhost:31337"
120
+ ```
121
+
122
+ - ✅ **Software**: FREE (MIT license)
123
+ - ✅ **Hardware**: YubiKey ~€50 (one-time)
124
+ - ✅ **Source**: https://github.com/PeculiarVentures/fortify-releases
125
+ - 📚 **Documentation**: [FORTIFY_WEBCRYPTO.md](doc/FORTIFY_WEBCRYPTO.md)
126
+
127
+ ### 3. Custom Providers
128
+
129
+ Extend `BaseProvider` for your own signature service:
130
+
131
+ ```ruby
132
+ module Sphragis::Providers
133
+ class MyProvider < BaseProvider
134
+ def sign(data)
135
+ # Your implementation
136
+ end
137
+ end
138
+ end
139
+ ```
140
+
141
+ See [PROVIDERS.md](doc/PROVIDERS.md) for details.
142
+
143
+ ## Interactive UI
144
+
145
+ Sphragis includes a complete web interface for signature placement:
146
+
147
+ ```ruby
148
+ # In your controller
149
+ def sign_document
150
+ @document = Document.find(params[:id])
151
+ redirect_to sphragis.preview_path(path: @document.pdf.path)
152
+ end
153
+ ```
154
+
155
+ Features:
156
+ - 📄 PDF.js viewer
157
+ - 🖱️ Drag-and-drop signature placement
158
+ - 📏 Real-time coordinate preview
159
+ - 🔄 Provider selection dropdown
160
+ - ✅ Live signature preview
161
+
162
+ ## API Documentation
163
+
164
+ ### PdfSigner
165
+
166
+ ```ruby
167
+ signer = Sphragis::PdfSigner.new(pdf_path, options)
168
+ signed_path = signer.sign
169
+ ```
170
+
171
+ **Options:**
172
+ - `provider`: `:harica`, `:fortify_webcrypto`, `:itsme` (default: configured default)
173
+ - `reason`: Reason for signing (e.g., "Approved")
174
+ - `location`: Signing location (e.g., "Athens, Greece")
175
+ - `contact`: Contact info (e.g., "admin@example.com")
176
+ - `x`, `y`, `width`, `height`: Signature box coordinates (points)
177
+ - `page`: Page number (0-indexed)
178
+
179
+ ### Configuration
180
+
181
+ ```ruby
182
+ Sphragis.configure do |config|
183
+ config.default_provider = :harica
184
+
185
+ # Harica
186
+ config.harica_username = "user@aegean.gr"
187
+ config.harica_password = "secret"
188
+ config.harica_api_key = "api_key"
189
+ config.harica_certificate_id = "cert_id"
190
+ config.harica_environment = "production" # or 'sandbox'
191
+
192
+ # Fortify WebCrypto
193
+ config.fortify_url = "https://localhost:31337"
194
+ config.fortify_certificate_id = "cert_id"
195
+
196
+ # Itsme
197
+ config.itsme_client_id = "client_id"
198
+ config.itsme_client_secret = "secret"
199
+ config.itsme_user_email = "user@example.com"
200
+ config.itsme_environment = "production"
201
+ end
202
+ ```
203
+
204
+ ### Provider Factory
205
+
206
+ ```ruby
207
+ # List available providers
208
+ Sphragis::ProviderFactory.available_providers
209
+ # => [:harica, :fortify_webcrypto]
210
+
211
+ # Create provider instance
212
+ provider = Sphragis::ProviderFactory.create(:harica)
213
+ provider.connect
214
+ signature = provider.sign(data)
215
+ provider.disconnect
216
+ ```
217
+
218
+ ## Cost Breakdown
219
+
220
+ ### Greek Academic Institution (Recommended)
221
+
222
+ ```
223
+ Sphragis gem: FREE
224
+ Harica: FREE (academic)
225
+ Total: €0
226
+ ```
227
+
228
+ ### Commercial with Hardware Token
229
+
230
+ ```
231
+ Sphragis gem: FREE
232
+ Fortify WebCrypto: FREE
233
+ YubiKey: €50 (one-time)
234
+ Certificate: €0-200/year
235
+ Total: €50-250 first year
236
+ ```
237
+
238
+ ### Development/Testing
239
+
240
+ ```
241
+ Sphragis gem: FREE
242
+ Simulated provider: FREE
243
+ Total: €0
244
+ ```
245
+
246
+ See [LICENSING_SUMMARY.md](doc/LICENSING_SUMMARY.md) for complete details.
247
+
248
+ ## Requirements
249
+
250
+ - Ruby 3.2+
251
+ - Rails 6.1+
252
+ - For Fortify WebCrypto:
253
+ - Fortify app (FREE): https://github.com/PeculiarVentures/fortify-releases
254
+ - Hardware token: YubiKey or similar (~€50)
255
+ - For Harica:
256
+ - Greek academic email (.gr.ac)
257
+ - Harica account (FREE)
258
+
259
+ ## Testing
260
+
261
+ ```bash
262
+ bundle exec rake test
263
+ ```
264
+
265
+ All tests use Minitest with Mocha for mocking.
266
+
267
+ ## Code Quality & Security
268
+
269
+ ```bash
270
+ # Run RuboCop
271
+ bundle exec rubocop
272
+
273
+ # Security audit
274
+ bundle exec bundle-audit check
275
+ ```
276
+
277
+ ## Documentation
278
+
279
+ - [PROVIDERS.md](doc/PROVIDERS.md) - Provider comparison and configuration
280
+ - [FORTIFY_WEBCRYPTO.md](doc/FORTIFY_WEBCRYPTO.md) - Fortify setup guide
281
+ - [LICENSING_SUMMARY.md](doc/LICENSING_SUMMARY.md) - Complete cost breakdown
282
+ - [MULTIPLE_PROVIDERS.md](doc/MULTIPLE_PROVIDERS.md) - Multi-provider usage
283
+ - [LOGO.md](doc/LOGO.md) - Logo design and branding
284
+
285
+ ## Logo & Branding
286
+
287
+ The Sphragis logo is inspired by ancient Greek σφραγιδόλιθοι (sealstones) - precious carved stones used for 3,000 years to authenticate documents. Just as ancient seals authenticated documents through physical impression, Sphragis authenticates digital documents through cryptographic signatures.
288
+
289
+ See [LOGO.md](doc/LOGO.md) for design details.
290
+
291
+ ## Development Status
292
+
293
+ **Current Version**: 0.1.0 (Early Development)
294
+
295
+ **⚠️ Important Notes:**
296
+ - This gem is in early development
297
+ - Not yet tested in production environments
298
+ - API may change in future versions
299
+ - Test thoroughly before production use
300
+ - Contributions and feedback welcome
301
+
302
+ **Completed:**
303
+ - ✅ Multi-provider architecture
304
+ - ✅ Harica integration
305
+ - ✅ Fortify WebCrypto integration
306
+ - ✅ Interactive UI with PDF.js
307
+ - ✅ Minitest test suite
308
+ - ✅ RuboCop configuration
309
+ - ✅ Security audit setup
310
+
311
+ **Planned:**
312
+ - 🔄 Production testing and hardening
313
+ - 🔄 Additional provider support
314
+ - 🔄 Batch signing operations
315
+ - 🔄 Signature verification
316
+ - 🔄 Audit logging
317
+ - 🔄 Performance optimization
318
+
319
+ ## Contributing
320
+
321
+ Contributions welcome! This gem is developed at the University of the Aegean.
322
+
323
+ 1. Fork the repository
324
+ 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
325
+ 3. Run tests (`bundle exec rake test`)
326
+ 4. Run RuboCop (`bundle exec rubocop`)
327
+ 5. Commit your changes (`git commit -am 'Add amazing feature'`)
328
+ 6. Push to the branch (`git push origin feature/amazing-feature`)
329
+ 7. Open a Pull Request
330
+
331
+ Please ensure:
332
+ - All tests pass
333
+ - RuboCop violations are resolved
334
+ - New features include tests
335
+ - Documentation is updated
336
+
337
+ ## License
338
+
339
+ MIT License - See [LICENSE](LICENSE) for details.
340
+
341
+ ## Author
342
+
343
+ **Michail Pantelakis**
344
+ - Email: mpantel@aegean.gr
345
+ - Institution: University of the Aegean
346
+ - GitHub: https://github.com/mpantel/sphragis
347
+
348
+ ## Acknowledgments
349
+
350
+ - **Peculiar Ventures** for Fortify WebCrypto (FREE, open source)
351
+ - **HARICA** for FREE academic certificates
352
+ - **University of the Aegean** for supporting this project
353
+ - Ancient Greek craftsmen who created the original σφραγιδόλιθοι
354
+
355
+ ## Disclaimer
356
+
357
+ **Sphragis is an independent open-source project.** We are NOT affiliated with, endorsed by, or sponsored by any of the third-party providers, services, or products mentioned in this documentation, including but not limited to:
358
+
359
+ - Peculiar Ventures (Fortify) • Harica • Yubico (YubiKey) • Nitrokey • ItsMe • OpenSC Project • Any certificate authorities or hardware manufacturers
360
+
361
+ All trademarks and product names are property of their respective owners. This gem provides integration code only. Users are responsible for complying with third-party terms of service and any associated costs.
362
+
363
+ ## Support
364
+
365
+ - **Issues**: https://github.com/mpantel/sphragis/issues
366
+ - **Email**: mpantel@aegean.gr
367
+ - **Documentation**: See docs/ directory
368
+
369
+ ## Related Projects
370
+
371
+ - [Fortify by Peculiar Ventures](https://github.com/PeculiarVentures/fortify)
372
+ - [HARICA](https://www.harica.gr)
373
+ - [Prawn PDF](https://github.com/prawnpdf/prawn)
374
+ - [PDF.js](https://mozilla.github.io/pdf.js/)
375
+
376
+ ---
377
+
378
+ **Σφραγίς** - Bringing 3,000 years of document authentication tradition to the digital age 🔏
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ task default: :test