public/javascript/session.js
function respondToRPMessage (event) {
    var parser, messenger, clientId, rpss,
      salt, opbs, input, opss, comparison

    // Parse message origin
    origin = event.origin
    parser = document.createElement('a')
    parser.href = document.referrer
    messenger = parser.protocol + '//' + parser.host

    // Ignore the message if origin doesn't match
    if (origin !== messenger) {
      return
    }

    // get a reference to the source so we can message it
    // immediately in response to a change in sessionState
    source = event.source

    // Parse the message
    clientId = event.data.split(' ')[0]
    rpss = event.data.split(' ')[1]
    salt = rpss.split('.')[1]

    // Validate message syntax
    if (!clientId || !rpss || !salt) {
      event.source.postMessage('error', origin)
    }

    // Get the OP browser state
    opbs = getOPBrowserState()

    // Recalculate session state for comparison
    input = [clientId, origin, opbs, salt].join(' ')
    opss = [CryptoJS.SHA256(input), salt].join('.')

    // Compare the RP session state with the OP session state
    comparison = compareSessionState(rpss, opss)

    // Compare session state and reply to RP
    event.source.postMessage(comparison, origin)
  }
function respondToRPMessage (event) {
    var parser, messenger, clientId, rpss,
      salt, opbs, input, opss, comparison

    // Parse message origin
    origin = event.origin
    parser = document.createElement('a')
    parser.href = document.referrer
    messenger = parser.protocol + '//' + parser.host

    // Ignore the message if origin doesn't match
    if (origin !== messenger) {
      return
    }

    // get a reference to the source so we can message it
    // immediately in response to a change in sessionState
    source = event.source

    // Parse the message
    clientId = event.data.split(' ')[0]
    rpss = event.data.split(' ')[1]
    salt = rpss.split('.')[1]

    // Validate message syntax
    if (!clientId || !rpss || !salt) {
      event.source.postMessage('error', origin)
    }

    // Get the OP browser state
    opbs = getOPBrowserState()

    // Recalculate session state for comparison
    input = [clientId, origin, opbs, salt].join(' ')
    opss = [CryptoJS.SHA256(input), salt].join('.')

    // Compare the RP session state with the OP session state
    comparison = compareSessionState(rpss, opss)

    // Compare session state and reply to RP
    event.source.postMessage(comparison, origin)
  }
function respondToRPMessage ( event ) { var parser , messenger , clientId , rpss , salt , opbs , input , opss , comparison // Parse message origin origin = event . origin parser = document . createElement ( 'a' ) parser . href = document . referrer messenger = parser . protocol + '//' + parser . host // Ignore the message if origin doesn't match if ( origin !== messenger ) { return } // get a reference to the source so we can message it // immediately in response to a change in sessionState source = event . source // Parse the message clientId = event . data . split ( ' ' ) [ 0 ] rpss = event . data . split ( ' ' ) [ 1 ] salt = rpss . split ( '.' ) [ 1 ] // Validate message syntax if ( ! clientId || ! rpss || ! salt ) { event . source . postMessage ( 'error' , origin ) } // Get the OP browser state opbs = getOPBrowserState ( ) // Recalculate session state for comparison input = [ clientId , origin , opbs , salt ] . join ( ' ' ) opss = [ CryptoJS . SHA256 ( input ) , salt ] . join ( '.' ) // Compare the RP session state with the OP session state comparison = compareSessionState ( rpss , opss ) // Compare session state and reply to RP event . source . postMessage ( comparison , origin ) }
Respond to RP postMessage
Respond to RP postMessage