Package org.tsugi.lti13
Class LTI13Util
- java.lang.Object
-
- org.tsugi.lti13.LTI13Util
-
public class LTI13Util extends Object
-
-
Constructor Summary
Constructors Constructor Description LTI13Util()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddCustomToLaunch(Properties ltiProps, Properties custom)static Stringbase64Encode(byte[] input)static StringbreakKeyIntoLines(String rawkey)static booleancheckLTI11Transition(LaunchJWT lj, String key, String secret)Check the OAuth signature for an LTI 1.3 Launch JWT See: https://www.imsglobal.org/spec/lti/v1p3/migr#lti-1-1-migration-claimstatic Stringcompute_HMAC_SHA256(String message, String secret)Compute the HMAC256 of a string (part of LTI 1.1 Transition) See: https://www.imsglobal.org/spec/lti/v1p3/migr#lti-1-1-migration-claim Based on: https://www.jokecamp.com/blog/examples-of-creating-base64-hashes-using-hmac-sha256-in-different-languages/#php https://stackoverflow.com/questions/7124735/hmac-sha256-algorithm-for-signature-calculationstatic KeyPairdeSerializeKeyPair(String ser)static KeyPairgenerateKeyPair()static Map<String,String>generateKeys()static DoublegetDoubleNull(Object key)static intgetInt(Object o)static StringgetKeyB64(Key key)static LonggetLong(Object key)static LonggetLongKey(Object key)static LonggetLongNull(Object key)static StringgetLTI11TransitionBase(LaunchJWT lj)Compute the base string for a Launch JWT See: https://www.imsglobal.org/spec/lti/v1p3/migr#lti-1-1-migration-claimstatic StringgetPrivateB64(Key key)static StringgetPrivateB64(KeyPair kp)static StringgetPrivateEncoded(String keyStr)static StringgetPrivateEncoded(Key key)static StringgetPrivateEncoded(KeyPair kp)static StringgetPublicB64(KeyPair kp)static StringgetPublicEncoded(String keyStr)static StringgetPublicEncoded(Key key)static StringgetPublicEncoded(KeyPair kp)static StringgetScoreUrlForLineItem(String lineItemUrl)Get the scores URL from a lineItem Url Moodle gives us lineItem URLs with query parameters.static StringgetStringNull(Object value)static voidreturn400(HttpServletResponse response, String error)static voidreturn400(HttpServletResponse response, String error, String detail)static voidreturn403(HttpServletResponse response, String error)static voidreturn403(HttpServletResponse response, String error, String detail)static voidreturn404(HttpServletResponse response, String error)static voidreturn404(HttpServletResponse response, String error, String detail)static voidreturn4XX(HttpServletResponse response, String error, String detail, int httpStatus)static StringserializeKeyPair(KeyPair kp)static voidsetProperty(Properties props, String key, String value)static Stringsha256(String input)static StringsignLTI11Transition(LaunchJWT lj, String secret)Compute the OAuth signature for an LTI 1.3 Launch JWT See: https://www.imsglobal.org/spec/lti/v1p3/migr#lti-1-1-migration-claimstatic Keystring2PrivateKey(String keyString)static Keystring2PublicKey(String keyString)static KeyPairstrings2KeyPair(String pubKeyStr, String privKeyStr)static StringstripPKCS8(String input)static voidsubstituteCustom(Properties custom, Properties lti2subst)static StringtimeStamp(String token)timeStamp - Add a time-stamp to the beginning of a stringstatic booleantimeStampCheck(String token, int seconds)timeStampCheck - Check a time-stamp at the beginning of a stringstatic booleantimeStampCheckSign(String token, String secret, int seconds)timeStampCheckSign - check to see if a token has not expired and is signedstatic StringtimeStampSign(String token, String secret)timeStampSign - Take a one-time token and add a timestamp timestamp:token:signaturestatic StringtoNull(String str)
-
-
-
Method Detail
-
generateKeys
public static Map<String,String> generateKeys() throws NoSuchAlgorithmException
- Throws:
NoSuchAlgorithmException
-
base64Encode
public static String base64Encode(byte[] input)
-
generateKeyPair
public static KeyPair generateKeyPair()
-
getLTI11TransitionBase
public static String getLTI11TransitionBase(LaunchJWT lj)
Compute the base string for a Launch JWT See: https://www.imsglobal.org/spec/lti/v1p3/migr#lti-1-1-migration-claim- Parameters:
lj- The Launch JSON Web Token with the LTI 1.1 transition data- Returns:
- string This is null if the base string cannot be computed
-
signLTI11Transition
public static String signLTI11Transition(LaunchJWT lj, String secret)
Compute the OAuth signature for an LTI 1.3 Launch JWT See: https://www.imsglobal.org/spec/lti/v1p3/migr#lti-1-1-migration-claim- Parameters:
lj- The Launch JSON Web Token with the LTI 11 transition datasecret- The OAuth secret- Returns:
- string This is null if the signature cannot be computed
-
checkLTI11Transition
public static boolean checkLTI11Transition(LaunchJWT lj, String key, String secret)
Check the OAuth signature for an LTI 1.3 Launch JWT See: https://www.imsglobal.org/spec/lti/v1p3/migr#lti-1-1-migration-claim- Parameters:
lj- The Launch JSON Web Token with the LTI 11 transition datakey- The OAuth keysecret- The OAuth secret- Returns:
- true if the signature matches, false if the JWT the signature does not match or the JWT data is malformed.
-
compute_HMAC_SHA256
public static String compute_HMAC_SHA256(String message, String secret)
Compute the HMAC256 of a string (part of LTI 1.1 Transition) See: https://www.imsglobal.org/spec/lti/v1p3/migr#lti-1-1-migration-claim Based on: https://www.jokecamp.com/blog/examples-of-creating-base64-hashes-using-hmac-sha256-in-different-languages/#php https://stackoverflow.com/questions/7124735/hmac-sha256-algorithm-for-signature-calculation- Parameters:
object- $message The message to signstring- $secret The secret used to sign the message- Returns:
- string The signed message
-
getScoreUrlForLineItem
public static String getScoreUrlForLineItem(String lineItemUrl)
Get the scores URL from a lineItem Url Moodle gives us lineItem URLs with query parameters.
-
return400
public static void return400(HttpServletResponse response, String error)
-
return400
public static void return400(HttpServletResponse response, String error, String detail)
-
return403
public static void return403(HttpServletResponse response, String error)
-
return403
public static void return403(HttpServletResponse response, String error, String detail)
-
return404
public static void return404(HttpServletResponse response, String error)
-
return404
public static void return404(HttpServletResponse response, String error, String detail)
-
return4XX
public static void return4XX(HttpServletResponse response, String error, String detail, int httpStatus)
-
substituteCustom
public static void substituteCustom(Properties custom, Properties lti2subst)
-
addCustomToLaunch
public static void addCustomToLaunch(Properties ltiProps, Properties custom)
-
setProperty
public static void setProperty(Properties props, String key, String value)
-
timeStamp
public static String timeStamp(String token)
timeStamp - Add a time-stamp to the beginning of a string
-
timeStampCheck
public static boolean timeStampCheck(String token, int seconds)
timeStampCheck - Check a time-stamp at the beginning of a string
-
timeStampSign
public static String timeStampSign(String token, String secret)
timeStampSign - Take a one-time token and add a timestamp timestamp:token:signature
-
timeStampCheckSign
public static boolean timeStampCheckSign(String token, String secret, int seconds)
timeStampCheckSign - check to see if a token has not expired and is signed
-
getInt
public static int getInt(Object o)
-
-