private bool ValidateServerCertificate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors sslPolicyErrors)
        {
            if (sslPolicyErrors != SslPolicyErrors.None)
            {
                if (Log.DebugEnabled())
                {
                    Log.Debug("Invalid certificate policy error: " + sslPolicyErrors);
                }
                return(false);
            }

            // Exclude certificate serial numbers.
            if (policy.revokeCertificates != null)
            {
                byte[] serialNumber = cert.GetSerialNumber();

                foreach (byte[] sn in policy.revokeCertificates)
                {
                    if (Util.ByteArrayEquals(serialNumber, sn))
                    {
                        if (Log.DebugEnabled())
                        {
                            Log.Debug("Invalid certificate serial number: " + ByteUtil.BytesToHexString(serialNumber));
                        }
                        return(false);
                    }
                }
            }

            // Search subject certificate name.
            if (FindTlsName(cert.Subject, "CN=", tlsName))
            {
                return(true);
            }

            // Search subject alternative names.
            var cert2 = (X509Certificate2)cert;

            foreach (X509Extension ext in cert2.Extensions)
            {
                if (ext.Oid.Value.Equals("2.5.29.17"))                 // Subject Alternative Name
                {
                    if (FindTlsName(ext.Format(false), "DNS Name=", tlsName))
                    {
                        return(true);
                    }
                }
            }

            if (Log.DebugEnabled())
            {
                Log.Debug("Invalid certificate, tlsName not found: " + tlsName);
            }
            return(false);
        }
Пример #2
0
        protected internal override void ParseRow(Key key)
        {
            BatchRead record = records[batchIndex];

            if (Util.ByteArrayEquals(key.digest, record.key.digest))
            {
                if (resultCode == 0)
                {
                    record.record = ParseRecord();
                }
            }
            else
            {
                throw new AerospikeException.Parse("Unexpected batch key returned: " + key.ns + ',' + ByteUtil.BytesToHexString(key.digest) + ',' + batchIndex);
            }
        }
Пример #3
0
        protected internal override void ParseRow(Key key)
        {
            if (opCount > 0)
            {
                throw new AerospikeException.Parse("Received bins that were not requested!");
            }

            int offset  = batch.offsets[index++];
            Key keyOrig = keys[offset];

            if (Util.ByteArrayEquals(key.digest, keyOrig.digest))
            {
                listener.OnExists(keyOrig, resultCode == 0);
            }
            else
            {
                throw new AerospikeException.Parse("Unexpected batch key returned: " + key.ns + ',' + ByteUtil.BytesToHexString(key.digest) + ',' + index + ',' + offset);
            }
        }
Пример #4
0
        protected internal override void ParseRow(Key key)
        {
            if (opCount > 0)
            {
                throw new AerospikeException.Parse("Received bins that were not requested!");
            }

            if (Util.ByteArrayEquals(key.digest, keys[batchIndex].digest))
            {
                existsArray[batchIndex] = resultCode == 0;
            }
            else
            {
                throw new AerospikeException.Parse("Unexpected batch key returned: " + key.ns + ',' + ByteUtil.BytesToHexString(key.digest) + ',' + batchIndex);
            }
        }
Пример #5
0
        protected internal override void ParseRow(Key key)
        {
            int offset  = batch.offsets[index++];
            Key keyOrig = keys[offset];

            if (Util.ByteArrayEquals(key.digest, keyOrig.digest))
            {
                if (resultCode == 0)
                {
                    Record record = ParseRecord();
                    listener.OnRecord(keyOrig, record);
                }
                else
                {
                    listener.OnRecord(keyOrig, null);
                }
            }
            else
            {
                throw new AerospikeException.Parse("Unexpected batch key returned: " + key.ns + ',' + ByteUtil.BytesToHexString(key.digest) + ',' + index + ',' + offset);
            }
        }
Пример #6
0
 public override string ToString()
 {
     return(ByteUtil.BytesToHexString(bytes, 0, length));
 }
Пример #7
0
 /// <summary>
 /// Return key elements in string format.
 /// </summary>
 public override string ToString()
 {
     return(this.ns + ":" + this.setName + ":" + this.userKey + ":" + ByteUtil.BytesToHexString(this.digest));
 }
Пример #8
0
        private bool ValidateServerCertificate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors sslPolicyErrors)
        {
            // Exclude certificate serial numbers.
            if (policy.revokeCertificates != null)
            {
                byte[] serialNumber = cert.GetSerialNumber();

                foreach (byte[] sn in policy.revokeCertificates)
                {
                    if (Util.ByteArrayEquals(serialNumber, sn))
                    {
                        if (Log.DebugEnabled())
                        {
                            Log.Debug("Invalid certificate serial number: " + ByteUtil.BytesToHexString(serialNumber));
                        }
                        return(false);
                    }
                }
            }

            if (sslPolicyErrors == SslPolicyErrors.None)
            {
                return(true);
            }

            // Search subject alternative names.
            var cert2 = (X509Certificate2)cert;

            foreach (X509Extension ext in cert2.Extensions)
            {
                if (ext.Oid.Value.Equals("2.5.29.17"))                 // Subject Alternative Name
                {
                    const string filter = "DNS Name=";
                    string       sans   = ext.Format(false);
                    string       san;
                    int          begin = 0;
                    int          end;

                    while ((begin = sans.IndexOf(filter, begin)) >= 0)
                    {
                        begin += filter.Length;
                        end    = sans.IndexOf(',', begin);

                        if (end >= 0)
                        {
                            san = sans.Substring(begin, end - begin);
                        }
                        else
                        {
                            san = sans.Substring(begin);
                        }

                        if (san.Equals(tlsName))
                        {
                            return(true);
                        }

                        if (end < 0)
                        {
                            break;
                        }

                        begin = end + 1;
                    }
                }
            }

            if (Log.DebugEnabled())
            {
                Log.Debug("TLS connection error: " + sslPolicyErrors);
            }
            return(false);
        }
Пример #9
0
        /// <summary>
        /// Parse all results in the batch.  Add records to shared list.
        /// If the record was not found, the bins will be null.
        /// </summary>
        protected internal override bool ParseRecordResults(int receiveSize)
        {
            //Parse each message response and add it to the result array
            dataOffset = 0;

            while (dataOffset < receiveSize)
            {
                if (!valid)
                {
                    throw new AerospikeException.QueryTerminated();
                }

                ReadBytes(MSG_REMAINING_HEADER_SIZE);
                int resultCode = dataBuffer[5];

                // The only valid server return codes are "ok" and "not found".
                // If other return codes are received, then abort the batch.
                if (resultCode != 0 && resultCode != ResultCode.KEY_NOT_FOUND_ERROR)
                {
                    throw new AerospikeException(resultCode);
                }

                byte info3 = dataBuffer[3];

                // If this is the end marker of the response, do not proceed further
                if ((info3 & Command.INFO3_LAST) == Command.INFO3_LAST)
                {
                    return(false);
                }

                int fieldCount = ByteUtil.BytesToShort(dataBuffer, 18);
                int opCount    = ByteUtil.BytesToShort(dataBuffer, 20);

                if (opCount > 0)
                {
                    throw new AerospikeException.Parse("Received bins that were not requested!");
                }

                Key key    = ParseKey(fieldCount);
                int offset = batch.offsets[index++];

                if (Util.ByteArrayEquals(key.digest, keys[offset].digest))
                {
                    existsArray[offset] = resultCode == 0;
                }
                else
                {
                    throw new AerospikeException.Parse("Unexpected batch key returned: " + key.ns + ',' + ByteUtil.BytesToHexString(key.digest) + ',' + index + ',' + offset);
                }
            }
            return(true);
        }
        protected internal override void ParseRow(Key key)
        {
            int offset = batch.offsets[index++];

            if (Util.ByteArrayEquals(key.digest, keys[offset].digest))
            {
                if (resultCode == 0)
                {
                    records[offset] = ParseRecordBatch();
                }
            }
            else
            {
                throw new AerospikeException.Parse("Unexpected batch key returned: " + key.ns + ',' + ByteUtil.BytesToHexString(key.digest) + ',' + index + ',' + offset);
            }
        }