public object Any(GetPublicKey request)
 {
     var rsaParameters = HostContext.GetPlugin<EncryptedMessagesFeature>().PrivateKey.Value;
     var publicKeyXml = rsaParameters.ToPublicKeyXml();
     Request.Response.ContentType = MimeTypes.Xml;
     Request.Response.AddHeader("X-PublicKey-Hash", publicKeyXml.ToSha256Hash());
     return publicKeyXml;
 }
Example #2
0
        public object Any(GetPublicKey request)
        {
            var rsaParameters = HostContext.GetPlugin <EncryptedMessagesFeature>().PrivateKey.Value;
            var publicKeyXml  = rsaParameters.ToPublicKeyXml();

            Request.Response.ContentType = MimeTypes.Xml;
            Request.Response.AddHeader("X-PublicKey-Hash", publicKeyXml.ToSha256Hash());
            return(publicKeyXml);
        }
Example #3
0
        /// <summary>Get the Extended Public Key from the device for the BIP32 path specified.</summary>
        /// <param name="pinChallenge">Callback that gets </param>
        /// <param name="accountPath">BIP32 path e.g. "44'/0'/0'/0/0 = first Bitcoin account, first public key., from this you can derive the address.</param>
        /// <returns>The public key of the for the account at the path specified.</returns>
        public PublicKey GetPublicKey(Func <PinMatrixRequestType?, string> pinChallenge, string accountPath)
        {
            // Get the path as units
            var path = NBitcoin.KeyPath.Parse(accountPath);

            // Build the message
            var xpub = new GetPublicKey
            {
                AddressN       = new List <uint>(path.Indexes),
                EcdsaCurveName = "secp256k1",
                ShowDisplay    = false
            };

            // Serialize it to bytes
            var msg = Contracts.GetPublicKey.SerializeToBytes(xpub);

            // Send the message to the device
            if (!_communicator.SendMessage(msg, MessageType.MessageType_GetPublicKey))
            {
                throw new ApplicationException("Error writing to device");
            }

            // Get the response from the device
            MessageType recievedType;
            var         received = _communicator.RecieveMessage(out recievedType);

            if (recievedType == MessageType.MessageType_PinMatrixRequest)
            {
                var pinRequest = PinMatrixRequest.Deserialize(received);
                var pin        = pinChallenge(pinRequest.Type);
                if (!_communicator.SendMessage(PinMatrixAck.SerializeToBytes(new PinMatrixAck {
                    Pin = pin
                }), MessageType.MessageType_PinMatrixAck))
                {
                    throw new ApplicationException("Error writing to device");
                }
                received = _communicator.RecieveMessage(out recievedType);
            }

            // PublicKey received
            if (recievedType == MessageType.MessageType_PublicKey)
            {
                return(PublicKey.Deserialize(received));
            }

            // The device returned Failure
            if (recievedType == MessageType.MessageType_Failure)
            {
                throw new KeepKeyException(Failure.Deserialize(received));
            }

            throw new NotImplementedException("Unable to process unexpected message type: " + recievedType);
        }
Example #4
0
        public void RequestPublicKey()
        {
            if (!_device.IsConnected)
            {
                return;
            }

            var path = new GetPublicKey();

            Utils.Write(path, MessageType.MessageTypeGetPublicKey);
            Read();
        }
Example #5
0
        /// <summary>
        /// 保存配置
        /// </summary>
        /// <param name="strTarget">节点名</param>
        /// <param name="strValue">新值</param>
        /// <param name="strSource">路径</param>
        public static void SaveXmlConfig()
        {
            //  string xmlPath = HttpContext.Current.Server.MapPath("APIManage\\Requests\\Xml_Requests\\XMLFile12_Request.xml");
            System.Xml.XmlDocument xdoc = new XmlDocument();
            xdoc.Load(GetPublicKey.GetSysPath("XMLFile12_Request.xml"));


            //  xdoc.Load(xmlPath);
            XmlElement  root     = xdoc.DocumentElement;
            XmlNodeList elemList = root.GetElementsByTagName("WorkKey");
            Random      ran      = new Random();
            int         RandKey  = ran.Next(100000000, 999999999);

            elemList[0].InnerXml = (RandKey + 1000000000000000).ToString();
            xdoc.Save(GetPublicKey.GetSysPath("XMLFile12_Request.xml"));
        }
Example #6
0
    /// <summary>
    /// Gets the public key data from the Trezor wallet.
    /// </summary>
    /// <returns> Task returning the ExtendedPublicKeyDataHolder instance. </returns>
    protected override async Task <ExtendedPublicKeyDataHolder> GetExtendedPublicKeyData()
    {
        var trezorManager = TrezorConnector.GetWindowsConnectedTrezor(GetExtendedPublicKeyDataEnterPin);

        if (trezorManager == null)
        {
            return(null);
        }

        var publicKeyRequest = new GetPublicKey {
            AddressNs = KeyPath.Parse(EXTENDED_PUBLIC_KEY_PATH).Indexes, ShowDisplay = false
        };
        var publicKeyResponse = (PublicKey)null;

        while (publicKeyResponse == null)
        {
            try
            {
                publicKeyResponse = await trezorManager.SendMessageAsync <PublicKey, GetPublicKey>(publicKeyRequest).ConfigureAwait(false);
            }
            catch (FailureException <Failure> )
            {
                MainThreadExecutor.QueueAction(() => PINIncorrect?.Invoke());

                publicKeyResponse = null;
                advance           = false;
            }
        }

        if (publicKeyResponse == null)
        {
            return(null);
        }

        return(new ExtendedPublicKeyDataHolder {
            publicKeyData = publicKeyResponse.Node.PublicKey, chainCodeData = publicKeyResponse.Node.ChainCode
        });
    }
 public object Any(GetPublicKey request)
 {
     var rsaParameters = HostContext.GetPlugin<EncryptedMessagesFeature>().PrivateKey.Value;
     return rsaParameters.ToPublicKeyXml();
 }
Example #8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //ServiceReferenceHSCRM.HsCRMWebSrvClient a = new ServiceReferenceHSCRM.HsCRMWebSrvClient();

            GetPublicKey.GetSysPublicKey();
        }