summaryrefslogtreecommitdiff
path: root/docs/howto/config.rst
blob: 0cbfcbf1f755bb0ff7a97f92d645d3e741db7d6a (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
.. _howto_config:

Configuration of PySAML2 entities
=================================

Whether you plan to run a PySAML2 Service Provider, Identity Provider or an
attribute authority, you have to configure it. The format of the configuration
file is the same regardless of which type of service you plan to run.
What differs are some of the directives.
Below you will find a list of all the used directives in alphabetical order.
The configuration is written as a python module which contains a named
dictionary ("CONFIG") that contains the configuration directives.

The basic structure of the configuration file is therefore like this::

    from saml2 import BINDING_HTTP_REDIRECT

    CONFIG = {
        "entityid": "http://saml.example.com:saml/idp.xml",
        "name": "Rolands IdP",
        "service": {
            "idp": {
                "endpoints": {
                    "single_sign_on_service": [
                        (
                            "http://saml.example.com:saml:8088/sso",
                            BINDING_HTTP_REDIRECT,
                        ),
                    ],
                    "single_logout_service": [
                        (
                            "http://saml.example.com:saml:8088/slo",
                            BINDING_HTTP_REDIRECT,
                        ),
                    ],
                },
                ...
            }
        },
        "key_file": "my.key",
        "cert_file": "ca.pem",
        "xmlsec_binary": "/usr/local/bin/xmlsec1",
        "delete_tmpfiles": True,
        "metadata": {
            "local": [
                "edugain.xml",
            ],
        },
        "attribute_map_dir": "attributemaps",
        ...
    }

.. note:: You can build the metadata file for your services directly from the
    configuration. The make_metadata.py script in the PySAML2 tools directory
    will do that for you.

Configuration directives
::::::::::::::::::::::::

.. contents::
    :local:
    :backlinks: entry

General directives
------------------

logging
^^^^^^^

The logging configuration format is the python logging format.
The configuration is passed to the python logging dictionary configuration handler,
directly.

Example::

    "logging": {
        "version": 1,
        "formatters": {
            "simple": {
                "format": "[%(asctime)s] [%(levelname)s] [%(name)s.%(funcName)s] %(message)s",
            },
        },
        "handlers": {
            "stdout": {
                "class": "logging.StreamHandler",
                "stream": "ext://sys.stdout",
                "level": "DEBUG",
                "formatter": "simple",
            },
        },
        "loggers": {
            "saml2": {
                "level": "DEBUG"
            },
        },
        "root": {
            "level": "DEBUG",
            "handlers": [
                "stdout",
            ],
        },
    },

The example configuration above will enable DEBUG logging to stdout.


debug
^^^^^

Example::

    debug: 1

Whether debug information should be sent to the log file.

additional_cert_files
^^^^^^^^^^^^^^^^^^^^^

Example::

    additional_cert_files: ["other-cert.pem", "another-cert.pem"]

Additional public certs that will be listed.  Useful during cert/key rotation or
if you need to include a certificate chain.

Each entry in *additional_cert_files* must be a PEM formatted file with a single certificate.

entity_attributes
^^^^^^^^^^^^^^^^^

Generates an ``Attribute`` element with the given NameFormat, Name, FriendlyName and
values, each as an ``AttributeValue`` element.

The element is added under the generated metadata ``EntityDescriptor`` as an
``Extension`` element under the ``EntityAttributes`` element.

And omit

Example::

    "entity_attributes": [
      {
        "name_format": "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
        "name": "urn:oasis:names:tc:SAML:profiles:subject-id:req",
        # "friendly_name" is not set
        "values": ["any"],
      },
    ]


assurance_certification
^^^^^^^^^^^^^^^^^^^^^^^

Example::

    "assurance_certification": [
        "https://refeds.org/sirtfi",
    ]

Generates an ``Attribute`` element with name-format
``urn:oasis:names:tc:SAML:2.0:attrname-format:uri`` and name
``urn:oasis:names:tc:SAML:attribute:assurance-certification`` that contains
``AttributeValue`` elements with the given values from the list.
The element is added under the generated metadata ``EntityDescriptor`` as an
``Extension`` element under the ``EntityAttributes`` element.

Read more about `representing assurance information at the specification <https://wiki.oasis-open.org/security/SAML2IDAssuranceProfile>`_.

attribute_map_dir
^^^^^^^^^^^^^^^^^

Points to a directory which has the attribute maps in Python modules.

Example::

    "attribute_map_dir": "attribute-maps"

A typical map file will look like this::

    MAP = {
        "identifier": "urn:oasis:names:tc:SAML:2.0:attrname-format:basic",
        "fro": {
            'urn:mace:dir:attribute-def:aRecord': 'aRecord',
            'urn:mace:dir:attribute-def:aliasedEntryName': 'aliasedEntryName',
            'urn:mace:dir:attribute-def:aliasedObjectName': 'aliasedObjectName',
            'urn:mace:dir:attribute-def:associatedDomain': 'associatedDomain',
            'urn:mace:dir:attribute-def:associatedName': 'associatedName',
            ...
        },
        "to": {
            'aRecord': 'urn:mace:dir:attribute-def:aRecord',
            'aliasedEntryName': 'urn:mace:dir:attribute-def:aliasedEntryName',
            'aliasedObjectName': 'urn:mace:dir:attribute-def:aliasedObjectName',
            'associatedDomain': 'urn:mace:dir:attribute-def:associatedDomain',
            'associatedName': 'urn:mace:dir:attribute-def:associatedName',
            ...
        }
    }

The attribute map module contains a MAP dictionary with three items.  The
`identifier` item is the name-format you expect to support.
The *to* and *fro* sub-dictionaries then contain the mapping between the names.

As you see the format is again a python dictionary where the key is the
name to convert from, and the value is the name to convert to.

Since *to* in most cases is the inverse of the *fro* file, the
software allows you only to specify one of them, and it will
automatically create the other.

contact_person
^^^^^^^^^^^^^^

This is only used by *make_metadata.py* when it constructs the metadata for
the service described by the configuration file.
This is where you describe who can be contacted if questions arise
about the service or if support is needed. The possible types are according to
the standard **technical**, **support**, **administrative**, **billing**
and **other**.::

    contact_person: [
        {
            "givenname": "Derek",
            "surname": "Jeter",
            "company": "Example Co.",
            "mail": ["jeter@example.com"],
            "type": "technical",
        },
        {
            "givenname": "Joe",
            "surname": "Girardi",
            "company": "Example Co.",
            "mail": "girardi@example.com",
            "type": "administrative",
        },
    ]

entityid
^^^^^^^^

Example::

    entityid: "http://saml.example.com/sp"

The globally unique identifier of the entity.

.. note:: It is recommended that the entityid should point to a real
    webpage where the metadata for the entity can be found.

name
^^^^

A string value that sets the name of the PySAML2 entity.

Example::

    "name": "Example IdP"

description
^^^^^^^^^^^

A string value that sets the description of the PySAML2 entity.

Example::

    "description": "My IdP",

verify_ssl_cert
^^^^^^^^^^^^^^^

Specifies if the SSL certificates should be verified. Can be ``True`` or ``False``.
The default configuration is ``False``.

Example::

    "verify_ssl_cert": True

key_file
^^^^^^^^

Example::

    key_file: "key.pem"

*key_file* is the name of a PEM formatted file that contains the private key
of the service. This is currently used both to encrypt/sign assertions and as
the client key in an HTTPS session.

cert_file
^^^^^^^^^

Example::

    cert_file: "cert.pem"

This is the public part of the service private/public key pair.
*cert_file* must be a PEM formatted file with a single certificate.

tmp_cert_file
^^^^^^^^^^^^^

Example::
    "tmp_cert_file": "tmp_cert.pem"

*tmp_cert_file* is a PEM formatted certificate file

tmp_key_file
^^^^^^^^^^^^

Example::
    "tmp_key_file": "tmp_key.pem"

*tmp_key_file* is a PEM formatted key file.

encryption_keypairs
^^^^^^^^^^^^^^^^^^^

Indicates which certificates will be used for encryption capabilities::

    # Encryption
    'encryption_keypairs': [
        {
            'key_file': BASE_DIR + '/certificates/private.key',
            'cert_file': BASE_DIR + '/certificates/public.cert',
        },
    ],

generate_cert_info
^^^^^^^^^^^^^^^^^^

Specifies if information about the certificate should be generated.
A boolean value can be ``True`` or ``False``.

Example::

    "generate_cert_info": False


ca_certs
^^^^^^^^

This is the path to a file containing root CA certificates for SSL server certificate validation.

Example::

    "ca_certs": full_path("cacerts.txt"),


metadata
^^^^^^^^

Contains a list of places where metadata can be found. This can be

* a local directory accessible on the server the service runs on
* a local file accessible on the server the service runs on
* a remote URL serving aggregate metadata
* a metadata query protocol (MDQ) service URL

For example::

    "metadata": {
        "local": [
            "/opt/metadata"
            "metadata.xml",
            "vo_metadata.xml",
        ],
        "remote": [
            {
                "url": "https://kalmar2.org/simplesaml/module.php/aggregator/?id=kalmarcentral2&set=saml2",
                "cert": "kalmar2.cert",
            },
        ],
        "mdq": [
            {
                "url": "http://mdq.ukfederation.org.uk/",
                "cert": "ukfederation-mdq.pem",
                "freshness_period": "P0Y0M0DT2H0M0S",
            },
            {
                "url": "https://mdq.thaturl.org/",
                "disable_ssl_certificate_validation": True,
                "check_validity": False,
            },
        ],
    },

The above configuration means that the service should read two aggregate local
metadata files, one aggregate metadata file from a remote server, and query a
remote MDQ server. To verify the authenticity of the metadata aggregate
downloaded from the remote server and the MDQ server local copies of the
metadata signing certificates should be used.  These public keys must be
acquired by some secure out-of-band method before being placed on the local
file system.

When the parameter *check_validity* is set to False metadata that have expired
will be accepted as valid.

When the paramenter *disable_ssl_certificate_validation* is set to True the
validity of ssl certificate will be skipped.

When using MDQ, the `freshness_period` option can be set to define a period for
which the metadata fetched from the the MDQ server are considered fresh. After
that period has passed the metadata are not valid anymore and must be fetched
again. The period must be in the format defined in
`ISO 8601 <https://www.iso.org/iso-8601-date-and-time-format.html>`_
or `RFC3999 <https://tools.ietf.org/html/rfc3339#appendix-A>`_.

By default, if `freshness_period` is not defined, the metadata are refreshed
every 12 hours (`P0Y0M0DT12H0M0S`).


organization
^^^^^^^^^^^^

Only used by *make_metadata.py*.
Where you describe the organization responsible for the service.::

    "organization": {
        "name": [
            ("Example Company", "en"),
            ("Exempel AB", "se")
        ],
        "display_name": ["Exempel AB"],
        "url": [
            ("http://example.com", "en"),
            ("http://exempel.se", "se"),
        ],
    }

.. note:: You can specify the language of the name, or the language used on
    the webpage, by entering a tuple, instead of a simple string,
    where the second part is the language code. If you don't specify a
    language, the default is "en" (English).

preferred_binding
^^^^^^^^^^^^^^^^^

Which binding should be preferred for a service.
Example configuration::

    "preferred_binding" = {
        "single_sign_on_service": [
            'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect',
            'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST',
            'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Artifact',
        ],
        "single_logout_service": [
            'urn:oasis:names:tc:SAML:2.0:bindings:SOAP',
            'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect',
            'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST',
            'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Artifact',
        ],
    }

The available services are:

* manage_name_id_service
* assertion_consumer_service
* name_id_mapping_service
* authn_query_service
* attribute_service
* authz_service
* assertion_id_request_service
* artifact_resolution_service
* attribute_consuming_service
* single_logout_service


service
^^^^^^^

Which services the server will provide; those are combinations of "idp", "sp"
and "aa".
So if a server is a Service Provider (SP) then the configuration
could look something like this::

    "service": {
        "sp": {
            "name": "Rolands SP",
            "endpoints": {
                "assertion_consumer_service": ["http://localhost:8087/"],
                "single_logout_service": [
                    (
                        "http://localhost:8087/slo",
                        'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect',
                    ),
                ],
            },
            "required_attributes": [
                "surname",
                "givenname",
                "edupersonaffiliation",
            ],
            "optional_attributes": ["title"],
            "idp": {
                "urn:mace:umu.se:saml:roland:idp": None,
            },
        }
    },

There are two options common to all services: 'name' and 'endpoints'.
The remaining options are specific to one or the other of the service types.
Which one is specified alongside the name of the option.

accepted_time_diff
^^^^^^^^^^^^^^^^^^

If your computer and another computer that you are communicating with are not
in sync regarding the computer clock, then here you can state how big a
difference you are prepared to accept.

.. note:: This will indiscriminately affect all time comparisons.
    Hence your server may accept a statement that in fact is too old.

allow_unknown_attributes
^^^^^^^^^^^^^^^^^^^^^^^^

Indicates that attributes that are not recognized (they are not configured in
attribute-mapping), will not be discarded.
Default to False.

xmlsec_binary
^^^^^^^^^^^^^

Currently xmlsec1 binaries are used for all the signing and encryption stuff.
This option defines where the binary is situated.

Example::

    "xmlsec_binary": "/usr/local/bin/xmlsec1",

xmlsec_path
^^^^^^^^^^^

This option is used to define non-system paths where the xmlsec1 binary can be located.
It can be used when the xmlsec_binary option is not defined.

Example::

    "xmlsec_path": ["/usr/local/bin", "/opt/local/bin"],

OR::

    from saml2.sigver import get_xmlsec_binary

    if get_xmlsec_binary:
        xmlsec_path = get_xmlsec_binary(["/opt/local/bin","/usr/local/bin"])
    else:
        xmlsec_path = '/usr/bin/xmlsec1'

    "xmlsec_binary": xmlsec_path,


delete_tmpfiles
^^^^^^^^^^^^^^^

In many cases temporary files will have to be created during the
encryption/decryption/signing/validation process.
This option defines whether these temporary files will be automatically deleted when
they are no longer needed. Setting this to False, will keep these files until they are
manually deleted or automatically deleted by the OS (i.e Linux rules for /tmp).
Absence of this option, defaults to True.


valid_for
^^^^^^^^^

How many *hours* this configuration is expected to be accurate.::

    "valid_for": 24

This, of course, is only used by *make_metadata.py*.
The server will not stop working when this amount of time has elapsed :-).


metadata_key_usage
^^^^^^^^^^^^^^^^^^^

This specifies the purpose of the entity's cryptographic keys used to sign data.
If this option is not configured it will default to ``"both"``.

The possible options for this configuration are ``both``, ``signing``, ``encryption``.

If metadata_key_usage is set to ``"signing"`` or ``"both"``, and a cert_file is provided
the value of use in the KeyDescriptor element will be set to ``"signing"``.

If metadata_key_usage is set to ``"both"`` or ``"encryption"`` and a enc_cert is provided
the value of ``"use"`` in the KeyDescriptor will be set to ``"encryption"``.

Example::

    "metadata_key_usage" : "both",


secret
^^^^^^

A string value that is used in the generation of the RelayState.

Example::

    "secret": "0123456789",

crypto_backend
^^^^^^^^^^^^^^
Defines the crypto backend used for signing and encryption. The default is ``xmlsec1``.
The options are ``xmlsec1`` and ``XMLSecurity``.

If set to "XMLSecurity", the crypto backend will be pyXMLSecurity.

Example::

    "crypto_backend": "xmlsec1",

verify_encrypt_advice
^^^^^^^^^^^^^^^^^^^^^

Specifies if the encrypted assertions in the advice element should be verified.
Can be ``True`` or ``False``.

Example::

    def verify_encrypt_cert(cert_str):
        osw = OpenSSLWrapper()
        ca_cert_str = osw.read_str_from_file(full_path("root_cert/localhost.ca.crt"))
        valid, mess = osw.verify(ca_cert_str, cert_str)
        return valid

::

    "verify_encrypt_cert_advice": verify_encrypt_cert,


verify_encrypt_cert_assertion
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Specifies if the encrypted assertions should be verified.
Can be ``True`` or ``False``.

Example::

    "verify_encrypt_cert_assertion": verify_encrypt_cert


Specific directives
-------------------

Directives that are specific to a certain type of service.

idp/aa
^^^^^^

Directives that are specific to an IdP or AA service instance.

sign_assertion
""""""""""""""

Specifies if the IdP should sign the assertion in an authentication response
or not. Can be True or False. Default is False.

sign_response
"""""""""""""

Specifies if the IdP should sign the authentication response or not. Can be
True or False. Default is False.

encrypt_assertion
"""""""""""""""""

Specifies if the IdP should encrypt the assertions. Can be ``True`` or ``False``.
Default is ``False``.

encrypted_advice_attributes
"""""""""""""""""""""""""""
Specifies if assertions in the advice element should be encrypted.
Can be ``True`` or ``False``. Default is ``False``.

encrypt_assertion_self_contained
""""""""""""""""""""""""""""""""

Specifies if all encrypted assertions should have all namespaces self contained.
Can be ``True`` or ``False``. Default is ``True``.

want_authn_requests_signed
""""""""""""""""""""""""""

Indicates that the AuthnRequest received by this IdP should be signed. Can be ``True`` or ``False``.
The default value is ``False``.

want_authn_requests_only_with_valid_cert
""""""""""""""""""""""""""""""""""""""""

When verifying a signed AuthnRequest ignore the signature and verify the
certificate.

policy
""""""

If the server is an IdP and/or an AA, then there might be reasons to do things
differently depending on who is asking (which is the requesting service); the
policy is where this behaviour is specified.

The keys are SP entity identifiers, Registration Authority names, or 'default'.
First, the policy for the requesting service is looked up using the SP entityID.
If no such policy is found, and if the SP metadata includes a Registration
Authority then a policy for the registration authority is looked up using the
Registration Authority name. If no policy is found, then the 'default' is looked
up. If there is no default and only SP entity identifiers as keys, then the
server will only accept connections from the specified SPs.

An example might be::

    "service": {
        "idp": {
            "policy": {
                # a policy for a service
                "urn:mace:example.com:saml:roland:sp": {
                    "lifetime": {"minutes": 5},
                    "attribute_restrictions": {
                        "givenName": None,
                        "surName": None,
                    },
                },

                # a policy for a registration authority
                "http://www.swamid.se/": {
                    "attribute_restrictions": {
                        "givenName": None,
                    },
                },

                # the policy for all other services
                "default": {
                    "lifetime": {"minutes":15},
                    "attribute_restrictions": None, # means all I have
                    "name_form": "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
                    "entity_categories": [
                        "edugain",
                    ],
                },
            }
        }
    }

*lifetime*
    This is the maximum amount of time before the information should be
    regarded as stale. In an Assertion, this is represented in the NotOnOrAfter
    attribute.
*attribute_restrictions*
    By default, there are no restrictions as to which attributes should be
    returned. Instead, all the attributes and values that are gathered by the
    database backends will be returned if nothing else is stated.
    In the example above the SP with the entity identifier
    "urn:mace:umu.se:saml:roland:sp"
    has an attribute restriction: only the attributes
    'givenName' and 'surName' are to be returned. There are no limitations as to
    what values on these attributes that can be returned.
*name_form*
    Which name-form that should be used when sending assertions.
    Using this information, the attribute name in the data source will be mapped to
    the friendly name, and the saml attribute name will be taken from the uri/oid
    defined in the attribute map.
*nameid_format*
    Which nameid format that should be used. Defaults to
    `urn:oasis:names:tc:SAML:2.0:nameid-format:transient`.
*entity_categories*
    Entity categories to apply.
*sign*
    Possible choices: "response", "assertion", "on_demand"

If restrictions on values are deemed necessary, those are represented by
regular expressions.::

    "service": {
        "aa": {
            "policy": {
                "urn:mace:umu.se:saml:roland:sp": {
                    "lifetime": {"minutes": 5},
                    "attribute_restrictions": {
                         "mail": [".*\.umu\.se$"],
                    }
                }
            }
        }
    }

Here only mail addresses that end with ".umu.se" will be returned.

scope
"""""

A list of string values that will be used to set the ``<Scope>`` element
The default value of regexp is ``False``.

Example::

    "scope": ["example.org", "example.com"],


ui_info
""""""""

This determines what information to display about an entity by
configuring its mdui:UIInfo element. The configurable options include;

*privacy_statement_url*
    The URL to information about the privacy practices of the entity.
*information_url*
    Which URL contains localized information about the entity.
*logo*
    The logo image for the entity. The value is a dictionary with keys
    height, width and text.
*display_name*
    The localized name for the entity.
*description*
    The localized description of the entity. The value is a dictionary with keys
    text and lang.
*keywords*
    The localized search keywords for the entity. The value is a dictionary with keys
    lang and text.

Example::

    "ui_info": {
    "privacy_statement_url": "http://example.com/saml2/privacyStatement.html",
    "information_url": "http://example.com/saml2/info.html",
    "logo": {
        "height": "40",
        "width" : "30",
        "text": "http://example.com/logo.jpg"
    },
    "display_name": "Example Co.",
    "description" : {"text":"Exempel Bolag","lang":"se"},
    "keywords": {"lang":"en", "text":["foo", "bar"]}
    }


name_qualifier
""""""""""""""

A string value that sets the ``NameQualifier`` attribute of the ``<NameIdentifier>`` element.

Example::

    "name_qualifier": "http://authentic.example.com/saml/metadata",


session_storage
"""""""""""""""

Example::

    "session_storage": ("mongodb", "session")

domain
""""""

Example::

    "domain": "umu.se",

sp
^^

Directives specific to SP instances

authn_requests_signed
"""""""""""""""""""""

Indicates if the Authentication Requests sent by this SP should be signed
by default. This can be overridden by application code for a specific call.

This sets the AuthnRequestsSigned attribute of the SPSSODescriptor node
of the metadata so the IdP will know this SP preference.

Valid values are True or False. Default value is True.

Example::

    "service": {
        "sp": {
            "authn_requests_signed": True,
        }
    }


want_response_signed
""""""""""""""""""""

Indicates that Authentication Responses to this SP must be signed. If set to
True, the SP will not consume any SAML Responses that are not signed.

Valid values are True or False. Default value is True.

Example::

    "service": {
        "sp": {
            "want_response_signed": True,
        }
    }


force_authn
"""""""""""

Mandates that the identity provider MUST authenticate the presenter directly
rather than rely on a previous security context.

Example::

    "service": {
        "sp": {
            "force_authn": True,
        }
    }


name_id_policy_format
"""""""""""""""""""""

A string value that will be used to set the ``Format`` attribute of the
``<NameIDPolicy>`` element of an ``<AuthnRequest>``.

Example::

    "service": {
        "sp": {
            "name_id_policy_format": "urn:oasis:names:tc:SAML:2.0:nameid-format:persistent",
        }
    }


name_id_format_allow_create
"""""""""""""""""""""""""""

A boolean value (``True`` or ``False``) that will be used to set the ``AllowCreate``
attribute of the ``<NameIDPolicy>`` element of an ``<AuthnRequest>``.

Example::

    "service": {
        "sp": {
            "name_id_format_allow_create": True,
        }
    }


name_id_format
""""""""""""""

A list of string values that will be used to set the ``<NameIDFormat>`` element of the
metadata of an entity.

Example::

    "service": {
        "sp": {
            "name_id_format": [
                "urn:oasis:names:tc:SAML:2.0:nameid-format:persistent",
                "urn:oasis:names:tc:SAML:2.0:nameid-format:transient",
            ]
        }
    }


allow_unsolicited
"""""""""""""""""

When set to true, the SP will consume unsolicited SAML Responses, i.e. SAML
Responses for which it has not sent a respective SAML Authentication Request.

Example::

    "service": {
        "sp": {
            "allow_unsolicited": True,
        }
    }

hide_assertion_consumer_service
"""""""""""""""""""""""""""""""

When set to true the AuthnRequest will not include the
AssertionConsumerServiceURL and ProtocolBinding attributes.

Example::

    "service": {
        "sp": {
            "hide_assertion_consumer_service": True,
        }
    }

This kind of functionality is required for the eIDAS SAML profile.

> eIDAS-Connectors SHOULD NOT provide AssertionConsumerServiceURL.

.. note::
    This is relevant only for the eIDAS SAML profile.


sp_type
"""""""

Sets the value for the eIDAS SPType node. By the eIDAS specification the value
can be one of *public* and *private*.

Example::

    "service": {
        "sp": {
            "sp_type": "private",
        }
    }

.. note::
    This is relevant only for the eIDAS SAML profile.


sp_type_in_metadata
"""""""""""""""""""

Whether the SPType node should appear in the metadata document
or as part of each AuthnRequest.

Example::

    "service": {
        "sp": {
            "sp_type_in_metadata": True,
        }
    }

.. note::
    This is relevant only for the eIDAS SAML profile.


requested_attributes
""""""""""""""""""""

A list of attributes that the SP requires from an eIDAS-Service (IdP).
Each attribute is an object with the following attributes:

* friendly_name
* name
* required
* name_format

Where friendly_name is an attribute name such as *DateOfBirth*, name is the
full attribute name such as
*http://eidas.europa.eu/attributes/naturalperson/DateOfBirth*, required
indicates whether this attributed is required for authentication, and
name_format indicates the name format for that attribute, such as
*urn:oasis:names:tc:SAML:2.0:attrname-format:uri*.

It is mandatory that at least name or friendly_name is set.
By default attributes are assumed to be required.
Missing attributes are inferred based on the attribute maps data.

Example::

    "service": {
        "sp": {
            "requested_attributes": [
                {
                    "name": "http://eidas.europa.eu/attributes/naturalperson/PersonIdentifier",
                },
                {
                    "friendly_name": "DateOfBirth",
                    "required": False,
                },
            ],
        }
    }

.. note::
    This is relevant only for the eIDAS SAML profile.

    This option is different from the required_attributes and
    optional_attributes parameters that control the requested
    attributes in the metadata of an SP.


idp
"""

Defines the set of IdPs that this SP is allowed to use; if unset, all listed
IdPs may be used.  If set, then the value is expected to be a list with entity
identifiers for the allowed IdPs.
A typical configuration, when the allowed set of IdPs are limited, would look
something like this::

    "service": {
        "sp": {
            "idp": ["urn:mace:umu.se:saml:roland:idp"],
        }
    }

In this case, the SP has only one IdP it can use.

optional_attributes
"""""""""""""""""""

Attributes that this SP would like to receive from IdPs.

Example::

    "service": {
        "sp": {
            "optional_attributes": ["title"],
        }
    }

Since the attribute names used here are the user-friendly ones an attribute map
must exist, so that the server can use the full name when communicating
with other servers.

required_attributes
"""""""""""""""""""

Attributes that this SP demands to receive from IdPs.

Example::

    "service": {
        "sp": {
            "required_attributes": [
                "surname",
                "givenName",
                "mail",
            ],
        }
    }

Again as for *optional_attributes* the names given are expected to be
the user-friendly names.

want_assertions_signed
""""""""""""""""""""""

Indicates if this SP wants the IdP to send the assertions signed. This
sets the WantAssertionsSigned attribute of the SPSSODescriptor node
of the metadata so the IdP will know this SP preference.

Valid values are True or False. Default value is False.

Example::

    "service": {
        "sp": {
            "want_assertions_signed": True,
        }
    }

want_assertions_or_response_signed
""""""""""""""""""""""""""""""""""

Indicates that *either* the Authentication Response *or* the assertions
contained within the response to this SP must be signed.

Valid values are True or False. Default value is False.

This configuration directive **does not** override ``want_response_signed``
or ``want_assertions_signed``. For example, if ``want_response_signed`` is True
and the Authentication Response is not signed an exception will be thrown
regardless of the value for this configuration directive.

Thus to configure the SP to accept either a signed response or signed assertions
set ``want_response_signed`` and ``want_assertions_signed`` both to False and
this directive to True.

Example::

    "service": {
        "sp": {
            "want_response_signed": False,
            "want_assertions_signed": False,
            "want_assertions_or_response_signed": True,
        }
    }

discovery_response
""""""""""""""""""

This configuration allows the SP to include one or more Discovery Response Endpoints.
The discovery_response can be the just the URL::

    "discovery_response":["http://example.com/sp/ds"],

or it can be a 2 tuple of the URL+Binding::

    from saml2.extension.idpdisc import BINDING_DISCO

    "discovery_response": [("http://example.com/sp/ds", BINDING_DISCO)]

ecp
"""

This configuration option takes a dictionary with the ecp client IP address as the
key and the entity ID as the value.

Example::

    "ecp": {
        "203.0.113.254": "http://example.com/idp",
    }

requested_attribute_name_format
"""""""""""""""""""""""""""""""

This sets the NameFormat attribute in the ``<RequestedAttribute>`` element.
The name formats are defined in saml2.saml.py. If not configured the default is ``NAME_FORMAT_URI``
which corresponds to ``urn:oasis:names:tc:SAML:2.0:attrname-format:uri``.

Example::

    from saml2.saml import NAME_FORMAT_BASIC

::

    "requested_attribute_name_format": NAME_FORMAT_BASIC


requested_authn_context
"""""""""""""""""""""""

This configuration option defines the ``<RequestedAuthnContext>`` for an AuthnRequest by
a client. The value is a dictionary with two fields

- ``authn_context_class_ref`` a list of string values representing
  ``<AuthnContextClassRef>`` elements.

- ``comparison`` a string representing the Comparison xml-attribute value of the
  ``<RequestedAuthnContext>`` element. Per the SAML core specificiation the value should
  be one of "exact", "minimum", "maximum", or "better". The default is "exact".

Example::

    "service": {
        "sp": {
            "requested_authn_context": {
                "authn_context_class_ref": [
                    "urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport",
                    "urn:oasis:names:tc:SAML:2.0:ac:classes:TLSClient",
                ],
                "comparison": "minimum",
            }
        }
    }


idp/aa/sp
^^^^^^^^^

If the configuration is covering both two or three different service types
(like if one server is actually acting as both an IdP and an SP) then in some
cases you might want to have these below different for the different services.

endpoints
"""""""""

Where the endpoints for the services provided are.
This directive has as value a dictionary with one or more of the following keys:

* artifact_resolution_service (aa, idp and sp)
* `assertion_consumer_service <https://wiki.shibboleth.net/confluence/display/CONCEPT/AssertionConsumerService>`_ (sp)
* assertion_id_request_service (aa, idp)
* attribute_service (aa)
* manage_name_id_service (aa, idp)
* name_id_mapping_service (idp)
* single_logout_service (aa, idp, sp)
* single_sign_on_service (idp)

The value per service is a list of endpoint specifications.
An endpoint specification can either be just the URL::

  ”http://localhost:8088/A"

or it can be a 2-tuple (URL+binding)::

  from saml2 import BINDING_HTTP_POST
  (”http://localhost:8087/A”, BINDING_HTTP_POST)

or a 3-tuple (URL+binding+index)::

  from saml2 import BINDING_HTTP_POST
  (”http://lingon.catalogix.se:8087/A”, BINDING_HTTP_POST, 1)

If no binding is specified, no index can be set.
If no index is specified, the index is set based on the position in the list.

Example::

    "service":
        "idp": {
            "endpoints": {
                "single_sign_on_service": [
                    ("http://localhost:8088/sso", BINDING_HTTP_REDIRECT),
                ],
                "single_logout_service": [
                    ("http://localhost:8088/slo", BINDING_HTTP_REDIRECT),
                ],
            },
        },
    },

only_use_keys_in_metadata
"""""""""""""""""""""""""

If set to False, the certificate contained in a SAML message will be used for
signature verification.
Default True.

validate_certificate
""""""""""""""""""""

Indicates that the certificate used in sign SAML messages must be valid.
Default to False.

logout_requests_signed
""""""""""""""""""""""

Indicates if this entity will sign the Logout Requests originated from it.

This can be overridden by application code for a specific call.

Valid values are True or False. Default value is False.

Example::

    "service": {
        "sp": {
            "logout_requests_signed": False,
        }
    }


signing_algorithm
"""""""""""""""""

Default algorithm to be used. Example::

    "service": {
        "sp": {
            "signing_algorithm": "http://www.w3.org/2001/04/xmldsig-more#rsa-sha512",
            "digest_algorithm": "http://www.w3.org/2001/04/xmlenc#sha512",
        }
    }


digest_algorithm
"""""""""""""""""

Default algorithm to be used. Example::

    "service": {
        "idp": {
            "signing_algorithm": "http://www.w3.org/2001/04/xmldsig-more#rsa-sha512",
            "digest_algorithm": "http://www.w3.org/2001/04/xmlenc#sha512",
        }
    }


logout_responses_signed
"""""""""""""""""""""""

Indicates if this entity will sign the Logout Responses while processing
a Logout Request.

This can be overridden by application code when calling ``handle_logout_request``.

Valid values are True or False. Default value is False.

Example::

    "service": {
        "sp": {
            "logout_responses_signed": False,
        }
    }


subject_data
""""""""""""

The name of a database where the map between a local identifier and
a distributed identifier is kept. By default, this is a shelve database.
So if you just specify a name, then a shelve database with that name
is created. On the other hand, if you specify a tuple, then the first
element in the tuple specifies which type of database you want to use
and the second element is the address of the database.

Example::

    "subject_data": "./idp.subject.db",

or if you want to use for instance memcache::

    "subject_data": ("memcached", "localhost:12121"),

*shelve* and *memcached* are the only database types that are currently
supported.


virtual_organization
""""""""""""""""""""

Gives information about common identifiers for virtual_organizations::

    "virtual_organization": {
        "urn:mace:example.com:it:tek": {
            "nameid_format": "urn:oid:1.3.6.1.4.1.1466.115.121.1.15-NameID",
            "common_identifier": "umuselin",
        }
    },

Keys in this dictionary are the identifiers for the virtual organizations.
The arguments per organization are 'nameid_format' and 'common_identifier'.
Useful if all the IdPs and AAs that are involved in a virtual organization
have common attribute values for users that are part of the VO.

Complete example
----------------

We start with a simple but fairly complete Service provider configuration::

    from saml2 import BINDING_HTTP_REDIRECT

    CONFIG = {
        "entityid": "http://example.com/sp/metadata.xml",
        "service": {
            "sp": {
                "name": "Example SP",
                "endpoints": {
                    "assertion_consumer_service": ["http://example.com/sp"],
                    "single_logout_service": [
                        ("http://example.com/sp/slo", BINDING_HTTP_REDIRECT),
                    ],
                },
            }
        },
        "key_file": "./mykey.pem",
        "cert_file": "./mycert.pem",
        "xmlsec_binary": "/usr/local/bin/xmlsec1",
        "delete_tmpfiles": True,
        "attribute_map_dir": "./attributemaps",
        "metadata": {
            "local": ["idp.xml"]
        }
        "organization": {
            "display_name": ["Example identities"]
        }
        "contact_person": [
            {
                "givenname": "Roland",
                "surname": "Hedberg",
                "phone": "+46 90510",
                "mail": "roland@example.com",
                "type": "technical",
            },
        ]
    }

This is the typical setup for an SP.
A metadata file to load is *always* needed, but it can, of course,
contain anything from 1 up to many entity descriptions.

------

A slightly more complex configuration::

    from saml2 import BINDING_HTTP_REDIRECT

    CONFIG = {
        "entityid": "http://sp.example.com/metadata.xml",
        "service": {
            "sp": {
                "name": "Example SP",
                "endpoints": {
                    "assertion_consumer_service": ["http://sp.example.com/"],
                    "single_logout_service": [
                        ("http://sp.example.com/slo", BINDING_HTTP_REDIRECT),
                    ],
                },
                "subject_data": ("memcached", "localhost:12121"),
                "virtual_organization": {
                    "urn:mace:example.com:it:tek": {
                        "nameid_format": "urn:oid:1.3.6.1.4.1.1466.115.121.1.15-NameID",
                        "common_identifier": "eduPersonPrincipalName",
                    }
                },
            }
        },
        "key_file": "./mykey.pem",
        "cert_file": "./mycert.pem",
        "xmlsec_binary": "/usr/local/bin/xmlsec1",
        "delete_tmpfiles": True,
        "metadata": {
            "local": ["example.xml"],
            "remote": [
                {
                    "url":"https://kalmar2.org/simplesaml/module.php/aggregator/?id=kalmarcentral2&set=saml2",
                    "cert":"kalmar2.pem",
                }
            ]
        },
        "attribute_maps": "attributemaps",
        "organization": {
            "display_name": ["Example identities"]
        }
        "contact_person": [
            {
                "givenname": "Roland",
                "surname": "Hedberg",
                "phone": "+46 90510",
                "mail": "roland@example.com",
                "type": "technical",
            },
        ]
    }

Uses metadata files, both local and remote, and will talk to whatever
IdP that appears in any of the metadata files.

Other considerations
::::::::::::::::::::

Entity Categories
-----------------

Entity categories and their attributes are defined in
src/saml2/entity_category/<registrar-of-entity-category>.py.
We can configure Entity Categories in PySAML2 in two ways:

1. Using the configuration options *entity_category_support* or
   *entity_category*, to generate the appropriate EntityAttribute metadata
   elements.
2. Using the configuration option *entity_categories* as part of the policy
   configuration, to make the entity category work as a filter on the
   attributes that will be released.

If the entity categories are configured as metadata, as follow::

    'debug' : True,
    'xmlsec_binary': get_xmlsec_binary([/usr/bin/xmlsec1']),
    'entityid': '%s/metadata' % BASE_URL,

    # or entity_category: [ ... ]
    'entity_category_support': [
        edugain.COCO, # "http://www.geant.net/uri/dataprotection-code-of-conduct/v1"
        refeds.RESEARCH_AND_SCHOLARSHIP,
    ],

    'attribute_map_dir': 'data/attribute-maps',
    'description': 'SAML2 IDP',

    'service': {
        'idp': {
    ...

In the metadata we'll then have::

    <md:Extensions>
      <mdattr:EntityAttributes>
        <saml:Attribute Name="http://macedir.org/entity-category-support" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri">
          <saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string">http://www.geant.net/uri/dataprotection-code-of-conduct/v1</saml:AttributeValue>
          <saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string">http://refeds.org/category/research-and-scholarship</saml:AttributeValue>
        </saml:Attribute>
      </mdattr:EntityAttributes>

If the entity categories are configurated in the policy section, they will act
as filters on the released attributes.

Example::

    "policy": {
      "default": {
        "lifetime": {"minutes": 15},
        # if the SP is not conform to entity_categories
        # the attributes will not be released
        "entity_categories": ["refeds",],