-
Notifications
You must be signed in to change notification settings - Fork 2
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
Update dependencies and add CSR subject check. #8
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
import os from "os"; | ||
import fs from "fs"; | ||
import path from "path"; | ||
import rimraf from "rimraf"; | ||
import { rimrafSync } from "rimraf"; | ||
import express, { ErrorRequestHandler, Request, Response } from "express"; | ||
import asyncHandler from "express-async-handler"; | ||
import rateLimit from "express-rate-limit"; | ||
import morgan from "morgan"; | ||
import multer from "multer"; | ||
import config from "./config"; | ||
import config from "./config.js"; | ||
import { | ||
shell, | ||
HttpError, | ||
BadRequestError, | ||
isHex, | ||
assertValidSignedDappnodeMessage | ||
} from "./utils"; | ||
} from "./utils/index.js"; | ||
|
||
const maxCsrSize = 10e3; // 10 KB; | ||
const renewalTimeThresholdMs = config.renewalTimeThresholdSec * 1000; | ||
|
@@ -30,7 +30,7 @@ const upload = multer({ | |
app.use( | ||
rateLimit({ | ||
windowMs: parseInt(config.rateLimitWindowMs), | ||
max: config.debug ? 0 : config.rateLimitMax | ||
limit: config.debug ? undefined : config.rateLimitMax | ||
}) | ||
); | ||
|
||
|
@@ -98,7 +98,7 @@ app.post( | |
}); | ||
} | ||
|
||
rimraf.sync(certBaseDir); | ||
rimrafSync(certBaseDir); | ||
fs.mkdirSync(certBaseDir, { recursive: true }); | ||
|
||
// Must attach Certificate Signing Request as "csr" formData | ||
|
@@ -109,6 +109,13 @@ app.post( | |
|
||
fs.writeFileSync(csrPath, req.file.buffer); | ||
|
||
|
||
const csrDomain = await shell(`openssl req -in ${csrPath} -subject -noout | cut -c 31-`); | ||
if (csrDomain != "dyndns.dappnode.io") { | ||
rimrafSync(certBaseDir); | ||
throw new BadRequestError("CSR Subject invalid."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this properly caught? Will it cause the app to exit? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is caught. You can see that request params were validated in the same way. |
||
} | ||
|
||
const command = [ | ||
"certbot", | ||
"certonly", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export * from "./asyncHandler"; | ||
export * from "./format"; | ||
export * from "./shell"; | ||
export * from "./signedDappnodeMessage"; | ||
export * from "./asyncHandler.js"; | ||
export * from "./format.js"; | ||
export * from "./shell.js"; | ||
export * from "./signedDappnodeMessage.js"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ export async function shell( | |
{ timeout, maxBuffer } | ||
); | ||
return stdout.trim(); | ||
} catch (e) { | ||
} catch (e: any) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you need to define There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IDK, compiler was complaining for some reason, that code worked fine before. 😅 |
||
// Rethrow a typed error, and ignore the internal NodeJS stack trace | ||
const err: child.ExecException = e; | ||
if (err.signal === "SIGTERM") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why 16? Wouldn't we want to have a more up-to-date version of node?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because that node is available in certbot image we use as final one.