- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我制作了一个托管 WCF 服务的控制台应用程序。我现在正在尝试修改它。这是目前有效的...
程序.cs:
namespace FileRetrievalPoC
{
class Program
{
static void Main(string[] args)
{
var address = "https://localhost:8000/FileRetrievalPoC";
Console.WriteLine("Starting a service at {0}...", address);
FileRetrievalService.Start(address, StoreLocation.LocalMachine, StoreName.TrustedPeople, "b7ba8f6e4c33ba55053f2e85898b383e40bf8ac9");
Console.WriteLine("Service started.");
Console.WriteLine("Press Enter to create a new proxy client and call the Get method.");
Console.WriteLine("Press Escape to end the application.");
while (true)
{
var key = Console.ReadKey();
if (key.Key == ConsoleKey.Enter)
{
var proxy = FileRetrievalService.Connect(address, "localhost", "username", "password");
Console.WriteLine("Read the following from the server: {0}", proxy.Get(@"C:\Users\User\Desktop\Document.txt"));
FileRetrievalService.CloseClients();
}
else if (key.Key == ConsoleKey.Escape)
break;
}
FileRetrievalService.CloseServer();
}
}
}
FileRetrievalService.cs:
class FileRetrievalService : IFileRetrieval
{
private static BasicHttpsBinding _binding = new BasicHttpsBinding()
{
HostNameComparisonMode = HostNameComparisonMode.Exact,
Security = new BasicHttpsSecurity()
{
Message = new BasicHttpMessageSecurity()
{
AlgorithmSuite = SecurityAlgorithmSuite.Basic256Sha256Rsa15,
ClientCredentialType = BasicHttpMessageCredentialType.UserName
},
Mode = BasicHttpsSecurityMode.TransportWithMessageCredential,
Transport = new HttpTransportSecurity()
{
ClientCredentialType = HttpClientCredentialType.Windows,
}
}
};
private static ChannelFactory<IFileRetrieval> _channelFactory;
private static ServiceHost _host;
public static void Start(string address, StoreLocation location, StoreName name, string thumbprint)
{
_host = new ServiceHost(typeof(FileRetrievalService));
_host.Credentials.ServiceCertificate.SetCertificate(location, name, X509FindType.FindByThumbprint, thumbprint);
_host.AddServiceEndpoint(typeof(IFileRetrieval), _binding, address);
_host.Open();
}
public static void CloseClients()
{
if (_channelFactory != null)
_channelFactory.Close();
_channelFactory = null;
}
public static void CloseServer()
{
if (_host != null)
_host.Close();
_host = null;
}
public static void CloseServerAndClients()
{
CloseServer();
CloseClients();
}
public static IFileRetrieval Connect(string address, string domain, string username, string password)
{
if (_channelFactory == null)
{
_channelFactory = new ChannelFactory<IFileRetrieval>(_binding, address);
_channelFactory.Credentials.UserName.UserName = domain + '\\' + username;
_channelFactory.Credentials.UserName.Password = password;
_channelFactory.Credentials.Windows.ClientCredential = new NetworkCredential(username, password, domain);
}
return _channelFactory.CreateChannel();
}
public string Get(string path)
{
return File.ReadAllText(path);
}
public void Set(string path, string contents)
{
File.WriteAllText(path, contents);
}
}
IFileRetrieval.cs:
[ServiceContract]
public interface IFileRetrieval
{
[OperationContract]
string Get(string path);
[OperationContract]
void Set(string path, string contents);
}
以上所有代码都有效,因为:
ClientCredentialType = BasicHttpMessageCredentialType.UserName
。_channelFactory.Credentials.UserName
对象上设置用户名凭据。我想增加安全性,并让客户端在连接到服务器时也提供 SSL 证书。为了尝试做到这一点,我使用以下逻辑对第 1 点和第 2 点的代码进行了以下替换:
ClientCredentialType = BasicHttpMessageCredentialType.Certificate
而不是 ClientCredentialType = BasicHttpMessageCredentialType.UserName
。Connect
方法中,我现在正在设置客户端的证书 (_channelFactory.Credentials.ClientCertificate.SetCertificate(location, name, X509FindType.FindByThumbprint, thumbprint);
)并修改方法以获取适当的证书信息(StoreLocation 位置、StoreName 名称、字符串指纹
),传递完全相同的参数以从客户端引用从客户端提供的相同证书服务器端。我删除了之前设置 _channelFactory.Credentials.UserName
对象的逻辑。这没有用,我得到以下异常:
An unsecured or incorrectly secured fault was received from the other party. See the inner FaultException for the fault code and detail.
它的内部异常说:
An error occurred when verifying security for the message.
从这里去哪里?我没有使用 IIS,那么如何进一步跟踪此错误?我有点不知所措。我希望有人能解释可能出了什么问题,以及我可以做些什么来修复错误或进一步调试它。
编辑:我找到了一种进一步调试它的方法,但它并没有比我想象的更有帮助。在我的 App.config
中,我添加了以下跟踪:
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="Verbose, ActivityTracing" propagateActivity="true">
<listeners>
<add name="listener" type="System.Diagnostics.XmlWriterTraceListener" initializeData= "C:\Users\YourAccountUsername\Desktop\WCFTraces.svclog" />
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging" switchValue="Verbose, ActivityTracing" propagateActivity="true">
<listeners>
<add name="listener" type="System.Diagnostics.XmlWriterTraceListener" initializeData= "C:\Users\YourAccountUsername\Desktop\WCFTraces.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
现在在 WCFTraces.svclog
中,我也看到了服务器端的一堆异常。第一个是:
Security processor was unable to find a security header in the message. This might be because the message is an unsecured fault or because there is a binding mismatch between the communicating parties. This can occur if the service is configured for security and the client is not using security.
考虑到我已经指定了客户端证书,我不确定为什么消息没有安全 header 。缺少什么客户端代码?
编辑:啊,我也看到了这个错误:
The key size requirements for the 'Basic256Sha256Rsa15' algorithm suite are not met by the 'System.IdentityModel.Tokens.X509SecurityToken' token which has key size of '8192'.
它收到的字节数不足。我的证书有一个 8192 字节的私钥和公钥,但这一定不能很好地匹配我选择的 AlgorithmSuite = SecurityAlgorithmSuite.Basic256Sha256Rsa15
。有谁知道我应该在这里做什么来允许这个证书?我可以尝试为此使用 256 位 key ...还是我的证书上的签名算法是 512 位的问题?
最佳答案
我终于明白了。这些错误误导我走上了一条黑暗的道路,但现在我明白了。
问题
这似乎是不成文的规定。当您指定 Mode = BasicHttpsSecurityMode.TransportWithMessageCredential
以告诉它同时使用消息和传输凭据,然后您使用证书作为消息凭据时,
Message = new BasicHttpMessageSecurity()
{
AlgorithmSuite = SecurityAlgorithmSuite.Basic256Sha256Rsa15,
ClientCredentialType = BasicHttpMessageCredentialType.Certificate
}
如果证书的 key 超过 4096 位,则您不能将证书用作消息凭据。
解决方案
我用 4096 位 RSA key 对制作了一个新的自签名证书,使用 SHA 512 作为签名算法。
关于c# - 无法获取证书消息凭据以在我的 WCF 服务中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31326727/
我有一个问题,我不断收到错误 没有为“svn.ssl.server”凭据注册的提供者 我正在使用在另一台 SVN 服务器上工作的相同代码,但我设置的新服务器似乎无法连接,即使我可以通过 Web 浏览器
如何通过 shell 在 Hudson 中输入 subversion 凭据? 我尝试在 HUDSON_HOME 中生成文件 hudson.scm.SubversionSCM.xml 并重新加载配置,但
我正在尝试使用 powershell 访问远程注册表,如下所示: $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("LocalMachi
我需要将凭据存储在 powershell 中以便多次使用。 StackOverflow 上有很多例子,所以我拿了一个 $tmpCred = Get-Credential $tmpCred.Passwo
我遇到了 youtube java 凭据的问题,通常它运行良好并且我能够上传到 youtube,但今天我收到此异常无效的凭据。 YouTubeService service = new YouTube
我正在阅读中提供的 Hadoop 凭证文档 https://hadoop.apache.org/docs/current/hadoop-project-dist/hadoop-common/Crede
我想知道在为 MySQL 凭据/主机创建变量时最佳做法或建议做什么。 define('HOST', 'localhost'); // etc.. mysql_connect(HO
我试图让 Jenkins 从 BitBucket 克隆我的 mercurial 项目。它不会,因为它说凭据有问题 - 好吧,bitbucket 拒绝 Jenkins 提供的任何内容。 我几乎 100%
这里有一百万篇关于如何使用 git 缓存凭据的帖子。但是,如果机器重新启动,它们似乎都不成立。有没有办法缓存在机器重新启动时持续的凭据? 最佳答案 是的,在 Debian 和 Ubuntu 上,您可以
我正在尝试在我的环境中为 IIS 节点使用共享配置,我想使用组托管服务帐户凭据来实现这一目标。 当我将应用程序池的凭据应用为 MyDomain\GmsaAccount$ 时,它运行良好,但是当我尝试在
我创建了一个应用程序,它充当 2 个不同 API(WebEx 和 Exchange Web 服务)和电子邮件之间的桥梁。用户向一个特殊的电子邮件地址发送日历邀请,该应用程序解析 ICS 并创建一个 W
我正在尝试将凭据从 Jenkins 迁移到另一个凭据存储。 我想从 Jenkins 商店读取凭据,并找到了这个脚本 ( https://github.com/tkrzeminski/jenkins-g
我有一个在 Windows 上运行的 Jenkins 服务器。它将用户名:密码存储在凭据插件中。这是一个定期更新密码的服务用户。 我正在寻找一种运行脚本的方法,最好是 Powershell,它将更新
我想知道如何创建 Jenkins 和 Jenkins 中运行的作业可以使用的凭据以连接到 3rd 方服务。 最佳答案 您应该指定您将使用的第 3 方服务。 以下是带有 的凭据示例bitbucket 我
我正在一个网站上工作,我们希望使用 Spring Security Kerberos 使用 Kerberos 身份验证。所以,我们不支持 NTLM。当用户发出未经身份验证的请求时,服务器将回复带有 h
如果我设置 git config --global credential.username my_username 选项,然后使用 --local 选项覆盖一个存储库,这并没有什么区别 - 它在尝试提
我正在尝试使用需要 gce_client_id 和 gce_client_secret key 的第 3 方应用程序。为了生成它们,我浏览了凭据图标并尝试创建一个 OAuth 2.0 客户端 ID。但
我在使用 Azure 时遇到身份验证问题。我有一个运行 powershell 脚本的连续构建服务器,我收到如下消息: Your Azure credentials have not been set
首先,我想说我在安全和身份验证方面的知识非常有限。 我有一个应用程序可以从 docker store 中提取和运行容器。这是一个私有(private)仓库,所以我需要传递用户名和密码,以便用户可以拉取
我使用 Google 文档中的代码(如下所示)来管理 Google 日历。 public class CalendarQuickstart { private static final Str
我是一名优秀的程序员,十分优秀!