Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
simplesamlphp
Manage
Activity
Members
Labels
Plan
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Perun
Perun ProxyIdP
v1
simplesamlphp
Commits
6cbc9945
Commit
6cbc9945
authored
8 years ago
by
Jaime Pérez
Browse files
Options
Downloads
Patches
Plain Diff
Minor formatting and phpdoc fixes.
parent
d2ab4711
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/authX509/lib/Auth/Source/X509userCert.php
+42
-57
42 additions, 57 deletions
modules/authX509/lib/Auth/Source/X509userCert.php
with
42 additions
and
57 deletions
modules/authX509/lib/Auth/Source/X509userCert.php
+
42
−
57
View file @
6cbc9945
<?php
<?php
/**
/**
* This class implements x509 certificate authentication with
* This class implements x509 certificate authentication with certificate validation against an LDAP directory.
* certificate validation against an LDAP directory.
*
*
* @author Emmanuel Dreyfus <manu@netbsd.org>
* @author Emmanuel Dreyfus <manu@netbsd.org>
* @package SimpleSAMLphp
* @package SimpleSAMLphp
...
@@ -11,14 +10,13 @@ class sspmod_authX509_Auth_Source_X509userCert extends SimpleSAML_Auth_Source
...
@@ -11,14 +10,13 @@ class sspmod_authX509_Auth_Source_X509userCert extends SimpleSAML_Auth_Source
{
{
/**
/**
* x509 attributes to use from the certificate
* x509 attributes to use from the certificate for searching the user in the LDAP directory.
* for searching the user in the LDAP directory.
*/
*/
private
$x509attributes
=
array
(
'UID'
=>
'uid'
);
private
$x509attributes
=
array
(
'UID'
=>
'uid'
);
/**
/**
* LDAP attribute containing the user certificate
* LDAP attribute containing the user certificate
.
*/
*/
private
$ldapusercert
=
array
(
'userCertificate;binary'
);
private
$ldapusercert
=
array
(
'userCertificate;binary'
);
...
@@ -32,11 +30,10 @@ class sspmod_authX509_Auth_Source_X509userCert extends SimpleSAML_Auth_Source
...
@@ -32,11 +30,10 @@ class sspmod_authX509_Auth_Source_X509userCert extends SimpleSAML_Auth_Source
/**
/**
* Constructor for this authentication source.
* Constructor for this authentication source.
*
*
* All subclasses who implement their own constructor must call this
* All subclasses who implement their own constructor must call this constructor before using $config for anything.
* constructor before using $config for anything.
*
*
* @param array $info
Information about this authentication source.
* @param array $info Information about this authentication source.
* @param array &$config
Configuration for this authentication source.
* @param array &$config Configuration for this authentication source.
*/
*/
public
function
__construct
(
$info
,
&
$config
)
public
function
__construct
(
$info
,
&
$config
)
{
{
...
@@ -44,19 +41,19 @@ class sspmod_authX509_Auth_Source_X509userCert extends SimpleSAML_Auth_Source
...
@@ -44,19 +41,19 @@ class sspmod_authX509_Auth_Source_X509userCert extends SimpleSAML_Auth_Source
assert
(
'is_array($config)'
);
assert
(
'is_array($config)'
);
if
(
isset
(
$config
[
'authX509:x509attributes'
]))
{
if
(
isset
(
$config
[
'authX509:x509attributes'
]))
{
$this
->
x509attributes
=
$this
->
x509attributes
=
$config
[
'authX509:x509attributes'
];
$config
[
'authX509:x509attributes'
];
}
}
if
(
array_key_exists
(
'authX509:ldapusercert'
,
$config
))
{
if
(
array_key_exists
(
'authX509:ldapusercert'
,
$config
))
{
$this
->
ldapusercert
=
$this
->
ldapusercert
=
$config
[
'authX509:ldapusercert'
];
$config
[
'authX509:ldapusercert'
];
}
}
parent
::
__construct
(
$info
,
$config
);
parent
::
__construct
(
$info
,
$config
);
$this
->
ldapcf
=
new
sspmod_ldap_ConfigHelper
(
$config
,
$this
->
ldapcf
=
new
sspmod_ldap_ConfigHelper
(
'Authentication source '
.
var_export
(
$this
->
authId
,
true
));
$config
,
'Authentication source '
.
var_export
(
$this
->
authId
,
true
)
);
return
;
return
;
}
}
...
@@ -65,17 +62,15 @@ class sspmod_authX509_Auth_Source_X509userCert extends SimpleSAML_Auth_Source
...
@@ -65,17 +62,15 @@ class sspmod_authX509_Auth_Source_X509userCert extends SimpleSAML_Auth_Source
/**
/**
* Finish a failed authentication.
* Finish a failed authentication.
*
*
* This function can be overloaded by a child authentication
* This function can be overloaded by a child authentication class that wish to perform some operations on failure.
* class that wish to perform some operations on failure
*
*
* @param array &$state
Information about the current authentication.
* @param array &$state Information about the current authentication.
*/
*/
public
function
authFailed
(
&
$state
)
public
function
authFailed
(
&
$state
)
{
{
$config
=
SimpleSAML_Configuration
::
getInstance
();
$config
=
SimpleSAML_Configuration
::
getInstance
();
$t
=
new
SimpleSAML_XHTML_Template
(
$config
,
$t
=
new
SimpleSAML_XHTML_Template
(
$config
,
'authX509:X509error.php'
);
'authX509:X509error.php'
);
$t
->
data
[
'errorcode'
]
=
$state
[
'authX509.error'
];
$t
->
data
[
'errorcode'
]
=
$state
[
'authX509.error'
];
$t
->
show
();
$t
->
show
();
...
@@ -84,15 +79,12 @@ class sspmod_authX509_Auth_Source_X509userCert extends SimpleSAML_Auth_Source
...
@@ -84,15 +79,12 @@ class sspmod_authX509_Auth_Source_X509userCert extends SimpleSAML_Auth_Source
/**
/**
* Validate certificate and login
* Validate certificate and login
.
*
*
* This function try to validate the certificate.
* This function try to validate the certificate. On success, the user is logged in without going through the login
* On success, the user is logged in without going through
* page. On failure, The authX509:X509error.php template is loaded.
* o login page.
* On failure, The authX509:X509error.php template is
* loaded.
*
*
* @param array &$state
Information about the current authentication.
* @param array &$state Information about the current authentication.
*/
*/
public
function
authenticate
(
&
$state
)
public
function
authenticate
(
&
$state
)
{
{
...
@@ -103,28 +95,28 @@ class sspmod_authX509_Auth_Source_X509userCert extends SimpleSAML_Auth_Source
...
@@ -103,28 +95,28 @@ class sspmod_authX509_Auth_Source_X509userCert extends SimpleSAML_Auth_Source
(
$_SERVER
[
'SSL_CLIENT_CERT'
]
==
''
))
{
(
$_SERVER
[
'SSL_CLIENT_CERT'
]
==
''
))
{
$state
[
'authX509.error'
]
=
"NOCERT"
;
$state
[
'authX509.error'
]
=
"NOCERT"
;
$this
->
authFailed
(
$state
);
$this
->
authFailed
(
$state
);
assert
(
'false'
);
// NOTREACHED
assert
(
'false'
);
// should never be reached
return
;
return
;
}
}
$client_cert
=
$_SERVER
[
'SSL_CLIENT_CERT'
];
$client_cert
=
$_SERVER
[
'SSL_CLIENT_CERT'
];
$client_cert_data
=
openssl_x509_parse
(
$client_cert
);
$client_cert_data
=
openssl_x509_parse
(
$client_cert
);
if
(
$client_cert_data
==
false
)
{
if
(
$client_cert_data
==
=
false
)
{
SimpleSAML\Logger
::
error
(
'authX509: invalid cert'
);
SimpleSAML\Logger
::
error
(
'authX509: invalid cert'
);
$state
[
'authX509.error'
]
=
"INVALIDCERT"
;
$state
[
'authX509.error'
]
=
"INVALIDCERT"
;
$this
->
authFailed
(
$state
);
$this
->
authFailed
(
$state
);
assert
(
'false'
);
//
NOTREACHED
assert
(
'false'
);
//
should never be reached
return
;
return
;
}
}
$dn
=
null
;
$dn
=
null
;
foreach
(
$this
->
x509attributes
as
$x509_attr
=>
$ldap_attr
)
{
foreach
(
$this
->
x509attributes
as
$x509_attr
=>
$ldap_attr
)
{
/
*
value is scalar
*/
/
/
value is scalar
if
(
array_key_exists
(
$x509_attr
,
$client_cert_data
[
'subject'
]))
{
if
(
array_key_exists
(
$x509_attr
,
$client_cert_data
[
'subject'
]))
{
$value
=
$client_cert_data
[
'subject'
][
$x509_attr
];
$value
=
$client_cert_data
[
'subject'
][
$x509_attr
];
SimpleSAML\Logger
::
info
(
'authX509: cert '
.
SimpleSAML\Logger
::
info
(
'authX509: cert '
.
$x509_attr
.
' = '
.
$value
);
$x509_attr
.
' = '
.
$value
);
$dn
=
$ldapcf
->
searchfordn
(
$ldap_attr
,
$value
,
true
);
$dn
=
$ldapcf
->
searchfordn
(
$ldap_attr
,
$value
,
true
);
if
(
$dn
!==
null
)
{
if
(
$dn
!==
null
)
{
break
;
break
;
...
@@ -133,12 +125,11 @@ class sspmod_authX509_Auth_Source_X509userCert extends SimpleSAML_Auth_Source
...
@@ -133,12 +125,11 @@ class sspmod_authX509_Auth_Source_X509userCert extends SimpleSAML_Auth_Source
}
}
if
(
$dn
===
null
)
{
if
(
$dn
===
null
)
{
SimpleSAML\Logger
::
error
(
'authX509: cert has '
.
SimpleSAML\Logger
::
error
(
'authX509: cert has no matching user in LDAP.'
);
'no matching user in LDAP'
);
$state
[
'authX509.error'
]
=
"UNKNOWNCERT"
;
$state
[
'authX509.error'
]
=
"UNKNOWNCERT"
;
$this
->
authFailed
(
$state
);
$this
->
authFailed
(
$state
);
assert
(
'false'
);
/
* NOTREACHED */
assert
(
'false'
);
/
/ should never be reached
return
;
return
;
}
}
...
@@ -148,35 +139,32 @@ class sspmod_authX509_Auth_Source_X509userCert extends SimpleSAML_Auth_Source
...
@@ -148,35 +139,32 @@ class sspmod_authX509_Auth_Source_X509userCert extends SimpleSAML_Auth_Source
$state
[
'Attributes'
]
=
$attributes
;
$state
[
'Attributes'
]
=
$attributes
;
$this
->
authSuccesful
(
$state
);
$this
->
authSuccesful
(
$state
);
assert
(
'false'
);
/
* NOTREACHED */
assert
(
'false'
);
/
/ should never be reached
return
;
return
;
}
}
$ldap_certs
=
$ldapcf
->
getAttributes
(
$dn
,
$this
->
ldapusercert
);
$ldap_certs
=
$ldapcf
->
getAttributes
(
$dn
,
$this
->
ldapusercert
);
if
(
$ldap_certs
===
false
)
{
if
(
$ldap_certs
===
false
)
{
SimpleSAML\Logger
::
error
(
'authX509: no certificate '
.
SimpleSAML\Logger
::
error
(
'authX509: no certificate found in LDAP for dn='
.
$dn
);
'found in LDAP for dn='
.
$dn
);
$state
[
'authX509.error'
]
=
"UNKNOWNCERT"
;
$state
[
'authX509.error'
]
=
"UNKNOWNCERT"
;
$this
->
authFailed
(
$state
);
$this
->
authFailed
(
$state
);
assert
(
'false'
);
/
* NOTREACHED */
assert
(
'false'
);
/
/ should never be reached
return
;
return
;
}
}
$merged_ldapcerts
=
array
();
$merged_ldapcerts
=
array
();
foreach
(
$this
->
ldapusercert
as
$attr
)
foreach
(
$this
->
ldapusercert
as
$attr
)
{
$merged_ldapcerts
=
array_merge
(
$merged_ldapcerts
,
$merged_ldapcerts
=
array_merge
(
$merged_ldapcerts
,
$ldap_certs
[
$attr
]);
$ldap_certs
[
$attr
]);
}
$ldap_certs
=
$merged_ldapcerts
;
$ldap_certs
=
$merged_ldapcerts
;
foreach
(
$ldap_certs
as
$ldap_cert
)
{
foreach
(
$ldap_certs
as
$ldap_cert
)
{
$pem
=
\SimpleSAML\Utils\Crypto
::
der2pem
(
$ldap_cert
);
$pem
=
\SimpleSAML\Utils\Crypto
::
der2pem
(
$ldap_cert
);
$ldap_cert_data
=
openssl_x509_parse
(
$pem
);
$ldap_cert_data
=
openssl_x509_parse
(
$pem
);
if
(
$ldap_cert_data
==
false
)
{
if
(
$ldap_cert_data
===
false
)
{
SimpleSAML\Logger
::
error
(
'authX509: cert in '
.
SimpleSAML\Logger
::
error
(
'authX509: cert in LDAP is invalid for dn='
.
$dn
);
'LDAP in invalid for '
.
'dn = '
.
$dn
);
continue
;
continue
;
}
}
...
@@ -186,35 +174,32 @@ class sspmod_authX509_Auth_Source_X509userCert extends SimpleSAML_Auth_Source
...
@@ -186,35 +174,32 @@ class sspmod_authX509_Auth_Source_X509userCert extends SimpleSAML_Auth_Source
$state
[
'Attributes'
]
=
$attributes
;
$state
[
'Attributes'
]
=
$attributes
;
$this
->
authSuccesful
(
$state
);
$this
->
authSuccesful
(
$state
);
assert
(
'false'
);
/
* NOTREACHED */
assert
(
'false'
);
/
/ should never be reached
return
;
return
;
}
}
}
}
SimpleSAML\Logger
::
error
(
'authX509: no matching cert in '
.
SimpleSAML\Logger
::
error
(
'authX509: no matching cert in LDAP for dn='
.
$dn
);
'LDAP for dn = '
.
$dn
);
$state
[
'authX509.error'
]
=
"UNKNOWNCERT"
;
$state
[
'authX509.error'
]
=
"UNKNOWNCERT"
;
$this
->
authFailed
(
$state
);
$this
->
authFailed
(
$state
);
assert
(
'false'
);
/
* NOTREACHED */
assert
(
'false'
);
/
/ should never be reached
return
;
return
;
}
}
/**
/**
* Finish a succesful authentication.
* Finish a succes
s
ful authentication.
*
*
* This function can be overloaded by a child authentication
* This function can be overloaded by a child authentication class that wish to perform some operations after login.
* class that wish to perform some operations after login.
*
*
* @param array &$state
Information about the current authentication.
* @param array &$state Information about the current authentication.
*/
*/
public
function
authSuccesful
(
&
$state
)
public
function
authSuccesful
(
&
$state
)
{
{
SimpleSAML_Auth_Source
::
completeAuth
(
$state
);
SimpleSAML_Auth_Source
::
completeAuth
(
$state
);
assert
(
'false'
);
/
* NOTREACHED */
assert
(
'false'
);
/
/ should never be reached
return
;
return
;
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment