subsequent transactions, including the ACK for the current INVITE.
The UAS stores the values of the To and From field, including any
tags. These become the local and remote addresses of the call leg,
respectively.
11.3 Caller Receives Response to Initial Request
Multiple responses may arrive at the UAC for a single INVITE request,
due to a forking proxy. Each response is distinguished by the "tag"
parameter in the To header field, and each represents a distinct call
leg. The caller MAY choose to acknowledge or terminate the call with
each responding UAS. To acknowledge, it sends an ACK request, and to
terminate it sends a BYE request. The To header field in the ACK or
BYE MUST be the same as the To field in the 200 response, including
any tag. The From header field MUST be the same as the From header
field in the 200 (OK) response, including any tag. The Request-URI of
the ACK or BYE request MAY be set to whatever address was found in
the Contact header field in the 200 (OK) response, if present.
Alternately, a UAC may copy the address from the To header field into
the Request-URI. The UAC also notes the value of the To and From
header fields in each response. For each call leg, the To header
field becomes the remote address, and the From header field becomes
the local address.
11.4 Caller or Callee Generate Subsequent Requests
Once the call has been established, either the caller or callee MAY
generate INVITE or BYE requests to change or terminate the call.
Regardless of whether the caller or callee is generating the new
request, the header fields in the request are set as follows. For the
desired call leg, the To header field is set to the remote address,
and the From header field is set to the local address (both including
any tags). The Contact header field MAY be different than the Contact
header field sent in a previous response or request. The Request-URI
MAY be set to the value of the Contact header field received in a
previous request or response from the remote party, or to the value
of the remote address.
11.5 Receiving Subsequent Requests
When a request is received subsequently, the following checks are
made:
1. If the Call-ID is new, the request is for a new call,
regardless of the values of the To and From header fields.
2. If the Call-ID exists, the request is for an existing call.
If the To, From, Call-ID, and CSeq values exactly match
(including tags) those of any requests received previously,
the request is a retransmission.
3. If there was no match to the previous step, the To and From
fields are compared against existing call leg local and
remote addresses. If there is a match, and the CSeq in the
request is higher than the last CSeq received on that leg,
the request is a new transaction for an existing call leg.
12 Behavior of SIP Proxy and Redirect Servers
This section describes behavior of SIP redirect and proxy servers in
detail. Proxy servers can "fork" connections, i.e., a single incoming
request spawns several outgoing (client) requests.
12.1 Redirect Server
A redirect server does not issue any SIP requests of its own. After
receiving a request other than CANCEL, the server gathers the list of
alternative locations and returns a final response of class 3xx or it
refuses the request. For well-formed CANCEL requests, it SHOULD
return a 2xx response. This response ends the SIP transaction. The
redirect server maintains transaction state for the whole SIP
transaction. It is up to the client to detect forwarding loops
between redirect servers.
12.2 User Agent Server
User agent servers behave similarly to redirect servers, except that
they also accept requests and can return a response of class 2xx.
12.3 Proxy Server
This section outlines processing rules for proxy servers. A proxy
server can either be stateful or stateless. When stateful, a proxy
remembers the incoming request which generated outgoing requests, and
the outgoing requests. A stateless proxy forgets all information once
an outgoing request is generated. A forking proxy SHOULD be stateful.
Proxies that accept TCP connections MUST be stateful.
Otherwise, if the proxy were to lose a request, the TCP
client would never retransmit it.
A stateful proxy SHOULD NOT become stateless until after it sends a
definitive response upstream, and at least 32 seconds after it
received a definitive response.
A stateful proxy acts as a virtual UAS/UAC. It implements the server
state machine when receiving requests, and the client state machine
for generating outgoing requests, with the exception of receiving a
2xx response to an INVITE. Instead of generating an ACK, the 2xx
response is always forwarded upstream towards the caller.
Furthermore, ACK's for 200 responses to INVITE's are always proxied
downstream towards the UAS, as they would be for a stateless proxy.
A stateless proxy does not act as a virtual UAS/UAC (as this would
require state). Rather, a stateless proxy forwards every request it
receives downstream, and every response it receives upstream.
12.3.1 Proxying Requests
To prevent loops, a server MUST check if its own address is already
contained in the Via header field of the incoming request.
The To, From, Call-ID, and Contact tags are copied exactly from the
original request. The proxy SHOULD change the Request-URI to indicate
the server where it intends to send the request.
A proxy server always inserts a Via header field containing its own
address into those requests that are caused by an incoming request.
Each proxy MUST insert a "branch" parameter (Section 6.40).
12.3.2 Proxying Responses
A proxy only processes a response if the topmost Via field matches
one of its addresses. A response with a non-matching top Via field
MUST be dropped.
12.3.3 Stateless Proxy: Proxying Responses
A stateless proxy removes its own Via field, and checks the address
in the next Via field. In the case of UDP, the response is sent to
the address listed in the "maddr" tag if present, otherwise to the
"received" tag if present, and finally to the address in the "sent-
by" field. A proxy MUST remain stateful when handling requests
received via TCP.
A stateless proxy MUST NOT generate its own provisional responses.
12.3.4 Stateful Proxy: Receiving Requests
When a stateful proxy receives a request, it checks the To, From
(including tags), Call-ID and CSeq against existing request records.
If the tuple exists, the request is a retransmission. The provisional
or final response sent previously is retransmitted, as per the server
state machine. If the tuple does not exist, the request corresponds
to a new transaction, and the request should be proxied.
A stateful proxy server MAY generate its own provisional (1xx)
responses.
12.3.5 Stateful Proxy: Receiving ACKs
When an ACK request is received, it is either processed locally or
proxied. To make this determination, the To, From, CSeq and Call-ID
fields are compared against those in previous requests. If there is
no match, the ACK request is proxied as if it were an INVITE request.
If there is a match, and if the server had ever sent a 200 response
upstream, the ACK is proxied. If the server had never sent any
responses upstream, the ACK is also proxied. If the server had sent a
3xx, 4xx, 5xx or 6xx response, but no 2xx response, the ACK is
processed locally if the tag in the To field of the ACK matches the
tag sent by the proxy in the response.
12.3.6 Stateful Proxy: Receiving Responses
When a proxy server receives a response that has passed the Via
checks, the proxy server checks the To (without the tag), From
(including the tag), Call-ID and CSeq against values seen in previous
requests. If there is no match, the response is forwarded upstream to
the address listed in the Via field. If there is a match, the
"branch" tag in the Via field is examined. If it matches a known
branch identifier, the response is for the given branch, and
processed by the virtual client for the given branch. Otherwise, the
response is dropped.
A stateful proxy should obey the rules in Section 12.4 to determine
if the response should be proxied upstream. If it is to be proxied,
the same rules for stateless proxies above are followed, with the
following addition for TCP. If a request was received via TCP
(indicated by the protocol in the top Via header), the proxy checks
to see if it has a connection currently open to that address. If so,
the response is sent on that connection. Otherwise, a new TCP
connection is opened to the address and port in the Via field, and
the response is sent there. Note that this implies that a UAC or
proxy MUST be prepared to receive responses on the incoming side of a
TCP connection. Definitive non 200-class responses MUST be
retransmitted by the proxy, even over a TCP connection.
12.3.7 Stateless, Non-Forking Proxy
Proxies in this category issue at most a single unicast request for
each incoming SIP request, that is, they do not "fork" requests.
However, servers MAY choose to always operate in a mode that allows
issuing of several requests, as described in Section 12.4.
The server can forward the request and any responses. It does not
have to maintain any state for the SIP transaction. Reliability is
assured by the next redirect or stateful proxy server in the server
chain.
A proxy server SHOULD cache the result of any address translations
and the response to speed forwarding of retransmissions. After the
cache entry has been expired, the server cannot tell whether an
incoming request is actually a retransmission of an older request.
The server will treat it as a new request and commence another
search.
12.4 Forking Proxy
The server MUST respond to the request immediately with a 100
(Trying) response.
Successful responses to an INVITE request MAY contain a Contact
header field so that the following ACK or BYE bypasses the proxy
search mechanism. If the proxy requires future requests to be routed
through it, it adds a Record-Route header to the request (Section
6.29).
The following C-code describes the behavior of a proxy server issuing
several requests in response to an incoming INVITE request. The
function request(r, a, b) sends a SIP request of type r to address a,
with branch id b. await_response() waits until a response is received
and returns the response. close(a) closes the TCP connection to
client with address a. response(r) sends a response to the client.
ismulticast() returns 1 if the location is a multicast address and
zero otherwise. The variable timeleft indicates the amount of time
left until the maximum response time has expired. The variable
recurse indicates whether the server will recursively try addresses
returned through a 3xx response. A server MAY decide to recursively
try only certain addresses, e.g., those which are within the same
domain as the proxy server. Thus, an initial multicast request can
trigger additional unicast requests.
/* request type */
typedef enum {INVITE, ACK, BYE, OPTIONS, CANCEL, REGISTER} Method;
process_request(Method R, int N, address_t address[])
{
struct {
int branch; /* branch id */
int done; /* has responded */
} outgoing[];
int done[]; /* address has responded */
char *location[]; /* list of locations */
int heard = 0; /* number of sites heard from */
int class; /* class of status code */
int timeleft = 120; /* sample timeout value */
int loc = 0; /* number of locations */
struct { /* response */
int status; /* response: CANCEL=-1 */
int locations; /* number of redirect locations */
char *location[]; /* redirect locations */
address_t a; /* address of respondent */
int branch; /* branch identifier */
} r, best; /* response, best response */
int i;
best.status = 1000;
for (i = 0; i < N; i++) {
request(R, address[i], i);
outgoing[i].done = 0;
outgoing[i].branch = i;
}
while (timeleft > 0 && heard < N) {
r = await_response();
class = r.status / 100;
/* If final response, mark branch as done. */
if (class >= 2) {
heard++;
for (i = 0; i < N; i++) {
if (r.branch == outgoing[i].branch) {
outgoing[i].done = 1;
break;
}
}
}
/* CANCEL: respond, fork and wait for responses */
else if (class < 0) {
best.status = 200;
response(best);
for (i = 0; i < N; i++) {
if (!outgoing[i].done)
request(CANCEL, address[i], outgoing[i].branch);
}
best.status = -1;
}
/* Send an ACK */
if (class != 2) {
if (R == INVITE) request(ACK, r.a, r.branch);
}
if (class == 2) {
if (r.status < best.status) best = r;
break;
}
else if (class == 3) {
/* A server MAY optionally recurse. The server MUST check
* whether it has tried this location before and whether
* the location is part of the Via path of the incoming
* request. This check is omitted here for brevity.
* Multicast locations MUST NOT be returned to the client if
* the server is not recursing.
*/
if (recurse) {
multicast = 0;
N += r.locations;
for (i = 0; i < r.locations; i++) {
request(R, r.location[i]);
}
} else if (!ismulticast(r.location)) {
best = r;
}
}
else if (class == 4) {
if (best.status >= 400) best = r;
}
else if (class == 5) {
if (best.status >= 500) best = r;
}
else if (class == 6) {
best = r;
break;
}
}
/* We haven't heard anything useful from anybody. */
if (best.status == 1000) {
best.status = 404;
}
if (best.status/100 != 3) loc = 0;
response(best);
}
Responses are processed as follows. The process completes (and state
can be freed) when all requests have been answered by final status
responses (for unicast) or 60 seconds have elapsed (for multicast). A
proxy MAY send a CANCEL to all branches and return a 408 (Timeout) to
the client after 60 seconds or more.
1xx: The proxy MAY forward the response upstream towards the client.
2xx: The proxy MUST forward the response upstream towards the client,
without sending an ACK downstream. After receiving a 2xx, the
server MAY terminate all other pending requests by sending a
CANCEL request and closing the TCP connection, if applicable.
(Terminating pending requests is advisable as searches consume
resources. Also, INVITE requests could "ring" on a number of
workstations if the callee is currently logged in more than
once.)
3xx: The proxy MUST send an ACK and MAY recurse on the listed Contact
addresses. Otherwise, the lowest-numbered response is returned
if there were no 2xx responses.
Location lists are not merged as that would prevent
forwarding of authenticated responses. Also, responses can
have message bodies, so that merging is not feasible.
4xx, 5xx: The proxy MUST send an ACK and remember the response if it
has a lower status code than any previous 4xx and 5xx responses.
On completion, the lowest-numbered response is returned if there
were no 2xx or 3xx responses.
6xx: The proxy MUST forward the response to the client and send an
ACK. Other pending requests MAY be terminated with CANCEL as
described for 2xx responses.
A proxy server forwards any response for Call-IDs for which it does
not have a pending transaction according to the response's Via
header. User agent servers respond to BYE requests for unknown call
legs with status code 481 (Transaction Does Not Exist); they drop ACK
requests with unknown call legs silently.
Special considerations apply for choosing forwarding destinations for
ACK and BYE requests. In most cases, these requests will bypass
proxies and reach the desired party directly, keeping proxies from
having to make forwarding decisions.
A proxy MAY maintain call state for a period of its choosing. If a
proxy still has list of destinations that it forwarded the last
INVITE to, it SHOULD direct ACK requests only to those downstream
servers.
13 Security Considerations
13.1 Confidentiality and Privacy: Encryption
13.1.1 End-to-End Encryption
SIP requests and responses can contain sensitive information about
the communication patterns and communication content of individuals.
The SIP message body MAY also contain encryption keys for the session
itself. SIP supports three complementary forms of encryption to
protect privacy:
o End-to-end encryption of the SIP message body and certain
sensitive header fields;
o hop-by-hop encryption to prevent eavesdropping that tracks
who is calling whom;
o hop-by-hop encryption of Via fields to hide the route a
request has taken.
Not all of the SIP request or response can be encrypted end-to-end
because header fields such as To and Via need to be visible to
proxies so that the SIP request can be routed correctly. Hop-by-hop
encryption encrypts the entire SIP request or response on the wire so
that packet sniffers or other eavesdroppers cannot see who is calling
whom. Hop-by-hop encryption can also encrypt requests and responses
that have been end-to-end encrypted. Note that proxies can still see
who is calling whom, and this information is also deducible by
performing a network traffic analysis, so this provides a very
limited but still worthwhile degree of protection.
SIP Via fields are used to route a response back along the path taken
by the request and to prevent infinite request loops. However, the
information given by them can also provide useful information to an
attacker. Section 6.22 describes how a sender can request that Via
fields be encrypted by cooperating proxies without compromising the
purpose of the Via field.
End-to-end encryption relies on keys shared by the two user agents
involved in the request. Typically, the message is sent encrypted
with the public key of the recipient, so that only that recipient can
read the message. All implementations SHOULD support PGP-based
encryption [33] and MAY implement other schemes.
A SIP request (or response) is end-to-end encrypted by splitting the
message to be sent into a part to be encrypted and a short header
that will remain in the clear. Some parts of the SIP message, namely
the request line, the response line and certain header fields marked
with "n" in the "enc." column in Table 4 and 5 need to be read and
returned by proxies and thus MUST NOT be encrypted end-to-end.
Possibly sensitive information that needs to be made available as
plaintext include destination address (To) and the forwarding path
(Via) of the call. The Authorization header field MUST remain in the
clear if it contains a digital signature as the signature is
generated after encryption, but MAY be encrypted if it contains
"basic" or "digest" authentication. The From header field SHOULD
normally remain in the clear, but MAY be encrypted if required, in
which case some proxies MAY return a 401 (Unauthorized) status if
they require a From field.
Other header fields MAY be encrypted or MAY travel in the clear as
desired by the sender. The Subject, Allow and Content-Type header
fields will typically be encrypted. The Accept, Accept-Language,
Date, Expires, Priority, Require, Call-ID, Cseq, and Timestamp header
fields will remain in the clear.
All fields that will remain in the clear MUST precede those that will
be encrypted. The message is encrypted starting with the first
character of the first header field that will be encrypted and
continuing through to the end of the message body. If no header
fields are to be encrypted, encrypting starts with the second CRLF
pair after the last header field, as shown below. Carriage return and
line feed characters have been made visible as "$", and the encrypted
part of the message is outlined.
INVITE sip:watson@boston.bell-telephone.com SIP/2.0$
Via: SIP/2.0/UDP 169.130.12.5$
To: T. A. Watson <sip:watson@bell-telephone.com>$
From: A. Bell <sip:a.g.bell@bell-telephone.com>$
Encryption: PGP version=5.0$
Content-Length: 224$
Call-ID: 187602141351@worcester.bell-telephone.com$
CSeq: 488$
$
*******************************************************
* Subject: Mr. Watson, come here.$ *
* Content-Type: application/sdp$ *
* $ *
* v=0$ *
* o=bell 53655765 2353687637 IN IP4 128.3.4.5$ *
* c=IN IP4 135.180.144.94$ *
* m=audio 3456 RTP/AVP 0 3 4 5$ *
*******************************************************
An Encryption header field MUST be added to indicate the encryption
mechanism used. A Content-Length field is added that indicates the
length of the encrypted body. The encrypted body is preceded by a
blank line as a normal SIP message body would be.
Upon receipt by the called user agent possessing the correct
decryption key, the message body as indicated by the Content-Length
field is decrypted, and the now-decrypted body is appended to the
clear-text header fields. There is no need for an additional
Content-Length header field within the encrypted body because the
length of the actual message body is unambiguous after decryption.
Had no SIP header fields required encryption, the message would have
been as below. Note that the encrypted body MUST then include a blank
line (start with CRLF) to disambiguate between any possible SIP
header fields that might have been present and the SIP message body.
INVITE sip:watson@boston.bell-telephone.com SIP/2.0$
Via: SIP/2.0/UDP 169.130.12.5$
To: T. A. Watson <sip:watson@bell-telephone.com>$
From: A. Bell <a.g.bell@bell-telephone.com>$
Encryption: PGP version=5.0$
Content-Type: application/sdp$
Content-Length: 107$
$
*************************************************
* $ *
* v=0$ *
* o=bell 53655765 2353687637 IN IP4 128.3.4.5$ *
* c=IN IP4 135.180.144.94$ *
* m=audio 3456 RTP/AVP 0 3 4 5$ *
*************************************************
13.1.2 Privacy of SIP Responses
SIP requests can be sent securely using end-to-end encryption and
authentication to a called user agent that sends an insecure
response. This is allowed by the SIP security model, but is not a
good idea. However, unless the correct behavior is explicit, it
would not always be possible for the called user agent to infer what
a reasonable behavior was. Thus when end-to-end encryption is used by
the request originator, the encryption key to be used for the
response SHOULD be specified in the request. If this were not done,
it might be possible for the called user agent to incorrectly infer
an appropriate key to use in the response. Thus, to prevent key-
guessing becoming an acceptable strategy, we specify that a called
user agent receiving a request that does not specify a key to be used
for the response SHOULD send that response unencrypted.
Any SIP header fields that were encrypted in a request SHOULD also be
encrypted in an encrypted response. Contact response fields MAY be
encrypted if the information they contain is sensitive, or MAY be
left in the clear to permit proxies more scope for localized
searches.
13.1.3 Encryption by Proxies
Normally, proxies are not allowed to alter end-to-end header fields
and message bodies. Proxies MAY, however, encrypt an unsigned request
or response with the key of the call recipient.
Proxies need to encrypt a SIP request if the end system
cannot perform encryption or to enforce organizational
security policies.
13.1.4 Hop-by-Hop Encryption
SIP requests and responses MAY also be protected by security
mechanisms at the transport or network layer. No particular mechanism
is defined or recommended here. Two possibilities are IPSEC [34] or
TLS [35]. The use of a particular mechanism will generally need to be
specified out of band, through manual configuration, for example.
13.1.5 Via field encryption
When Via header fields are to be hidden, a proxy that receives a
request containing an appropriate "Hide: hop" header field (as
specified in section 6.22) SHOULD encrypt the header field. As only
the proxy that encrypts the field will decrypt it, the algorithm
chosen is entirely up to the proxy implementor. Two methods satisfy
these requirements:
o The server keeps a cache of Via header fields and the
associated To header field, and replaces the Via header field
with an index into the cache. On the reverse path, take the
Via header field from the cache rather than the message.
This is insufficient to prevent message looping, and so an
additional ID MUST be added so that the proxy can detect loops.
This SHOULD NOT normally be the address of the proxy as the goal
is to hide the route, so instead a sufficiently large random
number SHOULD be used by the proxy and maintained in the cache.
It is possible for replies to get directed to the wrong
originator if the cache entry gets reused, so great care needs
to be taken to ensure this does not happen.
o The server MAY use a secret key to encrypt the Via field, a
timestamp and an appropriate checksum in any such message with
the same secret key. The checksum is needed to detect whether
successful decoding has occurred, and the timestamp is
required to prevent possible replay attacks and to ensure that
no two requests from the same previous hop have the same
encrypted Via field. This is the preferred solution.
13.2 Message Integrity and Access Control: Authentication
Protective measures need to be taken to prevent an active attacker
from modifying and replaying SIP requests and responses. The same
cryptographic measures that are used to ensure the authenticity of
the SIP message also serve to authenticate the originator of the
message. However, the "basic" and "digest" authentication mechanism
offer authentication only, without message integrity.
Transport-layer or network-layer authentication MAY be used for hop-
by-hop authentication. SIP also extends the HTTP WWW-Authenticate
(Section 6.42) and Authorization (Section 6.11) header field and
their Proxy counterparts to include cryptographically strong
signatures. SIP also supports the HTTP "basic" and "digest" schemes
(see Section 14) and other HTTP authentication schemes to be defined
that offer a rudimentary mechanism of ascertaining the identity of
the caller.
Since SIP requests are often sent to parties with which no
prior communication relationship has existed, we do not
specify authentication based on shared secrets.
SIP requests MAY be authenticated using the Authorization header
field to include a digital signature of certain header fields, the
request method and version number and the payload, none of which are
modified between client and called user agent. The Authorization
header field is used in requests to authenticate the request
originator end-to-end to proxies and the called user agent, and in
responses to authenticate the called user agent or proxies returning
their own failure codes. If required, hop-by-hop authentication can
be provided, for example, by the IPSEC Authentication Header.
SIP does not dictate which digital signature scheme is used for
authentication, but does define how to provide authentication using
PGP in Section 15. As indicated above, SIP implementations MAY also
use "basic" and "digest" authentication and other authentication
mechanisms defined for HTTP. Note that "basic" authentication has
severe security limitations. The following does not apply to these
schemes.
To cryptographically sign a SIP request, the order of the SIP header
fields is important. When an Authorization header field is present,
it indicates that all header fields following the Authorization
header field have been included in the signature. Therefore, hop-
by-hop header fields which MUST or SHOULD be modified by proxies MUST
precede the Authorization header field as they will generally be
modified or added-to by proxy servers. Hop-by-hop header fields
which MAY be modified by a proxy MAY appear before or after the
Authorization header. When they appear before, they MAY be modified
by a proxy. When they appear after, they MUST NOT be modified by a
proxy. To sign a request, a client constructs a message from the
request method (in upper case) followed, without LWS, by the SIP
version number, followed, again without LWS, by the request headers
to be signed and the message body. The message thus constructed is
then signed.
For example, if the SIP request is to be:
INVITE sip:watson@boston.bell-telephone.com SIP/2.0
Via: SIP/2.0/UDP 169.130.12.5
Authorization: PGP version=5.0, signature=...
From: A. Bell <sip:a.g.bell@bell-telephone.com>
To: T. A. Watson <sip:watson@bell-telephone.com>
Call-ID: 187602141351@worcester.bell-telephone.com
Subject: Mr. Watson, come here.
Content-Type: application/sdp
Content-Length: ...
v=0
o=bell 53655765 2353687637 IN IP4 128.3.4.5
c=IN IP4 135.180.144.94
m=audio 3456 RTP/AVP 0 3 4 5
Then the data block that is signed is:
INVITESIP/2.0From: A. Bell <sip:a.g.bell@bell-telephone.com>
To: T. A. Watson <sip:watson@bell-telephone.com>
Call-ID: 187602141351@worcester.bell-telephone.com
Subject: Mr. Watson, come here.
Content-Type: application/sdp
Content-Length: ...
v=0
o=bell 53655765 2353687637 IN IP4 128.3.4.5
c=IN IP4 135.180.144.94
m=audio 3456 RTP/AVP 0 3 4 5
Clients wishing to authenticate requests MUST construct the portion
of the message below the Authorization header using a canonical form.
This allows a proxy to parse the message, take it apart, and
reconstruct it, without causing an authentication failure due to
extra white space, for example. Canonical form consists of the
following rules:
o No short form header fields
o Header field names are capitalized as shown in this document
o No white space between the header name and the colon
o A single space after the colon
o Line termination with a CRLF
o No line folding
o No comma separated lists of header values; each must appear
as a separate header
o Only a single SP between tokens, between tokens and quoted
strings, and between quoted strings; no SP after last token or
quoted string
o No LWS between tokens and separators, except as described
above for after the colon in header fields
Note that if a message is encrypted and authenticated using a digital
signature, when the message is generated encryption is performed
before the digital signature is generated. On receipt, the digital
signature is checked before decryption.
A client MAY require that a server sign its response by including a
Require: org.ietf.sip.signed-response request header field. The
client indicates the desired authentication method via the WWW-
Authenticate header.
The correct behavior in handling unauthenticated responses to a
request that requires authenticated responses is described in section
13.2.1.
13.2.1 Trusting responses
There is the possibility that an eavesdropper listens to requests and
then injects unauthenticated responses that terminate, redirect or
otherwise interfere with a call. (Even encrypted requests contain
enough information to fake a response.)
Clients need to be particularly careful with 3xx redirection
responses. Thus a client receiving, for example, a 301 (Moved
Permanently) which was not authenticated when the public key of the
called user agent is known to the client, and authentication was
requested in the request SHOULD be treated as suspicious. The correct
behavior in such a case would be for the called-user to form a dated
response containing the Contact field to be used, to sign it, and
give this signed stub response to the proxy that will provide the
redirection. Thus the response can be authenticated correctly. A
client SHOULD NOT automatically redirect such a request to the new
location without alerting the user to the authentication failure
before doing so.
Another problem might be responses such as 6xx failure responses
which would simply terminate a search, or "4xx" and "5xx" response
failures.
If TCP is being used, a proxy SHOULD treat 4xx and 5xx responses as
valid, as they will not terminate a search. However, fake 6xx
responses from a rogue proxy terminate a search incorrectly. 6xx
responses SHOULD be authenticated if requested by the client, and
failure to do so SHOULD cause such a client to ignore the 6xx
response and continue a search.
With UDP, the same problem with 6xx responses exists, but also an
active eavesdropper can generate 4xx and 5xx responses that might
cause a proxy or client to believe a failure occurred when in fact it
did not. Typically 4xx and 5xx responses will not be signed by the
called user agent, and so there is no simple way to detect these
rogue responses. This problem is best prevented by using hop-by-hop
encryption of the SIP request, which removes any additional problems
that UDP might have over TCP.
These attacks are prevented by having the client require response
authentication and dropping unauthenticated responses. A server user
agent that cannot perform response authentication responds using the
normal Require response of 420 (Bad Extension).
13.3 Callee Privacy
User location and SIP-initiated calls can violate a callee's privacy.
An implementation SHOULD be able to restrict, on a per-user basis,
what kind of location and availability information is given out to
certain classes of callers.
13.4 Known Security Problems
With either TCP or UDP, a denial of service attack exists by a rogue
proxy sending 6xx responses. Although a client SHOULD choose to
ignore such responses if it requested authentication, a proxy cannot
do so. It is obliged to forward the 6xx response back to the client.
The client can then ignore the response, but if it repeats the
request it will probably reach the same rogue proxy again, and the
process will repeat.
14 SIP Authentication using HTTP Basic and Digest Schemes
SIP implementations MAY use HTTP's basic and digest authentication
mechanisms to provide a rudimentary form of security. This section
overviews usage of these mechanisms in SIP. The basic operation is
almost completely identical to that for HTTP [36]. This section
outlines this operation, pointing to [36] for details, and noting the
differences when used in SIP.
14.1 Framework
The framework for SIP authentication parallels that for HTTP [36]. In
particular, the BNF for auth-scheme, auth-param, challenge, realm,
realm-value, and credentials is identical. The 401 response is used
by user agent servers in SIP to challenge the authorization of a user
agent client. Additionally, registrars and redirect servers MAY make
use of 401 responses for authorization, but proxies MUST NOT, and
instead MAY use the 407 response. The requirements for inclusion of
the Proxy-Authenticate, Proxy-Authorization, WWW-Authenticate, and
Authorization in the various messages is identical to [36].
Since SIP does not have the concept of a canonical root URL, the
notion of protections spaces are interpreted differently for SIP. The
realm is a protection domain for all SIP URIs with the same value for
the userinfo, host and port part of the SIP Request-URI. For example:
INVITE sip:alice.wonderland@example.com SIP/2.0
WWW-Authenticate: Basic realm="business"
and
INVITE sip:aw@example.com SIP/2.0
WWW-Authenticate: Basic realm="business"
define different protection realms according to this rule.
When a UAC resubmits a request with its credentials after receiving a
401 or 407 response, it MUST increment the CSeq header field as it
would normally do when sending an updated request.
14.2 Basic Authentication
The rules for basic authentication follow those defined in [36], but
with the words "origin server" replaced with "user agent server,
redirect server , or registrar".
Since SIP URIs are not hierarchical, the paragraph in [36] that
states that "all paths at or deeper than the depth of the last
symbolic element in the path field of the Request-URI also are within
the protection space specified by the Basic realm value of the
current challenge" does not apply for SIP. SIP clients MAY
preemptively send the corresponding Authorization header with
requests for SIP URIs within the same protection realm (as defined
above) without receipt of another challenge from the server.
14.3 Digest Authentication
The rules for digest authentication follow those defined in [36],
with "HTTP 1.1" replaced by "SIP/2.0" in addition to the following
differences:
1. The URI included in the challenge has the following BNF:
URI = SIP-URL
2. The BNF for digest-uri-value is:
digest-uri-value = Request-URI ; a defined in Section
4.3
3. The example procedure for choosing a nonce based on Etag
does not work for SIP.
4. The Authentication-Info and Proxy-Authentication-Info
fields are not used in SIP.
5. The text in [36] regarding cache operation does not apply
to SIP.
6. [36] requires that a server check that the URI in the
request line, and the URI included in the Authorization
header, point to the same resource. In a SIP context, these
two URI's may actually refer to different users, due to
forwarding at some proxy. Therefore, in SIP, a server MAY
check that the request-uri in the Authorization header
corresponds to a user that the server is willing to accept
forwarded or direct calls for.
14.4 Proxy-Authentication
The use of the Proxy-Authentication and Proxy-Authorization parallel
that as described in [36], with one difference. Proxies MUST NOT add
the Proxy-Authorization header. 407 responses MUST be forwarded
upstream towards the client following the procedures for any other
response. It is the client's responsibility to add the Proxy-
Authorization header containing credentials for the proxy which has
asked for authentication.
If a proxy were to resubmit a request with a Proxy-
Authorization header field, it would need to increment the
CSeq in the new request. However, this would mean that the
UAC which submitted the original request would discard a
response from the UAS, as the CSeq value would be
different.
See sections 6.26 and 6.27 for additional information on usage of
these fields as they apply to SIP.
15 SIP Security Using PGP
15.1 PGP Authentication Scheme
The "pgp" authentication scheme is based on the model that the client
authenticates itself with a request signed with the client's private
key. The server can then ascertain the origin of the request if it
has access to the public key, preferably signed by a trusted third
party.
15.1.1 The WWW-Authenticate Response Header
WWW-Authenticate = "WWW-Authenticate" ":" "pgp" pgp-challenge
pgp-challenge = * (";" pgp-params )
pgp-params = realm | pgp-version | pgp-algorithm | nonce
realm = "realm" "=" realm-value
realm-value = quoted-string
pgp-version = "version" "="
<"> digit *( "." digit ) *letter <">
pgp-algorithm = "algorithm" "=" ( "md5" | "sha1" | token )
nonce = "nonce" "=" nonce-value
nonce-value = quoted-string
The meanings of the values of the parameters used above are as
follows:
realm: A string to be displayed to users so they know which identity
to use. This string SHOULD contain at least the name of the host
performing the authentication and MAY additionally indicate the
collection of users who might have access. An example might be "
Users with call-out privileges ".
pgp-algorithm: The value of this parameter indicates the PGP message
integrity check (MIC) to be used to produce the signature. If
this not present it is assumed to be "md5". The currently
defined values are "md5" for the MD5 checksum, and "sha1" for
the SHA.1 algorithm.
pgp-version: The version of PGP that the client MUST use. Common
values are "2.6.2" and "5.0". The default is 5.0.
nonce: A server-specified data string which should be uniquely
generated each time a 401 response is made. It is RECOMMENDED
that this string be base64 or hexadecimal data. Specifically,
since the string is passed in the header lines as a quoted
string, the double-quote character is not allowed. The contents
of the nonce are implementation dependent. The quality of the
implementation depends on a good choice. Since the nonce is used
only to prevent replay attacks and is signed, a time stamp in
units convenient to the server is sufficient.
Replay attacks within the duration of the call setup are of
limited interest, so that timestamps with a resolution of a
few seconds are often should be sufficient. In that case,
the server does not have to keep a record of the nonces.
Example:
WWW-Authenticate: pgp ;version="5.0"
;realm="Your Startrek identity, please" ;algorithm=md5
;nonce="913082051"
15.1.2 The Authorization Request Header
The client is expected to retry the request, passing an Authorization
header line, which is defined as follows.
Authorization = "Authorization" ":" "pgp" *( ";" pgp-response )
pgp-response = realm | pgp-version | pgp-signature
| signed-by | nonce
pgp-signature = "signature" "=" quoted-string
signed-by = "signed-by" "=" <"> URI <">
The client MUST increment the CSeq header before resubmitting the
request. The signature MUST correspond to the From header of the
request unless the signed-by parameter is provided.
pgp-signature: The PGP ASCII-armored signature [33], as it appears
between the "BEGIN PGP MESSAGE" and "END PGP MESSAGE"
delimiters, without the version indication. The signature is
included without any linebreaks.
The signature is computed across the nonce (if present), request
method, request version and header fields following the Authorization
header and the message body, in the same order as they appear in the
message. The request method and version are prepended to the header
fields without any white space. The signature is computed across the
headers as sent, and the terminating CRLF. The CRLF following the
Authorization header is NOT included in the signature.
A server MAY be configured not to generate nonces only if replay
attacks are not a concern.
Not generating nonces avoids the additional set of request,
401 response and possibly ACK messages and reduces delay by
one round-trip time.
Using the ASCII-armored version is about 25% less space-
efficient than including the binary signature, but it is
significantly easier for the receiver to piece together.
Versions of the PGP program always include the full
(compressed) signed text in their output unless ASCII-
armored mode ( -sta ) is specified. Typical signatures are
about 200 bytes long. -- The PGP signature mechanism allows
the client to simply pass the request to an external PGP
program. This relies on the requirement that proxy servers
are not allowed to reorder or change header fields.
realm: The realm is copied from the corresponding WWW-Authenticate
header field parameter.
signed-by: If and only if the request was not signed by the entity
listed in the From header, the signed-by header indicates the
name of the signing entity, expressed as a URI.
Receivers of signed SIP messages SHOULD discard any end-to-end header
fields above the Authorization header, as they may have been
maliciously added en route by a proxy.
Example:
Authorization: pgp version="5.0"
;realm="Your Startrek identity, please"
;nonce="913082051"
;signature="iQB1AwUBNNJiUaYBnHmiiQh1AQFYsgL/Wt3dk6TWK81/b0gcNDf
VAUGU4rhEBW972IPxFSOZ94L1qhCLInTPaqhHFw1cb3lB01rA0RhpV4t5yCdUt
SRYBSkOK29o5e1KlFeW23EzYPVUm2TlDAhbcjbMdfC+KLFX
=aIrx"
15.2 PGP Encryption Scheme
The PGP encryption scheme uses the following syntax:
Encryption = "Encryption" ":" "pgp" pgp-eparams
pgp-eparams = 1# ( pgp-version | pgp-encoding )
pgp-encoding = "encoding" "=" "ascii" | token
encoding: Describes the encoding or "armor" used by PGP. The value
"ascii" refers to the standard PGP ASCII armor, without the
lines containing "BEGIN PGP MESSAGE" and "END PGP MESSAGE" and
without the version identifier. By default, the encrypted part
is included as binary.
Example:
Encryption: pgp version="2.6.2", encoding="ascii"
15.3 Response-Key Header Field for PGP
Response-Key = "Response-Key" ":" "pgp" pgp-eparams
pgp-eparams = 1# ( pgp-version | pgp-encoding | pgp-key)
pgp-key = "key" "=" quoted-string
If ASCII encoding has been requested via the encoding parameter, the
key parameter contains the user's public key as extracted from the
pgp key ring with the "pgp -kxa user ".
Example:
Response-Key: pgp version="2.6.2", encoding="ascii",
key="mQBtAzNWHNYAAAEDAL7QvAdK2utY05wuUG+ItYK5tCF8HNJM60sU4rLaV+eUnkMk
mOmJWtc2wXcZx1XaXb2lkydTQOesrUR75IwNXBuZXPEIMThEa5WLsT7VLme7njnx
sE86SgWmAZx5ookIdQAFEbQxSGVubmluZyBTY2h1bHpyaW5uZSA8c2NodWx6cmlu
bmVAY3MuY29sdW1iaWEuZWR1Pg==
=+y19"
16 Examples
In the following examples, we often omit the message body and the
corresponding Content-Length and Content-Type headers for brevity.
16.1 Registration
A user at host saturn.bell-tel.com registers on start-up, via
multicast, with the local SIP server named bell-tel.com. In the
example, the user agent on saturn expects to receive SIP requests on
UDP port 3890.
C->S: REGISTER sip:bell-tel.com SIP/2.0
Via: SIP/2.0/UDP saturn.bell-tel.com
From: sip:watson@bell-tel.com
To: sip:watson@bell-tel.com
Call-ID: 70710@saturn.bell-tel.com
CSeq: 1 REGISTER
Contact: <sip:watson@saturn.bell-tel.com:3890;transport=udp>
Expires: 7200
The registration expires after two hours. Any future invitations for
watson@bell-tel.com arriving at sip.bell-tel.com will now be
redirected to watson@saturn.bell-tel.com, UDP port 3890.
If Watson wants to be reached elsewhere, say, an on-line service he
uses while traveling, he updates his reservation after first
cancelling any existing locations:
C->S: REGISTER sip:bell-tel.com SIP/2.0
Via: SIP/2.0/UDP saturn.bell-tel.com
From: sip:watson@bell-tel.com
To: sip:watson@bell-tel.com
Call-ID: 70710@saturn.bell-tel.com
CSeq: 2 REGISTER
Contact: *
Expires: 0
C->S: REGISTER sip:bell-tel.com SIP/2.0
Via: SIP/2.0/UDP saturn.bell-tel.com