0
ONVIF를 사용하여 사용자를 인증하기 위해 C로 API를 작성했습니다. 나는 인증 헤더를 만들기 위해 몇 가지 코드를 작성한다. 그러나이 헤더를 보냈을 때 서버는 "보안 토큰을 인증하거나 인증 할 수 없습니다"라고 응답했습니다.ONVIF 요청에서 인증 헤더가 작동하지 않습니까?
unsigned int nonce_int = 0, i = 0;
time_t utcTime = 0;
struct tm *timeInfo = NULL;
char sha1_input[100] = { 0 }, sha1_input1[100] = { 0 };
SHA1Context sha = { 0 };
nonce_int = GetRandomNumber();
encode_base64(sizeof(nonce_int), (char*)&nonce_int, nonceLen, noncestr);
utcTime = time(NULL);
timeInfo = localtime(&utcTime);
strftime(timestr, timeLen, "%Y-%m-%dT%H:%M:%SZ", timeInfo);
printf("\nTime in String Format = %s", timestr);
sprintf(sha1_input, "%d+%d+%s", nonce_int, utcTime, password);
strcpy(sha1_input1, sha1_input);
SHA1Reset(&sha);
SHA1Input(&sha, (const unsigned char*)sha1_input, strlen(sha1_input));
if(!SHA1Result(&sha))
{
printf("\nERROR-- could not compute message digest");
}
else
{
memset(sha1_input, 0x00, sizeof(sha1_input));
/*sprintf(sha1_input, "%X%X%X%X%X", sha.Message_Digest[0], sha.Message_Digest[1],
sha.Message_Digest[2], sha.Message_Digest[3], sha.Message_Digest[4]);*/
sprintf(sha1_input, "%u%u%u%u%u", sha.Message_Digest[0], sha.Message_Digest[1],
sha.Message_Digest[2], sha.Message_Digest[3], sha.Message_Digest[4]);
printf("\nSHA1 Digest = %s", sha1_input);
encode_base64(strlen(sha1_input), sha1_input, digestLen, digeststr);
printf("\nSHA1 Digest Base64 Encoded = %s", digeststr);
}
그 후 POST 메서드를 사용하여 HTTP에서이 요청을 보냈습니다.
snprintf(postData, sizeof(postData),
"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
"<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://www.w3.org/2003/05/soap-envelope\""
"xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401"
"-wss-wssecurity-secext-1.0.xsd\""
"xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-"
"200401-wss-wssecurity-utility-1.0.xsd\""
"xmlns:tds=\"http://www.onvif.org/ver20/ptz/wsdl\">"
"<SOAP-ENV:Header><wsse:Security><wsse:UsernameToken>"
"<wsse:Username>%s</wsse:Username>"
"<wsse:Password Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-"
"200401-wss-username-token-profile-1.0#PasswordDigest\">"
"%s</wsse:Password><wsse:Nonce>%s</wsse:Nonce>"
"<wsu:Created>%s</wsu:Created></wsse:UsernameToken>"
"</wsse:Security></SOAP-ENV:Header><SOAP-ENV:Body>"
"<tds:GetNodes>"
"</SOAP-ENV:Body></SOAP-ENV:Envelope>",
username, base64EncDigest, nonce_char, time_char);
응답 :
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope"
xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsa5="http://www.w3.org/2005/08/addressing"
xmlns:c14n="http://www.w3.org/2001/10/xml-exc-c14n#"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:ptzimg2="http://www.onvif.org/ver10/schema"
xmlns:ptzimg3="http://www.w3.org/2005/05/xmlmime"
xmlns:ptzimg4="http://docs.oasis-open.org/wsn/b-2"
xmlns:ptzimg5="http://docs.oasis-open.org/wsrf/bf-2"
xmlns:ptzimg6="http://docs.oasis-open.org/wsn/t-1"
xmlns:ptzimg1="http://www.onvif.org/ver20/ptz/wsdl"
xmlns:ptzimg7="http://www.onvif.org/ver20/imaging/wsdl"
xmlns:ter="http://www.onvif.org/ver10/error">
<SOAP-ENV:Header></SOAP-ENV:Header>
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<SOAP-ENV:Code>
<SOAP-ENV:Value>
SOAP-ENV:Sender
</SOAP-ENV:Value>
<SOAP-ENV:Subcode>
<SOAP-ENV:Value>
wsse:FailedAuthentication
</SOAP-ENV:Value>
</SOAP-ENV:Subcode>
</SOAP-ENV:Code>
<SOAP-ENV:Reason>
<SOAP-ENV:Text xml:lang="en">
The security token could not be authenticated or authorized
</SOAP-ENV:Text>
</SOAP-ENV:Reason>
<SOAP-ENV:Node>
http://www.w3.org/2003/05/soap-envelope/node/ultimateReceiver
</SOAP-ENV:Node>
<SOAP-ENV:Role>
http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver
</SOAP-ENV:Role>
<SOAP-ENV:Detail></SOAP-ENV:Detail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
내가 뭔가 잘못을하고있는 중이 야? 특히 생성 된 다이제스트? 감사합니다
''는 종료되지 않습니다. 복사/붙여 넣기 오류 또는 실제 오류? –
요청의 MIME 형식을 지정할 수 있습니까? – sithereal
감사합니다. @ 요아킴,하지만 지금은 인증 헤더에 문제가 있다고 말합니다. 내 질문을 편집하고 오류 응답을 첨부했습니다. 감사 –