Using the example set out in the MSDN for EWS API I have been trying to validate the server certificate but getting errors.
Operator '<>' is not definted for types 'System.Cryptogrpahy.X509Certificates.X509Chain' and 'Microsoft.VisualBasic.VariantType'.
Operator '<>' is not definted for types '1-dimesnional arrary of System.Security.Cryptography.X509Certificates.X509ChainStatus' and 'Microsoft.VisualBasic.VariantType'.
I understand the errors but I have no idea how to fix the problems because I cannot make a cast orfind anything helpful in the MSDN.. Can anyone help?
Operator '<>' is not definted for types 'System.Cryptogrpahy.X509Certificates.X509Chain' and 'Microsoft.VisualBasic.VariantType'.
Operator '<>' is not definted for types '1-dimesnional arrary of System.Security.Cryptography.X509Certificates.X509ChainStatus' and 'Microsoft.VisualBasic.VariantType'.
I understand the errors but I have no idea how to fix the problems because I cannot make a cast orfind anything helpful in the MSDN.. Can anyone help?
VB.NET:
Private Function CertificateValidationCallBack(ByVal sender As Object, _
ByVal certificate As System.Security.Cryptography.X509Certificates.X509Certificate, _
ByVal chain As System.Security.Cryptography.X509Certificates.X509Chain, _
ByVal sslPolicyErrors As System.Net.Security.SslPolicyErrors) As Boolean
Dim status As System.Security.Cryptography.X509Certificates.X509ChainStatus
'' If the certificate is a valid, signed certificate, return true.
If sslPolicyErrors = Security.SslPolicyErrors.None Then
Return True
End If
'' If there are errors in the certificate chain, look at each error to determine the cause.
If (sslPolicyErrors & sslPolicyErrors.RemoteCertificateChainErrors) Then
If (chain <> vbNull) & (chain.ChainStatus <> vbNull) Then
For Each status In chain.ChainStatus
If (certificate.Subject = certificate.Issuer) & (status.Status = System.Security.Cryptography.X509Certificates.X509ChainStatusFlags.UntrustedRoot) Then
'' Self-signed certificates with an untrusted root are valid.
Continue For
Else
If status.Status <> System.Security.Cryptography.X509Certificates.X509ChainStatusFlags.NoError Then
'' If there are any other errors in the certificate chain, the certificate is invalid, so the method returns false.
Return False
End If
End If
Next
End If
'' When processing reaches this line, the only errors in the certificate chain are untrusted root errors for self-signed certificates.
'' These certificates are valid for default Exchange server installations, so return true.
Return True
Else
'' In all other cases, return false.
Return False
End If
End Function