HMAC:SHA256 giving Error on Device

Hi

I am new to both ruby and rho mobile and currently i am trying to encrypt a key using HMAC-SHA2.

But when i try to use hmac = HMAC::SHA256.new(key) i get the error as given below in the log

RhoRuby| require_compiled: error: can not find digest/sha2.so

APP| App error: library not found for class Digest::SHA256 -- digest/sha2.so


Here is my Complete Code.


Controller.rb


require 'digest'

require 'digest/sha2'

require 'hmac-sha2'


def test_hmac

      key = '12344444'

      signature = 'abcdef'

      Alert.show_popup(key)

      puts "key :  #{key}"

      hmac = HMAC::SHA256.new(key)

      hmac.update(signature)

  

      puts "hmac: :  #{hmac}"

      puts Rho::RhoSupport.url_encode(Base64.encode64("#{hmac.digest}\n"))

end

My Build.yml :

android:

  manifest_template: "AndroidManifest.erb"

#android_title: 0

  version: "2.3.1"

  extensions:

    - screenorientation

    - coreapi

    - hmac

    - digest

    - digest-sha2

  capabilities:

    - hardware_acceleration

capabilities:

  - gps

  - camera

  - network_state

  - Network

  - hardware_acceleration

The above seems to work fine on Rho Simulator but does not work on android device.What can be the problem ??

My current version of Rhodes is 4.1.1 and of Ruby is 1.9.1


Please note that i need to make it work for both android and iOS devices


Any help is appreciated


Thanks

Siddhant

Siddhant Wadhera
Guys any help is

Guys any help is appreciated

thanks

Siddhant

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Kutir Mobility
Hi Siddhant, It seems to be

Hi Siddhant,

It seems to be error in the https://github.com/rhomobile/rhodes/blob/master/lib/extensions/digest-sha2/sha2/sha2.rb file. This issue needs help from Motorola. We will raise this issue with them to get an answer. In mean time, you can encode text directly using Base64 instead of Digest.


Visnupriya R

Kutir Mobility

Vote: 
Vote up!
Vote down!

Points: 1

You voted ‘up’


Siddhant Wadhera
Hi VisnuPriyaThank you for

Hi VisnuPriya

Thank you for the help

Will be looking forward to get an answer for this issue

Thanks

Siddhant

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Siddhant Wadhera
AlsoI get the same Behavior

Also

I get the same Behavior when i try to use HMAC:SHA1 as well

thanks

Siddhant

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Evgeny Vovchenko
Hello,Here is the doc

Hello,

Here is the doc:

Rhomobile | Ruby Native Extensions

OpenSSL – based libraries

openssl, ezcrypto

Add to build.yml:

extensions: ["openssl.so", "openssl", "digest-sha2", "ezcrypto"] 

digest-sha2

Add to build.yml:

extensions: ["openssl.so", "openssl", "digest", "digest-sha2" ] 

openssl.so is native c-library and should be included in extensions list to use openssl-base libraries

Try it please

Regards,

Evgeny.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Hector Meza
Evgeny, do we have a working

Evgeny, do we have a working sample? Thank you

HM

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Alexey Tikhvinsky
This sample works at my side

This sample works at my side:


build.yml

sdkversion: 5.0.0

name: sample

version: 1.0

vendor: rhomobile

build: debug

bbver: 6.0

applog: rholog.txt

iphone:

  configuration: Release

  sdk: iphonesimulator6.0

  provisionprofile:

  codesignidentity:

  entitlements:

  BundleIdentifier: com.rhomobile.sample

  BundleURLScheme: sample

wp:

  productid: '848f77a0-0f3c-0131-3a0b-3c0754090a18'

android:

  version: 2.3.3

  extensions: [hmac, openssl.so, openssl, digest, digest-md5, digest-sha1, digest-sha2]

controller:

require 'rho'

require 'rho/rhocontroller'

require 'rho/rhoerror'

require 'helpers/browser_helper'

require 'digest'

require 'digest/sha2'

require 'hmac-sha2'

require 'base64'

class SampleController < Rho::RhoController

  include BrowserHelper

 

  def index

      key = '12344444'

      signature = 'abcdef'

      Alert.show_popup(key)

      puts "key :  #{key}"

      hmac = HMAC::SHA256.new(key)

      hmac.update(signature)

 

      puts "hmac: :  #{hmac}"

      puts Rho::RhoSupport.url_encode(Base64.encode64("#{hmac.digest}\n"))

    render

  end

end

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Hector Meza
Did you run it on a device or

Did you run it on a device or just the simulator? The error was only occurring on the device (android).

thanks

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Alexey Tikhvinsky
I run it at Nexus 4 device

I run it at Nexus 4 device.

Please look at list of extensions in android section of build.yml. It contains several extensions which absent at initial post

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Siddhant Wadhera
Hi AlexeyThanks for the quick

Hi Alexey

Thanks for the quick response.I will include the openssl extension and give it a try.

Thanks

Siddhant

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Hector Meza
Siddhant, any updates on your

Siddhant, any updates on your testing?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Siddhant Wadhera
Hi HectorI made a separate

Hi Hector

I made a separate project and this worked,  i was missing the openssl.so extension.

I still need to add this in our current project and make sure that it works there as well.

I will try this and update.

Also we need to implement a key store to store some values instead of storing it in Database.Could you please provide a link of any API related to this.

Thanks

Siddhant

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Kutir Mobility
Hi SiddhantCould you please

Hi Siddhant

Could you please create a new question about keystore so that it will help others to easily search and follow-up.

Can you also mark this thread as "answered" as well.

Thank you.

Visnupriya

Kutir Mobility

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Siddhant Wadhera
Hi Visnupriyai have marked

Hi Visnupriya

i have marked this thread as answered.

Also i have created a new thread for key store implementation.Below is the Link of same

https://developer.motorolasolutions.com/message/81699#81699

Thanks

Siddhant

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Siddhant Wadhera
Hi Alexey/hectorI tried the

Hi Alexey/hector

I tried the solution given by you and it works fine when i build on my Windows Machine which has Rhodes 4.1.1 .

But when i try to build on our company Mac machine which has rhodes4.0.0 i get an error saying

The Java Script API is not available for the extensions:

openssl

digest

digest-sha2

Use RMS 4.0.0 to provide Java Script API

Could you please tell whats going wrong here?? As i need to make it work for both android and iOS Platform

Thanks

Siddhant

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Siddhant Wadhera
Hi AlexeyI even tried

Hi Alexey

I even tried building the project with rhodes4.1.1 on Mac Machine but i sill get the same error as shown below.I have also attached the text file having all the logs.If i remove the extension and build the app it works fine then.

The following build commands failed:

    PhaseScriptExecution Copy\ RhoBundle build/GasCAP.build/Release-iphoneos/rhorunner.build/Script-BD4D7DCE10AE2DA4003DCE59.sh

(1 failure)

cd /Users/varalakshmip/.rvm/gems/ruby-1.9.3-p547/gems/rhodes-4.1.1

UIApplicationExitsOnSuspend not configured, using default of false

************************************

ERROR during building by XCode !

XCode return next error code = pid 49869 exit 65

********* WARNING *****************************************************************************************************

The following extensions do not have JavaScript API:

openssl

digest

digest-md5

digest-sha1

digest-sha2

openssl

digest

digest-md5

digest-sha1

digest-sha2

Use RMS 4.0 extensions to provide JavaScript API

***********************************************************************************************************************

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Jon Tara
The Java Script API is not

The Java Script API is not available for the extensions:

openssl

digest

digest-sha2

Use RMS 4.0.0 to provide Java Script API

There's nothing wrong. It's just an informative message telling you that the extension doesn't have a Javascript API. You don't need one. It just means you can't call those APIs from Javascript.

The following build commands failed:

    PhaseScriptExecution Copy\ RhoBundle build/GasCAP.build/Release-iphoneos/rhorunner.build/Script-BD4D7DCE10AE2DA4003DCE59.sh

(1 failure)

cd /Users/varalakshmip/.rvm/gems/ruby-1.9.3-p547/gems/rhodes-4.1.1

UIApplicationExitsOnSuspend not configured, using default of false


This is the only real error you have. Unfortunately, I'm unfamiliar with it, so perhaps somebody else can help with this.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Hector Meza
Siddhant, have you tried to

Siddhant, have you tried to build the project with Rho 5.0?

I think it would be best to use the latest version, this is what the engineers are working with and testing.

HM

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Jon Tara
I second Hector's suggestion

I second Hector's suggestion.

If your code was written for 4.0 or 4.1, there are very few changes in 5.0. It is mainly a name for marketing purposes and the change of major version number seems to have been a last-minute afterthought (see attached photo from AppForum 2014).

There are some changes to build process, for the better. And it does support the new licensing model and does require that you set-up a (free) developer account for the licensing. We have a very large application (actually 7 apps) that were originally developed with 2.x, and painfully moved to 4.0. It took little effort to move to 5.0. It is nothing like the move from 2.x to 4.x.

You will get better support if you move to 5.0 (current I think is 5.0.2).

It's unfortunate that it's necessary to load openssl just for these functions. It's rather a lot of code to suck-in to your project when you don't really need openssl. I do have a project that actually uses openssl for communication, but it's not what I'm currently working on and haven't moved it from 2.x to 5.0.

You might want to seek-out implementations that don't depend on openssl. A pure Ruby implementation would be easy to drop-in as a Ruby extension (or just drop the code into your app, though it would suffer performance-wise (which may or may not be a problem for you.) An implementation with some C code is a bit more trouble, as it will have to be an extension and takes a bit more effort. The really burdensome thing with extensions is trying to import some Ruby Gem that has native code AND has a bunch of dependencies on other Gems...

IMG_0772.JPG

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Siddhant Wadhera
Hi HectorToday i upgraded to

Hi Hector

Today i upgraded to 5.0 and tried to build the app on my MAC machine but it would not build.I have openend a new thread for this

https://developer.motorolasolutions.com/message/81761

Kindly look into this

Thanks

Siddhant

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Log in to post comments