Skip to content

Allow setting block and key transport encryption algorithms on a per-SP basis #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/Jobs/SamlSso.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use LightSaml\Credential\X509Certificate;
use LightSaml\Model\Assertion\Conditions;
use LightSaml\Model\Protocol\AuthnRequest;
use RobRichards\XMLSecLibs\XMLSecurityKey;
use Illuminate\Foundation\Bus\Dispatchable;
use LightSaml\Model\Assertion\AuthnContext;
use LightSaml\Model\XmlDSig\SignatureWriter;
Expand Down Expand Up @@ -126,7 +127,7 @@ public function response()
// Encrypt the assertion

if ($this->encryptAssertion()) {
$encryptedAssertion = new EncryptedAssertionWriter();
$encryptedAssertion = $this->getEncryptionAssertionWriter();
$encryptedAssertion->encrypt($assertion, KeyHelper::createPublicKey(
$this->getSpCertificate()
));
Expand Down Expand Up @@ -228,4 +229,20 @@ private function encryptAssertion(): bool
config('samlidp.encrypt_assertion', true)
);
}

private function getEncryptionAssertionWriter() {
$blockEncryptionAlgorithm = config(sprintf(
'samlidp.sp.%s.block_encryption_algorithm', $this->getServiceProvider($this->authn_request)
));

$keyTransportEncryption = config(sprintf(
'samlidp.sp.%s.key_transport_encryption', $this->getServiceProvider($this->authn_request)
));

// because PHP < 7.4 is supported in this package we can't use the null coalescing assignment operator (??=)
$blockEncryptionAlgorithm = $blockEncryptionAlgorithm ?? XMLSecurityKey::AES128_CBC;
$keyTransportEncryption = $keyTransportEncryption ?? XMLSecurityKey::RSA_1_5;

return new EncryptedAssertionWriter($blockEncryptionAlgorithm, $keyTransportEncryption);
}
}