Announcement

Collapse
No announcement yet.

Im stucked with SSL connection... Help?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Elias Montoya
    replied
    Ah you are right, need to change:

    Code:
      v1 = "HOST"
      v2 = "loginnet.passport.com"
    ... To whatever server it tells me to connect before.
    It was working before because it was a coincidence. :P

    Leave a comment:


  • Paul Franks
    replied
    No, it appears to be working fine, just get "Authentication Error" in the result, assume you're using bogus credentials here.

    I pieced together your code from your previous posts, this gets a response in a msgbox. I commented out most the the headers, which probably aren't needed, especially the Content-Length, which M$ will calculate for you...

    Code:
    #COMPILE EXE
    #DIM ALL
    
    MACRO CreateObject(id) = NEW DISPATCH IN id
    
    $EmailAddress = "[email protected]"
    $Password     = "examplepassword"
    
    
    '=================================================================
    FUNCTION WriteMsnPort(FF AS LONG, TCPLine AS STRING, OPT AsIs AS LONG) AS STRING
     STATIC CurTran AS LONG
     LOCAL Index    AS LONG
     LOCAL Buffer   AS STRING
     LOCAL Answer   AS STRING
     ERRCLEAR
     IF INSTR(TCPLine, "%TRN") THEN
      INCR CurTran
      REPLACE "%TRN" WITH FORMAT$(CurTran) IN TCPLine
     END IF
     IF ISTRUE(VARPTR(AsIs)) THEN
      IF AsIs THEN
       'MSGBOX ">>" & TCPLine
       TCP SEND #FF, TCPLine & $CRLF
      ELSE
       GOTO ByParts
      END IF
     ELSE
      ByParts:
      TcpLine = TcpLine & $CRLF
      FOR Index = 1 TO PARSECOUNT(Tcpline, $CRLF)
       IF ISTRUE(LEN(PARSE$(TCPLine, $CRLF, Index))) THEN
         'msgbox ">>" & PARSE$(TCPLine, $CRLF, Index) & $CRLF
         TCP PRINT #FF, PARSE$(TCPLine, $CRLF, Index)
       END IF
      NEXT Index
     END IF
    
    
     Keepreading:
      TCP LINE #FF, Buffer
      Answer = (Answer & Buffer) & $CRLF
      IF EOF(FF) THEN GOTO ReceiveDone
      GOTO KeepReading
     ReceiveDone:
    
     'MSGBOX "<<" & Answer
    
     FUNCTION = Answer
    END FUNCTION
    '=================================================================
    
    
    FUNCTION XMLSkeleton AS STRING
    
    FUNCTION = _
    "<Envelope xmlns=""http://schemas.xmlsoap.org/soap/envelope/""" & $CRLF & _
    "   xmlns:wsse=""http://schemas.xmlsoap.org/ws/2003/06/secext""" & $CRLF & _
    "   xmlns:saml=""urn:oasis:names:tc:SAML:1.0:assertion""" & $CRLF & _
    "   xmlns:wsp=""http://schemas.xmlsoap.org/ws/2002/12/policy""" & $CRLF & _
    "   xmlns:wsu=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd""" & $CRLF & _
    "   xmlns:wsa=""http://schemas.xmlsoap.org/ws/2004/03/addressing""" & $CRLF & _
    "   xmlns:wssc=""http://schemas.xmlsoap.org/ws/2004/04/sc""" & $CRLF & _
    "   xmlns:wst=""http://schemas.xmlsoap.org/ws/2004/04/trust"">" & $CRLF & _
    "   <Header>" & $CRLF & _
    "       <ps:AuthInfo" & $CRLF & _
    "           xmlns:ps=""http://schemas.microsoft.com/Passport/SoapServices/PPCRL""" & $CRLF & _
    "           Id=""PPAuthInfo"">" & $CRLF & _
    "           <ps:HostingApp>{7108E71A-9926-4FCB-BCC9-9A9D3F32E423}</ps:HostingApp>" & $CRLF & _
    "           <ps:BinaryVersion>4</ps:BinaryVersion>" & $CRLF & _
    "           <ps:UIVersion>1</ps:UIVersion>" & $CRLF & _
    "           <ps:Cookies></ps:Cookies>" & $CRLF & _
    "           <ps:RequestParams>AQAAAAIAAABsYwQAAAAxMDMz</ps:RequestParams>" & $CRLF & _
    "       </ps:AuthInfo>" & $CRLF & _
    "       <wsse:Security>" & $CRLF & _
    "           <wsse:UsernameToken Id=""user"">" & $CRLF & _
    "               <wsse:Username><<<MyEmailAddress>>></wsse:Username>" & $CRLF & _
    "               <wsse:Password><<<MyPassword>>></wsse:Password>" & $CRLF & _
    "           </wsse:UsernameToken>" & $CRLF & _
    "       </wsse:Security>" & $CRLF & _
    "   </Header>" & $CRLF & _
    "   <Body>" & $CRLF & _
    "       <ps:RequestMultipleSecurityTokens" & $CRLF & _
    "           xmlns:ps=""http://schemas.microsoft.com/Passport/SoapServices/PPCRL""" & $CRLF & _
    "           Id=""RSTS"">" & $CRLF & _
    "           <wst:RequestSecurityToken Id=""RST0"">" & $CRLF & _
    "               <wst:RequestType>http://schemas.xmlsoap.org/ws/2004/04/security/trust/Issue</wst:RequestType>" & $CRLF & _
    "               <wsp:AppliesTo>" & $CRLF & _
    "                   <wsa:EndpointReference>" & $CRLF & _
    "                       <wsa:Address>http://Passport.NET/tb</wsa:Address>" & $CRLF & _
    "                   </wsa:EndpointReference>" & $CRLF & _
    "               </wsp:AppliesTo>" & $CRLF & _
    "           </wst:RequestSecurityToken>" & $CRLF & _
    "           <wst:RequestSecurityToken Id=""RSTn"">" & $CRLF & _
    "               <wst:RequestType>http://schemas.xmlsoap.org/ws/2004/04/security/trust/Issue</wst:RequestType>" & $CRLF & _
    "               <wsp:AppliesTo>" & $CRLF & _
    "                   <wsa:EndpointReference>" & $CRLF & _
    "                       <wsa:Address>domain</wsa:Address>" & $CRLF & _
    "                   </wsa:EndpointReference>" & $CRLF & _
    "               </wsp:AppliesTo>" & $CRLF & _
    "               <wsse:PolicyReference URI=""<<<MBI_KEY_OLD>>>""></wsse:PolicyReference>" & $CRLF & _
    "           </wst:RequestSecurityToken>" & $CRLF & _
    "       </ps:RequestMultipleSecurityTokens>" & $CRLF & _
    "   </Body>" & $CRLF & _
    "</Envelope>"
    
    END FUNCTION
    
    
    FUNCTION WriteSSLPOST(XMLPOST AS STRING) AS STRING
    
      LOCAL v1 AS VARIANT, v2 AS VARIANT, v3 AS VARIANT
      LOCAL v4 AS VARIANT, v5 AS VARIANT, v6 AS VARIANT
      LOCAL objResultXMLDoc AS DISPATCH
    
      SET objResultXMLDoc   = CreateObject("Msxml2.DOMDocument")
    
      ' Post the SOAP message.
      DIM objXMLHTTP AS DISPATCH
      SET objXMLHTTP = CreateObject("Microsoft.XMLHTTP")
      v1 ="post"
      v2 = "https://login.live.com/RST.srf"
      v3 = 0
      OBJECT CALL objXMLHTTP.open(v1, v2, v3)
    
      v1 = "Content-Type"
      v2 = "text/xml; charset=UTF-8"
    '  OBJECT CALL objXMLHTTP.setRequestHeader(v1, v2)
    
      v1 = "Accept"
      v2 = "TEXT/*"
    '  OBJECT CALL objXMLHTTP.setRequestHeader(v1, v2)
    
      v1 = "USER-Agent"
      v2 = "Vega"
    '  OBJECT CALL objXMLHTTP.setRequestHeader(v1, v2)
    
      v1 = "HOST"
      v2 = "loginnet.passport.com"
      OBJECT CALL objXMLHTTP.setRequestHeader(v1, v2)
    
      v1 = "Content-Length"
      v2 = FORMAT$(LEN(XMLPOST))
    '  OBJECT CALL objXMLHTTP.setRequestHeader(v1, v2)
    
      v1 = "Connection"
      v2 = "Keep-Alive"
    '  OBJECT CALL objXMLHTTP.setRequestHeader(v1, v2)
    
      v1 = "Cache-CONTROL"
      v2 = "no-cache"
    '  OBJECT CALL objXMLHTTP.setRequestHeader(v1, v2)
    
    
      SET v1 = XMLPOST
      OBJECT CALL objXMLHTTP.send(v1)
    
      '-- Save the response to v2
      OBJECT GET objXMLHTTP.ResponseText TO v2
    
      FUNCTION = VARIANT$(v2)
    
      ' clean up
      SET objXMLHTTP        = NOTHING
      SET objResultXMLDoc   = NOTHING
    
    END FUNCTION
    
    FUNCTION PBMAIN () AS LONG
    
    LOCAL Hserver1   AS LONG
    LOCAL HServer2   AS LONG
    LOCAL FF1        AS LONG
    LOCAL FF2        AS LONG
    LOCAL NextServer AS STRING
    LOCAL Result     AS STRING
    LOCAL XML        AS STRING
    LOCAL Key        AS STRING
    
    FF1 = FREEFILE
    ERRCLEAR
    TCP OPEN PORT 1863 AT "207.46.96.153" AS #FF1
    
    Result     = WriteMsnPort(FF1, "VER %TRN MSNP15 CVR0")
    Result     = WriteMsnPort(FF1, "CVR %TRN 0x0C0A winnt 5.1 i686 MSNMSGR 8.1.0178 MSFT " & $EmailAddress )
    NextServer = PARSE$(WriteMsnPort(FF1, "USR %TRN SSO I " & $EmailAddress), " ", 4)
    
    TCP CLOSE #FF1
    
    ERRCLEAR
    
    FF1 = FREEFILE
    TCP OPEN PORT VAL(PARSE$(NextServer, ":", 2)) AT PARSE$(NextServer, ":", 1) AS #FF1
    
    Result     = WriteMsnPort(FF1, "VER %TRN MSNP15 CVR0")
    Result     = WriteMsnPort(FF1, "CVR %TRN 0x0C0A winnt 5.1 i686 MSNMSGR 8.1.0178 MSFT " & $EmailAddress)
    Result     = WriteMsnPort(FF1, "USR %TRN SSO I " & $EmailAddress)
    
    Key = TRIM$(MID$(Result, INSTR(-1, Result, " "), 256), ANY " " & $CRLF)
    
    XML = XMLSkeleton()
    
    REPLACE "<<<MyEmailAddress>>>" WITH $emailaddress IN XML
    REPLACE "<<<MyPassword>>>"     WITH $Password     IN XML
    REPLACE "<<<MBI_KEY_OLD>>>"    WITH Key           IN XML
    
    Result = WriteSSLPOST(XML)
    
    MSGBOX Result
    
    END FUNCTION

    Leave a comment:


  • Elias Montoya
    replied
    Originally posted by Paul Franks View Post
    No third-party software to install and configure, either.
    Hmm i ended up using this: but now i dont know why it is not working, do you see anything wrong?:

    Code:
    FUNCTION WriteSSLPOST(XMLPOST AS STRING) AS STRING
    
      LOCAL v1 AS VARIANT, v2 AS VARIANT, v3 AS VARIANT
      LOCAL v4 AS VARIANT, v5 AS VARIANT, v6 AS VARIANT
      LOCAL objResultXMLDoc AS DISPATCH
    
      SET objResultXMLDoc   = CreateObject("Msxml2.DOMDocument")
    
      ' Post the SOAP message.
      DIM objXMLHTTP AS DISPATCH
      SET objXMLHTTP = CreateObject("Microsoft.XMLHTTP")
      v1 ="post"
      v2 = "https://login.live.com/RST.srf"
      v3 = 0
      OBJECT CALL objXMLHTTP.open(v1, v2, v3)
    
      v1 = "Content-Type"
      v2 = "text/xml; charset=UTF-8"
      OBJECT CALL objXMLHTTP.setRequestHeader(v1, v2)
    
      v1 = "Accept"
      v2 = "TEXT/*"
      OBJECT CALL objXMLHTTP.setRequestHeader(v1, v2)
    
      v1 = "USER-Agent"
      v2 = "Vega"
      OBJECT CALL objXMLHTTP.setRequestHeader(v1, v2)
    
      v1 = "HOST"
      v2 = "loginnet.passport.com"
      OBJECT CALL objXMLHTTP.setRequestHeader(v1, v2)
    
      v1 = "Content-Length"
      v2 = FORMAT$(LEN(XMLPOST))
      OBJECT CALL objXMLHTTP.setRequestHeader(v1, v2)
    
      v1 = "Connection"
      v2 = "Keep-Alive"
      OBJECT CALL objXMLHTTP.setRequestHeader(v1, v2)
    
      v1 = "Cache-CONTROL"
      v2 = "no-cache"
      OBJECT CALL objXMLHTTP.setRequestHeader(v1, v2)
    
    
      SET v1 = XMLPOST
      OBJECT CALL objXMLHTTP.send(v1)
    
      '-- Save the response to v2
      OBJECT GET objXMLHTTP.ResponseText TO v2
    
      FUNCTION = VARIANT$(v2)
    
      ' clean up
      SET objXMLHTTP        = NOTHING
      SET objResultXMLDoc   = NOTHING
    
    END FUNCTION

    Leave a comment:


  • Paul Franks
    replied
    Originally posted by Mark Strickland View Post

    A "quick and dirty" way to implement an SSL connection is to use STUNNEL (www.stunnel.org). It uses OpenSSL and makes a "regular" TCP connection work like an SSL (HTTPS) connection.

    It does not work in every case but it can simplify an SSL connection.
    Just as easy to use the COM services built into Windows (one of which I showed earlier), or the Windows HTTP Services API:

    http://msdn2.microsoft.com/en-us/lib...8VS.85%29.aspx

    No third-party software to install and configure, either.

    Leave a comment:


  • David Roberts
    replied
    Come back POFFS- all is forgiven.

    Leave a comment:


  • Elias Montoya
    replied
    These ones work perfect. Mines were a mess!!! Not knowing anything about Encryption
    makes it almost impossible!!

    Thanx David.

    Leave a comment:


  • David Roberts
    replied
    > The results are not the same in all cases, it is supposed to be the same always, right?

    Yes. Code from the old forum is getting mangled up. The messages had lost any capitalisation so their HMAC values would not be the same.

    Go back to the Source Code link, Elias, and use the last two posts.

    Leave a comment:


  • Elias Montoya
    replied
    David, i saw your code at:
    http://www.powerbasic.com/support/pb...highlight=HMAC

    The results are not the same in all cases, it is supposed to be the same always, right?

    Leave a comment:


  • Mark Strickland
    replied
    May not apply --- but

    I quickly read through this thread and may have missed something but if you are stuck on the SSL connection part this may help. If not file it away for future reference.

    A "quick and dirty" way to implement an SSL connection is to use STUNNEL (www.stunnel.org). It uses OpenSSL and makes a "regular" TCP connection work like an SSL (HTTPS) connection.

    It does not work in every case but it can simplify an SSL connection.

    Leave a comment:


  • David Roberts
    replied
    Sent.

    Leave a comment:


  • Elias Montoya
    replied
    Sure, its in my signature.

    Leave a comment:


  • David Roberts
    replied
    HMAC-SHA1 Test Vectors

    In addition you can use my HashFile.exe. You will need to save messages as txt files, or whatever, and then HMAC the file with whatever key you want to use. Keys may be Text or Hex strings.

    If you let me have an email address I'll send a zip file - 328KB.

    Leave a comment:


  • Elias Montoya
    replied
    Thanx robert, Yes, the HMAC is what is giving me fight, this is helping me a lot
    for learning, i didnt know anythins just couple days ago. Now i found some HMAC SHA1 specifications and im writting the routines in PB, well maybe just the HMAC part.

    Im guessing i am going to need some pre-computed results to test against the results
    of the routines i write.

    Leave a comment:


  • David Roberts
    replied
    alg1.Key = key
    hash1 = alg1.ComputeHash(magicb)

    You missed a line out, Elias.

    alg1 = HMACSHA1.Create
    alg1.Key = key
    hash1 = alg1.ComputeHash(magicb)

    HMAC uses a key - it authenticates the hash.

    A good description of the HMAC algorithm can be found here. It is what I use for HMAC-SHA256 because SHA256 is not in the MS Crypto APIs - as does Eddy Van Esch's HIME library which has SHA1 and HMAC-SHA1.
    Last edited by David Roberts; 12 Feb 2008, 11:17 AM.

    Leave a comment:


  • David Roberts
    replied
    I've just realised that your code in post #20, Elias, is Semen Matusovski's SHA1 code. That is a lot easier to implement than my code. I don't use %CALG_SHA1 directly - I use WhichHash which may be either %CALG_SHA1 or %CALG_MD5.

    > Seems like it computes the SHA1 Hash using some kind of a key

    SHA1 doesn't use a key but it may be used in hashing a key?

    Leave a comment:


  • David Roberts
    replied
    With regard to SHA1 I use the MS Crypto APIs directly.

    The following is a quick and dirty code rip from a working application which hashes files as opposed to text.

    It was thrown together very quickly but it does correctly calculate the Control samples indicated.

    With regard to HMAC I had read that there was a leak in the MS HMAC hash object so have reverted to first principles in my own code. I have since read that the bug is in NT4 and Win95.

    Code:
    #COMPILE  EXE
    #Register None
    #DIM      ALL
    #TOOLS    OFF
    
    %NOMMIDS = 1
    %NOGDI = 1
    
    #Include "WIN32API.INC"
    
    ' ***************************************************************
    ' Credit to Don Dickinson for the following equates & delarations
     
    %HP_HASHSIZE = &h0004
    %HP_HASHVAL  = &h0002
    %ALG_SID_MD5 = 3
    %ALG_SID_SHA1 = 4
    %ALG_CLASS_HASH = 32768
    %ALG_TYPE_ANY = 0
    %CALG_MD5 = %ALG_CLASS_HASH Or %ALG_TYPE_ANY Or %ALG_SID_MD5
    %CALG_SHA1 = %ALG_CLASS_HASH Or %ALG_TYPE_ANY Or %ALG_SID_SHA1
    %PROV_RSA_FULL = 1
    $MS_DEF_PROV = "Microsoft Base Cryptographic Provider v1.0"
    %CRYPT_NEWKEYSET = &h00000008
    
    Declare Function crGetDefaultRSAHandle As Long
    Declare Function CryptCreateHash Lib "advapi32.dll" Alias "CryptCreateHash" _
          (  ByVal hProv As Long, ByVal iAlgID As Long, ByVal hKey As Long, _
             ByVal dwFlags As Dword, hHash As Long ) As Long
    Declare Function CryptDestroyHash Lib "advapi32.dll" Alias "CryptDestroyHash" _
          (  ByVal hHash As Long ) As Long
    Declare Function CryptHashData Lib "advapi32.dll" Alias "CryptHashData" _
          (  ByVal hHash As Long, pbData As Any, ByVal dwDatalen As Dword, _
             ByVal dwFlags As Long ) As Long
    Declare Function CryptReleaseContext Lib "advapi32.dll" Alias "CryptReleaseContext" _
          (  ByVal hCryptProv As Long, ByVal dwFlags As Dword ) As Long
          
    Declare Function CryptAcquireContext Lib "advapi32.dll" Alias "CryptAcquireContextA" _
          (  hCryptProv As Long, zContainer As Asciiz, zProvider As Asciiz, _
             ByVal dwProvType As Dword, ByVal dwFlags As Dword ) As Long
    
    ' End of credits
    ' ******************************************************************************************         
    
    Declare Function CryptGetHashParam Lib "advapi32.dll" Alias "CryptGetHashParam" _
          (  ByVal hHash As Long, ByVal dwParam As Dword, pbData As Any, _
             pdwDataLen As Long, ByVal dwFlags As Long ) As Long         
    Declare Function FormatErrMsg( ByVal Long, String) As String
    
    Declare Function CreateHash( Long, Long, Long ) As Long
    Declare Function HashText( sText As String) As String
    
    ' *********************************
    Function PBMain( ) As Long
    
    Local sText As String
    
    MsgBox HashText("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq")
    
    End Function
    ' *********************************
    
    Function FormatErrMsg( ByVal WinErr As Long, Comment As String ) As String ' Windows Error message
    Local Buff  As Asciiz * 64
    
    	Call FormatMessage( %FORMAT_MESSAGE_FROM_SYSTEM, ByVal %Null, WinErr, %Null, Buff, SizeOf( Buff ), ByVal %Null )
    	If Len( Buff ) Then
       	Function = "Error" + Str$( WinErr ) + Comment + " : " + Buff
    	Else
      	Function = "Unknown error code: " + Str$( WinErr )
    	End If
    
    End Function
    
    ' Credit to Don Dickinson
    ' ***********************
    Function crGetDefaultRSAHandle As Long
    
    Local hProv                         As Long
    
      If CryptAcquireContext( hProv, ByVal %Null, ByVal %Null, %PROV_RSA_FULL, 0 ) = %False Then
    
      '- Create a new key container
      '
      '  This will only be called the first time you
      '  run this program.
      '
        If CryptAcquireContext( hProv, ByVal %Null, $MS_DEF_PROV, %PROV_RSA_FULL, _
        %CRYPT_NEWKEYSET ) = %False Then
          Function = %False
        Else
          Function = hProv
        End If
      Else
        Function = hProv
      End If
    End Function
    ' ***************
    
    Function CreateHash( hProv As Long, Which As Long, hHash As Long ) As Long
      If CryptCreateHash( hProv, Which, 0, 0, hHash ) = %FALSE Then
        CryptReleaseContext hProv, 0
      Else
        Function = %TRUE
      End If
    End Function      
    
    Function HashText( sText As String) As String
    Local hProv, hhash, hSize, WinErr, i As Long
    Dim hText As String
    Dim hByte( ) As Byte
    
    hProv = crGetDefaultRSAHandle
    If hProv = 0 Then
      WinErr = GetLastError
      MessageBox 0, FormatErrMsg( WinErr, " in HashText routine" ), " HashText", %MB_ICONERROR  Or %MB_APPLMODAL Or %MB_TOPMOST
      Function = "Error"
      Exit Function
    End If
    If CreateHash( hProv, %CALG_SHA1, hHash ) = %False Then ' Use %CALG_MD5 for, yep, MD5
      WinErr = GetLastError
      MessageBox 0, FormatErrMsg( WinErr, " in HashText routine" ), " HashText", %MB_ICONERROR  Or %MB_APPLMODAL Or %MB_TOPMOST
      Function = "Error"
      Exit Function
    End If
    
    If CRYPTHASHDATA( hHash, ByVal StrPtr(sText), Len(sText), 0 ) = %False Then
      WinErr = GetLastError
      MessageBox 0, FormatErrMsg( WinErr, " in HashText routine" ), " HashText", %MB_ICONERROR Or %MB_APPLMODAL Or %MB_TOPMOST
      Function = "Error"
      Exit Function
    End If
    
    If CryptGetHashParam( hHash, %HP_HASHSIZE, hSize, 4, 0 ) = %FALSE Then
      WinErr = GetLastError
      MessageBox 0, FormatErrMsg( WinErr, " in HashText routine" ), " HashText", %MB_ICONERROR  Or %MB_APPLMODAL Or %MB_TOPMOST
      Function = "Error"
      Exit Function
    End If
    ReDim hByte( hSize - 1 ) As Byte
    If CryptGetHashParam( hHash, %HP_HASHVAL, hByte( 0 ), hSize, 0 ) = %FALSE Then
      WinErr = GetLastError
      MessageBox 0, FormatErrMsg( WinErr, " in HashText routine" ), " HashText", %MB_ICONERROR  Or %MB_APPLMODAL Or %MB_TOPMOST
      Function = "Error"
      Exit Function
    End If
    hText = ""
    For i = 0 To hSize - 1
      hText = hText + Hex$( hByte( i ),2 )
    Next 
    
    CryptDestroyHash hHash
    CryptReleaseContext hProv, 0
    
    Function = hText
    
    End Function

    Leave a comment:


  • Elias Montoya
    replied
    No, it doesnt show there. it shows some of the interfaces of mscorlib.dll,
    but some of them are "restricted".

    Ill see what i can do.

    Leave a comment:


  • Paul Franks
    replied
    Did some searching, looks like M$ has a COM interface to the Win32 CryptoAPI called CAPICOM, which is very old, difficult to use, and being replaced by CNG, which is .NET only.

    Also found a COM crypto object for Google Checkout which appears to be much easier to use:

    http://code.google.com/apis/checkout..._Code_ASP.html

    Might help, I don't know for sure...

    Leave a comment:


  • Paul Franks
    replied
    Originally posted by Elias Montoya View Post
    COM class, .NET class... They look the same in the COm browser.
    how can i tell the difference?
    If it shows up in PB's COM browser, it's definitely COM. Can't find any docs for it on MSDN, though, but M$ is making if difficult to find anything that's not .NET.

    You'll need to produce the .INC file using the COM browser, then see what the actual object name is. That doesn't look right, should be something like Microsoft.xxxxx or MSCrypto.xxxxx or something similar.

    Leave a comment:


  • Elias Montoya
    replied
    I wont give up but i think i will give it a rest. Whan i cant figure out here
    is this part:

    Code:
            alg1.Key = key
            hash1 = alg1.ComputeHash(magicb)
    Seems like it computes the SHA1 Hash using some kind of a key, but the
    following code doesnt seem to use it:

    Code:
    #Compile Exe
    #Register None
    #Dim All
    #Include "Win32Api.Inc"
    
    $FileNm = "Win322.hlp"
    
       Type SHA
          H0 As Long
          H1 As Long
          H2 As Long
          H3 As Long
          H4 As Long
       End Type
    
       Function CalcSHA (Str As String, SHA As SHA) As Long
          #Register None
    
          Dim lStr As Long, nq As Long, n As Long, adrW As Long, adrWW As Long
          Dim H0 As Long, H1 As Long, H2 As Long, H3 As Long, H4 As Long, W(0 : 79) As Long
          Dim A As Long, B As Long, C As Long, D As Long, E As Long, TEMP As Long
    
          lStr = Len(Str)
          nq = Fix((lStr + 8) / 64) + 1
          n = 16 * nq
          ReDim WW(0 To n - 1) As Long
    
          WW(n - 1) = lStr * 8
          adrW = VarPtr(W(0))
          adrWW = VarPtr(WW(0))
          A = StrPtr(Str)
    
          ! PUSH EDI
          ! PUSH ESI
    
          ! MOV EDI, adrWW
          ! MOV ESI, A
          ! MOV ECX, lStr
          ! REP MOVSB
    
          ! MOV CL, &H80
          ! MOV [EDI], CL
    
          ! MOV EDI, adrWW
          ! MOV ECX, 2
     CalcSHA_Lbl1:
          ! MOV AX, [EDI]
          ! MOV DX, [EDI + 2]
          ! MOV [EDI], DH
          ! MOV [EDI + 1], DL
          ! MOV [EDI + 2], AH
          ! MOV [EDI + 3], AL
          ! ADD EDI, 4
          ! INC ECX
          ! CMP ECX, n
          ! JNE CalcSHA_Lbl1
    
          ! MOV H0, &H67452301&
          ! MOV H1, &HEFCDAB89&
          ! MOV H2, &H98BADCFE&
          ! MOV H3, &H10325476&
          ! MOV H4, &HC3D2E1F0&
    
     CalcSHA_Lbl2:
    
          ! MOV EDI, adrW
          ! MOV ESI, adrWW
          ! MOV ECX, 64
          ! REP MOVSB
          ! MOV adrWW, ESI
    
          ! MOV ECX, 0
     CalcSHA_Lbl3:
          ! MOV ESI, ECX
          ! ADD ESI, ESI
          ! ADD ESI, ESI
          ! ADD ESI, adrW
    
          ! MOV EAX, [ESI + 52]
          ! XOR EAX, [ESI + 32]
          ! XOR EAX, [ESI + 8]
          ! XOR EAX, [ESI]
    
          ! MOV EDX, EAX
          ! SHL EAX, 1
          ! SHR EDX, 31
          ! OR  EAX, EDX
          ! MOV [ESI + 64], EAX
    
          ! INC ECX
          ! CMP ECX, 64
          ! JNE CalcSHA_Lbl3
    
          ! MOV EAX, H0
          ! MOV A, EAX
          ! MOV EAX, H1
          ! MOV B, EAX
          ! MOV EAX, H2
          ! MOV C, EAX
          ! MOV EAX, H3
          ! MOV D, EAX
          ! MOV EAX, H4
          ! MOV E, EAX
    
          ! MOV EDI, 0
     CalcSHA_Lbl4:
          ! CMP EDI, 19
          ! JA CalcSHA_Lbl5
    
          ! MOV ECX, B
          ! AND ECX, C
          ! MOV EAX, B
          ! NOT EAX
          ! AND EAX, D
          ! OR  ECX, EAX
          ! ADD ECX, &H5A827999&
          ! JMP CalcSHA_Lbl8
    
     CalcSHA_Lbl5:
          ! CMP EDI, 39
          ! JA CalcSHA_Lbl6
    
          ! MOV ECX, B
          ! XOR ECX, C
          ! XOR ECX, D
          ! ADD ECX, &H6ED9EBA1&
          ! JMP CalcSHA_Lbl8
    
     CalcSHA_Lbl6:
          ! CMP EDI, 59
          ! JA CalcSHA_Lbl7
    
          ! MOV EAX, B
          ! AND EAX, C
          ! MOV ECX, B
          ! AND ECX, D
          ! MOV EDX, C
          ! AND EDX, D
          ! OR  ECX, EAX
          ! OR  ECX, EDX
          ! ADD ECX, &H8F1BBCDC&
          ! JMP CalcSHA_Lbl8
    
     CalcSHA_Lbl7:
          ! MOV ECX, B
          ! XOR ECX, C
          ! XOR ECX, D
          ! ADD ECX, &HCA62C1D6&
    
     CalcSHA_Lbl8:
          ! MOV EAX, A
          ! MOV EDX, EAX
          ! SHL EAX, 5
          ! SHR EDX, 27
          ! OR  EAX, EDX
          ! ADD EAX, E
          ! ADD ECX, EAX
    
          ! MOV ESI, EDI
          ! ADD ESI, ESI
          ! ADD ESI, ESI
          ! ADD ESI, adrW
          ! MOV ESI, [ESI]
          ! MOV TEMP, ESI
    
          ! ADD Temp, ECX
          ! MOV EAX, D
          ! MOV E, EAX
          ! MOV EAX, C
          ! MOV D, EAX
          ! MOV EAX, B
          ! MOV EDX, EAX
          ! SHL EAX, 30
          ! SHR EDX, 2
          ! OR  EAX, EDX
          ! MOV C, EAX
          ! MOV EAX, A
          ! MOV B, EAX
          ! MOV EAX, TEMP
          ! MOV A, EAX
    
          ! INC EDI
          ! CMP EDI, 80
          ! JNE CalcSHA_Lbl4
    
          ! MOV EAX, A
          ! ADD H0, EAX
          ! MOV EAX, B
          ! ADD H1, EAX
          ! MOV EAX, C
          ! ADD H2, EAX
          ! MOV EAX, D
          ! ADD H3, EAX
          ! MOV EAX, E
          ! ADD H4, EAX
    
          ! SUB nq, 1
          ! JNE CalcSHA_Lbl2
    
          ! POP ESI
          ! POP EDI
    
          SHA.H0 = H0: SHA.H1 = H1: SHA.H2 = H2: SHA.H3 = H3: SHA.H4 = H4
    
       End Function
    
       Function tSHA (SHA As SHA) As String
          Function = Hex$(SHA.H0, 8) + " " + Hex$(SHA.H1, 8) + " " + Hex$(SHA.H2, 8) + " " + _
                     Hex$(SHA.H3, 8) + " " + Hex$(SHA.H4, 8)
       End Function
       Function PbMain
    
          Dim SHA As SHA
    
          ' Control samples from official document
          CalcSHA "abc", SHA
          If tSHA(SHA) <> "A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D" Then MsgBox "Error-1"
    
          CalcSHA "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", SHA
          If tSHA(SHA) <> "84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1" Then MsgBox "Error-2"
    
          ' Test of speed
          Dim R As String, Tmp As String, t1 As Single, t2 As Single
          Open $FileNm For Binary As #1
          Tmp = Space$(Lof(1)): Get$ #1, Lof(1), Tmp: Close #1
    
          t1 = Timer: CalcSHA Tmp, SHA: t2 = Timer
          MsgBox Format$(Len(Tmp) / 1024 / (t2 - t1), "# Kb per second")
    
       End Function

    Leave a comment:

Working...
X