Authentication 使用Cordova验证证书

Authentication 使用Cordova验证证书,authentication,cordova,ssl,certificate,Authentication,Cordova,Ssl,Certificate,我想知道是否有一种简单/推荐的方法来验证Cordova中的远程站点证书。我希望我的应用程序验证$remote.thumbprint是否在预期指纹列表中,并且没有人MITM。代码(和列表)应该通过应用商店部署在手机上(我只是假设它们是可信的) 最好是一个简单的解决方案,不需要Android、IOS和WP的特定平台代码?为了查看远程站点上的证书信息,您必须访问该远程服务器。但是,假设您有权访问服务器,您可以编写一些服务器代码,返回指纹值列表以及您可能需要返回的其他内容。下面是如何使用asp.net使

我想知道是否有一种简单/推荐的方法来验证Cordova中的远程站点证书。我希望我的应用程序验证$remote.thumbprint是否在预期指纹列表中,并且没有人MITM。代码(和列表)应该通过应用商店部署在手机上(我只是假设它们是可信的)


最好是一个简单的解决方案,不需要Android、IOS和WP的特定平台代码?

为了查看远程站点上的证书信息,您必须访问该远程服务器。但是,假设您有权访问服务器,您可以编写一些服务器代码,返回指纹值列表以及您可能需要返回的其他内容。下面是如何使用asp.net使用C#实现此功能:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security.Cryptography;
using System.Security.Permissions;
using System.IO;
using System.Security.Cryptography.X509Certificates;

namespace FIPWS01
{
    public partial class certtest : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {


            try

            {

                X509Store store = new X509Store(StoreLocation.LocalMachine);

                store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);

                X509Certificate2Collection collection = (X509Certificate2Collection)store.Certificates;

               // X509Certificate2Collection fcollection = (X509Certificate2Collection)collection.Find(X509FindType.FindBySubjectName, "Kilpatrick", false);

                X509Certificate2Collection fcollection = (X509Certificate2Collection)collection.Find(X509FindType.FindBySubjectName, "[your info here]", false);

                Response.Write("Number of certificates: " + fcollection.Count + "<br>");

                foreach (X509Certificate2 x509 in fcollection)

                {

                    byte[] rawdata = x509.RawData;

                    Response.Write("Friendly Name: " + x509.FriendlyName + "<br>");

                    Response.Write("Simple Name: " + x509.GetNameInfo(X509NameType.SimpleName, true) +  "<br>");

                    Response.Write("Thumb Print: " + x509.Thumbprint + "<br>");

                }

                store.Close();

            }

            catch (CryptographicException)

                {

                    Response.Write("Information could not be written out for this certificate.");

                }




        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Web.UI;
使用System.Web.UI.WebControl;
使用System.Security.Cryptography;
使用System.Security.Permissions;
使用System.IO;
使用System.Security.Cryptography.X509证书;
命名空间FIPWS01
{
公共部分类certtest:System.Web.UI.Page
{
受保护的无效页面加载(对象发送方、事件参数e)
{
尝试
{
X509Store=新的X509Store(StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
X509Certificate2Collection=(X509Certificate2Collection)store.Certificates;
//X509Certificate2Collection fcollection=(X509Certificate2Collection)collection.Find(X509FindType.FindBySubjectName,“Kilprick”,false);
X509Certificate2Collection fcollection=(X509Certificate2Collection)collection.Find(X509FindType.FindBySubjectName,“[此处的信息]”,false);
响应。写入(“证书数量:+fcollection.Count+”
”; foreach(X509Certificate2 x509在fcollection中) { 字节[]rawdata=x509.rawdata; 回答。写下(“友好名称:+x509.FriendlyName+”
”; Write(“简单名称:”+x509.GetNameInfo(X509NameType.SimpleName,true)+“
”; 响应。写入(“指纹:+x509.指纹+”
”; } store.Close(); } 捕获(加密例外) { 答复。填写(“无法填写此证书的信息”); } } } }