Initial import from FreeBSD RELENG_4:
[dragonfly.git] / lib / libc / rpc / PSD.doc / rpc.rfc.ms
1 .\"
2 .\" Must use  --  tbl  --  with this one
3 .\"
4 .\" @(#)rpc.rfc.ms      2.2 88/08/05 4.0 RPCSRC
5 .\" $FreeBSD: src/lib/libc/rpc/PSD.doc/rpc.rfc.ms,v 1.1.14.1 2000/11/24 09:36:30 ru Exp $
6 .\"
7 .so stubs
8 .de BT
9 .if \\n%=1 .tl ''- % -''
10 ..
11 .ND
12 .\" prevent excess underlining in nroff
13 .if n .fp 2 R
14 .OH 'Remote Procedure Calls: Protocol Specification''Page %'
15 .EH 'Page %''Remote Procedure Calls: Protocol Specification'
16 .if \n%=1 .bp
17 .SH
18 \&Remote Procedure Calls: Protocol Specification
19 .LP
20 .NH 0
21 \&Status of this Memo
22 .LP
23 Note: This chapter specifies a protocol that Sun Microsystems, Inc.,
24 and others are using.  
25 It has been designated RFC1050 by the ARPA Network
26 Information Center.
27 .LP
28 .NH 1
29 \&Introduction
30 .LP
31 This chapter specifies  a  message protocol  used in implementing
32 Sun's Remote Procedure Call (RPC) package.  (The message protocol is
33 specified with the External Data Representation (XDR) language.
34 See the
35 .I "External Data Representation Standard: Protocol Specification"
36 for the details.  Here, we assume that  the  reader is familiar  
37 with XDR and do not attempt to justify it or its uses).  The paper
38 by Birrell and Nelson [1]  is recommended as an  excellent background
39 to  and justification of RPC.
40 .NH 2
41 \&Terminology
42 .LP
43 This chapter discusses servers, services, programs, procedures,
44 clients, and versions.  A server is a piece of software where network
45 services are implemented.  A network service is a collection of one
46 or more remote programs.  A remote program implements one or more
47 remote procedures; the procedures, their parameters, and results are
48 documented in the specific program's protocol specification (see the
49 \fIPort Mapper Program Protocol\fP\, below, for an example).  Network
50 clients are pieces of software that initiate remote procedure calls
51 to services.  A server may support more than one version of a remote
52 program in order to be forward compatible with changing protocols.
53 .LP
54 For example, a network file service may be composed of two programs.
55 One program may deal with high-level applications such as file system
56 access control and locking.  The other may deal with low-level file
57 IO and have procedures like "read" and "write".  A client machine of
58 the network file service would call the procedures associated with
59 the two programs of the service on behalf of some user on the client
60 machine.
61 .NH 2
62 \&The RPC Model
63 .LP
64 The remote procedure call model is similar to the local procedure
65 call model.  In the local case, the caller places arguments to a
66 procedure in some well-specified location (such as a result
67 register).  It then transfers control to the procedure, and
68 eventually gains back control.  At that point, the results of the
69 procedure are extracted from the well-specified location, and the
70 caller continues execution.
71 .LP
72 The remote procedure call is similar, in that one thread of control
73 logically winds through two processes\(emone is the caller's process,
74 the other is a server's process.  That is, the caller process sends a
75 call message to the server process and waits (blocks) for a reply
76 message.  The call message contains the procedure's parameters, among
77 other things.  The reply message contains the procedure's results,
78 among other things.  Once the reply message is received, the results
79 of the procedure are extracted, and caller's execution is resumed.
80 .LP
81 On the server side, a process is dormant awaiting the arrival of a
82 call message.  When one arrives, the server process extracts the
83 procedure's parameters, computes the results, sends a reply message,
84 and then awaits the next call message.
85 .LP
86 Note that in this model, only one of the two processes is active at
87 any given time.  However, this model is only given as an example.
88 The RPC protocol makes no restrictions on the concurrency model
89 implemented, and others are possible.  For example, an implementation
90 may choose to have RPC calls be asynchronous, so that the client may
91 do useful work while waiting for the reply from the server.  Another
92 possibility is to have the server create a task to process an
93 incoming request, so that the server can be free to receive other
94 requests.
95 .NH 2
96 \&Transports and Semantics
97 .LP
98 The RPC protocol is independent of transport protocols.  That is, RPC
99 does not care how a message is passed from one process to another.
100 The protocol deals only with specification and interpretation of
101 messages.
102 .LP
103 It is important to point out that RPC does not try to implement any
104 kind of reliability and that the application must be aware of the
105 type of transport protocol underneath RPC.  If it knows it is running
106 on top of a reliable transport such as TCP/IP[6], then most of the
107 work is already done for it.  On the other hand, if it is running on
108 top of an unreliable transport such as UDP/IP[7], it must implement
109 is own retransmission and time-out policy as the RPC layer does not
110 provide this service.
111 .LP
112 Because of transport independence, the RPC protocol does not attach
113 specific semantics to the remote procedures or their execution.
114 Semantics can be inferred from (but should be explicitly specified
115 by) the underlying transport protocol.  For example, consider RPC
116 running on top of an unreliable transport such as UDP/IP.  If an
117 application retransmits RPC messages after short time-outs, the only
118 thing it can infer if it receives no reply is that the procedure was
119 executed zero or more times.  If it does receive a reply, then it can
120 infer that the procedure was executed at least once.
121 .LP
122 A server may wish to remember previously granted requests from a
123 client and not regrant them in order to insure some degree of
124 execute-at-most-once semantics.  A server can do this by taking
125 advantage of the transaction ID that is packaged with every RPC
126 request.  The main use of this transaction is by the client RPC layer
127 in matching replies to requests.  However, a client application may
128 choose to reuse its previous transaction ID when retransmitting a
129 request.  The server application, knowing this fact, may choose to
130 remember this ID after granting a request and not regrant requests
131 with the same ID in order to achieve some degree of
132 execute-at-most-once semantics.  The server is not allowed to examine
133 this ID in any other way except as a test for equality.
134 .LP
135 On the other hand, if using a reliable transport such as TCP/IP, the
136 application can infer from a reply message that the procedure was
137 executed exactly once, but if it receives no reply message, it cannot
138 assume the remote procedure was not executed.  Note that even if a
139 connection-oriented protocol like TCP is used, an application still
140 needs time-outs and reconnection to handle server crashes.
141 .LP
142 There are other possibilities for transports besides datagram- or
143 connection-oriented protocols.  For example, a request-reply protocol
144 such as VMTP[2] is perhaps the most natural transport for RPC.
145 .SH
146 .I
147 NOTE:  At Sun, RPC is currently implemented on top of both TCP/IP
148 and UDP/IP transports.
149 .LP
150 .NH 2
151 \&Binding and Rendezvous Independence
152 .LP
153 The act of binding a client to a service is NOT part of the remote
154 procedure call specification.  This important and necessary function
155 is left up to some higher-level software.  (The software may use RPC
156 itself\(emsee the \fIPort Mapper Program Protocol\fP\, below).
157 .LP
158 Implementors should think of the RPC protocol as the jump-subroutine
159 instruction ("JSR") of a network; the loader (binder) makes JSR
160 useful, and the loader itself uses JSR to accomplish its task.
161 Likewise, the network makes RPC useful, using RPC to accomplish this
162 task.
163 .NH 2
164 \&Authentication
165 .LP
166 The RPC protocol provides the fields necessary for a client to
167 identify itself to a service and vice-versa.  Security and access
168 control mechanisms can be built on top of the message authentication.
169 Several different authentication protocols can be supported.  A field
170 in the RPC header indicates which protocol is being used.  More
171 information on specific authentication protocols can be found in the
172 \fIAuthentication Protocols\fP\,
173 below.
174 .KS
175 .NH 1
176 \&RPC Protocol Requirements
177 .LP
178 The RPC protocol must provide for the following:
179 .IP  1.
180 Unique specification of a procedure to be called.
181 .IP  2.
182 Provisions for matching response messages to request messages.
183 .KE
184 .IP  3.
185 Provisions for authenticating the caller to service and vice-versa.
186 .LP
187 Besides these requirements, features that detect the following are
188 worth supporting because of protocol roll-over errors, implementation
189 bugs, user error, and network administration:
190 .IP  1.
191 RPC protocol mismatches.
192 .IP  2.
193 Remote program protocol version mismatches.
194 .IP  3.
195 Protocol errors (such as misspecification of a procedure's parameters).
196 .IP  4.
197 Reasons why remote authentication failed.
198 .IP  5.
199 Any other reasons why the desired procedure was not called.
200 .NH 2
201 \&Programs and Procedures
202 .LP
203 The RPC call message has three unsigned fields:  remote program
204 number, remote program version number, and remote procedure number.
205 The three fields uniquely identify the procedure to be called.
206 Program numbers are administered by some central authority (like
207 Sun).  Once an implementor has a program number, he can implement his
208 remote program; the first implementation would most likely have the
209 version number of 1.  Because most new protocols evolve into better,
210 stable, and mature protocols, a version field of the call message
211 identifies which version of the protocol the caller is using.
212 Version numbers make speaking old and new protocols through the same
213 server process possible.
214 .LP
215 The procedure number identifies the procedure to be called.  These
216 numbers are documented in the specific program's protocol
217 specification.  For example, a file service's protocol specification
218 may state that its procedure number 5 is "read" and procedure number
219 12 is "write".
220 .LP
221 Just as remote program protocols may change over several versions,
222 the actual RPC message protocol could also change.  Therefore, the
223 call message also has in it the RPC version number, which is always
224 equal to two for the version of RPC described here.
225 .LP
226 The reply message to a request  message  has enough  information to
227 distinguish the following error conditions:
228 .IP  1.
229 The remote implementation of RPC does speak protocol version 2.
230 The lowest and highest supported RPC version numbers are returned.
231 .IP  2.
232 The remote program is not available on the remote system.
233 .IP  3.
234 The remote program does not support the requested version number.
235 The lowest and highest supported remote program version numbers are
236 returned.
237 .IP  4.
238 The requested procedure number does not exist.  (This is usually a
239 caller side protocol or programming error.)
240 .IP  5.
241 The parameters to the remote procedure appear to be garbage from the
242 server's point of view.  (Again, this is usually caused by a
243 disagreement about the protocol between client and service.)
244 .NH 2
245 \&Authentication
246 .LP
247 Provisions for authentication of caller to service and vice-versa are
248 provided as a part of the RPC protocol.  The call message has two
249 authentication fields, the credentials and verifier.  The reply
250 message has one authentication field, the response verifier.  The RPC
251 protocol specification defines all three fields to be the following
252 opaque type:
253 .DS
254 .ft CW
255 .vs 11
256 enum auth_flavor {
257     AUTH_NULL        = 0,
258     AUTH_UNIX        = 1,
259     AUTH_SHORT       = 2,
260     AUTH_DES         = 3
261     /* \fIand more to be defined\fP */
262 };
263
264 struct opaque_auth {
265     auth_flavor flavor;
266     opaque body<400>;
267 };
268 .DE
269 .LP
270 In simple English, any
271 .I opaque_auth 
272 structure is an 
273 .I auth_flavor 
274 enumeration followed by bytes which are  opaque to the RPC protocol
275 implementation.
276 .LP
277 The interpretation and semantics  of the data contained  within the
278 authentication   fields  is specified  by  individual,  independent
279 authentication  protocol specifications.   (See 
280 \fIAuthentication Protocols\fP\,
281 below, for definitions of the various authentication protocols.)
282 .LP
283 If authentication parameters were   rejected, the  response message
284 contains information stating why they were rejected.
285 .NH 2
286 \&Program Number Assignment
287 .LP
288 Program numbers are given out in groups of
289 .I 0x20000000 
290 (decimal 536870912) according to the following chart:
291 .TS
292 box tab (&) ;
293 lfI lfI
294 rfL cfI .
295 Program Numbers&Description
296 _
297 .sp .5
298 0 - 1fffffff&Defined by Sun
299 20000000 - 3fffffff&Defined by user
300 40000000 - 5fffffff&Transient
301 60000000 - 7fffffff&Reserved
302 80000000 - 9fffffff&Reserved
303 a0000000 - bfffffff&Reserved
304 c0000000 - dfffffff&Reserved
305 e0000000 - ffffffff&Reserved
306 .TE
307 .LP
308 The first group is a range of numbers administered by Sun
309 Microsystems and should be identical for all sites.  The second range
310 is for applications peculiar to a particular site.  This range is
311 intended primarily for debugging new programs.  When a site develops
312 an application that might be of general interest, that application
313 should be given an assigned number in the first range.  The third
314 group is for applications that generate program numbers dynamically.
315 The final groups are reserved for future use, and should not be used.
316 .NH 2
317 \&Other Uses of the RPC Protocol
318 .LP
319 The intended use of this protocol is for calling remote procedures.
320 That is, each call message is matched with a response message.
321 However, the protocol itself is a message-passing protocol with which
322 other (non-RPC) protocols can be implemented.  Sun currently uses, or
323 perhaps abuses, the RPC message protocol for the following two
324 (non-RPC) protocols:  batching (or pipelining) and broadcast RPC.
325 These two protocols are discussed but not defined below.
326 .NH 3
327 \&Batching
328 .LP
329 Batching allows a client to send an arbitrarily large sequence of
330 call messages to a server; batching typically uses reliable byte
331 stream protocols (like TCP/IP) for its transport.  In the case of
332 batching, the client never waits for a reply from the server, and the
333 server does not send replies to batch requests.  A sequence of batch
334 calls is usually terminated by a legitimate RPC in order to flush the
335 pipeline (with positive acknowledgement).
336 .NH 3
337 \&Broadcast RPC
338 .LP
339 In broadcast RPC-based protocols, the client sends a broadcast packet
340 to the network and waits for numerous replies.  Broadcast RPC uses
341 unreliable, packet-based protocols (like UDP/IP) as its transports.
342 Servers that support broadcast protocols only respond when the
343 request is successfully processed, and are silent in the face of
344 errors.  Broadcast RPC uses the Port Mapper RPC service to achieve
345 its semantics.  See the \fIPort Mapper Program Protocol\fP\, below,
346 for more information.
347 .KS
348 .NH 1
349 \&The RPC Message Protocol
350 .LP
351 This section defines the RPC message protocol in the XDR data
352 description language.  The message is defined in a top-down style.
353 .ie t .DS
354 .el .DS L
355 .ft CW
356 enum msg_type {
357         CALL  = 0,
358         REPLY = 1
359 };
360
361 .ft I
362 /*
363 * A reply to a call message can take on two forms:
364 * The message was either accepted or rejected.
365 */
366 .ft CW
367 enum reply_stat {
368         MSG_ACCEPTED = 0,
369         MSG_DENIED   = 1
370 };
371
372 .ft I
373 /*
374 * Given that a call message was accepted,  the following is the
375 * status of an attempt to call a remote procedure.
376 */
377 .ft CW
378 enum accept_stat {
379         SUCCESS       = 0, /* \fIRPC executed successfully       \fP*/
380         PROG_UNAVAIL  = 1, /* \fIremote hasn't exported program  \fP*/
381         PROG_MISMATCH = 2, /* \fIremote can't support version #  \fP*/
382         PROC_UNAVAIL  = 3, /* \fIprogram can't support procedure \fP*/
383         GARBAGE_ARGS  = 4  /* \fIprocedure can't decode params   \fP*/
384 };
385 .DE
386 .ie t .DS
387 .el .DS L
388 .ft I
389 /*
390 * Reasons why a call message was rejected:
391 */
392 .ft CW
393 enum reject_stat {
394         RPC_MISMATCH = 0, /* \fIRPC version number != 2          \fP*/
395         AUTH_ERROR = 1    /* \fIremote can't authenticate caller \fP*/
396 };
397
398 .ft I
399 /*
400 * Why authentication failed:
401 */
402 .ft CW
403 enum auth_stat {
404         AUTH_BADCRED      = 1,  /* \fIbad credentials \fP*/
405         AUTH_REJECTEDCRED = 2,  /* \fIclient must begin new session \fP*/
406         AUTH_BADVERF      = 3,  /* \fIbad verifier \fP*/
407         AUTH_REJECTEDVERF = 4,  /* \fIverifier expired or replayed  \fP*/
408         AUTH_TOOWEAK      = 5   /* \fIrejected for security reasons \fP*/
409 };
410 .DE
411 .KE
412 .ie t .DS
413 .el .DS L
414 .ft I
415 /*
416 * The  RPC  message: 
417 * All   messages  start with   a transaction  identifier,  xid,
418 * followed  by a  two-armed  discriminated union.   The union's
419 * discriminant is a  msg_type which switches to  one of the two
420 * types   of the message.   The xid  of a \fIREPLY\fP  message always
421 * matches  that of the initiating \fICALL\fP   message.   NB: The xid
422 * field is only  used for clients  matching reply messages with
423 * call messages  or for servers detecting  retransmissions; the
424 * service side  cannot treat this id  as any type   of sequence
425 * number.
426 */
427 .ft CW
428 struct rpc_msg {
429         unsigned int xid;
430         union switch (msg_type mtype) {
431                 case CALL:
432                         call_body cbody;
433                 case REPLY:  
434                         reply_body rbody;
435         } body;
436 };
437 .DE
438 .ie t .DS
439 .el .DS L
440 .ft I
441 /*
442 * Body of an RPC request call: 
443 * In version 2 of the  RPC protocol specification, rpcvers must
444 * be equal to 2.  The  fields prog,  vers, and proc specify the
445 * remote program, its version number, and the  procedure within
446 * the remote program to be called.  After these  fields are two
447 * authentication  parameters: cred (authentication credentials)
448 * and verf  (authentication verifier).  The  two authentication
449 * parameters are   followed by  the  parameters  to  the remote
450 * procedure,  which  are specified  by  the  specific   program
451 * protocol.
452 */
453 .ft CW
454 struct call_body {
455         unsigned int rpcvers;  /* \fImust be equal to two (2) \fP*/
456         unsigned int prog;
457         unsigned int vers;
458         unsigned int proc;
459         opaque_auth cred;
460         opaque_auth verf;
461         /* \fIprocedure specific parameters start here \fP*/
462 };
463 .DE
464 .ie t .DS
465 .el .DS L
466 .ft I
467 /*
468 * Body of a reply to an RPC request:
469 * The call message was either accepted or rejected.
470 */
471 .ft CW
472 union reply_body switch (reply_stat stat) {
473         case MSG_ACCEPTED:  
474                 accepted_reply areply;
475         case MSG_DENIED:  
476                 rejected_reply rreply;
477 } reply;
478 .DE
479 .ie t .DS
480 .el .DS L
481 .ft I
482 /*
483 * Reply to   an RPC request  that  was accepted  by the server:
484 * there could be an error even though the request was accepted.
485 * The first field is an authentication verifier that the server
486 * generates in order to  validate itself  to the caller.  It is
487 * followed by    a  union whose     discriminant  is   an  enum
488 * accept_stat.  The  \fISUCCESS\fP  arm of    the union  is  protocol
489 * specific.  The \fIPROG_UNAVAIL\fP, \fIPROC_UNAVAIL\fP, and \fIGARBAGE_ARGP\fP
490 * arms of the union are void.   The \fIPROG_MISMATCH\fP arm specifies
491 * the lowest and highest version numbers of the  remote program
492 * supported by the server.
493 */
494 .ft CW
495 struct accepted_reply {
496         opaque_auth verf;
497         union switch (accept_stat stat) {
498                 case SUCCESS:
499                         opaque results[0];
500                         /* \fIprocedure-specific results start here\fP */
501                 case PROG_MISMATCH:
502                         struct {
503                                 unsigned int low;
504                                 unsigned int high;
505                         } mismatch_info;
506                 default:
507 .ft I
508                         /*
509                         * Void.  Cases include \fIPROG_UNAVAIL, PROC_UNAVAIL\fP,
510                         * and \fIGARBAGE_ARGS\fP.
511                         */
512 .ft CW
513                         void;
514         } reply_data;
515 };
516 .DE
517 .ie t .DS
518 .el .DS L
519 .ft I
520 /*
521 * Reply to an RPC request that was rejected by the server: 
522 * The request  can   be rejected for   two reasons:  either the
523 * server   is not  running a   compatible  version  of the  RPC
524 * protocol    (\fIRPC_MISMATCH\fP), or    the  server   refuses    to
525 * authenticate the  caller  (\fIAUTH_ERROR\fP).  In  case of  an  RPC
526 * version mismatch,  the server returns the  lowest and highest
527 * supported    RPC  version    numbers.  In   case   of refused
528 * authentication, failure status is returned.
529 */
530 .ft CW
531 union rejected_reply switch (reject_stat stat) {
532         case RPC_MISMATCH:
533                 struct {
534                         unsigned int low;
535                         unsigned int high;
536                 } mismatch_info;
537         case AUTH_ERROR: 
538                 auth_stat stat;
539 };
540 .DE
541 .NH 1
542 \&Authentication Protocols
543 .LP
544 As previously stated, authentication parameters are opaque, but
545 open-ended to the rest of the RPC protocol.  This section defines
546 some "flavors" of authentication implemented at (and supported by)
547 Sun.  Other sites are free to invent new authentication types, with
548 the same rules of flavor number assignment as there is for program
549 number assignment.
550 .NH 2
551 \&Null Authentication
552 .LP
553 Often calls must be made where the caller does not know who he is or
554 the server does not care who the caller is.  In this case, the flavor
555 value (the discriminant of the \fIopaque_auth\fP's union) of the RPC
556 message's credentials, verifier, and response verifier is
557 .I AUTH_NULL .
558 The  bytes of the opaque_auth's body  are undefined.
559 It is recommended that the opaque length be zero.
560 .NH 2
561 \&UNIX Authentication
562 .LP
563 The caller of a remote procedure may wish to identify himself as he
564 is identified on a UNIX system.  The  value of the credential's
565 discriminant of an RPC call  message is  
566 .I AUTH_UNIX .
567 The bytes of
568 the credential's opaque body encode the following structure:
569 .DS
570 .ft CW
571 struct auth_unix {
572         unsigned int stamp;
573         string machinename<255>;
574         unsigned int uid;
575         unsigned int gid;
576         unsigned int gids<10>;
577 };
578 .DE
579 The 
580 .I stamp 
581 is an  arbitrary    ID which the  caller machine   may
582 generate.  The 
583 .I machinename 
584 is the  name of the  caller's machine (like  "krypton").  The 
585 .I uid 
586 is  the caller's effective user  ID.  The  
587 .I gid 
588 is  the caller's effective  group  ID.  The 
589 .I gids 
590 is  a
591 counted array of groups which contain the caller as  a member.  The
592 verifier accompanying the  credentials  should  be  of  
593 .I AUTH_NULL
594 (defined above).
595 .LP
596 The value of the discriminant of  the response verifier received in
597 the  reply  message  from  the    server  may   be   
598 .I AUTH_NULL 
599 or
600 .I AUTH_SHORT .
601 In  the  case  of 
602 .I AUTH_SHORT ,
603 the bytes of the response verifier's string encode an opaque
604 structure.  This new opaque structure may now be passed to the server
605 instead of the original
606 .I AUTH_UNIX
607 flavor credentials.  The server keeps a cache which maps shorthand
608 opaque structures (passed back by way of an
609 .I AUTH_SHORT
610 style response verifier) to the original credentials of the caller.
611 The caller can save network bandwidth and server cpu cycles by using
612 the new credentials.
613 .LP
614 The server may flush the shorthand opaque structure at any time.  If
615 this happens, the remote procedure call message will be rejected due
616 to an authentication error.  The reason for the failure will be
617 .I AUTH_REJECTEDCRED .
618 At this point, the caller may wish to try the original
619 .I AUTH_UNIX
620 style of credentials.
621 .KS
622 .NH 2
623 \&DES Authentication
624 .LP
625 UNIX authentication suffers from two major problems:
626 .IP  1.
627 The naming is too UNIX-system oriented.
628 .IP  2.
629 There is no verifier, so credentials can easily be faked.
630 .LP
631 DES authentication attempts to fix these two problems.
632 .KE
633 .NH 3
634 \&Naming
635 .LP
636 The first problem is handled by addressing the caller by a simple
637 string of characters instead of by an operating system specific
638 integer.  This string of characters is known as the "netname" or
639 network name of the caller.  The server is not allowed to interpret
640 the contents of the caller's name in any other way except to
641 identify the caller.  Thus, netnames should be unique for every
642 caller in the internet.
643 .LP
644 It is up to each operating system's implementation of DES
645 authentication to generate netnames for its users that insure this
646 uniqueness when they call upon remote servers.  Operating systems
647 already know how to distinguish users local to their systems.  It is
648 usually a simple matter to extend this mechanism to the network.
649 For example, a UNIX user at Sun with a user ID of 515 might be
650 assigned the following netname: "unix.515@sun.com".  This netname
651 contains three items that serve to insure it is unique.  Going
652 backwards, there is only one naming domain called "sun.com" in the
653 internet.  Within this domain, there is only one UNIX user with
654 user ID 515.  However, there may be another user on another
655 operating system, for example VMS, within the same naming domain
656 that, by coincidence, happens to have the same user ID.  To insure
657 that these two users can be distinguished we add the operating
658 system name.  So one user is "unix.515@sun.com" and the other is
659 "vms.515@sun.com".
660 .LP
661 The first field is actually a naming method rather than an
662 operating system name.  It just happens that today there is almost
663 a one-to-one correspondence between naming methods and operating
664 systems.  If the world could agree on a naming standard, the first
665 field could be the name of that standard, instead of an operating
666 system name.
667 .LP
668 .NH 3
669 \&DES Authentication Verifiers
670 .LP
671 Unlike UNIX authentication, DES authentication does have a verifier
672 so the server can validate the client's credential (and
673 vice-versa).  The contents of this verifier is primarily an
674 encrypted timestamp.  The server can decrypt this timestamp, and if
675 it is close to what the real time is, then the client must have
676 encrypted it correctly.  The only way the client could encrypt it
677 correctly is to know the "conversation key" of the RPC session.  And
678 if the client knows the conversation key, then it must be the real
679 client.
680 .LP
681 The conversation key is a DES [5] key which the client generates
682 and notifies the server of in its first RPC call.  The conversation
683 key is encrypted using a public key scheme in this first
684 transaction.  The particular public key scheme used in DES
685 authentication is Diffie-Hellman [3] with 192-bit keys.  The
686 details of this encryption method are described later.
687 .LP
688 The client and the server need the same notion of the current time
689 in order for all of this to work.  If network time synchronization
690 cannot be guaranteed, then client can synchronize with the server
691 before beginning the conversation, perhaps by consulting the
692 Internet Time Server (TIME[4]).
693 .LP
694 The way a server determines if a client timestamp is valid is
695 somewhat complicated.  For any other transaction but the first, the
696 server just checks for two things:
697 .IP  1.
698 the timestamp is greater than the one previously seen from the
699 same client.
700 .IP  2.
701 the timestamp has not expired.
702 .LP
703 A timestamp is expired if the server's time is later than the sum
704 of the client's timestamp plus what is known as the client's
705 "window".  The "window" is a number the client passes (encrypted)
706 to the server in its first transaction.  You can think of it as a
707 lifetime for the credential.
708 .LP
709 This explains everything but the first transaction.  In the first
710 transaction, the server checks only that the timestamp has not
711 expired.  If this was all that was done though, then it would be
712 quite easy for the client to send random data in place of the
713 timestamp with a fairly good chance of succeeding.  As an added
714 check, the client sends an encrypted item in the first transaction
715 known as the "window verifier" which must be equal to the window
716 minus 1, or the server will reject the credential.
717 .LP
718 The client too must check the verifier returned from the server to
719 be sure it is legitimate.  The server sends back to the client the
720 encrypted timestamp it received from the client, minus one second.
721 If the client gets anything different than this, it will reject it.
722 .LP
723 .NH 3
724 \&Nicknames and Clock Synchronization
725 .LP
726 After the first transaction, the server's DES authentication
727 subsystem returns in its verifier to the client an integer
728 "nickname" which the client may use in its further transactions
729 instead of passing its netname, encrypted DES key and window every
730 time.  The nickname is most likely an index into a table on the
731 server which stores for each client its netname, decrypted DES key
732 and window.
733 .LP
734 Though they originally were synchronized, the client's and server's
735 clocks can get out of sync again.  When this happens the client RPC
736 subsystem most likely will get back
737 .I RPC_AUTHERROR 
738 at which point it should resynchronize.
739 .LP
740 A client may still get the
741 .I RPC_AUTHERROR 
742 error even though it is
743 synchronized with the server.  The reason is that the server's
744 nickname table is a limited size, and it may flush entries whenever
745 it wants.  A client should resend its original credential in this
746 case and the server will give it a new nickname.  If a server
747 crashes, the entire nickname table gets flushed, and all clients
748 will have to resend their original credentials.
749 .KS
750 .NH 3
751 \&DES Authentication Protocol (in XDR language)
752 .ie t .DS
753 .el .DS L
754 .ft I
755 /*
756 * There are two kinds of credentials: one in which the client uses
757 * its full network name, and one in which it uses its "nickname"
758 * (just an unsigned integer) given to it by the server.  The
759 * client must use its fullname in its first transaction with the
760 * server, in which the server will return to the client its
761 * nickname.  The client may use its nickname in all further
762 * transactions with the server.  There is no requirement to use the
763 * nickname, but it is wise to use it for performance reasons.
764 */
765 .ft CW
766 enum authdes_namekind {
767         ADN_FULLNAME = 0,
768         ADN_NICKNAME = 1
769 };
770
771 .ft I
772 /*
773 * A 64-bit block of encrypted DES data
774 */
775 .ft CW
776 typedef opaque des_block[8];
777
778 .ft I
779 /*
780 * Maximum length of a network user's name
781 */
782 .ft CW
783 const MAXNETNAMELEN = 255;
784
785 .ft I
786 /*
787 * A fullname contains the network name of the client, an encrypted
788 * conversation key and the window.  The window is actually a
789 * lifetime for the credential.  If the time indicated in the
790 * verifier timestamp plus the window has past, then the server
791 * should expire the request and not grant it.  To insure that
792 * requests are not replayed, the server should insist that
793 * timestamps are greater than the previous one seen, unless it is
794 * the first transaction.  In the first transaction, the server
795 * checks instead that the window verifier is one less than the
796 * window.
797 */
798 .ft CW
799 struct authdes_fullname {
800 string name<MAXNETNAMELEN>;  /* \fIname of client \f(CW*/
801 des_block key;               /* \fIPK encrypted conversation key \f(CW*/
802 unsigned int window;         /* \fIencrypted window \f(CW*/
803 };
804
805 .ft I
806 /*
807 * A credential is either a fullname or a nickname
808 */
809 .ft CW
810 union authdes_cred switch (authdes_namekind adc_namekind) {
811         case ADN_FULLNAME:
812                 authdes_fullname adc_fullname;
813         case ADN_NICKNAME:
814                 unsigned int adc_nickname;
815 };
816
817 .ft I
818 /*
819 * A timestamp encodes the time since midnight, January 1, 1970.
820 */
821 .ft CW
822 struct timestamp {
823         unsigned int seconds;    /* \fIseconds \fP*/
824         unsigned int useconds;   /* \fIand microseconds \fP*/
825 };
826
827 .ft I
828 /*
829 * Verifier: client variety
830 * The window verifier is only used in the first transaction.  In
831 * conjunction with a fullname credential, these items are packed
832 * into the following structure before being encrypted:
833 *
834 * \f(CWstruct {\fP
835 *     \f(CWadv_timestamp;            \fP-- one DES block
836 *     \f(CWadc_fullname.window;      \fP-- one half DES block
837 *     \f(CWadv_winverf;              \fP-- one half DES block
838 * \f(CW}\fP
839 * This structure is encrypted using CBC mode encryption with an
840 * input vector of zero.  All other encryptions of timestamps use
841 * ECB mode encryption.
842 */
843 .ft CW
844 struct authdes_verf_clnt {
845         timestamp adv_timestamp;    /* \fIencrypted timestamp       \fP*/
846         unsigned int adv_winverf;   /* \fIencrypted window verifier \fP*/
847 };
848
849 .ft I
850 /*
851 * Verifier: server variety
852 * The server returns (encrypted) the same timestamp the client
853 * gave it minus one second.  It also tells the client its nickname
854 * to be used in future transactions (unencrypted).
855 */
856 .ft CW
857 struct authdes_verf_svr {
858 timestamp adv_timeverf;     /* \fIencrypted verifier      \fP*/
859 unsigned int adv_nickname;  /* \fInew nickname for client \fP*/
860 };
861 .DE
862 .KE
863 .NH 3
864 \&Diffie-Hellman Encryption
865 .LP
866 In this scheme, there are two constants,
867 .I BASE 
868 and
869 .I MODULUS .
870 The
871 particular values Sun has chosen for these for the DES
872 authentication protocol are:
873 .ie t .DS
874 .el .DS L
875 .ft CW
876 const BASE = 3;
877 const MODULUS = 
878         "d4a0ba0250b6fd2ec626e7efd637df76c716e22d0944b88b"; /* \fIhex \fP*/
879 .DE
880 .ft R
881 The way this scheme works is best explained by an example.  Suppose
882 there are two people "A" and "B" who want to send encrypted
883 messages to each other.  So, A and B both generate "secret" keys at
884 random which they do not reveal to anyone.  Let these keys be
885 represented as SK(A) and SK(B).  They also publish in a public
886 directory their "public" keys.  These keys are computed as follows:
887 .ie t .DS
888 .el .DS L
889 .ft CW
890 PK(A) = ( BASE ** SK(A) ) mod MODULUS
891 PK(B) = ( BASE ** SK(B) ) mod MODULUS
892 .DE
893 .ft R
894 The "**" notation is used here to represent exponentiation.  Now,
895 both A and B can arrive at the "common" key between them,
896 represented here as CK(A, B), without revealing their secret keys.
897 .LP
898 A computes:
899 .ie t .DS
900 .el .DS L
901 .ft CW
902 CK(A, B) = ( PK(B) ** SK(A)) mod MODULUS
903 .DE
904 .ft R
905 while B computes:
906 .ie t .DS
907 .el .DS L
908 .ft CW
909 CK(A, B) = ( PK(A) ** SK(B)) mod MODULUS
910 .DE
911 .ft R
912 These two can be shown to be equivalent:
913 .ie t .DS
914 .el .DS L
915 .ft CW
916 (PK(B) ** SK(A)) mod MODULUS = (PK(A) ** SK(B)) mod MODULUS
917 .DE
918 .ft R
919 We drop the "mod MODULUS" parts and assume modulo arithmetic to
920 simplify things:
921 .ie t .DS
922 .el .DS L
923 .ft CW
924 PK(B) ** SK(A) = PK(A) ** SK(B)
925 .DE
926 .ft R
927 Then, replace PK(B) by what B computed earlier and likewise for
928 PK(A).
929 .ie t .DS
930 .el .DS L
931 .ft CW
932 ((BASE ** SK(B)) ** SK(A) = (BASE ** SK(A)) ** SK(B)
933 .DE
934 .ft R
935 which leads to:
936 .ie t .DS
937 .el .DS L
938 .ft CW
939 BASE ** (SK(A) * SK(B)) = BASE ** (SK(A) * SK(B))
940 .DE
941 .ft R
942 This common key CK(A, B) is not used to encrypt the timestamps used
943 in the protocol.  Rather, it is used only to encrypt a conversation
944 key which is then used to encrypt the timestamps.  The reason for
945 doing this is to use the common key as little as possible, for fear
946 that it could be broken.  Breaking the conversation key is a far
947 less serious offense, since conversations are relatively
948 short-lived.
949 .LP
950 The conversation key is encrypted using 56-bit DES keys, yet the
951 common key is 192 bits.  To reduce the number of bits, 56 bits are
952 selected from the common key as follows.  The middle-most 8-bytes
953 are selected from the common key, and then parity is added to the
954 lower order bit of each byte, producing a 56-bit key with 8 bits of
955 parity.
956 .KS
957 .NH 1
958 \&Record Marking Standard
959 .LP
960 When RPC messages are passed on top of a byte stream protocol (like
961 TCP/IP), it is necessary, or at least desirable, to delimit one
962 message from another in order to detect and possibly recover from
963 user protocol errors.  This is called record marking (RM).  Sun uses
964 this RM/TCP/IP transport for passing RPC messages on TCP streams.
965 One RPC message fits into one RM record.
966 .LP
967 A record is composed of one or more record fragments.  A record
968 fragment is a four-byte header followed by 0 to (2**31) - 1 bytes of
969 fragment data.  The bytes encode an unsigned binary number; as with
970 XDR integers, the byte order is from highest to lowest.  The number
971 encodes two values\(ema boolean which indicates whether the fragment
972 is the last fragment of the record (bit value 1 implies the fragment
973 is the last fragment) and a 31-bit unsigned binary value which is the
974 length in bytes of the fragment's data.  The boolean value is the
975 highest-order bit of the header; the length is the 31 low-order bits.
976 (Note that this record specification is NOT in XDR standard form!)
977 .KE
978 .KS
979 .NH 1
980 \&The RPC Language
981 .LP
982 Just as there was a need to describe the XDR data-types in a formal
983 language, there is also need to describe the procedures that operate
984 on these XDR data-types in a formal language as well.  We use the RPC
985 Language for this purpose.  It is an extension to the XDR language.
986 The following example is used to describe the essence of the
987 language.
988 .NH 2
989 \&An Example Service Described in the RPC Language
990 .LP
991 Here is an example of the specification of a simple ping program.
992 .ie t .DS
993 .el .DS L
994 .vs 11
995 .ft I
996 /*
997 * Simple ping program
998 */
999 .ft CW
1000 program PING_PROG {
1001         /* \fILatest and greatest version\fP */
1002         version PING_VERS_PINGBACK {
1003         void 
1004         PINGPROC_NULL(void) = 0;
1005
1006 .ft I
1007         /*
1008         * Ping the caller, return the round-trip time
1009         * (in microseconds). Returns -1 if the operation
1010         * timed out.
1011         */
1012 .ft CW
1013         int
1014         PINGPROC_PINGBACK(void) = 1;        
1015 } = 2;     
1016
1017 .ft I
1018 /*
1019 * Original version
1020 */
1021 .ft CW
1022 version PING_VERS_ORIG {
1023         void 
1024         PINGPROC_NULL(void) = 0;
1025         } = 1;
1026 } = 1;
1027
1028 const PING_VERS = 2;      /* \fIlatest version \fP*/
1029 .vs
1030 .DE
1031 .KE
1032 .LP
1033 The first version described is
1034 .I PING_VERS_PINGBACK
1035 with  two procedures,   
1036 .I PINGPROC_NULL 
1037 and 
1038 .I PINGPROC_PINGBACK .
1039 .I PINGPROC_NULL 
1040 takes no arguments and returns no results, but it is useful for
1041 computing round-trip times from the client to the server and back
1042 again.  By convention, procedure 0 of any RPC protocol should have
1043 the same semantics, and never require any kind of authentication.
1044 The second procedure is used for the client to have the server do a
1045 reverse ping operation back to the client, and it returns the amount
1046 of time (in microseconds) that the operation used.  The next version,
1047 .I PING_VERS_ORIG ,
1048 is the original version of the protocol
1049 and it does not contain
1050 .I PINGPROC_PINGBACK
1051 procedure. It  is useful
1052 for compatibility  with old client  programs,  and as  this program
1053 matures it may be dropped from the protocol entirely.
1054 .KS
1055 .NH 2
1056 \&The RPC Language Specification
1057 .LP
1058 The  RPC language is identical to  the XDR language, except for the
1059 added definition of a
1060 .I program-def 
1061 described below.
1062 .DS
1063 .ft CW
1064 program-def:
1065         "program" identifier "{"
1066                 version-def 
1067                 version-def *
1068         "}" "=" constant ";"
1069
1070 version-def:
1071         "version" identifier "{"
1072                 procedure-def
1073                 procedure-def *
1074         "}" "=" constant ";"
1075
1076 procedure-def:
1077         type-specifier identifier "(" type-specifier ")"
1078         "=" constant ";"
1079 .DE
1080 .KE
1081 .NH 2
1082 \&Syntax Notes
1083 .IP  1.
1084 The following keywords  are  added  and   cannot  be used   as
1085 identifiers: "program" and "version";
1086 .IP  2.
1087 A version name cannot occur more than once within the  scope of
1088 a program definition. Nor can a version number occur more than once
1089 within the scope of a program definition.
1090 .IP  3.
1091 A procedure name cannot occur  more than once within  the scope
1092 of a version definition. Nor can a procedure number occur more than
1093 once within the scope of version definition.
1094 .IP  4.
1095 Program identifiers are in the same name space as  constant and
1096 type identifiers.
1097 .IP  5.
1098 Only unsigned constants can  be assigned to programs, versions
1099 and procedures.
1100 .NH 1
1101 \&Port Mapper Program Protocol
1102 .LP
1103 The port mapper program maps RPC program and version numbers to
1104 transport-specific port numbers.  This program makes dynamic binding
1105 of remote programs possible.
1106 .LP
1107 This is desirable because the range of reserved port numbers is very
1108 small and the number of potential remote programs is very large.  By
1109 running only the port mapper on a reserved port, the port numbers of
1110 other remote programs can be ascertained by querying the port mapper.
1111 .LP
1112 The port mapper also aids in broadcast RPC.  A given RPC program will
1113 usually have different port number bindings on different machines, so
1114 there is no way to directly broadcast to all of these programs.  The
1115 port mapper, however, does have a fixed port number.  So, to
1116 broadcast to a given program, the client actually sends its message
1117 to the port mapper located at the broadcast address.  Each port
1118 mapper that picks up the broadcast then calls the local service
1119 specified by the client.  When the port mapper gets the reply from
1120 the local service, it sends the reply on back to the client.
1121 .KS
1122 .NH 2
1123 \&Port Mapper Protocol Specification (in RPC Language)
1124 .ie t .DS
1125 .el .DS L
1126 .ft CW
1127 .vs 11
1128 const PMAP_PORT = 111;      /* \fIportmapper port number \fP*/
1129
1130 .ft I
1131 /*
1132 * A mapping of (program, version, protocol) to port number
1133 */
1134 .ft CW
1135 struct mapping {
1136         unsigned int prog;
1137         unsigned int vers;
1138         unsigned int prot;
1139         unsigned int port;
1140 };
1141
1142 .ft I
1143 /* 
1144 * Supported values for the "prot" field
1145 */
1146 .ft CW
1147 const IPPROTO_TCP = 6;      /* \fIprotocol number for TCP/IP \fP*/
1148 const IPPROTO_UDP = 17;     /* \fIprotocol number for UDP/IP \fP*/
1149
1150 .ft I
1151 /*
1152 * A list of mappings
1153 */
1154 .ft CW
1155 struct *pmaplist {
1156         mapping map;
1157         pmaplist next;
1158 };
1159 .vs
1160 .DE
1161 .ie t .DS
1162 .el .DS L
1163 .vs 11
1164 .ft I
1165 /*
1166 * Arguments to callit
1167 */
1168 .ft CW
1169 struct call_args {
1170         unsigned int prog;
1171         unsigned int vers;
1172         unsigned int proc;
1173         opaque args<>;
1174 };  
1175
1176 .ft I
1177 /*
1178 * Results of callit
1179 */
1180 .ft CW
1181 struct call_result {
1182         unsigned int port;
1183         opaque res<>;
1184 };
1185 .vs
1186 .DE
1187 .KE
1188 .ie t .DS
1189 .el .DS L
1190 .vs 11
1191 .ft I
1192 /*
1193 * Port mapper procedures
1194 */
1195 .ft CW
1196 program PMAP_PROG {
1197         version PMAP_VERS {
1198                 void 
1199                 PMAPPROC_NULL(void)         = 0;
1200
1201                 bool
1202                 PMAPPROC_SET(mapping)       = 1;
1203
1204                 bool
1205                 PMAPPROC_UNSET(mapping)     = 2;
1206
1207                 unsigned int
1208                 PMAPPROC_GETPORT(mapping)   = 3;
1209
1210                 pmaplist
1211                 PMAPPROC_DUMP(void)         = 4;
1212
1213                 call_result
1214                 PMAPPROC_CALLIT(call_args)  = 5;
1215         } = 2;
1216 } = 100000;
1217 .vs
1218 .DE
1219 .NH 2
1220 \&Port Mapper Operation
1221 .LP
1222 The portmapper program currently supports two protocols (UDP/IP and
1223 TCP/IP).  The portmapper is contacted by talking to it on assigned
1224 port number 111 (SUNRPC [8]) on either of these protocols.  The
1225 following is a description of each of the portmapper procedures:
1226 .IP \fBPMAPPROC_NULL:\fP
1227 This procedure does no work.  By convention, procedure zero of any
1228 protocol takes no parameters and returns no results.
1229 .IP \fBPMAPPROC_SET:\fP
1230 When a program first becomes available on a machine, it registers
1231 itself with the port mapper program on the same machine.  The program
1232 passes its program number "prog", version number "vers", transport
1233 protocol number "prot", and the port "port" on which it awaits
1234 service request.  The procedure returns a boolean response whose
1235 value is
1236 .I TRUE
1237 if the procedure successfully established the mapping and 
1238 .I FALSE 
1239 otherwise.  The procedure refuses to establish
1240 a mapping if one already exists for the tuple "(prog, vers, prot)".
1241 .IP \fBPMAPPROC_UNSET:\fP
1242 When a program becomes unavailable, it should unregister itself with
1243 the port mapper program on the same machine.  The parameters and
1244 results have meanings identical to those of
1245 .I PMAPPROC_SET .
1246 The protocol and port number fields of the argument are ignored.
1247 .IP \fBPMAPPROC_GETPORT:\fP
1248 Given a program number "prog", version number "vers", and transport
1249 protocol number "prot", this procedure returns the port number on
1250 which the program is awaiting call requests.  A port value of zeros
1251 means the program has not been registered.  The "port" field of the
1252 argument is ignored.
1253 .IP \fBPMAPPROC_DUMP:\fP
1254 This procedure enumerates all entries in the port mapper's database.
1255 The procedure takes no parameters and returns a list of program,
1256 version, protocol, and port values.
1257 .IP \fBPMAPPROC_CALLIT:\fP
1258 This procedure allows a caller to call another remote procedure on
1259 the same machine without knowing the remote procedure's port number.
1260 It is intended for supporting broadcasts to arbitrary remote programs
1261 via the well-known port mapper's port.  The parameters "prog",
1262 "vers", "proc", and the bytes of "args" are the program number,
1263 version number, procedure number, and parameters of the remote
1264 procedure.
1265 .LP
1266 .B Note:
1267 .RS
1268 .IP  1.
1269 This procedure only sends a response if the procedure was
1270 successfully executed and is silent (no response) otherwise.
1271 .IP  2.
1272 The port mapper communicates with the remote program using UDP/IP
1273 only.
1274 .RE
1275 .LP
1276 The procedure returns the remote program's port number, and the bytes
1277 of results are the results of the remote procedure.
1278 .bp
1279 .NH 1
1280 \&References
1281 .LP
1282 [1]  Birrell, Andrew D. & Nelson, Bruce Jay; "Implementing Remote
1283 Procedure Calls"; XEROX CSL-83-7, October 1983.
1284 .LP
1285 [2]  Cheriton, D.; "VMTP:  Versatile Message Transaction Protocol",
1286 Preliminary Version 0.3; Stanford University, January 1987.
1287 .LP
1288 [3]  Diffie & Hellman; "New Directions in Cryptography"; IEEE
1289 Transactions on Information Theory IT-22, November 1976.
1290 .LP
1291 [4]  Harrenstien, K.; "Time Server", RFC 738; Information Sciences
1292 Institute, October 1977.
1293 .LP
1294 [5]  National Bureau of Standards; "Data Encryption Standard"; Federal
1295 Information Processing Standards Publication 46, January 1977.
1296 .LP
1297 [6]  Postel, J.; "Transmission Control Protocol - DARPA Internet
1298 Program Protocol Specification", RFC 793; Information Sciences
1299 Institute, September 1981.
1300 .LP
1301 [7]  Postel, J.; "User Datagram Protocol", RFC 768; Information Sciences
1302 Institute, August 1980.
1303 .LP
1304 [8]  Reynolds, J.  & Postel, J.; "Assigned Numbers", RFC 923; Information
1305 Sciences Institute, October 1984.