forked from caml-pkcs11/caml-crush
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.ml
1024 lines (903 loc) · 48.4 KB
/
server.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
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
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
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
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
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(************************* MIT License HEADER ************************************
Copyright ANSSI (2013-2015)
Contributors : Ryad BENADJILA [ryadbenadjila@gmail.com],
Thomas CALDERON [calderon.thomas@gmail.com]
Marion DAUBIGNARD [marion.daubignard@ssi.gouv.fr]
This software is a computer program whose purpose is to implement
a PKCS#11 proxy as well as a PKCS#11 filter with security features
in mind. The project source tree is subdivided in six parts.
There are five main parts:
1] OCaml/C PKCS#11 bindings (using OCaml IDL).
2] XDR RPC generators (to be used with ocamlrpcgen and/or rpcgen).
3] A PKCS#11 RPC server (daemon) in OCaml using a Netplex RPC basis.
4] A PKCS#11 filtering module used as a backend to the RPC server.
5] A PKCS#11 client module that comes as a dynamic library offering
the PKCS#11 API to the software.
There is one "optional" part:
6] Tests in C and OCaml to be used with client module 5] or with the
bindings 1]
Here is a big picture of how the PKCS#11 proxy works:
---------------------- -------- socket (TCP or Unix) --------------------
| 3] PKCS#11 RPC server|-|2] RPC |<+++++++++++++++++++> | 5] Client library |
---------------------- | Layer | [SSL/TLS optional] | -------- |
| -------- | |2] RPC | PKCS#11 |
---------------------- | | Layer |functions|
| 4] PKCS#11 filter | | -------- |
---------------------- --------------------
| |
---------------------- |
| 1] PKCS#11 OCaml | { PKCS#11 INTERFACE }
| bindings | |
---------------------- APPLICATION
|
|
{ PKCS#11 INTERFACE }
|
REAL PKCS#11 MIDDLEWARE
(shared library)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Except as contained in this notice, the name(s) of the above copyright holders
shall not be used in advertising or otherwise to promote the sale, use or other
dealings in this Software without prior written authorization.
The current source code is part of the PKCS#11 daemon 3] source tree:
----------------------
| 3] PKCS#11 RPC server|
----------------------
Project: PKCS#11 Filtering Proxy
File: src/pkcs11proxyd/server.ml
************************** MIT License HEADER ***********************************)
open Pkcs11_rpc_aux
open Pkcs11
open Rpc_helpers
(* Handling the filter passthrough *)
IFDEF WITHOUT_FILTER THEN
DEFINE CALLP11=Pkcs11
ELSE
DEFINE CALLP11=Frontend
ENDIF
INCLUDE "server_ssl.ml"
(* PKCS#11 functions debug variable *)
let ref_pkcs_debug = ref 0
let ref_daemonize_args = ref ""
IFNDEF WITH_SSL THEN
let libnames_config_ref = ref ""
let filter_config_file_ref = ref ""
ENDIF
(* Debug helper *)
(* This function prints the name of the calling function *)
let debug_print_call function_name =
(* Debug *)
if !ref_pkcs_debug = 1
then begin
let s = Printf.sprintf "%s called in process %d" function_name (Unix.getpid()) in
Netplex_cenv.log `Info s;
end
(*********)
(* This function prints the pid and the return value of a PKCS#11 function *)
let debug_print_ret function_name ret_value =
(* Debug *)
if !ref_pkcs_debug = 1
then begin
let s = Printf.sprintf "%s returned in process %d with %s" function_name (Unix.getpid()) (match_cKR_value ret_value) in
Netplex_cenv.log `Info s;
end
(*********)
(* Basic debug *)
let debug_print function_name in_string =
(* Debug *)
if !ref_pkcs_debug = 1
then begin
let s = Printf.sprintf "%s in process %d: %s" function_name (Unix.getpid()) in_string in
Netplex_cenv.log `Info s;
end
(*********)
let c_Daemonize (param) =
debug_print_call "C_Daemonize";
(* To keep things consistent c_Daemonize can pass through filter as well *)
let ret = Pkcs11.c_Daemonize param in
debug_print_ret "C_Daemonize" ret;
(Int64.of_nativeint ret)
let c_SetupArch (arch) =
debug_print "C_SetupArch peer arch is" (Pkcs11.match_arch_value (Int64.to_nativeint arch));
let ret = CALLP11.c_SetupArch (Int64.to_nativeint arch) in
debug_print "C_SetupArch server arch is" (Pkcs11.match_arch_value ret);
(Int64.of_nativeint ret)
let c_Initialize () =
debug_print_call "C_Initialize";
let ret = CALLP11.c_Initialize () in
debug_print_ret "C_Initialize" ret;
(Int64.of_nativeint ret)
(*************************************************************************)
let c_GetSlotList (token_present, count) =
debug_print_call "C_GetSlotList";
let (ret, slot_list_, count_) = CALLP11.c_GetSlotList (Int64.to_nativeint token_present) (Int64.to_nativeint count) in
debug_print_ret "C_GetSlotList" ret;
{c_getslotlist_rv = (Int64.of_nativeint ret) ; c_getslotlist_slot_list = (Array.map Int64.of_nativeint slot_list_) ; c_getslotlist_count = (Int64.of_nativeint count_)}
(*************************************************************************)
let c_Finalize () =
debug_print_call "C_Finalize";
let ret = CALLP11.c_Finalize () in
debug_print_ret "C_Finalize" ret;
(Int64.of_nativeint ret)
(*************************************************************************)
let c_GetInfo () =
debug_print_call "C_GetInfo";
let (ret, info_) = CALLP11.c_GetInfo () in
debug_print_ret "C_GetInfo" ret;
{c_getinfo_rv = (Int64.of_nativeint ret) ; c_getinfo_info = (ck_info_pkcs11_to_rpc_aux info_) }
(*************************************************************************)
let c_WaitForSlotEvent (flags) =
debug_print_call "C_WaitForSlotEvent";
let (ret, count_) = CALLP11.c_WaitForSlotEvent (Int64.to_nativeint flags) in
debug_print_ret "C_WaitForSlotEvent" ret;
{c_waitforslotevent_rv = (Int64.of_nativeint ret) ; c_waitforslotevent_count = (Int64.of_nativeint count_) }
(*************************************************************************)
let c_GetSlotInfo (slot_id) =
debug_print_call "C_GetSlotInfo";
let (ret, slot_info_) = CALLP11.c_GetSlotInfo (Int64.to_nativeint slot_id) in
debug_print_ret "C_GetSlotInfo" ret;
{c_getslotinfo_rv = (Int64.of_nativeint ret) ; c_getslotinfo_slot_info = (ck_slot_info_pkcs11_to_rpc_aux slot_info_) }
(*************************************************************************)
let c_GetTokenInfo (slot_id) =
debug_print_call "C_GetTokenInfo";
let (ret, token_info_) = CALLP11.c_GetTokenInfo (Int64.to_nativeint slot_id) in
debug_print_ret "C_GetTokenInfo" ret;
{c_gettokeninfo_rv = (Int64.of_nativeint ret) ; c_gettokeninfo_token_info = (ck_token_info_pkcs11_to_rpc_aux token_info_)}
(*************************************************************************)
let c_Login (handle, user_type, pin) =
debug_print_call "C_Login";
let real_pin = (Pkcs11.string_to_char_array pin) in
let ret = CALLP11.c_Login (Int64.to_nativeint handle) (Int64.to_nativeint user_type) real_pin in
debug_print_ret "C_Login" ret;
(Int64.of_nativeint ret)
(*************************************************************************)
let c_Logout (handle) =
debug_print_call "C_Logout";
let ret = CALLP11.c_Logout (Int64.to_nativeint handle) in
debug_print_ret "C_Logout" ret;
(Int64.of_nativeint ret)
(*************************************************************************)
let c_OpenSession (slot_id, flags) =
debug_print_call "C_OpenSession";
let (ret, session_) = CALLP11.c_OpenSession (Int64.to_nativeint slot_id) (Int64.to_nativeint flags) in
debug_print_ret "C_OpenSession" ret;
{c_opensession_rv = (Int64.of_nativeint ret) ; c_opensession_handle = (Int64.of_nativeint session_) }
(*************************************************************************)
let c_CloseSession (session) =
debug_print_call "C_CloseSession";
let ret = CALLP11.c_CloseSession (Int64.to_nativeint session) in
debug_print_ret "C_CloseSession" ret;
(Int64.of_nativeint ret)
(*************************************************************************)
let c_GetMechanismList (slot_id, count) =
debug_print_call "C_GetMechanismList";
let (ret, mech_list_, count_) = CALLP11.c_GetMechanismList (Int64.to_nativeint slot_id) (Int64.to_nativeint count) in
debug_print_ret "C_GetMechanismList" ret;
{c_getmechanismlist_rv = (Int64.of_nativeint ret) ; c_getmechanismlist_list = (Array.map Int64.of_nativeint mech_list_) ; c_getmechanismlist_count = (Int64.of_nativeint count_)}
(*************************************************************************)
let c_CloseAllSessions (slot_id) =
debug_print_call "C_CloseAllSessions";
let ret = CALLP11.c_CloseAllSessions (Int64.to_nativeint slot_id) in
debug_print_ret "C_CloseAllSessions" ret;
(Int64.of_nativeint ret)
(*************************************************************************)
let c_GetSessionInfo (session) =
debug_print_call "C_GetSessionInfo";
let (ret, session_info_) = CALLP11.c_GetSessionInfo (Int64.to_nativeint session) in
debug_print_ret "C_GetSessionInfo" ret;
{c_getsessioninfo_rv = (Int64.of_nativeint ret) ; c_getsessioninfo_info = (ck_session_info_pkcs11_to_rpc_aux session_info_) }
(*************************************************************************)
let c_GetMechanismInfo (slot_id, mechanism_type) =
debug_print_call "C_GetMechanismInfo";
let (ret, mech_info_) = CALLP11.c_GetMechanismInfo (Int64.to_nativeint slot_id) (Int64.to_nativeint mechanism_type) in
debug_print_ret "C_GetMechanismInfo" ret;
{c_getmechanisminfo_rv = (Int64.of_nativeint ret) ; c_getmechanisminfo_info = (ck_mechanism_info_pkcs11_to_rpc_aux mech_info_)}
(*************************************************************************)
let c_InitPIN (session_handle, pin) =
debug_print_call "C_InitPIN";
let real_pin = (Pkcs11.string_to_char_array pin) in
let ret = CALLP11.c_InitPIN (Int64.to_nativeint session_handle) real_pin in
debug_print_ret "C_InitPIN" ret;
(Int64.of_nativeint ret)
(*************************************************************************)
let c_SetPIN (session_handle, old_pin, new_pin) =
debug_print_call "C_SetPIN";
let real_old_pin = (Pkcs11.string_to_char_array old_pin) in
let real_new_pin = (Pkcs11.string_to_char_array new_pin) in
let ret = CALLP11.c_SetPIN (Int64.to_nativeint session_handle) real_old_pin real_new_pin in
debug_print_ret "C_SetPIN" ret;
(Int64.of_nativeint ret)
(*************************************************************************)
let c_SeedRandom (session_handle, seed) =
debug_print_call "C_SeedRandom";
let real_seed = (Pkcs11.string_to_char_array seed) in
let ret = CALLP11.c_SeedRandom (Int64.to_nativeint session_handle) real_seed in
debug_print_ret "C_SeedRandom" ret;
(Int64.of_nativeint ret)
(*************************************************************************)
let c_InitToken (slot_id, so_pin, label) =
debug_print_call "C_InitToken";
let real_label = (Pkcs11.string_to_char_array label) in
let real_so_pin = (Pkcs11.string_to_char_array so_pin) in
let ret = CALLP11.c_InitToken (Int64.to_nativeint slot_id) real_so_pin real_label in
debug_print_ret "C_InitToken" ret;
(Int64.of_nativeint ret)
(*************************************************************************)
let c_GenerateRandom (session_handle, count) =
debug_print_call "C_GenerateRandom";
let (ret, rand_data_) = CALLP11.c_GenerateRandom (Int64.to_nativeint session_handle) (Int64.to_nativeint count) in
debug_print_ret "C_GenerateRandom" ret;
{c_generaterandom_rv = (Int64.of_nativeint ret) ; c_generaterandom_data = (Pkcs11.char_array_to_string rand_data_) }
(*************************************************************************)
let c_FindObjectsInit (session_handle, attributes) =
debug_print_call "C_FindObjectsInit";
let real_attributes = (Array.map ck_attribute_rpc_aux_to_pkcs11 attributes) in
let ret = CALLP11.c_FindObjectsInit (Int64.to_nativeint session_handle) real_attributes in
debug_print_ret "C_FindObjectsInit" ret;
(Int64.of_nativeint ret)
(*************************************************************************)
let c_FindObjects (session_handle, count) =
debug_print_call "C_FindObjects";
let (ret, objects_, count_) = CALLP11.c_FindObjects (Int64.to_nativeint session_handle) (Int64.to_nativeint count) in
debug_print_ret "C_FindObjects" ret;
{c_findobjects_rv = (Int64.of_nativeint ret) ; c_findobjects_objects = (Array.map Int64.of_nativeint objects_) ; c_findobjects_count = (Int64.of_nativeint count_) }
(*************************************************************************)
let c_FindObjectsFinal (session_handle) =
debug_print_call "C_FindObjectsFinal";
let ret = CALLP11.c_FindObjectsFinal (Int64.to_nativeint session_handle) in
debug_print_ret "C_FindObjectsFinal" ret;
(Int64.of_nativeint ret)
(*************************************************************************)
let c_GenerateKey (session_handle, mechanism, attributes) =
debug_print_call "C_GenerateKey";
let real_mechanism = (ck_mechanism_rpc_aux_to_pkcs11 mechanism) in
let real_attributes = (Array.map ck_attribute_rpc_aux_to_pkcs11 attributes) in
let (ret, object_handle_) = CALLP11.c_GenerateKey (Int64.to_nativeint session_handle) real_mechanism real_attributes in
debug_print_ret "C_GenerateKey" ret;
{c_generatekey_rv = (Int64.of_nativeint ret) ; c_generatekey_handle = (Int64.of_nativeint object_handle_)}
(*************************************************************************)
let c_GenerateKeyPair (session_handle, mechanism, pub_attributes, priv_attributes) =
debug_print_call "C_GenerateKeyPair";
let real_mechanism = (ck_mechanism_rpc_aux_to_pkcs11 mechanism) in
let real_pub_attributes = (Array.map ck_attribute_rpc_aux_to_pkcs11 pub_attributes) in
let real_priv_attributes = (Array.map ck_attribute_rpc_aux_to_pkcs11 priv_attributes) in
let (ret, pub_handle_, priv_handle_) = CALLP11.c_GenerateKeyPair (Int64.to_nativeint session_handle) real_mechanism real_pub_attributes real_priv_attributes in
debug_print_ret "C_GenerateKeyPair" ret;
{c_generatekeypair_rv = (Int64.of_nativeint ret) ; c_generatekeypair_pubhandle = (Int64.of_nativeint pub_handle_); c_generatekeypair_privhandle = (Int64.of_nativeint priv_handle_)}
(*************************************************************************)
let c_CreateObject (session_handle, attributes) =
debug_print_call "C_CreateObject";
let real_attributes = (Array.map ck_attribute_rpc_aux_to_pkcs11 attributes) in
let (ret, handle_) = CALLP11.c_CreateObject (Int64.to_nativeint session_handle) real_attributes in
debug_print_ret "C_CreateObject" ret;
{c_createobject_rv = (Int64.of_nativeint ret) ; c_createobject_handle = (Int64.of_nativeint handle_)}
(*************************************************************************)
let c_CopyObject (session_handle, object_handle, attributes) =
debug_print_call "C_CopyObject";
let real_attributes = (Array.map ck_attribute_rpc_aux_to_pkcs11 attributes) in
let (ret, handle_) = CALLP11.c_CopyObject (Int64.to_nativeint session_handle) (Int64.to_nativeint object_handle) real_attributes in
debug_print_ret "C_CopyObject" ret;
{c_copyobject_rv = (Int64.of_nativeint ret) ; c_copyobject_handle = (Int64.of_nativeint handle_)}
(*************************************************************************)
let c_DestroyObject (session_handle, object_handle) =
debug_print_call "C_DestroyObject";
let ret = CALLP11.c_DestroyObject (Int64.to_nativeint session_handle) (Int64.to_nativeint object_handle) in
debug_print_ret "C_DestroyObject" ret;
(Int64.of_nativeint ret)
(*************************************************************************)
let c_GetAttributeValue (session_handle, object_handle, attributes) =
debug_print_call "C_GetAttributeValue";
let real_attributes = (Array.map ck_attribute_rpc_aux_to_pkcs11 attributes) in
let (ret, attributes_) = CALLP11.c_GetAttributeValue (Int64.to_nativeint session_handle) (Int64.to_nativeint object_handle) real_attributes in
debug_print_ret "C_GetAttributeValue" ret;
{c_getattributevalue_rv = (Int64.of_nativeint ret) ; c_getattributevalue_value = (Array.map ck_attribute_pkcs11_to_rpc_aux attributes_) }
(*************************************************************************)
let c_SetAttributeValue (session_handle, object_handle, attributes) =
debug_print_call "C_SetAttributeValue";
let real_attributes = (Array.map ck_attribute_rpc_aux_to_pkcs11 attributes) in
let ret = CALLP11.c_SetAttributeValue (Int64.to_nativeint session_handle) (Int64.to_nativeint object_handle) real_attributes in
debug_print_ret "C_SetAttributeValue" ret;
(Int64.of_nativeint ret)
(*************************************************************************)
let c_GetObjectSize (session_handle, object_handle) =
debug_print_call "C_GetObjectSize";
let (ret, size_) = CALLP11.c_GetObjectSize (Int64.to_nativeint session_handle) (Int64.to_nativeint object_handle) in
debug_print_ret "C_GetObjectSize" ret;
{c_getobjectsize_rv = (Int64.of_nativeint ret) ; c_getobjectsize_size = (Int64.of_nativeint size_)}
(*************************************************************************)
let c_WrapKey (session_handle, mechanism, wrapping_handle, wrapped_handle) =
debug_print_call "C_WrapKey";
let real_mechanism = (ck_mechanism_rpc_aux_to_pkcs11 mechanism) in
let (ret, wrapped_value_) = CALLP11.c_WrapKey (Int64.to_nativeint session_handle) real_mechanism (Int64.to_nativeint wrapping_handle) (Int64.to_nativeint wrapped_handle) in
debug_print_ret "C_WrapKey" ret;
{c_wrapkey_rv = (Int64.of_nativeint ret) ; c_wrapkey_value = (Pkcs11.char_array_to_string wrapped_value_) }
(*************************************************************************)
let c_UnwrapKey (session_handle, mechanism, unwrapping_handle, wrapped_key, attributes) =
debug_print_call "C_UnwrapKey";
let real_mechanism = (ck_mechanism_rpc_aux_to_pkcs11 mechanism) in
let real_attributes = (Array.map ck_attribute_rpc_aux_to_pkcs11 attributes) in
let real_wrapped_key = (Pkcs11.string_to_char_array wrapped_key) in
let (ret, unwrapped_value_) = CALLP11.c_UnwrapKey (Int64.to_nativeint session_handle) real_mechanism (Int64.to_nativeint unwrapping_handle) real_wrapped_key real_attributes in
debug_print_ret "C_UnwrapKey" ret;
{c_unwrapkey_rv = (Int64.of_nativeint ret) ; c_unwrapkey_handle = (Int64.of_nativeint unwrapped_value_) }
(*************************************************************************)
let c_DeriveKey (session_handle, mechanism, initial_key, attributes) =
debug_print_call "C_DeriveKey";
let real_mechanism = (ck_mechanism_rpc_aux_to_pkcs11 mechanism) in
let real_attributes = (Array.map ck_attribute_rpc_aux_to_pkcs11 attributes) in
let (ret, derived_key_) = CALLP11.c_DeriveKey (Int64.to_nativeint session_handle) real_mechanism (Int64.to_nativeint initial_key) real_attributes in
debug_print_ret "C_DeriveKey" ret;
{c_derivekey_rv = (Int64.of_nativeint ret) ; c_derivekey_handle = (Int64.of_nativeint derived_key_) }
(*************************************************************************)
let c_DigestInit (session_handle, mechanism) =
debug_print_call "C_DigestInit";
let real_mechanism = (ck_mechanism_rpc_aux_to_pkcs11 mechanism) in
let ret = CALLP11.c_DigestInit (Int64.to_nativeint session_handle) real_mechanism in
debug_print_ret "C_DigestInit" ret;
(Int64.of_nativeint ret)
(*************************************************************************)
let c_Digest (session_handle, data) =
debug_print_call "C_Digest";
let real_data = (Pkcs11.string_to_char_array data) in
let (ret, digested_) = CALLP11.c_Digest (Int64.to_nativeint session_handle) real_data in
debug_print_ret "C_Digest" ret;
{c_digest_rv = (Int64.of_nativeint ret) ; c_digest_value = (Pkcs11.char_array_to_string digested_) }
(*************************************************************************)
let c_DigestUpdate (session_handle, data) =
debug_print_call "C_DigestUpdate";
let real_data = (Pkcs11.string_to_char_array data) in
let ret = CALLP11.c_DigestUpdate (Int64.to_nativeint session_handle) real_data in
debug_print_ret "C_DigestUpdate" ret;
(Int64.of_nativeint ret)
(*************************************************************************)
let c_DigestFinal (session_handle) =
debug_print_call "C_DigestFinal";
let (ret, digested_) = CALLP11.c_DigestFinal (Int64.to_nativeint session_handle) in
debug_print_ret "C_DigestFinal" ret;
{c_digestfinal_rv = (Int64.of_nativeint ret) ; c_digestfinal_value = (Pkcs11.char_array_to_string digested_) }
(*************************************************************************)
let c_DigestKey (session_handle, object_handle) =
debug_print_call "C_DigestKey";
let ret = CALLP11.c_DigestKey (Int64.to_nativeint session_handle) (Int64.to_nativeint object_handle) in
debug_print_ret "C_DigestKey" ret;
(Int64.of_nativeint ret)
(*************************************************************************)
let c_SignInit (session_handle, mechanism, object_handle) =
debug_print_call "C_SignInit";
let real_mechanism = (ck_mechanism_rpc_aux_to_pkcs11 mechanism) in
let ret = CALLP11.c_SignInit (Int64.to_nativeint session_handle) real_mechanism (Int64.to_nativeint object_handle) in
debug_print_ret "C_SignInit" ret;
(Int64.of_nativeint ret)
(*************************************************************************)
let c_Sign (session_handle, data) =
debug_print_call "C_Sign";
let real_data = (Pkcs11.string_to_char_array data) in
let (ret, signed_) = CALLP11.c_Sign (Int64.to_nativeint session_handle) real_data in
debug_print_ret "C_Sign" ret;
{c_sign_rv = (Int64.of_nativeint ret) ; c_sign_value = (Pkcs11.char_array_to_string signed_) }
(*************************************************************************)
let c_SignUpdate (session_handle, data) =
debug_print_call "C_SignUpdate";
let real_data = (Pkcs11.string_to_char_array data) in
let ret = CALLP11.c_SignUpdate (Int64.to_nativeint session_handle) real_data in
debug_print_ret "C_SignUpdate" ret;
(Int64.of_nativeint ret)
(*************************************************************************)
let c_SignFinal (session_handle) =
debug_print_call "C_SignFinal";
let (ret, signed_) = CALLP11.c_SignFinal (Int64.to_nativeint session_handle) in
debug_print_ret "C_SignFinal" ret;
{c_signfinal_rv = (Int64.of_nativeint ret) ; c_signfinal_value = (Pkcs11.char_array_to_string signed_) }
(*************************************************************************)
let c_VerifyInit (session_handle, mechanism, object_handle) =
debug_print_call "C_VerifyInit";
let real_mechanism = (ck_mechanism_rpc_aux_to_pkcs11 mechanism) in
let ret = CALLP11.c_VerifyInit (Int64.to_nativeint session_handle) real_mechanism (Int64.to_nativeint object_handle) in
debug_print_ret "C_VerifyInit" ret;
(Int64.of_nativeint ret)
(*************************************************************************)
let c_Verify (session_handle, data, signed_data ) =
debug_print_call "C_Verify";
let real_data = (Pkcs11.string_to_char_array data) in
let real_signed_data = (Pkcs11.string_to_char_array signed_data) in
let ret = CALLP11.c_Verify (Int64.to_nativeint session_handle) real_data real_signed_data in
debug_print_ret "C_Verify" ret;
(Int64.of_nativeint ret)
(*************************************************************************)
let c_VerifyUpdate (session_handle, data) =
debug_print_call "C_VerifyUpdate";
let real_data = (Pkcs11.string_to_char_array data) in
let ret = CALLP11.c_VerifyUpdate (Int64.to_nativeint session_handle) real_data in
debug_print_ret "C_VerifyUpdate" ret;
(Int64.of_nativeint ret)
(*************************************************************************)
let c_VerifyFinal (session_handle, data) =
debug_print_call "C_VerifyFinal";
let real_data = (Pkcs11.string_to_char_array data) in
let ret = CALLP11.c_VerifyFinal (Int64.to_nativeint session_handle) real_data in
debug_print_ret "C_VerifyFinal" ret;
(Int64.of_nativeint ret)
(*************************************************************************)
let c_EncryptInit (session_handle, mechanism, object_handle) =
debug_print_call "C_EncryptInit";
let real_mechanism = (ck_mechanism_rpc_aux_to_pkcs11 mechanism) in
let ret = CALLP11.c_EncryptInit (Int64.to_nativeint session_handle) real_mechanism (Int64.to_nativeint object_handle) in
debug_print_ret "C_EncryptInit" ret;
(Int64.of_nativeint ret)
(*************************************************************************)
let c_Encrypt (session_handle, data ) =
debug_print_call "C_Encrypt";
let real_data = (Pkcs11.string_to_char_array data) in
let (ret, encrypted_) = CALLP11.c_Encrypt (Int64.to_nativeint session_handle) real_data in
debug_print_ret "C_Encrypt" ret;
{c_encrypt_rv = (Int64.of_nativeint ret) ; c_encrypt_value = (Pkcs11.char_array_to_string encrypted_) }
(*************************************************************************)
let c_EncryptUpdate (session_handle, data) =
debug_print_call "C_EncryptUpdate";
let real_data = (Pkcs11.string_to_char_array data) in
let (ret, encrypted_) = CALLP11.c_EncryptUpdate (Int64.to_nativeint session_handle) real_data in
debug_print_ret "C_EncryptUpdate" ret;
{c_encryptupdate_rv = (Int64.of_nativeint ret) ; c_encryptupdate_value = (Pkcs11.char_array_to_string encrypted_) }
(*************************************************************************)
let c_EncryptFinal (session_handle) =
debug_print_call "C_EncryptFinal";
let (ret, encrypted_) = CALLP11.c_EncryptFinal (Int64.to_nativeint session_handle) in
debug_print_ret "C_EncryptFinal" ret;
{c_encryptfinal_rv = (Int64.of_nativeint ret) ; c_encryptfinal_value = (Pkcs11.char_array_to_string encrypted_) }
(*************************************************************************)
let c_DecryptInit (session_handle, mechanism, object_handle) =
debug_print_call "C_DecryptInit";
let real_mechanism = (ck_mechanism_rpc_aux_to_pkcs11 mechanism) in
let ret = CALLP11.c_DecryptInit (Int64.to_nativeint session_handle) real_mechanism (Int64.to_nativeint object_handle) in
debug_print_ret "C_DecryptInit" ret;
(Int64.of_nativeint ret)
(*************************************************************************)
let c_Decrypt (session_handle, data ) =
debug_print_call "C_Decrypt";
let real_data = (Pkcs11.string_to_char_array data) in
let (ret, decrypted_) = CALLP11.c_Decrypt (Int64.to_nativeint session_handle) real_data in
debug_print_ret "C_Decrypt" ret;
{c_decrypt_rv = (Int64.of_nativeint ret) ; c_decrypt_value = (Pkcs11.char_array_to_string decrypted_) }
(*************************************************************************)
let c_DecryptUpdate (session_handle, data) =
debug_print_call "C_DecryptUpdate";
let real_data = (Pkcs11.string_to_char_array data) in
let (ret, decrypted_) = CALLP11.c_DecryptUpdate (Int64.to_nativeint session_handle) real_data in
debug_print_ret "C_DecryptUpdate" ret;
{c_decryptupdate_rv = (Int64.of_nativeint ret) ; c_decryptupdate_value = (Pkcs11.char_array_to_string decrypted_) }
(*************************************************************************)
let c_DecryptFinal (session_handle) =
debug_print_call "C_DecryptFinal";
let (ret, decrypted_) = CALLP11.c_DecryptFinal (Int64.to_nativeint session_handle) in
debug_print_ret "C_DecryptFinal" ret;
{c_decryptfinal_rv = (Int64.of_nativeint ret) ; c_decryptfinal_value = (Pkcs11.char_array_to_string decrypted_) }
(*************************************************************************)
let c_SignRecoverInit (session_handle, mechanism, object_handle) =
debug_print_call "C_SignRecoverInit";
let real_mechanism = (ck_mechanism_rpc_aux_to_pkcs11 mechanism) in
let ret = CALLP11.c_SignRecoverInit (Int64.to_nativeint session_handle) real_mechanism (Int64.to_nativeint object_handle) in
debug_print_ret "C_SignRecoverInit" ret;
(Int64.of_nativeint ret)
(*************************************************************************)
let c_SignRecover (session_handle, data ) =
debug_print_call "C_SignRecover";
let real_data = (Pkcs11.string_to_char_array data) in
let (ret, recover_) = CALLP11.c_SignRecover (Int64.to_nativeint session_handle) real_data in
debug_print_ret "C_SignRecover" ret;
{c_signrecover_rv = (Int64.of_nativeint ret) ; c_signrecover_value = (Pkcs11.char_array_to_string recover_) }
(*************************************************************************)
let c_VerifyRecoverInit (session_handle, mechanism, object_handle) =
debug_print_call "C_VerifyRecoverInit";
let real_mechanism = (ck_mechanism_rpc_aux_to_pkcs11 mechanism) in
let ret = CALLP11.c_VerifyRecoverInit (Int64.to_nativeint session_handle) real_mechanism (Int64.to_nativeint object_handle) in
debug_print_ret "C_VerifyRecoverInit" ret;
(Int64.of_nativeint ret)
(*************************************************************************)
let c_VerifyRecover (session_handle, data ) =
debug_print_call "C_VerifyRecover";
let real_data = (Pkcs11.string_to_char_array data) in
let (ret, recover_) = CALLP11.c_VerifyRecover (Int64.to_nativeint session_handle) real_data in
debug_print_ret "C_VerifyRecover" ret;
{c_verifyrecover_rv = (Int64.of_nativeint ret) ; c_verifyrecover_value = (Pkcs11.char_array_to_string recover_) }
(*************************************************************************)
let c_DigestEncryptUpdate (session_handle, data ) =
debug_print_call "C_DigestEncryptUpdate";
let real_data = (Pkcs11.string_to_char_array data) in
let (ret, recover_) = CALLP11.c_DigestEncryptUpdate (Int64.to_nativeint session_handle) real_data in
debug_print_ret "C_DigestEncryptUpdate" ret;
{c_digestencryptupdate_rv = (Int64.of_nativeint ret) ; c_digestencryptupdate_value = (Pkcs11.char_array_to_string recover_) }
(*************************************************************************)
let c_DecryptDigestUpdate (session_handle, data ) =
debug_print_call "C_DecryptDigestUpdate";
let real_data = (Pkcs11.string_to_char_array data) in
let (ret, recover_) = CALLP11.c_DecryptDigestUpdate (Int64.to_nativeint session_handle) real_data in
debug_print_ret "C_DecryptDigestUpdate" ret;
{c_decryptdigestupdate_rv = (Int64.of_nativeint ret) ; c_decryptdigestupdate_value = (Pkcs11.char_array_to_string recover_) }
(*************************************************************************)
let c_SignEncryptUpdate (session_handle, data ) =
debug_print_call "C_SignEncryptUpdate";
let real_data = (Pkcs11.string_to_char_array data) in
let (ret, recover_) = CALLP11.c_SignEncryptUpdate (Int64.to_nativeint session_handle) real_data in
debug_print_ret "C_SignEncryptUpdate" ret;
{c_signencryptupdate_rv = (Int64.of_nativeint ret) ; c_signencryptupdate_value = (Pkcs11.char_array_to_string recover_) }
(*************************************************************************)
let c_DecryptVerifyUpdate (session_handle, data ) =
debug_print_call "C_DecryptVerifyUpdate";
let real_data = (Pkcs11.string_to_char_array data) in
let (ret, recover_) = CALLP11.c_DecryptVerifyUpdate (Int64.to_nativeint session_handle) real_data in
debug_print_ret "C_DecryptVerifyUpdate" ret;
{c_decryptverifyupdate_rv = (Int64.of_nativeint ret) ; c_decryptverifyupdate_value = (Pkcs11.char_array_to_string recover_) }
(*************************************************************************)
let c_GetOperationState (session_handle) =
debug_print_call "C_GetOperationState";
let (ret, state_) = CALLP11.c_GetOperationState (Int64.to_nativeint session_handle) in
debug_print_ret "C_GetOperationState" ret;
{c_getoperationstate_rv = (Int64.of_nativeint ret) ; c_getoperationstate_value = (Pkcs11.char_array_to_string state_) }
(*************************************************************************)
let c_SetOperationState (session_handle, state, encryption_handle, authentication_handle) =
debug_print_call "C_SetOperationState";
let real_state = (Pkcs11.string_to_char_array state) in
let ret = CALLP11.c_SetOperationState (Int64.to_nativeint session_handle) real_state (Int64.to_nativeint encryption_handle) (Int64.to_nativeint authentication_handle) in
debug_print_ret "C_SetOperationState" ret;
(Int64.of_nativeint ret)
(*************************************************************************)
let c_GetFunctionStatus (session_handle) =
debug_print_call "C_GetFunctionStatus";
let ret = CALLP11.c_GetFunctionStatus (Int64.to_nativeint session_handle) in
debug_print_ret "C_GetFunctionStatus" ret;
(Int64.of_nativeint ret)
(*************************************************************************)
let c_CancelFunction (session_handle) =
debug_print_call "C_CancelFunction";
let ret = CALLP11.c_CancelFunction (Int64.to_nativeint session_handle) in
debug_print_ret "C_CancelFunction" ret;
(Int64.of_nativeint ret)
(*************************************************************************)
IFDEF WITHOUT_FILTER THEN
let get_module_config_name (modulename) =
let regexpression =
if compare modulename "" = 0 then
Printf.sprintf "\\(^\|.*;\\):\\([^;]*\\);"
else
Printf.sprintf ".*%s:\\([^;]*\\);" modulename
in
let matching_group =
if compare modulename "" = 0 then
2
else
1
in
let b = Str.string_match (Str.regexp regexpression) !libnames_config_ref 0 in
if b = false then
begin
(* Return thet the module has not been found *)
let s = Printf.sprintf "C_LoadModule in process %d did not match any libname for '%s'!" (Unix.getpid()) modulename in
Netplex_cenv.log `Err s;
raise (Failure "Reading configuration");
end
else
begin
let matchedlib = Str.matched_group matching_group !libnames_config_ref in
(* Debug *)
if !ref_pkcs_debug = 1
then begin
let s = Printf.sprintf "C_LoadModule aliased '%s' to '%s' in process %d" modulename matchedlib (Unix.getpid()) in
Netplex_cenv.log `Info s;
end;
(matchedlib)
end;
ELSE
let get_module_config_name (modulename) =
(modulename)
ENDIF
let c_LoadModule (modulename) =
debug_print_call "C_LoadModule";
let ret =
(try CALLP11.c_LoadModule (Pkcs11.string_to_char_array (get_module_config_name modulename))
(* If we have an exception, there is a problem, return an error *)
with _ -> (Pkcs11.cKR_GENERAL_ERROR)) in
debug_print_ret "C_LoadModule" ret;
(Int64.of_nativeint ret)
let setup srv _ =
Pkcs11_rpc_srv.P.V.bind
~proc_c_setuparch: c_SetupArch
~proc_c_initialize: c_Initialize
~proc_c_getslotlist: c_GetSlotList
~proc_c_getinfo: c_GetInfo
~proc_c_getslotinfo: c_GetSlotInfo
~proc_c_gettokeninfo: c_GetTokenInfo
~proc_c_finalize: c_Finalize
~proc_c_waitforslotevent: c_WaitForSlotEvent
~proc_c_login: c_Login
~proc_c_logout: c_Logout
~proc_c_opensession: c_OpenSession
~proc_c_closesession: c_CloseSession
~proc_c_getmechanismlist: c_GetMechanismList
~proc_c_closeallsessions: c_CloseAllSessions
~proc_c_getsessioninfo: c_GetSessionInfo
~proc_c_getmechanisminfo: c_GetMechanismInfo
~proc_c_initpin: c_InitPIN
~proc_c_setpin: c_SetPIN
~proc_c_seedrandom: c_SeedRandom
~proc_c_inittoken: c_InitToken
~proc_c_generaterandom: c_GenerateRandom
~proc_c_findobjectsinit: c_FindObjectsInit
~proc_c_findobjects: c_FindObjects
~proc_c_findobjectsfinal: c_FindObjectsFinal
~proc_c_generatekey: c_GenerateKey
~proc_c_generatekeypair: c_GenerateKeyPair
~proc_c_createobject: c_CreateObject
~proc_c_copyobject: c_CopyObject
~proc_c_destroyobject: c_DestroyObject
~proc_c_getattributevalue: c_GetAttributeValue
~proc_c_setattributevalue: c_SetAttributeValue
~proc_c_getobjectsize: c_GetObjectSize
~proc_c_wrapkey: c_WrapKey
~proc_c_unwrapkey: c_UnwrapKey
~proc_c_derivekey: c_DeriveKey
~proc_c_digestinit: c_DigestInit
~proc_c_digest: c_Digest
~proc_c_digestupdate: c_DigestUpdate
~proc_c_digestfinal: c_DigestFinal
~proc_c_digestkey: c_DigestKey
~proc_c_signinit: c_SignInit
~proc_c_sign: c_Sign
~proc_c_signupdate: c_SignUpdate
~proc_c_signfinal: c_SignFinal
~proc_c_verifyinit: c_VerifyInit
~proc_c_verify: c_Verify
~proc_c_verifyupdate: c_VerifyUpdate
~proc_c_verifyfinal: c_VerifyFinal
~proc_c_encryptinit: c_EncryptInit
~proc_c_encrypt: c_Encrypt
~proc_c_encryptupdate: c_EncryptUpdate
~proc_c_encryptfinal: c_EncryptFinal
~proc_c_decryptinit: c_DecryptInit
~proc_c_decrypt: c_Decrypt
~proc_c_decryptupdate: c_DecryptUpdate
~proc_c_decryptfinal: c_DecryptFinal
~proc_c_signrecoverinit: c_SignRecoverInit
~proc_c_signrecover: c_SignRecover
~proc_c_verifyrecoverinit: c_VerifyRecoverInit
~proc_c_verifyrecover: c_VerifyRecover
~proc_c_digestencryptupdate: c_DigestEncryptUpdate
~proc_c_signencryptupdate: c_SignEncryptUpdate
~proc_c_decryptdigestupdate: c_DecryptDigestUpdate
~proc_c_decryptverifyupdate: c_DecryptVerifyUpdate
~proc_c_getoperationstate: c_GetOperationState
~proc_c_setoperationstate: c_SetOperationState
~proc_c_getfunctionstatus: c_GetFunctionStatus
~proc_c_cancelfunction: c_CancelFunction
~proc_c_loadmodule: c_LoadModule
srv
(* WITHOUT SSL *)
IFNDEF WITH_SSL THEN
let socket_config _ = Rpc_server.default_socket_config
IFDEF WITHOUT_FILTER THEN
let configure cf addr =
(* Handle filter passthrough for the specific C_LoadModule call *)
let filter_config_file =
try
Some (cf # string_param (cf # resolve_parameter addr "filter_config"))
with
| Not_found -> (None); in
if filter_config_file <> None
then
begin
let s = Printf.sprintf "CONFIGURATION: unused option 'filter_config' found in the server configuration file while the server has been compiled with filter passthrough!" in
Netplex_cenv.log `Info s;
end;
let libnames_config =
try
cf # string_param (cf # resolve_parameter addr "libnames")
with
| Not_found -> failwith "Required parameter libnames is missing! (server compiled with filter passthrough mode)!" in
libnames_config_ref := libnames_config;
("")
ELSE
let configure cf addr =
(* Warning if this parameter is present! *)
let libnames_config =
try
Some (cf # string_param (cf # resolve_parameter addr "libnames"))
with
| Not_found -> (None); in
if libnames_config <> None
then
begin
let s = Printf.sprintf "CONFIGURATION: unused option 'libnames' found in the server configuration file while the server has been compiled for using the filter module!" in
Netplex_cenv.log `Info s;
end;
(* Handle configuration file for the filter *)
let filter_config_file =
try
cf # string_param (cf # resolve_parameter addr "filter_config")
with
| Not_found -> failwith "Required parameter filter_config is missing! (this is a path to the filter configuration rules)" in
filter_config_file_ref := filter_config_file;
("")
ENDIF
ENDIF
IFNDEF WITHOUT_FILTER
THEN
(* Loading modules for Netplex levers *)
module T = struct
type s = string (* argument type. Here, the message string *)
type r = bool (* result type. Here, whether the lever was successful *)
end
module L = Netplex_cenv.Make_lever(T)
module LV = Netplex_cenv.Make_var_type(L)
IFDEF DAEMONIZE THEN
(** Filter hooks that are defined when we use the filter *)
let custom_hooks =
( object
inherit Netplex_kit.empty_processor_hooks()
val mutable server_shutdown_lever = (fun _ -> assert false)
method post_add_hook _ ctrl =
(* This is run in controller context, right after program startup.
Register now the lever function, which starts a helper service.
*)
let lever =
L.register ctrl
(fun _ _ -> Netplex_cenv.system_shutdown (); (true)) in
(* Remember the created lever until the child forks *)
server_shutdown_lever <- lever;
(* Call C_Daemonize *)
if !ref_daemonize_args = "" then
begin
let param = (Pkcs11.string_to_char_array "") in
let _ = c_Daemonize param in
()
end
else
begin
let param = (Pkcs11.string_to_char_array !ref_daemonize_args) in
let _ = c_Daemonize param in
()
end
method post_start_hook _ =
(* Make the lever generally available in the child *)
LV.set "server_shutdown_lever" server_shutdown_lever;
(* Get the shutdow helper *)
let shutdown_lever = LV.get "server_shutdown_lever" in
try Filter_configuration.get_config !filter_config_file_ref
with Filter_common.Modules_except -> let _ = shutdown_lever "0" in failwith "Filter configuration: modules parsing error!";
| Filter_common.Mechanisms_except -> let _ = shutdown_lever "0" in failwith "Filter configuration: mechanisms parsing error!";
| Filter_common.Labels_except -> let _ = shutdown_lever "0" in failwith "Filter configuration: labels parsing error!";
| Filter_common.Ids_except -> let _ = shutdown_lever "0" in failwith "Filter configuration: ids parsing error!";
| Filter_common.P11_functions_except -> let _ = shutdown_lever "0" in failwith "Filter configuration: PKCS#11 functions parsing error!";
| Filter_common.Enforce_RO_except -> let _ = shutdown_lever "0" in failwith "Filter configuration: RO enforcing option parsing error!";
| Filter_common.Forbid_admin -> let _ = shutdown_lever "0" in failwith "Filter configuration: forbid admin option parsing error!";
| Filter_common.Remove_padding_oracles -> let _ = shutdown_lever "0" in failwith "Filter configuration: remove padding oracles option parsing error!";
| Filter_common.Actions_except -> let _ = shutdown_lever "0" in failwith "Filter configuration: filter actions parsing error!";
| Filter_common.Config_file_none -> let _ = shutdown_lever "0" in failwith "Filter configuration: no configuration file!";
| Filter_common.Config_file_wrong_type -> let _ = shutdown_lever "0" in failwith "Filter configuration: critical exception when parsing the configuration file!";
| _ -> let _ = shutdown_lever "0" in failwith "Filter configuration: unknown critical exception when parsing the configuration file!";
(*method post_finish_hook _ _ _ = Netlog.logf `Info "post_finish_hook in pid %d" (Unix.getpid());*)
(* method shutdown () = Netlog.logf `Info "shutdow hook in pid %d" (Unix.getpid()); *)
end
)
ELSE
(** Filter hooks that are defined when we use the filter *)
let custom_hooks =
( object(_)
inherit Netplex_kit.empty_processor_hooks()
val mutable server_shutdown_lever = (fun _ -> assert false)
method post_add_hook _ ctrl =
(* This is run in controller context, right after program startup.
Register now the lever function, which starts a helper service.
*)
let lever =
L.register ctrl
(fun _ _ -> Netplex_cenv.system_shutdown (); (true)) in
(* Remember the created lever until the child forks *)
server_shutdown_lever <- lever
method post_start_hook _ =
(* Make the lever generally available in the child *)
LV.set "server_shutdown_lever" server_shutdown_lever;
(* Get the shutdow helper *)
let shutdown_lever = LV.get "server_shutdown_lever" in
try Filter_configuration.get_config !filter_config_file_ref
with Filter_common.Modules_except -> let _ = shutdown_lever "0" in failwith "Filter configuration: modules parsing error!";
| Filter_common.Mechanisms_except -> let _ = shutdown_lever "0" in failwith "Filter configuration: mechanisms parsing error!";
| Filter_common.Labels_except -> let _ = shutdown_lever "0" in failwith "Filter configuration: labels parsing error!";
| Filter_common.Ids_except -> let _ = shutdown_lever "0" in failwith "Filter configuration: ids parsing error!";
| Filter_common.P11_functions_except -> let _ = shutdown_lever "0" in failwith "Filter configuration: PKCS#11 functions parsing error!";
| Filter_common.Enforce_RO_except -> let _ = shutdown_lever "0" in failwith "Filter configuration: RO enforcing option parsing error!";
| Filter_common.Forbid_admin -> let _ = shutdown_lever "0" in failwith "Filter configuration: forbud admin option parsing error!";
| Filter_common.Remove_padding_oracles -> let _ = shutdown_lever "0" in failwith "Filter configuration: remove padding oracles option parsing error!";
| Filter_common.Actions_except -> let _ = shutdown_lever "0" in failwith "Filter configuration: filter actions parsing error!";
| Filter_common.Config_file_none -> let _ = shutdown_lever "0" in failwith "Filter configuration: no configuration file!";
| Filter_common.Config_file_wrong_type -> let _ = shutdown_lever "0" in failwith "Filter configuration: critical exception when parsing the configuration file!";
| _ -> let _ = shutdown_lever "0" in failwith "Filter configuration: unknown critical exception when parsing the configuration file!";
(* method post_finish_hook _ _ _ = Netlog.logf `Info "post_finish_hook in pid %d" (Unix.getpid()); *)
(* method shutdown () = Netlog.logf `Info "shutdow hook in pid %d" (Unix.getpid()); *)
(* method global_exception_handler _ = Netlog.logf `Info "exception handler hook in pid %d" (Unix.getpid()); (true) *)
end
)
ENDIF
ELSE
IFDEF DAEMONIZE
THEN
let custom_hooks =
( object(self)
inherit Netplex_kit.empty_processor_hooks()
method post_add_hook _ _ =
if !ref_daemonize_args = "" then
begin
let param = (Pkcs11.string_to_char_array "") in
let _ = c_Daemonize param in
()
end
else
begin
let param = (Pkcs11.string_to_char_array !ref_daemonize_args) in
let _ = c_Daemonize param in
()
end
end
)
ELSE
let custom_hooks =
( object(self)
inherit Netplex_kit.empty_processor_hooks()
end
)
ENDIF
ENDIF
let rpc_pkcs11_factory =
Rpc_netplex.rpc_factory
~configure
~socket_config
~name:"rpc_pkcs11"
~setup
~hooks:(fun _ -> custom_hooks)
(* No need for posthooks when there is no filte r*)
()
let enable_pkcs_debug () =
ref_pkcs_debug := 1;
()
let set_daemonize_args s =
ref_daemonize_args := s;
()
let start() =
let (opt_list, cmdline_cfg) = Netplex_main.args() in
let opt_list =
[ "-debug", Arg.String (fun s -> Netlog.Debug.enable_module s),
"<module> Enable debug messages for <module>";
"-debug-all", Arg.Unit (fun () -> Netlog.Debug.enable_all()),
" Enable all debug messages";
"-debug-list", Arg.Unit (fun () -> List.iter print_endline (Netlog.Debug.names());