forsyth20121205-174063a80cc13 years agoHistory
278 lines · 6.6 KB · Text
RawDownload
.TH SECSTORE 2.SH NAMEsecstore \- fetch data from Plan 9's secure storage service.SH SYNOPSIS.EXinclude "dial.m";include "secstore.m";secstore := load Secstore Secstore->PATH; Maxfilesize: con 128*1024;	# default init:       fn();privacy:    fn(): int;cansecstore:    fn(addr: string, user: string): int;mkseckey:   fn(pass: string): array of byte;dial:       fn(addr: string): ref Dial->Connection;auth:       fn(conn: ref Dial->Connection, user: string, seckey: array of byte):                (string, string);connect:    fn(addr: string, user: string, seckey: array of byte):                (ref Dial->Connection, string, string);sendpin:    fn(conn: ref Dial->Connection, pin: string): int;files:       fn(conn: ref Dial->Connection):                list of (string, int, string, string, array of byte);getfile:    fn(conn: ref Dial->Connection, name: string,                maxsize: int): array of byte;putfile:    fn(conn: ref Dial->Connection, name: string, data: array of byte): int;remove:     fn(conn: ref Dial->Connection, file: string): int;bye:        fn(conn: ref Dial->Connection); mkfilekey:   fn(pass: string): array of byte;decrypt:    fn(data: array of byte, filekey: array of byte): array of byte;encrypt:    fn(data: array of byte, filekey: array of byte): array of byte;erasekey:   fn(key: array of byte); lines:      fn(file: array of byte): list of array of byte;.EE.SH DESCRIPTION.B Secstoreestablishes a secure authenticated connection with a Plan 9.I secstoreservice (or equivalent, such as Plan 9 from User Space),that can then be used to fetch and decrypt data files, such as the.B factotumfile containing the initial keys for an instance of.IR factotum (4).The module's functions hold the file descriptors for the connection in a.BR Dial->Connectionvalue,as returned by.IR dial (2).The.I addrparameter that gives the network address of the.I secstoreservice is also as defined in.IR dial (2).A nil value defaults to.BR "net!$auth!secstore" ,for translation in the usual way by.IR cs (8)..PP.B Initmust be called before invoking any other operation of the module..PP.B Privacyensures the memory of the calling process cannot be read, for instance by.IR prog (3).It returns zero on success and a negative value on failure..PP.B Cansecstorereturns true if a connection can be made to a.I secstoreat network address.IR addr ,and the given.I userhas a.I secstoreaccount;it returns false otherwise..PPUsers authenticate themselves to the service using a secret key and a special protocol that does notreveal the key itself to the remote service.The textual secret (eg, password or pass phrase) is not used directly by the following functions,but only after transformation by.BR mkseckey ,which hashes it into an array of bytes.That is the.I keyparameter to the functions..PP.B Dialdials the.I secstoreat network address.I addr(as defined by.IR dial (2))and returns a reference to the resulting.BR Dial->Connection .It returns nil on an error and sets the error string..PP.B Authauthenticates a fresh connection as belonging to a given.I userof the service.The parameter.I connrefers to the.B Dial->Connectionvalue representing the connection..I Usernames a user registered with the service.The parameter.I seckeyis the result of applying.B mkseckeyto the user's secret..I Authreturns a tuple.BI ( srvname,\ diag )..I Srvnameis the service name configured in the remote host (often simply.BR secstore ).On an error,.I srvnameis nil, and.I diagis a diagnostic.If the remote servicehas been configured to demand extra authentication data, then.I diagcontains a demand for it.Currently the only such value is.RB ` need pin ';call.B sendpinto provide it to the connection.If.B sendpinsucceeds, it returns zero, and.I conncan be used normally; on error,.B sendpinreturns -1 and the connection cannot be used..PP.B Connectcombines the actions of.B dialand.BR auth :dials the.I secstoreat.IR addr ,and mutually authenticates the server and the given.I userusing the user's secret.I keyfor that service.It returns a tuple.BI ( conn,\ srvname,\ diag ),where each component is as described for.B dialand.B authabove.On an error,.I connis nil, and.I diagcontains a diagnostic..PP.B Getfileretrieves the file.I namefrom the secure store, and returns its contents as an array of bytes..I Maxsizegives the largest acceptable file size; if the value is zero or negative,a large value is used by default.The files stored on the service are separately encrypted under the user's secret key..B Mkfilekeytakes a textual secret.I keyand returns a hash of it as an array of bytes,suitable for use as the.I filekeyparameter in subsequent calls to.BR decrypt .(The.I filekeyis not the same value as the.I seckeyused for initial authentication, although the secret text is the same.).PP.B Putfilewrites.I dataunder file.I nameto the secure store, overwriting a possibly existing file by that name..I Datashould already be encrypted.The caller can arrange this by calling.BR encrypt ..B Putfilereturns 0 on success and a negative value on error..PP.B Removedeletes the given.I filefrom the server.It returns 0 on success and a negative value on error..PP.B Decryptdecrypts the.I datapreviously fetched from a file on the secure store.It uses the.I filekeyproduced by.B mkfilekeyto decrypt the data in place (ie, modifying the contents of.IR data )and returns a slice of.I datathat excludes any headers and trailers in the encoding.It returns nil if the file could not be decrypted (usually because the.I keyvalue is not actually the encryption key)..PP.B Encryptdoes the opposite of.BR decrypt .Given plain.I dataand.I filekeyproduced by.BR mkfilekey ,it returns an encrypted version of data, including headers and trailers.This data is suitable for writing to the secure store with.BR putfile ..PP.B Erasekeyclears the bytes of.I keyto zero; it should be called on every value produced by.B mkfilekeyand.BR mkseckey ,after use,but can also be used on the data arrays returned by.B getfileand.BR decrypt ..PP.B Linesreturns a list of slices of.IR file ,representing each line of.I filein turn (including newline)..IR Factotum (4)for instance requires keys to be written to its control file one at a time..PP.B Byecloses the connection to the.IR secstore ..SH SOURCE.B /appl/lib/secstore.b.SH DIAGNOSTICSAs well as returning the error values described above, functions set the system error string..SH SEE ALSO.IR crypt (1),.IR secstore (1),.IR factotum (2),.IR factotum (4)