科尔多瓦插件 x509store
cordova plugin x509store
我必须开发一个 cordova 主要针对 Windows 平台的应用程序。
在这个应用程序中,我必须操纵认证商店。长话短说,我必须做一个 cordova 插件(或者可能是一个 activeX 技巧)。
我在 C# 中制作了一个 windows 运行时组件,如 here 所述,以使用 X509Store(因为我需要 Windows)。
我用visual studio 2015做了一个windows运行时组件项目(我试过通用windows和8.1)。它有效,我可以在我的 .js 中调用 C# 方法。
但问题是:windows 运行时组件项目没有命名空间 System.Security.Cryptography.X509Certificates。所以我无法访问 X509Store。
作为解决方法,我制作了一个 Class 库(.NetCore、.dll),它调用 X509Store 和 return 字符串,至少显示证书(json stringify) . classic class 库也可以访问 x509store 但是当我在这个 windows 运行时组件项目中引用它时它会出现目标错误。 (portable/universal dll 项目也没有 X509Store)。我的 .netcore dll 有效,我在控制台应用程序 (.NetCore) 项目中尝试过它,它显示了我所有的证书。但是当我从 cordova 应用程序(cordova 应用程序 -> 插件 -> 运行时 -> .netcore dll)调用它时,它是空的(未找到证书,并且当前用户未定义)。我认为这是因为执行上下文不一样(webapp vs console app)。而且我认为这不是一个好的解决方案(甚至不起作用)。
那么,如何在 windows 运行时组件中访问(windows 用户的)证书存储?因为我认为 javascript.
不可能
谢谢
P.S: 如果需要我可以提供一些源代码
编辑:
我忘记了运行时项目中存在与 .netcore dll 的程序集冲突,我通过在 plugin.xml 文件(System.Runtime.dll 等 ..)中引用正确的 dll 来解决,因为我没有设法解决它在 visual studio
//script inside cordova, called after device ready
signatureplugin.getAllCertNames(function(a) { }, function(a) { }, 0);
//signatureplugin.js
var exec = require('cordova/exec');
module.exports = {
getAllCertNames: function(successCallback, errorCallback, args) {
exec(successCallback, errorCallback, "SignaturePlugin", "getAllCertNames", [args]);
}
};
//signaturepluginProxy.js
module.exports = {
getAllCertNames: function(successCallback, errorCallback, args) {
var res = SignerVerifier.PluginRT.getAllCertNames();
for (var i = 0, len = res.length; i < len; i++) {
alert(res[i]);
}
}
};
require("cordova/exec/proxy").add("SignaturePlugin", module.exports);
//windows runtime component
using CertStore;
namespace SignerVerifier
{
public sealed class PluginRT
{
public static string[] getAllCertNames()
{
var certStore = new StoreManager();
var res = certStore.getAllCertificates();
return res;
}
}
}
//.NetCore dll
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
using Newtonsoft.Json;
using System;
namespace CertStore
{
public class StoreManager
{
private X509Store store;
public StoreManager()
{
store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
}
public string[] getAllCertificates()
{
List<string> res = new List<string>();
store.Open(OpenFlags.ReadOnly);
var certificates = store.Certificates;
foreach (var cert in certificates)
{
res.Add(JsonConvert.SerializeObject(cert));
}
store.Dispose();
return res.ToArray();
}
}
}
如果我做一个 javascript 空白应用程序项目 + Windows 运行时组件项目(来自 "universal" 的项目,我没有 "Windows Store",我使用 windows 10) 然后添加 .netcore dll 我得到了导致异常的冲突:
System.IO.FileLoadException: Could not load file or assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
(在 cordova 中,我通过从 .netcore 中使用的 nuget 包 NETStandard.Library.1.6.0 引用 System.Runtime.dll 等来防止此异常)
我一定错过了什么。 .NetCore dll 似乎不兼容,但 windows 运行时项目目标 .NetCore
编辑 2:(已解决)
vcsjones 的回答 = 无用的解决方法(并且之前的编辑没有问题)。
但是无论如何都存在安全问题,我必须在 appxmanifest
的 Capabilities 中检查 "Shared User Certificates"
WinRT 的证书管理不同于桌面和核心框架。对于 WinRT,您将使用 Windows.Security
命名空间。
您可以使用 Windows.Security.Cryptography.Certificates.CertificateStore
class 打开和管理证书存储。
我必须开发一个 cordova 主要针对 Windows 平台的应用程序。 在这个应用程序中,我必须操纵认证商店。长话短说,我必须做一个 cordova 插件(或者可能是一个 activeX 技巧)。 我在 C# 中制作了一个 windows 运行时组件,如 here 所述,以使用 X509Store(因为我需要 Windows)。 我用visual studio 2015做了一个windows运行时组件项目(我试过通用windows和8.1)。它有效,我可以在我的 .js 中调用 C# 方法。
但问题是:windows 运行时组件项目没有命名空间 System.Security.Cryptography.X509Certificates。所以我无法访问 X509Store。
作为解决方法,我制作了一个 Class 库(.NetCore、.dll),它调用 X509Store 和 return 字符串,至少显示证书(json stringify) . classic class 库也可以访问 x509store 但是当我在这个 windows 运行时组件项目中引用它时它会出现目标错误。 (portable/universal dll 项目也没有 X509Store)。我的 .netcore dll 有效,我在控制台应用程序 (.NetCore) 项目中尝试过它,它显示了我所有的证书。但是当我从 cordova 应用程序(cordova 应用程序 -> 插件 -> 运行时 -> .netcore dll)调用它时,它是空的(未找到证书,并且当前用户未定义)。我认为这是因为执行上下文不一样(webapp vs console app)。而且我认为这不是一个好的解决方案(甚至不起作用)。
那么,如何在 windows 运行时组件中访问(windows 用户的)证书存储?因为我认为 javascript.
不可能谢谢
P.S: 如果需要我可以提供一些源代码
编辑:
我忘记了运行时项目中存在与 .netcore dll 的程序集冲突,我通过在 plugin.xml 文件(System.Runtime.dll 等 ..)中引用正确的 dll 来解决,因为我没有设法解决它在 visual studio
//script inside cordova, called after device ready
signatureplugin.getAllCertNames(function(a) { }, function(a) { }, 0);
//signatureplugin.js
var exec = require('cordova/exec');
module.exports = {
getAllCertNames: function(successCallback, errorCallback, args) {
exec(successCallback, errorCallback, "SignaturePlugin", "getAllCertNames", [args]);
}
};
//signaturepluginProxy.js
module.exports = {
getAllCertNames: function(successCallback, errorCallback, args) {
var res = SignerVerifier.PluginRT.getAllCertNames();
for (var i = 0, len = res.length; i < len; i++) {
alert(res[i]);
}
}
};
require("cordova/exec/proxy").add("SignaturePlugin", module.exports);
//windows runtime component
using CertStore;
namespace SignerVerifier
{
public sealed class PluginRT
{
public static string[] getAllCertNames()
{
var certStore = new StoreManager();
var res = certStore.getAllCertificates();
return res;
}
}
}
//.NetCore dll
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
using Newtonsoft.Json;
using System;
namespace CertStore
{
public class StoreManager
{
private X509Store store;
public StoreManager()
{
store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
}
public string[] getAllCertificates()
{
List<string> res = new List<string>();
store.Open(OpenFlags.ReadOnly);
var certificates = store.Certificates;
foreach (var cert in certificates)
{
res.Add(JsonConvert.SerializeObject(cert));
}
store.Dispose();
return res.ToArray();
}
}
}
如果我做一个 javascript 空白应用程序项目 + Windows 运行时组件项目(来自 "universal" 的项目,我没有 "Windows Store",我使用 windows 10) 然后添加 .netcore dll 我得到了导致异常的冲突:
System.IO.FileLoadException: Could not load file or assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
(在 cordova 中,我通过从 .netcore 中使用的 nuget 包 NETStandard.Library.1.6.0 引用 System.Runtime.dll 等来防止此异常) 我一定错过了什么。 .NetCore dll 似乎不兼容,但 windows 运行时项目目标 .NetCore
编辑 2:(已解决)
vcsjones 的回答 = 无用的解决方法(并且之前的编辑没有问题)。
但是无论如何都存在安全问题,我必须在 appxmanifest
WinRT 的证书管理不同于桌面和核心框架。对于 WinRT,您将使用 Windows.Security
命名空间。
您可以使用 Windows.Security.Cryptography.Certificates.CertificateStore
class 打开和管理证书存储。