Skip to content

Instantly share code, notes, and snippets.

@kbjorklu kbjorklu/main.cpp Secret
Last active Oct 26, 2018

Embed
What would you like to do?
Verify PGE decision signature
// build e.g. with:
// clang++ -Wall -Wextra -pedantic -std=c++11 \
// -isystem /path/to/jwt-cpp/include \
// -isystem /usr/local/opt/openssl/include/ -lssl -lcrypto main.cpp
#include <jwt-cpp/jwt.h> // https://github.com/Thalhammer/jwt-cpp
#include <iostream>
// GET https://pge.unityads.unity3d.com/v2/key.pub
const char *const pge_public_key =
"-----BEGIN PUBLIC KEY-----\n"
"MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAyiDvOoh0OEy7C/rSkB7f\n"
"pEwKlcwPyVN0xzzKgwjJFD5VADCEpoJNDT3TpTMVpRty3IGdcSQqQLC7/mGxsY3v\n"
"Okej3avyWDG0ErkMeT6p7yz+AXvvRCO5j7z6YaqGktJwNKnQ/rE7yfHCtNbGnWoW\n"
"Xeb5igqjaPP+itmOZhk1Btbrwk0LDAvlvWIZxwWPjLNNCgNIU9eAIGHxL+aJFzi8\n"
"ZNrPWxXz+8prK7VX7SNGty6Cpns7lypeA3+44qSciun/0SLmM8qsBjuX9AvPuRLf\n"
"jsM+hw7Y6lOhTyWiEtF7eR7ReTxx+LFG1BD2SSZ5DRtHSxTGApFeeyJfv/JvrZPa\n"
"kAlOSMmdkW1x+Z6jHqoniGobbfyeFAicl4xC35KJh4+q04w5BmBUYx+TFyN8hUPP\n"
"LAyNG8aWnF4ne6F1bZbCQTO3ZlcGQd4BkEOTRlKf1L4Fh7JgOuARQGh4d4iiPcpY\n"
"+euG+XBNZTo3U8bb6kDeeqvvrSsE7U6/7JI9trLtUOkbtR5RE8FPRVVB4HbT61xS\n"
"Xv9lxelVYkS1megjt1UVkkwUB+FANrCNbTMonIc7uV2/fXfUj3LdV1vkBrTKf1uF\n"
"iGhEfGQ3HJiwBxd1yyiQbTHXl+SiW/uGJhcuRIP4E6lchq993czbaeP/BOtLKk1O\n"
"vhtX6p/kgg4OgwyElV/jcysCAwEAAQ==\n"
"-----END PUBLIC KEY-----\n";
// Result signature from POST https://pge.unityads.unity3d.com/v2/questions
const char *const example_token =
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJkZWNpc2lvbl9pZCI6ImEwYTY4N"
"2IzLTAyMTUtNDkzZi05NTJjLWUzNDU3Y2IwNzNmMiIsImRlY2lzaW9uX25hbWUiOiJ"
"kaWZmaWN1bHR5IiwiY2hvc2VuX2FsdGVybmF0aXZlIjoiZWFzeSIsImFsdGVybmF0a"
"XZlcyI6WyJlYXN5IiwibWVkaXVtIiwiZGlmZmljdWx0Il0sInRyZWF0bWVudCI6Imd"
"kcHIiLCJpYXQiOjE1NDA1NTU1NDEsImlzcyI6ImFkcy1wZ2UudW5pdHlhZHMudW5pd"
"HkzZC5jb20iLCJzdWIiOiI3NDcifQ.EAxv7PkPFSiQQ4TX2oXmRi8iPvbWJRku0LXa"
"y2jKpV1GEutq2l7TgXGSi6jZxofNbVUeikG3VgODvbPA-PRMn3E5sSXRm1nNhGTYZp"
"NL6yFYsj1sF2h3Yf4GKuH3e0F9sQANwHmHZU_oog_We37etR4X4vyuxCIODTXONlNv"
"eVho5sEKF4igHncwPMVOrpvv7Ph1K5n35OV53Qacm62mYy8Pl3BvSZqZN3EzDVKdg4"
"Z7KZlY4bVd1iHdyW94M1JIlZDj2tkuWA0pMK4QhLXXoWREMQElTnsJd3SIGqPDI9qC"
"zwJtOBJ7VzFKou_rtACV0zXNO6bpa1zirT8kIb5Cxb8p1RhOLe399oqiTXf8HT1JH8"
"82JDUm8T2Jq6Plp-gmAVBSnXa3bvo1nVDA9zkRqkIJIcZEqfuTmCQ8uyBQUthJytNl"
"I8t4bNpJQbWVB4d8MxV2lIxfMVH6IlNC6sszo7wOydQ-6a5Vt4Y7TkMMQEXILvmDCa"
"MICosPbHKp9__zXOFfpr9HwRu4biLS1T3blyzTUqhE5THj7y3i5nHLx3Bspze9DJtO"
"lp1o7LGJQwqB3X_kCkToTgKAWUIlhBB7C6vV2mKDk6xyYOPwaq-6CowzSoXwVM5wLp"
"txwHskJc9UHTt2vQr2OWEJcaHLzvPxGpMl_jRZXfWPEpvg_5eyAnI";
int main()
{
auto decoded = jwt::decode(example_token);
for (auto &e : decoded.get_payload_claims())
std::cout << e.first << " = " << e.second.to_json() << std::endl;
auto verifier = jwt::verify().allow_algorithm(jwt::algorithm::rs256(pge_public_key));
try
{
verifier.verify(decoded);
}
catch (const std::exception &e)
{
std::cerr << "verification failed: " << e.what() << std::endl;
}
}
@kbjorklu

This comment has been minimized.

Copy link
Owner Author

kbjorklu commented Oct 26, 2018

$ clang++ -Wall -Wextra -pedantic -std=c++11 -isystem ../jwt-cpp/include -isystem /usr/local/opt/openssl/include/ -lssl -lcrypto main.cpp
$ ./a.out 
alternatives = ["easy","medium","difficult"]
chosen_alternative = "easy"
decision_id = "a0a687b3-0215-493f-952c-e3457cb073f2"
decision_name = "difficulty"
iat = 1540555541
iss = "ads-pge.unityads.unity3d.com"
sub = "747"
treatment = "gdpr"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.