I got the message when I try to sign a transaction:
Transaction payment = new Transaction();
BitcoinSecret PaymentSecret = new BitcoinSecret("1sXCvdpXz...UqkXW9mvT");
...
payment.Sign(Container.PaymentSecret, false);
I dig into the opensource NBitcoin API and figured out these lines give me the error message. What can I do? (https://github.com/NicolasDorier/NBitcoin/blob/master/NBitcoin/Crypto/DeterministicECDSA.cs)
try
{
hmac = MacUtilities.GetMac(macName);
}
catch(SecurityUtilityException nsae)
{
throw new InvalidOperationException(nsae.Message, nsae);
}
If someone would like to figure out what is happening exactly, here's a code snippet that'll cause the bug:
string mechanism = "HMACSHA256";
if (mechanism.StartsWith("HMAC"))
{
Console.WriteLine("good");
}
else
{
Console.WriteLine("bad");
}
Console.ReadLine();
If you set mechanism = "HMAC-SHA256", then the bug won't happen.
If you use mechanism.StartsWith("HMAC",StringComparison.InvariantCulture), then bug won't happen.
I've also fixed the bug in github and created a pull request to the NBitcoin API, so hopefully it won't happen with others in the future.
The problem was here:
NBitcoin/NBitcoin.BouncyCastle/security/MacUtilities.cs
public static IMac GetMac(string algorithm)
{
...
if(mechanism.StartsWith("HMAC"))
{
...
}
...
}
The mechanism string is "HMACSHA256" and the if statement never evaluates true for me, because my language is Hungarian and "CS" is a letter in Hungarian. So according to the StartsWith function "HMACSHA256" doesn't start with "HMAC" in Hungarian.
The issue has been fixed in the NBitcoin API by Nicolas Dorier as adding StringComparison.OrdinalIgnoreCase setting to the StartWith function.
In case someone wants to test it, here's an email from Nicolas:
Ok, for history.
Thread.CurrentThread.CurrentCulture = new CultureInfo("hu");
string mechanism = "HMACSHA256";
var v1 = mechanism.StartsWith("HMAC");
mechanism = "HMAC-SHA256";
var v2 = mechanism.StartsWith("HMAC");
In hungarian, v1 is false and v2 true.
There is a hyphen after HMAC. HMAC-SHA256
I just tried the code on my machine, and it works perfectly.
public void CanSignSimple()
{
Key bob = new Key();
Transaction tx = new Transaction();
tx.Inputs.Add(new TxIn()
{
ScriptSig = bob.ScriptPubKey
});
tx.Sign(bob, false);
}
It should be noted that I am not using Bouncy castle library now. I copied the needed part of bouncycastle INSIDE NBitcoin.
Your bug seems like you are using NBitcoin along with the official BouncyCastle, which can happen only if you recompiled everything yourself with using the official BouncyCastle lib, OR you are using an old version of NBitcoin.
What version are you using ?
Related
EDIT.
I have a problem with XmlDsigXPathTransform valiation. Sad to say even when I copied 1:1 the example from docs the xpath validations ends failed. What am I missing? I can't figure anything anymore about this when even the docs example fails.
https://learn.microsoft.com/pl-pl/dotnet/api/system.security.cryptography.xml.xmldsigxpathtransform?view=netframework-4.6.1
var signatureReference = new Reference { Uri = "", };
XmlDsigXPathTransform XPathTransform =
CreateXPathTransform(XPathString);
signatureReference.DigestMethod = "http://www.w3.org/2001/04/xmlenc#sha256";
signatureReference.AddTransform(XPathTransform);
signedXml.AddReference(signatureReference);
private static XmlDsigXPathTransform CreateXPathTransform(string XPathString)
{
XmlDocument doc = new XmlDocument();
XmlElement xPathElem = doc.CreateElement("XPath");
xPathElem.InnerText = XPathString;
XmlDsigXPathTransform xForm = new XmlDsigXPathTransform();
xForm.LoadInnerXml(xPathElem.SelectNodes("."));
return xForm;
}
The XmlDsigXPathTransform is no longer considered safe, so any document using it is automatically considered to have an invalid signature.
https://referencesource.microsoft.com/#System.Security/system/security/cryptography/xml/signedxml.cs,8b616077b30145cd
If you really want to use it, you have to enable it in the Windows Registry on whatever computers are going to call CheckSignature.
https://support.microsoft.com/en-us/topic/after-you-apply-security-update-3141780-net-framework-applications-encounter-exception-errors-or-unexpected-failures-while-processing-files-that-contain-signedxml-922edd45-a91e-c755-bb30-2604acf37362
SignedXml is old and outdated, my recommendation is to not use it at all, unless you have to for compatibility (the .NET team calls it legacy and says it's not being invested in on issues, e.g. https://github.com/dotnet/runtime/issues/44674#issuecomment-875163316).
what is the best way to get daily bytes-out and byte-in report for every user in hotspot list(without the user manager).i found the tik4net but i couldn't use it and i found almost no documentation on this reference.
i have tried the mk.cs and tik4net already but no luck so far.
this was the sample on using torch tool :
using (ITikConnection connection = ConnectionFactory.CreateConnection(TikConnectionType.Api))
{
connection.Open("IP", "USR", "PW");
var loadingContext = connection.LoadAsync<ToolTorch>(
torchItem => Console.WriteLine(torchItem.ToString()),
error => Console.WriteLine(error.ToString()),
connection.CreateParameter("interface", "DSL"),
connection.CreateParameter("port", "any"),
connection.CreateParameter("src-address", "0.0.0.0/0"),
connection.CreateParameter("dst-address", "0.0.0.0/0"));
Console.ReadLine();
loadingContext.Cancel();
{
so the question is:
what is the best reference in c# to get user reports without the user manager in c#?
can anyone please provide some sample code ?
UPDATE :
i just worked around and played with the code a little bit and got here :
using (ITikConnection connection = ConnectionFactory.CreateConnection(TikConnectionType.Api))
{
connection.Open("IP", "USR", "PW");
var hs = connection.LoadAll<HotspotActive>();
foreach (var user in hs)
{
var ids = user.Id;
listBox1.Items.Add(ids);
connection.Delete<HotspotActive>(user);
}
}
but i get an exception error on connection.Delete<HotspotActive>(user); , i dont know if i went the correct way.
So I'm building an app with twilio voice, and I've got all the phonecall stuff working. But I'm having a little trouble understanding which parameters my callback should have.
I've registered the URL as described in the docs:
options.From = formatPhoneNumber(callout.callback_number);
options.To = formatPhoneNumber(offer.employee_phone_number);
options.Url = TwilioCallBotController.TwilioCalloutScriptURL;
options.StatusCallback = TwilioCallBotController.StatusCallbackURL;
options.StatusCallbackEvents = new []{"initiated", "ringing", "answered", "completed" };
options.StatusCallbackMethod = "POST";
I've also made a callback method here, but I'm not having much luck finding out how the parameters are supposed to work with their API. I'm kindof at a loss as to what could be the reason behind this one not working:
[HttpPost]
public ActionResult TwilioStatusCallback()
{
var twiml = new Twilio.TwiML.TwilioResponse();
twiml.Say("This is a test");
string CallSid = Request.Form["CallSid"];
string CallStatus = Request.Form["CallStatus"];
Debug.WriteLine("Status Callback Delivered");
Shift_Offer shoffer = db.Shift_Offers.Where(s => s.twillio_sid == CallSid).ToList()[0];
shoffer.status = CallStatus.ToString();// + DateTime.Now.ToString();
return TwiML(twiml);
}
Edit:
So it turns out that the API is very sensitive about the method signature (the call was previously throwing a method not found exception in a number of microsoft DLLs, including System.Web and System.Web.Mvc.
So I've actually gotten the software to call the method by using an empty method signature (no parameters).
However I'm still having trouble getting the parameters from the HTTPPOST
Edit: So upon further investigation I've managed to inspect the Request. The values I'm after exist in Request.Form["foo"], but they don't seem to be getting put into the two strings I have declared. I've removed the ["HttpPost"] attribute to try to troubleshoot the issue, but I'm really at a loss as to why I can see the values in the debugger, but they're not translating into memory.
public ActionResult TwilioStatusCallback()
{
var twiml = new Twilio.TwiML.TwilioResponse();
string sid = Request.Form["CallSid"];
string status = Request.Form["CallStatus"];
Shift_Offer shoffer = db.Shift_Offers.Where(s => s.twillio_sid == sid).ToList()[0];
shoffer.status = status;// + DateTime.Now.ToString();
return TwiML(twiml);
}
Last issue was that the database wasn't being saved.
Just added a db.SaveChanges() and we're good.
I'm trying to use the VersionOne API via the C# APIClient, but my meta model is only getting an Unknown AssetType error wrapping a 405 exception. What am I doing wrong? Here's a code snippet:
VersionOneAPIConnector conn = VersionOneClientFactory.CreateClient(Endpoint.Data);
conn.WithVersionOneUsernameAndPassword("username", "password");
IMetaModel meta = new MetaModel(VersionOneClientFactory.CreateClient(Endpoint.Meta));
Services s = new Services(meta, conn);
If it helps, here's the CreateClient method:
public static VersionOneAPIConnector CreateClient(Endpoint e)
{
StringBuilder url = new StringBuilder("https://www#.v1host.com/MyCompany/");
switch (e)
{
case Endpoint.Data: url.Append("rest-1.v1"); break;
case Endpoint.Localization: url.Append("loc-2.v1"); break;
case Endpoint.Meta: url.Append("meta.v1"); break;
case Endpoint.Query: url.Append("query.v1"); break;
}
return new VersionOneAPIConnector(
url.ToString(),
proxyProvider: new ProxyProvider(
new Uri("http://proxy.server"),
"proxy_username",
"proxy_password"
));
}
Here's what I see in Visual Studio:
In this case I use a breakpoint to show you the issues in the Locals window. If I were to actually try to do anything, the MetaException gets thrown.
I tried your code and ran into the same issue. I was able to make it work by adding a "/" at the end of each endpoint (the meta endpoint in particular). Could you try that?
This seems to fix it:
proxyProvider: new ProxyProvider(
new Uri("https://proxy.server:port"),
"proxy_username",
"proxy_password"
)
I could've sworn whatever example I was using said to not include port. Apparently that was fallacious. Sorry for the trouble guys, but thanks for trying to help!
Also, verified that mkunzi's answer is valid too. You need the slashes at the end of the endpoints (e.g. "meta.v1/") or it won't work.
I am fairly new to the use of APIs and haven't touched Quickbase until today. I was researching the Quickbase API and it seemed as if all the examples I saw were written in XML or some similar variant. Is there a way to write code in C# that will do the same things that I saw could be done on the Quickbase website's API documentation? If you know of any code examples, please let me know.
There is a QuickBase C# SDK that might help get you started.
using System;
using Intuit.QuickBase.Client;
namespace MyProgram.QB.Interaction
{
class MyApplication
{
static void Main(string[] args)
{
var client = QuickBase.Client.QuickBase.Login("your_QB_username", "your_QB_password");
var application = client.Connect("your_app_dbid", "your_app_token");
var table = application.GetTable("your_table_dbid");
table.Query();
foreach(var record in table.Records)
{
Console.WriteLine(record["your_column_heading"]);
}
client.Logout();
}
}
}
There is also a QuickBase API Wrapper example as well.
Back in 2009 I wrote an .NET API for QuickBase which makes working with the platform easy, it also supports uploading and downloading of attached files.
IQuickBaseService svc = new QuickBaseService("user", "pass", "URL", "token");
Schema schema = svc.GetSchema("DBID");
Console.WriteLine("Schema : {0}", schema.Name);
Console.WriteLine("Variables - ");
for (KeyValuePair<string, string> ent in schema.Variables.OrderBy(en => en.Key)) {
Console.WriteLine("Var: {0} = {1}", ent.Key, ent.Value);
}
for (Query q : schema.Queries) {
// Work with queries.
}
// schema.Children
// schema.Fields
// ...
svc.SignOut();
Performing a query is simple.
QueryResult res;
res = svc.Query("tableid", 1); // Execute query number 1
res = svc.Query("tableid", "{{140.EX.'1'}}") // execute QB query text
foreach (QueryRow row in result.Rows) {
// Do something with row, use get<type>, not all shown here.
// row.GetBool(1);
// row.GetInt(1);
// row.GetLong(1);
// row.GetFloat(1);
// row.GetDouble(1);
// row.GetDecimal(1);
// row.GetString(1);
// row.GetDate(1);
// row.GetDateTime(1);
// row.GetObject(1);
}
QuickBase SDK Code is now moved to github https://github.com/QuickbaseAdmirer/QuickBase-C-Sharp-SDK