Class LTI13Util


  • public class LTI13Util
    extends Object
    • Constructor Detail

      • LTI13Util

        public LTI13Util()
    • Method Detail

      • base64Encode

        public static String base64Encode​(byte[] input)
      • stripPKCS8

        public static String stripPKCS8​(String input)
      • generateKeyPair

        public static KeyPair generateKeyPair()
      • getKeyB64

        public static String getKeyB64​(Key key)
      • getPublicB64

        public static String getPublicB64​(KeyPair kp)
      • getPublicEncoded

        public static String getPublicEncoded​(KeyPair kp)
      • getPublicEncoded

        public static String getPublicEncoded​(Key key)
      • getPublicEncoded

        public static String getPublicEncoded​(String keyStr)
      • getPrivateB64

        public static String getPrivateB64​(KeyPair kp)
      • getPrivateB64

        public static String getPrivateB64​(Key key)
      • getPrivateEncoded

        public static String getPrivateEncoded​(KeyPair kp)
      • getPrivateEncoded

        public static String getPrivateEncoded​(Key key)
      • getPrivateEncoded

        public static String getPrivateEncoded​(String keyStr)
      • breakKeyIntoLines

        public static String breakKeyIntoLines​(String rawkey)
      • string2PrivateKey

        public static Key string2PrivateKey​(String keyString)
      • string2PublicKey

        public static Key string2PublicKey​(String keyString)
      • strings2KeyPair

        public static KeyPair strings2KeyPair​(String pubKeyStr,
                                              String privKeyStr)
      • serializeKeyPair

        public static String serializeKeyPair​(KeyPair kp)
      • deSerializeKeyPair

        public static KeyPair deSerializeKeyPair​(String ser)
      • 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 data
        secret - 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 data
        key - The OAuth key
        secret - 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 sign
        string - $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.
      • substituteCustom

        public static void substituteCustom​(Properties custom,
                                            Properties lti2subst)
      • addCustomToLaunch

        public static void addCustomToLaunch​(Properties ltiProps,
                                             Properties custom)
      • 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)
      • getLongKey

        public static Long getLongKey​(Object key)
      • getLong

        public static Long getLong​(Object key)
      • getLongNull

        public static Long getLongNull​(Object key)
      • getDoubleNull

        public static Double getDoubleNull​(Object key)
      • getStringNull

        public static String getStringNull​(Object value)