private SafeguardA2AContext(string networkAddress, CertificateContext clientCertificate, int apiVersion,
                                    bool ignoreSsl)
        {
            _networkAddress = networkAddress;
            _apiVersion     = apiVersion;

            var safeguardA2AUrl = $"https://{_networkAddress}/service/a2a/v{_apiVersion}";

            _a2AClient = new RestClient(safeguardA2AUrl);

            var safeguardCoreUrl = $"https://{_networkAddress}/service/core/v{_apiVersion}";

            _coreClient = new RestClient(safeguardCoreUrl);

            if (ignoreSsl)
            {
                _ignoreSsl = true;
                _a2AClient.RemoteCertificateValidationCallback  += (sender, certificate, chain, errors) => true;
                _coreClient.RemoteCertificateValidationCallback += (sender, certificate, chain, errors) => true;
            }

            _clientCertificate            = clientCertificate.Clone();
            _a2AClient.ClientCertificates = new X509Certificate2Collection()
            {
                _clientCertificate.Certificate
            };
            _coreClient.ClientCertificates = new X509Certificate2Collection()
            {
                _clientCertificate.Certificate
            };
        }
        private SafeguardA2AContext(string networkAddress, string certificateThumbprint, string certificatePath,
                                    SecureString certificatePassword, int apiVersion, bool ignoreSsl)
        {
            _networkAddress = networkAddress;

            // set cloning properties
            _certificateThumbprint = certificateThumbprint;
            _certificatePath       = certificatePath;
            _certificatePassword   = certificatePassword?.Copy();
            _apiVersion            = apiVersion;

            var safeguardA2AUrl = $"https://{_networkAddress}/service/a2a/v{_apiVersion}";

            _a2AClient = new RestClient(safeguardA2AUrl);

            if (ignoreSsl)
            {
                _ignoreSsl = true;
                _a2AClient.RemoteCertificateValidationCallback += (sender, certificate, chain, errors) => true;
            }
            _clientCertificate = !string.IsNullOrEmpty(_certificateThumbprint)
                ? new CertificateContext(_certificateThumbprint)
                : new CertificateContext(_certificatePath, _certificatePassword);
            _a2AClient.ClientCertificates = new X509Certificate2Collection()
            {
                _clientCertificate.Certificate
            };
        }
Exemple #3
0
        internal void SignData(StringBuilder sb, CertificateContext certContext)
        {
            this._logProvider.LogMessage(String.Format("Signing request with certificate from context: {0}", certContext.ToString()));
            var base64  = this._certificateManager.SignToBase64(sb.ToString(), certContext);
            var escaped = Uri.EscapeDataString(Helper.UpperCaseUrlEncode(base64));

            sb.AppendFormat("&{0}={1}", HttpRedirectBindingConstants.Signature, escaped);
        }
Exemple #4
0
 public SafeguardEventListener(string eventUrl, CertificateContext clientCertificate, SecureString apiKey,
     bool ignoreSsl, RemoteCertificateValidationCallback validationCallback) : this(eventUrl, ignoreSsl, validationCallback)
 {
     _clientCertificate = clientCertificate.Clone();
     if (apiKey == null)
         throw new ArgumentException("Parameter may not be null", nameof(apiKey));
     _apiKey = apiKey.Copy();
 }
        public ICertificateStore GetStoreFromContext(CertificateContext certContext)
        {
            if (certContext is X509CertificateContext)
            {
                return(new X509StoreCertificateConfiguration(certContext));
            }

            throw new NotSupportedException(String.Format("Certificate context of type: {0} is not supported.", certContext.GetType().Name));
        }
Exemple #6
0
        public bool CheckCompatibility(CertificateContext context)
        {
            if (null == context)
            {
                throw new ArgumentNullException(nameof(context));
            }

            return(true);
        }
Exemple #7
0
        public Form GetForm(CertificateContext context)
        {
            if (null == context)
            {
                throw new ArgumentNullException(nameof(context));
            }

            return(GetForm(context, context.Certificate.Identifier));
        }
        internal void SignData(HttpRedirectContext context, CertificateContext certContext)
        {
            var query = context.BuildQuesryString();

            this._logProvider.LogMessage(String.Format("Signing request with certificate from context: {0}", certContext.ToString()));
            var base64 = this._certificateManager.SignToBase64(query, certContext);

            context.RequestParts.Add(HttpRedirectBindingConstants.Signature, base64);
        }
Exemple #9
0
        public X509StoreCertificateConfiguration(CertificateContext certificateContext)
            : base(new X509Store(((X509CertificateContext)certificateContext).StoreName, ((X509CertificateContext)certificateContext).StoreLocation))
        {
            if (certificateContext == null)
            {
                throw new ArgumentNullException("certificateContext");
            }

            this._certificateContext = certificateContext;
        }
Exemple #10
0
        public bool VerifySignatureFromBase64(string data, string signed, CertificateContext certContext)
        {
            var dataBytes   = Encoding.UTF8.GetBytes(data);
            var signedBytes = Convert.FromBase64String(signed);

            var cert     = this.GetCertificateFromContext(certContext);
            var verified = RSADataProtection.VerifyDataSHA1Signed((RSA)cert.PrivateKey, dataBytes, signedBytes);

            return(verified);
        }
        /// <summary>
        /// Sign data and encode it as base64
        /// </summary>
        /// <param name="dataToSign"></param>
        /// <param name="certContext"></param>
        /// <returns></returns>
        public string SignToBase64(string dataToSign, CertificateContext certContext)
        {
            this._logProvider.LogMessage(String.Format("Signing data with certificate from context: {0}", certContext.ToString()));
            var data   = Encoding.UTF8.GetBytes(dataToSign);
            var cert   = this.GetCertificateFromContext(certContext);
            var signed = this.SignData(dataToSign, cert);

            var base64 = Convert.ToBase64String(signed);

            return(base64);
        }
Exemple #12
0
        public static X509CertificateImpl InitFromHandleCore(IntPtr handle)
        {
            // both Marshal.PtrToStructure and Marshal.Copy use LinkDemand (so they will always success from here)
            CertificateContext cc = (CertificateContext)Marshal.PtrToStructure(handle, typeof(CertificateContext));

            byte[] data = new byte [cc.cbCertEncoded];
            Marshal.Copy(cc.pbCertEncoded, data, 0, (int)cc.cbCertEncoded);
            var x509 = new MX.X509Certificate(data);

            return(new X509CertificateImplMono(x509));
        }
Exemple #13
0
 private void InitFromHandle(IntPtr handle)
 {
     if (handle != IntPtr.Zero)
     {
         // both Marshal.PtrToStructure and Marshal.Copy use LinkDemand (so they will always success from here)
         CertificateContext cc   = (CertificateContext)Marshal.PtrToStructure(handle, typeof(CertificateContext));
         byte[]             data = new byte [cc.cbCertEncoded];
         Marshal.Copy(cc.pbCertEncoded, data, 0, (int)cc.cbCertEncoded);
         x509 = new Mono.Security.X509.X509Certificate(data);
     }
     // for 1.x IntPtr.Zero results in an "empty" certificate instance
 }
Exemple #14
0
 public SafeguardEventListener(string eventUrl, CertificateContext clientCertificate, IEnumerable<SecureString> apiKeys,
     bool ignoreSsl, RemoteCertificateValidationCallback validationCallback) : this(eventUrl, ignoreSsl, validationCallback)
 {
     _clientCertificate = clientCertificate.Clone();
     if (apiKeys == null)
         throw new ArgumentException("Parameter may not be null", nameof(apiKeys));
     _apiKeys = new List<SecureString>();
     foreach (var apiKey in apiKeys)
         _apiKeys.Add(apiKey.Copy());
     if (!_apiKeys.Any())
         throw new ArgumentException("Parameter must include at least one item", nameof(apiKeys));
 }
        /// <summary>
        /// Get x509 store from certificate context. Only x509 store supported.
        /// </summary>
        /// <param name="certContext"></param>
        /// <returns></returns>
        public ICertificateStore GetStoreFromContext(CertificateContext certContext)
        {
            var sb          = new StringBuilder();
            var x509Context = certContext as X509CertificateContext;

            if (x509Context == null)
            {
                sb.AppendFormat("Certificate context of type: {0} is not supported.", certContext.GetType().Name);
                throw new NotSupportedException(sb.ToString());
            }

            sb.AppendLine("Try to get certificate store from context. Certificate context details:");
            sb.AppendLine(x509Context.ToString());
            this._logProvider.LogMessage(sb.ToString());

            return(new X509StoreCertificateConfiguration(x509Context));
        }
Exemple #16
0
		public IntPtr GetHandleEx (byte[] certificate) 
		{
			CertificateContext cc = new CertificateContext ();
//			cc.dwCertEncodingType = 0x10001; // PKCS_7_ASN_ENCODING | X509_ASN_ENCODING
//			cc.dwCertEncodingType = 0x10000; // PKCS_7_ASN_ENCODING 
			cc.dwCertEncodingType = 0x1; // X509_ASN_ENCODING
			cc.cbCertEncoded = (UInt32) certificate.Length;
			cc.pbCertEncoded = Marshal.AllocCoTaskMem (certificate.Length);
			cc.pCertInfo = (IntPtr) 0;
			cc.hCertStore = (IntPtr) 0;
			Marshal.Copy (certificate, 0, cc.pbCertEncoded, certificate.Length);

			int size = Marshal.SizeOf (cc.GetType ());
			IntPtr result = Marshal.AllocCoTaskMem (size);
			Marshal.StructureToPtr (cc, result, false);
			return result;
		}
Exemple #17
0
        public IntPtr GetHandleEx(byte[] certificate)
        {
            CertificateContext cc = new CertificateContext();

//			cc.dwCertEncodingType = 0x10001; // PKCS_7_ASN_ENCODING | X509_ASN_ENCODING
//			cc.dwCertEncodingType = 0x10000; // PKCS_7_ASN_ENCODING
            cc.dwCertEncodingType = 0x1;             // X509_ASN_ENCODING
            cc.cbCertEncoded      = (UInt32)certificate.Length;
            cc.pbCertEncoded      = Marshal.AllocCoTaskMem(certificate.Length);
            cc.pCertInfo          = (IntPtr)0;
            cc.hCertStore         = (IntPtr)0;
            Marshal.Copy(certificate, 0, cc.pbCertEncoded, certificate.Length);

            int    size   = Marshal.SizeOf(cc.GetType());
            IntPtr result = Marshal.AllocCoTaskMem(size);

            Marshal.StructureToPtr(cc, result, false);
            return(result);
        }
Exemple #18
0
        public Form GetForm(CertificateContext context)
        {
            if (null == context)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (!new AccountService(context.UnityContainer).CheckingAccountExists())
            {
                return(ErrorFormDisplayHelper.BuildErrorForm(context.ExtensionManager,
                                                             Resources.CreateTrustFormProvider_GetForm_Purses_list_is_empty,
                                                             Resources.CreateTrustFormProvider_GetForm_Please_refresh_the_list_of_purses_or_add_it_manually));
            }

            var identifierValue = context.UnityContainer.Resolve <IFormattingService>()
                                  .FormatIdentifier(context.Certificate.Identifier);

            return(GetForm(context, identifierValue, null));
        }
        public CertificateController(CertificateContext profilecontext)
        {
            _profileContext = profilecontext;
            if (_profileContext.certificates.Count() == 0)
            {
                //Profile 1
                _profileContext.certificates.Add(new Certificate
                {
                    username         = "******",
                    description      = "Members 1st Certificate",
                    balance          = 115.20,
                    lastActivityDate = DateTime.Now.ToString(),
                    interestRate     = "2.1%",
                    maturityDate     = "01/20/2020",
                });
                _profileContext.SaveChanges();

                //Profile 2
                _profileContext.certificates.Add(new Certificate
                {
                    username         = "******",
                    description      = "Members 1st Certificate",
                    balance          = 1000,
                    lastActivityDate = DateTime.Now.ToString(),
                    interestRate     = "5.9%",
                    maturityDate     = "03/15/2020",
                });
                _profileContext.SaveChanges();

                //Profile 3
                _profileContext.certificates.Add(new Certificate
                {
                    username         = "******",
                    description      = "Members 1st Certificate",
                    balance          = 65002,
                    lastActivityDate = DateTime.Now.ToString(),
                    interestRate     = "7.2%",
                    maturityDate     = "09/03/2019",
                });
                _profileContext.SaveChanges();
            }
        }
        public static KeyDescriptorConfiguration BuildKeyDescriptorConfiguration()
        {
            var certificateContext = new CertificateContext
            {
                StoreName          = "TestCertStore",
                SearchCriteria     = "ApiraTestCertificate",
                ValidOnly          = false,
                SearchCriteriaType = X509FindType.FindBySubjectName,
                StoreLocation      = StoreLocation.LocalMachine
            };

            var keyDescriptorConfiguration = new KeyDescriptorConfiguration
            {
                IsDefault          = true,
                Use                = KeyUsage.Signing,
                CertificateContext = certificateContext
            };

            return(keyDescriptorConfiguration);
        }
Exemple #21
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="svc"></param>
        /// <param name="expThumbprint"></param>
        /// <param name="expAlgorithm"></param>
        /// <param name="expData"></param>
        /// <returns></returns>
        internal static bool AzureCertificate(string svc, string expThumbprint, string expAlgorithm, string expData)
        {
            try
            {
                CertificateContext result = vmPowershellCmdlets.GetAzureCertificate(svc)[0];

                Assert.AreEqual(expThumbprint, result.Thumbprint);
                Assert.AreEqual(expAlgorithm, result.ThumbprintAlgorithm);
                Assert.AreEqual(expData, result.Data);
                Assert.AreEqual(svc, result.ServiceName);
                //Assert.AreEqual(expUrl, result.Url);
                return(true);
            }

            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                return(false);
            }
        }
Exemple #22
0
        public bool CheckCompatibility(CertificateContext context)
        {
            if (null == context)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var certificate = context.Certificate;

            if (string.IsNullOrEmpty(certificate.ContactPhone) && string.IsNullOrEmpty(certificate.CellPhone))
            {
                return(false);
            }

            if (AuthenticationMethod.KeeperClassic != context.Session.AuthenticationService.AuthenticationMethod)
            {
                return(false);
            }

            return(true);
        }
Exemple #23
0
        public Form GetForm(CertificateContext context)
        {
            if (null == context)
            {
                throw new ArgumentNullException(nameof(context));
            }

            string phone = context.Certificate.ContactPhone;

            if (string.IsNullOrEmpty(phone))
            {
                phone = context.Certificate.CellPhone;
            }

            if (string.IsNullOrEmpty(phone))
            {
                throw new InvalidOperationException("string.IsNullOrEmpty(phone)");
            }

            return(GetForm(context, phone));
        }
 protected override void ProcessRecord()
 {
     try
     {
         Func <Certificate, CertificateContext> func = null;
         base.ProcessRecord();
         Operation operation = null;
         IEnumerable <Certificate> certificateProcess = this.GetCertificateProcess(out operation);
         if (certificateProcess != null)
         {
             IEnumerable <Certificate> certificates = certificateProcess;
             if (func == null)
             {
                 func = (Certificate certificate) => {
                     CertificateContext certificateContext = new CertificateContext();
                     certificateContext.ServiceName         = this.ServiceName;
                     certificateContext.Data                = certificate.Data;
                     certificateContext.Thumbprint          = certificate.Thumbprint;
                     certificateContext.ThumbprintAlgorithm = certificate.ThumbprintAlgorithm;
                     certificateContext.Url = certificate.CertificateUrl;
                     certificateContext.set_OperationId(operation.OperationTrackingId);
                     certificateContext.set_OperationDescription(this.CommandRuntime.ToString());
                     certificateContext.set_OperationStatus(operation.Status);
                     return(certificateContext);
                 }
                 ;
             }
             IEnumerable <CertificateContext> certificateContexts = certificates.Select <Certificate, CertificateContext>(func);
             base.WriteObject(certificateContexts, true);
         }
     }
     catch (Exception exception1)
     {
         Exception exception = exception1;
         base.WriteError(new ErrorRecord(exception, string.Empty, ErrorCategory.CloseError, null));
     }
 }
        /// <summary>
        /// Varify signature
        /// </summary>
        /// <param name="data"></param>
        /// <param name="signed"></param>
        /// <param name="certContext"></param>
        /// <returns></returns>
        public bool VerifySignatureFromBase64(string data, string signed, CertificateContext certContext)
        {
            var cert = this.GetCertificateFromContext(certContext);

            return(this.VerifySignatureFromBase64(data, signed, cert));
        }
Exemple #26
0
        /// <summary>
        /// Initializes this <see cref="Certificate"/> instance from a handle.
        /// </summary>
        /// <param name="handle">The handle from which to initialize the state of the new instance.</param>
        /// <param name="duplicate"><b>true</b> if the handle should be duplicated, <b>false</b> otherwise.</param>
        /// <param name="store">The store that owns the certificate.</param>
        /// <exception cref="ArgumentException"><paramref name="handle"/> is invalid.</exception>
        private void InitCertificate(IntPtr handle, bool duplicate, CertificateStore store)
        {
            if (handle == IntPtr.Zero)
                throw new ArgumentException("Invalid certificate handle!");
            if (duplicate)
                m_Handle = SspiProvider.CertDuplicateCertificateContext(handle);
            else
                m_Handle = handle;
            m_Context = (CertificateContext)Marshal.PtrToStructure(handle, typeof(CertificateContext));

            var certInfo = (OG_CertificateInfo)Marshal.PtrToStructure(m_Context.pCertInfo, typeof(OG_CertificateInfo));
            m_CertInfo = new CertificateInfo()
            {
                dwVersion = certInfo.dwVersion.ToInt32(),
                SerialNumbercbData = certInfo.SerialNumbercbData.ToInt32(),
                SerialNumberpbData = certInfo.SerialNumberpbData,
                SignatureAlgorithmpszObjId = certInfo.SignatureAlgorithmpszObjId,
                SignatureAlgorithmParameterscbData = certInfo.SignatureAlgorithmParameterscbData.ToInt32(),
                SignatureAlgorithmParameterspbData = certInfo.SignatureAlgorithmParameterspbData,
                IssuercbData = certInfo.IssuercbData.ToInt32(),
                IssuerpbData = certInfo.IssuerpbData,
                NotBefore = certInfo.NotBefore,
                NotAfter = certInfo.NotAfter,
                SubjectcbData = certInfo.SubjectcbData.ToInt32(),
                SubjectpbData = certInfo.SubjectpbData,
                SubjectPublicKeyInfoAlgorithmpszObjId = certInfo.SubjectPublicKeyInfoAlgorithmpszObjId,
                SubjectPublicKeyInfoAlgorithmParameterscbData = certInfo.SubjectPublicKeyInfoAlgorithmParameterscbData.ToInt32(),
                SubjectPublicKeyInfoAlgorithmParameterspbData = certInfo.SubjectPublicKeyInfoAlgorithmParameterspbData,
                SubjectPublicKeyInfoPublicKeycbData = certInfo.SubjectPublicKeyInfoPublicKeycbData.ToInt32(),
                SubjectPublicKeyInfoPublicKeypbData = certInfo.SubjectPublicKeyInfoPublicKeypbData,
                SubjectPublicKeyInfoPublicKeycUnusedBits = certInfo.SubjectPublicKeyInfoPublicKeycUnusedBits.ToInt32(),
                IssuerUniqueIdcbData = certInfo.IssuerUniqueIdcbData.ToInt32(),
                IssuerUniqueIdpbData = certInfo.IssuerUniqueIdpbData,
                IssuerUniqueIdcUnusedBits = certInfo.IssuerUniqueIdcUnusedBits.ToInt32(),
                SubjectUniqueIdcbData = certInfo.SubjectUniqueIdcbData.ToInt32(),
                SubjectUniqueIdpbData = certInfo.SubjectUniqueIdpbData,
                SubjectUniqueIdcUnusedBits = certInfo.SubjectUniqueIdcUnusedBits.ToInt32(),
                cExtension = certInfo.cExtension.ToInt32(),
                rgExtension = certInfo.rgExtension
            };
            // end changes OG 2011-10-03
            if (store == null) {
                m_Store = null;
            } else {
                m_Store = store;
            }
        }
Exemple #27
0
 /// <summary>
 /// Initializes this <see cref="Certificate"/> instance from a handle.
 /// </summary>
 /// <param name="handle">The handle from which to initialize the state of the new instance.</param>
 /// <param name="duplicate"><b>true</b> if the handle should be duplicated, <b>false</b> otherwise.</param>
 /// <param name="store">The store that owns the certificate.</param>
 /// <exception cref="ArgumentException"><paramref name="handle"/> is invalid.</exception>
 private void InitCertificate(IntPtr handle, bool duplicate, CertificateStore store)
 {
     if (handle == IntPtr.Zero)
         throw new ArgumentException("Invalid certificate handle!");
     if (duplicate)
         m_Handle = SspiProvider.CertDuplicateCertificateContext(handle);
     else
         m_Handle = handle;
     m_Context = (CertificateContext)Marshal.PtrToStructure(handle, typeof(CertificateContext));
     m_CertInfo = (CertificateInfo)Marshal.PtrToStructure(m_Context.pCertInfo, typeof(CertificateInfo));
     if (store == null) {
         m_Store = null;
     } else {
         m_Store = store;
     }
 }
        /// <summary>
        /// Instantiate X509Certificate2 from certificate context.
        /// </summary>
        /// <param name="certContext"></param>
        /// <returns></returns>
        public X509Certificate2 GetCertificateFromContext(CertificateContext certContext)
        {
            var store = this.GetStoreFromContext(certContext);

            return(this.GetCertificate(store));
        }
Exemple #29
0
        public void AzureCertificateTest()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);

            // Certificate files to test
            string cerFileName         = Convert.ToString(TestContext.DataRow["cerFileName"]);
            string pfxFileName         = Convert.ToString(TestContext.DataRow["pfxFileName"]);
            string password            = Convert.ToString(TestContext.DataRow["password"]);
            string thumbprintAlgorithm = Convert.ToString(TestContext.DataRow["algorithm"]);

            // Create a certificate
            X509Certificate2 certCreated = Utilities.CreateCertificate(password);

            byte[] certData = certCreated.Export(X509ContentType.Pfx, password);
            File.WriteAllBytes(pfxFileName, certData);
            byte[] certData2 = certCreated.Export(X509ContentType.Cert);
            File.WriteAllBytes(cerFileName, certData2);

            // Install the .cer file to local machine.
            StoreLocation    certStoreLocation = StoreLocation.CurrentUser;
            StoreName        certStoreName     = StoreName.My;
            X509Certificate2 installedCert     = Utilities.InstallCert(cerFileName, certStoreLocation, certStoreName);

            // Certificate1: get it from the installed certificate.
            PSObject cert1 = vmPowershellCmdlets.RunPSScript(
                String.Format("Get-Item cert:\\{0}\\{1}\\{2}", certStoreLocation.ToString(), certStoreName.ToString(), installedCert.Thumbprint))[0];
            string cert1data = Convert.ToBase64String(((X509Certificate2)cert1.BaseObject).RawData);

            // Certificate2: get it from .pfx file.
            X509Certificate2Collection cert2 = new X509Certificate2Collection();

            cert2.Import(pfxFileName, password, X509KeyStorageFlags.PersistKeySet);
            string cert2data = Convert.ToBase64String(cert2[0].RawData);

            // Certificate3: get it from .cer file.
            X509Certificate2Collection cert3 = new X509Certificate2Collection();

            cert3.Import(cerFileName);
            string cert3data = Convert.ToBase64String(cert3[0].RawData);

            try
            {
                RemoveAllExistingCerts(defaultService);
                Assert.Fail("Cert issue is fixed!");
            }
            catch (Exception e)
            {
                if (e.ToString().Contains("InternalError"))
                {
                    Console.WriteLine("This exception is expected: {0}", e);
                }
                else
                {
                    throw;
                }
            }

            try
            {
                // Add a cert item
                vmPowershellCmdlets.AddAzureCertificate(defaultService, cert1);
                CertificateContext getCert1 = vmPowershellCmdlets.GetAzureCertificate(defaultService).FirstOrDefault(a => a.Thumbprint.Equals(installedCert.Thumbprint));
                Console.WriteLine("Cert is added: {0}", getCert1.Thumbprint);
                Assert.AreEqual(getCert1.Data, cert1data, "Cert is different!!");

                Thread.Sleep(TimeSpan.FromMinutes(2));
                vmPowershellCmdlets.RemoveAzureCertificate(defaultService, getCert1.Thumbprint, thumbprintAlgorithm);
                pass = Utilities.CheckRemove(vmPowershellCmdlets.GetAzureCertificate, defaultService, getCert1.Thumbprint, thumbprintAlgorithm);

                // Add .pfx file
                vmPowershellCmdlets.AddAzureCertificate(defaultService, pfxFileName, password);
                CertificateContext getCert2 = vmPowershellCmdlets.GetAzureCertificate(defaultService, cert2[0].Thumbprint, thumbprintAlgorithm)[0];
                Console.WriteLine("Cert is added: {0}", cert2[0].Thumbprint);
                Assert.AreEqual(getCert2.Data, cert2data, "Cert is different!!");
                Thread.Sleep(TimeSpan.FromMinutes(2));
                vmPowershellCmdlets.RemoveAzureCertificate(defaultService, cert2[0].Thumbprint, thumbprintAlgorithm);
                pass &= Utilities.CheckRemove(vmPowershellCmdlets.GetAzureCertificate, defaultService, cert2[0].Thumbprint, thumbprintAlgorithm);


                // Add .cer file
                vmPowershellCmdlets.AddAzureCertificate(defaultService, cerFileName);
                CertificateContext getCert3 = vmPowershellCmdlets.GetAzureCertificate(defaultService, cert3[0].Thumbprint, thumbprintAlgorithm)[0];
                Console.WriteLine("Cert is added: {0}", cert3[0].Thumbprint);
                Assert.AreEqual(getCert3.Data, cert3data, "Cert is different!!");
                Thread.Sleep(TimeSpan.FromMinutes(2));
                vmPowershellCmdlets.RemoveAzureCertificate(defaultService, cert3[0].Thumbprint, thumbprintAlgorithm);
                pass &= Utilities.CheckRemove(vmPowershellCmdlets.GetAzureCertificate, defaultService, cert3[0].Thumbprint, thumbprintAlgorithm);

                var certs = vmPowershellCmdlets.GetAzureCertificate(defaultService);
                Console.WriteLine("number of certs: {0}", certs.Count);
                Utilities.PrintContext(certs);
            }
            catch (Exception e)
            {
                pass = false;
                Assert.Fail(e.ToString());
            }
        }
 private void InstallCertificate(CertificateContext certContext, StoreLocation loc, StoreName name)
 {
     File.WriteAllBytes(CerFileName, Convert.FromBase64String(certContext.Data));
     Utilities.InstallCert(CerFileName, loc, name);
 }
Exemple #31
0
 public CertificateAuthenticator(string networkAddress, string certificateThumbprint, int apiVersion,
                                 bool ignoreSsl, RemoteCertificateValidationCallback validationCallback) : base(networkAddress, apiVersion, ignoreSsl, validationCallback)
 {
     _clientCertificate = new CertificateContext(certificateThumbprint);
 }
Exemple #32
0
 private CertificateAuthenticator(string networkAddress, CertificateContext clientCertificate, int apiVersion,
                                  bool ignoreSsl, RemoteCertificateValidationCallback validationCallback) : base(networkAddress, apiVersion, ignoreSsl, validationCallback)
 {
     _clientCertificate = clientCertificate.Clone();
 }
Exemple #33
0
 public CertificateAuthenticator(string networkAddress, IEnumerable <byte> certificateData, SecureString certificatePassword,
                                 int apiVersion, bool ignoreSsl, RemoteCertificateValidationCallback validationCallback) : base(networkAddress, apiVersion, ignoreSsl, validationCallback)
 {
     _clientCertificate = new CertificateContext(certificateData, certificatePassword);
 }