Skip to content

Commit a2fb87e

Browse files
authored
Merge pull request #195 from onelogin/key_rollover_mngmt
Improve Key Rollover management
2 parents 37d6190 + d5c9f7b commit a2fb87e

File tree

21 files changed

+823
-116
lines changed

21 files changed

+823
-116
lines changed

README.md

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ Or also we can provide those data in the setting file at the 'x509cert' and the
157157

158158
Sometimes we could need a signature on the metadata published by the SP, in this case we could use the x.509 cert previously mentioned or use a new x.509 cert: metadata.crt and metadata.key.
159159

160+
Use `sp_new.crt` if you are in a key rollover process and you want to
161+
publish that x509certificate on Service Provider metadata.
162+
160163
If you want to create self-signed certs, you can do it at the https://www.samltool.com/self_signed_certs.php service, or using the command:
161164

162165
```bash
@@ -279,6 +282,15 @@ This is the settings.json file:
279282
// the certs folder. But we can also provide them with the following parameters
280283
"x509cert": "",
281284
"privateKey": ""
285+
286+
/*
287+
* Key rollover
288+
* If you plan to update the SP x509cert and privateKey
289+
* you can define here the new x509cert and it will be
290+
* published on the SP metadata so Identity Providers can
291+
* read them and get ready for rollover.
292+
*/
293+
// 'x509certNew': '',
282294
},
283295

284296
// Identity Provider Data that we want connected with our SP.
@@ -320,8 +332,24 @@ This is the settings.json file:
320332
* Notice that if you want to validate any SAML Message sent by the HTTP-Redirect binding, you
321333
* will need to provide the whole x509cert.
322334
*/
323-
// 'certFingerprint' => '',
324-
// 'certFingerprintAlgorithm' => 'sha1',
335+
// 'certFingerprint': '',
336+
// 'certFingerprintAlgorithm': 'sha1',
337+
338+
/* In some scenarios the IdP uses different certificates for
339+
* signing/encryption, or is under key rollover phase and
340+
* more than one certificate is published on IdP metadata.
341+
* In order to handle that the toolkit offers that parameter.
342+
* (when used, 'x509cert' and 'certFingerprint' values are
343+
* ignored).
344+
*/
345+
// 'x509certMulti': {
346+
// 'signing': [
347+
// '<cert1-string>'
348+
// ],
349+
// 'encryption': [
350+
// '<cert2-string>'
351+
// ]
352+
// }
325353
}
326354
}
327355
```
@@ -475,6 +503,23 @@ json_data_file.close()
475503
auth = OneLogin_Saml2_Auth(req, settings_data)
476504
```
477505

506+
#### Metadata Based Configuration
507+
508+
The method above requires a little extra work to manually specify attributes about the IdP. (And your SP application)
509+
510+
There's an easier method -- use a metadata exchange. Metadata is just an XML file that defines the capabilities of both the IdP and the SP application. It also contains the X.509 public key certificates which add to the trusted relationship. The IdP administrator can also configure custom settings for an SP based on the metadata.
511+
512+
Using ````parse_remote```` IdP metadata can be obtained and added to the settings withouth further ado.
513+
514+
``
515+
idp_data = OneLogin_Saml2_IdPMetadataParser.parse_remote('https://example.com/auth/saml2/idp/metadata')
516+
``
517+
518+
If the Metadata contains several entities, the relevant EntityDescriptor can be specified when retrieving the settings from the IdpMetadataParser by its Entity Id value:
519+
520+
idp_data = OneLogin_Saml2_IdPMetadataParser.parse_remote(https://example.com/metadatas, entity_id='idp_entity_id')
521+
522+
478523
#### How load the library ####
479524

480525
In order to use the toolkit library you need to import the file that contains the class that you will need
@@ -815,6 +860,25 @@ else:
815860
print ', '.join(errors)
816861
```
817862

863+
### SP Key rollover ###
864+
865+
If you plan to update the SP x509cert and privateKey you can define the new x509cert as $settings['sp']['x509certNew'] and it will be
866+
published on the SP metadata so Identity Providers can read them and get ready for rollover.
867+
868+
869+
### IdP with multiple certificates ###
870+
871+
In some scenarios the IdP uses different certificates for
872+
signing/encryption, or is under key rollover phase and more than one certificate is published on IdP metadata.
873+
874+
In order to handle that the toolkit offers the $settings['idp']['x509certMulti'] parameter.
875+
876+
When that parameter is used, 'x509cert' and 'certFingerprint' values will be ignored by the toolkit.
877+
878+
The 'x509certMulti' is an array with 2 keys:
879+
- 'signing'. An array of certs that will be used to validate IdP signature
880+
- 'encryption' An array with one unique cert that will be used to encrypt data to be sent to the IdP
881+
818882

819883
### Main classes and methods ###
820884

@@ -924,14 +988,17 @@ Configuration of the OneLogin Python Toolkit
924988
* ***check_sp_certs*** Checks if the x509 certs of the SP exists and are valid.
925989
* ***get_sp_key*** Returns the x509 private key of the SP.
926990
* ***get_sp_cert*** Returns the x509 public cert of the SP.
991+
* ***get_sp_cert_new*** Returns the future x509 public cert of the SP.
927992
* ***get_idp_cert*** Returns the x509 public cert of the IdP.
928993
* ***get_sp_data*** Gets the SP data.
929994
* ***get_idp_data*** Gets the IdP data.
930995
* ***get_security_data*** Gets security data.
931996
* ***get_contacts*** Gets contacts data.
932997
* ***get_organization*** Gets organization data.
933998
* ***format_idp_cert*** Formats the IdP cert.
999+
* ***format_idp_cert_multi*** Formats all registered IdP certs.
9341000
* ***format_sp_cert*** Formats the SP cert.
1001+
* ***format_sp_cert_new*** Formats the SP cert new.
9351002
* ***format_sp_key*** Formats the private key.
9361003
* ***set_strict*** Activates or deactivates the strict mode.
9371004
* ***is_strict*** Returns if the 'strict' mode is active.
@@ -992,6 +1059,9 @@ A class that contains methods to obtain and parse metadata from IdP
9921059

9931060
For more info, look at the source code; each method is documented and details about what does and how to use it are provided. Make sure to also check the doc folder where HTML documentation about the classes and methods is provided.
9941061

1062+
1063+
1064+
9951065
Demos included in the toolkit
9961066
-----------------------------
9971067

demo-bottle/saml/certs/README

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ Take care of this folder that could contain private key. Be sure that this folde
22

33
Onelogin Python Toolkit expects that certs for the SP could be stored in this folder as:
44

5-
* sp.key Private Key
6-
* sp.crt Public cert
5+
* sp.key Private Key
6+
* sp.crt Public cert
7+
* sp_new.crt Future Public cert
78

89
Also you can use other cert to sign the metadata of the SP using the:
910

demo-django/saml/certs/README

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ Take care of this folder that could contain private key. Be sure that this folde
22

33
Onelogin Python Toolkit expects that certs for the SP could be stored in this folder as:
44

5-
* sp.key Private Key
6-
* sp.crt Public cert
5+
* sp.key Private Key
6+
* sp.crt Public cert
7+
* sp_new.crt Future Public cert
78

89
Also you can use other cert to sign the metadata of the SP using the:
910

demo-flask/saml/certs/README

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ Take care of this folder that could contain private key. Be sure that this folde
22

33
Onelogin Python Toolkit expects that certs for the SP could be stored in this folder as:
44

5-
* sp.key Private Key
6-
* sp.crt Public cert
5+
* sp.key Private Key
6+
* sp.crt Public cert
7+
* sp_new.crt Future Public cert
78

89
Also you can use other cert to sign the metadata of the SP using the:
910

demo_pyramid/demo_pyramid/saml/certs/README

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ Take care of this folder that could contain private key. Be sure that this folde
22

33
Onelogin Python Toolkit expects that certs for the SP could be stored in this folder as:
44

5-
* sp.key Private Key
6-
* sp.crt Public cert
5+
* sp.key Private Key
6+
* sp.crt Public cert
7+
* sp_new.crt Future Public cert
78

89
Also you can use other cert to sign the metadata of the SP using the:
910

0 commit comments

Comments
 (0)