lib/mqttbridge/YalgaarConnect.rb in yalgaar-1.0.1 vs lib/mqttbridge/YalgaarConnect.rb in yalgaar-1.0.2

- old
+ new

@@ -1,10 +1,10 @@ #@fileName <YalgaarConnect.rb> #@brief - <Connect all varialbes and common methods> # #Revision Log: -# v1.0.1 : Aug 4, 2016 INITIAL OF PROGRAMMER - REVISION DETAIL_1 <- THIS IS THE LATEST REVISION +# v1.0.2 : Aug 4, 2016 INITIAL OF PROGRAMMER - REVISION DETAIL_1 <- THIS IS THE LATEST REVISION #Description: #YalgaarInitModule contents methods and variables and enum.. # #@bug Known Issues: # 1. ISSUE NAME - NONE @@ -50,11 +50,11 @@ return end #~ puts args.size case args.size when TWOARGV - isEncrpt=0 + @@isEncrpt=0 @@clientKey=args[0] @@isSecure=args[1] @@uuid=generateUUID(3) #~ puts @@uuid @@ -90,15 +90,15 @@ end end th = Thread.new do |client| @@client.get do |topic,message| - messageParsing(topic,message,isEncrpt) + messageParsing(topic,message,@@isEncrpt) end end when THREEARGV - isEncrpt=0 + @@isEncrpt=0 @@clientKey=args[0] @@isSecure=args[1] @@uuid=args[2] if @@uuid == 0 @@uuid=generateUUID(3) @@ -139,25 +139,46 @@ end th = Thread.new do |client| @@client.get do |topic,message| #~ puts "#{topic}: #{message}" - messageParsing(topic,message,isEncrpt) + messageParsing(topic,message,@@isEncrpt) end end when FOURARGV - isEncrpt=1 + @@isEncrpt=1 @@clientKey=args[0] @@isSecure=args[1] @@uuid=generateUUID(3) @@aesSecretKey=args[2] if args[3]==YALGAR_AES_128 @@aesType='AES-128-ECB' + validAESKey = /^[a-zA-Z0-9]{16}$/ + validAES = validAESKey.match(@@aesSecretKey) + if validAES == nil + errmesg=showErrCode(YALGAAR_INVALID_AES_KEY_LENGTH) + @@lErrorConnectionCallback.call(errmesg) + return + end elsif args[3]==YALGAR_AES_192 @@aesType='AES-192-ECB' + validAESKey = /^[a-zA-Z0-9]{24}$/ + validAES = validAESKey.match(@@aesSecretKey) + if validAES == nil + errmesg=showErrCode(YALGAAR_INVALID_AES_KEY_LENGTH) + @@lErrorConnectionCallback.call(errmesg) + return + end elsif args[3]==YALGAR_AES_256 @@aesType='AES-256-ECB' + validAESKey = /^[a-zA-Z0-9]{32}$/ + validAES = validAESKey.match(@@aesSecretKey) + if validAES == nil + errmesg=showErrCode(YALGAAR_INVALID_AES_KEY_LENGTH) + @@lErrorConnectionCallback.call(errmesg) + return + end else errmesg=showErrCode(YALGAAR_INVALID_AES_TYPE) @@lErrorConnectionCallback.call(errmesg) return end @@ -194,28 +215,49 @@ end end th = Thread.new do |client| @@client.get do |topic,message| - messageParsing(topic,message,isEncrpt) + messageParsing(topic,message,@@isEncrpt) end end when FIVEARGV - isEncrpt=1 + @@isEncrpt=1 @@clientKey=args[0] @@isSecure=args[1] @@uuid=args[2] if @@uuid==0 @@uuid=generateUUID(3) end @@aesSecretKey=args[3] if args[4]==YALGAR_AES_128 @@aesType='AES-128-ECB' + validAESKey = /^[a-zA-Z0-9]{16}$/ + validAES = validAESKey.match(@@aesSecretKey) + if validAES == nil + errmesg=showErrCode(YALGAAR_INVALID_AES_KEY_LENGTH) + @@lErrorConnectionCallback.call(errmesg) + return + end elsif args[4]==YALGAR_AES_192 @@aesType='AES-192-ECB' + validAESKey = /^[a-zA-Z0-9]{24}$/ + validAES = validAESKey.match(@@aesSecretKey) + if validAES == nil + errmesg=showErrCode(YALGAAR_INVALID_AES_KEY_LENGTH) + @@lErrorConnectionCallback.call(errmesg) + return + end elsif args[4]==YALGAR_AES_256 @@aesType='AES-256-ECB' + validAESKey = /^[a-zA-Z0-9]{32}$/ + validAES = validAESKey.match(@@aesSecretKey) + if validAES == nil + errmesg=showErrCode(YALGAAR_INVALID_AES_KEY_LENGTH) + @@lErrorConnectionCallback.call(errmesg) + return + end else errmesg=showErrCode(YALGAAR_INVALID_AES_TYPE) @@lErrorConnectionCallback.call(errmesg) return end @@ -252,10 +294,10 @@ end end th = Thread.new do |client| @@client.get do |topic,message| #puts "#{topic}: #{message}" - messageParsing(topic,message,isEncrpt) + messageParsing(topic,message,@@isEncrpt) end end else puts 'Invalid Arguments' end