Conversion error for b64encode

I am encrypting username and password values from the [HTTP::payload] of an HTTP_RESPONSE and decrypting those same values on an HTTP_REQUEST. The values encrypt fine and I can log them as such. The decoding, however, fails saying that there is a conversion error. I have confirmed that it is in fact passing it the the encrypted values and using the same key. Is there something I am missing? Did the encrypted values get messed up when I parse them out of the request?

Thanks for the help!

I assume you’re referring to the rule from your previous post (Click here)?

If so, can you try logging the encrypted value you insert in the response and the encrypted value you parse from the request to make sure they match? Also, what version are you running? There is an issue with decoding encrypted strings

The issue was discussed here:

(Click here)

spark:

In fact, this is not resolved in 9.4.1. CR79907 is resolved in 9.4.2, as well as v9.3.1 and v9.3.0 HF3.

Aaron

We are running 9.4.2.

I think I see the problem, if anyone has any ideas how to get around it…

The encrypted values have special characters, while the extracted values have them replaced with HEX values. (i.e “/” becomes “2F”)

Is there any way around this?

Can you post a longer sample of the before and after?

Thanks,

Aaron

Original Encrypted Value: rDTgkrSbSZ7002v4NOCStJtJnvTTc5TfCvAYBaXl6E587VHDQT2ynFakvgg==

Extracted Value: r2BDTgkrSbSZ7002v4NOCStJtJnvTTc5TfCvAYBaXl6E2B5872BVHDQT2ynFakvgg3D3D

I’m still missing the answer. Can you add log statements to log your key, and the user/pass pre- and post-encryption and then post the log output and your rule?

I’m guessing this might have something to do with the form that you get the user/pass from the HTTP payload in, but I’m not too sure. Anyone else have ideas?

Thanks,

Aaron

I believe you are correct. It looks like the form is messing it up. I will talk with our app guys.

Thanks for the help!

The issue appears to be the special characters inroduced by the encryption. Is there any way to encrypt without the introduction of special characters? Thanks

I have eliminated some of the issues with special characters and hex, but it is still giving the decoding error.

If I take a string, encrypt it, then decrypt it, it works fine. But my iRule encrypts the string then puts it back in the payload. In another event, those new values are extracted from the payload and decrpyted and this is where it fails. I have confirmed that the original encrypted/encoded string is identical to the extracted string. I have also confirmed that the key is the same in both situations. There is not much else that could be wrong here.

My thought is that there is a different data type than string needed to decrpyt it. Is that a possibility? Is there someway to typecast the string into a more “decryptable” type?

One other thing to mention is that it looks like it is an issue with the decoding specifically, not necessarily the decryption(Although maybe that is just because it never got past the decoding.)

Hi ormeb,

I think you’re on the right track. When I wrote ‘form’ earlier I meant datatype--not the actual HTML form in the response.

Anyone have ideas on this?

Thanks,

Aaron

The solution is to use the following before the decryption process:

set decoded_data [URI::decode $encrypted_data]

This clears up the manipulation done by the browser, thanks to Support for helping with that solution.

Wiki page updated with accurate notes re: affected versions, and the URI::encode/decode workaround.

Click here

Thanks, guys

/deb

Hey all,

I’m experiencing the same b64decode error " - conversion error invoked from within “b64decode [lindex $::banner_prg_png_class 0]”

I’ve encoded a png image as directed by this post http://devcentral.f5.com/wiki/default.aspx/iRules/LTMMaintenancePage.html

I’ve created the file and removed all of the ‘returns’, created the class, and associated the iRule with the VIP.

This code fails:

when HTTP_REQUEST { 
 log local0.info "Rule initiated" 
 HTTP::respond 200 content [b64decode [lindex $::banner_png_class 0]] "Content-Type" "image/png" 
 log local0.info "Response Successful"    
 }

When I replace the “[lindex $::banner_png_class 0]” with the actual b64 text - it works just fine.

What I’m trying to do in the end is to have a 200 respond with a multilined html response with several images, but I can’t get past this step…

Thanks in advance.

Which LTM version are you running? Can you take a look at these posts for some ideas and reply here if it still doesn’t work?

http://devcentral.f5.com/Default.aspx?tabid=53&view=topic&postid=58407&ptarget=58409

http://devcentral.f5.com/Default.aspx?tabid=53&view=topic&postid=33977&ptarget=34099

Can you post the content of the external file? It should be in the format of

“base64_encoded_string”,

Aaron

Thus far, I’ve been working in our lab which is running 10.0.0.5401.0.

I was using the ‘F5 Logo’ example:

"iVBORw0KGgoAAAANSUhEUgAAAL4AAAC3AgMAAADRFQzGAAAACVBMVEUAAADDAAD///8UoaPIAAA\

DhElEQVRo3u3ZOW7dMBAAUB8lSBXkPmTB3g1PEqSf3jAwgYenTP4icVYuXpDmq/Dyv564SSNy+NT2\

jpenB3iALYAp7wBI12MZpOOoayClgXAAMJAWAPLzbdMtSPIoM4AKpBnQ5+siNDAF6CI0sOerIhRwCl\

AdpUDyjho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p20NpfmAAAAAElFTkSuQmCC",

OK. Just tried on 9.4.7 320.1 and it worked…hmm, why wouldn’t it work in v10?

I’ll post back final results here in a bit…

Wow. Guess I should have tried everything on v9 earlier on in my testing.

Everything works PERFECT on v9, but v10 is a no go. Is this a known issue?

There could be a bug in 10.0.0. 10.0.1 is out, so you could try upgrading and retesting.

Aaron

Referencing a class that way in v10 just returns the name of the class. You’ll need to use the class command introduced in v10. Check out the bottom example in the wiki page for class:

http://devcentral.f5.com/wiki/default.aspx/iRules/class.html Click here

Awesome, thanks!

FYI - I think the syntax is swapped in the example (should be “-value 0” instead of “value -0” in the class section.

Cheers!