You are not logged in.
Pages: 1
My guess is that your private key comes from
https://bitcoin.stackexchange.com/quest … generationAnd Bitcoin uses ecc256k1, not ecc256r1, AFAICT.
Thanks for pointing out the right 'ecc' format for this case, and unfortunately mormot can't handle it.
=Coldzer0
I would recommend making sure that the one you are using is ecc256r1 and not ec25519, Because mORMot2 only support the ecc256r1.
I'll investigate if the provided private key is of type 'ecc256r1', and also thank you for the sample!
Ab,
I always try to understand what I am doing. Believe me, I avoid asking in this forum because of the intimidating way you respond to some people here, without knowing precisely what each user may have done before asking, but for this case, it simply didn't work. I also tried to google some responses using mormot stuff, but I also found nothing. I didn't invent the private key. There is one page with some steps to find a final result, starting with a 256-bit private key given by them (the one used in my post, as well as the result public key from the original private key, also posted there). It is a 256-bit private key as it is supposed to be, the SAME SIZE of the one used in your 'test.core.ecc', line 89. I just need to calculate a 256-bit public key for a well-generated 256-bit private key, as is the case in my original question, and I am trying to use the mormot one because looks like it's fast.
I am trying the private/public key functions but the first conversion isn't working with the testing 'private_key' I have:
var PrivateKey : TEccPrivateKey;
PublicKey : TEccPublicKey;
private_key,
public_key : RawUtf8;
begin
private_key := '18e14a7b6a307f426a94f8114701e7c8e774e7f9a47e2c2035db29a206321725';
if mormot.core.text.HexToBin(PAnsiChar(private_key), @PrivateKey, SizeOf(PrivateKey)) then
begin
Ecc256r1PublicFromPrivate(PrivateKey, PublicKey);
public_key := mormot.core.text.BinToHexDisplay(@PublicKey, SizeOf(PublicKey)); // I'm not sure if this conversion is the proper one
// 'public_key' should be '50863ad64a87ae8a2fe83c1af1a8403cb53f53e486d8511dad8a04887e5b2352'
end;
end;
Also, I'm unsure how to convert the 'PublicKey' variable to a readable one while in the testing phase. Any hint?
DynArrayLoadJson / DynArraySaveJson work with no problem on my side.
Please provide us with some code to reproduce the problem.
When I begin to play with mORMot 'DynArrayLoadJson' was not working properly, but today I could make it work. I refactored the type used from:
TMyArray = array of packed record
...
end;
TMyEntity = packed record
MyArray : TMyArray;
end;
To:
TMyData = packed record
...
end;
TMyArray = array of TMyData;
Now, I can read/write the JSON data with "DynArrayLoadJson / DynArraySaveJson" the same way that my "wrong" code did, but I am still getting AV when closing the test application. I am still checking what is causing that. Thanks!
PS: The 'AV' occurs only inside Delphi. I still need to try FastMM4 like you suggested
I wish everyone a happy new year.
Sorry for my ignorance. But I don't know how to load an array of records with function RecordLoadJson. I don't remember being able to call this function other than with TypeInfo.Kind is Record. I can trigger an access violation with the following source code:
Thomas, since I discovered the outstanding mORMot framework almost three years ago, I realized I should start using it deeply in my projects, but it requires some education to begin playing with it. For the project in question, and as I am still learning mORMot, I created a testing environment application where I also learn mORMot fundamentals, and then next I use what is mature in the real projects. I was never happy with the fact that when serializing/unserializing JSON I was not using the right counterpart function, as I had tested the right pair or functions (like 'DynArrayLoadJson / DynArraySaveJson', 'RecordLoadJson / RecordSaveJson') and it never worked as I was expecting, probably due something I was doing wrong. I never felt well when I was mixing those previous functions to read/write JSON. The main JSON I have to deal with I defined like this:
TMyArray = array of packed record
...
end;
TMyEntity = packed record
MyArray : TMyArray;
end;
The "combination" that worked, in this case, was something like this:
When reading:
var TempRec : TMyEntity;
RecordLoadJson(TempRec, my_json TypeInfo(TMyEntity));
When writing:
var tmp : RawJson;
tmp := DynArraySaveJson(MyEntity.MyArray, TypeInfo(TMyArray), false);
I never make that work if I had used the pair "DynArrayLoadJson / DynArraySaveJson". This has been working since March/2022. No "access violation" until some weeks ago, then AV for the writing part, and after the last commit it came back to normal (ALL that without any change in my code), but now I got an AV in a unit that I don't use at all.
You said that you don't know how to load an array of records with 'RecordLoadJson'. The way I did above allow me to do it, although that would sound weird because 'RecordLoadJson' is used to load a 'TMyEntity' (that is a record of an array of record), I guess the whole bunch of JSON records are treated as a big JSON, but I am not sure. I would like to simply use 'DynArrayLoadJson / DynArraySaveJson' for that, but I never knew how to do it.
Thanks, ab and mpv, I'll try to follow your tips and see what I can find. Mpv, some of the symptoms you described in the post mentioned I can see too. Those 'ghost' AVs are not easy to find, but I'll keep chasing them.
I hope everybody has a Happy New Year!
Let's do a simple chronology of what has happened so far, using Delphi 11.2:
1) My test environment has been working well since March/2022, in this case, using only three mORMot objects/functions: 'TSimpleHttpClient', 'RecordLoadJson', and 'DynArraySaveJson';
2) After the commit right before my first message (or the previous one) on this thread, without changing anything in my code, I began to get an "access violation" error according to what was described above;
3) After the latest commit I got today, the "access violation" is gone. I thought something at 'mormot.core.json' could be the cause of the access violation, but I checked all the latest changes on that unit and found nothing relevant that could lead to that error;
4) Now when I close my test application I get another "access violation" error, now at 'mormot.core.base', precisely on this procedure, line 7086:
procedure ObjArrayClear(var aObjArray);
var
a: TObjectDynArray absolute aObjArray;
begin
if a = nil then
exit;
// release all owned TObject instances
RawObjectsClear(pointer(aObjArray), PDALen(PAnsiChar(a) - _DALEN)^ + _DAOFF); <--- The "access violation" is here
// release the dynamic array itself
a := nil;
end;
5) I debugged all my 'finalization' sections (I don't have any 'OnClose/OnDestroy' events in my test application) and all then are clear, no error at all;
6) I personally don't use any function/procedure of 'mormot.core.base'. It is listed in my uses clause just because I use 'RawUtf8' variables and that type is defined there;
7) It looks like some side effect is taking place in my case, but I don't think it is easily reproducible in a 'test case'. As I said, I only use those three 'object/functions' from mORMot in this test application. I really don't know why that function is been called at the end of the application, but it has anything to do with my code.
8) For sure there is a hidden "bug" somewhere in mORMot, and if I have a clue where it is I'll post it here.
Thomas, thanks again for your input.
I am still investigating what has changed, as I told you in the first message, nothing was changed in the code from my side. The error that I got is "access violation", typical of accessing an area of memory not previously reserved, but now the error is been raised with the same data that some days ago was working ok. If I found something new, I'll post it here.
It is like
MyTypeArray = array of packed record
...
end;
I read a huge JSON that I receive from a REST service and load it using 'RecordLoadJson' without trouble. At some point in my test environment, I need to save the final JSON and it is when I use 'tmp := DynArraySaveJson(MyData, TypeInfo(MyTypeArray), false);'. It was working great until some days ago. Now it raises that "access violation error".
Hello Thomas,
Thanks for your help. However, right now I am unable to produce a sample to test the problem. I have a lack of time due to the kind of analysis I have to do with the data read through mORMot JSON routines. It is a huge set of data, and it is really time-consuming. I was talking about the concrete case that my test application was not raising an error when I was using:
tmp := DynArraySaveJson(MyData, TypeInfo(MyTypeArray), false);
I changed nothing in my code but the "access violation" error started after the latest or previous commit. Looking a little further, I realized that the error occurs at the following looping:
mormot.core.json - line 5330
repeat
jsonsave(P, c); <-- The error occurs here
dec(n);
if n = 0 then
break;
c.W.BlockAfterItem(c.Options);
inc(P, s);
until false;
I am trying to get the previous commits and compare them to see what could have changed.
In a project that was working normally until the latest commit, now I got the error "Project X raised exception class $C0000005 with message 'access violation at 0x00301608: read of address 0x1c43ef44"
The error happens when I use 'DynArraySaveJson'. It seems to be here:
mormot.core.json -- line 5501
if isHumanReadable in flags then
c.W.WriteObjectPropNameHumanReadable(pointer(p^.Name), length(p^.Name))
else
c.W.AddProp(pointer(p^.Name), length(p^.Name)); <-- The error is here
My intention was just to help in the process as a whole
Thanks
Fixed!
Thanks!
I am receiving the following errors when compiling the latest update on Delphi 11.2:
[dcc32 Error] mormot.lib.winhttp.pas(2103): E2003 Undeclared identifier: 'SysErrorMessagePerModule'
[dcc32 Error] mormot.lib.winhttp.pas(2264): E2003 Undeclared identifier: 'SysErrorMessagePerModule'
[dcc32 Error] mormot.lib.winhttp.pas(2435): E2003 Undeclared identifier: 'SysErrorMessagePerModule'
[dcc32 Error] mormot.lib.winhttp.pas(2611): E2003 Undeclared identifier: 'SysErrorMessagePerModule'
One more great contribution!
Thanks, Thomas!
Perhaps a new public gist may be more convenient.
..
The file is not mine, so I don't feel comfortable doing this
Email sent
Does anybody still have copies of these gists available? I need a mormot server with oauth authentication and was hoping this would be something to build on. But the gists seem to be all gone already.
email sent
I have published my fourth article with the topic mORMot ...
Awesome!
Hi Thomas!
Thank you for your series of articles and samples! Have sure that they are helping clarify a little more the "how-to" in the mORMot world, that powerful but sometimes hermetic (until you figure it out...) series of frameworks.
Have a great day!
While Ab fixes that properly, you can do this to fix that compile error:
---
FormatString('%.%', [efn, ALGO_EXT[a]], String(fn));
---
Thank you, Ab, for the dedication and excellence of your framework! This article will help many who are just starting to understand this part of the powerful mORMot!
...
Edit:
I guess your code is wrong because you use String which is UnicodeString = UTF-16 on Delphi.
Replace tmp: RawUtf8; by tmp: RawUtf8; and I guess it would work.
That's it!! A 'RawUtf8' did the thing!!
I knew that the record as it is defined here is well dealt with by 'mORMot' because it worked before for other situations like that, but I didn't realize about 'RawUtf8'!
Thank you, Ab!
Hello there,
Using the help provided here I could convert the JSON from a REST service from the format above shown on 'JSON_Test.TXT' to an array that is better handled by my application ('JSON_Test_03.txt'). However, although now it is an array I can't load it to an array using 'DynArrayLoadJson' as shown here: https://github.com/PrometeusRec/JSON_Te … N_Test.dpr
'new_array' is empty after calling 'DynArrayLoadJson'. I guess it was supposed to load that record correctly, but for some reason, it doesn't.
In the same application, I successfully loaded other JSON arrays similar to the one above, but sometimes 'DynArrayLoadJson' won't work as expected. Is there something wrong with the JSON file above for it not working?
In your case you will find the object names as follows:
var doc: TDocVariantData; begin if not doc.InitJsonFromFile('_testData.json', JSON_OPTIONS_FAST_EXTENDED) then Exit; //=> WriteLn(RawUtf8ArrayToCsv(doc.Names));
Thanks, Thomas, ALL worked like a charm!
1) That is a valid JSON, it just doesn't write objects as array but as separate objects, Record01, Record02...
You'll have to convert it to array manually, you can use TDocVariantData.InitJSON to read and fill whole content and then you'll have to go through it manually and convert it to your internal array of records.
Thanks for the tip, I'll check it out.
2) Yes, if you load that json in TDocVariantData you'll have json object with two properties, ABC and DEF (both are objects as well). So you could read it as
with (there are other options), GetValueOrNull('ABC').
When you know the values it is ok, but what if you don't know previously that the values will be 'ABC', 'DEF'? Is there a parse function that will give you those values, so you can try the solution you told below for late binding?
I am still learning the HUGE JSON framework of mORMot, but there are situations where I still don't know how to figure them out, like the one below:
1) I need to read JSON values that are like the one in the file 'JSON_Test.TXT' (link below). The values there are not properly an array (looking at the JSON file there is no '[',']' pair), but look like one, and neither is a sole record. Is there a mORMot function that can read it and fill an 'array of packed record' able to be read by a call like 'DynArrayLoadJson' for that situation?
2) Another question: Is there a way to read the values that precede the initial record ('Record01') of the set of records for each entity? For the specific file the values 'ABC' and 'DEF'?
https://github.com/PrometeusRec/JSON_Test
Thanks for any help!
--> What is the proper method to send a text back to the server using the bidirectional open connection? Thanks!
Nevermind, I made it using 'SendFrames'
IIRC a HTTP/1.1 upgrade should have no content-length by definition.
So that test had really passed!
What is the input headers content?
Perhaps the client has some unexpected headers.
Input headers were empty
Based on the test done by 'aProtocol.SetSubprotocol(prot)', I realized that the problem was when creating an instance of 'TWebSocketProtocolChat', where I was giving a name when calling 'Create'. It was not clear to me, based on the comments in the source code, what 'aName' meant exactly, and I thought it was a name the programmer was giving to that specific use. When I left it empty it passed the test done at line 451 (above) and worked as expected.
--> What is the proper method to send a text back to the server using the bidirectional open connection? Thanks!
I verified that for the following line (451 - mormot.net.ws.client):
if not IdemPChar(pointer(cmd), 'HTTP/1.1 101') or
not (hfConnectionUpgrade in Http.HeaderFlags) or
(Http.ContentLength > 0) or
not IdemPropNameU(Http.Upgrade, 'websocket') or
not aProtocol.SetSubprotocol(prot) then
exit;
All five tests fail for "(Http.ContentLength > 0)", and only the last case passes for "not aProtocol.SetSubprotocol(prot)"
Still trying to figure out why it doesn't upgrade for the first four cases
I am still doing some tests with mORMot WebSockets but for some reason, I am getting 'Invalid HTTP Upgrade Header' after upgrading to WebSocket. I tried with five different WebSocket servers that I found on Internet, but for only one of them, the result was ok, although they are all supposed to respond the same way, with JSON or plain text.
I did a simple test program here https://github.com/PrometeusRec/mormot_ … t_Test.dpr where you can see the five websites above, and uncomment one website at a time and test it. Currently, only the last one is giving an answer different from 'Invalid HTTP Upgrade Header' after calling 'WebSocketsUpgrade'. I tested all those websites on 'https://www.piesocket.com/websocket-tester#' and all worked as expected. For two of those, you can enter the JSON in the comments if you want to see them respond, as all the others will give an automatic response right after the connection.
What is the proper method to send a text back to the server using the bi-direction open connection? Thanks!
Compiling error at:
[dcc32 Error] mormot.net.sock.pas(1353): E2441 Inline function declared in interface section must not use local symbol 'PSockAddr'
Delphi 11
Indeed, I was mixing those pieces of information. Thanks!
Thanks for the suggestion about the best protocol in my case.
However, I can't test that point because I am stuck on try connecting to the server. I can't test the rest of my code because I can't go on from the connection phase. I tried different WebSockets servers and the result was always the same ('Is a server available on this address:port? THttpClientWebSockets.OpenBind({websocket site}) [Not Found - #3]'):
var ClientWS : THttpClientWebSockets;
WSSConnection : TGetWSSRequests;
lProto : TWebSocketProtocolChat;
begin
WSSConnection := TGetWSSRequests.Create;
ClientWS := THttpClientWebSockets.Create;
ClientWS.OnCallbackRequestProcess := WSSConnection.DealWSSRequests;
ClientWS.Open('wss://socketsbay.com/wss/v2/2/demo','443'); // <--- HERE it raises the error I told in my first message
...
I don't need a REST WebSocket in my case, and that's why I am using 'THttpClientWebSockets'. Unfortunately, while I tried looking through the mORMot 2 source code and samples, I didn't find the right way to work with 'THttpClientWebSockets' so far. I thought it was like 'TSimpleHttpClient' with the particularities of 'WebSockets', eg. the callback functions. All samples that I saw about this matter were using both server and client using mORMmot. I didn't see a sample for using WebSockets to talk to an ordinary WebSocket server.
Hello,
I have seen some mORMot samples showing up how to create both server and client using WebSocket, using different protocols. I created a simple client to communicate with an ordinary WebSocket server, and when I try using a 'THttpClientWebSockets' to access it when I do a 'Client.Open(WSS site, port)' I receive a 'Is a server available on this address:port? THttpClientWebSockets.OpenBind({websocket site}) [Not Found - #3]' error message. The WebSocket site is working ok, and I've tested it using one WebSocket tester website, like 'https://www.piesocket.com/websocket-tester', receiving the expected initial message.
Can an ordinary WebSocket server be accessed through mORMot using 'THttpClientWebSockets'? I tested both '80' and '443' ports that I guess are the ones to access the WebSocket server that I need because the above WebSocket tester even needs a port in the URI for accessing the server. In case that is possible, the best protocol to be used would be 'TWebSocketProtocolJson'? The server uses plain JSON to receive commands and send responses.
Thanks for any help!
When I tried recompiling a code using the latest mORMot 2 source code I got the following error:
[dcc32 Error] mormot.core.buffers.pas(2228): E2169 Field definition not allowed after methods or properties
Delphi 11
It is because your code is incorrect.
The JSON is an object holding an array, not an array itself.
Ok, thanks!
Hi Thomas and Arnaud!
I can confirm that. I am using Delphi 10.3.3. 'DynArrayLoadJson' didn't work in this case. The fix shown by Thomas worked as expected, but why was it necessary to create a 'packed record' type of the array of the fields loaded from the JSON, and not the array type itself? I didn't see that need when I read the item '10.1.3.2.4 Text-based definition' of mORMot's documentation.
Thank you!
Hi there,
While learning more about mORMot2 I am doing some tests with JSON. I am loading a JSON and trying to deserialize it with 'DynArrayLoadJson'. You can check it here https://github.com/PrometeusRec/mormot_ … n/Test.pas
The JSON file test is there as well. However, no 'JSON' is being loaded into the array. My questions are:
1) Is the JSON content different from what 'DynArrayLoadJson' expects, or is there some error in the type of the fields?
2) On that sample 'packed record' created there is a commented field that is not present in the JSON that I need to read (the exact type shown in the '.TXT' file). The original 'JSON' file may have more fields than the 'packed record' that you will need, but the contrary is not allowed? I would like to make some processing and save the results in fields of the same 'packed record'. Is that possible?
Thanks!
No, the default authentication has a specific signature computed for each URI.
Check the documentation about it.What you can do is use a JWT instead.
Thank you for the prompt answer. I think you are talking about my second question when I try to access the REST API using authentication, but my current test (using SSL) is not using authentication (I did it without SSL and it worked according to documentation), so the signature computed for a URI should not be used in this case, right? What is the cause of the "Authentication Failed: Invalid signature (0)" message?
No, speed is same, I say it's easier to maintain. I've started too with SQLModel for existing FB that's used outside of my app and I've transitioned to interface based approach, following sqlmodel proved too restrictive especially since I need data from several tables.
The applications use the FB database, and now it will be accessed by a mobile application as well. I am really impressed with SQLite 3 performance, and I thought about converting the FB database to it, but I am concerned about SQLite issues with simultaneous writing. I don't know SQLite well, but I am aware of its limitation when dealing with concurrency writings, so I will stick with an external database for while.
I already followed Mormot documentation about SSL, and I am trying to test it using Chrome or Firefox. Despite Chrome not liking my "Dev Certification Authority" and showing it as "Not Secure" (For Firefox it is ok), I am doing simple tests using a browser, and after that build the client-side. After the SLL all set, I am trying accessing the REST API with SSL enabled (the source above was updated):
'https://localhost:8043/root/test/1'
and I am receiving:
{
"errorCode":403,
"errorText":"Authentication Failed: Invalid signature (0)"
}
Googling a little, I found that this message is related to a problem in authenticating. However, I am setting 'aHandleUserAuthentication' to 'false', at first. 'AUTHGROUP' and 'AUTHUSER' tables were created by Mormot when I was testing authenticating without SSL (I guess that they are only used if 'aHandleUserAuthentication' is set to 'true', right?), but I want to have the REST API accessing working with SSL without authentication first, then with it.
After fixing this issue (accessing the REST API through a browser or AJAX client) can the right above input using authentication like this?
'https://localhost:8043/root/test/1?user=User&password=synopse'
Thank you AB, I'll take a look at it!
So you have some existing Firebird DB and you want to serve data from it though REST server?
Note that in such case I would skip altogether defining TSQLModel with existing tables and using FB as external DB. Write interface service that would connect to database (with zeos for example), get data as json and return it to client.
Thank you for the suggestion. I already got my application test working as expected and using the 'standard' way with TSQLModel. I have included in my tests Mormot secure authentication and it worked too, and now I am trying to have it working with SSL. Is there a real advantage for using interface services, like more speed in the JSON response, for instance? I still didn't study this part of Mormot documentation, but anyway I am already glad about the results that I am getting. Mormot framework is the most impressive piece of code for Delphi in this area that I have seen, and I wonder why I didn't hear about it before.
The test table already exists. I created a fresh Firebird database with just one table and two fields only to begin to understand and learn the Mormot framework. I was expecting that the "CreateMissingTables" call create the 'ID' field on that table. However, that is not happening and, according to the error posted, "CreateMissingTables" is trying to read that field, when the error occurs.
Hello,
I begin using the Mormot framework and my primary interest in it is as a REST server. I read some docs about how to do for Mormot to access external databases (Firebird in this case), including the Mormot manual related, and I created a small test, but it is raising an error when I call 'CreateMissingTables'. The code and the error message generated are at https://gist.github.com/PrometeusRec/c4 … 68732fbd9f
I am using the latest 'Zeos' version and compiling for Delphi 10.3.3
I am trying to fix this basic thing for two days, but I can't understand what is wrong with it. The 'TEST.FDB' database has just two raws but looks like the 'ID' field is not being really created in the 'CreateMissingTables' call, but it thinks that it was, and then the error message raised. Am I missing something for this test work?
Thanks for any help.
Pages: 1