Add some configure bits for GSS-API

rxgk will require gss_pseudo_random and might want a couple other
krb5-specific bits.  We'll also need substvars to tell whether or
not we can try building these things.

Change-Id: Id18eb3f554605875696095eb40c25ec54df1f74b
Reviewed-on: http://gerrit.openafs.org/10561
Reviewed-by: Chas Williams - CONTRACTOR <chas@cmf.nrl.navy.mil>
Reviewed-by: D Brashear <shadow@your-file-system.com>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Add rxgk boilerplate

Just the skeleton of what needs to be there.  The actual import is split
over multiple commits, to make the reviewer's burden more manageable.

Error table, protocol description, and stubs for the security object
routines, with header to declare them.

The public header rxgk.h currently only contains a few typedefs and the
NewSecurityObject prototypes, and includes the RPC interface and com_err
code headers.

Change-Id: I7893f78119bb4aef12112cc1e51e1ec69de326c2
Reviewed-on: http://gerrit.openafs.org/10562
Reviewed-by: Chas Williams - CONTRACTOR <chas@cmf.nrl.navy.mil>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: D Brashear <shadow@your-file-system.com>
Dummy Makefile for rxgk

Include a libtool export symbol list for the shared library, which
only has the client RPC calls and the NewFooSecurityObject primitives
for now, since that's all that's stubbed out.

Also connect the rxgk directory up to be buildable from the root, but
nothing depends on it yet so it will not be built.

Looking ahead, build a libafsrpc_rxgk.la object.

Change-Id: I12ddefbdaa1ad4845649e3a32efdeaaa21b5e9b7
Reviewed-on: http://gerrit.openafs.org/10563
Reviewed-by: Chas Williams - CONTRACTOR <chas@cmf.nrl.navy.mil>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: D Brashear <shadow@your-file-system.com>
libafs: Speed up afs_CheckTokenCache

On systems with a large number of PAGs and files in use, the
periodic daemon job that checks for expired credentials and
cleans up the axs cache can run for a very long time.  This
can lead to kernel soft lockups and eventually hang processes
and file access because of unavailable locks.

Rework the scanning logic in afs_CheckTokenCache to make the
scanning more efficient in most real world cases.  On a test
system accessing ~4000 files from processes in 1000 PAGs, this
has been observed to reduce the runtime of afs_CheckTokenCache
from a problematic ~70s down to about 0.7s.

Additionally, this changes the conditions in which an axscache is
discarded. uid+cell (rather than just uid) must now match, and
if no matching unixuser is found, it will also be discarded.

Adapted from code from Jeffrey Altman who provided the original
loop algorithm and code.

Change-Id: I65b275b4244b3b6ab65453623bb8729530a9e1a6
Reviewed-on: http://gerrit.openafs.org/11123
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Chas Williams - CONTRACTOR <chas@cmf.nrl.navy.mil>
Reviewed-by: D Brashear <shadow@your-file-system.com>
Build both pthreaded and LWP rxgk library

There are no object files built by this makefile that are not
controlled by libtool, so it is easy for us to support both LWP
and pthread versions of the code.  This lets us build a librxgk.a,
providing just the security class functionality of rxgk without
the GSS negotiation portions.

If we did not build the LWP librxgk.a, we would need to sprinkle
conditionals on AFS_PTHREAD_ENV everywhere throughout the tree
where rxgk functionality is used, which is tedious.  It is much
cleaner to be able to always call such routines, even if sometimes
the implementations are stubs that return failure.  As it turns
out, most of the time the functionality is available anyway.

librxgk.a is deliberately not installed; it is provided only so
that in-tree binaries will be linkable.

Change-Id: I12ddefbdaa1ad4845649e3a32efdeaaa21b5e9b7
Configure glue for rxgk

Add an --enable-rxgk switch to control whether the feature is used.
For now, just build the code as a dependency of finale, but we will
phase it in to other parts of the tree as appropriate.

We want to always build as much code as we can to benefit from the
automated build testing, so build rxgk if there is an appropriate
GSSAPI library available, but do not install anything unless the
configure argument was given.

Provide a symbol in afsconfig.h so that code using rxgk can be
conditionally compiled.

Change-Id: Iab661d47aac77c1a238e809362015b869752df18
Export a few krb5 routines for rxgk

We need oafs_h_krb5_generate_random_block when generating random
keys and oafs_h_krb5_crypto_fx_cf2 for CombineTokens.
Having oafs_h_krb5_crypto_prf_length proves very convenient for
key derivation of transport keys, so move it to the public header
and export it.
oafs_h_krb5_enctype_keysize is needed so that we can tell whether or not we
need to pass through random_to_key() when making rxgk_keys.
oafs_h_krb5_random_to_key is needed for that random_to_key() operation.

Change-Id: Ia34c8028b07df203b3885157e2d46c6bb512f608
Add rxgk_crypto_rfc3961.c

rxgk wrappers around an external crypto library, in this case, our
in-tree rfc3961 library.  Primitives for encryption/decryption and
MIC/VerifyMIC, ways to generate and free rxgk_key objects, etc..

Change-Id: I7525086043baf54f5c3019b3f5ab3495760c4236
Add RXGK_NOW()

A quick routine to get the current timestamp.

Change-Id: I0051b5c8e5ad61e35431d97454bf2741daba90cb
Export {Get,Set}ServiceSpecific from liboafs_rx.la

rxgk will use service-specific data.

Change-Id: Id9e2d4b9920e771e1583b9362e61de6216c246b4
Add rxgk_util.c

A few helper routines for the security class implementation, and
routines to set and retrieve a getkey function from rx service-specific
data.

Change-Id: I395802b6c3b2436df4b00906544fc797f3e12e9b
Add rxgk_token.c

Routines for constructing tokens (both regular and printed), extracting
and decrypting tokens, and helpers therein.

Provide the ability to print a token using a given session key and
using a random session key; the former is useful for certain variants
of localauth wherein a dummy GSS negotiation is performed with the
same identity acting as initiator and acceptor.

Change-Id: I0cde7fd0cdf9a27777523cd502b21bdccef41dcc
Add rxgk_gss.c

All the routines which deal with GSSAPI types.
This is, in practice, how the client gets a token, and the server
backend for GSSNegotiate().

These routines are split out into a separate file, and their prototypes
hidden behind ifndef KERNEL, because we need to allow rxgk to be usable
in the absence of a gssapi library, which is the case in the kernel.

Provide a compatibility definition of GSS_C_PRF_KEY_FULL, as there
are known implementations in the wild that provide the function but
do not provide the keyusage constants.

Change-Id: Id2966de07853dd6a74cb40225851728d2422421c
Implement SRXGK_GSSNegotiate()

In-kernel we must fail; the userspace implementation is already
in the tree in rxgk_gss.c.

Change-Id: Id715e3287df5921a20aebe4e65259fd2097dc2b4
Add rxgk_packet.c

Routines to apply and verify encryption and MICs to the data in
rx packets.  Backend to the rxgk_crypto framework for the actual
crypto operations.

Change-Id: I724efacf7df1d688c0d61a327fa9ee9c8168d715
Implement the rxgk server routines

Provide non-trivial implementations of the security class routines
used by the server, along with helpers as necessary.

In addition to the normal NewServerSecurityObject routine, provide
wrappers NewServiceSecObj and NewEphemeralService_SecObj that create
the security object, create an rx service for the key negotiation service
needed for clients to negotiate tokens useful with this server security
object, and register the getkey function used for the security object
as service-specific data to be used when encrypting tokens produced by
this rx service.  The Ephemeral variant creates a random token-encrypting
key for use by the service, so no getkey routine needs to be supplied
by the caller.

The identity supplied in a client's token is given as a list of
PrAuthNames; we assume that at most one name is supplied at present,
as the meaning of compound identities (and the use of compound
identities for keyed cache managers) is not fully specified yet.
Convert the PrAuthName to an rx_identity for caching in the server
connection state, as the rx_identity type is more compatible with
superuser checks on the connection.

Also provide an rxgk_GetServerInfo routine which extracts the cached
identity, for use in libauth when making superuser checks.
This moves our dependency on rx_identity from the private data structures
into the public header, so move the nested include accordingly.

Change-Id: I0f48b69d4ab758d8a4d76ebfb1daf3009c4fe060
Implement rxgk client security object routines

Also add rxgk_NegotiateSecurityObject, a routine that creates
an rxnull connection to a target server, obtains a token using
the GSSNegotiate RPC on that connection, and uses the resulting
token to make an rxgk connection to that same server.

Change-Id: Ic7e11b02cb1573cfdb6d11d4de9a77ab1c563262
Implement SRXGK_CombineTokens

Most of the logic we need is already in place in rxgk_token.c; we just
need to pull out the token data structures, combine the identity lists,
and call into that code.

Change-Id: I68dd5dffab579d89601a55b8ed82961f8e12fc1b
Build rxgk support into libafsrpc

This is done rather differently for the shared and static libafsrpc
forms.  For the shared library, we can add a dependency on the shared
$(GSSAPI_LIBS) and link in liboafs_rxgk.la directly.  libafsrpc_rxgk.la
(which only has stubs for the rxgk GSS-using routines) is linked into
the static library, so that it remains useful for statically linking
applications.  Consumers of libafsrpc.a need not be modified in
accordance with this change.

Change-Id: I76c0329ba842fb0d4d66534810b114a0813c90a0
BuildServerSecurityObjects allocate for rxgk

Don't do anything with it for now, just leave a place in the
array.

Change-Id: I304e0f6bcf7d3b2a2cb46c976f41e09809a436db