import type { DigestSecurityScheme, DigestSecurityValues } from '@superfaceai/ast'; import type { ICrypto, ILogger } from '../../../../../interfaces'; import type { IFetch } from '../../interfaces'; import type { AuthCache, AuthenticateRequestAsync, HandleResponseAsync, ISecurityHandler } from '../interfaces'; /** * Represents algorithm used in Digest auth. */ declare type DigestAlgorithm = 'MD5' | 'MD5-sess' | 'SHA-256' | 'SHA-256-sess'; /** * Represents values extracted from initial digest call */ export declare type DigestAuthValues = { algorithm: DigestAlgorithm; scheme: string; realm: string; qop: 'auth' | 'auth-int' | undefined; opaque: string | undefined; nonce: string; cnonce: string; }; export declare function hashDigestConfiguration(configuration: DigestSecurityValues, crypto: ICrypto): string; /** * Helper for digest authentication */ export declare class DigestHandler implements ISecurityHandler { readonly configuration: DigestSecurityScheme & DigestSecurityValues; private readonly fetchInstance; private readonly crypto; private readonly logger?; private readonly log?; private readonly logSensitive?; private readonly statusCode; private readonly challengeHeader; private readonly authorizationHeader; private readonly nonceRaw; private readonly cnonceSize; private nc; constructor(configuration: DigestSecurityScheme & DigestSecurityValues, fetchInstance: IFetch & AuthCache, crypto: ICrypto, logger?: ILogger | undefined); authenticate: AuthenticateRequestAsync; handleResponse: HandleResponseAsync; /** * * @param url url of the request * @param method HTTP method * @param digest extracted of cached digest values * @returns string containing information needed to digest authorization */ private buildDigestAuth; private extractDigestValues; private makeNonce; } /** * Extracts "MD5", "MD5-sess", "SHA-256" or "SHA-256-sess" algorithm from passed header. "MD5" is default value. * @param rawHeader string containing algorithm type * @returns "MD5", "MD5-sess", "SHA-256" or "SHA-256-sess" */ export declare function extractAlgorithm(rawHeader: string): DigestAlgorithm; /** * Extracts QOP from raw header. Throws on values other than "auth" or "auth-int" * @param rawHeader string containing qop * @returns "auth", "auth-int" or undefined */ export declare function extractQop(rawHeader: string): 'auth' | 'auth-int' | undefined; /** * Computes hash from data using specified algorithm * @param algorithm used to compute hash * @param data data to be hashed * @returns hashed data */ export declare function computeHash(algorithm: DigestAlgorithm, data: string, crypto: ICrypto): string; export {};