1. XenForo 1.5.14 中文版——支持中文搜索!现已发布!查看详情
  2. Xenforo 爱好者讨论群:215909318 XenForo专区

新闻 Firefly 4.6.0 正式版发布,新增OpenSSL引擎支持 下载

本帖由 漂亮的石头2017-11-21 发布。版面名称:软件资讯

  1. 漂亮的石头

    漂亮的石头 版主 管理成员

    注册:
    2012-02-10
    帖子:
    488,069
    赞:
    47
    Firefly v4.6.0 新增了OpenSSL引擎支持,命名参数SQL API,HTTP客户端连接泄露追踪,并修复了一些bug。完善了HTTP服务器与客户端Kotlin版数据库访问Kotlin版以及SSL/TLS配置文档。

    使用OpenSSL引擎

    现在Firefly支持JDK SSL引擎和OpenSSL引擎作为网络安全层。JDK SSL引擎是默认的。JDK8的SSL引擎不支持ALPN(应用层协议协商),HTTP2协议在TLS握手中需要ALPN的支持。如果您使用JDK8 SSL引擎则需要添加VM参数来设置一个引导程序alpn-boot.jar(具体情况参考SSL/TLS配置文档)。如果您在某些情况下无法修改VM参数,我们提供了支持ALPN的OpenSSL引擎支持,不需要任何VM设置就能启用HTTP2协议。例如:



    public class OpensslHTTPsServer {
    public static void main(String[] args) {
    $.httpsServer(new DefaultOpenSSLSecureSessionFactory())
    .router().get("/").handler(ctx -> ctx.end("hello world!"))
    .listen("localhost", 8081);
    }
    }

    访问 https://localhost:8081 ,浏览器将显示



    hello world!

    您也可以使用自己的证书文件,例如:



    public class OpensslFileCertHTTPsServer {
    public static void main(String[] args) throws IOException {
    ClassPathResource certificate = new ClassPathResource("/myCA.cer");
    ClassPathResource privateKey = new ClassPathResource("/myCAPriv8.key");
    SecureSessionFactory factory = new FileCertificateOpenSSLSecureSessionFactory(
    certificate.getFile().getAbsolutePath(),
    privateKey.getFile().getAbsolutePath());

    $.httpsServer(factory)
    .router().get("/").handler(ctx -> ctx.end("hello world!"))
    .listen("localhost", 8081);
    }
    }

    注意:OpenSSL私钥文件必须使用PKCS8格式,您可以使用“openssl pkcs8”命令进行格式转换,例如:



    openssl genrsa -out myCA.key 2048
    openssl req -new -x509 -key myCA.key -out myCA.cer -days 36500
    openssl pkcs8 -topk8 -inform PEM -outform PEM -in myCA.key -out myCAPriv8.key -nocrypt

    命名参数SQL API

    命名参数SQL增加了代码的可读性。当我们使用命名参数SQL的时候,可以使用map或者javabean来替换占位符。

    Java版例子:

    @test
    public void testInsert() {
    String sql = "insert into `test`.`user`(pt_name, pt_password) values(?,?)";
    Mono<Long> newUserId = exec(c -> c.insert(sql, "hello user", "hello user pwd"));
    StepVerifier.create(newUserId).expectNext(size + 1L).verifyComplete();

    String namedSql = "insert into `test`.`user`(pt_name, pt_password) values:)name, :password)";
    Map<String, Object> paramMap = new HashMap<>();
    paramMap.put("name", "hello user1");
    paramMap.put("password", "hello user pwd1");
    newUserId = exec(c -> c.namedInsert(namedSql, paramMap));
    StepVerifier.create(newUserId).expectNext(size + 2L).verifyComplete();

    User user = new User();
    user.setName("hello user2");
    user.setPassword("hello user pwd2");
    newUserId = exec(c -> c.namedInsert(namedSql, user));
    StepVerifier.create(newUserId).expectNext(size + 3L).verifyComplete();
    }

    Kotlin版例子:

    @test
    fun testInsert() = runBlocking {
    val newUserId = exec {
    it.asyncInsert<Long>("insert into `test`.`user`(pt_name, pt_password) values(?,?)",
    "hello user", "hello user pwd")
    }
    assertEquals(size + 1L, newUserId)

    val namedSQL = "insert into `test`.`user`(pt_name, pt_password) values:)name, :password)"
    val newUserId2 = exec {
    it.asyncNamedInsert<Long>(namedSQL, mapOf("name" to "hello user", "password" to "hello user pwd"))
    }
    assertEquals(size + 2L, newUserId2)

    val newUserId3 = exec {
    it.asyncNamedInsert<Long>(namedSQL, User(null, "hello user", "hello user pwd", null))
    }
    assertEquals(size + 3L, newUserId3)
    }

    更新日志:


    1. 网络工具增加OpenSSL引擎支持。


    2. 增加命名参数SQL API。


    3. 完成了Kotlin相关文档。


    4. 新增了SSL/TLS配置文档。


    5. 修复了使用请求Accept头匹配router时,router优先级错误的问题。


    6. 增加了默认的bad message监听器。


    7. 增加了HTTP client连接泄露追踪。
    Firefly 4.6.0 正式版发布,新增OpenSSL引擎支持下载地址
     
正在加载...