Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix decode base64 bug #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions circuits/jwt.circom
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ include "./jwt_type_regex.circom";
include "./ascii.circom";
include "./timestamp.circom";

template JWTVerify(max_msg_bytes, max_json_bytes, n, k) {
template JWTVerify(max_msg_bytes, max_body_bytes,max_json_bytes, n, k) {
signal input message[max_msg_bytes];
signal input modulus[k]; // rsa pubkey
signal input signature[k];
Expand Down Expand Up @@ -66,21 +66,11 @@ template JWTVerify(max_msg_bytes, max_json_bytes, n, k) {

// decode to JSON format
component message_b64 = Base64Decode(max_json_bytes);
component eqs[max_msg_bytes];
signal int[max_msg_bytes];
signal body[max_body_bytes] <== VarShiftLeft(max_msg_bytes, max_body_bytes)(message, period_idx + 1);

for (var i = 0; i < max_msg_bytes - 1; i++) {
eqs[i] = GreaterEqThan(15);
eqs[i].in[0] <== i;
eqs[i].in[1] <== period_idx;

var i_plus_one = eqs[i].out;
var i_normal = 1 - eqs[i].out;

int[i] <== (message[i] * i_normal);
message_b64.in[i] <== (message[i + 1] * (i_plus_one)) + int[i];
for (var i = 0; i < max_body_bytes; i++) {
message_b64.in[i] <== body[i];
}
message_b64.in[max_msg_bytes - 1] <== 0;

/************************** JWT REGEXES *****************************/

Expand Down Expand Up @@ -142,4 +132,4 @@ template JWTVerify(max_msg_bytes, max_json_bytes, n, k) {
less_exp_time.out === 1;
}

component main { public [ modulus, time ] } = JWTVerify(1024, 766, 121, 17);
component main { public [ modulus, time ] } = JWTVerify(1024, 900, 673, 121, 17);
6 changes: 4 additions & 2 deletions scripts/generate_input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ function AsciiArrayToString(arr: Buffer) {
function findDomain(msg: string) {
let domain_idx;
let domain;
var s = Buffer.from(msg, "base64");
const allParts = msg.split(".");
var s = Buffer.from(allParts[1], "base64");
var json = AsciiArrayToString(s);
const email_regex = /([-a-zA-Z._+]+)@([-a-zA-Z]+).([a-zA-Z]+)/;
const match = json.match(email_regex);
Expand All @@ -120,7 +121,8 @@ function findDomain(msg: string) {
}

function findTimestampInJSON(msg: string) {
var s = Buffer.from(msg, "base64");
const allParts = msg.split(".");
var s = Buffer.from(allParts[1], "base64");
var json = AsciiArrayToString(s);
let time_index = json.indexOf(`"exp":`) + 6;
let timestamp = json.substring(time_index, time_index + 10);
Expand Down