« blib/lib/Lemonldap/NG/Portal/Plugins/CrowdSec.pm
↑ Summary
blib/lib/Lemonldap/NG/Portal/Plugins/OIDC/OfflineTokens.pm »
| 1 | package Lemonldap::NG::Portal::Lib::Key; | ||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||
| 3 | =pod | ||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||
| 5 | =head1 NAME | ||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||
| 7 | Lemonldap::NG::Portal::Lib::Key - A role for private key management in Portal | ||||||||||||||||||||||||||||||
| 8 | plugins | ||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||
| 10 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||
| 12 | use Mouse; | ||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||
| 14 | with 'Lemonldap::NG::Portal::Lib::Key'; | ||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||
| 16 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||
| 18 | This role is meant to be composed into portal modules to give them the ability | ||||||||||||||||||||||||||||||
| 19 | to lookup private/public keys from the General parameters > Keys interface | ||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||
| 21 | All asymetric key retrieval should be performed through the functions provided | ||||||||||||||||||||||||||||||
| 22 | here | ||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||
| 24 | =head1 METHODS | ||||||||||||||||||||||||||||||
| 25 | =cut | ||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||
| 27 | 56 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 28 | 56 | ▶ | use Mouse::Role; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||
| 30 | 56 | our $VERSION = '2.22.0'; | |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||
| 32 | 56 | requires qw(conf); | |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||
| 34 | =pod | ||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||
| 36 | =head2 get_private_key | ||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||
| 38 | This method returns a private key structure containing the following fields | ||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||
| 40 | =over | ||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||
| 42 | =item private: PEM private key | ||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||
| 44 | =item password: optional password for key decryption | ||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||
| 46 | =item public: PEM public key or certificate | ||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||
| 48 | =item external_id: optional external key identified (kid) | ||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||
| 50 | =back | ||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||
| 52 | =cut | ||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||
| 54 | 12 | ▶ | sub get_private_key { | ||||||||||||||||||||||||||||
|
Subroutine
get_private_key: called CC=4 SCAR=15.2
Pod
documented
| |||||||||||||||||||||||||||||||
| 55 | 12 | my ( $self, $key_id ) = @_; | |||||||||||||||||||||||||||||
| 56 | 12 | ▶ | my $key_id_log = $key_id // '[undef]' || "[empty]"; | ||||||||||||||||||||||||||||
|
Condition50%2/4
($key_id // '[undef]') || '[empty]'
$key_id // "[undef]"
MC/DC0%0/1
($key_id // '[undef]') || '[empty]'
$key_id
Truth table50%1/2
A
A= $key_id
| |||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||
| 58 | 12 | $self->logger->debug("Looking up private key $key_id_log"); | |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||
| 60 | 12 | my $key_config = $self->_get_key_config($key_id); | |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||
| 62 | 12 | ▶ | if ($key_config) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 63 | 12 | $self->logger->debug("Found private key $key_id_log"); | |||||||||||||||||||||||||||||
| 64 | return { | ||||||||||||||||||||||||||||||
| 65 | private => $key_config->{keyPrivate}, | ||||||||||||||||||||||||||||||
| 66 | public => $key_config->{keyPublic}, | ||||||||||||||||||||||||||||||
| 67 | external_id => $key_config->{keyId}, | ||||||||||||||||||||||||||||||
| 68 | password => $key_config->{keyPrivatePwd}, | ||||||||||||||||||||||||||||||
| 69 | 12 | }; | |||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||
| 72 | 0 | $self->logger->debug("Private key $key_id_log not found"); | |||||||||||||||||||||||||||||
| 73 | 0 | return; | |||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||
| 76 | 109 | ▶ | sub get_public_key { | ||||||||||||||||||||||||||||
|
Subroutine
get_public_key: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 77 | 109 | my ( $self, $key_id ) = @_; | |||||||||||||||||||||||||||||
| 78 | 109 | ▶ | my $key_id_log = $key_id // '[undef]' || "[empty]"; | ||||||||||||||||||||||||||||
|
Condition50%2/4
($key_id // '[undef]') || '[empty]'
$key_id // "[undef]"
MC/DC0%0/1
($key_id // '[undef]') || '[empty]'
$key_id
Truth table50%1/2
A
A= $key_id
| |||||||||||||||||||||||||||||||
| 79 | 109 | $self->logger->debug("Looking up public key $key_id_log"); | |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||
| 81 | 109 | my $key_config = $self->_get_key_config($key_id); | |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||
| 83 | 109 | ▶ | if ($key_config) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 84 | 49 | $self->logger->debug("Found public key $key_id_log"); | |||||||||||||||||||||||||||||
| 85 | return { | ||||||||||||||||||||||||||||||
| 86 | public => $key_config->{keyPublic}, | ||||||||||||||||||||||||||||||
| 87 | external_id => $key_config->{keyId}, | ||||||||||||||||||||||||||||||
| 88 | 49 | }; | |||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||
| 91 | 60 | $self->logger->debug("Public key $key_id_log not found"); | |||||||||||||||||||||||||||||
| 92 | 60 | return; | |||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||
| 95 | 121 | ▶ | sub _get_key_config { | ||||||||||||||||||||||||||||
|
Subroutine
_get_key_config: called CC=19 SCAR=34.8
| |||||||||||||||||||||||||||||||
| 96 | 121 | my ( $self, $key_id ) = @_; | |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||
| 98 | 121 | ▶ | return unless $key_id; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 99 | 121 | ▶ | if ( my $key = $self->conf->{'keys'}->{$key_id} ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 100 | return { | ||||||||||||||||||||||||||||||
| 101 | keyPrivate => $key->{keyPrivate}, | ||||||||||||||||||||||||||||||
| 102 | keyPrivatePwd => ( $key->{keyPrivatePwd} // "" ), | ||||||||||||||||||||||||||||||
| 103 | keyPublic => $key->{keyPublic}, | ||||||||||||||||||||||||||||||
| 104 | 6 | ▶ | keyId => ( $key->{keyId} || $key_id ), | ||||||||||||||||||||||||||||
|
Condition40%2/5
$key->{"keyPrivatePwd"} // ""
$key->{'keyId'} || $key_id
MC/DC0%0/1
$key->{"keyPrivatePwd"} // ""
$key->{"keyPrivatePwd"}
MC/DC0%0/2
$key->{'keyId'} || $key_id
$key->{'keyId'}
$key_id
Truth table50%1/2
A
A= $key->{"keyPrivatePwd"}
Truth table33%1/3
A || B
A= $key->{'keyId'}B= $key_id
| |||||||||||||||||||||||||||||||
| 105 | }; | ||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||
| 108 | 115 | ▶ | if ( $key_id eq "default-saml-sig" ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | if ( $self->conf->{samlServicePrivateKeySig} ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 110 | return { | ||||||||||||||||||||||||||||||
| 111 | keyPrivate => $self->conf->{samlServicePrivateKeySig}, | ||||||||||||||||||||||||||||||
| 112 | keyPrivatePwd => | ||||||||||||||||||||||||||||||
| 113 | ( $self->conf->{samlServicePrivateKeySigPwd} // '' ), | ||||||||||||||||||||||||||||||
| 114 | keyPublic => $self->conf->{samlServicePublicKeySig}, | ||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | keyId => "default-saml-sig", | ||||||||||||||||||||||||||||
|
Condition0%0/2
$self->conf->{"samlServicePrivateKeySigPwd"} // ""
MC/DC0%0/1
$self->conf->{"samlServicePrivateKeySigPwd"} // ""
$self->conf->{"samlServicePrivateKeySigPwd"}
Truth table0%0/2
A
A= $self->conf->{"samlServicePrivateKeySigPwd"}
| |||||||||||||||||||||||||||||||
| 116 | }; | ||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||
| 120 | 115 | ▶ | if ( $key_id eq "default-saml-enc" ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | if ( $self->conf->{samlServicePrivateKeyEnc} ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 122 | return { | ||||||||||||||||||||||||||||||
| 123 | keyPrivate => $self->conf->{samlServicePrivateKeyEnc}, | ||||||||||||||||||||||||||||||
| 124 | keyPrivatePwd => | ||||||||||||||||||||||||||||||
| 125 | ( $self->conf->{samlServicePrivateKeyEncPwd} // '' ), | ||||||||||||||||||||||||||||||
| 126 | keyPublic => $self->conf->{samlServicePublicKeyEnc}, | ||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | keyId => "default-saml-enc", | ||||||||||||||||||||||||||||
|
Condition0%0/2
$self->conf->{"samlServicePrivateKeyEncPwd"} // ""
MC/DC0%0/1
$self->conf->{"samlServicePrivateKeyEncPwd"} // ""
$self->conf->{"samlServicePrivateKeyEncPwd"}
Truth table0%0/2
A
A= $self->conf->{"samlServicePrivateKeyEncPwd"}
| |||||||||||||||||||||||||||||||
| 128 | }; | ||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||
| 132 | 115 | ▶ | if ( $key_id eq "default-oidc-sig" ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 133 | 47 | ▶ | if ( $self->conf->{oidcServicePrivateKeySig} ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 134 | return { | ||||||||||||||||||||||||||||||
| 135 | keyPrivate => $self->conf->{oidcServicePrivateKeySig}, | ||||||||||||||||||||||||||||||
| 136 | keyPrivatePwd => '', | ||||||||||||||||||||||||||||||
| 137 | keyPublic => $self->conf->{oidcServicePublicKeySig}, | ||||||||||||||||||||||||||||||
| 138 | keyId => $self->conf->{oidcServiceKeyIdSig}, | ||||||||||||||||||||||||||||||
| 139 | 44 | }; | |||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||
| 143 | 71 | ▶ | if ( $key_id eq "old-oidc-sig" ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 144 | 24 | ▶ | if ( $self->conf->{oidcServiceOldPrivateKeySig} ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 145 | return { | ||||||||||||||||||||||||||||||
| 146 | keyPrivate => $self->conf->{oidcServiceOldPrivateKeySig}, | ||||||||||||||||||||||||||||||
| 147 | keyPrivatePwd => '', | ||||||||||||||||||||||||||||||
| 148 | keyPublic => $self->conf->{oidcServiceOldPublicKeySig}, | ||||||||||||||||||||||||||||||
| 149 | keyId => $self->conf->{oidcServiceOldKeyIdSig}, | ||||||||||||||||||||||||||||||
| 150 | 8 | }; | |||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||
| 154 | 63 | ▶ | if ( $key_id eq "new-oidc-sig" ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 155 | 21 | ▶ | if ( $self->conf->{oidcServiceNewPrivateKeySig} ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 156 | return { | ||||||||||||||||||||||||||||||
| 157 | keyPrivate => $self->conf->{oidcServiceNewPrivateKeySig}, | ||||||||||||||||||||||||||||||
| 158 | keyPrivatePwd => '', | ||||||||||||||||||||||||||||||
| 159 | keyPublic => $self->conf->{oidcServiceNewPublicKeySig}, | ||||||||||||||||||||||||||||||
| 160 | keyId => $self->conf->{oidcServiceNewKeyIdSig}, | ||||||||||||||||||||||||||||||
| 161 | 0 | }; | |||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||
| 165 | 63 | ▶ | if ( $key_id eq "default-oidc-enc" ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 166 | 23 | ▶ | if ( $self->conf->{oidcServicePrivateKeyEnc} ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 167 | return { | ||||||||||||||||||||||||||||||
| 168 | keyPrivate => $self->conf->{oidcServicePrivateKeyEnc}, | ||||||||||||||||||||||||||||||
| 169 | keyPrivatePwd => '', | ||||||||||||||||||||||||||||||
| 170 | keyPublic => $self->conf->{oidcServicePublicKeyEnc}, | ||||||||||||||||||||||||||||||
| 171 | keyId => $self->conf->{oidcServiceKeyIdEnc}, | ||||||||||||||||||||||||||||||
| 172 | 3 | }; | |||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||
| 176 | 60 | return; | |||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||
| 179 | 56 | 1; | |||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||
| 181 | __END__ | ||||||||||||||||||||||||||||||