1.HTML "Security in Plan 9 2.de SS 3.NH 2 4.. 5.EQ 6delim $# 7.EN 8.TL 9Security in Plan 9 10.AU 11Russ Cox, MIT LCS 12.br 13Eric Grosse, Bell Labs 14.br 15Rob Pike, Bell Labs 16.br 17Dave Presotto, Avaya Labs and Bell Labs 18.br 19Sean Quinlan, Bell Labs 20.br 21.CW {rsc,ehg,rob,presotto,seanq}@plan9.bell-labs.com 22.AB 23The security architecture of the Plan 9™ 24operating system has recently been redesigned 25to address some technical shortcomings. 26This redesign provided an opportunity also to make the system more 27convenient to use securely. 28Plan 9 has thus improved in two ways not usually seen together: 29it has become more secure 30.I and 31easier to use. 32.LP 33The central component of the new architecture is a per-user 34self-contained agent called 35.CW factotum . 36.CW Factotum 37securely holds a 38copy of the user's keys and negotiates authentication protocols, on 39behalf of the user, with secure services around the network. 40Concentrating security code in a single program offers several 41advantages including: ease of update or repair to broken security 42software and protocols; the ability to run secure services at a lower 43privilege level; uniform management of keys for all services; and an 44opportunity to provide single sign on, even to unchanged legacy 45applications. 46.CW Factotum 47has an unusual architecture: it is implemented 48as a Plan 9 file server. 49.FS 50Appeared, in a slightly different form, in 51.I 52Proc. of the 2002 Usenix Security Symposium, 53.R 54San Francisco. 55.FE 56.AE 57.NH 1 58Introduction 59.LP 60Secure computing systems face two challenges: 61first, they must employ sophisticated technology that is difficult to design 62and prove correct; and second, 63they must be easy for regular people to use. 64The question of ease of use is sometimes neglected, but it is essential: 65weak but easy-to-use security can be more effective than strong but 66difficult-to-use security if it is more likely to be used. 67People lock their front doors when they leave the house, knowing 68full well that a burglar is capable of picking the lock (or avoiding 69the door altogether); yet few would accept the cost and 70awkwardness of a bank vault door on the 71house even though that might reduce the probability of a robbery. 72A related point is that users need a clear model of how the security 73operates (if not how it actually provides security) in order to use it 74well; for example, the clarity of a lock icon on a web browser 75is offset by the confusing and typically insecure 76steps for installing X.509 certificates. 77.LP 78The security architecture of the Plan 9 79operating system 80[Pike95] 81has recently been redesigned to make it both more secure 82and easier to use. 83By 84.I security 85we mean three things: 86first, the business of authenticating users and services; 87second, the safe handling, deployment, and use of keys 88and other secret information; and 89third, the use of encryption and integrity checks 90to safeguard communications 91from prying eyes. 92.LP 93The old security architecture of Plan 9 94had several engineering problems in common with other operating systems. 95First, it had an inadequate notion of security domain. 96Once a user provided a password to connect to a local file store, 97the system required that the same password be used to access all the other file 98stores. 99That is, the system treated all network services as 100belonging to the same security domain. 101.LP 102Second, the algorithms and protocols used in authentication, 103by nature tricky and difficult to get right, were compiled into the 104various applications, kernel modules, and file servers. 105Changes and fixes to a security protocol 106required that all components using that protocol needed to be recompiled, 107or at least relinked, and restarted. 108.LP 109Third, the file transport protocol, 9P 110[Pike93], 111that forms the core of 112the Plan 9 system, had its authentication protocol embedded in its design. 113This meant that fixing or changing the authentication used by 9P 114required deep changes to the system. 115If someone were to find a way to break the protocol, the system would 116be wide open and very hard to fix. 117.LP 118These and a number of lesser problems, combined with a desire 119for more widespread use of encryption in the system, spurred us to 120rethink the entire security architecture of Plan 9. 121.LP 122The centerpiece of the new architecture is an agent, 123called 124.CW factotum , 125that handles the user's keys and negotiates all security 126interactions with system services and applications. 127Like a trusted assistant with a copy of the owner's keys, 128.CW factotum 129does all the negotiation for security and authentication. 130Programs no longer need to be compiled with cryptographic 131code; instead they communicate with 132.CW factotum 133agents 134that represent distinct entities in the cryptographic exchange, 135such as a user and server of a secure service. 136If a security protocol needs to be added, deleted, or modified, 137only 138.CW factotum 139needs to be updated for all system services 140to be kept secure. 141.LP 142Building on 143.CW factotum , 144we modified 145secure services in the system to move 146user authentication code into 147.CW factotum ; 148made authentication a separable component of the file server protocol; 149deployed new security protocols; 150designed a secure file store, 151called 152.CW secstore , 153to protect our keys but make them easy to get when they are needed; 154designed a new kernel module to support transparent use of 155Transport Layer Security (TLS) 156[RFC2246]; 157and began using encryption for all communications within the system. 158The overall architecture is illustrated in Figure 1a. 159.if h .B1 10 60 160.KF 161.EQ 162gsize 9 163.EN 164.PS 3i 165 166# Secstore 167Sec: box "Secstore" wid 1.3i ht .5i 168 169# Terminal 170Term0: box invis ht .1i with .e at Sec.e + (-1.1i, -.5i) 171Term: box wid 1.1i ht 1i with .nw at Term0.ne 172Termlab: "\s-2Terminal\s+2" at Term.s + (0, -.15i) 173FT: ellipse "$ F sub T#" wid .40i ht .30i with .ne at Term.ne + (-.1i, -.1i) 174PT: ellipse "$ P sub T#" wid .6i ht .45i with .sw at Term.sw + (.2i, .2i) 175 176# CPU 177Cpu0: box invis ht .1i with .w at Term0.w + (3i, 0) 178Cpu: box wid 1.1i ht 1i with .nw at Cpu0.ne 179Cpulab: "\s-2CPU Server\s+2" at Cpu.s + (0, -.15i) 180FC: ellipse "$ F sub C#" wid .40 ht .30i with .nw at Cpu.nw + (.1i, -.1i) 181PC: ellipse "$ P sub C#" wid .6i ht .45i with .se at Cpu.se + (-.2i, .2i) 182 183# Authentication Server 184Auth: box dashed "Auth Server" wid 1.3i ht .5i with .e at Sec.e + (0, -2.3i) 185 186# File Server 187File0: box invis ht .1i with .w at Cpu0.w + (0, -1.5i) 188File: box wid 1.1i ht 1i with .nw at File0.ne 189Filelab: "\s-2File Server\s+2" at File.s + (0, -.15i) 190FF: ellipse "$ F sub F#" wid .40i ht .30i with .nw at File.nw + (.1i, -.1i) 191PF: ellipse "$ P sub F#" wid .6i ht .45i with .se at File.se + (-.2i, .2i) 192 193# Connections 194line from PT.e + (0, +0.05i) to PC.w + (0, +0.05i) 195spline from PT.e + (0, -0.05i) right 1i then down 1.5i right .5i then right to PF.w + (0, -0.05i) 196spline from PC.w + (0, -0.05i) left 1.1i then down 1.4i then right to PF.w + (0, 0.05i) 197line <-> from FC.se to PC.nw 198line <-> from FT.sw to PT.ne 199line <-> from FF.se to PF.nw 200spline <-> from Sec.e right .5i then down .655i then left to FT.e 201#spline from Auth.e + (0, 0.05i) right .5i then up 1i then to FT.se 202#spline from Auth.e + (0, 0.00i) right .7i then up 1i then to FC.sw 203#spline from Auth.e + (0, -0.05i) right .5i then to FF.w 204.PE 205.LP 206.ps 9 207.vs 10 208Figure 1a. Components of the security architecture. 209Each box is a (typically) separate machine; each ellipse a process. 210The ellipses labeled $F sub X# 211are 212.CW factotum 213processes; those labeled 214$P sub X# 215are the pieces and proxies of a distributed program. 216The authentication server is one of several repositories for users' security information 217that 218.CW factotum 219processes consult as required. 220.CW Secstore 221is a shared resource for storing private information such as keys; 222.CW factotum 223consults it for the user during bootstrap. 224.sp 225.KE 226.if h .B2 227.EQ 228gsize 11 229.EN 230.LP 231Secure protocols and algorithms are well understood 232and are usually not the weakest link in a system's security. 233In practice, most security problems arise from buggy servers, 234confusing software, or administrative oversights. 235It is these practical problems that we are addressing. 236Although this paper describes the algorithms and protocols we are using, 237they are included mainly for concreteness. 238Our main intent is to present a simple security architecture built 239upon a small trusted code base that is easy to verify (whether by manual or 240automatic means), easy to understand, and easy to use. 241.LP 242Although it is a subjective assessment, 243we believe we have achieved our goal of ease of use. 244That we have achieved 245our goal of improved security is supported by our plan to 246move our currently private computing environment onto the Internet 247outside the corporate firewall. 248The rest of this paper explains the architecture and how it is used, 249to explain why a system that is easy to use securely is also safe 250enough to run in the open network. 251.NH 1 252An Agent for Security 253.LP 254One of the primary reasons for the redesign of the Plan 9 255security infrastructure was to remove the authentication 256method both from the applications and from the kernel. 257Cryptographic code 258is large and intricate, so it should 259be packaged as a separate component that can be repaired or 260modified without altering or even relinking applications 261and services that depend on it. 262If a security protocol is broken, it should be trivial to repair, 263disable, or replace it on the fly. 264Similarly, it should be possible for multiple programs to use 265a common security protocol without embedding it in each program. 266.LP 267Some systems use dynamically linked libraries (DLLs) to address these configuration issues. 268The problem with this approach is that it leaves 269security code in the same address space as the program using it. 270The interactions between the program and the DLL 271can therefore accidentally or deliberately violate the interface, 272weakening security. 273Also, a program using a library to implement secure services 274must run at a privilege level necessary to provide the service; 275separating the security to a different program makes it possible 276to run the services at a weaker privilege level, isolating the 277privileged code to a single, more trustworthy component. 278.LP 279Following the lead of the SSH agent 280[Ylon96], 281we give each user 282an agent process responsible 283for holding and using the user's keys. 284The agent program is called 285.CW factotum 286because of its similarity to the proverbial servant with the 287power to act on behalf of his master because he holds the 288keys to all the master's possessions. It is essential that 289.CW factotum 290keep the keys secret and use them only in the owner's interest. 291Later we'll discuss some changes to the kernel to reduce the possibility of 292.CW factotum 293leaking information inadvertently. 294.LP 295.CW Factotum 296is implemented, like most Plan 9 services, as a file server. 297It is conventionally mounted upon the directory 298.CW /mnt/factotum , 299and the files it serves there are analogous to virtual devices that provide access to, 300and control of, the services of the 301.CW factotum . 302The next few sections describe the design of 303.CW factotum 304and how it operates with the other pieces of Plan 9 to provide 305security services. 306.SS 307Logging in 308.LP 309To make the discussions that follow more concrete, 310we begin with a couple of examples showing how the 311Plan 9 security architecture appears to the user. 312These examples both involve a user 313.CW gre 314logging in after booting a local machine. 315The user may or may not have a secure store in which 316all his keys are kept. 317If he does, 318.CW factotum 319will prompt him for the password to the secure store 320and obtain keys from it, prompting only when a key 321isn't found in the store. 322Otherwise, 323.CW factotum 324must prompt for each key. 325.LP 326In the typescripts, \f6\s9\en\s0\fP 327represents a literal newline 328character typed to force a default response. 329User input is in italics, and 330long lines are folded and indented to fit. 331.LP 332This first example shows a user logging in without 333help from the secure store. 334First, 335.CW factotum 336prompts for a user name that the local kernel 337will use: 338.P1 339user[none]: \f6\s9gre\s0\fP 340.P2 341(Default responses appear in square brackets.) 342The kernel then starts accessing local resources 343and requests, through 344.CW factotum , 345a user/password pair to do so: 346.P1 347!Adding key: dom=cs.bell-labs.com 348 proto=p9sk1 349user[gre]: \f6\s9\en\s0\fP 350password: \f6****\fP 351.P2 352Now the user is logged in to the local system, and 353the mail client starts up: 354.P1 355!Adding key: proto=apop 356 server=plan9.bell-labs.com 357user[gre]: \f6\s9\en\s0\fP 358password: \f6****\fP 359.P2 360.CW Factotum 361is doing all the prompting and the applications 362being started are not even touching the keys. 363Note that it's always clear which key is being requested. 364.LP 365Now consider the same login sequence, but in the case where 366.CW gre 367has a secure store account: 368.P1 369user[none]: \f6\s9gre\s0\fP 370secstore password: \f6*********\fP 371STA PIN+SecurID: \f6*********\fP 372.P2 373That's the last 374.CW gre 375will hear from 376.CW factotum 377unless an attempt is made to contact 378a system for which no key is kept in the secure store. 379.SS 380The factotum 381.LP 382Each computer running Plan 9 has one user id that owns all the 383resources on that system \(em the scheduler, local disks, 384network interfaces, etc. 385That user, the 386.I "host owner" , 387is the closest analogue in Plan 9 to a Unix 388.CW root 389account (although it is far weaker; 390rather than having special powers, as its name implies the host owner 391is just a regular user that happens to own the 392resources of the local machine). 393On a single-user system, which we call a terminal, 394the host owner is the id of the terminal's user. 395Shared servers such as CPU servers normally have a pseudo-user 396that initially owns all resources. 397At boot time, the Plan 9 kernel starts a 398.CW factotum 399executing as, and therefore with the privileges of, 400the host owner. 401.LP 402New processes run as 403the same user as the process which created them. 404When a process must take on the identity of a new user, 405such as to provide a login shell 406on a shared CPU server, 407it does so by proving to the host owner's 408.CW factotum 409that it is 410authorized to do so. 411This is done by running an 412authentication protocol with 413.CW factotum 414to 415prove that the process has access to secret information 416which only the new user should possess. 417For example, consider the setup in Figure 1a. 418If a user on the terminal 419wants to log in to the CPU server using the 420Plan 9 421.CW cpu 422service 423[Pike93], 424then 425$P sub T# 426might be the 427.CW cpu 428client program and 429$P sub C# 430the 431.CW cpu 432server. 433Neither $P sub C# nor $P sub T# 434knows the details of the authentication. 435They 436do need to be able to shuttle messages back and 437forth between the two 438.CW factotums , 439but this is 440a generic function easily performed without 441knowing, or being able to extract, secrets in 442the messages. 443$P sub T# 444will make a network connection to $P sub C#. 445$P sub T# 446and 447$P sub C# 448will then relay messages between 449the 450.CW factotum 451owned by the user, $F sub T#, 452and the one owned by the CPU server, $F sub C#, 453until mutual authentication has been established. 454Later 455sections describe the RPC between 456.CW factotum 457and 458applications and the library functions to support proxy operations. 459.LP 460The kernel always uses a single local instance of 461.CW factotum , 462running as the 463host owner, for 464its authentication purposes, but 465a regular user may start other 466.CW factotum 467agents. 468In fact, the 469.CW factotum 470representing the user need not be 471running on the same machine as its client. 472For instance, it is easy for a user on a CPU server, 473through standard Plan 9 operations, 474to replace the 475.CW /mnt/factotum 476in the user's private file name space on the server 477with a connection to the 478.CW factotum 479running on the terminal. 480(The usual file system permissions prevent interlopers 481from doing so maliciously.) 482This permits secure operations on the CPU server to be 483transparently validated by the user's own 484.CW factotum , 485so 486secrets need never leave the user's terminal. 487The SSH agent 488[Ylon96] 489does much the 490same with special SSH protocol messages, but 491an advantage to making our agent a file system 492is that we need no new mechanism to access our remote 493agent; remote file access is sufficient. 494.LP 495Within 496.CW factotum , 497each protocol is implemented as a state 498machine with a generic interface, so protocols are in 499essence pluggable modules, easy to add, modify, or drop. 500Writing a message to and reading a message from 501.CW factotum 502each require a separate RPC and result in 503a single state transition. 504Therefore 505.CW factotum 506always runs to completion on every RPC and never blocks 507waiting for input during any authentication. 508Moreover, the number of simultaneous 509authentications is limited only by the amount of memory we're 510willing to dedicate to representing the state machines. 511.LP 512Authentication protocols are implemented only 513within 514.CW factotum , 515but adding and removing 516protocols does require relinking the binary, so 517.CW factotum 518processes (but no others) 519need to be restarted in order to take advantage of 520new or repaired protocols. 521.LP 522At the time of writing, 523.CW factotum 524contains authentication 525modules for the Plan 9 shared key protocol (p9sk1), 526SSH's RSA authentication, passwords in the clear, APOP, CRAM, PPP's CHAP, 527Microsoft PPP's MSCHAP, and VNC's challenge/response. 528.SS 529Local capabilities 530.LP 531A capability system, managed by the kernel, is used to empower 532.CW factotum 533to grant permission to another process to change its user id. 534A 535kernel device driver 536implements two files, 537.CW /dev/caphash 538and 539.CW /dev/capuse . 540The write-only file 541.CW /dev/caphash 542can be opened only by the host owner, and only once. 543.CW Factotum 544opens this file immediately after booting. 545.LP 546To use the files, 547.CW factotum 548creates a string of the form 549.I userid1\f(CW@\fPuserid2\f(CW@\fPrandom-string , 550uses SHA1 HMAC to hash 551.I userid1\f(CW@\fPuserid2 552with key 553.I random-string , 554and writes that hash to 555.CW /dev/caphash . 556.CW Factotum 557then passes the original string to another 558process on the same machine, running 559as user 560.I userid1 , 561which 562writes the string to 563.CW /dev/capuse . 564The kernel hashes the string and looks for 565a matching hash in its list. 566If it finds one, 567the writing process's user id changes from 568.I userid1 569to 570.I userid2 . 571Once used, or if a timeout expires, 572the capability is discarded by the kernel. 573.LP 574The capabilities are local to the machine on which they are created. 575Hence a 576.CW factotum 577running on one machine cannot pass capabilities 578to processes on another and expect them to work. 579.SS 580Keys 581.LP 582We define the word 583.I key 584to mean not only a secret, but also a description of the 585context in which that secret is to be used: the protocol, 586server, user, etc. to which it applies. 587That is, 588a key is a combination of secret and descriptive information 589used to authenticate the identities of parties 590transmitting or receiving information. 591The set of keys used 592in any authentication depends both on the protocol and on 593parameters passed by the program requesting the authentication. 594.LP 595Taking a tip from SDSI 596[RiLa], 597which represents security information as textual S-expressions, 598keys in Plan 9 are represented as plain UTF-8 text. 599Text is easily 600understood and manipulated by users. 601By contrast, 602a binary or other cryptic format 603can actually reduce overall security. 604Binary formats are difficult for users to examine and can only be 605cracked by special tools, themselves poorly understood by most users. 606For example, very few people know or understand what's inside 607their X.509 certificates. 608Most don't even know where in the system to 609find them. 610Therefore, they have no idea what they are trusting, and why, and 611are powerless to change their trust relationships. 612Textual, centrally stored and managed keys are easier to use and safer. 613.LP 614Plan 9 has historically represented databases as attribute/value pairs, 615since they are a good foundation for selection and projection operations. 616.CW Factotum 617therefore represents 618the keys in the format 619.I attribute\f(CW=\fPvalue , 620where 621.I attribute 622is an identifier, possibly with a single-character prefix, and 623.I value 624is an arbitrary quoted string. 625The pairs themselves are separated by white space. 626For example, a Plan 9 key and an APOP key 627might be represented like this: 628.P1 629dom=bell-labs.com proto=p9sk1 user=gre 630 !password='don''t tell' 631proto=apop server=x.y.com user=gre 632 !password='open sesame' 633.P2 634If a value is empty or contains white space or single quotes, it must be quoted; 635quotes are represented by doubled single quotes. 636Attributes that begin with an exclamation mark 637.CW ! ) ( 638are considered 639.I secret . 640.CW Factotum 641will never let a secret value escape its address space 642and will suppress keyboard echo when asking the user to type one. 643.LP 644A program requesting authentication selects a key 645by providing a 646.I query , 647a list of elements to be matched by the key. 648Each element in the list is either an 649.I attribute\f(CW=\fPvalue 650pair, which is satisfied by keys with 651exactly that pair; 652or an attribute followed by a question mark, 653.I attribute\f(CW? , 654which is satisfied by keys with some pair specifying 655the attribute. 656A key matches a query if every element in the list 657is satisfied. 658For instance, to select the APOP key in the previous example, 659an APOP client process might specify the query 660.P1 661server=x.y.com proto=apop 662.P2 663Internally, 664.CW factotum 's 665APOP module would add the requirements of 666having 667.CW user 668and 669.CW !password 670attributes, forming the query 671.P1 672server=x.y.com proto=apop user? !password? 673.P2 674when searching for an appropriate key. 675.LP 676.CW Factotum 677modules expect keys to have some well-known attributes. 678For instance, the 679.CW proto 680attribute specifies the protocol module 681responsible for using a particular key, 682and protocol modules may expect other well-known attributes 683(many expect keys to have 684.CW !password 685attributes, for example). 686Additional attributes can be used as comments or for 687further discrimination without intervention by 688.CW factotum ; 689for example, the APOP and IMAP mail clients conventionally 690include a 691.CW server 692attribute to select an appropriate key for authentication. 693.LP 694Unlike in SDSI, 695keys in Plan 9 have no nested structure. This design 696keeps the representation simple and straightforward. 697If necessary, we could add a nested attribute 698or, in the manner of relational databases, an attribute that 699selects another tuple, but so far the simple design has been sufficient. 700.LP 701A simple common structure for all keys makes them easy for users 702to administer, 703but the set of attributes and their interpretation is still 704protocol-specific and can be subtle. 705Users may still 706need to consult a manual to understand all details. 707Many attributes 708.CW proto , ( 709.CW user , 710.CW password , 711.CW server ) 712are self-explanatory and our short experience 713has not uncovered any particular difficulty in handling keys. 714Things 715will likely get messier, however, 716when we grapple with public 717keys and their myriad components. 718.SS 719Protecting keys 720.LP 721Secrets must be prevented from escaping 722.CW factotum . 723There are a number of ways they could leak: 724another process might be able to debug the agent process, the 725agent might swap out to disk, or the process might willingly 726disclose the key. 727The last is the easiest to avoid: 728secret information in a key is marked 729as such, and 730whenever 731.CW factotum 732prints keys or queries for new 733ones, it is careful to avoid displaying secret information. 734(The only exception to this is the 735``plaintext password'' protocol, which consists 736of sending the values of the 737.CW user 738and 739.CW !password 740attributes. 741Only keys tagged with 742.CW proto=pass 743can have their passwords disclosed by this mechanism.) 744.LP 745Preventing the first two forms of leakage 746requires help from the kernel. 747In Plan 9, every process is 748represented by a directory in the 749.CW /proc 750file system. 751Using the files in this directory, 752other processes could (with appropriate access permission) examine 753.CW factotum 's 754memory and registers. 755.CW Factotum 756is protected from processes of other users 757by the default access bits of its 758.CW /proc 759directory. 760However, we'd also like to protect the 761agent from other processes owned by the same user, 762both to avoid honest mistakes and to prevent 763an unattended terminal being 764exploited to discover secret passwords. 765To do this, we added a control message to 766.CW /proc 767called 768.CW private . 769Once the 770.CW factotum 771process has written 772.CW private 773to its 774.CW /proc/\f2pid\fP/ctl 775file, no process can access 776.CW factotum 's 777memory 778through 779.CW /proc . 780(Plan 9 has no other mechanism, such as 781.CW /dev/kmem , 782for accessing a process's memory.) 783.LP 784Similarly, the agent's address space should not be 785swapped out, to prevent discovering unencrypted 786keys on the swapping media. 787The 788.CW noswap 789control message in 790.CW /proc 791prevents this scenario. 792Neither 793.CW private 794nor 795.CW noswap 796is specific to 797.CW factotum . 798User-level file servers such as 799.CW dossrv , 800which interprets FAT file systems, 801could use 802.CW noswap 803to keep their buffer caches from being 804swapped to disk. 805.LP 806Despite our precautions, attackers might still 807find a way to gain access to a process running as the host 808owner on a machine. 809Although they could not directly 810access the keys, attackers could use the local 811.CW factotum 812to perform authentications for them. 813In the case 814of some keys, for example those locking bank 815accounts, we want a way to disable or at least 816detect such access. 817That is the role of the 818.CW confirm 819attribute in a key. 820Whenever a key with a 821.CW confirm 822attribute is accessed, the local user must 823confirm use of the key via a local GUI. 824The next section describes the actual mechanism. 825.LP 826We have not addressed leaks possible as a result of 827someone rebooting or resetting a machine running 828.CW factotum . 829For example, someone could reset a machine 830and reboot it with a debugger instead of a kernel, 831allowing them to examine the contents of memory 832and find keys. We have not found a satisfactory 833solution to this problem. 834.SS 835Factotum transactions 836.LP 837External programs manage 838.CW factotum 's 839internal key state 840through its file interface, 841writing textual 842.CW key 843and 844.CW delkey 845commands to the 846.CW /mnt/factotum/ctl 847file. 848Both commands take a list of attributes as an argument. 849.CW Key 850creates a key with the given attributes, replacing any 851extant key with an identical set of public attributes. 852.CW Delkey 853deletes all keys that match the given set of attributes. 854Reading the 855.CW ctl 856file returns a list of keys, one per line, displaying only public attributes. 857The following example illustrates these interactions. 858.P1 859% cd /mnt/factotum 860% ls -l 861-lrw------- gre gre 0 Jan 30 22:17 confirm 862--rw------- gre gre 0 Jan 30 22:17 ctl 863-lr-------- gre gre 0 Jan 30 22:17 log 864-lrw------- gre gre 0 Jan 30 22:17 needkey 865--r--r--r-- gre gre 0 Jan 30 22:17 proto 866--rw-rw-rw- gre gre 0 Jan 30 22:17 rpc 867% cat >ctl 868key dom=bell-labs.com proto=p9sk1 user=gre 869 !password='don''t tell' 870key proto=apop server=x.y.com user=gre 871 !password='bite me' 872^D 873% cat ctl 874key dom=bell-labs.com proto=p9sk1 user=gre 875key proto=apop server=x.y.com user=gre 876% echo 'delkey proto=apop' >ctl 877% cat ctl 878key dom=bell-labs.com proto=p9sk1 user=gre 879% 880.P2 881(A file with the 882.CW l 883bit set can be opened by only one process at a time.) 884.LP 885The heart of the interface is the 886.CW rpc 887file. 888Programs authenticate with 889.CW factotum 890by writing a request to the 891.CW rpc 892file 893and reading back the reply; this sequence is called an RPC 894.I transaction . 895Requests and replies have the same format: 896a textual verb possibly followed by arguments, 897which may be textual or binary. 898The most common reply verb is 899.CW ok , 900indicating success. 901An RPC session begins with a 902.CW start 903transaction; the argument is a key query as described 904earlier. 905Once started, an RPC conversation usually consists of 906a sequence of 907.CW read 908and 909.CW write 910transactions. 911If the conversation is successful, an 912.CW authinfo 913transaction will return information about 914the identities learned during the transaction. 915The 916.CW attr 917transaction returns a list of attributes for the current 918conversation; the list includes any attributes given in 919the 920.CW start 921query as well as any public attributes from keys being used. 922.LP 923As an example of the 924.CW rpc 925file in action, consider a mail client 926connecting to a mail server and authenticating using 927the POP3 protocol's APOP challenge-response command. 928There are four programs involved: the mail client $P sub C#, the client 929.CW factotum 930$F sub C#, the mail server $P sub S#, and the server 931.CW factotum 932$F sub S#. 933All authentication computations are handled by the 934.CW factotum 935processes. 936The mail programs' role is just to relay messages. 937.LP 938At startup, the mail server at 939.CW x.y.com 940begins an APOP conversation 941with its 942.CW factotum 943to obtain the banner greeting, which 944includes a challenge: 945.P1 946$P sub S -> F sub S#: start proto=apop role=server 947$F sub S -> P sub S#: ok 948$P sub S -> F sub S#: read 949$F sub S -> P sub S#: ok +OK POP3 \f2challenge\fP 950.P2 951Having obtained the challenge, the server greets the client: 952.P1 953$P sub S -> P sub C#: +OK POP3 \f2challenge\fP 954.P2 955The client then uses an APOP conversation with its 956.CW factotum 957to obtain a response: 958.P1 959$P sub C -> F sub C#: start proto=apop role=client 960 server=x.y.com 961$F sub C -> P sub C#: ok 962$P sub C -> F sub C#: write +OK POP3 \f2challenge\fP 963$F sub C -> P sub C#: ok 964$P sub C -> F sub C#: read 965$F sub C -> P sub C#: ok APOP gre \f2response\fP 966.P2 967.CW Factotum 968requires that 969.CW start 970requests include a 971.CW proto 972attribute, and the APOP module requires an additional 973.CW role 974attribute, but the other attributes are optional and only 975restrict the key space. 976Before responding to the 977.CW start 978transaction, the client 979.CW factotum 980looks for a key to 981use for the rest of the conversation. 982Because of the arguments in the 983.CW start 984request, the key must have public attributes 985.CW proto=apop 986and 987.CW server=x.y.com ; 988as mentioned earlier, 989the APOP module additionally requires that the key have 990.CW user 991and 992.CW !password 993attributes. 994Now that the client has obtained a response 995from its 996.CW factotum , 997it echoes that response to the server: 998.P1 999$P sub C -> P sub S#: APOP gre \f2response\fP 1000.P2 1001Similarly, the server passes this message to 1002its 1003.CW factotum 1004and obtains another to send back. 1005.P1 1006$P sub S -> F sub S#: write APOP gre \f2response\fP 1007$F sub S -> P sub S#: ok 1008$P sub S -> F sub S#: read 1009$F sub S -> P sub S#: ok +OK welcome 1010 1011$P sub S -> P sub C#: +OK welcome 1012.P2 1013Now the authentication protocol is done, and 1014the server can retrieve information 1015about what the protocol established. 1016.P1 1017$P sub S -> F sub S#: authinfo 1018$F sub S -> P sub S#: ok client=gre 1019 capability=\f2capability\fP 1020.P2 1021The 1022.CW authinfo 1023data is a list of 1024.I attr\f(CW=\fPvalue 1025pairs, here a client user name and a capability. 1026(Protocols that establish shared secrets or provide 1027mutual authentication indicate this by adding 1028appropriate 1029.I attr\f(CW=\fPvalue 1030pairs.) 1031The capability can be used by the server to change its 1032identity to that of the client, as described earlier. 1033Once it has changed its identity, the server can access and serve 1034the client's mailbox. 1035.LP 1036Two more files provide hooks for a graphical 1037.CW factotum 1038control interface. 1039The first, 1040.CW confirm , 1041allows the user detailed control over the use of certain keys. 1042If a key has a 1043.CW confirm= 1044attribute, then the user must approve each use of the key. 1045A separate program with a graphical interface reads from the 1046.CW confirm 1047file to see when a confirmation is necessary. 1048The read blocks until a key usage needs to be approved, whereupon 1049it will return a line of the form 1050.P1 1051confirm tag=1 \f2attributes\fP 1052.P2 1053requesting permission to use the key with those public attributes. 1054The graphical interface then prompts the user for approval 1055and writes back 1056.P1 1057tag=1 answer=yes 1058.P2 1059(or 1060.CW answer=no ). 1061.LP 1062The second file, 1063.CW needkey , 1064diverts key requests. 1065In the APOP example, if a suitable key had not been found 1066during the 1067.CW start 1068transaction, 1069.CW factotum 1070would have indicated failure by 1071returning a response indicating 1072what key was needed: 1073.P1 1074$F sub C -> P sub C#: needkey proto=apop 1075 server=x.y.com user? !password? 1076.P2 1077A typical client would then prompt the user for the desired 1078key information, create a new key via the 1079.CW ctl 1080file, and then reissue the 1081.CW start 1082request. 1083If the 1084.CW needkey 1085file is open, 1086then instead of failing, the transaction 1087will block, and the next read from the 1088.CW /mnt/factotum/needkey 1089file will return a line of the form 1090.P1 1091needkey tag=1 \f2attributes\f2 1092.P2 1093The graphical interface then prompts the user for the needed 1094key information, creates the key via the 1095.CW ctl 1096file, and writes back 1097.CW tag=1 1098to resume the transaction. 1099.LP 1100The remaining files are informational and used for debugging. 1101The 1102.CW proto 1103file contains a list of supported protocols (to see what protocols the 1104system supports, 1105.CW cat 1106.CW /mnt/factotum/proto ), 1107and the 1108.CW log 1109file contains a log of operations and debugging output 1110enabled by a 1111.CW debug 1112control message. 1113.LP 1114The next few sections explain how 1115.CW factotum 1116is used by system services. 1117.NH 1 1118Authentication in 9P 1119.LP 1120Plan 9 uses a remote file access protocol, 9P 1121[Pike93], 1122to connect to resources such as the 1123file server and remote processes. 1124The original design for 9P included special messages at the start of a conversation 1125to authenticate the user. 1126Multiple users can share a single connection, such as when a CPU server 1127runs processes for many users connected to a single file server, 1128but each must authenticate separately. 1129The authentication protocol, similar to that of Kerberos 1130[Stei88], 1131used a sequence of messages passed between client, file server, and authentication 1132server to verify the identities of the user, calling machine, and serving machine. 1133One major drawback to the design was that the authentication method was defined by 9P 1134itself and could not be changed. 1135Moreover, there was no mechanism to relegate 1136authentication to an external (trusted) agent, 1137so a process implementing 9P needed, besides support for file service, 1138a substantial body of cryptographic code to implement a handful of startup messages 1139in the protocol. 1140.LP 1141A recent redesign of 9P 1142addressed a number of file service issues outside the scope of this paper. 1143On issues of authentication, there were two goals: 1144first, to remove details about authentication from the 1145protocol itself; second, to allow an external program to execute the authentication 1146part of the protocol. 1147In particular, we wanted a way to quickly incorporate 1148ideas found in other systems such as SFS 1149[Mazi99]. 1150.LP 1151Since 9P is a file service protocol, the solution involved creating a new type of file 1152to be served: an 1153.I authentication 1154.I file . 1155Connections to a 9P service begin in a state that 1156allows no general file access but permits the client 1157to open an authentication file 1158by sending a special message, generated by the new 1159.CW fauth 1160system call: 1161.P1 1162afd = fauth(int fd, char *servicename); 1163.P2 1164Here 1165.CW fd 1166is the user's file descriptor for the established network connection to the 9P server 1167and 1168.CW servicename 1169is the name of the desired service offered on that server, typically the file subsystem 1170to be accessed. 1171The returned file descriptor, 1172.CW afd , 1173is a unique handle representing the authentication file 1174created for this connection to authenticate to 1175this service; it is analogous to a capability. 1176The authentication file represented by 1177.CW afd 1178is not otherwise addressable on the server, such as through 1179the file name hierarchy. 1180In all other respects, it behaves like a regular file; 1181most important, it accepts standard read and write operations. 1182.LP 1183To prove its identity, the user process (via 1184.CW factotum ) 1185executes the authentication protocol, 1186described in the next section of this paper, 1187over the 1188.CW afd 1189file descriptor with ordinary reads and writes. 1190When client and server have successfully negotiated, the authentication file 1191changes state so it can be used as evidence of authority in 1192.CW mount . 1193.LP 1194Once identity is established, the process presents the (now verified) 1195.CW afd 1196as proof of identity to the 1197.CW mount 1198system call: 1199.P1 1200mount(int fd, int afd, char *mountpoint, 1201 int flag, char *servicename) 1202.P2 1203If the 1204.CW mount 1205succeeds, the user now 1206has appropriate permissions for the file hierarchy made 1207visible at the mount point. 1208.LP 1209This sequence of events has several advantages. 1210First, the actual authentication protocol is implemented using regular reads and writes, 1211not special 9P messages, so 1212they can be processed, forwarded, proxied, and so on by 1213any 9P agent without special arrangement. 1214Second, the business of negotiating the authentication by reading and writing the 1215authentication file can be delegated to an outside agent, in particular 1216.CW factotum ; 1217the programs that implement the client and server ends of a 9P conversation need 1218no authentication or cryptographic code. 1219Third, 1220since the authentication protocol is not defined by 9P itself, it is easy to change and 1221can even be negotiated dynamically. 1222Finally, since 1223.CW afd 1224acts like a capability, it can be treated like one: 1225handed to another process to give it special permissions; 1226kept around for later use when authentication is again required; 1227or closed to make sure no other process can use it. 1228.LP 1229All these advantages stem from moving the authentication negotiation into 1230reads and writes on a separate file. 1231As is often the case in Plan 9, 1232making a resource (here authentication) accessible with a file-like interface 1233reduces 1234.I a 1235.I priori 1236the need for special interfaces. 1237.LP 1238.SS 1239Plan 9 shared key protocol 1240.LP 1241In addition to the various standard protocols supported by 1242.CW factotum , 1243we use a shared key protocol for native 1244Plan 9 authentication. 1245This protocol provides backward compatibility with 1246older versions of the system. One reason for the new 1247architecture is to let us replace such protocols 1248in the near future with more cryptographically secure ones. 1249.LP 1250.I P9sk1 1251is a shared key protocol that uses tickets much like those 1252in the original Kerberos. 1253The difference is that we've 1254replaced the expiration time in Kerberos tickets with 1255a random nonce parameter and a counter. 1256We summarize it here: 1257.P1 1258$C -> S: ~~ "nonce" sub C# 1259$S -> C: ~~ "nonce" sub S , "uid" sub S , "domain" sub S# 1260 1261$C -> A: ~~ "nonce" sub S , "uid" sub S , "domain" sub S , "uid" sub C ,# 1262 $"factotum" sub C# 1263$A -> C: ~~ K sub C roman "{" "nonce" sub S , "uid" sub C , "uid" sub S, K sub n roman "}",# 1264 $K sub S roman "{" "nonce" sub S , "uid" sub C , "uid" sub S, K sub n roman "}"# 1265 1266$C -> S: ~~ K sub S roman "{" "nonce" sub S , "uid" sub C , "uid" sub S , K sub n roman "}",# 1267 $K sub n roman "{" "nonce" sub S , "counter" roman "}"# 1268$S -> C: ~~ K sub n roman "{" "nonce" sub C , "counter" roman "}"# 1269.P2 1270(Here $K roman "{" x roman "}"# indicates $x# encrypted with 1271DES key $K#.) 1272The first two messages exchange nonces and server identification. 1273After this initial exchange, the client contacts the authentication 1274server to obtain a pair of encrypted tickets, one encrypted with 1275the client key and one with the server key. 1276The client relays the server ticket to the server. 1277The server believes that the ticket is new 1278because it contains 1279$"nonce" sub S# 1280and that the ticket is from the authentication 1281server because it is encrypted in the server key $K sub S#. 1282The ticket is basically a statement from the authentication 1283server that now $"uid" sub C# and $"uid" sub S# share a 1284secret $K sub n#. 1285The authenticator $K sub n roman "{" "nonce" sub S , "counter" roman "}"# 1286convinces the server that the client knows $K sub n# and thus 1287must be $"uid" sub C#. 1288Similarly, authenticator $K sub n roman "{" "nonce" sub C , "counter" roman "}"# 1289convinces the client that the server knows $K sub n# and thus 1290must be $"uid" sub S#. 1291Tickets can be reused, without contacting the authentication 1292server again, by incrementing the counter before each 1293authenticator is generated. 1294.LP 1295In the future we hope to introduce a public key version of 1296p9sk1, 1297which would allow authentication even 1298when the authentication server is not available. 1299.SS 1300The authentication server 1301.LP 1302Each Plan 9 security domain has an authentication server (AS) 1303that all users trust to keep the complete set of shared keys. 1304It also offers services for users and administrators to manage the 1305keys, create and disable accounts, and so on. 1306It typically runs on 1307a standalone machine with few other services. 1308The AS comprises two services, 1309.CW keyfs 1310and 1311.CW authsrv . 1312.LP 1313.CW Keyfs 1314is a user-level file system that manages an 1315encrypted database of user accounts. 1316Each account is represented by a directory containing the 1317files 1318.CW key , 1319containing the Plan 9 key for p9sk1; 1320.CW secret 1321for the challenge/response protocols (APOP, VNC, CHAP, MSCHAP, 1322CRAM); 1323.CW log 1324for authentication outcomes; 1325.CW expire 1326for an expiration time; and 1327.CW status . 1328If the expiration time passes, 1329if the number of successive failed authentications 1330exceeds 50, or if 1331.CW disabled 1332is written to the status file, 1333any attempt to access the 1334.CW key 1335or 1336.CW secret 1337files will fail. 1338.LP 1339.CW Authsrv 1340is a network service that brokers shared key authentications 1341for the protocols p9sk1, APOP, VNC, CHAP, MSCHAP, 1342and CRAM. Remote users can also call 1343.CW authsrv 1344to change their passwords. 1345.LP 1346The 1347p9sk1 1348protocol was described in the previous 1349section. 1350The challenge/response protocols differ 1351in detail but all follow the general structure: 1352.P1 1353$C -> S: ~~ "nonce" sub C# 1354$S -> C: ~~ "nonce" sub S , "uid" sub S ,"domain" sub S# 1355$C -> A: ~~ "nonce" sub S , "uid" sub S , "domain" sub S ,# 1356 $"hostid" sub C , "uid" sub C# 1357$A -> C: ~~ K sub C roman "{" "nonce" sub S , "uid" sub C , "uid" sub S, K sub n roman "}",# 1358 $K sub S roman "{" "nonce" sub S , "uid" sub C , "uid" sub S, K sub n roman "}"# 1359$C -> S: ~~ K sub S roman "{" "nonce" sub S , "uid" sub C , "uid" sub S, K sub n roman "}",# 1360 $K sub n roman "{" "nonce" sub S roman "}"# 1361$S -> C: ~~ K sub n roman "{" "nonce" sub C roman "}"# 1362.P2 1363The password protocol is: 1364.P1 1365$C -> A: ~~ "uid" sub C# 1366$A -> C: ~~ K sub c roman "{" K sub n roman "}"# 1367$C -> A: ~~ K sub n roman "{" "password" sub "old" , "password" sub "new" roman "}"# 1368$A -> C: ~~ OK# 1369.P2 1370To avoid replay attacks, the pre-encryption 1371clear text for each of the protocols (as well as for p9sk1) includes 1372a tag indicating the encryption's role in the 1373protocol. We elided them in these outlines. 1374.SS 1375Protocol negotiation 1376.LP 1377Rather than require particular protocols for particular services, 1378we implemented a negotiation metaprotocol, 1379.I p9any , 1380which chooses the actual authentication protocol to use. 1381P9any 1382is used now by all native services on Plan 9. 1383.LP 1384The metaprotocol is simple. The callee sends a 1385null-terminated string of the form: 1386.P1 1387v.$n# $proto sub 1#@$domain sub 1# $proto sub 2#@$domain sub 2# ... 1388.P2 1389where 1390.I n 1391is a decimal version number, $proto sub k# 1392is the name of a protocol for which the 1393.CW factotum 1394has a key, and $domain sub k# 1395is the name of the domain in which the key is 1396valid. 1397The caller then responds 1398.P1 1399\f2proto\fP@\f2domain\fP 1400.P2 1401indicating its choice. 1402Finally the callee responds 1403.P1 1404OK 1405.P2 1406Any other string indicates failure. 1407At this point the chosen protocol commences. 1408The final fixed-length reply is used to make it easy to 1409delimit the I/O stream should the chosen protocol 1410require the caller rather than the callee to send the first message. 1411.LP 1412With this negotiation metaprotocol, the underlying 1413authentication protocols used for Plan 9 services 1414can be changed under any application just 1415by changing the keys known by the 1416.CW factotum 1417agents at each end. 1418.LP 1419P9any is vulnerable to man in the middle attacks 1420to the extent that the attacker may constrain the 1421possible choices by changing the stream. However, 1422we believe this is acceptable since the attacker 1423cannot force either side to choose algorithms 1424that it is unwilling to use. 1425.NH 1 1426Library Interface to Factotum 1427.LP 1428Although programs can access 1429.CW factotum 's 1430services through its file system interface, 1431it is more common to use a C library that 1432packages the interaction. 1433There are a number of routines in the library, 1434not all of which are relevant here, but a few 1435examples should give their flavor. 1436.LP 1437First, consider the problem of mounting a remote file server using 9P. 1438An earlier discussion showed how the 1439.CW fauth 1440and 1441.CW mount 1442system calls use an authentication file, 1443.CW afd , 1444as a capability, 1445but not how 1446.CW factotum 1447manages 1448.CW afd . 1449The library contains a routine, 1450.CW amount 1451(authenticated mount), that is used by most programs in preference to 1452the raw 1453.CW fauth 1454and 1455.CW mount 1456calls. 1457.CW Amount 1458engages 1459.CW factotum 1460to validate 1461.CW afd ; 1462here is the complete code: 1463.P1 1464.ta 3n +3n +3n +3n 1465int 1466amount(int fd, char *mntpt, 1467 int flags, char *aname) 1468{ 1469 int afd, ret; 1470 AuthInfo *ai; 1471 1472 afd = fauth(fd, aname); 1473 if(afd >= 0){ 1474 ai = auth_proxy(afd, amount_getkey, 1475 "proto=p9any role=client"); 1476 if(ai != NULL) 1477 auth_freeAI(ai); 1478 } 1479 ret = mount(fd, afd, mntpt, 1480 flags, aname); 1481 if(afd >= 0) 1482 close(afd); 1483 return ret; 1484} 1485.P2 1486where parameter 1487.CW fd 1488is a file descriptor returned by 1489.CW open 1490or 1491.CW dial 1492for a new connection to a file server. 1493The conversation with 1494.CW factotum 1495occurs in the call to 1496.CW auth_proxy , 1497which specifies, as a key query, 1498which authentication protocol to use 1499(here the metaprotocol 1500.CW p9any ) 1501and the role being played 1502.CW client ). ( 1503.CW Auth_proxy 1504will read and write the 1505.CW factotum 1506files, and the authentication file descriptor 1507.CW afd , 1508to validate the user's right to access the service. 1509If the call is successful, any auxiliary data, held in an 1510.CW AuthInfo 1511structure, is freed. 1512In any case, the 1513.CW mount 1514is then called with the (perhaps validated) 1515.CW afd. 1516A 9P server can cause the 1517.CW fauth 1518system call to fail, as an indication that authentication is 1519not required to access the service. 1520.LP 1521The second argument to 1522.CW auth_proxy 1523is a function, here 1524.CW amount_getkey , 1525to be called if secret information such as a password or 1526response to a challenge is required as part of the authentication. 1527This function, of course, will provide this data to 1528.CW factotum 1529as a 1530.CW key 1531message on the 1532.CW /mnt/factotum/ctl 1533file. 1534.LP 1535Although the final argument to 1536.CW auth_proxy 1537in this example is a simple string, in general 1538it can be a formatted-print specifier in the manner of 1539.CW printf , 1540to enable the construction of more elaborate key queries. 1541.LP 1542As another example, consider the Plan 9 1543.CW cpu 1544service, which exports local devices to a shell process on 1545a remote machine, typically 1546to connect the local screen and keyboard to a more powerful computer. 1547At heart, 1548.CW cpu 1549is a superset of a service called 1550.CW exportfs 1551[Pike93], 1552which allows one machine to see an arbitrary portion of the file name space 1553of another machine, such as to 1554export the network device to another machine 1555for gatewaying. 1556However, 1557.CW cpu 1558is not just 1559.CW exportfs 1560because it also delivers signals such as interrupt 1561and negotiates the initial environment 1562for the remote shell. 1563.LP 1564To authenticate an instance of 1565.CW cpu 1566requires 1567.CW factotum 1568processes on both ends: the local, client 1569end running as the user on a terminal 1570and the remote, server 1571end running as the host owner of the server machine. 1572Here is schematic code for the two ends: 1573.P1 1574.ta 3n +3n +3n +3n 1575/* client */ 1576int 1577p9auth(int fd) 1578{ 1579 AuthInfo *ai; 1580 1581 ai = auth_proxy(fd, auth_getkey, 1582 "proto=p9any role=client"); 1583 if(ai == NULL) 1584 return -1; 1585 1586 /* start cpu protocol here */ 1587} 1588 1589/* server */ 1590int 1591srvp9auth(int fd, char *user) 1592{ 1593 AuthInfo *ai; 1594 1595 ai = auth_proxy(fd, NULL, 1596 "proto=p9any role=server"); 1597 if(ai == NULL) 1598 return -1; 1599 /* set user id for server process */ 1600 if(auth_chuid(ai, NULL) < 0) 1601 return -1; 1602 1603 /* start cpu protocol here */ 1604} 1605.P2 1606.CW Auth_chuid 1607encapsulates the negotiation to change a user id using the 1608.CW caphash 1609and 1610.CW capuse 1611files of the (server) kernel. 1612Note that although the client process may ask the user for new keys, using 1613.CW auth_getkey , 1614the server machine, presumably a shared machine with a pseudo-user for 1615the host owner, sets the key-getting function to 1616.CW NULL . 1617.NH 1 1618Secure Store 1619.LP 1620.CW Factotum 1621keeps its keys in volatile memory, which must somehow be 1622initialized at boot time. 1623Therefore, 1624.CW factotum 1625must be 1626supplemented by a persistent store, perhaps 1627a floppy disk containing a key file of commands to be copied into 1628.CW /mnt/factotum/ctl 1629during bootstrap. 1630But removable media are a nuisance to carry and 1631are vulnerable to theft. 1632Keys could be stored encrypted on a shared file system, but 1633only if those keys are not necessary for authenticating to 1634the file system in the first place. 1635Even if the keys are encrypted under a user 1636password, a thief might well succeed with a dictionary attack. 1637Other risks of local storage are loss of the contents 1638through mechanical mishap or dead batteries. 1639Thus for convenience and 1640safety we provide a 1641.CW secstore 1642(secure store) server in the network to hold each user's permanent list of keys, a 1643.I key 1644.I file . 1645.LP 1646.CW Secstore 1647is a file server for encrypted data, 1648used only during bootstrapping. 1649It must provide strong 1650authentication and resistance to passive and active protocol attacks 1651while assuming nothing more from the client than a password. 1652Once 1653.CW factotum 1654has loaded the key file, further encrypted or authenticated 1655file storage can be accomplished by standard mechanisms. 1656.EQ 1657define mod % ~ roman "mod" ~ % 1658define sha1 % "sha1" % 1659.EN 1660.LP 1661The cryptographic technology that enables 1662.CW secstore 1663is a form of encrypted 1664key exchange 1665called PAK 1666[Boyk00], 1667analogous to 1668EKE 1669[Bell93], 1670SRP 1671[Wu98], 1672or 1673SPEKE 1674[Jabl]. 1675PAK was chosen 1676because it comes with a proof of equivalence in strength to 1677Diffie-Hellman; subtle flaws in some earlier encrypted key exchange 1678protocols and implementations have encouraged us to take special care. 1679In outline, the PAK protocol is: 1680.P1 1681$C -> S:~ C, g sup x H# 1682$S -> C:~ S, g sup y , hash(g sup xy , C, S)# 1683$C -> S:~ hash(g sup xy , S, C)# 1684.P2 1685where $H# is a preshared secret between client $C# and server $S#. 1686There are several variants of PAK, all presented in papers 1687mainly concerned with proofs of cryptographic properties. 1688To aid implementers, we have distilled a description of the specific 1689version we use into an Appendix to this paper. 1690The Plan 9 open source license provides for use of Lucent's 1691encrypted key exchange patents in this context. 1692.LP 1693As a further layer of defense against password theft, 1694we provide (within the encrypted channel $C -> S#) 1695information that is validated at a RADIUS server, 1696such as the digits from a hardware token 1697[RFC2138]. 1698This provides two-factor authentication, which potentially 1699requires tricking two independent administrators in any attack by 1700social engineering. 1701.LP 1702The key file stored on the server is encrypted with AES (Rijndael) using CBC 1703with a 10-byte initialization vector and trailing authentication padding. 1704All this is invisible to the user of 1705.CW secstore . 1706For that matter, it is invisible to the 1707.CW secstore 1708server as well; 1709if the AES Modes of Operation are standardized and a new encryption format 1710designed, it can be implemented by a client without change to the server. 1711The 1712.CW secstore 1713is deliberately not backed up; the user is expected to 1714use more than one 1715.CW secstore 1716or save the key file on removable media 1717and lock it away. 1718The user's password is hashed to create the $H# used 1719in the PAK protocol; a different hash of the password is used as 1720the file encryption key. 1721Finally, there is a command (inside the authenticated, 1722encrypted channel between client and 1723.CW secstore ) 1724to change passwords by sending 1725a new $H#; 1726for consistency, the client process must at the same time fetch and re-encrypt all files. 1727.LP 1728When 1729.CW factotum 1730starts, it dials the local 1731.CW secstore 1732and checks whether the user has an account. 1733If so, 1734it prompts for the user's 1735.CW secstore 1736password and fetches the key file. 1737The PAK protocol 1738ensures mutual authentication and prevents dictionary attacks on the password 1739by passive wiretappers or active intermediaries. 1740Passwords saved in 1741the key file can be long random strings suitable for 1742simpler challenge/response authentication protocols. 1743Thus the user need only remember 1744a single, weaker password to enable strong, ``single sign on'' authentication to 1745unchanged legacy applications scattered across multiple authentication domains. 1746.NH 1 1747Transport Layer Security 1748.LP 1749Since the Plan 9 operating system is designed for use in network elements 1750that must withstand direct attack, unguarded by firewall or VPN, we seek 1751to ensure that all applications use channels with appropriate mutual 1752authentication and encryption. 1753A principal tool for this is TLS 1.0 1754[RFC2246]. 1755(TLS 1.0 is nearly the same as SSL 3.0, 1756and our software is designed to interoperate 1757with implementations of either standard.) 1758.LP 1759TLS defines a record layer protocol for message integrity and privacy 1760through the use of message digesting and encryption with shared secrets. 1761We implement this service as a kernel device, though it could 1762be performed at slightly higher cost by invoking a separate program. 1763The library interface to the TLS kernel device is: 1764.P1 1765int pushtls(int fd, char *hashalg, 1766 char *cryptalg, int isclient, 1767 char *secret, char *dir); 1768.P2 1769Given a file descriptor, the names of message digest and 1770encryption algorithms, and the shared secret, 1771.CW pushtls 1772returns a new file descriptor for the encrypted connection. 1773(The final argument 1774.CW dir 1775receives the name of the directory in the TLS device that 1776is associated with the new connection.) 1777The function is named by analogy with the ``push'' operation 1778supported by the stream I/O system of Research Unix and the 1779first two editions of Plan 9. 1780Because adding encryption is as simple as replacing one 1781file descriptor with another, adding encryption to a particular 1782network service is usually trivial. 1783.LP 1784The Plan 9 shared key authentication protocols establish a shared 56-bit secret 1785as a side effect. 1786Native Plan 9 network services such as 1787.CW cpu 1788and 1789.CW exportfs 1790use these protocols for authentication and then invoke 1791.CW pushtls 1792with the shared secret. 1793.LP 1794Above the record layer, TLS specifies a handshake protocol using public keys 1795to establish the session secret. 1796This protocol is widely used with HTTP and IMAP4 1797to provide server authentication, though with client certificates it could provide 1798mutual authentication. The library function 1799.P1 1800int tlsClient(int fd, TLSconn *conn) 1801.P2 1802handles the initial handshake and returns the result of 1803.CW pushtls . 1804On return, it fills the 1805.CW conn 1806structure with the session ID used 1807and the X.509 certificate presented by the 1808server, but makes no effort to verify the certificate. 1809Although the original design intent of X.509 certificates expected 1810that they would be used with a Public Key Infrastructure, 1811reliable deployment has been so long delayed and problematic 1812that we have adopted the simpler policy of just using the 1813X.509 certificate as a representation of the public key, 1814depending on a locally-administered directory of SHA1 thumbprints 1815to allow applications to decide which public keys to trust 1816for which purposes. 1817.NH 1 1818Related Work and Discussion 1819.LP 1820Kerberos, one of the earliest distributed authentication 1821systems, keeps a set of authentication tickets in a temporary file called 1822a ticket cache. The ticket cache is protected by Unix file permissions. 1823An environment variable containing the file name of the ticket cache 1824allows for different ticket caches in different simultaneous login sessions. 1825A user logs in by typing his or her Kerberos password. 1826The login program uses the Kerberos password to obtain a temporary 1827ticket-granting ticket from the authentication server, initializes the 1828ticket cache with the ticket-granting ticket, and then forgets the password. 1829Other applications can use the ticket-granting ticket to sign tickets 1830for themselves on behalf of the user during the login session. 1831The ticket cache is removed when the user logs out 1832[Stei88]. 1833The ticket cache relieves the user from typing a password 1834every time authentication is needed. 1835.LP 1836The secure shell SSH develops this idea further, replacing the 1837temporary file with a named Unix domain socket connected to 1838a user-level program, called an agent. 1839Once the SSH agent is started and initialized with one or 1840more RSA private keys, SSH clients can employ it 1841to perform RSA authentications on their behalf. 1842In the absence of an agent, SSH typically uses RSA keys 1843read from encrypted disk files or uses passphrase-based 1844authentication, both of which would require prompting the user 1845for a passphrase whenever authentication is needed 1846[Ylon96]. 1847The self-certifying file system SFS uses a similar agent 1848[Kami00], 1849not only for moderating the use of client authentication keys 1850but also for verifying server public keys 1851[Mazi99]. 1852.LP 1853.CW Factotum 1854is a logical continuation of this evolution, 1855replacing the program-specific SSH or SFS agents with 1856a general agent capable of serving a wide variety of programs. 1857Having one agent for all programs removes the need 1858to have one agent for each program. 1859It also allows the programs themselves to be protocol-agnostic, 1860so that, for example, one could build an SSH workalike 1861capable of using any protocol supported by 1862.CW factotum , 1863without that program knowing anything about the protocols. 1864Traditionally each program needs to implement each 1865authentication protocol for itself, an $O(n sup 2 )# coding 1866problem that 1867.CW factotum 1868reduces to $O(n)#. 1869.LP 1870Previous work on agents has concentrated on their use by clients 1871authenticating to servers. 1872Looking in the other direction, Sun Microsystem's 1873pluggable authentication module (PAM) is one 1874of the earliest attempts to 1875provide a general authentication mechanism for Unix-like 1876operating systems 1877[Sama96]. 1878Without a central authority like PAM, system policy is tied 1879up in the various implementations of network services. 1880For example, on a typical Unix, if a system administrator 1881decides not to allow plaintext passwords for authentication, 1882the configuration files for a half dozen different servers \(em 1883.CW rlogind , 1884.CW telnetd , 1885.CW ftpd , 1886.CW sshd , 1887and so on \(em 1888need to be edited. 1889PAM solves this problem by hiding the details of a given 1890authentication mechanism behind a common library interface. 1891Directed by a system-wide configuration file, 1892an application selects a particular authentication mechanism 1893by dynamically loading the appropriate shared library. 1894PAM is widely used on Sun's Solaris and some Linux distributions. 1895.LP 1896.CW Factotum 1897achieves the same goals 1898using the agent approach. 1899.CW Factotum 1900is the only process that needs to create 1901capabilities, so all the network servers can run as 1902untrusted users (e.g., 1903Plan 9's 1904.CW none 1905or Unix's 1906.CW nobody ), 1907which greatly reduces the harm done if a server is buggy 1908and is compromised. 1909In fact, if 1910.CW factotum 1911were implemented on Unix along with 1912an analogue to the Plan 9 capability device, venerable 1913programs like 1914.CW su 1915and 1916.CW login 1917would no longer need to be installed ``setuid root.'' 1918.LP 1919Several other systems, such as Password Safe [Schn], 1920store multiple passwords in an encrypted file, 1921so that the user only needs to remember one password. 1922Our 1923.CW secstore 1924solution differs from these by placing the storage in 1925a hardened location in the network, so that the encrypted file is 1926less liable to be stolen for offline dictionary attack and so that 1927it is available even when a user has several computers. 1928In contrast, Microsoft's Passport system 1929[Micr] 1930keeps credentials in 1931the network, but centralized at one extremely-high-value target. 1932The important feature of Passport, setting up trust relationships 1933with e-merchants, is outside our scope. 1934The 1935.CW secstore 1936architecture is almost identical to 1937Perlman and Kaufman's 1938[Perl99] 1939but with newer EKE technology. 1940Like them, we chose to defend mainly against outside attacks 1941on 1942.CW secstore ; 1943if additional defense of the files on the server 1944itself is desired, one can use distributed techniques 1945[Ford00]. 1946.LP 1947We made a conscious choice of placing encryption, message integrity, 1948and key management at the application layer 1949(TLS, just above layer 4) rather than at layer 3, as in IPsec. 1950This leads to a simpler structure for the network stack, easier 1951integration with applications and, most important, easier network 1952administration since we can recognize which applications are misbehaving 1953based on TCP port numbers. TLS does suffer (relative to IPsec) from 1954the possibility of forged TCP Reset, but we feel that this is adequately 1955dealt with by randomized TCP sequence numbers. 1956In contrast with other TLS libraries, Plan 9 does not 1957require the application to change 1958.CW write 1959calls to 1960.CW sslwrite 1961but simply to add a few lines of code at startup 1962[Resc01]. 1963.NH 1 1964Conclusion 1965.LP 1966Writing safe code is difficult. 1967Stack attacks, 1968mistakes in logic, and bugs in compilers and operating systems 1969can each make it possible for an attacker 1970to subvert the intended execution sequence of a 1971service. 1972If the server process has the privileges 1973of a powerful user, such as 1974.CW root 1975on Unix, then so does the attacker. 1976.CW Factotum 1977allows us 1978to constrain the privileged execution to a single 1979process whose core is a few thousand lines of code. 1980Verifying such a process, both through manual and automatic means, 1981is much easier and less error prone 1982than requiring it of all servers. 1983.LP 1984An implementation of these ideas is in Plan 9 from Bell Labs, Fourth Edition, 1985freely available from \f(CWhttp://\%plan9.bell-labs.com/\%plan9\fP. 1986.SH 1987Acknowledgments 1988.LP 1989William Josephson contributed to the implementation of password changing in 1990.CW secstore . 1991We thank Phil MacKenzie and Martín Abadi for helpful comments on early parts 1992of the design. 1993Chuck Blake, 1994Peter Bosch, 1995Frans Kaashoek, 1996Sape Mullender, 1997and 1998Lakshman Y. N., 1999predominantly Dutchmen, gave helpful comments on the paper. 2000Russ Cox is supported by a fellowship from the Fannie and John Hertz Foundation. 2001.SH 2002References 2003.LP 2004[Bell93] 2005S.M. Bellovin and M. Merritt, 2006``Augmented Encrypted Key Exchange,'' 2007Proceedings of the 1st ACM Conference on Computer and Communications Security, 1993, pp. 244 - 250. 2008.LP 2009[Boyk00] 2010Victor Boyko, Philip MacKenzie, and Sarvar Patel, 2011``Provably Secure Password-Authenticated Key Exchange using Diffie-Hellman,'' 2012Eurocrypt 2000, 156\-171. 2013... http://www.bell-labs.com/who/philmac/research/pak-final.ps.gz 2014.LP 2015[RFC2246] 2016T . Dierks and C. Allen, 2017``The TLS Protocol, Version 1.0,'' 2018RFC 2246. 2019.LP 2020[Ford00] 2021Warwick Ford and Burton S. Kaliski, Jr., 2022``Server-Assisted Generation of a Strong Secret from a Password,'' 2023IEEE Fifth International Workshop on Enterprise Security, 2024National Institute of Standards and Technology (NIST), 2025Gaithersburg MD, June 14 - 16, 2000. 2026.LP 2027[Jabl] 2028David P. Jablon, 2029``Strong Password-Only Authenticated Key Exchange,'' 2030\f(CWhttp://\%integritysciences.com/\%speke97.html\fP. 2031.LP 2032[Kami00] 2033Michael Kaminsky. 2034``Flexible Key Management with SFS Agents,'' 2035Master's Thesis, MIT, May 2000. 2036.LP 2037[Mack] 2038Philip MacKenzie, 2039private communication. 2040.LP 2041[Mazi99] 2042David Mazières, Michael Kaminsky, M. Frans Kaashoek and Emmett Witchel, 2043``Separating key management from file system security,'' 2044Symposium on Operating Systems Principles, 1999, pp. 124-139. 2045.LP 2046[Micr] 2047Microsoft Passport, 2048\f(CWhttp://\%www.passport.com/\fP. 2049.LP 2050[Perl99] 2051Radia Perlman and Charlie Kaufman, 2052``Secure Password-Based Protocol for Downloading a Private Key,'' 2053Proc. 1999 Network and Distributed System Security Symposium, 2054Internet Society, January 1999. 2055.LP 2056[Pike95] 2057Rob Pike, Dave Presotto, Sean Dorward, Bob Flandrena, Ken Thompson, Howard Trickey, and Phil Winterbottom, 2058``Plan 9 from Bell Labs,'' 2059Computing Systems, \f3\&8\fP, 3, Summer 1995, pp. 221-254. 2060.LP 2061[Pike93] 2062Rob Pike, Dave Presotto, Ken Thompson, Howard Trickey, Phil Winterbottom, 2063``The Use of Name Spaces in Plan 9,'' 2064Operating Systems Review, \f3\&27\fP, 2, April 1993, pp. 72-76 2065(reprinted from Proceedings of the 5th ACM SIGOPS European Workshop, 2066Mont Saint-Michel, 1992, Paper nº 34). 2067.LP 2068[Resc01] 2069Eric Rescorla, 2070``SSL and TLS: Designing and Building Secure Systems,'' 2071Addison-Wesley, 2001. ISBN 0-201-61598-3, p. 387. 2072.LP 2073[RFC2138] 2074C. Rigney, A. Rubens, W. Simpson, S. Willens, 2075``Remote Authentication Dial In User Service (RADIUS),'' 2076RFC2138, April 1997. 2077.LP 2078[RiLa] 2079Ronald L. Rivest and Butler Lampson, 2080``SDSI\(emA Simple Distributed Security Infrastructure,'' 2081\f(CWhttp://\%theory.lcs.mit.edu/\%~rivest/\%sdsi10.ps\fP. 2082.LP 2083[Schn] 2084Bruce Schneier, Password Safe, 2085\f(CWhttp://\%www.counterpane.com/\%passsafe.html\fP. 2086.LP 2087[Sama96] 2088Vipin Samar, 2089``Unified Login with Pluggable Authentication Modules (PAM),'' 2090Proceedings of the Third ACM Conference on Computer Communications and Security, 2091March 1996, New Delhi, India. 2092... http://www1.acm.org/pubs/articles/proceedings/commsec/238168/p1-samar/p1-samar.pdf 2093.LP 2094[Stei88] 2095Jennifer G. Steiner, Clifford Neumann, and Jeffrey I. Schiller, 2096``\fIKerberos\fR: An Authentication Service for Open Network Systems,'' 2097Proceedings of USENIX Winter Conference, Dallas, Texas, February 1988, pp. 191\-202. 2098... ftp://athena-dist.mit.edu/pub/kerberos/doc/usenix.PS 2099.LP 2100[Wu98] 2101T. Wu, 2102``The Secure Remote Password Protocol,'' 2103Proceedings of 2104the 1998 Internet Society Network and Distributed System Security 2105Symposium, San Diego, CA, March 1998, pp. 97-111. 2106.LP 2107[Ylon96] 2108Ylonen, T., 2109``SSH\(emSecure Login Connections Over the Internet,'' 21106th USENIX Security Symposium, pp. 37-42. San Jose, CA, July 1996. 2111.SH 2112Appendix: Summary of the PAK protocol 2113.LP 2114Let $q>2 sup 160# and $p>2 sup 1024# be primes 2115such that $p=rq+1# with $r# not a multiple of $q#. 2116Take $h ∈ Z sub p sup *# such that $g == h sup r# is not 1. 2117These parameters may be chosen by the NIST algorithm for DSA, 2118and are public, fixed values. 2119The client $C# knows a secret $pi# 2120and computes $H == (H sub 1 (C, ~ pi )) sup r# and $H sup -1#, 2121where $H sub 1# is a hash function yielding a random element of $Z sub p sup *#, 2122and $H sup -1# may be computed by gcd. 2123(All arithmetic is modulo $p#.) 2124The client gives $H sup -1# to the server $S# ahead of time by a private channel. 2125To start a new connection, the client generates a random value $x#, 2126computes $m == g sup x H#, 2127then calls the server and sends $C# and $m#. 2128The server checks $m != 0 mod p#, 2129generates random $y#, 2130computes $ mu == g sup y#, 2131$ sigma == (m H sup -1 ) sup y#, 2132and sends $S#, $mu#, $k == sha1 ( roman "\"server\"", C, S, m, mu , sigma , H sup -1 )#. 2133Next the client computes $sigma = mu sup x#, 2134verifies $k#, 2135and sends $k' == sha1 ( roman "\"client\"", C, S, m, mu , sigma , H sup -1 )#. 2136The server then verifies $k'# and both sides begin 2137using session key $K == sha1 ( roman "\"session\"", C, S, m, mu , sigma , H sup -1 )#. 2138In the published version of PAK, the server name $S# 2139is included in the initial 2140hash $H#, but doing so is inconvenient in our application, 2141as the server may be known by various equivalent names. 2142.LP 2143MacKenzie has shown 2144[Mack] 2145that the 2146equivalence proof [Boyk00] 2147can be adapted to cover our version. 2148