span> outlineStyle.js 11e3a9652a first 8 年之前 outlineWidth.js 11e3a9652a first 8 年之前 overflow.js 11e3a9652a first 8 年之前 overflowX.js 11e3a9652a first 8 年之前 overflowY.js 11e3a9652a first 8 年之前 padding.js 11e3a9652a first 8 年之前 paddingBottom.js 11e3a9652a first 8 年之前 paddingLeft.js 11e3a9652a first 8 年之前 paddingRight.js 11e3a9652a first 8 年之前 paddingTop.js 11e3a9652a first 8 年之前 page.js 11e3a9652a first 8 年之前 pageBreakAfter.js 11e3a9652a first 8 年之前 pageBreakBefore.js 11e3a9652a first 8 年之前 pageBreakInside.js 11e3a9652a first 8 年之前 pause.js 11e3a9652a first 8 年之前 pauseAfter.js 11e3a9652a first 8 年之前 pauseBefore.js 11e3a9652a first 8 年之前 pitch.js 11e3a9652a first 8 年之前 pitchRange.js 11e3a9652a first 8 年之前 playDuring.js 11e3a9652a first 8 年之前 pointerEvents.js 11e3a9652a first 8 年之前 position.js 11e3a9652a first 8 年之前 quotes.js 11e3a9652a first 8 年之前 resize.js 11e3a9652a first 8 年之前 richness.js 11e3a9652a first 8 年之前 right.js 11e3a9652a first 8 年之前 shapeRendering.js 11e3a9652a first 8 年之前 size.js 11e3a9652a first 8 年之前 speak.js 11e3a9652a first 8 年之前 speakHeader.js 11e3a9652a first 8 年之前 speakNumeral.js 11e3a9652a first 8 年之前 speakPunctuation.js 11e3a9652a first 8 年之前 speechRate.js 11e3a9652a first 8 年之前 src.js 11e3a9652a first 8 年之前 stopColor.js 11e3a9652a first 8 年之前 stopOpacity.js 11e3a9652a first 8 年之前 stress.js 11e3a9652a first 8 年之前 stroke.js 11e3a9652a first 8 年之前 strokeDasharray.js 11e3a9652a first 8 年之前 strokeDashoffset.js 11e3a9652a first 8 年之前 strokeLinecap.js 11e3a9652a first 8 年之前 strokeLinejoin.js 11e3a9652a first 8 年之前 strokeMiterlimit.js 11e3a9652a first 8 年之前 strokeOpacity.js 11e3a9652a first 8 年之前 strokeWidth.js 11e3a9652a first 8 年之前 tableLayout.js 11e3a9652a first 8 年之前 textAlign.js 11e3a9652a first 8 年之前 textAnchor.js 11e3a9652a first 8 年之前 textDecoration.js 11e3a9652a first 8 年之前 textIndent.js 11e3a9652a first 8 年之前 textLineThrough.js 11e3a9652a first 8 年之前 textLineThroughColor.js 11e3a9652a first 8 年之前 textLineThroughMode.js 11e3a9652a first 8 年之前 textLineThroughStyle.js 11e3a9652a first 8 年之前 textLineThroughWidth.js 11e3a9652a first 8 年之前 textOverflow.js 11e3a9652a first 8 年之前 textOverline.js 11e3a9652a first 8 年之前 textOverlineColor.js 11e3a9652a first 8 年之前 textOverlineMode.js 11e3a9652a first 8 年之前 textOverlineStyle.js 11e3a9652a first 8 年之前 textOverlineWidth.js 11e3a9652a first 8 年之前 textRendering.js 11e3a9652a first 8 年之前 textShadow.js 11e3a9652a first 8 年之前 textTransform.js 11e3a9652a first 8 年之前 textUnderline.js 11e3a9652a first 8 年之前 textUnderlineColor.js 11e3a9652a first 8 年之前 textUnderlineMode.js 11e3a9652a first 8 年之前 textUnderlineStyle.js 11e3a9652a first 8 年之前 textUnderlineWidth.js 11e3a9652a first 8 年之前 top.js 11e3a9652a first 8 年之前 unicodeBidi.js 11e3a9652a first 8 年之前 unicodeRange.js 11e3a9652a first 8 年之前 vectorEffect.js 11e3a9652a first 8 年之前 verticalAlign.js 11e3a9652a first 8 年之前 visibility.js 11e3a9652a first 8 年之前 voiceFamily.js 11e3a9652a first 8 年之前 volume.js 11e3a9652a first 8 年之前 webkitAnimation.js 11e3a9652a first 8 年之前 webkitAnimationDelay.js 11e3a9652a first 8 年之前 webkitAnimationDirection.js 11e3a9652a first 8 年之前 webkitAnimationDuration.js 11e3a9652a first 8 年之前 webkitAnimationFillMode.js 11e3a9652a first 8 年之前 webkitAnimationIterationCount.js 11e3a9652a first 8 年之前 webkitAnimationName.js 11e3a9652a first 8 年之前 webkitAnimationPlayState.js 11e3a9652a first 8 年之前 webkitAnimationTimingFunction.js 11e3a9652a first 8 年之前 webkitAppearance.js 11e3a9652a first 8 年之前 webkitAspectRatio.js 11e3a9652a first 8 年之前 webkitBackfaceVisibility.js 11e3a9652a first 8 年之前 webkitBackgroundClip.js 11e3a9652a first 8 年之前 webkitBackgroundComposite.js 11e3a9652a first 8 年之前 webkitBackgroundOrigin.js 11e3a9652a first 8 年之前 webkitBackgroundSize.js 11e3a9652a first 8 年之前 webkitBorderAfter.js 11e3a9652a first 8 年之前 webkitBorderAfterColor.js 11e3a9652a first 8 年之前 webkitBorderAfterStyle.js 11e3a9652a first 8 年之前 webkitBorderAfterWidth.js 11e3a9652a first 8 年之前 webkitBorderBefore.js 11e3a9652a first 8 年之前 webkitBorderBeforeColor.js 11e3a9652a first 8 年之前 webkitBorderBeforeStyle.js 11e3a9652a first 8 年之前 webkitBorderBeforeWidth.js 11e3a9652a first 8 年之前 webkitBorderEnd.js 11e3a9652a first 8 年之前 webkitBorderEndColor.js 11e3a9652a first 8 年之前 webkitBorderEndStyle.js 11e3a9652a first 8 年之前 webkitBorderEndWidth.js 11e3a9652a first 8 年之前 webkitBorderFit.js 11e3a9652a first 8 年之前 webkitBorderHorizontalSpacing.js 11e3a9652a first 8 年之前 webkitBorderImage.js 11e3a9652a first 8 年之前 webkitBorderRadius.js 11e3a9652a first 8 年之前 webkitBorderStart.js 11e3a9652a first 8 年之前 webkitBorderStartColor.js 11e3a9652a first 8 年之前 webkitBorderStartStyle.js 11e3a9652a first 8 年之前 webkitBorderStartWidth.js 11e3a9652a first 8 年之前 webkitBorderVerticalSpacing.js 11e3a9652a first 8 年之前 webkitBoxAlign.js 11e3a9652a first 8 年之前 webkitBoxDirection.js 11e3a9652a first 8 年之前 webkitBoxFlex.js 11e3a9652a first 8 年之前 webkitBoxFlexGroup.js 11e3a9652a first 8 年之前 webkitBoxLines.js 11e3a9652a first 8 年之前 webkitBoxOrdinalGroup.js 11e3a9652a first 8 年之前 webkitBoxOrient.js 11e3a9652a first 8 年之前 webkitBoxPack.js 11e3a9652a first 8 年之前 webkitBoxReflect.js 11e3a9652a first 8 年之前 webkitBoxShadow.js 11e3a9652a first 8 年之前 webkitColorCorrection.js 11e3a9652a first 8 年之前 webkitColumnAxis.js 11e3a9652a first 8 年之前 webkitColumnBreakAfter.js 11e3a9652a first 8 年之前 webkitColumnBreakBefore.js 11e3a9652a first 8 年之前 webkitColumnBreakInside.js 11e3a9652a first 8 年之前 webkitColumnCount.js 11e3a9652a first 8 年之前 webkitColumnGap.js 11e3a9652a first 8 年之前 webkitColumnRule.js 11e3a9652a first 8 年之前 webkitColumnRuleColor.js 11e3a9652a first 8 年之前 webkitColumnRuleStyle.js 11e3a9652a first 8 年之前 webkitColumnRuleWidth.js 11e3a9652a first 8 年之前 webkitColumnSpan.js 11e3a9652a first 8 年之前 webkitColumnWidth.js 11e3a9652a first 8 年之前 webkitColumns.js 11e3a9652a first 8 年之前 webkitFilter.js 11e3a9652a first 8 年之前 webkitFlexAlign.js 11e3a9652a first 8 年之前 webkitFlexDirection.js 11e3a9652a first 8 年之前 webkitFlexFlow.js 11e3a9652a first 8 年之前 webkitFlexItemAlign.js 11e3a9652a first 8 年之前 webkitFlexLinePack.js 11e3a9652a first 8 年之前 webkitFlexOrder.js 11e3a9652a first 8 年之前 webkitFlexPack.js 11e3a9652a first 8 年之前 webkitFlexWrap.js 11e3a9652a first 8 年之前 webkitFlowFrom.js 11e3a9652a first 8 年之前 webkitFlowInto.js 11e3a9652a first 8 年之前 webkitFontFeatureSettings.js 11e3a9652a first 8 年之前 webkitFontKerning.js 11e3a9652a first 8 年之前 webkitFontSizeDelta.js 11e3a9652a first 8 年之前 webkitFontSmoothing.js 11e3a9652a first 8 年之前 webkitFontVariantLigatures.js 11e3a9652a first 8 年之前 webkitHighlight.js 11e3a9652a first 8 年之前 webkitHyphenateCharacter.js 11e3a9652a first 8 年之前 webkitHyphenateLimitAfter.js 11e3a9652a first 8 年之前 webkitHyphenateLimitBefore.js 11e3a9652a first 8 年之前 webkitHyphenateLimitLines.js 11e3a9652a first 8 年之前 webkitHyphens.js 11e3a9652a first 8 年之前 webkitLineAlign.js 11e3a9652a first 8 年之前 webkitLineBoxContain.js 11e3a9652a first 8 年之前 webkitLineBreak.js 11e3a9652a first 8 年之前 webkitLineClamp.js 11e3a9652a first 8 年之前 webkitLineGrid.js 11e3a9652a first 8 年之前 webkitLineSnap.js 11e3a9652a first 8 年之前 webkitLocale.js 11e3a9652a first 8 年之前 webkitLogicalHeight.js 11e3a9652a first 8 年之前 webkitLogicalWidth.js 11e3a9652a first 8 年之前 webkitMarginAfter.js 11e3a9652a first 8 年之前 webkitMarginAfterCollapse.js 11e3a9652a first 8 年之前 webkitMarginBefore.js 11e3a9652a first 8 年之前 webkitMarginBeforeCollapse.js 11e3a9652a first 8 年之前 webkitMarginBottomCollapse.js 11e3a9652a first 8 年之前 webkitMarginCollapse.js 11e3a9652a first 8 年之前 webkitMarginEnd.js 11e3a9652a first 8 年之前 webkitMarginStart.js 11e3a9652a first 8 年之前 webkitMarginTopCollapse.js 11e3a9652a first 8 年之前 webkitMarquee.js 11e3a9652a first 8 年之前 webkitMarqueeDirection.js 11e3a9652a first 8 年之前 webkitMarqueeIncrement.js 11e3a9652a first 8 年之前 webkitMarqueeRepetition.js 11e3a9652a first 8 年之前 webkitMarqueeSpeed.js 11e3a9652a first 8 年之前 webkitMarqueeStyle.js 11e3a9652a first 8 年之前 webkitMask.js 11e3a9652a first 8 年之前 webkitMaskAttachment.js 11e3a9652a first 8 年之前 webkitMaskBoxImage.js 11e3a9652a first 8 年之前 webkitMaskBoxImageOutset.js 11e3a9652a first 8 年之前 webkitMaskBoxImageRepeat.js 11e3a9652a first 8 年之前 webkitMaskBoxImageSlice.js 11e3a9652a first 8 年之前 webkitMaskBoxImageSource.js 11e3a9652a first 8 年之前 webkitMaskBoxImageWidth.js 11e3a9652a first 8 年之前 webkitMaskClip.js 11e3a9652a first 8 年之前 webkitMaskComposite.js 11e3a9652a first 8 年之前 webkitMaskImage.js 11e3a9652a first 8 年之前 webkitMaskOrigin.js 11e3a9652a first 8 年之前 webkitMaskPosition.js 11e3a9652a first 8 年之前 webkitMaskPositionX.js 11e3a9652a first 8 年之前 webkitMaskPositionY.js 11e3a9652a first 8 年之前 webkitMaskRepeat.js 11e3a9652a first 8 年之前 webkitMaskRepeatX.js 11e3a9652a first 8 年之前 webkitMaskRepeatY.js 11e3a9652a first 8 年之前 webkitMaskSize.js 11e3a9652a first 8 年之前 webkitMatchNearestMailBlockquoteColor.js 11e3a9652a first 8 年之前 webkitMaxLogicalHeight.js 11e3a9652a first 8 年之前 webkitMaxLogicalWidth.js 11e3a9652a first 8 年之前 webkitMinLogicalHeight.js 11e3a9652a first 8 年之前 webkitMinLogicalWidth.js 11e3a9652a first 8 年之前 webkitNbspMode.js 11e3a9652a first 8 年之前 webkitOverflowScrolling.js 11e3a9652a first 8 年之前 webkitPaddingAfter.js 11e3a9652a first 8 年之前 webkitPaddingBefore.js 11e3a9652a first 8 年之前 webkitPaddingEnd.js 11e3a9652a first 8 年之前 webkitPaddingStart.js 11e3a9652a first 8 年之前 webkitPerspective.js 11e3a9652a first 8 年之前 webkitPerspectiveOrigin.js 11e3a9652a first 8 年之前 webkitPerspectiveOriginX.js 11e3a9652a first 8 年之前 webkitPerspectiveOriginY.js 11e3a9652a first 8 年之前 webkitPrintColorAdjust.js 11e3a9652a first 8 年之前 webkitRegionBreakAfter.js 11e3a9652a first 8 年之前 webkitRegionBreakBefore.js 11e3a9652a first 8 年之前 webkitRegionBreakInside.js 11e3a9652a first 8 年之前 webkitRegionOverflow.js 11e3a9652a first 8 年之前 webkitRtlOrdering.js 11e3a9652a first 8 年之前 webkitSvgShadow.js 11e3a9652a first 8 年之前 webkitTapHighlightColor.js 11e3a9652a first 8 年之前 webkitTextCombine.js 11e3a9652a first 8 年之前 webkitTextDecorationsInEffect.js 11e3a9652a first 8 年之前 webkitTextEmphasis.js 11e3a9652a first 8 年之前 webkitTextEmphasisColor.js 11e3a9652a first 8 年之前 webkitTextEmphasisPosition.js 11e3a9652a first 8 年之前 webkitTextEmphasisStyle.js 11e3a9652a first 8 年之前 webkitTextFillColor.js 11e3a9652a first 8 年之前 webkitTextOrientation.js 11e3a9652a first 8 年之前 webkitTextSecurity.js 11e3a9652a first 8 年之前 webkitTextSizeAdjust.js 11e3a9652a first 8 年之前 webkitTextStroke.js 11e3a9652a first 8 年之前 webkitTextStrokeColor.js 11e3a9652a first 8 年之前 webkitTextStrokeWidth.js 11e3a9652a first 8 年之前 webkitTransform.js 11e3a9652a first 8 年之前 webkitTransformOrigin.js 11e3a9652a first 8 年之前 webkitTransformOriginX.js 11e3a9652a first 8 年之前 webkitTransformOriginY.js 11e3a9652a first 8 年之前 webkitTransformOriginZ.js 11e3a9652a first 8 年之前 webkitTransformStyle.js 11e3a9652a first 8 年之前 webkitTransition.js 11e3a9652a first 8 年之前 webkitTransitionDelay.js 11e3a9652a first 8 年之前 webkitTransitionDuration.js 11e3a9652a first 8 年之前 webkitTransitionProperty.js 11e3a9652a first 8 年之前 webkitTransitionTimingFunction.js 11e3a9652a first 8 年之前 webkitUserDrag.js 11e3a9652a first 8 年之前 webkitUserModify.js 11e3a9652a first 8 年之前 webkitUserSelect.js 11e3a9652a first 8 年之前 webkitWrap.js 11e3a9652a first 8 年之前 webkitWrapFlow.js 11e3a9652a first 8 年之前 webkitWrapMargin.js 11e3a9652a first 8 年之前 webkitWrapPadding.js 11e3a9652a first 8 年之前 webkitWrapShapeInside.js 11e3a9652a first 8 年之前 webkitWrapShapeOutside.js 11e3a9652a first 8 年之前 webkitWrapThrough.js 11e3a9652a first 8 年之前 webkitWritingMode.js 11e3a9652a first 8 年之前 whiteSpace.js 11e3a9652a first 8 年之前 widows.js 11e3a9652a first 8 年之前 width.js 11e3a9652a first 8 年之前 wordBreak.js 11e3a9652a first 8 年之前 wordSpacing.js 11e3a9652a first 8 年之前 wordWrap.js 11e3a9652a first 8 年之前 writingMode.js 11e3a9652a first 8 年之前 zIndex.js 11e3a9652a first 8 年之前 zoom.js 11e3a9652a first 8 年之前 adminSystem - Gogs: Go Git Service

Nessuna descrizione

client.js 11KB

    'use strict'; // Load modules const Url = require('url'); const Hoek = require('hoek'); const Cryptiles = require('cryptiles'); const Crypto = require('./crypto'); const Utils = require('./utils'); // Declare internals const internals = {}; // Generate an Authorization header for a given request /* uri: 'http://example.com/resource?a=b' or object from Url.parse() method: HTTP verb (e.g. 'GET', 'POST') options: { // Required credentials: { id: 'dh37fgj492je', key: 'aoijedoaijsdlaksjdl', algorithm: 'sha256' // 'sha1', 'sha256' }, // Optional ext: 'application-specific', // Application specific data sent via the ext attribute timestamp: Date.now() / 1000, // A pre-calculated timestamp in seconds nonce: '2334f34f', // A pre-generated nonce localtimeOffsetMsec: 400, // Time offset to sync with server time (ignored if timestamp provided) payload: '{"some":"payload"}', // UTF-8 encoded string for body hash generation (ignored if hash provided) contentType: 'application/json', // Payload content-type (ignored if hash provided) hash: 'U4MKKSmiVxk37JCCrAVIjV=', // Pre-calculated payload hash app: '24s23423f34dx', // Oz application id dlg: '234sz34tww3sd' // Oz delegated-by application id } */ exports.header = function (uri, method, options) { const result = { field: '', artifacts: {} }; // Validate inputs if (!uri || (typeof uri !== 'string' && typeof uri !== 'object') || !method || typeof method !== 'string' || !options || typeof options !== 'object') { result.err = 'Invalid argument type'; return result; } // Application time const timestamp = options.timestamp || Utils.nowSecs(options.localtimeOffsetMsec); // Validate credentials const credentials = options.credentials; if (!credentials || !credentials.id || !credentials.key || !credentials.algorithm) { result.err = 'Invalid credential object'; return result; } if (Crypto.algorithms.indexOf(credentials.algorithm) === -1) { result.err = 'Unknown algorithm'; return result; } // Parse URI if (typeof uri === 'string') { uri = Url.parse(uri); } // Calculate signature const artifacts = { ts: timestamp, nonce: options.nonce || Cryptiles.randomString(6), method, resource: uri.pathname + (uri.search || ''), // Maintain trailing '?' host: uri.hostname, port: uri.port || (uri.protocol === 'http:' ? 80 : 443), hash: options.hash, ext: options.ext, app: options.app, dlg: options.dlg }; result.artifacts = artifacts; // Calculate payload hash if (!artifacts.hash && (options.payload || options.payload === '')) { artifacts.hash = Crypto.calculatePayloadHash(options.payload, credentials.algorithm, options.contentType); } const mac = Crypto.calculateMac('header', credentials, artifacts); // Construct header const hasExt = artifacts.ext !== null && artifacts.ext !== undefined && artifacts.ext !== ''; // Other falsey values allowed let header = 'Hawk id="' + credentials.id + '", ts="' + artifacts.ts + '", nonce="' + artifacts.nonce + (artifacts.hash ? '", hash="' + artifacts.hash : '') + (hasExt ? '", ext="' + Hoek.escapeHeaderAttribute(artifacts.ext) : '') + '", mac="' + mac + '"'; if (artifacts.app) { header = header + ', app="' + artifacts.app + (artifacts.dlg ? '", dlg="' + artifacts.dlg : '') + '"'; } result.field = header; return result; }; // Validate server response /* res: node's response object artifacts: object received from header().artifacts options: { payload: optional payload received required: specifies if a Server-Authorization header is required. Defaults to 'false' } */ exports.authenticate = function (res, credentials, artifacts, options, callback) { artifacts = Hoek.clone(artifacts); options = options || {}; let wwwAttributes = null; let serverAuthAttributes = null; const finalize = function (err) { if (callback) { const headers = { 'www-authenticate': wwwAttributes, 'server-authorization': serverAuthAttributes }; return callback(err, headers); } return !err; }; if (res.headers['www-authenticate']) { // Parse HTTP WWW-Authenticate header wwwAttributes = Utils.parseAuthorizationHeader(res.headers['www-authenticate'], ['ts', 'tsm', 'error']); if (wwwAttributes instanceof Error) { wwwAttributes = null; return finalize(new Error('Invalid WWW-Authenticate header')); } // Validate server timestamp (not used to update clock since it is done via the SNPT client) if (wwwAttributes.ts) { const tsm = Crypto.calculateTsMac(wwwAttributes.ts, credentials); if (tsm !== wwwAttributes.tsm) { return finalize(new Error('Invalid server timestamp hash')); } } } // Parse HTTP Server-Authorization header if (!res.headers['server-authorization'] && !options.required) { return finalize(); } serverAuthAttributes = Utils.parseAuthorizationHeader(res.headers['server-authorization'], ['mac', 'ext', 'hash']); if (serverAuthAttributes instanceof Error) { serverAuthAttributes = null; return finalize(new Error('Invalid Server-Authorization header')); } artifacts.ext = serverAuthAttributes.ext; artifacts.hash = serverAuthAttributes.hash; const mac = Crypto.calculateMac('response', credentials, artifacts); if (mac !== serverAuthAttributes.mac) { return finalize(new Error('Bad response mac')); } if (!options.payload && options.payload !== '') { return finalize(); } if (!serverAuthAttributes.hash) { return finalize(new Error('Missing response hash attribute')); } const calculatedHash = Crypto.calculatePayloadHash(options.payload, credentials.algorithm, res.headers['content-type']); if (calculatedHash !== serverAuthAttributes.hash) { return finalize(new Error('Bad response payload mac')); } return finalize(); }; // Generate a bewit value for a given URI /* uri: 'http://example.com/resource?a=b' or object from Url.parse() options: { // Required credentials: { id: 'dh37fgj492je', key: 'aoijedoaijsdlaksjdl', algorithm: 'sha256' // 'sha1', 'sha256' }, ttlSec: 60 * 60, // TTL in seconds // Optional ext: 'application-specific', // Application specific data sent via the ext attribute localtimeOffsetMsec: 400 // Time offset to sync with server time }; */ exports.getBewit = function (uri, options) { // Validate inputs if (!uri || (typeof uri !== 'string' && typeof uri !== 'object') || !options || typeof options !== 'object' || !options.ttlSec) { return ''; } options.ext = (options.ext === null || options.ext === undefined ? '' : options.ext); // Zero is valid value // Application time const now = Utils.now(options.localtimeOffsetMsec); // Validate credentials const credentials = options.credentials; if (!credentials || !credentials.id || !credentials.key || !credentials.algorithm) { return ''; } if (Crypto.algorithms.indexOf(credentials.algorithm) === -1) { return ''; } // Parse URI if (typeof uri === 'string') { uri = Url.parse(uri); } // Calculate signature const exp = Math.floor(now / 1000) + options.ttlSec; const mac = Crypto.calculateMac('bewit', credentials, { ts: exp, nonce: '', method: 'GET', resource: uri.pathname + (uri.search || ''), // Maintain trailing '?' host: uri.hostname, port: uri.port || (uri.protocol === 'http:' ? 80 : 443), ext: options.ext }); // Construct bewit: id\exp\mac\ext const bewit = credentials.id + '\\' + exp + '\\' + mac + '\\' + options.ext; return Hoek.base64urlEncode(bewit); }; // Generate an authorization string for a message /* host: 'example.com', port: 8000, message: '{"some":"payload"}', // UTF-8 encoded string for body hash generation options: { // Required credentials: { id: 'dh37fgj492je', key: 'aoijedoaijsdlaksjdl', algorithm: 'sha256' // 'sha1', 'sha256' }, // Optional timestamp: Date.now() / 1000, // A pre-calculated timestamp in seconds nonce: '2334f34f', // A pre-generated nonce localtimeOffsetMsec: 400, // Time offset to sync with server time (ignored if timestamp provided) } */ exports.message = function (host, port, message, options) { // Validate inputs if (!host || typeof host !== 'string' || !port || typeof port !== 'number' || message === null || message === undefined || typeof message !== 'string' || !options || typeof options !== 'object') { return null; } // Application time const timestamp = options.timestamp || Utils.nowSecs(options.localtimeOffsetMsec); // Validate credentials const credentials = options.credentials; if (!credentials || !credentials.id || !credentials.key || !credentials.algorithm) { // Invalid credential object return null; } if (Crypto.algorithms.indexOf(credentials.algorithm) === -1) { return null; } // Calculate signature const artifacts = { ts: timestamp, nonce: options.nonce || Cryptiles.randomString(6), host, port, hash: Crypto.calculatePayloadHash(message, credentials.algorithm) }; // Construct authorization const result = { id: credentials.id, ts: artifacts.ts, nonce: artifacts.nonce, hash: artifacts.hash, mac: Crypto.calculateMac('message', credentials, artifacts) }; return result; };