2010-01-27 3 views
3

저는 XML 서명 (WSDL)에 대해 DigestValue 및 SignatureValue를 생성하는 방법에 대한 몇 가지 예제를 찾으려고했습니다. 나는 응용 프로그램 공급자로부터 하나의 예를 가지고 있고 샘플과 동일한의 DigestValue와 SignatureValue를 생산하는 것 캔트PHP/linux 도구를 사용하여 enveloped XML Signature에 대해 DigestValue 및 SignatureValue를 생성하는 방법

<?xml version="1.0" encoding="UTF-8"?> 
<soapenv:Envelope xmlns:SOAP-SEC="http://schemas.xmlsoap.org/soap/security/2000-12" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
<soapenv:Header> 
<SOAP-SEC:Signature soapenv:actor="" soapenv:mustUnderstand="0"> 
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"> 
<ds:SignedInfo> 
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/> 
<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/> 
<ds:Reference URI="#Body"> 
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/> 
<ds:DigestValue></ds:DigestValue> 
</ds:Reference> 
</ds:SignedInfo> 
<ds:SignatureValue></ds:SignatureValue> 
</ds:Signature> 
</SOAP-SEC:Signature> 
</soapenv:Header> 
<soapenv:Body Id="Body"> 
<SomeApplicationMethod soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> 
<Application href="#id0"/></SomeApplicationMethod> 
<multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="urn:NCDServices" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns1:SomeApplicationMethod"> 
<param2 xsi:type="soapenc:string">123456</param2> 
<param3 xsi:type="soapenc:string">someString</param3> 
<param4 xsi:type="soapenc:string">string123 bla bla</param4> 
<param5 xsi:type="soapenc:string">0</param5> 
</multiRef> 
</soapenv:Body> 
</soapenv:Envelope> 

: 아래

응용 프로그램에 대한 샘플 SOAP입니다. 애플리케이션 문서에 따르면 전체 Body 섹션에서 digestValue를 만들어야합니다.

나는 sha1, 그 다음 base64encode를 cannonicalize해야한다는 것을 알고있다. 그러나 신체 부분을 어떻게 인식 할 수 있습니까? (sha1 및 base64 인 코드는 이해하기 쉽습니다).

처음에 내가 문자열 VAR 만드는 시도하려는 :

$whole_body = '<soapenv:Body Id="Body"> ........stuff inside...... </soapenv:Body>'; 

을하지만 내가 PHP (적어도 VAR와 같은 문자열 및 PHP 5.2과의 C14N 기능 같은 것은 없다는 것을 발견 아래, 걱정하지 마라, 나는 5.2.6를 가지고있다).

나는 xmlseclibs.php 코드를 살펴 봤는데, DOMelement 객체를 사용하여 C14N 기능을 사용하는 것으로 보입니다. 나는 DOMelement가 무엇인지 잘 모른다.

xmlseclibs.php를 사용하여 XML에 서명을 시도했지만 작동하지 않는 것 같다. 응용 프로그램에서 'signature not valid'오류가 발생했다.

초보자를 도울 수있는 사람이 있습니까 (읽으세요, 나 :))?

협조 해 주셔서 감사합니다.

답변

1
<?php 

$dom = new DOMDocument(); 
$dom->loadXML($yourXML); // the XML you specified above. 

$canonicalized = $dom->C14N(); // for the whole document 

// .. or: 
$tag = $dom->getElementById("yourID"); // give it an ID, or use getElementsByTagName with ->item(0) or something 
$canonicalized = $tag->C14N(); 

// $canonicalized is the canonicalized form of the XML 
// So, The DigestValue is just: 
$digest = base64_encode(pack("H*", sha1($canonicalized))); 
?> 

트릭을해야합니다.

나는 실제로 얼마 전에 작업을 진행하게 관리 ... ... XML-DSIG 바쁜, 나는 가난한 문서를받은, 정규화 무엇을 조각 궁금 또한 :(

1

흠입니다.

나는?

+0

당신이 몸을 얻고 서명하는 코드를 게시하시기 바랍니다 수 있습니다. 사용하기 매우 쉽고, 나는 당신이 그 라이브러리를 시도 제안 http://code.google.com/p/xmlseclibs/

. 롭 리차즈 xmlseclibs를 사용하여 결국 당신에게 – user447951

+0

감사 @ user447951, g http://code.google.com/p/xmlseclibs/의 코드 – mohdyusuf