Skip to content

Instantly share code, notes, and snippets.

@CIPop
Last active November 6, 2018 03:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CIPop/baf530337cc6b29e3d6a88047661f69c to your computer and use it in GitHub Desktop.
Save CIPop/baf530337cc6b29e3d6a88047661f69c to your computer and use it in GitHub Desktop.
Tool to import certificates into the My\Intermediate Certificate store.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the https://github.com/dotnet/corefx project root for more information.
// Usage: <ImportIntermediateCerts.exe> <certificateChain.p7b>
// Importing certificates into the Intermediate Certificate store is required if the remote server
// has access only to the Root CA but not to the entire chain.
using System;
using System.Security.Cryptography.X509Certificates;
namespace CertificateTool
{
class Program
{
static void Main(string[] args)
{
if (args.Length < 1)
{
Console.WriteLine("Missing path to certificate collection file (*.p7b).");
return;
}
Console.WriteLine($"Importing certificate {args[0]}.");
var certs = new X509Certificate2Collection();
certs.Import(args[0]);
Console.WriteLine("Opening store.");
var store = new X509Store(StoreName.CertificateAuthority, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadWrite);
Console.WriteLine($"Importing {certs.Count} certificates");
store.AddRange(certs);
store.Close();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment