forked from Account-Link/github-zktls
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-proof.js
More file actions
189 lines (161 loc) Β· 5.74 KB
/
run-proof.js
File metadata and controls
189 lines (161 loc) Β· 5.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// Playwright script: Run zkTLS proof with injected cookies
// This runs inside GitHub Actions or locally for testing
import { chromium } from 'playwright';
import { writeFileSync, mkdirSync } from 'fs';
import path from 'path';
const TARGET_URL = process.env.TARGET_URL || 'http://host.docker.internal:3000/profile';
const COOKIES_JSON = process.env.COOKIES || '[]';
const OUTPUT_DIR = process.env.OUTPUT_DIR || './proof-output';
async function runProof() {
console.log('π¦ GitHub zkTLS Proof Generator');
console.log('================================\n');
// Parse cookies
let cookies;
try {
cookies = JSON.parse(COOKIES_JSON);
console.log(`β Loaded ${cookies.length} cookie(s)`);
} catch (e) {
console.error('β Failed to parse cookies:', e.message);
process.exit(1);
}
// Create output directory
mkdirSync(OUTPUT_DIR, { recursive: true });
// Launch browser
console.log('\nLaunching Chromium...');
const browser = await chromium.launch({
headless: true,
args: ['--disable-dev-shm-usage']
});
const context = await browser.newContext({
// Add cookies to context
cookies: cookies.map(cookie => ({
name: cookie.name,
value: cookie.value,
domain: cookie.domain || 'localhost',
path: cookie.path || '/',
httpOnly: cookie.httpOnly || false,
secure: cookie.secure || false,
sameSite: cookie.sameSite || 'Lax'
}))
});
console.log('β Cookies injected into browser context');
const page = await context.newPage();
// Enable request/response logging
const networkLog = [];
page.on('request', request => {
networkLog.push({
type: 'request',
timestamp: new Date().toISOString(),
method: request.method(),
url: request.url(),
headers: request.headers()
});
});
page.on('response', response => {
networkLog.push({
type: 'response',
timestamp: new Date().toISOString(),
status: response.status(),
url: response.url(),
headers: response.headers()
});
});
console.log(`\nNavigating to: ${TARGET_URL}`);
try {
// Visit target page
await page.goto(TARGET_URL, { waitUntil: 'networkidle' });
console.log('β Page loaded');
// Take screenshot
const screenshotPath = path.join(OUTPUT_DIR, 'proof-screenshot.png');
await page.screenshot({ path: screenshotPath, fullPage: true });
console.log(`β Screenshot saved: ${screenshotPath}`);
// Extract page content
const pageContent = await page.content();
const pageTitle = await page.title();
const pageUrl = page.url();
// Check if authenticated (look for common indicators)
const bodyText = await page.textContent('body');
const isAuthenticated = bodyText.includes('Logged in') ||
bodyText.includes('Profile') ||
bodyText.includes('@');
console.log(`β Page title: ${pageTitle}`);
console.log(`β Final URL: ${pageUrl}`);
console.log(`β Authentication detected: ${isAuthenticated}`);
// If there's an API endpoint, try fetching it
let apiData = null;
if (TARGET_URL.includes('/profile')) {
const apiUrl = TARGET_URL.replace('/profile', '/api/data');
console.log(`\nFetching API data from: ${apiUrl}`);
try {
const apiResponse = await page.goto(apiUrl);
if (apiResponse.ok()) {
apiData = await apiResponse.json();
console.log('β API data retrieved:', JSON.stringify(apiData, null, 2));
}
} catch (e) {
console.log('β Could not fetch API data:', e.message);
}
}
// Generate proof certificate
const proof = {
generated: new Date().toISOString(),
target: {
url: TARGET_URL,
finalUrl: pageUrl,
title: pageTitle
},
authentication: {
authenticated: isAuthenticated,
method: 'cookie-based',
cookieCount: cookies.length
},
evidence: {
screenshot: 'proof-screenshot.png',
pageContentLength: pageContent.length,
bodyTextPreview: bodyText.substring(0, 200),
networkRequests: networkLog.length
},
apiData: apiData,
environment: {
userAgent: await page.evaluate(() => navigator.userAgent),
timestamp: new Date().toISOString(),
platform: process.platform
}
};
// Save proof certificate
const proofPath = path.join(OUTPUT_DIR, 'proof-certificate.json');
writeFileSync(proofPath, JSON.stringify(proof, null, 2));
console.log(`\nβ Proof certificate saved: ${proofPath}`);
// Save network log
const networkPath = path.join(OUTPUT_DIR, 'network-log.json');
writeFileSync(networkPath, JSON.stringify(networkLog, null, 2));
console.log(`β Network log saved: ${networkPath}`);
// Save page HTML
const htmlPath = path.join(OUTPUT_DIR, 'page-content.html');
writeFileSync(htmlPath, pageContent);
console.log(`β Page HTML saved: ${htmlPath}`);
console.log('\n================================');
console.log('π Proof generation complete!');
console.log(`\nOutput directory: ${OUTPUT_DIR}`);
console.log(`Authenticated: ${isAuthenticated}`);
if (apiData) {
console.log(`User: @${apiData.user?.username || 'unknown'}`);
}
} catch (error) {
console.error('\nβ Proof generation failed:', error.message);
// Save error screenshot
try {
await page.screenshot({ path: path.join(OUTPUT_DIR, 'error-screenshot.png') });
} catch (e) {
// Ignore screenshot errors
}
throw error;
} finally {
await browser.close();
}
}
// Run proof generation
runProof().catch(error => {
console.error('Fatal error:', error);
process.exit(1);
});