[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Translate to ASCII after URL encoding



Thanks for the response, Mike.  A co-worker and I discovered the problem
yesterday.  You're right - the ASCII translation worked fine.  I was looking
in the address box in the browser, which had the %n stripped.  When I looked
at the actual URL written to the batch file, it was correct.  

The real problem was that when the batch file executed, it parsed the %n as
a parameter.  In my example below the first instance was %2F.  The batch
file processor assumed the %2 was the second parameter.  Since there isn't a
second parameter, it was replaced with a zero-length string.  All I need to
do is replace every instance of % with %% and the batch file processor will
interpret it as a since %.  

And I agree with you about PBEWithMD5AndDES, but it's a requirement of our
trading partner /shrug.

Thanks again.

Barry




-----Original Message-----
From: ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx
[mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Mike Krebs
Sent: Wednesday, July 31, 2013 4:10 PM
To: HTTPAPI and FTPAPI Projects
Subject: RE: Translate to ASCII after URL encoding

Hi Barry,

I don't think the problem is with XLATE. Did you debug before and after
callp http_xlate(dataLen: DataASCII: TO_ASCII ); to find that it was missing
things? The routine doesn't drop any characters. It just runs through the
string and does its thing. In a test I did using your string, I got back a
same length string with nice ascii hex characters.

If I follow what you want to do and what you are doing, I don't think it
will work.

Don't you need to convert to ASCII first, then encrypt with
PBEWithMD5AndDES? When doing encryption, I think you need the right hex
values to start with.

Anyway, after that, URL encoding becomes easy or hard depending on your take
because the string is in ASCII I don't think you can use
http_url_encoder_addvar. Not sure, maybe there is a way. But the encoding
routine is pretty simple. Find the ascii characters that need to be replaced
and do a loop adding them into the output string. 

The write to the IFS without translation.

I don't think I was much help but maybe jarred a brain cell loose for you to
find the answer.

<aside> I like the description on a website for PBEWithMD5AndDES...
       "This option combines all the benefits of slow, insecure 56-bit
encryption with an insecure hash function (MD5). Don't use it, except to
interface with legacy code."</aside>

 

-----Original Message-----
From: ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx
[mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Barry Shrum
Sent: Tuesday, July 30, 2013 5:01 PM
To: ftpapi@xxxxxxxxxxxxxxxxxxxxxx
Subject: Translate to ASCII after URL encoding

I need to encrypt the query string of a URL using PBEWithMD5AndDES.  I'm
using Java to do that and it's working great.  However, the encrypted string
can include special characters which are not URL-safe.  I use
http_url_encoder_addvar to URL encode it and, again, this works great.  I
need to write the URL in a batch file on the IFS that will be later called
by the Windows client to launch a browser.  

 

The problem I'm having is that after using http_xlate, the string that is
returned strips the '%' and the first of the two hex characters from the
encoded special character strings.  In the query string examples below, the
first line is what is returned from the Java encryption program to my RPG
program.  The second line is what I get after converting it to ASCII and
writing to the IFS file.  The last line is the second line with spaces added
to illustrate what characters are missing.  

 

&aa=HlsJMyUO9aCCTrNuo4YFc4iej8OFUm6%2FfVyPvl297evOWkGkG3xZVai%2FnuiI6pvaFKN%
2F5PZOI%2Bk%3D

&aa=HlsJMyUO9aCCTrNuo4YFc4iej8OFUm6FfVyPvl297evOWkGkG3xZVaiFnuiI6pvaFKNF5PZO
IBkD

&aa=HlsJMyUO9aCCTrNuo4YFc4iej8OFUm6  FfVyPvl297evOWkGkG3xZVai  FnuiI6pvaFKN
F5PZOI  Bk  D

 

How can I make the encrypted portion URL-safe and get it (along with the
rest of the URL) into a batch file that Windows understands?

 

Here is part of the program:

 

   Exsr EncryptURL;    // the encrypted query string is returned in
EncryptedQuery

                                                                           

   // URL encode the result                                                

   EncryptedQryV = %trim(EncryptedQuery);                                  

   Encoder = http_url_encoder_new();                                       

   rc = http_url_encoder_addvar(Encoder: 'aa': %addr(EncryptedQryV) +2:    

        %len(EncryptedQryV));                                              

   EncodedQuery = http_url_encoder_getstr(Encoder);                        

   http_url_encoder_free(Encoder);    

 

   URLFull = URLDomain + %trim(EncodedQuery) + DblQuote;


                                                                           

 EndIf;                                                                    

                                                                           

 If Not Error;                                                             

   // Write the batch file                                                 

   Exsr OpenFile;                                                          

   Exsr WriteFile;                                                         

   callp close(fd);                                                        

 EndIf;                                                                    

 

 

BegSr WriteFile;        // Convert the data to ASCII and write the file

//==================                                                   

                                                                       

DataASCII = 'start ' + URLFull;                                        

dataLen   = %Len(%Trim(DataASCII));                                    

                                                                       

// Translate it to ASCII and write the record                          

callp http_xlate(dataLen: DataASCII: TO_ASCII );                       

                                                                       

callp write(fd: %Addr(DataASCII): DataLen);                            

                                                                       

DataASCII = CRLF + 'exit' + CRLF;                                      

dataLen   = %Len(%Trim(DataASCII));                                    

                                                                       

// Translate it to ASCII and write the record                          

                                                                       

callp http_xlate(dataLen: DataASCII: TO_ASCII );                       

DataLen = %Len(%Trim(DataASCII));                                      

callp write(fd: %Addr(DataASCII): DataLen);                            

 

EndSr;  // WriteFile;

 

 

Thanks,

 

Barry Shrum

-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------


-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------