1

I am getting an invalid signature error when trying to create a QuickBlox session:

Private Sub GenerateSignature() As String
Dim timestamp As Long : timestamp = DateTime.Now / 1000
Dim nonce As Int : nonce = Rnd(1, 1000)

Dim signatureParams As String
signatureParams = "application_id=[appid]&auth_key=[authkey]&nonce=[nonce]&timestamp=[time]".Replace( _
    "[appid]", ApplicationID).Replace("[authkey]", AuthorizationKey).Replace("[nonce]", nonce).Replace("[time]", timestamp)

Dim sig As String : sig = EncryptHMACSHA(signatureParams, AuthorizationSecret)

Log(signatureParams)

Log("Generated Signature for Token: " & sig.ToLowerCase)

Return sig.ToLowerCase
End Sub

Public Sub GetSessionToken()
Dim job As HttpJob
job.Initialize("GetToken", Me)

Dim timestamp As Long : timestamp = DateTime.Now / 1000
Dim nonce As Int : nonce = Rnd(1, 1000)

Dim tokenParams As String
tokenParams = "application_id=[appid]&auth_key=[authkey]&nonce=[nonce]&timestamp=[time]&signature=[sig]".Replace("[appid]", ApplicationID) _
    .Replace("[authkey]", AuthorizationKey).Replace("[nonce]", nonce).Replace("[time]", timestamp).Replace("[sig]", GenerateSignature)

Log(tokenParams)

job.PostString("https://api.quickblox.com/session.xml", tokenParams)
job.GetRequest.SetHeader("QuickBlox-REST-API-Version", "0.1.0")
End Sub

Private Sub EncryptHMACSHA(Target As String, Key As String) As String
Dim m As Mac
Dim k As KeyGenerator
k.Initialize("HMACSHA1")
k.KeyFromBytes(Key.GetBytes("UTF8"))
m.Initialise("HMACSHA1", k.Key)
m.Update(Target.GetBytes("UTF8"))
Dim b() As Byte
b = m.Sign
Dim bc As ByteConverter

Return bc.HexFromBytes(b)
End Sub

I have checked the encryption function and the timestamp vs other online samples and it appears to be working. I have the order of the url parameters correct. I still cannot figure out why I am getting "Unexpected Signature".

1 Answers1

0

As I see you use different timestamp & nonce for signature generation & session creation request

You should use the same

Dim timestamp As Long : timestamp = DateTime.Now / 1000
Dim nonce As Int : nonce = Rnd(1, 1000)
Rubycon
  • 18,156
  • 10
  • 49
  • 70