Class GSIRequestHandler
- java.lang.Object
-
- org.dcache.xrootd.plugins.authn.gsi.GSIRequestHandler
-
- Direct Known Subclasses:
GSIClientRequestHandler,GSIServerRequestHandler
public abstract class GSIRequestHandler extends java.lang.ObjectShared settings and functionality for processing both client and server GSI authentication requests.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringASYNC_CIPHER_MODERSA algorithm, no block chaining mode (not a block-cipher) and PKCS1 padding, which is recommended to be used in conjunction with RSAprotected DHBufferHandlerbufferHandlerprotected java.lang.Stringchallengestatic intCHALLENGE_BYTESprotected GSICredentialManagercredentialManagerstatic java.lang.StringCRYPTO_MODEstatic java.lang.StringCRYPTO_MODE_NO_PADprotected DHSessiondhSessionprotected longlastRequestprotected static org.slf4j.LoggerLOGGERstatic longMAX_TIME_SKEWMaximum request time skew.protected booleannoPaddingstatic intPROTO_PRE_DELEGATIONstatic intPROTO_WITH_DELEGATIONstatic java.lang.StringPROTOCOLstatic intPROTOCOL_VERSIONstatic java.lang.StringPUBLIC_KEY_ALGORITHMFor use in encoding/decoding X509 public keys.static java.lang.StringPUBLIC_KEY_FOOTERstatic java.lang.StringPUBLIC_KEY_HEADERprotected static java.security.SecureRandomRANDOMprotected RSASessionrsaSessionstatic java.lang.StringSESSION_IV_DELIMRandom session IV.static intSESSION_IV_LENstatic java.lang.StringSUPPORTED_CIPHER_ALGORITHMwe limit ourselves to AES-128 with CBC blockmode.static java.lang.StringSUPPORTED_DIGESTSstatic intSYNC_CIPHER_BLOCKSIZEBlocksize in bytesstatic java.lang.StringSYNC_CIPHER_MODE_PADDEDSync cipher mode supported by the server.static java.lang.StringSYNC_CIPHER_MODE_UNPADDEDstatic java.lang.StringSYNC_CIPHER_NAME
-
Constructor Summary
Constructors Modifier Constructor Description protectedGSIRequestHandler(GSICredentialManager credentialManager)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected NestedBucketBufferdecryptMainBucketWithSessionKey(java.util.Map<XrootdSecurityProtocol.BucketType,XrootdBucket> receivedBuckets, java.lang.String step)Assumes the dhSession has been finalized.protected byte[]dhParams(boolean sign)protected java.security.cert.X509Certificate[]extractChain(java.util.Map<XrootdSecurityProtocol.BucketType,XrootdBucket> nestedBuckets)Pull out the string content of the kXRS_x509 bucket and convert it into a cert chain.protected voidfinalizeSessionKey(java.util.Map<XrootdSecurityProtocol.BucketType,XrootdBucket> receivedBuckets, XrootdSecurityProtocol.BucketType bucketType)For the pre-4.9 protocol, the DH client params are sent in the clear (unsigned) in the kXRS_puk bucket.protected static intfindSessionIVLen(java.lang.String cipher)static java.lang.StringgenerateChallengeString()Generate a new challenge string to be used in server-client communicationabstract intgetProtocolVersion()protected abstract java.lang.StringgetSyncCipherMode()protected booleanisRequestExpired()protected XrootdBucketpostProcessMainBucket(java.util.Map<XrootdSecurityProtocol.BucketType,XrootdBucket> buckets, java.util.Optional<java.lang.String> serializedX509, int step)Generate a new challenge string.protected java.security.cert.X509Certificate[]processRSAVerification(java.util.Map<XrootdSecurityProtocol.BucketType,XrootdBucket> nestedBuckets, java.util.Optional<java.security.PublicKey> toMatch)protected voidupdateLastRequest()protected java.lang.StringvalidateCiphers(java.lang.String[] algorithms)protected voidvalidateCryptoMode(java.lang.String cryptoMode)protected java.lang.StringvalidateDigests(java.lang.String[] digests)protected voidverifySignedRTag(java.util.Map<XrootdSecurityProtocol.BucketType,XrootdBucket> nestedBuckets)From the main bucket extract the challenge tag signed by the sender.
-
-
-
Field Detail
-
LOGGER
protected static org.slf4j.Logger LOGGER
-
PROTOCOL
public static final java.lang.String PROTOCOL
- See Also:
- Constant Field Values
-
PROTO_WITH_DELEGATION
public static final int PROTO_WITH_DELEGATION
- See Also:
- Constant Field Values
-
PROTO_PRE_DELEGATION
public static final int PROTO_PRE_DELEGATION
- See Also:
- Constant Field Values
-
PROTOCOL_VERSION
public static final int PROTOCOL_VERSION
- See Also:
- Constant Field Values
-
CRYPTO_MODE
public static final java.lang.String CRYPTO_MODE
- See Also:
- Constant Field Values
-
CRYPTO_MODE_NO_PAD
public static final java.lang.String CRYPTO_MODE_NO_PAD
- See Also:
- Constant Field Values
-
SUPPORTED_CIPHER_ALGORITHM
public static final java.lang.String SUPPORTED_CIPHER_ALGORITHM
we limit ourselves to AES-128 with CBC blockmode.- See Also:
- Constant Field Values
-
SUPPORTED_DIGESTS
public static final java.lang.String SUPPORTED_DIGESTS
- See Also:
- Constant Field Values
-
ASYNC_CIPHER_MODE
public static final java.lang.String ASYNC_CIPHER_MODE
RSA algorithm, no block chaining mode (not a block-cipher) and PKCS1 padding, which is recommended to be used in conjunction with RSA- See Also:
- Constant Field Values
-
SYNC_CIPHER_MODE_PADDED
public static final java.lang.String SYNC_CIPHER_MODE_PADDED
Sync cipher mode supported by the server. It currently must match the SUPPORTED_CIPHER_ALGORITHM advertised by the server- See Also:
- Constant Field Values
-
SYNC_CIPHER_MODE_UNPADDED
public static final java.lang.String SYNC_CIPHER_MODE_UNPADDED
- See Also:
- Constant Field Values
-
SYNC_CIPHER_NAME
public static final java.lang.String SYNC_CIPHER_NAME
- See Also:
- Constant Field Values
-
PUBLIC_KEY_ALGORITHM
public static final java.lang.String PUBLIC_KEY_ALGORITHM
For use in encoding/decoding X509 public keys.- See Also:
- Constant Field Values
-
PUBLIC_KEY_HEADER
public static final java.lang.String PUBLIC_KEY_HEADER
- See Also:
- Constant Field Values
-
PUBLIC_KEY_FOOTER
public static final java.lang.String PUBLIC_KEY_FOOTER
- See Also:
- Constant Field Values
-
SYNC_CIPHER_BLOCKSIZE
public static final int SYNC_CIPHER_BLOCKSIZE
Blocksize in bytes- See Also:
- Constant Field Values
-
CHALLENGE_BYTES
public static final int CHALLENGE_BYTES
- See Also:
- Constant Field Values
-
MAX_TIME_SKEW
public static final long MAX_TIME_SKEW
Maximum request time skew. Request is considered invalid if it exceeds this window.
-
SESSION_IV_DELIM
public static final java.lang.String SESSION_IV_DELIM
Random session IV.- See Also:
- Constant Field Values
-
SESSION_IV_LEN
public static final int SESSION_IV_LEN
- See Also:
- Constant Field Values
-
RANDOM
protected static final java.security.SecureRandom RANDOM
-
credentialManager
protected final GSICredentialManager credentialManager
-
dhSession
protected DHSession dhSession
-
rsaSession
protected RSASession rsaSession
-
bufferHandler
protected DHBufferHandler bufferHandler
-
challenge
protected java.lang.String challenge
-
lastRequest
protected long lastRequest
-
noPadding
protected boolean noPadding
-
-
Constructor Detail
-
GSIRequestHandler
protected GSIRequestHandler(GSICredentialManager credentialManager)
-
-
Method Detail
-
findSessionIVLen
protected static int findSessionIVLen(java.lang.String cipher) throws XrootdException- Throws:
XrootdException
-
generateChallengeString
public static java.lang.String generateChallengeString()
Generate a new challenge string to be used in server-client communication- Returns:
- challenge string
-
getProtocolVersion
public abstract int getProtocolVersion()
-
getSyncCipherMode
protected abstract java.lang.String getSyncCipherMode()
-
decryptMainBucketWithSessionKey
protected NestedBucketBuffer decryptMainBucketWithSessionKey(java.util.Map<XrootdSecurityProtocol.BucketType,XrootdBucket> receivedBuckets, java.lang.String step) throws javax.crypto.NoSuchPaddingException, java.security.InvalidAlgorithmParameterException, java.security.NoSuchAlgorithmException, javax.crypto.IllegalBlockSizeException, javax.crypto.BadPaddingException, java.security.NoSuchProviderException, java.security.InvalidKeyException, java.io.IOException, XrootdException
Assumes the dhSession has been finalized.- Parameters:
receivedBuckets- from the request- Returns:
- the main bucket as a nested bucket buffer
- Throws:
javax.crypto.NoSuchPaddingExceptionjava.security.InvalidAlgorithmParameterExceptionjava.security.NoSuchAlgorithmExceptionjavax.crypto.IllegalBlockSizeExceptionjavax.crypto.BadPaddingExceptionjava.security.NoSuchProviderExceptionjava.security.InvalidKeyExceptionjava.io.IOExceptionXrootdException
-
dhParams
protected byte[] dhParams(boolean sign) throws java.io.IOException, javax.crypto.BadPaddingException, javax.crypto.IllegalBlockSizeException- Parameters:
sign- if true, use the rsaCipher (assumed to be initialized with local private key) to sign the params.- Returns:
- encoded DH parameters, either signed or unsigned.
- Throws:
java.io.IOExceptionjavax.crypto.BadPaddingExceptionjavax.crypto.IllegalBlockSizeException
-
extractChain
protected java.security.cert.X509Certificate[] extractChain(java.util.Map<XrootdSecurityProtocol.BucketType,XrootdBucket> nestedBuckets) throws XrootdException, java.io.IOException
Pull out the string content of the kXRS_x509 bucket and convert it into a cert chain.- Parameters:
nestedBuckets- containing the x509 bucket.- Returns:
- the cert chain
- Throws:
XrootdExceptionjava.io.IOException
-
finalizeSessionKey
protected void finalizeSessionKey(java.util.Map<XrootdSecurityProtocol.BucketType,XrootdBucket> receivedBuckets, XrootdSecurityProtocol.BucketType bucketType) throws java.io.IOException, java.security.GeneralSecurityException, XrootdException
For the pre-4.9 protocol, the DH client params are sent in the clear (unsigned) in the kXRS_puk bucket. For 4.9+, the params are sent in the kXRS_cipher bucket, and are signed with the client's private key, so they must be decrypted. This method assumes that the rsaCipher has already been initialized for decryption using the public key sent by the client in the kXRS_puk bucket.- Parameters:
receivedBuckets-bucketType- kXRS_cipher or kXRS_puk.- Throws:
java.io.IOExceptionjava.security.GeneralSecurityExceptionXrootdException
-
isRequestExpired
protected boolean isRequestExpired()
-
postProcessMainBucket
protected XrootdBucket postProcessMainBucket(java.util.Map<XrootdSecurityProtocol.BucketType,XrootdBucket> buckets, java.util.Optional<java.lang.String> serializedX509, int step) throws javax.crypto.BadPaddingException, javax.crypto.IllegalBlockSizeException, java.security.NoSuchProviderException, javax.crypto.NoSuchPaddingException, java.security.NoSuchAlgorithmException, java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException, XrootdException, java.io.IOException
Generate a new challenge string. Sign the sender's challenge string (assumes rsaCipher has been initialized for encryption). If the response including this bucket follows session key finalization, the bucket needs to be encrypted. This is indicated by the switch logic on the step parameter.- Returns:
- main bucket either encrypted or not, depending on step
- Throws:
javax.crypto.BadPaddingExceptionjavax.crypto.IllegalBlockSizeExceptionjava.security.NoSuchProviderExceptionjavax.crypto.NoSuchPaddingExceptionjava.security.NoSuchAlgorithmExceptionjava.security.InvalidKeyExceptionjava.security.InvalidAlgorithmParameterExceptionXrootdExceptionjava.io.IOException
-
processRSAVerification
protected java.security.cert.X509Certificate[] processRSAVerification(java.util.Map<XrootdSecurityProtocol.BucketType,XrootdBucket> nestedBuckets, java.util.Optional<java.security.PublicKey> toMatch) throws java.security.InvalidKeyException, java.io.IOException, XrootdException
- Parameters:
nestedBuckets- containing the x509 certificate buckettoMatch- if a sender public key has already been extracted.- Returns:
- the extracted and verified certificate chain
- Throws:
java.security.InvalidKeyExceptionjava.io.IOExceptionXrootdException
-
updateLastRequest
protected void updateLastRequest()
-
validateCiphers
protected java.lang.String validateCiphers(java.lang.String[] algorithms) throws XrootdException- Throws:
XrootdException
-
validateCryptoMode
protected void validateCryptoMode(java.lang.String cryptoMode) throws XrootdException- Throws:
XrootdException
-
validateDigests
protected java.lang.String validateDigests(java.lang.String[] digests) throws XrootdException- Throws:
XrootdException
-
verifySignedRTag
protected void verifySignedRTag(java.util.Map<XrootdSecurityProtocol.BucketType,XrootdBucket> nestedBuckets) throws XrootdException, javax.crypto.BadPaddingException, javax.crypto.IllegalBlockSizeException, java.io.IOException
From the main bucket extract the challenge tag signed by the sender. Decrypt this using the rsaCipher (assumes it has been intialized using the received public key). Check that it matches the token previously generated.- Throws:
XrootdExceptionjavax.crypto.BadPaddingExceptionjavax.crypto.IllegalBlockSizeExceptionjava.io.IOException
-
-