On Thu, 12 Dec 2024 20:53:17 GMT, Xue-Lei Andrew Fan <xue...@openjdk.org> wrote:

> > For third-party providers that override java.security.Provider::getService 
> > or java.security.Provider::getServices to return services that have not 
> > been evaluated against the filter or are evaluated and not allowed, a 
> > second filter enforcement occurs in 
> > java.security.Provider.Service::newInstance.
> 
> For unknown providers that override the Provider::getService and 
> Provider::getServices methods, I'm not sure how the filter could get them 
> evaluated with the 1st filter. For the 2nd filter, please refer to the next 
> comment.
> 

Yes, that's why we proposed filtering at 3 layers.

> > In rare situations, a third-party provider can override 
> > java.security.Provider.Service::newInstance and return an unvetted service 
> > implementation (SPI).
> 
> Well, there is a concern of mine. I don't agree the case is rare. What if you 
> are making a wrong judgment about it popularity here? Did you have data to 
> support your point. How could you get the case covered even for the rare case 
> even if it is really rare?
> 

While our perception of what is common and rare may be different, services 
overriding `newInstance` will be filtered anyways when used for Java SE service 
types (Cipher, Signature, Mac, etc). It's only the combination of a Provider 
that overrides getService/getServices + does not call putService/put + 
overrides newInstance without calling its parent + uses a non-Java SE service 
type that would be unfiltered. If this is a case that it is worth addressing 
—we don't have that impression, frankly—, we can expose one of the (now) 
internal-only Filter APIs. Cooperation from providers would still be needed, 
and there won't be any guarantees.

> With a new public API, for example ServicePermission.permit(Provider 
> service). I don't think you need the 2nd filter for 
> java.security.Provider.Service::newInstance any longer. All you need is to 
> updates the following 2 or 3 methods, plus a few bug fixes out of the scope 
> of this JEP: provider.putService() (optional, for performance improvement 
> only) provider.getService() provider.getServices()
> 
> And document the public API and have third party provider follow the spec and 
> use the API. Without a public API, there is not much we can do for unknown 
> third party providers. Even with the public API, third party's provider may 
> not follow it. But they now have a way to follow the spec, and application 
> also have solutions for those that do not follow the new spec yet.

Our proposal makes filtering transparent to security providers (including 
3rd-party ones) and does not require any cooperation: 3rd party security 
providers will be filtered whether they want/like it or not. If my 
understanding is correct, your proposal requires cooperation from 3rd-party 
providers so they invoke a public API and follow the filter's verdict. Even if 
they implement this API, older versions of the same provider will not be 
filter-aware. This would make the filter weaker, and compliance/enforcement 
provider-dependent. For example, you'll need to check the provider version and 
implementation to know if it is filter-aware.

> 
> Let's see the scenarios:
> 
> 1. Define a public service API: ServicePermission.permit(Provider service), 
> and a method to get the service so that it can be set with a security 
> property (see [UUID.fromString improvement to be more efficient when parsing 
> 36-byte valid values #4](https://github.com/openjdk/jdk/pull/4)).
> 2. Using the service specified in [UUID.fromString improvement to be more 
> efficient when parsing 36-byte valid values 
> #4](https://github.com/openjdk/jdk/pull/4), update  provider.getService() and 
> provider.getServices(), and submit to JDK repository.
> 3. Application implement the ServicePermission service, 
> ThisIsMyFilterProvider (JDK could have a java.security property filter 
> implementation in a new JEP, but it is not necessarily have any value in 
> default JDK).
> 4. Update java.security update, 
> java.security.filter="ThisIsMyFilterProvider", default value is empty.
> 5. Enjoy it.
> 
> > are we going to have different syntax depending on the 3rd-party filter 
> > implementor?
> 
> No, there is not syntax to maintain at all, unless you want to define a 
> specific ServicePermission provider. You can do that with your proposal about 
> the syntax for default JDK, and enforce it for your own proposal. You don't 
> want to worry about those applications that don't use your proposal: 
> java.security.filter=my-filter-Provider-with-my-loved-syntax
>

If my understanding is correct, your proposal opens the door for filter 
providers that may have, each of them, their own configuration to specify what 
is allowed and what is not. Statically determining what is filtered is not as 
easy as reading `java.security.filter` and interpreting a unique syntax: you 
need to analyze how 3rd-party filter providers are configured. This is what I 
mean by more complexity.

> > The problems of filtering by algorithm parameters and by use (e.g. MD5 for 
> > UUID) are not easy to solve, will require further discussion and are 
> > orthogonal to a pluggable filter.
> 
> No, it is not easy for your proposal. But it is not that hard with a 
> customizable ServicePermission.permit(Provider service) APIs. I think smart 
> developers could have it addressed for specific environment, so that we don't 
> need to worry about them for a general approach for all environment.

To filter by use, you need to know who the caller is (call stack, more 
specifically) and whether or not the use should be allowed. Java SE service 
types invoke the filter in getInstance but cache the filter decision in the 
Service instance for efficiency. To filter by use we would need to call the 
filter for every single getInstance call (it's not the service any more, but 
who is getting a reference to the service), and pass the call stack perhaps. 
Even if we do that, once an SPI instance is created, the filter loses track of 
further uses. This problem is orthogonal to who makes the decision (built-in? 
3rd-party?), and it's not an easy one to solve.

I don't see how the problem of filtering with finer granularity would be 
addressed either. The problem is not the implementation —in fact, that would be 
the easy part for the built-in filter—, the problem is how concepts are less 
universal once you go down the algorithm level. In other words, it's not a 
single rule that applies to any security provider anymore but you need to write 
rules tailored to each provider —e.g. you need to know what algorithm 
parameters a provider use for X algorithm, how values are specified (bits? 
bytes?) and that will be reflected in the filtering rule—. This problem is 
orthogonal to who makes the filtering decision.

> 
> It looks like more simple, powerful and having actual requirements, is it?

I don't see it in the same way at the moment, but I'll let other engineers 
weigh-in and follow the discussion. @adinn ? @franferrax ?

-------------

PR Comment: https://git.openjdk.org/jdk/pull/15539#issuecomment-2540171500

Reply via email to