public async Task RegisterAsync(RegistrationRequest request, RemoteBillingService billingService) { using (var repository = new Repository <User>(_provider)) { var user = await repository.Get(x => x.UserName == request.UserAccount.Email).SingleOrDefaultAsync(); if (user != null && user.Confirmed.HasValue) { throw new SmartcontractException($"Пользователь с e-mail {request.UserAccount.Email} уже зарегистрирован в системе", ApiErrorCode.ValidationError); } else if (user != null && !user.Confirmed.HasValue) { throw new SmartcontractException($"На эту почту уже отправлена ссылка для подтверждения почты", ApiErrorCode.ValidationError); } user = new User { Email = request.UserAccount.Email, UserName = request.UserAccount.Email, Phone = request.UserAccount.Phone }; if (request.InvitedUser) { user.Confirmed = DateTime.Now; } var signedCms = CertificatesHelper.DecodeCmsFromString(request.SignedCms); foreach (var certificate in signedCms.Certificates) { var information = CertificatesHelper.ReadX509CertificateCommonData(certificate); if (information.SerialNumber != request.Profile.PersonIin) { throw new SmartcontractException("ИИН в подписи не соответствует ИИН профиля", ApiErrorCode.ValidationError); } if (!string.IsNullOrEmpty(request.Profile.OrganizationXin)) { if (information.Bin != request.Profile.OrganizationXin && request.Profile.OrganizationXin != request.Profile.PersonIin) { throw new SmartcontractException("БИН в подписи не соответствует БИН организации", ApiErrorCode.ValidationError); } } } await billingService.RegisterUserAsync(user.UserName, user.UserName); await billingService.AddFreePacketAsync(user.UserName); repository.Insert(user); user.Password = _passwordHasher.HashPassword(user, request.UserAccount.Password); repository.Update(user); var profileManager = new ProfileManager(_provider); await profileManager.CreateOrAttachToProfile(request.Profile, request.InvitedUser, user.UserName, repository); repository.Commit(); } }
public async Task <IActionResult> GetSubjectData([FromBody] RegistrationCmsRequest request, [FromServices] ICryptoProviderService cryptoProvider) { var signedCms = CertificatesHelper.DecodeCmsFromString(request.Cms); var OSCPval = await cryptoProvider.VerifyExpiredCert(request.Cms); if (OSCPval) { return(Json(ApiResponse.Failed(ApiErrorCode.ValidationError, "Отозванный сертификат невозможно использовать в системе"))); } if (signedCms.Certificates.Count == 0) { return(Json(ApiResponse.Failed(ApiErrorCode.ResourceNotFound, "У сертификата отсутствуют данные"))); } var certificate = signedCms.Certificates[0]; var data = CertificatesHelper.ReadX509CertificateCommonData(certificate); return(Json(ApiResponse.Success(data))); }
private void txtCertificate_Click(object sender, EventArgs e) { String value = txtWill.Text; if (InputBox("Editing Certificate", ref value) == DialogResult.OK) { try { if (value.Length > 0) { CertificatesHelper.load(value, txtSecurityPassword.Text); } txtCertificate.Text = value; } catch (Exception) { MessageBox.Show("Can not load certificate , please verify that its in pem encoded format. In case password is required please provide it first"); return; } } }
public void CheckInvalidParamsTest() { // I know, this is kind of twisted, but there's really bad people // out there. CertificatesHelper.GetCertificatesFrom((CertificateStore)2); }
public Boolean Init(ConnectionListener<string> listener, IPEndPoint localEndPoint, string certFile, string certPassword, bool fLoadWholeChain) { if (channel == null) { this._listener = listener; bootstrap = new Bootstrap(); loopGroup = new MultithreadEventLoopGroup(workerThreads); bootstrap.Group(loopGroup); bootstrap.Channel<SocketDatagramChannel>(); UDPClient currClient = this; bootstrap.Handler(new ActionChannelInitializer<SocketDatagramChannel>(channel => { IChannelPipeline pipeline = channel.Pipeline; if (isSecured) { Pkcs12Store keystore = null; if (certificate != null && certificate.Length > 0) keystore = CertificatesHelper.loadBC(certificate, certificatePassword); AsyncDtlsClient client = new MyAsyncDtlsClient(certFile, certPassword, fLoadWholeChain); _clientProtocol = new AsyncDtlsClientProtocol(client, new SecureRandom(), channel, currClient, true, ProtocolVersion.DTLSv12); pipeline.AddLast(new DtlsClientHandler(_clientProtocol, this)); } pipeline.AddLast("handler", new RawMessageHandler(listener)); #if false pipeline.AddLast(new CoapEncoder(channel)); pipeline.AddLast(new ExceptionHandler()); #endif })); bootstrap.RemoteAddress(address); #if true try { Task<IChannel> task; if (localEndPoint != null) { task = bootstrap.BindAsync(localEndPoint); } else { task = bootstrap.BindAsync(IPEndPoint.MinPort); } task.GetAwaiter().OnCompleted(() => { try { channel = task.Result; Task connectTask = channel.ConnectAsync(address); connectTask.GetAwaiter().OnCompleted(() => { if (_clientProtocol == null) { if (channel != null) listener.Connected(); else listener.ConnectFailed(); } else { startHandhshakeTimer(); _clientProtocol.InitHandshake(null); } }); } catch (Exception) { listener.ConnectFailed(); return; } }); } catch (Exception) { return false; } } #endif return true; }
public Boolean Init(ConnectionListener <MQMessage> listener) { if (channel == null) { bootstrap = new Bootstrap(); loopGroup = new MultithreadEventLoopGroup(workerThreads); bootstrap.Group(loopGroup); bootstrap.Channel <TcpSocketChannel>(); bootstrap.Option(ChannelOption.TcpNodelay, true); bootstrap.Option(ChannelOption.SoKeepalive, true); X509Certificate2 cert = null; if (certificate != null && certificate.Length > 0) { cert = CertificatesHelper.load(certificate, certificatePassword); } WebSocketClientHandshaker handshaker = WebSocketClientHandshakerFactory.NewHandshaker(this.getUri(), WebSocketVersion.V13, null, false, EmptyHttpHeaders.Default, 1280000); WebSocketClientHandler handler = new WebSocketClientHandler(this, handshaker, listener); bootstrap.Handler(new ActionChannelInitializer <ISocketChannel>(channel => { IChannelPipeline pipeline = channel.Pipeline; if (isSecured) { if (cert != null) { pipeline.AddLast("ssl", new TlsHandler(stream => new SslStream(stream, true, (sender, certificate, chain, errors) => true, (sender, targetHost, localCertificates, remoteCertificate, acceptableIssuers) => cert), new ClientTlsSettings(address.Host, new List <X509Certificate>() { cert }))); } else { pipeline.AddLast("ssl", TlsHandler.Client(address.Host)); } } pipeline.AddLast("http - codec", new HttpClientCodec()); pipeline.AddLast("aggregator", new HttpObjectAggregator(65536)); pipeline.AddLast("handler", handler); pipeline.AddLast(new ExceptionHandler()); })); bootstrap.RemoteAddress(address); try { Task <IChannel> task = bootstrap.ConnectAsync(); task.GetAwaiter().OnCompleted(() => { try { channel = task.Result; } catch (Exception) { listener.ConnectFailed(); return; } if (channel != null) { listener.Connected(); } else { listener.ConnectFailed(); } }); } catch (Exception) { return(false); } } return(true); }
public Boolean Init(ConnectionListener <SNMessage> listener) { if (channel == null) { this._listener = listener; bootstrap = new Bootstrap(); loopGroup = new MultithreadEventLoopGroup(workerThreads); bootstrap.Group(loopGroup); bootstrap.Channel <SocketDatagramChannel>(); UDPClient currClient = this; bootstrap.Handler(new ActionChannelInitializer <SocketDatagramChannel>(channel => { IChannelPipeline pipeline = channel.Pipeline; if (isSecured) { Pkcs12Store keystore = null; if (certificate != null && certificate.Length > 0) { keystore = CertificatesHelper.loadBC(certificate, certificatePassword); } AsyncDtlsClient client = new AsyncDtlsClient(keystore, certificatePassword, null); _clientProtocol = new AsyncDtlsClientProtocol(client, new SecureRandom(), channel, null, currClient, true, ProtocolVersion.DTLSv12); pipeline.AddLast(new DtlsClientHandler(_clientProtocol, this)); } pipeline.AddLast("handler", new SNHandler(listener)); pipeline.AddLast("encoder", new SNEncoder(channel)); pipeline.AddLast(new ExceptionHandler()); })); bootstrap.RemoteAddress(address); try { com.mobius.software.windows.iotbroker.mqtt_sn.net.UDPClient curr = this; Task <IChannel> task = bootstrap.BindAsync(IPEndPoint.MinPort); task.GetAwaiter().OnCompleted(() => { try { channel = task.Result; Task connectTask = channel.ConnectAsync(address); connectTask.GetAwaiter().OnCompleted(() => { if (_clientProtocol == null) { if (channel != null) { listener.Connected(); } else { listener.ConnectFailed(); } } else { startHandhshakeTimer(); _clientProtocol.InitHandshake(null); } }); } catch (Exception) { listener.ConnectFailed(); return; } }); } catch (Exception) { return(false); } } return(true); }
public Boolean Init(ConnectionListener <AMQPHeader> listener) { if (channel == null) { bootstrap = new Bootstrap(); loopGroup = new MultithreadEventLoopGroup(workerThreads); bootstrap.Group(loopGroup); bootstrap.Channel <TcpSocketChannel>(); bootstrap.Option(ChannelOption.TcpNodelay, true); bootstrap.Option(ChannelOption.SoKeepalive, true); X509Certificate2 cert = null; if (certificate != null && certificate.Length > 0) { cert = CertificatesHelper.load(certificate, certificatePassword); } bootstrap.Handler(new ActionChannelInitializer <ISocketChannel>(channel => { IChannelPipeline pipeline = channel.Pipeline; if (isSecured) { if (cert != null) { pipeline.AddLast("ssl", new TlsHandler(stream => new SslStream(stream, true, (sender, certificate, chain, errors) => true, (sender, targetHost, localCertificates, remoteCertificate, acceptableIssuers) => cert), new ClientTlsSettings(address.Host, new List <X509Certificate>() { cert }))); } else { pipeline.AddLast("ssl", TlsHandler.Client(address.Host)); } } pipeline.AddLast(new AMQPDecoder()); pipeline.AddLast("handler", new AMQPHandler(listener)); pipeline.AddLast(new AMQPEncoder()); pipeline.AddLast(new ExceptionHandler()); })); bootstrap.RemoteAddress(address); try { Task <IChannel> task = bootstrap.ConnectAsync(); task.GetAwaiter().OnCompleted(() => { try { channel = task.Result; } catch (Exception) { listener.ConnectFailed(); return; } if (channel != null) { listener.Connected(); } else { listener.ConnectFailed(); } }); } catch (Exception) { return(false); } } return(true); }
private X509Certificate2 GetCertificate(string thumbprint) { return(CertificatesHelper.FindCertificate(StoreLocation.LocalMachine, StoreName.Root, X509FindType.FindByThumbprint, thumbprint)); }