Https 生成主密钥tls1.2

Https 生成主密钥tls1.2,https,key,tls1.2,Https,Key,Tls1.2,我正在尝试使用openssl中的命令行手动为https会话找出/生成主密钥。我一直在HTTPS对话中跟踪所有相关数据,直到客户端密钥交换、更改密码规范、加密握手消息。到目前为止,我在RFC5246中了解到,要做到这一点,需要: master_secret=PRF(pre_master_secret,“master secret”,ClientHello.random+ServerHello.random)[0..47] RFC中的进一步读数等于: p_hash(secret,seed)=HMAC

我正在尝试使用openssl中的命令行手动为https会话找出/生成主密钥。我一直在HTTPS对话中跟踪所有相关数据,直到客户端密钥交换、更改密码规范、加密握手消息。到目前为止,我在RFC5246中了解到,要做到这一点,需要: master_secret=PRF(pre_master_secret,“master secret”,ClientHello.random+ServerHello.random)[0..47]

RFC中的进一步读数等于:

p_hash(secret,seed)=HMAC_hash(secret,A(1)+seed)+HMAC_hash(secret,A(2)+seed)+。。。 其中secret=来自客户端的主密钥 其中A(0)=SEED=“master secret”+clienthello.random+serverhello.random

A(1)=HMAC_散列(秘密,A(0)) A(2)=HMAC_散列(秘密,A(1))

然后迭代,直到得到所需的主密钥/密钥的48字节

如果我的假设是正确的,我希望通过使用openssl的命令行进行迭代来获得我的48个字节,如果可能的话,可以是这样的2倍或获得48个字节所需的数量。我知道这只是向屏幕回显我当然会存储在下一次迭代中使用的值。 echo-n“值”| openssl dgst-sha1-hmac“密钥”

我对RFC的解释是否有偏差,或者类似的情况是否可能?如果我的解释正确,我是否遗漏了任何步骤? 当做
大卫我不清楚你的问题。(英语不是我的母语。) 但我自己实现了prf函数。并用测试向量进行了测试。 它很好用

template<class H> class PRF
{//H is hash function usually sha256
public:
    template<class It> void secret(const It begin, const It end) {
        for(It it = begin; it != end; it++) secret_.push_back(*it);
        hmac_.key(secret_.begin(), secret_.end());
    }
    void label(const char* p) {
        while(*p) label_.push_back(*p++);
    }
    template<class It> void seed(const It begin, const It end) {
        for(It it = begin; it != end; it++) seed_.push_back(*it);
    }
    std::vector<unsigned char> get_n_byte(int n) {
        auto seed = label_;//seed = label + seed_
        seed.insert(seed.end(), seed_.begin(), seed_.end());
        std::vector<unsigned char> r, v;
        std::vector<std::array<unsigned char, H::output_size>> vA;
        vA.push_back(hmac_.hash(seed.begin(), seed.end()));//A(1)
        while(r.size() < n) {
            v.clear();
            v.insert(v.end(), vA.back().begin(), vA.back().end());
            v.insert(v.end(), seed.begin(), seed.end());
            auto h = hmac_.hash(v.begin(), v.end());
            r.insert(r.end(), h.begin(), h.end());
            vA.push_back(hmac_.hash(vA.back().begin(), vA.back().end()));//A(i+1)
        }
        while(r.size() != n) r.pop_back();
        return r;
    }

protected:
    HMAC<H> hmac_;
    std::vector<unsigned char> secret_, label_, seed_;
};
模板类PRF
{//H是哈希函数,通常为sha256
公众:
模板无效机密(常量开始,常量结束){
对于(It=begin;It!=end;It++)秘密,向后推(*It);
hmac_.key(secret_.begin(),secret_.end());
}
无效标签(常量字符*p){
while(*p)label_u.push_uback(*p++);
}
模板无效种子(常量开始,常量结束){
对于(It=begin;It!=end;It++)种子,向后推(*It);
}
std::向量获取字节(int n){
自动种子=标签\;//种子=标签+种子_
seed.insert(seed.end(),seed.begin(),seed.end());
std::向量r,v;
std::向量vA;
vA.push_back(hmac_u.hash(seed.begin(),seed.end());//A(1)
while(r.size()
正如您在代码中看到的那样,(i+1)是通过对以前生成的一个进行散列而生成的。 代码不是抽象的,而是一个具体的例子

我希望你能在这段代码中得到你需要的信息