Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Attributes | Private Attributes
nsCSecurityContext Class Reference

nsCSecurityContext implements nsISecurityContext interface for navigator. More...

#include <nsCSecurityContext.h>

Inheritance diagram for nsCSecurityContext:
Inheritance graph
[legend]
Collaboration diagram for nsCSecurityContext:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS NS_IMETHOD Implies (const char *target, const char *action, PRBool *bAllowedAccess)
 Get the security context to be used in LiveConnect.
NS_IMETHOD GetOrigin (char *buf, int len)
 Get the code base of the subject (caller).
NS_IMETHOD GetCertificateID (char *buf, int len)
 Get the certificate thumbprint of the subject (caller).
 nsCSecurityContext (JSContext *cx)
 nsCSecurityContext (nsIPrincipal *principal)
virtual ~nsCSecurityContext (void)

Protected Attributes

JSStackFramem_pJStoJavaFrame
JSContextm_pJSCX

Private Attributes

nsCOMPtr< nsIPrincipalm_pPrincipal
PRBool m_HasUniversalJavaCapability
PRBool m_HasUniversalBrowserReadCapability

Detailed Description

nsCSecurityContext implements nsISecurityContext interface for navigator.

This is used by a JVM to implement netscape.javascript.JSObject functionality.

Definition at line 60 of file nsCSecurityContext.h.


Constructor & Destructor Documentation

Definition at line 179 of file nsCSecurityContext.cpp.

                   : m_pJStoJavaFrame(NULL), m_pJSCX(cx),
                     m_pPrincipal(NULL),
                     m_HasUniversalJavaCapability(PR_FALSE),
                     m_HasUniversalBrowserReadCapability(PR_FALSE)
{
    MOZ_COUNT_CTOR(nsCSecurityContext);

      // Get the Script Security Manager.

    nsresult rv = NS_OK;
    nsCOMPtr<nsIScriptSecurityManager> secMan = 
             do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
    if (NS_FAILED(rv) || !secMan) return;

    
    nsCOMPtr<nsIPrincipal> principal;
    if (NS_FAILED(secMan->GetSubjectPrincipal(getter_AddRefs(principal))))
        // return;
        ; // Don't return here because the security manager returns 
          // NS_ERROR_FAILURE when there is no subject principal. In
          // that case we are not done.

    nsCOMPtr<nsIPrincipal> sysprincipal;
    if (NS_FAILED(secMan->GetSystemPrincipal(getter_AddRefs(sysprincipal))))
        return;

    // Do early evaluation of "UniversalJavaPermission" capability.

    PRBool equals;
    if (!principal || 
        NS_SUCCEEDED(principal->Equals(sysprincipal, &equals)) && equals) {
        // We have native code or the system principal: just allow general access
        m_HasUniversalBrowserReadCapability = PR_TRUE;
        m_HasUniversalJavaCapability = PR_TRUE;
    }
    else {
        // Otherwise, check with the js security manager.
        secMan->IsCapabilityEnabled("UniversalBrowserRead",&m_HasUniversalBrowserReadCapability);
        secMan->IsCapabilityEnabled("UniversalJavaPermission",&m_HasUniversalJavaCapability);
    }
}

Here is the call graph for this function:

Definition at line 222 of file nsCSecurityContext.cpp.

                   : m_pJStoJavaFrame(NULL), m_pJSCX(NULL),
                     m_pPrincipal(principal),
                     m_HasUniversalJavaCapability(PR_FALSE),
                     m_HasUniversalBrowserReadCapability(PR_FALSE)
{
    MOZ_COUNT_CTOR(nsCSecurityContext);

      // Get the Script Security Manager.

    nsresult rv = NS_OK;
    nsCOMPtr<nsIScriptSecurityManager> secMan = 
             do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
    if (NS_FAILED(rv) || !secMan) return;

    nsCOMPtr<nsIPrincipal> sysprincipal;
    if (NS_FAILED(secMan->GetSystemPrincipal(getter_AddRefs(sysprincipal))))
        return;

    // Do early evaluation of "UniversalJavaPermission" capability.

    if (!m_pPrincipal || m_pPrincipal == sysprincipal) {
        // We have native code or the system principal: just allow general access
        m_HasUniversalBrowserReadCapability = PR_TRUE;
        m_HasUniversalJavaCapability = PR_TRUE;
    }
    else {
        // Otherwise, check with the js security manager.
        secMan->IsCapabilityEnabled("UniversalBrowserRead",&m_HasUniversalBrowserReadCapability);
        secMan->IsCapabilityEnabled("UniversalJavaPermission",&m_HasUniversalJavaCapability);
    }
}

Here is the call graph for this function:

Definition at line 255 of file nsCSecurityContext.cpp.


Member Function Documentation

NS_METHOD nsCSecurityContext::GetCertificateID ( char *  buf,
int  len 
) [virtual]

Get the certificate thumbprint of the subject (caller).

Parameters:
buf-- Result buffer.
len-- Buffer length.
Returns:
-- NS_OK if the codebase string was obtained. -- NS_FALSE otherwise.

Implements nsISecurityContext.

Definition at line 143 of file nsCSecurityContext.cpp.

{
    nsCOMPtr<nsIPrincipal> principal;
  
    // Get the Script Security Manager.

    nsresult rv      = NS_OK;
    nsCOMPtr<nsIScriptSecurityManager> secMan = 
             do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
    if (NS_FAILED(rv) || !secMan) return NS_ERROR_FAILURE;

    secMan->GetSubjectPrincipal(getter_AddRefs(principal));
    if (!principal) {
        return NS_ERROR_FAILURE;
    }

    nsCAutoString certificate;
    principal->GetFingerprint(certificate);

    PRInt32 certlen = certificate.Length();
    if (buflen <= certlen) {
        return NS_ERROR_FAILURE;
    }

    memcpy(buf, certificate.get(), certlen);
    buf[certlen] = nsnull;

    return NS_OK;
}

Here is the call graph for this function:

NS_METHOD nsCSecurityContext::GetOrigin ( char *  buf,
int  len 
) [virtual]

Get the code base of the subject (caller).

Parameters:
buf-- Result buffer.
len-- Buffer length.
Returns:
-- NS_OK if the codebase string was obtained. -- NS_FALSE otherwise.

Implements nsISecurityContext.

Definition at line 108 of file nsCSecurityContext.cpp.

{
    if (!m_pPrincipal) {
        // Get the Script Security Manager.
        nsresult rv = NS_OK;
        nsCOMPtr<nsIScriptSecurityManager> secMan =
             do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
        if (NS_FAILED(rv) || !secMan) {
            return NS_ERROR_FAILURE;
        }

        secMan->GetSubjectPrincipal(getter_AddRefs(m_pPrincipal));
        if (!m_pPrincipal) {
            return NS_ERROR_FAILURE;
        }
    }

    nsXPIDLCString origin;
    m_pPrincipal->GetOrigin(getter_Copies(origin));

    PRInt32 originlen = origin.Length();
    if (origin.IsEmpty() || originlen > buflen - 1) {
        return NS_ERROR_FAILURE;
    }

    // Copy the string into to user supplied buffer. Is there a better
    // way to do this?

    memcpy(buf, origin, originlen);
    buf[originlen] = nsnull; // Gotta terminate it.

    return NS_OK;
}

Here is the call graph for this function:

NS_METHOD nsCSecurityContext::Implies ( const char *  target,
const char *  action,
PRBool bAllowedAccess 
) [virtual]

Get the security context to be used in LiveConnect.

This is used for JavaScript <--> Java.

Parameters:
target-- Possible target.
action-- Possible action on the target.
Returns:
-- NS_OK if the target and action is permitted on the security context. -- NS_FALSE otherwise.

Implements nsISecurityContext.

Definition at line 76 of file nsCSecurityContext.cpp.

{
    if(!bAllowedAccess) {
        return NS_ERROR_FAILURE;
    }
  
    if(!nsCRT::strcmp(target,"UniversalBrowserRead")) {
        // XXX we lie to the applet and say we have UniversalBrowserRead
        // even if we don't so that we can bypass the Java plugin's broken
        // origin checks.  Note that this only affects the plugin's perception
        // of our script's capabilities, and has no bearing on the script's
        // real capabilities. This code should be changed to assign
        // |m_HasUniversalBrowserReadCapability| into the out parameter
        // once Java's origin checking code is fixed.
        // See bug 146458 for details.
        if (JSJ_IsJSCallApplet()) {
            *bAllowedAccess = PR_TRUE;
        }
        else {
            *bAllowedAccess = m_HasUniversalBrowserReadCapability;
        }
    } else if(!nsCRT::strcmp(target,"UniversalJavaPermission")) {
        *bAllowedAccess = m_HasUniversalJavaCapability;
    } else {
        *bAllowedAccess = PR_FALSE;
    }

    return NS_OK;
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 114 of file nsCSecurityContext.h.

Definition at line 113 of file nsCSecurityContext.h.

Definition at line 110 of file nsCSecurityContext.h.

Definition at line 109 of file nsCSecurityContext.h.

Definition at line 112 of file nsCSecurityContext.h.


The documentation for this class was generated from the following files: