简体   繁体   English

Java本机接口和安全性

[英]Java Native Interface and Security

Is there any chance for the the violation of java security policy through java native interface. 是否有通过Java本机接口违反Java安全策略的机会。 Which are the main areas we have to use JNI 我们必须使用JNI的主要领域

Java's Security policies simply do not apply to native code called via JNI, so obviously the native code can violate them at will. Java的安全策略根本不适用于通过JNI调用的本机代码,因此显然本机代码可能会随意违反它们。

As for what JNI us used for, these days it's mainly to call OS-specific APIs or interface with existing non-Java code. 至于我们使用的JNI,最近主要是调用特定于OS的API或与现有的非Java代码进行接口。 Improving performance used to be a frequently-cited reason, but considering the state of VMs and JIT compilers today, that almost never makes sense. 提高性能曾经是经常被提及的原因,但是考虑到当今VM和JIT编译器的状态,这几乎没有任何意义。

Yes, once you invoke native code through JNI it can do pretty much anything the current user is allowed to do - eg delete all their files. 是的,一旦通过JNI调用本机代码,它就可以执行当前用户被允许执行的几乎所有操作,例如删除其所有文件。 The Java system cannot police anything that native code does. Java系统无法管理本机代码所做的任何事情。

You don't have to use JNI for anything - it's typically used for eg low-level access (eg critical error handling for a removable drive) or to access a C API which doesn't have a pure-Java equivalent. 不必使用JNI的任何东西-它通常用于例如,低级别的访问(如关键错误处理的可移动驱动器),或者访问一个C API不具有纯Java等价物。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM