libevent gives data that I'm not expecting? - c++

So I've been trying to find out why I receive information through my buffer that I know for a fact that aren't being sent by the client. Does anyone else where the problem lies?
I've tried googling and ofcourse stackoverflow but still couldn't find an answer to my question.
char tmpBuffer[SIZE_OF_BUFFER];
struct evbuffer* bufferInput = bufferevent_get_input(bufferEvent);
int size = evbuffer_remove(bufferInput, tmpBuffer, sizeof(tmpBuffer));
dump_hex(tmpBuffer, size);
0x000000: 0d e2 00 00 00 03 01 26 .......&
0x000008: 01 00 02 65 6e 00 08 75 ...en..u
0x000010: 73 65 72 6e 61 6d 65 00 sername.
0x000018: 08 70 61 73 73 77 6f 72 .passwor
0x000020: 64 00 00 00 e7 53 65 72 d....Ser
0x000028: 76 65 72 20 63 6f 6e 6e ver conn
0x000030: 65 63 74 69 6f 6e 20 73 ection s
0x000038: 74 61 74 75 73 3a 0a 20 tatus:.
0x000040: 20 43 6f 6e 6e 65 63 74 Connect
0x000048: 65 64 3a 20 20 20 20 20 ed:
0x000050: 20 20 59 65 73 0a 20 20 Yes.
0x000058: 43 6f 6e 6e 65 63 74 65 Connecte
0x000060: 64 20 74 6f 3a 20 20 20 d to:
0x000068: 20 31 32 37 2e 30 2e 30 127.0.0
0x000070: 2e 31 3a 35 35 35 35 0a .1:6666.
0x000078: 20 20 52 61 77 20 70 61 Raw pa
0x000080: 72 73 65 72 3a 20 20 20 rser:
0x000088: 20 20 20 5b 6f 62 6a 65 [obje
0x000090: 63 74 20 4d 65 73 73 61 ct Messa
0x000098: 67 65 52 65 63 65 69 76 geReceiv
0x0000a0: 65 72 5d 0a 20 20 4d 65 er]. Me
0x0000a8: 73 73 61 67 65 20 68 61 ssage ha
0x0000b0: 6e 64 6c 65 72 3a 20 5b ndler: [
0x0000b8: 6f 62 6a 65 63 74 20 4d object M
0x0000c0: 65 73 73 61 67 65 57 61 essageWa
0x0000c8: 74 63 68 65 72 5d 0a 20 tcher].
0x0000d0: 20 4f 75 74 70 75 74 20 Output
0x0000d8: 62 75 66 66 65 72 3a 20 buffer:
0x0000e0: 20 20 30 20 6d 65 73 73 0 mess
0x0000e8: 61 67 65 28 73 29 0a 20 age(s).
0x0000f0: 20 49 6e 70 75 74 20 62 Input b
0x0000f8: 75 66 66 65 72 3a 20 20 uffer:
0x000100: 20 20 30 20 62 79 74 65 0 byte
0x000108: 28 73 29 0a 00 20 30 38 (s).. 08
0x000110: 37 33 33 30 38 36 64 39 733086d9
0x000118: 32 63 38 33 64 62 37 31 2c83db71
0x000120: 39 33 36 39 32 61 62 30 93692ab0
0x000128: 31 36 64 36 31 64 16d61d
Is the data that I receive, but the only data that I know that is being sent by the client is in the first part. You can see the username and password there.

Related

How can you download the feed processing report from a S3 presigned URL (Amazon Feed API)

I am using the below code
Step 6 from the link
https://github.com/amzn/selling-partner-api-docs/blob/main/guides/use-case-guides/feeds-api-use-case-guide-2020-09-04.md#step-5-get-information-for-retrieving-the-feed-processing-report
string path = Path.GetTempPath();
IRestRequest restRequest = new RestRequest(Method.GET);
RestClient restClient = new RestClient(presignedurl);
byte[] response = restClient.DownloadData(restRequest);
File.WriteAllBytes(#path + "\\words123.txt" , response);
The txt file returns Signature mismatch Error
SignatureDoesNotMatchThe request signature we calculated does not match the signature you provided. Check your key and signing method.AWS4-HMAC-SHA256
20210127T204937Z
20210127/eu-west-1/s3/aws4_request
41 57 53 34 2d 48 4d 41 43 2d 53 48 41 32 35 36 0a 32 30 32 31 30 31 32 37 54 32 30 34 39 33 37 5a 0a 32 30 32 31 30 31 32 37 2f 65 75 2d 77 65 73 74 2d 31 2f 73 33 2f 61 77 73 34 5f 72 65 71 75 65 73 74 0a 64 66 34 62 62 66 61 65 66 64 66 34 30 39 30 36 38 64 32 31 37 64 33 35 62 39 30 64 39 39 38 65 62 64 61 37 39 31 61 64 65 33 66 38 36 66 32 38 61 30 64 34 65 62 34 35 37 65 66 37 63 62 37 33GET
//NinetyDays/amzn1.tortuga.3.3bec27f6-e87b-493a-ae7f-fab8a639382f.T2P4950ASWH2IA
X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=%2F20210127%2Feu-west-1%2Fs3%2Faws4_request&X-Amz-Date=20210127T204937Z&X-Amz-Expires=300&X-Amz-SignedHeaders=content-type%3Bhost
content-type:
host:tortuga-prod-eu.s3-eu-west-1.amazonaws.com
content-type;host
UNSIGNED-PAYLOAD47 45 54 0a 2f 2f 4e 69 6e 65 74 79 44 61 79 73 2f 61 6d 7a 6e 31 2e 74 6f 72 74 75 67 61 2e 33 2e 33 62 65 63 32 37 66 36 2d 65 38 37 62 2d 34 39 33 61 2d 61 65 37 66 2d 66 61 62 38 61 36 33 74 2d 31 2e 61 6d 61 7a 6f 6e 61 77 73 2e 63 6f 6d 0a 0a 63 6f 6e 74 65 6e 74 2d 74 79 70 65 3b 68 6f 73 74 0a 55 4e 53 49 47 4e 45 44 2d 50 41 59 4c 4f 41 44DD34A4A3A3CC0692AkCloh5JBLZKUaoKBjA9hFvoLYKjT+SG6E+oMy1pDHRhS7miIYw6/91bBN4eJCuGp9fkpTiEcPg=
Just for security purposes always redact the names of the private resource like in this acute case your s3 bucket name
From the error seems like your presignedUrl is not correct. This specific part.
X-Amz-SignedHeaders=content-type%3Bhost content-type: host:tortuga-prod-eu.s3-eu-west-1.amazonaws.com content-type;host UNSIGNED-PAYLOAD47 45 54 0a
this guide Signing AWS requests with Signature Version 4 can help you signing step of the request by step just to understand the process.
In end, you have a URL like:
https://iam.amazonaws.com?Action=ListUsers&Version=2010-05-08&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIDEXAMPLE%2F20150830%2Fus-east-1%2Fiam%2Faws4_request&X-Amz-Date=20150830T123600Z&X-Amz-Expires=60&X-Amz-SignedHeaders=content-type%3Bhost&X-Amz-Signature=37ac2f4fde00b0ac9bd9eadeb459b1bbee224158d66e7ae5fcadb70b2d181d02
Not sure if checked this Generating a presigned object URL, there is a nice example of java.

AWS S3 Rest API: Unable to upload object

I am trying to upload an object into a bucket in s3. I am using the REST API (no SDK) I have follow the documentation:
https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-header-based-auth.html
and
https://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html
From this documentation:
Example: PUT Object (section)
Mention that my canonical should look like this for a text file with content "Welcome to Amazon S3.":
PUT
/test%24file.text
date:Fri, 24 May 2013 00:00:00 GMT
host:examplebucket.s3.amazonaws.com
x-amz-content-sha256:44ce7dd67c959e0d3524ffac1771dfbba87d2b6b4b4e99e42034a8b803f8b072
x-amz-date:20130524T000000Z
x-amz-storage-class:REDUCED_REDUNDANCY
date;host;x-amz-content-sha256;x-amz-date;x-amz-storage-class
44ce7dd67c959e0d3524ffac1771dfbba87d2b6b4b4e99e42034a8b803f8b072
When I do the request (updating the times and signatures), I get the following error
<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>SignatureDoesNotMatch</Code>
<Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message>
<AWSAccessKeyId>AKIA5BJ3BZ3BKLL6FV5Y</AWSAccessKeyId>
<StringToSign>AWS4-HMAC-SHA256
20190626T012158Z
20190626/us-west-2/s3/aws4_request
b58f679417e49a3f9a2be1fe6d13b642207660a328949d9e2a374eb92d8f97ef</StringToSign>
<SignatureProvided>cfa3661fb2a9367fb9690a4a4d76e0cb21f436d5f79a645ba8d3c146c8250fc8</SignatureProvided>
<StringToSignBytes>41 57 53 34 2d 48 4d 41 43 2d 53 48 41 32 35 36 0a 32 30 31 39 30 36 32 36 54 30 31 32 31 35 38 5a 0a 32 30 31 39 30 36 32 36 2f 75 73 2d 77 65 73 74 2d 32 2f 73 33 2f 61 77 73 34 5f 72 65 71 75 65 73 74 0a 62 35 38 66 36 37 39 34 31 37 65 34 39 61 33 66 39 61 32 62 65 31 66 65 36 64 31 33 62 36 34 32 32 30 37 36 36 30 61 33 32 38 39 34 39 64 39 65 32 61 33 37 34 65 62 39 32 64 38 66 39 37 65 66</StringToSignBytes>
<CanonicalRequest>PUT
/
date:Wed, 26 Jun 2019 01:21:58 GMT
host:mulesofttdx19.s3-us-west-2.amazonaws.com
x-amz-content-sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
x-amz-date:20190626T012158Z
x-amz-storage-class:REDUCED_REDUNDANCY
date;host;x-amz-content-sha256;x-amz-date;x-amz-storage-class
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855</CanonicalRequest>
<CanonicalRequestBytes>50 55 54 0a 2f 0a 0a 64 61 74 65 3a 57 65 64 2c 20 32 36 20 4a 75 6e 20 32 30 31 39 20 30 31 3a 32 31 3a 35 38 20 47 4d 54 0a 68 6f 73 74 3a 6d 75 6c 65 73 6f 66 74 74 64 78 31 39 2e 73 33 2d 75 73 2d 77 65 73 74 2d 32 2e 61 6d 61 7a 6f 6e 61 77 73 2e 63 6f 6d 0a 78 2d 61 6d 7a 2d 63 6f 6e 74 65 6e 74 2d 73 68 61 32 35 36 3a 65 33 62 30 63 34 34 32 39 38 66 63 31 63 31 34 39 61 66 62 66 34 63 38 39 39 36 66 62 39 32 34 32 37 61 65 34 31 65 34 36 34 39 62 39 33 34 63 61 34 39 35 39 39 31 62 37 38 35 32 62 38 35 35 0a 78 2d 61 6d 7a 2d 64 61 74 65 3a 32 30 31 39 30 36 32 36 54 30 31 32 31 35 38 5a 0a 78 2d 61 6d 7a 2d 73 74 6f 72 61 67 65 2d 63 6c 61 73 73 3a 52 45 44 55 43 45 44 5f 52 45 44 55 4e 44 41 4e 43 59 0a 0a 64 61 74 65 3b 68 6f 73 74 3b 78 2d 61 6d 7a 2d 63 6f 6e 74 65 6e 74 2d 73 68 61 32 35 36 3b 78 2d 61 6d 7a 2d 64 61 74 65 3b 78 2d 61 6d 7a 2d 73 74 6f 72 61 67 65 2d 63 6c 61 73 73 0a 65 33 62 30 63 34 34 32 39 38 66 63 31 63 31 34 39 61 66 62 66 34 63 38 39 39 36 66 62 39 32 34 32 37 61 65 34 31 65 34 36 34 39 62 39 33 34 63 61 34 39 35 39 39 31 62 37 38 35 32 62 38 35 35</CanonicalRequestBytes>
<RequestId>51CE31BA9D71033A</RequestId>
<HostId>DzMCaanrDg/dPzsbdTESZtj0XtAAIAWqFXaGXfuipcpfLk1l38itMovqQA93NbBjdn8jIRxRFGc=</HostId>
</Error>
It seems that the canonical request doesnt accept the name, (I tried different options with the same result), because their string it responds () like this
/
instead of
/test%24file.text
I dont understand how will I pass the name of the file, or if there is something else I am missing.
I have set all my headers like this:
request.setMethod('PUT');
request.setEndpoint(canonicalUriFor);
request.setHeader('Host', 'mulesofttdx19.s3-us-west-2.amazonaws.com');
request.setHeader('Date', iso_aws_DateTime);
request.setHeader('Authorization', strAuthorizationHeader);
request.setHeader('x-amz-date',iso8601time);
request.setHeader('x-amz-storage-class','REDUCED_REDUNDANCY');
request.setHeader('X-Amz-Content-Sha256',NewAttachmentSync.hexEncodedHash(payload));

Node, React Native Fetch Blob, S3 Upload invalid signature

So I've been staring at this for a while and I can't obviously see anything wrong, I'm grabbing a signedURL from my Lambda and then uploading to it using rn-fetch-blob.
Lambda Code is as follows:
export default async (event, context, callback, utils) => {
const { imageName } = JSON.parse(event.body)
console.log('​imageName', imageName)
// These access keys relate to a user with AdministratorAccess
utils.AWS.config.update({
accessKeyId: 'XXXXX',
secretAccessKey: 'XXXXXXX',
})
let s3 = new utils.AWS.S3({ signatureVersion: 'v4' })
let params = { Bucket: 'MY_BUCKET', Key: imageName, Expires: 60, ContentType: 'image/jpeg' }
let url = await s3.getSignedUrl('putObject', params)
callback(null, utils.responder.success({ url.data.url }))
}
React native code is as follows:
const uploadImageToS3Endpoint = (s3Url, imageUrl) => {
var source = imageUrl.replace('file://', '')
return RNFetchBlob.fetch('POST', s3Url, {
'Content-Type': 'image/jpeg'
}, RNFetchBlob.wrap(source))
}
I get back(along with a load of other stuff, edited for brevity)
The request signature we calculated does not match the signature you provided. Check your key and signing method.
I did also try allocating public write to the S3 bucket to prove out it wasn't a permissions issue, still got the same result. Any advice would be greatly appreciated as this should be simple!
EDIT
AWS Response RN Fetch
"<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message><AWSAccessKeyId>THE_KEY</AWSAccessKeyId><StringToSign>AWS4-HMAC-SHA256
20181230T120956Z
20181230/eu-west-2/s3/aws4_request
b7b755c6335c0401711fafa241bbd816b5c7ad225c41cc324b0daaac2ee9f587</StringToSign><SignatureProvided>5345073e95a1dd39fa28f0a3c5c7350b2d7da75a5dedf3c2a895fdbd0e354961</SignatureProvided><StringToSignBytes>41 57 53 34 2d 48 4d 41 43 2d 53 48 41 32 35 36 0a 32 30 31 38 31 32 33 30 54 31 32 30 39 35 36 5a 0a 32 30 31 38 31 32 33 30 2f 65 75 2d 77 65 73 74 2d 32 2f 73 33 2f 61 77 73 34 5f 72 65 71 75 65 73 74 0a 62 37 62 37 35 35 63 36 33 33 35 63 30 34 30 31 37 31 31 66 61 66 61 32 34 31 62 62 64 38 31 36 62 35 63 37 61 64 32 32 35 63 34 31 63 63 33 32 34 62 30 64 61 61 61 63 32 65 65 39 66 35 38 37</StringToSignBytes><CanonicalRequest>POST
/C1E2DB45-CB94-4D3C-AEA7-C1CE4B42FCF1.jpg
Content-Type=image%2Fjpeg&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJMVYRTCLXJGL2JGQ%2F20181230%2Feu-west-2%2Fs3%2Faws4_request&X-Amz-Date=20181230T120956Z&X-Amz-Expires=60&X-Amz-SignedHeaders=host
host:tthsshopproductimages.s3.eu-west-2.amazonaws.com
host
UNSIGNED-PAYLOAD</CanonicalRequest><CanonicalRequestBytes>50 4f 53 54 0a 2f 43 31 45 32 44 42 34 35 2d 43 42 39 34 2d 34 44 33 43 2d 41 45 41 37 2d 43 31 43 45 34 42 34 32 46 43 46 31 2e 6a 70 67 0a 43 6f 6e 74 65 6e 74 2d 54 79 70 65 3d 69 6d 61 67 65 25 32 46 6a 70 65 67 26 58 2d 41 6d 7a 2d 41 6c 67 6f 72 69 74 68 6d 3d 41 57 53 34 2d 48 4d 41 43 2d 53 48 41 32 35 36 26 58 2d 41 6d 7a 2d 43 72 65 64 65 6e 74 69 61 6c 3d 41 4b 49 41 4a 4d 56 59 52 54 43 4c 58 4a 47 4c 32 4a 47 51 25 32 46 32 30 31 38 31 32 33 30 25 32 46 65 75 2d 77 65 73 74 2d 32 25 32 46 73 33 25 32 46 61 77 73 34 5f 72 65 71 75 65 73 74 26 58 2d 41 6d 7a 2d 44 61 74 65 3d 32 30 31 38 31 32 33 30 54 31 32 30 39 35 36 5a 26 58 2d 41 6d 7a 2d 45 78 70 69 72 65 73 3d 36 30 26 58 2d 41 6d 7a 2d 53 69 67 6e 65 64 48 65 61 64 65 72 73 3d 68 6f 73 74 0a 68 6f 73 74 3a 74 74 68 73 73 68 6f 70 70 72 6f 64 75 63 74 69 6d 61 67 65 73 2e 73 33 2e 65 75 2d 77 65 73 74 2d 32 2e 61 6d 61 7a 6f 6e 61 77 73 2e 63 6f 6d 0a 0a 68 6f 73 74 0a 55 4e 53 49 47 4e 45 44 2d 50 41 59 4c 4f 41 44</CanonicalRequestBytes><RequestId>4E4DFD848923AC27</RequestId><HostId>DljdK6KPnzAeXxwUyYu32gb4g4JRI8kDTsdqZVqcM3wLYBsZ6kfT8UGZq6FI5/VimHdY6iL8eKg=</HostId></Error>"
RNFetchBlob.fetch(
'PUT',
link,
{
'Content-Type': undefined
},
RNFetchBlob.wrap(Platform.OS === "android" ? this.selectedImage.uri : this.selectedImage.uri.replace("file://", "")),
)
.then((resp) => {
console.log("Response data", resp)
this.onImageUploadSuccess(resp)
}).catch((err) => {
this.onUploadFailure(err)
})
This works for me

APNs Provider API HTTP/2 using c++, openssl

I try to send header frame and data frame with HPACK, and I received goaway frame with COMPRESSION_ERROR (0x9) from APNS.
my step:
send setting frame
recv setting frame
send ACK
recv ACK
send header frame
send data frame
requset:
HEADERS
- END_STREAM
+ END_HEADERS
:method = POST
:scheme = https
:path = /3/device/ad92823c9e42e37241b6cdf6f583c6cdf5dcc21289c57fb6641213abeff8095d
host = api.development.push.apple.com
DATA
+ END_STREAM
{ "aps" : { "alert" : "Hello" } }
Hex:
00 00 77 01 04 00 00 00 01 HEADER FRAME
83 :method = POST
86 :scheme = https
04 :path = (Literal Header Field without Indexing)
4a length(74)
2f 33 2f 64 65 76 69 63 /3/device/ad92823c9e42e37241b6cdf6f583c6cdf5dcc21289c57fb6641213abeff8095d
65 2f 61 64 39 32 38 32
33 63 39 65 34 32 65 33
37 32 34 31 62 36 63 64
66 36 66 35 38 33 63 36
63 64 66 35 64 63 63 32
31 32 38 39 63 35 37 66
62 36 36 34 31 32 31 33
61 62 65 66 66 38 30 39
35 64
66 host =
1e length(30)
61 70 69 2e 64 65 76 65 api.development.psuh.apple.com
6c 6f 70 6d 65 6e 74 2e
70 75 73 68 2e 61 70 70
6c 65 2e 63 6f 6d
00 00 21 00 01 00 00 00 01 DATA FRAME
7b 20 22 61 70 73 22 20 { "aps" : { "alert" : "hello" } }
3a 20 7b 20 22 61 6c 65
72 74 22 20 3a 20 22 68
65 6c 6c 6f 22 20 7d 20
7d
any tips?
thanks

POP3 Authentication

I am trying to write a simple POP3 server and I have a problem with authentication.
I run the server and try to connect to it with help of Icedove. When the client connects to the server, the following occurs:
Server:+OK POP3 server ready.\r\n
Client:CAPA\r\n
Server:-ERR incorrect operation\r\n
Client:USER sti#blabla.ru\r\n
Server:+OK please send PASS command\r\n
Client:PASS sadsd\r\n
Server:+OK sti#blabla.ru is welcome here\r\n
Client:QUIT\r\n
socket closed
I can't understand why client close connection after "+OK sti#blabla.ru is welcome here\r\n" and just says me that the user name or pass incorrect.
I am trying to experiment so new log is slightly different.
Wireshark log:
00000000 2b 4f 4b 20 50 4f 50 33 20 73 65 72 76 65 72 20 +OK POP3 server
00000010 72 65 61 64 79 2e 0d 0a ready...
00000000 41 55 54 48 0d 0a AUTH..
00000018 2d 45 52 52 20 69 6e 63 6f 72 72 65 63 74 20 6f -ERR inc orrect o
00000028 70 65 72 61 74 69 6f 0d 0a peratio. .
00000006 43 41 50 41 0d 0a CAPA..
00000031 2d 45 52 52 20 69 6e 63 6f 72 72 65 63 74 20 6f -ERR inc orrect o
00000041 70 65 72 61 74 69 6f 0d 0a peratio. .
0000000C 55 53 45 52 20 73 74 69 0d 0a USER sti ..
0000004A 2b 4f 4b 20 70 6c 65 61 73 65 20 73 65 6e 64 20 +OK plea se send
0000005A 50 41 53 53 20 63 6f 6d 6d 61 6e 64 0d 0a PASS com mand..
00000016 50 41 53 53 20 73 61 64 73 64 0d 0a PASS sad sd..
00000068 2b 4f 4b 20 73 74 69 27 73 20 6d 61 69 6c 64 72 +OK sti' s maildr
00000078 6f 70 20 68 61 73 20 35 20 6d 65 73 73 61 67 65 op has 5 message
00000088 73 20 28 35 35 20 6f 63 74 65 74 73 29 0d 0a s (55 oc tets)..
00000022 51 55 49 54 0d 0a QUIT..