94b2861243
Former-commit-id: 5f9c6ae75f295e057a7d2971f3a6df4656fa8850
62 lines
1.9 KiB
C#
62 lines
1.9 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Text;
|
|
using System.Security.Cryptography.X509Certificates;
|
|
using MNS = Mono.Net.Security;
|
|
|
|
namespace Mono.Btls
|
|
{
|
|
static class BtlsCertSync
|
|
{
|
|
static void Main (string[] args)
|
|
{
|
|
if (!MNS.MonoTlsProviderFactory.IsBtlsSupported ()) {
|
|
Console.Error.WriteLine ("BTLS is not supported in this runtime!");
|
|
Environment.Exit (255);
|
|
}
|
|
|
|
var configPath = Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData);
|
|
configPath = Path.Combine (configPath, ".mono");
|
|
|
|
var oldStorePath = Path.Combine (configPath, "certs", "Trust");
|
|
var newStorePath = MonoBtlsX509StoreManager.GetStorePath (MonoBtlsX509StoreType.UserTrustedRoots);
|
|
|
|
if (!Directory.Exists (oldStorePath)) {
|
|
Console.WriteLine ("Old trust store {0} does not exist.");
|
|
Environment.Exit (255);
|
|
}
|
|
|
|
if (Directory.Exists (newStorePath))
|
|
Directory.Delete (newStorePath, true);
|
|
Directory.CreateDirectory (newStorePath);
|
|
|
|
var oldfiles = Directory.GetFiles (oldStorePath, "*.cer");
|
|
Console.WriteLine ("Found {0} files in the old store.", oldfiles.Length);
|
|
|
|
foreach (var file in oldfiles) {
|
|
Console.WriteLine ("Converting {0}.", file);
|
|
var data = File.ReadAllBytes (file);
|
|
using (var x509 = MonoBtlsX509.LoadFromData (data, MonoBtlsX509Format.DER)) {
|
|
ConvertToNewFormat (newStorePath, x509);
|
|
}
|
|
}
|
|
}
|
|
|
|
static void ConvertToNewFormat (string root, MonoBtlsX509 x509)
|
|
{
|
|
long hash = x509.GetSubjectNameHash ();
|
|
|
|
string newName;
|
|
int index = 0;
|
|
do {
|
|
newName = Path.Combine (root, string.Format ("{0:x8}.{1}", hash, index++));
|
|
} while (File.Exists (newName));
|
|
Console.WriteLine (" new name: {0}", newName);
|
|
|
|
using (var stream = new FileStream (newName, FileMode.Create))
|
|
using (var bio = MonoBtlsBio.CreateMonoStream (stream))
|
|
x509.ExportAsPEM (bio, true);
|
|
}
|
|
}
|
|
}
|