Skip to content

Commit 2e044e6

Browse files
author
Bingle Kruger
committed
feat: execute python using enclave
1 parent 861adbc commit 2e044e6

File tree

5 files changed

+505
-126
lines changed

5 files changed

+505
-126
lines changed
+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* Nautilus Trusted Compute
3+
* Copyright (C) 2025 Nautilus
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as published
7+
* by the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Affero General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Affero General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
// app/api/execute-python/route.ts
20+
import { NextRequest, NextResponse } from 'next/server';
21+
import fetch from 'node-fetch';
22+
import https from 'https';
23+
24+
export async function POST(req: NextRequest) {
25+
try {
26+
const { publicIp, github_url, expected_hash } = await req.json();
27+
28+
if (!publicIp || !github_url || !expected_hash) {
29+
return NextResponse.json({ error: 'Missing publicIp, github_url, or expected_hash' }, { status: 400 });
30+
}
31+
32+
const url = `https://${publicIp}/execute_python`;
33+
34+
const response = await fetch(url, {
35+
method: 'POST',
36+
headers: {
37+
'Content-Type': 'application/json',
38+
},
39+
body: JSON.stringify({ github_url, expected_hash }),
40+
agent: new https.Agent({
41+
rejectUnauthorized: false, // Ignore self-signed certificate
42+
}),
43+
} as any); // Temporary type assertion
44+
45+
if (!response.ok) {
46+
const errorText = await response.text();
47+
return NextResponse.json({ error: `Enclave error: ${errorText}` }, { status: response.status });
48+
}
49+
50+
const result = await response.json(); // Expecting JSON output from Python execution
51+
return NextResponse.json({ result });
52+
} catch (error) {
53+
console.error('Proxy error:', error);
54+
return NextResponse.json({ error: 'Failed to proxy request to enclave' }, { status: 500 });
55+
}
56+
}
+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/**
2+
* Nautilus Trusted Compute
3+
* Copyright (C) 2025 Nautilus
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as published
7+
* by the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Affero General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Affero General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
// app/api/update-drt-state/route.ts
20+
import { NextRequest, NextResponse } from 'next/server';
21+
import { currentUser } from '@clerk/nextjs/server';
22+
import { prisma } from "@/lib/prisma";
23+
24+
export async function POST(req: NextRequest) {
25+
try {
26+
const user = await currentUser();
27+
28+
if (!user) {
29+
console.warn("🚨 Unauthorized: No user found in Clerk.");
30+
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
31+
}
32+
33+
const { drtInstanceId, state } = await req.json();
34+
35+
if (!drtInstanceId || !state) {
36+
return NextResponse.json({ error: "Missing drtInstanceId or state" }, { status: 400 });
37+
}
38+
39+
// Verify the DRTInstance belongs to the user
40+
const drtInstance = await prisma.dRTInstance.findFirst({
41+
where: {
42+
id: drtInstanceId,
43+
ownerId: user.id,
44+
},
45+
});
46+
47+
if (!drtInstance) {
48+
return NextResponse.json({ error: "DRTInstance not found or not owned by user" }, { status: 404 });
49+
}
50+
51+
// Update the state
52+
const updatedDrtInstance = await prisma.dRTInstance.update({
53+
where: { id: drtInstanceId },
54+
data: { state },
55+
});
56+
57+
console.log(`✅ Updated DRTInstance ${drtInstanceId} state to ${state}`);
58+
59+
return NextResponse.json({ success: true, drtInstance: updatedDrtInstance });
60+
} catch (error) {
61+
console.error("❌ Error updating DRT state:", error);
62+
return NextResponse.json({ error: "Internal server error" }, { status: 500 });
63+
} finally {
64+
await prisma.$disconnect();
65+
}
66+
}

ntc-web/app/api/user-data/route.ts

+14-5
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,28 @@ export async function GET(request: NextRequest) {
4141
}
4242
},
4343
drtInstances: {
44-
include: { drt: true, pool: true }
44+
include: {
45+
drt: true,
46+
pool: {
47+
include: {
48+
enclaveMeasurement: true // Add this nested include
49+
}
50+
}
51+
}
4552
}
4653
}
4754
});
4855

4956
if (!userData) {
5057
console.warn(`⚠️ No user data found for Clerk ID: ${user.id}`);
51-
return NextResponse.json({ pools: [], drtInstances: [] }, { status: 200 }); // Return empty arrays
58+
return NextResponse.json({ pools: [], drtInstances: [] }, { status: 200 });
5259
}
5360

61+
// console.log('Fetched user data:', JSON.stringify(userData, null, 2)); // Debug log
62+
5463
return NextResponse.json({
55-
pools: userData.pools ?? [], // Ensure empty array
56-
drtInstances: userData.drtInstances ?? [] // Ensure empty array
64+
pools: userData.pools ?? [],
65+
drtInstances: userData.drtInstances ?? []
5766
});
5867

5968
} catch (error) {
@@ -62,4 +71,4 @@ export async function GET(request: NextRequest) {
6271
} finally {
6372
await prisma.$disconnect();
6473
}
65-
}
74+
}

0 commit comments

Comments
 (0)