evaluate :: Request -> Response -> IO Demo3EvalResult
evaluate (Request d pcrSelect nonce) 
  (Response (EvidencePackage eList eNonce eSig) caCert@(Signed pubKey caSig)  tpmQuote@(Quote pcrComposite qSig)) = do
  caPublicKey <- readPubCA
  let blobEvidence :: ByteString
      blobEvidence = ePack eList eNonce caCert --pubKey
      evBlobSha1 =  bytestringDigest $ sha1 blobEvidence
      
      quoteInfo :: TPM_QUOTE_INFO
      quoteInfo = TPM_QUOTE_INFO (tpm_pcr_composite_hash $ pcrComposite)                                                        (TPM_NONCE evBlobSha1) 
     {- blobQuote :: ByteString
      blobQuote = encode quoteInfo
-}
      
      aikPublicKey = tpm_get_rsa_PublicKey pubKey
      
      r1 = verify caPublicKey caCert
      signedQuoteInfo = Signed quoteInfo qSig
      
      size = tpm_key_pubsize pubKey
      mod = tpm_key_pubmod pubKey
      modLength = Data.ByteString.Lazy.length $ encode mod
      exp = (tpm_key_pubexp pubKey)
      blobSize = Data.ByteString.Lazy.length $ encode quoteInfo
      
      qSigSize = Data.ByteString.Lazy.length $ qSig
      
      shaBlobLen = Data.ByteString.Lazy.length evBlobSha1
  
      nonceLength = Data.ByteString.Lazy.length $ encode eNonce
  
  {-
  putStrLn $ "Nonce Length: " ++ show nonceLength
  
  putStrLn $ "Key Size: " ++ show size  
  putStrLn $ "Key Mod: " ++ show mod
  putStrLn $ "Mod Length: " ++ show modLength
  putStrLn $ "Key Exp: " ++ show exp
  putStrLn $ "Blob Length: " ++ show blobSize
  putStrLn $ "SHA1 Blob Len: " ++ show shaBlobLen
  putStrLn $ "Quote Sig Length: " ++ show qSigSize
-}
  let r2 =  verify aikPublicKey signedQuoteInfo
      r3 = nonce == eNonce
  goldenPcrComposite <- readComp
  let r4 = pcrComposite == goldenPcrComposite
      ms = evaluateEvidence d eList 
  return (r1, r2, r3, r4, ms)
evaluate :: Request -> Response -> IO Demo3EvalResult
evaluate (Request d pcrSelect nonce) 
  (Response (EvidencePackage eList eNonce eSig) caCert@(Signed pubKey caSig)  tpmQuote@(Quote pcrComposite qSig)) = do
  caPublicKey <- readPubCA
  let blobEvidence :: ByteString
      blobEvidence = ePack eList eNonce caCert --pubKey
      evBlobSha1 =  bytestringDigest $ sha1 blobEvidence
      
      quoteInfo :: TPM_QUOTE_INFO
      quoteInfo = TPM_QUOTE_INFO (tpm_pcr_composite_hash $ pcrComposite)                                                        (TPM_NONCE evBlobSha1) 
     {- blobQuote :: ByteString
      blobQuote = encode quoteInfo
-}
      
      aikPublicKey = tpm_get_rsa_PublicKey pubKey
      
      r1 = verify caPublicKey caCert
      signedQuoteInfo = Signed quoteInfo qSig
      
      size = tpm_key_pubsize pubKey
      mod = tpm_key_pubmod pubKey
      modLength = Data.ByteString.Lazy.length $ encode mod
      exp = (tpm_key_pubexp pubKey)
      blobSize = Data.ByteString.Lazy.length $ encode quoteInfo
      
      qSigSize = Data.ByteString.Lazy.length $ qSig
      
      shaBlobLen = Data.ByteString.Lazy.length evBlobSha1
  
      nonceLength = Data.ByteString.Lazy.length $ encode eNonce
  
  {-
  putStrLn $ "Nonce Length: " ++ show nonceLength
  
  putStrLn $ "Key Size: " ++ show size  
  putStrLn $ "Key Mod: " ++ show mod
  putStrLn $ "Mod Length: " ++ show modLength
  putStrLn $ "Key Exp: " ++ show exp
  putStrLn $ "Blob Length: " ++ show blobSize
  putStrLn $ "SHA1 Blob Len: " ++ show shaBlobLen
  putStrLn $ "Quote Sig Length: " ++ show qSigSize
-}
  let r2 =  verify aikPublicKey signedQuoteInfo
      r3 = nonce == eNonce
  goldenPcrComposite <- readComp
  let r4 = pcrComposite == goldenPcrComposite
      ms = evaluateEvidence d eList 
  return (r1, r2, r3, r4, ms)
evaluate (Request d pcrSelect nonce) 
  (Response (EvidencePackage eList eNonce eSig) caCert@(Signed pubKey caSig)  tpmQuote@(Quote pcrComposite qSig)) = do
  caPublicKey <- readPubCA
  let blobEvidence :: ByteString
      blobEvidence = ePack eList eNonce caCert --pubKey
      evBlobSha1 =  bytestringDigest $ sha1 blobEvidence
      
      quoteInfo :: TPM_QUOTE_INFO
      quoteInfo = TPM_QUOTE_INFO (tpm_pcr_composite_hash $ pcrComposite)                                                        (TPM_NONCE evBlobSha1) 
     {- blobQuote :: ByteString
      blobQuote = encode quoteInfo
-}
      
      aikPublicKey = tpm_get_rsa_PublicKey pubKey
      
      r1 = verify caPublicKey caCert
      signedQuoteInfo = Signed quoteInfo qSig
      
      size = tpm_key_pubsize pubKey
      mod = tpm_key_pubmod pubKey
      modLength = Data.ByteString.Lazy.length $ encode mod
      exp = (tpm_key_pubexp pubKey)
      blobSize = Data.ByteString.Lazy.length $ encode quoteInfo
      
      qSigSize = Data.ByteString.Lazy.length $ qSig
      
      shaBlobLen = Data.ByteString.Lazy.length evBlobSha1
  
      nonceLength = Data.ByteString.Lazy.length $ encode eNonce
  
  {-
  putStrLn $ "Nonce Length: " ++ show nonceLength
  
  putStrLn $ "Key Size: " ++ show size  
  putStrLn $ "Key Mod: " ++ show mod
  putStrLn $ "Mod Length: " ++ show modLength
  putStrLn $ "Key Exp: " ++ show exp
  putStrLn $ "Blob Length: " ++ show blobSize
  putStrLn $ "SHA1 Blob Len: " ++ show shaBlobLen
  putStrLn $ "Quote Sig Length: " ++ show qSigSize
-}
  let r2 =  verify aikPublicKey signedQuoteInfo
      r3 = nonce == eNonce
  goldenPcrComposite <- readComp
  let r4 = pcrComposite == goldenPcrComposite
      ms = evaluateEvidence d eList 
  return (r1, r2, r3, r4, ms)