- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在尝试连接到 HTTPS 代理后面的 WCF API 时遇到以下错误:
名称为“CN=hostname”的服务器证书未能通过身份验证,因为其指纹(“X”)与端点身份(“Y”)中指定的指纹不匹配。因此,当前的 HTTPS 请求已失败。请更新客户端使用的端点标识或服务器使用的证书。
其中 X 是代理使用的证书的指纹,Y 是服务使用的证书的指纹
问题是我设法从 STS 获得了 token ,但之后我无法执行任何 Web 服务调用。
我通过使用本地 SSL 代理在我的 PC 上重现了这个问题,代理上使用的证书在我的 PC 上是可信的。使用 HTTP 时一切正常。
我搜索了几天的解决方案,我注意到这篇知识库文章接近我的问题但不再适用(我在 .Net 4.5 中运行示例和服务器):https://support.microsoft.com/en-us/kb/2564823
我错过了什么?
代码如下:
class Program
{
static void Main(string[] args)
{
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-us");
string serverUrl = ConfigurationManager.AppSettings["ServerURL"];
GenericXmlSecurityToken token = GetToken(serverUrl);
Console.WriteLine("Token Received");
Console.WriteLine(token);
TestServiceClient client = CreateClient(serverUrl, token);
try
{
client.SearchSomething();
Console.WriteLine("SearchSomething succeeded");
}
catch (Exception e)
{
Console.WriteLine("SearchSomething failed :" + e);
}
Console.ReadLine();
}
private static TestServiceClient CreateClient(string serverUrl, GenericXmlSecurityToken token)
{
var binding = new WS2007FederationHttpBinding(WSFederationHttpSecurityMode.Message)
{
MaxReceivedMessageSize = int.MaxValue,
MaxBufferPoolSize = int.MaxValue
};
binding.Security.Message.EstablishSecurityContext = false;
binding.Security.Message.IssuedTokenType = "http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1";
binding.Security.Message.NegotiateServiceCredential = false;
binding.ReaderQuotas.MaxDepth = int.MaxValue;
binding.ReaderQuotas.MaxStringContentLength = int.MaxValue;
binding.ReaderQuotas.MaxArrayLength = int.MaxValue;
binding.ReaderQuotas.MaxBytesPerRead = int.MaxValue;
binding.ReaderQuotas.MaxNameTableCharCount = int.MaxValue;
var uri = new Uri(serverUrl + "Test.Service/Test.Service.svc");
var identity = new X509CertificateEndpointIdentity(new X509Certificate2(ConfigurationManager.AppSettings["ServiceCertificate"], ConfigurationManager.AppSettings["ServiceCertificatePassword"]));
var client = new TestServiceClient(binding, new EndpointAddress(uri, identity));
client.ClientCredentials.SupportInteractive = false;
var customBinding = new CustomBinding();
var bindingElements = binding.CreateBindingElements();
if (serverUrl.Contains("https"))
{
bindingElements.Remove<HttpTransportBindingElement>();
bindingElements.Add(new HttpsTransportBindingElement() { MaxReceivedMessageSize = int.MaxValue });
}
customBinding.Elements.AddRange(bindingElements.ToArray());
client.Endpoint.Binding = customBinding;
var clientCredentials = new SamlClientCredentials(token, client.ClientCredentials);
client.Endpoint.Behaviors.Remove<ClientCredentials>();
client.Endpoint.Behaviors.Add(clientCredentials);
return client;
}
private static GenericXmlSecurityToken GetToken(string serverUrl)
{
string username = ConfigurationManager.AppSettings["Username"];
string password = ConfigurationManager.AppSettings["Password"];
string identityDnsName = ConfigurationManager.AppSettings["IdentityDnsName"];
string ClientCertificate = ConfigurationManager.AppSettings["ClientCertificate"];
string ClientCertificatePassword = ConfigurationManager.AppSettings["ClientCertificatePassword"];
string ServiceCertificate = ConfigurationManager.AppSettings["ServiceCertificate"];
string ServiceCertificatePassword = ConfigurationManager.AppSettings["ServiceCertificatePassword"];
var stsUrl = serverUrl + "Security.Sts/Security.Sts.svc";
GenericXmlSecurityToken token = null;
try
{
var customBinding = new CustomBinding();
var securityBindingElement =
(SymmetricSecurityBindingElement) SecurityBindingElement.CreateMutualCertificateBindingElement();
securityBindingElement.SetKeyDerivation(true);
securityBindingElement.MessageSecurityVersion =
MessageSecurityVersion
.WSSecurity11WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10;
securityBindingElement.MessageProtectionOrder = MessageProtectionOrder.SignBeforeEncrypt;
securityBindingElement.RequireSignatureConfirmation = false;
var securityTokenParameters = new UserNameSecurityTokenParameters()
{
InclusionMode = SecurityTokenInclusionMode.AlwaysToRecipient,
RequireDerivedKeys = false
};
securityBindingElement.EndpointSupportingTokenParameters.SignedEncrypted.Add(securityTokenParameters);
customBinding.Elements.Add(securityBindingElement);
if (serverUrl.StartsWith("http:"))
customBinding.Elements.Add(new HttpTransportBindingElement()
{
MaxReceivedMessageSize = int.MaxValue,
MaxBufferPoolSize = int.MaxValue,
MaxBufferSize = int.MaxValue
});
else if (serverUrl.StartsWith("https:"))
customBinding.Elements.Add(new HttpsTransportBindingElement()
{
MaxReceivedMessageSize = int.MaxValue,
MaxBufferPoolSize = int.MaxValue,
MaxBufferSize = int.MaxValue
});
var stsChannelFactory = new WSTrustChannelFactory(customBinding,
new EndpointAddress(new Uri(stsUrl), new DnsEndpointIdentity(identityDnsName)));
stsChannelFactory.Credentials.SupportInteractive = false;
stsChannelFactory.Credentials.ClientCertificate.Certificate = new X509Certificate2(ClientCertificate,
ClientCertificatePassword);
stsChannelFactory.Credentials.ServiceCertificate.DefaultCertificate =
new X509Certificate2(ServiceCertificate, ServiceCertificatePassword);
stsChannelFactory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode =
X509CertificateValidationMode.None;
stsChannelFactory.Credentials.UserName.UserName = username;
stsChannelFactory.Credentials.UserName.Password = password;
foreach (OperationDescription operationDescription in stsChannelFactory.Endpoint.Contract.Operations)
{
var operationBehavior =
operationDescription.Behaviors.Find<DataContractSerializerOperationBehavior>();
if (operationBehavior != null)
operationBehavior.MaxItemsInObjectGraph = int.MaxValue;
}
var stsChannel = stsChannelFactory.CreateChannel();
RequestSecurityToken request = new RequestSecurityToken();
request.KeyType = "http://schemas.microsoft.com/idfx/keytype/symmetric";
request.RequestType = "http://docs.oasis-open.org/ws-sx/ws-trust/200512/Issue";
request.TokenType = "http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1";
token = (GenericXmlSecurityToken) stsChannel.Issue(request);
return token;
}
catch (Exception e)
{
Console.WriteLine("GetToken Exception :" + e);
}
return token;
}
}
internal class SamlClientCredentials : ClientCredentials
{
public GenericXmlSecurityToken Token { get; private set; }
public SamlClientCredentials(GenericXmlSecurityToken token, ClientCredentials clientCredentials)
: base(clientCredentials)
{
Token = token;
}
protected override ClientCredentials CloneCore()
{
return new SamlClientCredentials(Token, this);
}
public override SecurityTokenManager CreateSecurityTokenManager()
{
return new SamlSecurityTokenManager(this);
}
}
internal class SamlSecurityTokenManager : ClientCredentialsSecurityTokenManager
{
private SamlClientCredentials clientCredentials;
public SamlSecurityTokenManager(SamlClientCredentials clientCredentials)
: base(clientCredentials)
{
this.clientCredentials = clientCredentials;
}
public override SecurityTokenProvider CreateSecurityTokenProvider(SecurityTokenRequirement tokenRequirement)
{
if (tokenRequirement.TokenType == SecurityTokenTypes.Saml || tokenRequirement.TokenType == "http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1")
return new SamlSecurityTokenProvider(this.clientCredentials.Token);
return base.CreateSecurityTokenProvider(tokenRequirement);
}
}
internal class SamlSecurityTokenProvider : SecurityTokenProvider
{
private readonly GenericXmlSecurityToken token;
public SamlSecurityTokenProvider(GenericXmlSecurityToken token)
{
this.token = token;
}
protected override SecurityToken GetTokenCore(TimeSpan timeout)
{
return token;
}
}
最佳答案
正如我对这个问题的评论:在花费大量时间搜索解决方案之后,由于服务器身份检查,似乎不打算在这种情况下使用安全模式为“消息”的 WS2007FederationHttpBinding。仍然可以在 SSL 卸载程序和服务身份上使用相同的证书。
这是我选择保留安全模型并解决我的问题的解决方案
关于.net - WCF WS2007FederationHttpBinding 与 HTTPS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38977458/
我有一个使用 spring-ws 的 web 服务(服务器端)的实现。我想更改我的代码以使用 spring-integration-ws(ws:入站网关和 channel )。我已经尝试过示例,但仍然
我正在尝试使用 JAX-WS (Metro) 开发一个独立的 Java Web 服务客户端,它使用 WS-Security 和用户名 token 身份验证(密码摘要、随机数和时间戳)和时间戳验证以及
我开始使用 JAX WS 研究 Java Web 服务。我正在阅读的书的第一章展示了如何仅使用 java SE 构建和部署简单的 jax ws web 服务。特别是,Web 服务是通过 Endpoin
我尝试在 Netbean 6.8 中使用 ws-import 生成 Java 类。我想重新生成 jax-ws,因为在 ebay.api.paypalapi 包中发现了一个错误(我认为该错误是由于 Pa
我正在为我的项目编写服务器端,它需要 websockets 提供的功能。我一直在寻找并在 npm 中找到了 3 个库。 ws、websocket 和express-ws。您能否解释一下它们之间的区别并
我有一个用于测试 Web 服务的项目,它使用 spring-ws 库。spring-ws 在不久的将来会支持 WS-Reliable Messaging 吗? 最佳答案 作为 Spring-WS 的领
我在 Tomcat 上部署了一个有状态的 Web 服务。它由工厂服务和主要 API 服务组成,并且运行良好。工厂服务向主 API 实例返回一个 W3CEndpointReference,客户端使用该
我构建了一个最小的 Web 服务并使用 javax.xml.ws.Endpoint 发布它。如果我尝试在http://localhost:1234/AddService?wsdl 工作正常。 尝试在
我正在实现一个必须支持 WS-Trust (1.3) 的网络服务。 OASIS 将 WS-Trust 的命名空间定义为 http://docs.oasis-open.org/ws-sx/ws-trus
有没有办法操纵jaxws中使用的编码器。 我喜欢发送一个在网络服务请求中提交的 cdata,为此我想在这里尝试类似描述的东西:http://odedpeer.blogspot.de/2010/07/j
我正在尝试使用 Spring-WS 构建一个简单的 Web 服务客户端,但遇到了麻烦。我试图调用的 SOAP 服务使用 HTTP 基本身份验证以确保安全。 使用 Spring-WS 教程示例,我已经配
我对网络服务很陌生。我找不到 JAX-WS 和 CXF 之间的区别。 据我了解,JAX-WS是java提供的规范,CXF是实现。 如果我错了,请纠正我。 最佳答案 是的,你是对的。 JAX-WS 是基
我有很多用 @WebService(targetNamespace = "mynamespace") 注释的端点.每@WebResult和 @WebParam与 targetNamespace = "
根据网上的文献,我可以看到有两个与Web Services Eventing相关的规范: WS-BaseNotification - 由 OASIS 于 2004 年提交 WS-Eventing -
对于基于 SOAP 的 Web 服务,为什么应该选择 Spring WS 而不是 JAX-WS。我已经阅读了一些文章,甚至 Spring WS 文档功能,但我仍然不清楚。如果我需要说服某人使用 Spr
我使用 wsimport 创建了一个肥皂客户端,我需要将消息中字符串字段内的 xml 数据发送到网络服务器。我知道我实际上并不需要在 Web 服务调用中使用 cdata,但 Web 服务需要此字段位于
我想问一下如何在 JAX-WS 中指定 SOAP Web 服务,这样如果我希望通过值 A 或值B。任何其他值都应该返回错误。 我想到了Java中的枚举,但仍然不知道如何实现它。 有什么建议吗?预先感谢
我用 pyws 实现了一个简单的 Web 服务服务器和 suds . from pyws.server import SoapServer from pyws.functions.register i
我正在 javascript 中使用 websockets 连接到 API 并读取一些数据。 这是代码: function processHUOBIAPI(client,exchange_name,e
我正在使用 Node.js + Express + Express-ws 创建应用程序,但在连接后尝试发送消息时出现以下错误: const fs = require('fs'); con
我是一名优秀的程序员,十分优秀!