︙ | | |
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
-
+
-
+
|
#
###############################################################################
proc usage { error } {
if {[string length $error] > 0} then {puts stdout $error}
puts stdout "usage:\
[file tail [info nameofexecutable]]\
[file tail [getShellExecutableName]]\
[file tail [info script]] <fileName> \[vendor\] \[embed\]\
\[duration\] \[entityType\] \[encoding\] \[publicKeyFile\]\
\[privateKeyFile\]"
\[privateKeyFile\] \[importFirst\]"
#
# NOTE: Indicate to the caller, if any, that we have failed.
#
exit 1
}
|
︙ | | |
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
-
+
|
puts stdout [appendArgs \
"removed embedded certificate from file \"" $fileName \"]
}
}
}
if {[llength $argv] >= 1 && [llength $argv] <= 8} then {
if {[llength $argv] >= 1 && [llength $argv] <= 9} then {
#
# NOTE: This tool requires Eagle.
#
package require Eagle
#
# NOTE: Needed for the [getTemporaryPath] script procedure.
|
︙ | | |
317
318
319
320
321
322
323
324
325
326
327
328
329
330
|
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
|
+
+
+
+
+
+
+
+
+
|
#
# NOTE: Default to "EagleEnterprisePluginRootPublic.snk" in the current
# directory (which may not actually exist).
#
set publicKeyFile EagleEnterprisePluginRootPublic.snk
}
#
# NOTE: Do we want to import the existing certificate first?
#
if {[llength $argv] >= 9} then {
set importFirst [lindex $argv 8]
} else {
set importFirst false; # TODO: Good default?
}
#
# NOTE: If the configuration file exists, load it now.
#
set configFileName [file join $path sign.settings.eagle]
if {[file exists $configFileName]} then {source $configFileName}
#
|
︙ | | |
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
|
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
|
+
-
+
|
#
# NOTE: Attempt to re-sign the license certificate file. Skip
# setting the Id as it should already be set correctly.
#
if {[certificate sign -encoding $encoding -settimestamp \
-setkey $certificate $privateKey] ne "SignedOk"} then {
error [appendArgs \
"failed to create updated signature for " $fileType \
"failed to create signature for " $fileType " \"" $fileName \"]
" \"" $fileName \"]
}
#
# NOTE: Attempt to re-verify the license certificate file.
#
if {[certificate verify -encoding $encoding $certificate \
$privateKey] ne "VerifiedOk"} then {
|
︙ | | |
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
|
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
|
+
+
+
-
-
+
+
+
|
# placed) based on the data file name.
#
set certificateFile [appendArgs $fileName .harpy]
#
# NOTE: Create an empty certificate object.
#
if {$importFirst} then {
set certificate [certificate import -alias $certificateFile]
} else {
set certificate [object create -alias \
Licensing.Components.Public.Certificate]
set certificate [object create -alias \
Licensing.Components.Public.Certificate]
}
#
# HOOK: Post-certificate object creation (create).
#
catch {certificate_hook phase1}
#
|
︙ | | |
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
|
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
|
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
|
catch {certificate_hook phase2}
#
# NOTE: Attempt to sign the embedded file certificate and place
# the Id, timestamp, public key token, and signature bytes
# into the certificate we created above.
#
if {$importFirst} then {
if {[certificate sign -encoding $encoding \
-setkey -hashflags {+Basic Embedded} $certificate \
$privateKey] ne "SignedOk"} then {
error [appendArgs \
"failed to create updated embedded signature for " \
$fileType " \"" $fileName \"]
}
} else {
if {[certificate sign -encoding $encoding -setid -settimestamp \
-setkey -hashflags {+Basic Embedded} $certificate \
$privateKey] ne "SignedOk"} then {
error [appendArgs \
"failed to create embedded signature for " $fileType " \"" \
$fileName \"]
if {[certificate sign -encoding $encoding -setid -settimestamp \
-setkey -hashflags {+Basic Embedded} $certificate \
$privateKey] ne "SignedOk"} then {
error [appendArgs \
"failed to create embedded signature for " $fileType \
" \"" $fileName \"]
}
}
#
# NOTE: Sanity check that the embedded file certificate we just
# created validates properly.
#
if {[certificate verify -encoding $encoding \
-hashflags {+Basic Embedded} $certificate \
$publicKey] ne "VerifiedOk"} then {
error [appendArgs \
"failed to verify embedded signature for " $fileType " \"" \
$fileName \"]
"failed to verify embedded signature for " $fileType \
" \"" $fileName \"]
}
} else {
#
# HOOK: Post-certificate property setup (non-embedded).
#
catch {certificate_hook phase2}
#
# NOTE: Attempt to sign the data file and place the Id, timestamp,
# public key token, and signature bytes into the blank
# certificate we created above.
#
if {$importFirst} then {
if {[certificate signfile -encoding $encoding -setid -settimestamp \
-setkey $certificate $privateKey $fileName] ne "SignedOk"} then {
error [appendArgs \
"failed to create signature for " $fileType " \"" $fileName \"]
if {[certificate signfile -encoding $encoding \
-setkey $certificate $privateKey \
$fileName] ne "SignedOk"} then {
error [appendArgs \
"failed to create updated signature for " $fileType \
" \"" $fileName \"]
}
} else {
if {[certificate signfile -encoding $encoding -setid \
-settimestamp -setkey $certificate $privateKey \
$fileName] ne "SignedOk"} then {
error [appendArgs \
"failed to create signature for " $fileType \
" \"" $fileName \"]
}
}
#
# NOTE: Sanity check that the data file certificate we just
# created validates properly.
#
if {[certificate verifyfile -encoding $encoding \
$certificate $publicKey $fileName] ne "VerifiedOk"} then {
error [appendArgs \
"failed to verify signature for " $fileType " \"" $fileName \"]
"failed to verify signature for " $fileType \
" \"" $fileName \"]
}
}
}
#
# NOTE: When embedding, do not modify the external certificate
# file. Also, do not save out the entity value we set.
|
︙ | | |
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
|
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
|
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
|
"\" xmlns" [appendArgs \" [info newline] $spaces xmlns]] $data]
writeCertificateFile $certificateFile $data
#
# NOTE: Show that we signed it.
#
if {$importFirst} then {
puts stdout [appendArgs \
"signed " $fileType " \"" $fileName "\" (as \"" $entityType \
"\") using encoding \"" $encoding "\" with key " [keypair token \
$privateKeyFile]]
puts stdout [appendArgs \
"re-signed " $fileType " \"" $fileName "\" (as \"" $entityType \
"\") using encoding \"" $encoding "\" with key " [keypair token \
$privateKeyFile]]
} else {
puts stdout [appendArgs \
"signed " $fileType " \"" $fileName "\" (as \"" $entityType \
"\") using encoding \"" $encoding "\" with key " [keypair token \
$privateKeyFile]]
}
#
# NOTE: Do we need to embed the certificate at the end of the script
# file?
#
if {$shouldEmbed} then {
#
|
︙ | | |
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
|
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
|
-
-
-
+
+
+
+
|
catch {certificate_hook phase3}
#
# NOTE: Play nice and cleanup all the variables we created during the
# whole the signing process.
#
unset -nocomplain fileName vendor embed duration entityType encoding \
privateKeyFile publicKeyFile configFileName embedSpacing embedPrefix \
embedSuffix publicKey privateKey shouldEmbed fileType certificate \
certificateFile data xmlNs xmlNsXsi xmlNsXsd spaces lines line
privateKeyFile publicKeyFile importFirst configFileName embedSpacing \
embedPrefix embedSuffix publicKey privateKey shouldEmbed fileType \
certificate certificateFile data xmlNs xmlNsXsi xmlNsXsd spaces \
lines line
if {[info exists path_set]} then {
unset -nocomplain path path_set
}
} else {
usage ""
}
|