Hello Jason,

Here is the our code:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using OAuth;
using System.Text;
using WSESimpleTCPDLL;
using System.Runtime.InteropServices;
using System.Collections.Specialized;


/// <summary>
/// Summary description for oBasePage
/// </summary>
public class oBasePage : System.Web.UI.Page
{
    HttpContext htp;
    public oBasePage(HttpContext _htp)
    {
        htp = _htp;

    }

    public bool isvalidrequest()
    {
        string AppId =
System.Configuration.ConfigurationManager.AppSettings["oAppId"].ToString();
        if (htp.Request.QueryString["opensocial_app_id"].ToString() !=
AppId)
        {
            //
htp.Response.Write(htp.Request.QueryString["opensocial_app_id"].ToString());
            //Response.End()
            return false;
        }
        X509Certificate Cert =
X509Certificate.CreateFromCertFile(htp.Request.PhysicalApplicationPath
+ "/bin/pub.1199819524.-1556113204990931254.cer");

        //Getting Post variables
        string http_params;
        NameValueCollection _p = htp.Request.Form;
        Hashtable _hp = new Hashtable();
        foreach (string k in _p.Keys)
        {
            if (k != null)
            {
                _hp[k] = _p[k];
            }
        }

        SortedList _ps = new SortedList((IDictionary)_hp);

        string[] pairs1 = new string[_ps.Keys.Count];
        int l = 0;
        foreach (string name in _ps.Keys)
        {
            if (name == "__display_name")
            {
                pairs1[l++] = name + "=" +
Uri.EscapeDataString(_ps[name].ToString());
                //htp.Response.Write("" +
Uri.EscapeDataString(_ps[name].ToString()));
            }
            else
            {
                pairs1[l++] = name + "=" +
Uri.EscapeDataString(_ps[name].ToString());
            }
        }
        http_params = (String.Join("&", pairs1));

        if (_ps.Keys.Count != 0)
        {
            http_params = "&" + http_params;
        }


        RSACryptoServiceProvider Provider =
CertUtil.GetCertPublicKey(Cert);
        OAuth.OAuthBase ba = new OAuthBase();
        string signature =
(htp.Request.QueryString["oauth_signature"]);
        string baseString = ba.GenerateSignatureBase(htp.Request.Url,

        htp.Request.QueryString["oauth_consumer_key"], "",
htp.Request.QueryString["oauth_token"], "", htp.Request.HttpMethod,

        htp.Request.QueryString["oauth_timestamp"],
htp.Request.QueryString["oauth_nonce"], "RSA-SHA1", http_params);
        byte[] sign = Convert.FromBase64String(signature);
        byte[] bstring = Encoding.UTF8.GetBytes(baseString);
        return (Provider.VerifyData(bstring, "SHA1", sign));

    }

}







/// <summary>
/// Summary description for CertUtil.
/// </summary>
public sealed class CertUtil
{
    const uint CERT_SYSTEM_STORE_CURRENT_USER = 0x00010000;
    const uint CERT_STORE_READONLY_FLAG = 0x00008000;
    const uint CERT_STORE_OPEN_EXISTING_FLAG = 0x00004000;
    const uint CERT_FIND_SUBJECT_STR = 0x00080007;
    const uint X509_ASN_ENCODING = 0x00000001;
    const uint PKCS_7_ASN_ENCODING = 0x00010000;
    const uint RSA_CSP_PUBLICKEYBLOB = 19;
    const int AT_KEYEXCHANGE = 1; //keyspec values
    const int AT_SIGNATURE = 2;
    static uint ENCODING_TYPE = PKCS_7_ASN_ENCODING |
X509_ASN_ENCODING;


    private CertUtil()
    {
    }


    public static RSACryptoServiceProvider
GetCertPublicKey(X509Certificate cert)
    {
        byte[] publickeyblob;
        byte[] encodedpubkey = cert.GetPublicKey(); //asn.1 encoded
public key


        uint blobbytes = 0;


        if (Win32.CryptDecodeObject(ENCODING_TYPE,
RSA_CSP_PUBLICKEYBLOB,
        encodedpubkey, (uint)encodedpubkey.Length, 0, null, ref
blobbytes))
        {
            publickeyblob = new byte[blobbytes];
            Win32.CryptDecodeObject(ENCODING_TYPE,
RSA_CSP_PUBLICKEYBLOB,
            encodedpubkey, (uint)encodedpubkey.Length, 0,
publickeyblob, ref blobbytes);
        }
        else
        {
            throw new Exception("Could not decode publickeyblob from
certificate publickey");
        }


        PUBKEYBLOBHEADERS pkheaders = new PUBKEYBLOBHEADERS();
        int headerslength = Marshal.SizeOf(pkheaders);
        IntPtr buffer = Marshal.AllocHGlobal(headerslength);
        Marshal.Copy(publickeyblob, 0, buffer, headerslength);
        pkheaders = (PUBKEYBLOBHEADERS)Marshal.PtrToStructure(buffer,
typeof(PUBKEYBLOBHEADERS));
        Marshal.FreeHGlobal(buffer);


        //----- Get public exponent -------------
        byte[] exponent = BitConverter.GetBytes(pkheaders.pubexp);
        //little-endian ordered
        Array.Reverse(exponent); //convert to big-endian order


        //----- Get modulus -------------
        int modulusbytes = (int)pkheaders.bitlen / 8;
        byte[] modulus = new byte[modulusbytes];
        try
        {
            Array.Copy(publickeyblob, headerslength, modulus, 0,
modulusbytes);
            Array.Reverse(modulus); //convert from little to big-
endian ordering.
        }
        catch (Exception)
        {
            throw new Exception("Problem getting modulus from
publickeyblob");
        }


        RSAParameters parms = new RSAParameters();
        parms.Modulus = modulus;
        parms.Exponent = exponent;
        RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
        rsa.ImportParameters(parms);
        return rsa;
    }
}


On Oct 2, 5:40 am, Jason <[EMAIL PROTECTED]> wrote:
> Thanks Marco. Can you test the source in the thread I linked to
> previously while I work to verify the problem with yours?
>
> - Jason
>
> On Oct 1, 1:46 pm, csharpsocial <[EMAIL PROTECTED]> wrote:
>
> > Hi Jason,
> > I have sent you a test app with the code.
>
> > Thanks for your help
>
> > Marco
>
> > On Oct 1, 7:24 pm, Jason <[EMAIL PROTECTED]> wrote:
>
> > > Are all of you using custom (e.g. in-house, self-written) C#
> > > validation code or is there a shared routine for .NET back-ends. It's
> > > somewhat disconcerting that this would break suddenly in such a
> > > limited way (the PHP code provided in the wiki seems to work, so it's
> > > not an issue with the public key), but it's also clear that there is
> > > something going on.
>
> > > Feel free to send me your source and I'll look into it straightaway,
> > > but you may also want to take a look at this thread in the meantime
> > > which has a complete C# validation routine (towards the bottom of the
> > > post) that the developer indicates is working:
>
> > >http://groups.google.com/group/opensocial-orkut/browse_thread/thread/...
>
> > > - Jason
>
> > > On Sep 29, 11:32 pm, Raman <[EMAIL PROTECTED]> wrote:
>
> > > > Yes, ditto.
> > > > I have a live app running on orkut (or should I say, it was). Coz, my 
> > > > dot
> > > > net code is not able to authenticate the requests from Orkut anymore. 
> > > > Whats
> > > > the issue? What have been changed?
>
> > > > Raman- Hide quoted text -
>
> > > - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Orkut Developer Forum" group.
To post to this group, send email to opensocial-orkut@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/opensocial-orkut?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to