小编Hei*_*nzi的帖子

tomcat不提供中间证书(https)

我使用openssl可执行文件在控制台上创建了一个密钥和一个csr.然后我将csr发送到CA并获得了证书.现在我想将它导入tomcat.

所以我用我的密钥和我的证书创建了一个PKCS#12文件:

openssl pkcs12 -export -in mycert.cert -inkey mykey.pem -out key_and_cert.p12
Run Code Online (Sandbox Code Playgroud)

然后创建一个包含它的密钥库:

keytool -importkeystore -deststorepass [password] -destkeystore keystore.jks -srckeystore key_and_cert.p12 -srcstoretype PKCS12 -srcstorepass [password]
Run Code Online (Sandbox Code Playgroud)

然后我导入中间证书chain.crt:

keytool -import -trustcacerts -alias root -file chain.crt -keystore keystore.jks
Run Code Online (Sandbox Code Playgroud)

这里输出"keytool -keystore keystore.jks -list":

Keystore-Typ: JKS
Keystore-Provider: SUN

Ihr Keystore enthält 2 Einträge.

root, 14.11.2011, trustedCertEntry,
Zertifikatsfingerabdruck (MD5): [fingerprint]
1, 14.11.2011, PrivateKeyEntry, 
Zertifikatsfingerabdruck (MD5): [fingerprint]
Run Code Online (Sandbox Code Playgroud)

tomcat server.xml包含:

<Connector port="443" protocol="HTTP/1.1" SSLEnabled="true"
           maxThreads="150" scheme="https" secure="true"
           clientAuth="false" URIEncoding="UTF-8" compression="on"
           sslProtocol="TLS"
           keystoreFile="/[absolute-path]/keystore.jks"
           keystorePass="[password]" />
Run Code Online (Sandbox Code Playgroud)

当我重新启动tomcat时,它在catalina.out中没有记录任何错误,一切似乎都没问题.但是当我运行firefox时,它会报告

[domain] uses an invalid …
Run Code Online (Sandbox Code Playgroud)

https tomcat openssl certificate keystore

25
推荐指数
4
解决办法
3万
查看次数

Rust 异步删除

我面临着一种情况,我需要从对象的放置处理程序运行异步代码。整个应用程序在 tokio 异步上下文中运行,因此我知道 drop 处理程序是使用活动的 tokio 运行时调用的,但不幸的是 drop 本身是一个同步函数。

理想情况下,我想要一个适用于多线程和当前线程运行时的解决方案,但如果不存在,那么我可以使用阻止删除线程并依赖其他线程来驱动的解决方案期货。

我考虑了多种选择,但我不确定哪种方法最好,也不了解它们的权衡。对于这些示例,我们假设我的类有一个async terminate(&mut self)我希望从 调用的函数drop()

struct MyClass;
impl MyClass {
    async fn terminate(&mut self) {}
}
Run Code Online (Sandbox Code Playgroud)

选项1:tokio::runtime::Handle::block_on

impl Drop for MyClass {
    fn drop(&mut self) {
        tokio::runtime::Handle::current().block_on(self.terminate());
    }
}
Run Code Online (Sandbox Code Playgroud)

这似乎是最直接的方法,但不幸的是它会引起恐慌

Cannot start a runtime from within a runtime. This happens because a function (like `block_on`) attempted to block the current thread while the thread is being used to drive asynchronous tasks.
Run Code Online (Sandbox Code Playgroud)

操场

我对此有点困惑,因为我认为Handle::block_on会使用当前正在运行的运行时,但它似乎试图启动一个新的运行时?这里发生了什么? …

asynchronous rust async-await rust-tokio rust-futures

23
推荐指数
1
解决办法
4688
查看次数

在clang-tidy中忽略系统头

tldr;>如何在clang-tidy中隐藏系统头文件中的警告?

我有以下最小示例源文件,它会在系统标头中触发一个铿锵有力的警告:

#include <future>

int main() {
  std::promise<int> p;
  p.set_value(3);
}
Run Code Online (Sandbox Code Playgroud)

在Ubuntu 17.04上使用clang-tidy 4.0.0使用libstdc ++ 7.0.1调用它:

$ clang-tidy main.cpp -extra-arg=-std=c++14
Run Code Online (Sandbox Code Playgroud)

产量

Running without flags.
1 warning generated.
/usr/lib/gcc/x86_64-linux-gnu/7.0.1/../../../../include/c++/7.0.1/mutex:693:5: warning: Address of stack memory associated with local variable '__callable' is still referred to by the global variable '__once_callable' upon returning to the caller.  This will be a dangling reference [clang-analyzer-core.StackAddressEscape]
    }
    ^
/home/user/main.cpp:5:3: note: Calling 'promise::set_value'
  p.set_value(3);
  ^
/usr/lib/gcc/x86_64-linux-gnu/7.0.1/../../../../include/c++/7.0.1/future:1094:9: note: Calling '_State_baseV2::_M_set_result'
      { _M_future->_M_set_result(_State::__setter(this, std::move(__r))); }
        ^
/usr/lib/gcc/x86_64-linux-gnu/7.0.1/../../../../include/c++/7.0.1/future:401:2: note: Calling 'call_once' …
Run Code Online (Sandbox Code Playgroud)

c++ clang clang-static-analyzer libtooling clang-tidy

19
推荐指数
2
解决办法
5460
查看次数

使用haskell构建动态库并使用C++实现

我想构建一个包含haskell函数的动态库.我在linux上工作,想从C++代码调用这个动态库.

我在http://wiki.python.org/moin/PythonVsHaskell上使用了这个例子并拥有以下文件:

Test.hs:

{-# LANGUAGE ForeignFunctionInterface #-}
module Test where

import Foreign.C.Types

hsfun :: CInt -> IO CInt
hsfun x = do
    putStrLn "Hello World"
    return (42 + x)

foreign export ccall
    hsfun :: CInt -> IO CInt
Run Code Online (Sandbox Code Playgroud)

module_init.c:

#define CAT(a,b) XCAT(a,b)
#define XCAT(a,b) a ## b
#define STR(a) XSTR(a)
#define XSTR(a) #a

#include <HsFFI.h>

extern void CAT (__stginit_, MODULE) (void);

static void library_init (void) __attribute__ ((constructor));
static void
library_init (void)
{
  /* This seems to be a …
Run Code Online (Sandbox Code Playgroud)

c++ haskell g++ ffi ghc

17
推荐指数
1
解决办法
1991
查看次数

如何在Node.JS加密中使用id-aes256-GCM?"TypeError:DecipherFinal失败"

我想使用经过身份验证的加密方案(如AES-GCM)加密Node.js中的某些数据.

如果我运行以下示例代码

app.get("/test", function(req,res)  {
  var key = "12345678901234567890123456789012";
  var iv = "123456789012"; 
  var cipher = crypto.createCipheriv("id-aes256-GCM",key.toString("binary"),iv.toString("binary"));
  var decipher = crypto.createDecipheriv("id-aes256-GCM",key.toString("binary"),iv.toString("binary"));

  console.log(decipher.update(cipher.update("bla")));
  console.log(decipher.update(cipher.final()));
  console.log(decipher.final());
});
Run Code Online (Sandbox Code Playgroud)

我没有得到控制台输出,但错误消息"TypeError:DecipherFinal失败".如果我使用密码AES-256-CTR而不是"id-aes256-GCM",此代码工作正常并在控制台上打印"bla".

我究竟做错了什么?

编辑:

进一步调查显示,cipher.update("bla")返回"â"(单个字符......奇怪)和cipher.final()返回一个空字符串.我认为这不能是一个正确的密文,至少应该有明文的大小......

javascript security cryptography node.js express

16
推荐指数
1
解决办法
2716
查看次数

Play2.0:重启致命错误?

我使用scala的playframework 2.0.4.我使用"play dist"部署应用程序,然后使用"./start"脚本启动它.

最近,我遇到了我的生产实例没有足够的内存和崩溃的情况.我收到了一个错误

Uncaught error from thread [play-akka.actor.promises-dispatcher-456] shutting down JVM since 'akka.jvm-exit-on-fatal-error' is enabled
Run Code Online (Sandbox Code Playgroud)

游戏过程已经死了.

有没有办法禁用akka.jvm-exit-on-fatal-error并将其设置为在崩溃时重启播放应用程序?这是一个生产环境,一个没有运行的应用程序并没有真正起作用.

scala akka playframework playframework-2.0

9
推荐指数
1
解决办法
914
查看次数

C++禁止覆盖虚函数

我使用的A类从库中,并希望通过自己的B类B类的用户应该从中获得一些功能添加到它,就好像他会从A类派生

class A {
    public:
        virtual void func1()=0;
        virtual void func2()=0;
        ...
}
class B: public A {
    public:
        virtual void func1() {...}
}
Run Code Online (Sandbox Code Playgroud)

因此,如果某人创建了一个源自B的C类,他应该实现func2:

class C: public B {
    public:
        virtual void func2() {...}
}
Run Code Online (Sandbox Code Playgroud)

对我的应用程序来说非常重要的是,C类不会覆盖func1,从而消除了B :: func1().

有没有办法禁止为B的所有子类重写此虚函数?如果不是普通的C++,那么当这个函数被覆盖时,boost MPL中是否存在抛出编译器错误的东西?

c++ boost boost-mpl

8
推荐指数
2
解决办法
722
查看次数

用C++编写Haskell解释器(使用ghc或hugs作为库)

我正在编写一个需要解释和评估haskell代码的C++应用程序.此代码在编译时是未知的,但由用户给出.有没有办法使用haskell编译器/解释器(如GHCi或拥抱)作为库?

  • 我找到了FFI,但这似乎只适用于编译时已知的haskell代码.
  • 我找到了GHC API和提示,但它们似乎只有在我想解释haskell中的haskell代码时才能工作.

c++ haskell ghc ghci hugs

8
推荐指数
1
解决办法
1439
查看次数

没有函数参数的变量模板

我可以在不使用模板参数作为函数参数的情况下使用可变参数模板吗?

当我使用它们时,它编译:

#include <iostream>
using namespace std;

template<class First>
void print(First first)
{
    cout << 1 << endl;
}

template<class First, class ... Rest>
void print(First first, Rest ...rest)
{
    cout << 1 << endl;
    print<Rest...>(rest...);
}

int main()
{
    print<int,int,int>(1,2,3);
}
Run Code Online (Sandbox Code Playgroud)

但是,当我不使用它们时,它不会编译并抱怨模棱两可:

#include <iostream>
using namespace std;

template<class First>
void print()
{
    cout << 1 << endl;
}

template<class First, class ... Rest>
void print()
{
    cout << 1 << endl;
    print<Rest...>();
}

int main()
{
    print<int,int,int>();
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,我想作为模板参数提供的类是不可实例化的(它们具有在模板函数内部调用的静态函数).有没有办法做到这一点?

c++ templates function-parameter variadic-templates c++11

8
推荐指数
2
解决办法
3936
查看次数

创建非默认可构造类的虚拟对象

tl; dr:我想构造一个包含泛型类型Value成员的ListEntry类,但Value不是默认构造的,ListEntry不知道如何构造它.我永远不会访问这个Value成员,所以没有初始化它并不重要.

为什么我这样做

我正在实现一个大致类似于以下内容的双链表

template<class Value>
class ListEntry {
  Value value;
  ListEntry<Value> *prev;
  ListEntry<Value> *next;
};
template<class Value>
class List {
  ListEntry<Value> sentinel;
};
Run Code Online (Sandbox Code Playgroud)

列表条目之间的链接总是形成一个闭合的圆圈,其中sentinel将最后一个列表元素连接到第一个列表元素.使用sentinel.prev =&sentinel和sentinel.next =&sentinel初始化sentinel对象.

这样,我摆脱了很多特殊情况,我永远不必检查nullptr,因为没有空指针.将元素添加到列表的末尾(在最后一个元素和sentinel之间)不是特殊情况,但与在两个真实元素之间的列表中间添加元素相同.

因此,在所有实际列表条目中,值字段将包含列表条目的实际值.对于它们,我可以通过在其构造函数中赋予它一个Value对象来初始化ListEntry,因此我不需要Value是默认的可构造的.在哨兵中,永远不会访问值字段.但不幸的是,由于Value不是默认构造的,编译器不允许我创建sentinel对象.

我可以使ListEntry中的value成员成为指针,boost :: optional或类似的东西.由于性能问题,我不喜欢这样.关于如何在没有性能/内存成本的情况下在ListEntry中存储Value并且不需要Value可默认构造的任何想法?在我看来,必须有一种获取Value对象而不调用其构造函数的方法.

c++ default-constructor sentinel c++14

7
推荐指数
2
解决办法
1881
查看次数