Skip to content

Commit 9a88f5a

Browse files
committed
[project @ OpenID Signed Assertions(Implementation of old sxip draft)]
In our solution, one party, which we call the Attribute Provider (AP), provides a signed certificate that the the user possesses some attribute (e.g. is over 18). This certificate is stored as an attribute at the user's OP, and other RPs can request this certificate when they want to verify attributes of the user. For the implementation, we have followed the OpenID Signed Assertions draft: http://www.mail-archive.com/[email protected]/msg00907.html The Signed Assertions Draft did not specify how signed assertions are stored at the OP, so we adopted the following scheme: Attribute: http://X Certificate: http://X/signature This enables RPs that don't care about certificates to completely ignore them. Assertions are SAML documents as specified in the OpenID Signed Assertions old draft. We are developing a demo application in which a university issues certificates verifying students' age, student-hood, and even their photo (also potentially useful to dating sites). So basically the university acts as an attribute provider, signing assertions about user claims. These claims are stored as an attribute in the OpenId provider and we can use the OpenID AX protocol to pass assertions as attributes. The data flow is: User requests assertion --- University(Attribute provider) --- (store request) --- Openid provider Relying Party(Dating site) --- (fetch request) --- OpenID Provider The RP gets the assertion, verifies the signature, and takes actions depending on the result. In some scenarios, the RP may deny the user request if the attribute verification fails (e.g. the dating site may forbid users under 18). In other scenarios the RP may treat them differently (e.g. the dating site could tag certified photos as "Verified Photo"). Note that the RP must have some sort of trust relationship with the AP. We've tried to keep the system as open as possible. Our protocol and implementation do not specify how this trust relationship is created or managed. For example, there could be a PKI specifically set up for verifying claims about student-hood, another trust system set up for verifying claims about age, etc. Santosh Subramanian Shishir Randive Michael Hart Rob Johnson
1 parent 7607004 commit 9a88f5a

File tree

2 files changed

+400
-0
lines changed

2 files changed

+400
-0
lines changed

Auth/OpenID/AP.php

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
<?php
2+
3+
/**
4+
* Introduces the notion of an Attribute Provider that attests and signs
5+
* attributes
6+
* Uses OpenID Signed Assertions(Sxip draft) for attesting attributes
7+
* PHP versions 4 and 5
8+
*
9+
* LICENSE: See the COPYING file included in this distribution.
10+
*
11+
* @package OpenID
12+
* @author Santosh Subramanian <[email protected]>
13+
* @author Shishir Randive <[email protected]>
14+
* Stony Brook University.
15+
*
16+
*/
17+
require_once 'Auth/OpenID/SAML.php';
18+
/**
19+
* The Attribute_Provider class which signs the attribute,value pair
20+
* for a given openid.
21+
*/
22+
class Attribute_Provider
23+
{
24+
private $public_key_certificate=null;
25+
private $private_key=null;
26+
private $authenticatedUser=null;
27+
private $notBefore=null;
28+
private $notOnOrAfter=null;
29+
private $rsadsa=null;
30+
private $acsURI=null;
31+
private $attribute=null;
32+
private $value=null;
33+
private $assertionTemplate=null;
34+
/**
35+
* Creates an Attribute_Provider object initialized with startup values.
36+
* @param string $public_key_certificate - The public key certificate
37+
of the signer.
38+
* @param string $private_key - The private key of the signer.
39+
* @param string $notBefore - Certificate validity time
40+
* @param string $notOnOrAfter - Certificate validity time
41+
* @param string $rsadsa - Choice of the algorithm (RSA/DSA)
42+
* @param string $acsURI - URI of the signer.
43+
* @param string $assertionTemplate - SAML template used for assertion
44+
*/
45+
function Attribute_Provider($public_key_certificate,$private_key,$notBefore,$notOnOrAfter,$rsadsa,$acsURI,
46+
$assertionTemplate)
47+
{
48+
$this->public_key_certificate=$public_key_certificate;
49+
$this->private_key=$private_key;
50+
$this->notBefore=$notBefore;
51+
$this->notOnOrAfter=$notOnOrAfter;
52+
$this->rsadsa=$rsadsa;
53+
$this->acsURI=$acsURI;
54+
$this->assertionTemplate=$assertionTemplate;
55+
}
56+
/**
57+
* Create the signed assertion.
58+
* @param string $openid - Openid of the entity being asserted.
59+
* @param string $attribute - The attribute name being asserted.
60+
* @param string $value - The attribute value being asserted.
61+
*/
62+
function sign($openid,$attribute,$value)
63+
{
64+
$samlObj = new SAML();
65+
$responseXmlString = $samlObj->createSamlAssertion($openid,
66+
$this->notBefore,
67+
$this->notOnOrAfter,
68+
$this->rsadsa,
69+
$this->acsURI,
70+
$attribute,
71+
sha1($value),
72+
$this->assertionTemplate);
73+
$signedAssertion=$samlObj->signAssertion($responseXmlString,
74+
$this->private_key,
75+
$this->public_key_certificate);
76+
return $signedAssertion;
77+
}
78+
}
79+
/**
80+
* The Attribute_Verifier class which verifies the signed assertion at the Relying party.
81+
*/
82+
class Attribute_Verifier
83+
{
84+
/**
85+
* The certificate the Relying party trusts.
86+
*/
87+
private $rootcert;
88+
/**
89+
* This function loads the public key certificate that the relying party trusts.
90+
* @param string $cert - Trusted public key certificate.
91+
*/
92+
function load_trusted_root_cert($cert)
93+
{
94+
$this->rootcert=$cert;
95+
}
96+
/**
97+
* Verifies the certificate given the SAML document.
98+
* @param string - signed SAML assertion
99+
* return @boolean - true if verification is successful, false if unsuccessful.
100+
*/
101+
function verify($responseXmlString)
102+
{
103+
$samlObj = new SAML();
104+
$ret = $samlObj->verifyAssertion($responseXmlString,$this->rootcert);
105+
return $ret;
106+
}
107+
}
108+
109+
/**
110+
* This is a Store Request creating class at the Attribute Provider.
111+
*/
112+
class AP_OP_StoreRequest
113+
{
114+
/**
115+
* Creates store request and adds it as an extension to AuthRequest object
116+
passed to it.
117+
* @param &Auth_OpenID_AuthRequest &$auth_request - A reference to
118+
the AuthRequest object.
119+
* @param &Attribute_Provider &$attributeProvider - A reference to the
120+
Attribute Provider object.
121+
* @param string $attribute - The attribute name being asserted.
122+
* @param string $value - The attribute value being asserted.
123+
* @param string $openid - Openid of the entity being asserted.
124+
* @return &Auth_OpenID_AuthRequest - Auth_OpenID_AuthRequest object
125+
returned with StoreRequest extension.
126+
*/
127+
static function createStoreRequest(&$auth_request,&$attributeProvider,
128+
$attribute,$value,$openid)
129+
{
130+
if(!$auth_request){
131+
return null;
132+
}
133+
$signedAssertion=$attributeProvider->sign($openid,$attribute,$value);
134+
$store_request=new Auth_OpenID_AX_StoreRequest;
135+
$store_request->addValue($attribute,base64_encode($value));
136+
$store_request->addValue($attribute.'/signature',
137+
base64_encode($signedAssertion));
138+
if($store_request) {
139+
$auth_request->addExtension($store_request);
140+
return $auth_request;
141+
}
142+
}
143+
}
144+
145+
/*
146+
*This is implemented at the RP Takes care of getting the attribute from the
147+
*AX_Fetch_Response object and verifying it.
148+
*/
149+
class RP_OP_Verify
150+
{
151+
/**
152+
* Verifies a given signed assertion.
153+
* @param &Attribute_Verifier &$attributeVerifier - An instance of the class
154+
passed for the verification.
155+
* @param Auth_OpenID_Response - Response object for extraction.
156+
* @return boolean - true if successful, false if verification fails.
157+
*/
158+
function verifyAssertion(&$attributeVerifier,$response)
159+
{
160+
$ax_resp=Auth_OpenID_AX_FetchResponse::fromSuccessResponse($response);
161+
if($ax_resp instanceof Auth_OpenID_AX_FetchResponse){
162+
$ax_args=$ax_resp->getExtensionArgs();
163+
if($ax_args) {
164+
$value=base64_decode($ax_args['value.ext1.1']);
165+
if($attributeVerifier->verify($value)){
166+
return base64_decode($ax_args['value.ext0.1']);
167+
} else {
168+
return null;
169+
}
170+
} else {
171+
return null;
172+
}
173+
} else {
174+
return null;
175+
}
176+
}
177+
}
178+
179+
180+
?>

0 commit comments

Comments
 (0)