GNUTLS中的SNI,何时询问

SNI in GNUTLS, when to ask?

本文关键字:何时询 SNI 中的 GNUTLS      更新时间:2023-10-16

所以,我试图在我的GNUTLS服务器中实现SNI。

我的代码:
if(sniCallback != NULL) {
    size_t ds = 256;
    char data[ds];
    unsigned int type = (unsigned int)GNUTLS_NAME_DNS;
    int snir = gnutls_server_name_get(sessiond, &data[0], &ds, &type, (unsigned int)0);
    data[ds - 1] = 0; // the last one must always be 
    if(snir >= 0) {
        jstring js = (*this)->NewStringUTF(this, data);
        jlong snicert = (*this)->CallLongMethod(this, sniCallback, (*this)->GetMethodID(this, (*this)->GetObjectClass(this, sniCallback), "getSNICert", "(Ljava/lang/String;)J"), js);
        if(snicert > 0L) {
            struct cert* oc = (struct cert*)snicert;
            gnutls_credentials_set(sessiond, GNUTLS_CRD_CERTIFICATE, oc->cert);
        }
    } else {
        printf("%in", snir);
    }
}

(不介意JNI)

我得到-56错误代码,这是GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE,文档翻译为未发送SNI(尚未)。我如何知道我何时有SNI信息?也就是我什么时候能得到客户端你好?我直接从Chrome得到这个,所以我知道有SNI。这些都是NIO的

对于那些和我在同一条道路上的人,答案是:

gnutls_handshake_set_post_client_hello_function