Java 版本
获取源码
你可以使用 git 命令,也可以直接在 Github 下载 ZIP 包
git clone https://github.com/baidu/openrasp.git准备环境
为了保证最大兼容性,我们建议使用 JDK 6 进行编译
为编译所依赖的JNI模块,需要安装 c++ 编译器和 cmake 生成器
以 CentOS 为例,使用如下命令,安装 g++ 5.3.1
yum install -y centos-release-scl
yum install -y devtoolset-4-gcc-c++安装完成后,执行如下命令进入编译环境
scl enable devtoolset-4 bash安装高版本 cmake
# 下载并解压到 /tmp,避免与已有 cmake 冲突
curl -L https://github.com/Kitware/CMake/releases/download/v3.15.3/cmake-3.15.3-Linux-x86_64.tar.gz | tar zx -C /tmp
# 增加临时 PATH
export PATH=/tmp/cmake-3.15.3-Linux-x86_64/bin:$PATH编译 openrasp-v8 基础库
以 64位 Linux 系统为例,在OpenRASP仓库根目录执行以下命令
更多平台的编译细节请参考
https://github.com/baidu-security/openrasp-v8/blob/master/.travis.yml
https://github.com/baidu-security/openrasp-v8/tree/master/.travis
开始编译
方案1 - 使用
IDEA Intellij进行操作导入
maven 工程,目录选agent/java,正常编译即可方案2 - 使用
mvn命令编译进入命令行,
最终生成的 JAR 包在
boot/target和engine/target目录下,aka:$openrasp_path/agent/java/boot/target/rasp.jar和$openrasp_path/agent/java/engine/target/rasp.jar方案3 - 使用
build-java.sh生成安装包如果你使用 Linux 进行编译,可以执行源代码目录下面的
build-java.sh进行编译和打包操作。这个脚本会在源代码根目录,生成rasp-java.tar.gz和rasp-java.zip两个文件
常见问题
1. maven 超时
如果总是出现超时错误,你可以考虑使用阿里云的镜像。
[ERROR] Plugin org.apache.maven.plugins:maven-resources-plugin:3.0.2 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:3.0.2: Could not transfer artifact org.apache.maven.plugins:maven-resources-plugin:pom:3.0.2 from/to central (https://repo.maven.apache.org/maven2): Connect to repo.maven.apache.org:443 [repo.maven.apache.org/151.101.196.215] failed: Operation timed out (Connection timed out) -> [Help 1]
修改方法是编辑 ~/.m2/settings.xml,并填写如下内容
2. git-commit-id-plugin 错误
如果你使用 JDK 1.6 编译,可能会遇到如下错误:
[ERROR] Plugin pl.project13.maven:git-commit-id-plugin:2.1.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for pl.project13.maven:git-commit-id-plugin:jar:2.1.5: Could not transfer artifact pl.project13.maven:git-commit-id-plugin:pom:2.1.5 from/to central (https://repo.maven.apache.org/maven2): Received fatal alert: protocol_version -> [Help 1]
这是一个 https 证书错误,解决方法是替换 maven 仓库地址为 http 版本。可以考虑修改 ~/.m2/settings.xml,并添加如下内容
3. 缺少 Premain-Class 属性
如果你使用IDE编译,最终可能出现这样的错误:
Failed to find Premain-Class manifest attribute in D:\apache-tomcat-7.0.82\rasp\rasp.jar
这是因为IDE没有修改 META-INF 下面的文件。我们建议你使用 maven 编译,或者直接导入 maven 工程
Last updated