Tim*_*Tim 2 php certificate single-sign-on
我是php的新手,我需要对SSO服务器进行身份验证.SSO服务器是.Net服务器,使用SSL证书.
当我从SSO服务器返回时,响应被编码.我当然有证书的密钥,但我怎么能解密回复呢?
这对我来说很模糊,请不要犹豫,详细说明你的答案:)
非常感谢您的帮助,最好的问候
您可以使用http/ssl流包装器让php透明地处理ssl部分.
让我们开始简单:
$c = file_get_contents('file.txt');
Run Code Online (Sandbox Code Playgroud)
没有指定包装器,因此默认情况下使用file://.该file://封装试图打开本地文件file.txt的和file_get_contents()函数从流中读取数据.
下一步:http包装器
$c = file_get_contents('http://docs.php.net/fopen');
Run Code Online (Sandbox Code Playgroud)
现在指定了一个包装器.该HTTP的包装器使得为h的请求ttp://docs.php.net/fopen并将结果作为一个流返回,其中包含file_get_contents()所有数据.
如果启用了ssl支持,您也可以使用http s(另请参阅http://docs.php.net/openssl).
$c = file_get_contents('https://developer.mozilla.org/en/gecko_dom_reference');
Run Code Online (Sandbox Code Playgroud)
可选:服务器/客户端身份验证
您可以将上下文附加到php流,允许您为涉及的流包装器设置选项/参数.
例如,http-wrapper 在向服务器发送http请求时会考虑http.user_agent参数.所以,如果你想使服务器"相信"火狐的特定版本发出请求为一个文件,你可以这样做
$context = stream_context_create(
array(
'http'=>array('user-agent'=>'Mozilla/6.0 (Windows; U; Windows NT 7.0; en-US; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.9 (.NET CLR 3.5.30729)')
)
);
$c = file_get_contents('http://docs.php.net/fopen', 0, $context);
Run Code Online (Sandbox Code Playgroud)
$context = stream_context_create(
array(
'http'=>array( ...http-wrapper options here ),
'ssl'=>array( ...ssl-wrapper options here )
)
);
Run Code Online (Sandbox Code Playgroud)
在允许访问资源之前,https服务器可能要求您进行身份验证.必须随请求一起发送客户端证书,服务器决定是否可接受.上下文参数ssl.local_cert允许您指定请求中使用的客户端证书.证书文件可能受密码保护.在这种情况下,您必须提供密码ssl.passphrase
$context = stream_context_create(
array(
'ssl'=>array(
'local_cert'=>'xyz/VolkerCA/UserVolker.pem',
'passphrase'=>'my secret passphrase'
)
)
);
$c = file_get_contents('https://hermes..../ssl/test.php', 0, $context);
Run Code Online (Sandbox Code Playgroud)
另一方面,您可能(也)想确保服务器确实是它声称的那样.如何确定(服务器)证书是否可接受/有效/值得信赖是否超出了这篇文章.http://docs.php.net/book.openssl
设置ssl.verify_peer = true并将信息传递到ssl.cafile查找验证数据的位置
$context = stream_context_create(
array(
'ssl'=>array(
'local_cert'=>'xyz/VolkerCA/UserVolker.pem',
'passphrase'=>'my secret passphrase',
'verify_peer'=>true,
'cafile'=>'xyz/VolkerCA/VolkerCA.pem'
)
)
);
$c = file_get_contents('https://hermes..../ssl/test.php', 0, $context);
Run Code Online (Sandbox Code Playgroud)