import { SocketFunction } from "socket-function/SocketFunction"; import { SocketFunctionHook } from "socket-function/SocketFunctionTypes"; import { getNodeIdIP } from "socket-function/src/nodeCache"; import { setHTTPResultHeaders, getCurrentHTTPRequest } from "socket-function/src/callHTTPHandler"; import { performLocalCall } from "socket-function/src/callManager"; import { RequireController } from "socket-function/require/RequireController"; import { timeInMinute } from "socket-function/src/misc"; import { getCommonName, getMachineId, getOwnMachineId, validateCertificate, verify } from "../../misc/https/certs"; import { ArchiveFileInfo, ArchivesConfig, ArchivesSyncStatus, FindConfig, SourceConfig, IMMUTABLE_CACHE_TIME } from "../IArchives"; import { ROUTING_FILE, getRoute, routeContains } from "./remoteConfig"; import { findBucketStore, getStore, getBucketStores, readBucketInternal, writeRoutingConfig, getBucketArchivesConfig, bucketSyncStatus, debugBucketIndexTotals, ActiveBucketInfo, debugListAccountBuckets, ServerBucketInfo, debugGetActiveBucket, activateBucket, getActiveBucketKeys, } from "./storageServerState"; import { debugClearAccountWriteStats } from "./accessStats"; import { getStorageServerConfig, assertWritesAllowed } from "./serverConfig"; import { getTrustedMachines, isMachineAccepted, MachineState } from "../../security/machines/machines"; import { BlobStore } from "./blobStore"; import { getRoutingFileResult } from "./bucketDisk"; import { StorageClientController } from "./storageClientController"; import { trackAccess, trackAccessCall, getAccessTotals, readAccessSummaries, clearAccountAccessStats, AccessTotals, AccessSummaryState } from "./accessStats"; import { logMutation, listStorageLogFiles, readStorageLogFile } from "./storageLogs"; import { LogFileInfo } from "../StreamingLogs"; import { assertValidName, assertValidPath, assertValidArgs } from "./validation"; import type { SummaryEntry } from "../../treeSummary"; export const REMOTE_STORAGE_CLASS_GUID = "RemoteStorageController-b7e42a91"; export const STORAGE_AUTH_PURPOSE = "remoteStorage-auth-1"; export const STORAGE_NOT_AUTHENTICATED = "REMOTE_STORAGE_NOT_AUTHENTICATED_cf2f7b1e"; export const STORAGE_ACCESS_DENIED = "REMOTE_STORAGE_ACCESS_DENIED_9d81a4c0"; const AUTH_TIME_WINDOW = timeInMinute * 10; const ACCESS_CHECK_SLOW_TIME = 50; const MAX_SESSIONS = 100 * 1000; const MAX_REQUESTS_PER_IP = 50; export type AuthTokenData = { purpose: string; time: number; server: string; }; export type AuthToken = { certPem: string; issuerPem: string; signature: string; data: AuthTokenData; }; export type AccessState = { machineId: string; ip: string; hasAccess: boolean; // Why not, including the command that grants access, when there is no access. reason?: string; // Everything the repo trusts, when there is. trustedMachines?: MachineState[]; }; const sessions = new Map(); // We must never serve anything that can be evaluated as code (html, js - and svg, which can embed