Skip to content

Commit 51c06ee

Browse files
author
Hans Hörberg
committed
Merge remote-tracking branch 'upstream/master'
# Conflicts: # src/saml2/xmldsig/__init__.py
2 parents b99e90b + 73849b4 commit 51c06ee

File tree

4 files changed

+255
-49
lines changed

4 files changed

+255
-49
lines changed

src/saml2/metadata.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python
2+
from saml2.algsupport import algorithm_support_in_metadata
23
from saml2.md import AttributeProfile
34
from saml2.sigver import security_context
45
from saml2.config import Config
@@ -728,6 +729,12 @@ def entity_descriptor(confd):
728729
item = mdattr.EntityAttributes(attribute=attr)
729730
entd.extensions.add_extension_element(item)
730731

732+
if not entd.extensions:
733+
entd.extensions = md.Extensions()
734+
735+
for item in algorithm_support_in_metadata(confd.xmlsec_binary):
736+
entd.extensions.add_extension_element(item)
737+
731738
serves = confd.serves
732739
if not serves:
733740
raise SAMLError(

src/saml2/xmldsig/__init__.py

Lines changed: 58 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
ENCODING_BASE64 = 'http://www.w3.org/2000/09/xmldsig#base64'
1313

1414
# digest and signature algorithms (not implemented = commented out)
15-
DIGEST_MD5 = 'http://www.w3.org/2001/04/xmldsig-more#md5' # test framework only!
15+
DIGEST_MD5 = 'http://www.w3.org/2001/04/xmldsig-more#md5' # test framework
16+
# only!
1617
DIGEST_SHA1 = 'http://www.w3.org/2000/09/xmldsig#sha1'
1718
DIGEST_SHA224 = 'http://www.w3.org/2001/04/xmldsig-more#sha224'
1819
DIGEST_SHA256 = 'http://www.w3.org/2001/04/xmlenc#sha256'
@@ -28,20 +29,20 @@
2829
('DIGEST_RIPEMD160', DIGEST_RIPEMD160))
2930
DIGEST_AVAIL_ALG = DIGEST_ALLOWED_ALG + (('DIGEST_MD5', DIGEST_MD5),)
3031

31-
# SIG_DSA_SHA1 = 'http,//www.w3.org/2000/09/xmldsig#dsa-sha1'
32-
# SIG_DSA_SHA256 = 'http://www.w3.org/2009/xmldsig11#dsa-sha256'
33-
# SIG_ECDSA_SHA1 = 'http://www.w3.org/2001/04/xmldsig-more#ECDSA_sha1'
34-
# SIG_ECDSA_SHA224 = 'http://www.w3.org/2001/04/xmldsig-more#ECDSA_sha224'
35-
# SIG_ECDSA_SHA256 = 'http://www.w3.org/2001/04/xmldsig-more#ECDSA_sha256'
36-
# SIG_ECDSA_SHA384 = 'http://www.w3.org/2001/04/xmldsig-more#ECDSA_sha384'
37-
# SIG_ECDSA_SHA512 = 'http://www.w3.org/2001/04/xmldsig-more#ECDSA_sha512'
32+
SIG_DSA_SHA1 = 'http,//www.w3.org/2000/09/xmldsig#dsa-sha1'
33+
SIG_DSA_SHA256 = 'http://www.w3.org/2009/xmldsig11#dsa-sha256'
34+
SIG_ECDSA_SHA1 = 'http://www.w3.org/2001/04/xmldsig-more#ECDSA_sha1'
35+
SIG_ECDSA_SHA224 = 'http://www.w3.org/2001/04/xmldsig-more#ECDSA_sha224'
36+
SIG_ECDSA_SHA256 = 'http://www.w3.org/2001/04/xmldsig-more#ECDSA_sha256'
37+
SIG_ECDSA_SHA384 = 'http://www.w3.org/2001/04/xmldsig-more#ECDSA_sha384'
38+
SIG_ECDSA_SHA512 = 'http://www.w3.org/2001/04/xmldsig-more#ECDSA_sha512'
3839
SIG_RSA_MD5 = 'http://www.w3.org/2001/04/xmldsig-more#rsa-md5' # test framework
3940
SIG_RSA_SHA1 = 'http://www.w3.org/2000/09/xmldsig#rsa-sha1'
4041
SIG_RSA_SHA224 = 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha224'
4142
SIG_RSA_SHA256 = 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256'
4243
SIG_RSA_SHA384 = 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha384'
4344
SIG_RSA_SHA512 = 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha512'
44-
# SIG_RSA_RIPEMD160 = 'http://www.w3.org/2001/04/xmldsig-more#rsa-ripemd160'
45+
SIG_RSA_RIPEMD160 = 'http://www.w3.org/2001/04/xmldsig-more#rsa-ripemd160'
4546
sig_default = SIG_RSA_SHA1
4647
SIG_ALLOWED_ALG = (('SIG_RSA_SHA1', SIG_RSA_SHA1),
4748
('SIG_RSA_SHA224', SIG_RSA_SHA224),
@@ -138,7 +139,8 @@ def signature_value_type__from_string(xml_string):
138139

139140

140141
class CanonicalizationMethodType_(SamlBase):
141-
"""The http://www.w3.org/2000/09/xmldsig#:CanonicalizationMethodType element """
142+
"""The http://www.w3.org/2000/09/xmldsig#:CanonicalizationMethodType
143+
element """
142144

143145
c_tag = 'CanonicalizationMethodType'
144146
c_namespace = NAMESPACE
@@ -190,8 +192,8 @@ class TransformType_(SamlBase):
190192
c_attributes = SamlBase.c_attributes.copy()
191193
c_child_order = SamlBase.c_child_order[:]
192194
c_cardinality = SamlBase.c_cardinality.copy()
193-
c_children['{http://www.w3.org/2000/09/xmldsig#}XPath'] = ('x_path',
194-
[TransformType_XPath])
195+
c_children['{http://www.w3.org/2000/09/xmldsig#}XPath'] = (
196+
'x_path', [TransformType_XPath])
195197
c_cardinality['x_path'] = {"min": 0}
196198
c_attributes['Algorithm'] = ('algorithm', 'anyURI', True)
197199
c_child_order.extend(['x_path'])
@@ -331,9 +333,9 @@ class X509IssuerSerialType_(SamlBase):
331333
c_child_order = SamlBase.c_child_order[:]
332334
c_cardinality = SamlBase.c_cardinality.copy()
333335
c_children['{http://www.w3.org/2000/09/xmldsig#}X509IssuerName'] = (
334-
'x509_issuer_name', X509IssuerName)
336+
'x509_issuer_name', X509IssuerName)
335337
c_children['{http://www.w3.org/2000/09/xmldsig#}X509SerialNumber'] = (
336-
'x509_serial_number', X509SerialNumber)
338+
'x509_serial_number', X509SerialNumber)
337339
c_child_order.extend(['x509_issuer_name', 'x509_serial_number'])
338340

339341
def __init__(self,
@@ -393,9 +395,10 @@ class PGPDataType_(SamlBase):
393395
c_attributes = SamlBase.c_attributes.copy()
394396
c_child_order = SamlBase.c_child_order[:]
395397
c_cardinality = SamlBase.c_cardinality.copy()
396-
c_children['{http://www.w3.org/2000/09/xmldsig#}PGPKeyID'] = ('pgp_key_id', PGPKeyID)
398+
c_children['{http://www.w3.org/2000/09/xmldsig#}PGPKeyID'] = (
399+
'pgp_key_id', PGPKeyID)
397400
c_children['{http://www.w3.org/2000/09/xmldsig#}PGPKeyPacket'] = (
398-
'pgp_key_packet', PGPKeyPacket)
401+
'pgp_key_packet', PGPKeyPacket)
399402
c_cardinality['pgp_key_packet'] = {"min": 0, "max": 1}
400403
c_child_order.extend(['pgp_key_id', 'pgp_key_packet'])
401404

@@ -529,7 +532,8 @@ def __init__(self,
529532

530533

531534
def signature_property_type__from_string(xml_string):
532-
return saml2.create_class_from_xml_string(SignaturePropertyType_, xml_string)
535+
return saml2.create_class_from_xml_string(SignaturePropertyType_,
536+
xml_string)
533537

534538

535539
class HMACOutputLengthType_(SamlBase):
@@ -659,8 +663,8 @@ class DSAKeyValueType_(SamlBase):
659663
c_cardinality['j'] = {"min": 0, "max": 1}
660664
c_children['{http://www.w3.org/2000/09/xmldsig#}Seed'] = ('seed', Seed)
661665
c_cardinality['seed'] = {"min": 0, "max": 1}
662-
c_children['{http://www.w3.org/2000/09/xmldsig#}PgenCounter'] = ('pgen_counter',
663-
PgenCounter)
666+
c_children['{http://www.w3.org/2000/09/xmldsig#}PgenCounter'] = (
667+
'pgen_counter', PgenCounter)
664668
c_cardinality['pgen_counter'] = {"min": 0, "max": 1}
665669
c_child_order.extend(['p', 'q', 'g', 'y', 'j', 'seed', 'pgen_counter'])
666670

@@ -809,7 +813,7 @@ class SignatureMethodType_(SamlBase):
809813
c_child_order = SamlBase.c_child_order[:]
810814
c_cardinality = SamlBase.c_cardinality.copy()
811815
c_children['{http://www.w3.org/2000/09/xmldsig#}HMACOutputLength'] = (
812-
'hmac_output_length', HMACOutputLength)
816+
'hmac_output_length', HMACOutputLength)
813817
c_cardinality['hmac_output_length'] = {"min": 0, "max": 1}
814818
c_attributes['Algorithm'] = ('algorithm', 'anyURI', True)
815819
c_child_order.extend(['hmac_output_length'])
@@ -957,17 +961,20 @@ class X509DataType_(SamlBase):
957961
c_attributes = SamlBase.c_attributes.copy()
958962
c_child_order = SamlBase.c_child_order[:]
959963
c_cardinality = SamlBase.c_cardinality.copy()
960-
c_children['{http://www.w3.org/2000/09/xmldsig#}X509IssuerSerial'] = ('x509_issuer_serial',
961-
X509IssuerSerial)
964+
c_children['{http://www.w3.org/2000/09/xmldsig#}X509IssuerSerial'] = (
965+
'x509_issuer_serial',
966+
X509IssuerSerial)
962967
c_cardinality['x509_issuer_serial'] = {"min": 0, "max": 1}
963968
c_children['{http://www.w3.org/2000/09/xmldsig#}X509SKI'] = ('x509_ski',
964969
X509SKI)
965970
c_cardinality['x509_ski'] = {"min": 0, "max": 1}
966-
c_children['{http://www.w3.org/2000/09/xmldsig#}X509SubjectName'] = ('x509_subject_name',
967-
X509SubjectName)
971+
c_children['{http://www.w3.org/2000/09/xmldsig#}X509SubjectName'] = (
972+
'x509_subject_name',
973+
X509SubjectName)
968974
c_cardinality['x509_subject_name'] = {"min": 0, "max": 1}
969-
c_children['{http://www.w3.org/2000/09/xmldsig#}X509Certificate'] = ('x509_certificate',
970-
X509Certificate)
975+
c_children['{http://www.w3.org/2000/09/xmldsig#}X509Certificate'] = (
976+
'x509_certificate',
977+
X509Certificate)
971978
c_cardinality['x509_certificate'] = {"min": 0, "max": 1}
972979
c_children['{http://www.w3.org/2000/09/xmldsig#}X509CRL'] = ('x509_crl',
973980
X509CRL)
@@ -1147,11 +1154,11 @@ class KeyValueType_(SamlBase):
11471154
c_attributes = SamlBase.c_attributes.copy()
11481155
c_child_order = SamlBase.c_child_order[:]
11491156
c_cardinality = SamlBase.c_cardinality.copy()
1150-
c_children['{http://www.w3.org/2000/09/xmldsig#}DSAKeyValue'] = ('dsa_key_value',
1151-
DSAKeyValue)
1157+
c_children['{http://www.w3.org/2000/09/xmldsig#}DSAKeyValue'] = (
1158+
'dsa_key_value', DSAKeyValue)
11521159
c_cardinality['dsa_key_value'] = {"min": 0, "max": 1}
1153-
c_children['{http://www.w3.org/2000/09/xmldsig#}RSAKeyValue'] = ('rsa_key_value',
1154-
RSAKeyValue)
1160+
c_children['{http://www.w3.org/2000/09/xmldsig#}RSAKeyValue'] = (
1161+
'rsa_key_value', RSAKeyValue)
11551162
c_cardinality['rsa_key_value'] = {"min": 0, "max": 1}
11561163
c_child_order.extend(['dsa_key_value', 'rsa_key_value'])
11571164

@@ -1191,7 +1198,8 @@ def x509_data_from_string(xml_string):
11911198

11921199

11931200
class SignaturePropertiesType_(SamlBase):
1194-
"""The http://www.w3.org/2000/09/xmldsig#:SignaturePropertiesType element """
1201+
"""The http://www.w3.org/2000/09/xmldsig#:SignaturePropertiesType element
1202+
"""
11951203

11961204
c_tag = 'SignaturePropertiesType'
11971205
c_namespace = NAMESPACE
@@ -1200,7 +1208,7 @@ class SignaturePropertiesType_(SamlBase):
12001208
c_child_order = SamlBase.c_child_order[:]
12011209
c_cardinality = SamlBase.c_cardinality.copy()
12021210
c_children['{http://www.w3.org/2000/09/xmldsig#}SignatureProperty'] = (
1203-
'signature_property', [SignatureProperty])
1211+
'signature_property', [SignatureProperty])
12041212
c_cardinality['signature_property'] = {"min": 1}
12051213
c_attributes['Id'] = ('id', 'ID', False)
12061214
c_child_order.extend(['signature_property'])
@@ -1222,7 +1230,8 @@ def __init__(self,
12221230

12231231

12241232
def signature_properties_type__from_string(xml_string):
1225-
return saml2.create_class_from_xml_string(SignaturePropertiesType_, xml_string)
1233+
return saml2.create_class_from_xml_string(SignaturePropertiesType_,
1234+
xml_string)
12261235

12271236

12281237
class Transforms(TransformsType_):
@@ -1264,8 +1273,8 @@ class RetrievalMethodType_(SamlBase):
12641273
c_attributes = SamlBase.c_attributes.copy()
12651274
c_child_order = SamlBase.c_child_order[:]
12661275
c_cardinality = SamlBase.c_cardinality.copy()
1267-
c_children['{http://www.w3.org/2000/09/xmldsig#}Transforms'] = ('transforms',
1268-
Transforms)
1276+
c_children['{http://www.w3.org/2000/09/xmldsig#}Transforms'] = (
1277+
'transforms', Transforms)
12691278
c_cardinality['transforms'] = {"min": 0, "max": 1}
12701279
c_attributes['URI'] = ('uri', 'anyURI', False)
12711280
c_attributes['Type'] = ('type', 'anyURI', False)
@@ -1317,13 +1326,13 @@ class ReferenceType_(SamlBase):
13171326
c_attributes = SamlBase.c_attributes.copy()
13181327
c_child_order = SamlBase.c_child_order[:]
13191328
c_cardinality = SamlBase.c_cardinality.copy()
1320-
c_children['{http://www.w3.org/2000/09/xmldsig#}Transforms'] = ('transforms',
1321-
Transforms)
1329+
c_children['{http://www.w3.org/2000/09/xmldsig#}Transforms'] = (
1330+
'transforms', Transforms)
13221331
c_cardinality['transforms'] = {"min": 0, "max": 1}
1323-
c_children['{http://www.w3.org/2000/09/xmldsig#}DigestMethod'] = ('digest_method',
1324-
DigestMethod)
1325-
c_children['{http://www.w3.org/2000/09/xmldsig#}DigestValue'] = ('digest_value',
1326-
DigestValue)
1332+
c_children['{http://www.w3.org/2000/09/xmldsig#}DigestMethod'] = (
1333+
'digest_method', DigestMethod)
1334+
c_children['{http://www.w3.org/2000/09/xmldsig#}DigestValue'] = (
1335+
'digest_value', DigestValue)
13271336
c_attributes['Id'] = ('id', 'ID', False)
13281337
c_attributes['URI'] = ('uri', 'anyURI', False)
13291338
c_attributes['Type'] = ('type', 'anyURI', False)
@@ -1507,9 +1516,9 @@ class SignedInfoType_(SamlBase):
15071516
c_child_order = SamlBase.c_child_order[:]
15081517
c_cardinality = SamlBase.c_cardinality.copy()
15091518
c_children['{http://www.w3.org/2000/09/xmldsig#}CanonicalizationMethod'] = (
1510-
'canonicalization_method', CanonicalizationMethod)
1511-
c_children['{http://www.w3.org/2000/09/xmldsig#}SignatureMethod'] = ('signature_method',
1512-
SignatureMethod)
1519+
'canonicalization_method', CanonicalizationMethod)
1520+
c_children['{http://www.w3.org/2000/09/xmldsig#}SignatureMethod'] = (
1521+
'signature_method', SignatureMethod)
15131522
c_children['{http://www.w3.org/2000/09/xmldsig#}Reference'] = ('reference',
15141523
[Reference])
15151524
c_cardinality['reference'] = {"min": 1}
@@ -1595,10 +1604,10 @@ class SignatureType_(SamlBase):
15951604
c_attributes = SamlBase.c_attributes.copy()
15961605
c_child_order = SamlBase.c_child_order[:]
15971606
c_cardinality = SamlBase.c_cardinality.copy()
1598-
c_children['{http://www.w3.org/2000/09/xmldsig#}SignedInfo'] = ('signed_info',
1599-
SignedInfo)
1607+
c_children['{http://www.w3.org/2000/09/xmldsig#}SignedInfo'] = (
1608+
'signed_info', SignedInfo)
16001609
c_children['{http://www.w3.org/2000/09/xmldsig#}SignatureValue'] = (
1601-
'signature_value', SignatureValue)
1610+
'signature_value', SignatureValue)
16021611
c_children['{http://www.w3.org/2000/09/xmldsig#}KeyInfo'] = ('key_info',
16031612
KeyInfo)
16041613
c_cardinality['key_info'] = {"min": 0, "max": 1}
@@ -1659,7 +1668,8 @@ def signature_from_string(xml_string):
16591668
SignedInfo.c_tag: signed_info_from_string,
16601669
SignedInfoType_.c_tag: signed_info_type__from_string,
16611670
CanonicalizationMethod.c_tag: canonicalization_method_from_string,
1662-
CanonicalizationMethodType_.c_tag: canonicalization_method_type__from_string,
1671+
CanonicalizationMethodType_.c_tag:
1672+
canonicalization_method_type__from_string,
16631673
SignatureMethod.c_tag: signature_method_from_string,
16641674
SignatureMethodType_.c_tag: signature_method_type__from_string,
16651675
Reference.c_tag: reference_from_string,

tests/test_30_mdstore.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,6 @@ def test_metadata_extension_algsupport():
464464
mds = MetadataStore(list(ONTS.values()), ATTRCONV, None)
465465
mds.imp(METADATACONF["12"])
466466
mdf = mds.metadata[full_path("uu.xml")]
467-
_txt = mdf.dumps()
468467
assert mds
469468

470469
if __name__ == "__main__":

0 commit comments

Comments
 (0)