param([Parameter(Mandatory=$true)][string]$OutputDirectory) $ErrorActionPreference = 'Stop' $folder = [IO.Path]::GetFullPath($OutputDirectory) [IO.Directory]::CreateDirectory($folder) | Out-Null if ((Test-Path (Join-Path $folder 'server.crt')) -or (Test-Path (Join-Path $folder 'server.key'))) { throw 'Certificat deja present : choisir un dossier neuf.' } # Local demonstration certificate only. No certificate-store or trusted-root changes. Add-Type -TypeDefinition @' using System; using System.IO; using System.Linq; using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; using System.Text; public static class OdycerLocalTls { static byte[] Der(byte tag, byte[] bytes) { byte[] length; if(bytes.Length<128) length=new byte[]{(byte)bytes.Length}; else { var v=BitConverter.GetBytes(bytes.Length).Reverse().SkipWhile(b=>b==0).ToArray(); length=new byte[]{(byte)(128+v.Length)}.Concat(v).ToArray(); } return new byte[]{tag}.Concat(length).Concat(bytes).ToArray(); } static byte[] Integer(byte[] value) { var v=value.SkipWhile(b=>b==0).ToArray(); if(v.Length==0) v=new byte[]{0}; if(v[0]>=128) v=new byte[]{0}.Concat(v).ToArray(); return Der(2,v); } static string Pem(string name,byte[] bytes) { string raw=Convert.ToBase64String(bytes); var output=new StringBuilder("-----BEGIN "+name+"-----\n"); for(int i=0;i