2 .\" Must use -- tbl -- with this one
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 $
9 .if \\n%=1 .tl ''- % -''
12 .\" prevent excess underlining in nroff
14 .OH 'Remote Procedure Calls: Protocol Specification''Page %'
15 .EH 'Page %''Remote Procedure Calls: Protocol Specification'
18 \&Remote Procedure Calls: Protocol Specification
23 Note: This chapter specifies a protocol that Sun Microsystems, Inc.,
25 It has been designated RFC1050 by the ARPA Network
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.
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.
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.
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
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.
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.
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.
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
96 \&Transports and Semantics
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
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.
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.
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.
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.
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.
147 NOTE: At Sun, RPC is currently implemented on top of both TCP/IP
148 and UDP/IP transports.
151 \&Binding and Rendezvous Independence
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).
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
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\,
176 \&RPC Protocol Requirements
178 The RPC protocol must provide for the following:
180 Unique specification of a procedure to be called.
182 Provisions for matching response messages to request messages.
185 Provisions for authenticating the caller to service and vice-versa.
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:
191 RPC protocol mismatches.
193 Remote program protocol version mismatches.
195 Protocol errors (such as misspecification of a procedure's parameters).
197 Reasons why remote authentication failed.
199 Any other reasons why the desired procedure was not called.
201 \&Programs and Procedures
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.
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
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.
226 The reply message to a request message has enough information to
227 distinguish the following error conditions:
229 The remote implementation of RPC does speak protocol version 2.
230 The lowest and highest supported RPC version numbers are returned.
232 The remote program is not available on the remote system.
234 The remote program does not support the requested version number.
235 The lowest and highest supported remote program version numbers are
238 The requested procedure number does not exist. (This is usually a
239 caller side protocol or programming error.)
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.)
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
261 /* \fIand more to be defined\fP */
270 In simple English, any
274 enumeration followed by bytes which are opaque to the RPC protocol
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.)
283 If authentication parameters were rejected, the response message
284 contains information stating why they were rejected.
286 \&Program Number Assignment
288 Program numbers are given out in groups of
290 (decimal 536870912) according to the following chart:
295 Program Numbers&Description
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
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.
317 \&Other Uses of the RPC Protocol
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.
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).
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.
349 \&The RPC Message Protocol
351 This section defines the RPC message protocol in the XDR data
352 description language. The message is defined in a top-down style.
363 * A reply to a call message can take on two forms:
364 * The message was either accepted or rejected.
374 * Given that a call message was accepted, the following is the
375 * status of an attempt to call a remote procedure.
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*/
390 * Reasons why a call message was rejected:
394 RPC_MISMATCH = 0, /* \fIRPC version number != 2 \fP*/
395 AUTH_ERROR = 1 /* \fIremote can't authenticate caller \fP*/
400 * Why authentication failed:
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*/
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
430 union switch (msg_type mtype) {
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
455 unsigned int rpcvers; /* \fImust be equal to two (2) \fP*/
461 /* \fIprocedure specific parameters start here \fP*/
468 * Body of a reply to an RPC request:
469 * The call message was either accepted or rejected.
472 union reply_body switch (reply_stat stat) {
474 accepted_reply areply;
476 rejected_reply rreply;
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.
495 struct accepted_reply {
497 union switch (accept_stat stat) {
500 /* \fIprocedure-specific results start here\fP */
509 * Void. Cases include \fIPROG_UNAVAIL, PROC_UNAVAIL\fP,
510 * and \fIGARBAGE_ARGS\fP.
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.
531 union rejected_reply switch (reject_stat stat) {
542 \&Authentication Protocols
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
551 \&Null Authentication
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
558 The bytes of the opaque_auth's body are undefined.
559 It is recommended that the opaque length be zero.
561 \&UNIX Authentication
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
568 the credential's opaque body encode the following structure:
573 string machinename<255>;
576 unsigned int gids<10>;
581 is an arbitrary ID which the caller machine may
584 is the name of the caller's machine (like "krypton"). The
586 is the caller's effective user ID. The
588 is the caller's effective group ID. The
591 counted array of groups which contain the caller as a member. The
592 verifier accompanying the credentials should be of
596 The value of the discriminant of the response verifier received in
597 the reply message from the server may be
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
607 flavor credentials. The server keeps a cache which maps shorthand
608 opaque structures (passed back by way of an
610 style response verifier) to the original credentials of the caller.
611 The caller can save network bandwidth and server cpu cycles by using
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
620 style of credentials.
625 UNIX authentication suffers from two major problems:
627 The naming is too UNIX-system oriented.
629 There is no verifier, so credentials can easily be faked.
631 DES authentication attempts to fix these two problems.
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.
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
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
669 \&DES Authentication Verifiers
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
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.
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]).
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:
698 the timestamp is greater than the one previously seen from the
701 the timestamp has not expired.
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.
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.
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.
724 \&Nicknames and Clock Synchronization
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
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
738 at which point it should resynchronize.
740 A client may still get the
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.
751 \&DES Authentication Protocol (in XDR language)
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.
766 enum authdes_namekind {
773 * A 64-bit block of encrypted DES data
776 typedef opaque des_block[8];
780 * Maximum length of a network user's name
783 const MAXNETNAMELEN = 255;
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
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*/
807 * A credential is either a fullname or a nickname
810 union authdes_cred switch (authdes_namekind adc_namekind) {
812 authdes_fullname adc_fullname;
814 unsigned int adc_nickname;
819 * A timestamp encodes the time since midnight, January 1, 1970.
823 unsigned int seconds; /* \fIseconds \fP*/
824 unsigned int useconds; /* \fIand microseconds \fP*/
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:
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
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.
844 struct authdes_verf_clnt {
845 timestamp adv_timestamp; /* \fIencrypted timestamp \fP*/
846 unsigned int adv_winverf; /* \fIencrypted window verifier \fP*/
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).
857 struct authdes_verf_svr {
858 timestamp adv_timeverf; /* \fIencrypted verifier \fP*/
859 unsigned int adv_nickname; /* \fInew nickname for client \fP*/
864 \&Diffie-Hellman Encryption
866 In this scheme, there are two constants,
871 particular values Sun has chosen for these for the DES
872 authentication protocol are:
878 "d4a0ba0250b6fd2ec626e7efd637df76c716e22d0944b88b"; /* \fIhex \fP*/
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:
890 PK(A) = ( BASE ** SK(A) ) mod MODULUS
891 PK(B) = ( BASE ** SK(B) ) mod MODULUS
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.
902 CK(A, B) = ( PK(B) ** SK(A)) mod MODULUS
909 CK(A, B) = ( PK(A) ** SK(B)) mod MODULUS
912 These two can be shown to be equivalent:
916 (PK(B) ** SK(A)) mod MODULUS = (PK(A) ** SK(B)) mod MODULUS
919 We drop the "mod MODULUS" parts and assume modulo arithmetic to
924 PK(B) ** SK(A) = PK(A) ** SK(B)
927 Then, replace PK(B) by what B computed earlier and likewise for
932 ((BASE ** SK(B)) ** SK(A) = (BASE ** SK(A)) ** SK(B)
939 BASE ** (SK(A) * SK(B)) = BASE ** (SK(A) * SK(B))
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
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
958 \&Record Marking Standard
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.
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!)
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
989 \&An Example Service Described in the RPC Language
991 Here is an example of the specification of a simple ping program.
997 * Simple ping program
1001 /* \fILatest and greatest version\fP */
1002 version PING_VERS_PINGBACK {
1004 PINGPROC_NULL(void) = 0;
1008 * Ping the caller, return the round-trip time
1009 * (in microseconds). Returns -1 if the operation
1014 PINGPROC_PINGBACK(void) = 1;
1022 version PING_VERS_ORIG {
1024 PINGPROC_NULL(void) = 0;
1028 const PING_VERS = 2; /* \fIlatest version \fP*/
1033 The first version described is
1034 .I PING_VERS_PINGBACK
1035 with two procedures,
1038 .I PINGPROC_PINGBACK .
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,
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.
1056 \&The RPC Language Specification
1058 The RPC language is identical to the XDR language, except for the
1059 added definition of a
1065 "program" identifier "{"
1068 "}" "=" constant ";"
1071 "version" identifier "{"
1074 "}" "=" constant ";"
1077 type-specifier identifier "(" type-specifier ")"
1084 The following keywords are added and cannot be used as
1085 identifiers: "program" and "version";
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.
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.
1095 Program identifiers are in the same name space as constant and
1098 Only unsigned constants can be assigned to programs, versions
1101 \&Port Mapper Program Protocol
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.
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.
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.
1123 \&Port Mapper Protocol Specification (in RPC Language)
1128 const PMAP_PORT = 111; /* \fIportmapper port number \fP*/
1132 * A mapping of (program, version, protocol) to port number
1144 * Supported values for the "prot" field
1147 const IPPROTO_TCP = 6; /* \fIprotocol number for TCP/IP \fP*/
1148 const IPPROTO_UDP = 17; /* \fIprotocol number for UDP/IP \fP*/
1152 * A list of mappings
1166 * Arguments to callit
1181 struct call_result {
1193 * Port mapper procedures
1199 PMAPPROC_NULL(void) = 0;
1202 PMAPPROC_SET(mapping) = 1;
1205 PMAPPROC_UNSET(mapping) = 2;
1208 PMAPPROC_GETPORT(mapping) = 3;
1211 PMAPPROC_DUMP(void) = 4;
1214 PMAPPROC_CALLIT(call_args) = 5;
1220 \&Port Mapper Operation
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
1237 if the procedure successfully established the mapping and
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
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
1269 This procedure only sends a response if the procedure was
1270 successfully executed and is silent (no response) otherwise.
1272 The port mapper communicates with the remote program using UDP/IP
1276 The procedure returns the remote program's port number, and the bytes
1277 of results are the results of the remote procedure.
1282 [1] Birrell, Andrew D. & Nelson, Bruce Jay; "Implementing Remote
1283 Procedure Calls"; XEROX CSL-83-7, October 1983.
1285 [2] Cheriton, D.; "VMTP: Versatile Message Transaction Protocol",
1286 Preliminary Version 0.3; Stanford University, January 1987.
1288 [3] Diffie & Hellman; "New Directions in Cryptography"; IEEE
1289 Transactions on Information Theory IT-22, November 1976.
1291 [4] Harrenstien, K.; "Time Server", RFC 738; Information Sciences
1292 Institute, October 1977.
1294 [5] National Bureau of Standards; "Data Encryption Standard"; Federal
1295 Information Processing Standards Publication 46, January 1977.
1297 [6] Postel, J.; "Transmission Control Protocol - DARPA Internet
1298 Program Protocol Specification", RFC 793; Information Sciences
1299 Institute, September 1981.
1301 [7] Postel, J.; "User Datagram Protocol", RFC 768; Information Sciences
1302 Institute, August 1980.
1304 [8] Reynolds, J. & Postel, J.; "Assigned Numbers", RFC 923; Information
1305 Sciences Institute, October 1984.