Phil Jones said:
My concern (as was pointed out to me a few psts back on this list) is that
Friend is still accessible via Reflection - which means it's not secure,
it's just not visible.
What I think I need to do is adorn the method (or Class etc) with a
code-access-security permission. Something that actually walks the stack
to make sure the calling procedure actually is a Friend.
This is one possible approach, but you should be careful not to subclass
System.Security.CodeAccessPermission if you want to ensure that your
permission is not trivially bypassed by disabling CAS. You might also want
to keep in mind that it is relatively simple to decompile an assembly,
remove the permission demands, and recompile. Depending on what kind of
threat you attempting to protect against, this may make the permission
approach far too much bother for the level of protection it provides.
This seems like it'd be such a common requirement (ie. when I declare
Friend, I really mean Friend, in the securist sense) that the framework
would provide for it. Maybe not - but I just wanted to check.
You'll probably find StrongNameIdentityPermission demands recommended for
this in at least a few places. However, they're easily bypassed by fully
trusted code, so they may not suit your goals. Basically, there's nothing
built into CAS to truly protect any given code from being called by fully
trusted code. If you are considering rolling your own protection mechanism,
I'd recommend a licensing approach rather than a CAS permission approach.
While licensing will be a bit more difficult and time-consuming to
implement, you'll be able to use it more widely than a permission that
merely checks that callers are in the same assembly.