Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "rtckit/sip",
"description": "Parser/Renderer for SIP protocol written in PHP",
"version": "0.4.0",
"version": "0.5.0",
"type": "library",
"keywords": [
"sip",
Expand Down
8 changes: 4 additions & 4 deletions src/Header/AuthHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ public static function parse(array $hbody): AuthHeader
break;

case 'nc':
if (!ctype_digit($pv)) {
throw new InvalidHeaderParameter('Invalid Auth header, non-integer nc parameter', Response::BAD_REQUEST);
if (!ctype_xdigit($pv)) {
throw new InvalidHeaderParameter('Invalid Auth header, non-hexadecimal nc parameter', Response::BAD_REQUEST);
}

$val->nc = (int)$pv;
$val->nc = $pv;
break;

case 'opaque':
Expand Down Expand Up @@ -245,7 +245,7 @@ public function render(string $hname): string
}

if (isset($value->nc)) {
$params[] = sprintf('ns=%08d', $value->nc);
$params[] = sprintf('nc=%08s', $value->nc);
}

if (isset($value->opaque)) {
Expand Down
4 changes: 2 additions & 2 deletions src/Header/AuthValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class AuthValue
/** @var string Quality of protection */
public string $qop;

/** @var int Number once count */
public int $nc;
/** @var string Number once count */
public string $nc;

/** @var string Server's opaque data blob */
public string $opaque;
Expand Down
10 changes: 5 additions & 5 deletions tests/Header/AuthHeaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function testShouldParseEnclosedCharacters()

public function testShouldParseVariousNcValueFormatting()
{
$nc = 42;
$nc = hexdec('00000042');

$auth = AuthHeader::parse([
'Digest realm="sip.domain.net",qop="auth",nonce="7900f98e-3d80-4504-adbc-a61e5e040207",stale=FALSE,algorithm=MD5,nc=42',
Expand All @@ -114,7 +114,7 @@ public function testShouldParseVariousNcValueFormatting()
$count = count($auth->values);

for ($i = 0; $i < $count; $i++) {
$this->assertEquals($nc, $auth->values[$i]->nc);
$this->assertEquals($nc, hexdec($auth->values[$i]->nc));
}
}

Expand Down Expand Up @@ -170,15 +170,15 @@ public function testShouldRenderWellFormedValues()
$digest->values[0]->algorithm = 'MD5';
$digest->values[0]->cnonce = '7900f98e';
$digest->values[0]->qop = 'auth-int';
$digest->values[0]->nc = 42;
$digest->values[0]->nc = '42';
$digest->values[0]->opaque = 'misc';

$rendered = $digest->render('Authorization');

$this->assertNotNull($rendered);
$this->assertIsString($rendered);
$this->assertEquals(
'Authorization: Digest username="bob",realm="sip.domain.net",domain="sip:sip.domain.net",nonce="a61e5e040207",uri="sip:sip.domain.net",response="KJHAFgHFIUAG",stale=TRUE,algorithm="MD5",cnonce="7900f98e",qop="auth-int",ns=00000042,opaque="misc"' . "\r\n",
'Authorization: Digest username="bob",realm="sip.domain.net",domain="sip:sip.domain.net",nonce="a61e5e040207",uri="sip:sip.domain.net",response="KJHAFgHFIUAG",stale=TRUE,algorithm="MD5",cnonce="7900f98e",qop="auth-int",nc=00000042,opaque="misc"' . "\r\n",
$rendered
);

Expand All @@ -204,7 +204,7 @@ public function testShouldRenderWellFormedValues()
$this->assertNotNull($rendered);
$this->assertIsString($rendered);
$this->assertEquals(
'Authorization: Digest username="bob",realm="sip.domain.net",domain="sip:sip.domain.net",nonce="a61e5e040207",uri="sip:sip.domain.net",response="KJHAFgHFIUAG",stale=TRUE,algorithm="MD5",cnonce="7900f98e",qop="auth-int",ns=00000042,opaque="misc"' . "\r\n" .
'Authorization: Digest username="bob",realm="sip.domain.net",domain="sip:sip.domain.net",nonce="a61e5e040207",uri="sip:sip.domain.net",response="KJHAFgHFIUAG",stale=TRUE,algorithm="MD5",cnonce="7900f98e",qop="auth-int",nc=00000042,opaque="misc"' . "\r\n" .
'Authorization: Basic MiScCreds' . "\r\n",
$rendered
);
Expand Down