示例#1
0
        protected X509Certificate2 CreateAndPutClientCertificate(string serverCertPath,
                                                                 RavenServer.CertificateHolder serverCertificateHolder,
                                                                 Dictionary <string, DatabaseAccess> permissions,
                                                                 SecurityClearance clearance,
                                                                 RavenServer server = null)
        {
            var clientCertificate = CertificateUtils.CreateSelfSignedClientCertificate("RavenTestsClient", serverCertificateHolder, out _);
            var serverCertificate = new X509Certificate2(serverCertPath);

            using (var store = GetDocumentStore(new Options
            {
                AdminCertificate = serverCertificate,
                Server = server
            }))
            {
                var requestExecutor = store.GetRequestExecutor();
                using (requestExecutor.ContextPool.AllocateOperationContext(out JsonOperationContext context))
                {
                    var command = new PutClientCertificateOperation("RavenTestsClient", clientCertificate, permissions, clearance)
                                  .GetCommand(store.Conventions, context);

                    requestExecutor.Execute(command, context);
                }
            }
            return(clientCertificate);
        }
示例#2
0
        public X509Certificate2 CreateAndPutExpiredClientCertificate(string serverCertPath, Dictionary <string, DatabaseAccess> permissions, SecurityClearance clearance = SecurityClearance.ValidUser)
        {
            var serverCertificate       = new X509Certificate2(serverCertPath, (string)null, X509KeyStorageFlags.MachineKeySet);
            var serverCertificateHolder = new SecretProtection(new SecurityConfiguration()).LoadCertificateFromPath(serverCertPath, null, Server.ServerStore);

            var clientCertificate = CertificateUtils.CreateSelfSignedExpiredClientCertificate("expired client cert", serverCertificateHolder);

            using (var store = GetDocumentStore(new Options
            {
                AdminCertificate = serverCertificate,
                ClientCertificate = serverCertificate
            }))
            {
                var requestExecutor = store.GetRequestExecutor();
                using (requestExecutor.ContextPool.AllocateOperationContext(out JsonOperationContext context))
                {
                    var command = new PutClientCertificateOperation("expired client cert", clientCertificate, permissions, clearance)
                                  .GetCommand(store.Conventions, context);

                    requestExecutor.Execute(command, context);
                }
            }
            return(clientCertificate);
        }