Protection Engine for Cloud Services

 View Only

 .Net SDK ERR_SOCKET_ERR

Ragunathan Dayalan's profile image
Ragunathan Dayalan posted May 01, 2023 10:27 AM

I'm implementing SPE virus scanning mechanism for one our application where customer uploaded documents are sent to ICAP service for AV scans. I'm currently using the SDK provided for .Net version. I tried to follow the documentation and implemented the solution same way, but not sure what else is i'm missing. I have even opened up firewall between the client and server where ICAP service is running but still i'm seeing ERR_SOCKET_ERR.
I'm using the StreamScanRequest for send the file as byte[] in chunks. Below is my code i'm using and any guidance is appreciated.

List<ScanEngineInfo> scanEngineInfo = new List<ScanEngineInfo>();

            scanEngineInfo.Add(new ScanEngineInfo()
            {
                scanEngineIP = config["ScanService:BaseAddress"],
                scanEnginePort = Convert.ToInt32(config["ScanService:Port"])
            });
            ScanRequestManager scanRequestManager = new ScanRequestManager();
            scanRequestManager.PrepareForScan(scanEngineInfo, 60000, 10000);

           StreamScanRequest streamScanRequest = scanRequestManager.CreateStreamScanRequest(Policy.SCAN, true);

            bool startStatus = streamScanRequest.Start(null, null);
            byte[] buff = new byte[512];
            long bytesToRead = file.Length - 1;
            int buffCapRead = buff.Length;
            int bytesRead = 0;
            Stream fin = new MemoryStream(file);
            do
            {
                if (bytesToRead >= buffCapRead)
                {
                    buffCapRead = buff.Length;
                }
                else
                {
                    buffCapRead = (int)bytesToRead;
                }

                // Refresh data buffer.
                buff = new byte[buffCapRead];

                bytesRead = fin.Read(buff, 0, buffCapRead);
                // Send the bytes to Symantec Protection Engine
                bool sendStatus = streamScanRequest.Send(buff);
                stringBuilder.AppendLine($"send status: {sendStatus}, bytes read: {bytesRead}");
                bytesToRead = bytesToRead - bytesRead;
            } while (bytesToRead > 0);
            if (fin != null)
            {
                fin.Close();
            }

            Stream resultStream = new MemoryStream();
            var result = streamScanRequest.Finish(resultStream);