@@ -4,7 +4,8 @@ import { EncryptCommand, EncryptFileCommand } from '../../../@types/commands.js'
44import * as base58 from 'base58-js'
55import { Readable } from 'stream'
66import { Storage } from '../../storage/index.js'
7- import { getConfiguration } from '../../../utils/index.js'
7+ import { getConfiguration , isPolicyServerConfigured } from '../../../utils/index.js'
8+ import { PolicyServer } from '../../policyServer/index.js'
89import { EncryptMethod } from '../../../@types/fileObject.js'
910import {
1011 ValidateParams ,
@@ -49,9 +50,41 @@ export class EncryptHandler extends CommandHandler {
4950
5051 async handle ( task : EncryptCommand ) : Promise < P2PCommandResponse > {
5152 const validationResponse = await this . verifyParamsAndRateLimits ( task )
53+
5254 if ( this . shouldDenyTaskHandling ( validationResponse ) ) {
5355 return validationResponse
5456 }
57+ const isAuthRequestValid = await this . validateTokenOrSignature (
58+ task . authorization ,
59+ task . consumerAddress ,
60+ task . nonce ,
61+ task . signature ,
62+ String ( task . nonce )
63+ )
64+ if ( isAuthRequestValid . status . httpStatus !== 200 ) {
65+ return isAuthRequestValid
66+ }
67+
68+ if ( isPolicyServerConfigured ( ) ) {
69+ const policyServer = new PolicyServer ( )
70+ const response = await policyServer . checkEncrypt (
71+ task . consumerAddress ,
72+ task . policyServer
73+ )
74+ if ( ! response ) {
75+ CORE_LOGGER . logMessage (
76+ `Error: Encrypt for ${ task . consumerAddress } was denied` ,
77+ true
78+ )
79+ return {
80+ stream : null ,
81+ status : {
82+ httpStatus : 403 ,
83+ error : `Error: Encrypt for ${ task . consumerAddress } was denied`
84+ }
85+ }
86+ }
87+ }
5588 try {
5689 const oceanNode = this . getOceanNode ( )
5790 // prepare an empty array in case if
@@ -112,6 +145,39 @@ export class EncryptFileHandler extends CommandHandler {
112145 if ( this . shouldDenyTaskHandling ( validationResponse ) ) {
113146 return validationResponse
114147 }
148+ const isAuthRequestValid = await this . validateTokenOrSignature (
149+ task . authorization ,
150+ task . consumerAddress ,
151+ task . nonce ,
152+ task . signature ,
153+ String ( task . nonce )
154+ )
155+ if ( isAuthRequestValid . status . httpStatus !== 200 ) {
156+ return isAuthRequestValid
157+ }
158+
159+ if ( isPolicyServerConfigured ( ) ) {
160+ const policyServer = new PolicyServer ( )
161+ const response = await policyServer . checkEncryptFile (
162+ task . consumerAddress ,
163+ task . policyServer ,
164+ task . files
165+ )
166+ if ( ! response ) {
167+ CORE_LOGGER . logMessage (
168+ `Error: EncryptFile for ${ task . consumerAddress } was denied` ,
169+ true
170+ )
171+ return {
172+ stream : null ,
173+ status : {
174+ httpStatus : 403 ,
175+ error : `Error: EncryptFile for ${ task . consumerAddress } was denied`
176+ }
177+ }
178+ }
179+ }
180+
115181 try {
116182 const oceanNode = this . getOceanNode ( )
117183 const config = await getConfiguration ( )
0 commit comments