@@ -118,15 +118,14 @@ bool AWSAuthEventStreamV4Signer::SignRequest(Aws::Http::HttpRequest& request, co
118
118
AWS_LOGSTREAM_DEBUG (v4StreamingLogTag, " Canonical Request String: " << canonicalRequestString);
119
119
120
120
// now compute sha256 on that request string
121
- auto hashResult = m_hash. Calculate (canonicalRequestString);
122
- if (!hashResult. IsSuccess () )
121
+ auto sha256Digest = HashingUtils::CalculateSHA256 (canonicalRequestString);
122
+ if (sha256Digest. GetLength () == 0 )
123
123
{
124
124
AWS_LOGSTREAM_ERROR (v4StreamingLogTag, " Failed to hash (sha256) request string" );
125
125
AWS_LOGSTREAM_DEBUG (v4StreamingLogTag, " The request string is: \" " << canonicalRequestString << " \" " );
126
126
return false ;
127
127
}
128
128
129
- auto sha256Digest = hashResult.GetResult ();
130
129
Aws::String canonicalRequestHash = HashingUtils::HexEncode (sha256Digest);
131
130
Aws::String simpleDate = now.ToGmtString (Aws::Auth::AWSAuthHelper::SIMPLE_DATE_FORMAT_STR);
132
131
@@ -178,39 +177,38 @@ bool AWSAuthEventStreamV4Signer::SignEventMessage(Event::Message& message, Aws::
178
177
nonSignatureHeaders.push_back (static_cast <char >(EventHeaderValue::EventHeaderType::TIMESTAMP)); // type of the value
179
178
WriteBigEndian (nonSignatureHeaders, static_cast <uint64_t >(now.Millis ())); // the value of the timestamp in big-endian
180
179
181
- auto hashOutcome = m_hash. Calculate (nonSignatureHeaders);
182
- if (!hashOutcome. IsSuccess () )
180
+ auto nonSignatureHeadersHash = HashingUtils::CalculateSHA256 (nonSignatureHeaders);
181
+ if (nonSignatureHeadersHash. GetLength () == 0 )
183
182
{
184
183
AWS_LOGSTREAM_ERROR (v4StreamingLogTag, " Failed to hash (sha256) non-signature headers." );
185
184
return false ;
186
185
}
187
186
188
- const auto nonSignatureHeadersHash = hashOutcome.GetResult ();
189
187
stringToSign << HashingUtils::HexEncode (nonSignatureHeadersHash) << Aws::Auth::AWSAuthHelper::NEWLINE;
190
188
189
+ ByteBuffer payloadHash;
191
190
if (!message.GetEventPayload ().empty ())
192
191
{
193
192
// use a preallocatedStreamBuf to avoid making a copy.
194
193
// The Hashing API requires either Aws::String or IStream as input.
195
194
// TODO: the hashing API should be accept 'unsigned char*' as input.
196
195
Utils::Stream::PreallocatedStreamBuf streamBuf (message.GetEventPayload ().data (), message.GetEventPayload ().size ());
197
196
Aws::IOStream payload (&streamBuf);
198
- hashOutcome = m_hash. Calculate (payload);
197
+ payloadHash = HashingUtils::CalculateSHA256 (payload);
199
198
}
200
199
else
201
200
{
202
201
// only a signature and a date will be in a frame
203
202
AWS_LOGSTREAM_INFO (v4StreamingLogTag, " Signing an event with an empty payload" );
204
203
205
- hashOutcome = m_hash. Calculate (" " ); // SHA256 of an empty buffer
204
+ payloadHash = HashingUtils::CalculateSHA256 (" " ); // SHA256 of an empty buffer
206
205
}
207
206
208
- if (!hashOutcome. IsSuccess () )
207
+ if (payloadHash. GetLength () == 0 )
209
208
{
210
209
AWS_LOGSTREAM_ERROR (v4StreamingLogTag, " Failed to hash (sha256) non-signature headers." );
211
210
return false ;
212
211
}
213
- const auto payloadHash = hashOutcome.GetResult ();
214
212
stringToSign << HashingUtils::HexEncode (payloadHash);
215
213
AWS_LOGSTREAM_DEBUG (v4StreamingLogTag, " Payload hash - " << HashingUtils::HexEncode (payloadHash));
216
214
@@ -259,15 +257,15 @@ Aws::Utils::ByteBuffer AWSAuthEventStreamV4Signer::GenerateSignature(const Aws::
259
257
260
258
Aws::StringStream ss;
261
259
262
- auto hashResult = m_HMAC. Calculate (ByteBuffer ((unsigned char *)stringToSign.c_str (), stringToSign.length ()), key);
263
- if (! hashResult.IsSuccess () )
260
+ auto hashResult = HashingUtils::CalculateSHA256HMAC (ByteBuffer ((unsigned char *)stringToSign.c_str (), stringToSign.length ()), key);
261
+ if (hashResult.GetLength () == 0 )
264
262
{
265
263
AWS_LOGSTREAM_ERROR (v4StreamingLogTag, " Unable to hmac (sha256) final string" );
266
264
AWS_LOGSTREAM_DEBUG (v4StreamingLogTag, " The final string is: \" " << stringToSign << " \" " );
267
265
return {};
268
266
}
269
267
270
- return hashResult. GetResult () ;
268
+ return hashResult;
271
269
}
272
270
273
271
Aws::String AWSAuthEventStreamV4Signer::GenerateStringToSign (const Aws::String& dateValue, const Aws::String& simpleDate,
@@ -287,38 +285,35 @@ Aws::Utils::ByteBuffer AWSAuthEventStreamV4Signer::ComputeHash(const Aws::String
287
285
{
288
286
Aws::String signingKey (Aws::Auth::AWSAuthHelper::SIGNING_KEY);
289
287
signingKey.append (secretKey);
290
- auto hashResult = m_HMAC. Calculate (ByteBuffer ((unsigned char *)simpleDate.c_str (), simpleDate.length ()),
288
+ auto hashResult = HashingUtils::CalculateSHA256HMAC (ByteBuffer ((unsigned char *)simpleDate.c_str (), simpleDate.length ()),
291
289
ByteBuffer ((unsigned char *)signingKey.c_str (), signingKey.length ()));
292
290
293
- if (! hashResult.IsSuccess () )
291
+ if (hashResult.GetLength () == 0 )
294
292
{
295
293
AWS_LOGSTREAM_ERROR (v4StreamingLogTag, " Failed to HMAC (SHA256) date string \" " << simpleDate << " \" " );
296
294
return {};
297
295
}
298
296
299
- auto kDate = hashResult.GetResult ();
300
- hashResult = m_HMAC.Calculate (ByteBuffer ((unsigned char *)region.c_str (), region.length ()), kDate );
301
- if (!hashResult.IsSuccess ())
297
+ hashResult = HashingUtils::CalculateSHA256HMAC (ByteBuffer ((unsigned char *)region.c_str (), region.length ()), hashResult);
298
+ if (hashResult.GetLength () == 0 )
302
299
{
303
300
AWS_LOGSTREAM_ERROR (v4StreamingLogTag, " Failed to HMAC (SHA256) region string \" " << region << " \" " );
304
301
return {};
305
302
}
306
303
307
- auto kRegion = hashResult.GetResult ();
308
- hashResult = m_HMAC.Calculate (ByteBuffer ((unsigned char *)serviceName.c_str (), serviceName.length ()), kRegion );
309
- if (!hashResult.IsSuccess ())
304
+ hashResult = HashingUtils::CalculateSHA256HMAC (ByteBuffer ((unsigned char *)serviceName.c_str (), serviceName.length ()), hashResult);
305
+ if (hashResult.GetLength () == 0 )
310
306
{
311
307
AWS_LOGSTREAM_ERROR (v4StreamingLogTag, " Failed to HMAC (SHA256) service string \" " << m_serviceName << " \" " );
312
308
return {};
313
309
}
314
310
315
- auto kService = hashResult.GetResult ();
316
- hashResult = m_HMAC.Calculate (ByteBuffer ((unsigned char *)Aws::Auth::AWSAuthHelper::AWS4_REQUEST, strlen (Aws::Auth::AWSAuthHelper::AWS4_REQUEST)), kService );
317
- if (!hashResult.IsSuccess ())
311
+ hashResult = HashingUtils::CalculateSHA256HMAC (ByteBuffer ((unsigned char *)Aws::Auth::AWSAuthHelper::AWS4_REQUEST, strlen (Aws::Auth::AWSAuthHelper::AWS4_REQUEST)), hashResult);
312
+ if (hashResult.GetLength () == 0 )
318
313
{
319
314
AWS_LOGSTREAM_ERROR (v4StreamingLogTag, " Unable to HMAC (SHA256) request string" );
320
315
AWS_LOGSTREAM_DEBUG (v4StreamingLogTag, " The request string is: \" " << Aws::Auth::AWSAuthHelper::AWS4_REQUEST << " \" " );
321
316
return {};
322
317
}
323
- return hashResult. GetResult () ;
318
+ return hashResult;
324
319
}
0 commit comments